Skip to content

Commit

Permalink
Remove signature rejection logic based on hash (#303)
Browse files Browse the repository at this point in the history
The hash rejection is handled by the lower level library go-crypto.
  • Loading branch information
lubux authored Oct 29, 2024
1 parent d208118 commit c664aa9
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions crypto/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package crypto

import (
"bytes"
"crypto"
"fmt"
"time"

Expand All @@ -14,13 +13,6 @@ import (
"github.com/ProtonMail/gopenpgp/v3/constants"
)

var allowedHashesSet = map[crypto.Hash]struct{}{
crypto.SHA224: {},
crypto.SHA256: {},
crypto.SHA384: {},
crypto.SHA512: {},
}

// VerifiedSignature is a result of a signature verification.
type VerifiedSignature struct {
Signature *packet.Signature
Expand Down Expand Up @@ -223,15 +215,6 @@ func newSignatureFailed(cause error) SignatureVerificationError {
}
}

// newSignatureInsecure creates a new SignatureVerificationError, type
// SignatureFailed, with a message describing the signature as insecure.
func newSignatureInsecure() SignatureVerificationError {
return SignatureVerificationError{
Status: constants.SIGNATURE_FAILED,
Message: "Insecure signature",
}
}

// newSignatureNotSigned creates a new SignatureVerificationError, type
// SignatureNotSigned.
func newSignatureNotSigned() SignatureVerificationError {
Expand Down Expand Up @@ -305,8 +288,6 @@ func createVerifyResult(
signatureError = newSignatureNoVerifier()
case signature.SignatureError != nil:
signatureError = newSignatureFailed(signature.SignatureError)
case signature.CorrespondingSig == nil || !isHashAllowed(signature.CorrespondingSig.Hash):
signatureError = newSignatureInsecure()
case verificationContext != nil:
err := verificationContext.verifyContext(signature.CorrespondingSig)
if err != nil {
Expand Down Expand Up @@ -394,6 +375,9 @@ func findContext(notations []*packet.Notation) (string, error) {
}

func (context *VerificationContext) verifyContext(sig *packet.Signature) error {
if sig == nil {
return errors.New("gopenpgp: no signature packet found for signature")
}
signatureContext, err := findContext(sig.Notations)
if err != nil {
return err
Expand All @@ -409,8 +393,3 @@ func (context *VerificationContext) verifyContext(sig *packet.Signature) error {

return nil
}

func isHashAllowed(h crypto.Hash) bool {
_, ok := allowedHashesSet[h]
return ok
}

0 comments on commit c664aa9

Please sign in to comment.