Check hash with the given algorithm

This commit is contained in:
Paul van Brouwershaven
2025-03-10 16:54:56 +01:00
parent 540ffbbec8
commit 52e3fa5072

View File

@@ -2,7 +2,6 @@ package verify
import ( import (
"bytes" "bytes"
"crypto"
"crypto/x509" "crypto/x509"
"encoding/asn1" "encoding/asn1"
"fmt" "fmt"
@@ -175,8 +174,9 @@ func Reader(file io.ReaderAt, size int64) (apiResp *Response, err error) {
apiResp.Error = fmt.Sprintln("Failed to parse timestamp", err) apiResp.Error = fmt.Sprintln("Failed to parse timestamp", err)
} else { } else {
r := bytes.NewReader(s.EncryptedDigest) r := bytes.NewReader(s.EncryptedDigest)
h := crypto.SHA256.New()
b := make([]byte, 32) h := signer.TimeStamp.HashAlgorithm.New()
b := make([]byte, h.Size())
for { for {
n, err := r.Read(b) n, err := r.Read(b)
if err == io.EOF { if err == io.EOF {
@@ -187,7 +187,7 @@ func Reader(file io.ReaderAt, size int64) (apiResp *Response, err error) {
} }
if !bytes.Equal(h.Sum(nil), signer.TimeStamp.HashedMessage) { if !bytes.Equal(h.Sum(nil), signer.TimeStamp.HashedMessage) {
apiResp.Error = fmt.Sprintln("Hash in timestamp is different from pkcs7") apiResp.Error = fmt.Sprintln("Timestamp hash does not match")
} }
break break