mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
@@ -79,6 +79,7 @@ type sesVerifyResult struct {
|
|||||||
SealCert SignatureCertInfo
|
SealCert SignatureCertInfo
|
||||||
SignCertRaw []byte
|
SignCertRaw []byte
|
||||||
SealCertRaw []byte
|
SealCertRaw []byte
|
||||||
|
SealRaw []byte
|
||||||
Certs [][]byte
|
Certs [][]byte
|
||||||
SealType string
|
SealType string
|
||||||
}
|
}
|
||||||
@@ -193,6 +194,7 @@ func verifySESSignature(data, signedData []byte, options *signatureVerifyOptions
|
|||||||
result.SealCert = signatureCertInfo(sig.Seal.Cert)
|
result.SealCert = signatureCertInfo(sig.Seal.Cert)
|
||||||
result.SignCertRaw = sig.Cert
|
result.SignCertRaw = sig.Cert
|
||||||
result.SealCertRaw = sig.Seal.Cert
|
result.SealCertRaw = sig.Seal.Cert
|
||||||
|
result.SealRaw = sig.Seal.Raw
|
||||||
result.Certs = append(result.Certs, sig.Seal.CertList.Certs...)
|
result.Certs = append(result.Certs, sig.Seal.CertList.Certs...)
|
||||||
result.Certs = append(result.Certs, options.SignCerts...)
|
result.Certs = append(result.Certs, options.SignCerts...)
|
||||||
result.SealType = sig.Seal.PicType
|
result.SealType = sig.Seal.PicType
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ type signatureVerifyOptions struct {
|
|||||||
VerifyTime *time.Time
|
VerifyTime *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var signatureMethodReplacer = strings.NewReplacer("-", "", "_", "", " ", "")
|
||||||
|
|
||||||
// SignatureVerifyOption 签名验证选项函数
|
// SignatureVerifyOption 签名验证选项函数
|
||||||
type SignatureVerifyOption func(*signatureVerifyOptions)
|
type SignatureVerifyOption func(*signatureVerifyOptions)
|
||||||
|
|
||||||
@@ -295,12 +297,7 @@ func (r *Reader) verifySignature(sigListPath string, sigRef Signature, options *
|
|||||||
report.Error = err.Error()
|
report.Error = err.Error()
|
||||||
return report
|
return report
|
||||||
}
|
}
|
||||||
sig, err := parseSESSignature(signedValue)
|
report.SealMatchOK = bytes.Equal(sealData, sesResult.SealRaw)
|
||||||
if err != nil {
|
|
||||||
report.Error = err.Error()
|
|
||||||
return report
|
|
||||||
}
|
|
||||||
report.SealMatchOK = bytes.Equal(sealData, sig.Seal.Raw)
|
|
||||||
}
|
}
|
||||||
report.Valid = report.DigestOK && report.DataHashOK && report.SignedValueOK && report.SealOK && report.SealMatchOK && report.CertOK && report.certificatePolicyOK()
|
report.Valid = report.DigestOK && report.DataHashOK && report.SignedValueOK && report.SealOK && report.SealMatchOK && report.CertOK && report.certificatePolicyOK()
|
||||||
return report
|
return report
|
||||||
@@ -498,15 +495,14 @@ func isECDSASignatureMethod(method string) bool {
|
|||||||
// 返回: string 规范化算法标识
|
// 返回: string 规范化算法标识
|
||||||
func signatureMethodText(method string) string {
|
func signatureMethodText(method string) string {
|
||||||
method = strings.TrimSpace(method)
|
method = strings.TrimSpace(method)
|
||||||
if strings.HasPrefix(strings.ToLower(method), "urn:oid:") {
|
if len(method) >= len("urn:oid:") && strings.EqualFold(method[:len("urn:oid:")], "urn:oid:") {
|
||||||
method = method[len("urn:oid:"):]
|
method = method[len("urn:oid:"):]
|
||||||
}
|
}
|
||||||
if idx := strings.LastIndexAny(method, "#/"); idx >= 0 && idx+1 < len(method) {
|
if idx := strings.LastIndexAny(method, "#/"); idx >= 0 && idx+1 < len(method) {
|
||||||
method = method[idx+1:]
|
method = method[idx+1:]
|
||||||
}
|
}
|
||||||
method = strings.ToUpper(method)
|
method = strings.ToUpper(method)
|
||||||
method = strings.NewReplacer("-", "", "_", "", " ", "").Replace(method)
|
return signatureMethodReplacer.Replace(method)
|
||||||
return method
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// verifyPublicKeySignature 验证公钥签名
|
// verifyPublicKeySignature 验证公钥签名
|
||||||
|
|||||||
Reference in New Issue
Block a user