Skip to content

Commit 9d2beb2

Browse files
authored
Remove VerifyDetachedSignatureAndSaltedHash and SaltedHashSpecifier (#196)
This commit removes the openpgp.VerifyDetachedSignatureAndSaltedHash function and the packet.SaltedHashSpecifier as they are not required anymore. They were introduced for verifying the headers in cleartext messages. However, in the latest crypto refresh specification, cleartext message headers were dropped.
1 parent f60acf6 commit 9d2beb2

File tree

3 files changed

+10
-44
lines changed

3 files changed

+10
-44
lines changed

openpgp/packet/signature.go

-7
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,6 @@ type VerifiableSignature struct {
127127
Packet *Signature
128128
}
129129

130-
// SaltedHashSpecifier specifies that the given salt and hash are
131-
// used by a v6 signature.
132-
type SaltedHashSpecifier struct {
133-
Hash crypto.Hash
134-
Salt []byte
135-
}
136-
137130
// NewVerifiableSig returns a struct of type VerifiableSignature referencing the input signature.
138131
func NewVerifiableSig(signature *Signature) *VerifiableSignature {
139132
return &VerifiableSignature{

openpgp/read.go

+10-35
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package openpgp // import "github.com/ProtonMail/go-crypto/openpgp"
77

88
import (
9-
"bytes"
109
"crypto"
1110
_ "crypto/sha256"
1211
_ "crypto/sha512"
@@ -455,45 +454,32 @@ func (scr *signatureCheckReader) Read(buf []byte) (int, error) {
455454
// if any, and a possible signature verification error.
456455
// If the signer isn't known, ErrUnknownIssuer is returned.
457456
func VerifyDetachedSignature(keyring KeyRing, signed, signature io.Reader, config *packet.Config) (sig *packet.Signature, signer *Entity, err error) {
458-
return verifyDetachedSignature(keyring, signed, signature, nil, nil, false, config)
457+
return verifyDetachedSignature(keyring, signed, signature, nil, false, config)
459458
}
460459

461460
// VerifyDetachedSignatureAndHash performs the same actions as
462461
// VerifyDetachedSignature and checks that the expected hash functions were used.
463462
func VerifyDetachedSignatureAndHash(keyring KeyRing, signed, signature io.Reader, expectedHashes []crypto.Hash, config *packet.Config) (sig *packet.Signature, signer *Entity, err error) {
464-
return verifyDetachedSignature(keyring, signed, signature, expectedHashes, nil, true, config)
465-
}
466-
467-
// VerifyDetachedSignatureAndSaltedHash performs the same actions as
468-
// VerifyDetachedSignature and checks that the expected hash functions and salts were used.
469-
func VerifyDetachedSignatureAndSaltedHash(keyring KeyRing, signed, signature io.Reader, expectedHashes []crypto.Hash, expectedSaltedHashes []*packet.SaltedHashSpecifier, config *packet.Config) (sig *packet.Signature, signer *Entity, err error) {
470-
return verifyDetachedSignature(keyring, signed, signature, expectedHashes, expectedSaltedHashes, true, config)
463+
return verifyDetachedSignature(keyring, signed, signature, expectedHashes, true, config)
471464
}
472465

473466
// CheckDetachedSignature takes a signed file and a detached signature and
474467
// returns the entity the signature was signed by, if any, and a possible
475468
// signature verification error. If the signer isn't known,
476469
// ErrUnknownIssuer is returned.
477470
func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader, config *packet.Config) (signer *Entity, err error) {
478-
_, signer, err = verifyDetachedSignature(keyring, signed, signature, nil, nil, false, config)
479-
return
480-
}
481-
482-
// CheckDetachedSignatureAndSaltedHash performs the same actions as
483-
// CheckDetachedSignature and checks that the expected hash functions or salted hash functions were used.
484-
func CheckDetachedSignatureAndSaltedHash(keyring KeyRing, signed, signature io.Reader, expectedHashes []crypto.Hash, expectedSaltedHashes []*packet.SaltedHashSpecifier, config *packet.Config) (signer *Entity, err error) {
485-
_, signer, err = verifyDetachedSignature(keyring, signed, signature, expectedHashes, expectedSaltedHashes, true, config)
471+
_, signer, err = verifyDetachedSignature(keyring, signed, signature, nil, false, config)
486472
return
487473
}
488474

489475
// CheckDetachedSignatureAndHash performs the same actions as
490476
// CheckDetachedSignature and checks that the expected hash functions were used.
491477
func CheckDetachedSignatureAndHash(keyring KeyRing, signed, signature io.Reader, expectedHashes []crypto.Hash, config *packet.Config) (signer *Entity, err error) {
492-
_, signer, err = verifyDetachedSignature(keyring, signed, signature, expectedHashes, nil, true, config)
478+
_, signer, err = verifyDetachedSignature(keyring, signed, signature, expectedHashes, true, config)
493479
return
494480
}
495481

496-
func verifyDetachedSignature(keyring KeyRing, signed, signature io.Reader, expectedHashes []crypto.Hash, expectedSaltedHashes []*packet.SaltedHashSpecifier, checkHashes bool, config *packet.Config) (sig *packet.Signature, signer *Entity, err error) {
482+
func verifyDetachedSignature(keyring KeyRing, signed, signature io.Reader, expectedHashes []crypto.Hash, checkHashes bool, config *packet.Config) (sig *packet.Signature, signer *Entity, err error) {
497483
var issuerKeyId uint64
498484
var hashFunc crypto.Hash
499485
var sigType packet.SignatureType
@@ -523,22 +509,11 @@ func verifyDetachedSignature(keyring KeyRing, signed, signature io.Reader, expec
523509
sigType = sig.SigType
524510
if checkHashes {
525511
matchFound := false
526-
if sig.Version == 6 {
527-
// check for salted hashes
528-
for _, expectedSaltedHash := range expectedSaltedHashes {
529-
if hashFunc == expectedSaltedHash.Hash && bytes.Equal(sig.Salt(), expectedSaltedHash.Salt) {
530-
matchFound = true
531-
break
532-
}
533-
}
534-
535-
} else {
536-
// check for hashes
537-
for _, expectedHash := range expectedHashes {
538-
if hashFunc == expectedHash {
539-
matchFound = true
540-
break
541-
}
512+
// check for hashes
513+
for _, expectedHash := range expectedHashes {
514+
if hashFunc == expectedHash {
515+
matchFound = true
516+
break
542517
}
543518
}
544519
if !matchFound {

openpgp/v2/read.go

-2
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,6 @@ func VerifyDetachedSignature(keyring KeyRing, signed, signature io.Reader, confi
669669
// Once all data is read from md.UnverifiedBody the detached signature is verified.
670670
// If a verification error occurs it is stored in md.SignatureError
671671
// If the signer isn't known, ErrUnknownIssuer is returned.
672-
// If expectedHashes or expectedSaltedHashes is not nil, the method checks
673-
// if they match the signatures metadata or else return an error
674672
func VerifyDetachedSignatureReader(keyring KeyRing, signed, signature io.Reader, config *packet.Config) (md *MessageDetails, err error) {
675673
return verifyDetachedSignatureReader(keyring, signed, signature, config)
676674
}

0 commit comments

Comments
 (0)