feat(签名验签): 优化签名验签

This commit is contained in:
2026-07-10 20:39:28 +08:00
parent 19fadab4ad
commit 4cc24722c2
2 changed files with 15 additions and 37 deletions
-35
View File
@@ -202,13 +202,6 @@ func cleanFontName(name string) string {
return strings.ToLower(name)
}
// matchFontPatternRank 获取字体文件匹配等级
// 入参: pattern 匹配模式, name 字体文件名
// 返回: int 匹配等级
func matchFontPatternRank(pattern, name string) int {
return newFontPatternMatcher(pattern).rank(name)
}
type fontFileCandidate struct {
name string
base string
@@ -426,13 +419,6 @@ func fontFileStyleRank(suffix string, bold, italic bool) int {
return rank
}
// fontFileStyle 获取字体文件样式
// 入参: pattern 匹配模式, name 字体文件名
// 返回: bool 是否粗体, bool 是否斜体
func fontFileStyle(pattern, name string) (bool, bool) {
return fontFileStyleFromSuffix(fontFileStyleSuffix(pattern, name))
}
// fontFileStyleFromSuffix 获取样式后缀对应的字体样式
// 入参: suffix 样式后缀
// 返回: bool 是否粗体, bool 是否斜体
@@ -480,27 +466,6 @@ func fontFileKnownStyleSuffix(suffix string) bool {
}
}
// fontFileStyleSuffix 获取字体文件样式后缀
// 入参: pattern 匹配模式, name 字体文件名
// 返回: string 样式后缀
func fontFileStyleSuffix(pattern, name string) string {
key := fontNormalizeName(name)
stem := fontPatternStem(pattern)
if stem == "" || key == "" {
return ""
}
if strings.HasPrefix(key, stem) {
return strings.TrimPrefix(key, stem)
}
for _, alias := range fontExactCandidateNames(stem) {
alias = fontNormalizeName(alias)
if alias != "" && strings.HasPrefix(key, alias) {
return strings.TrimPrefix(key, alias)
}
}
return ""
}
// fontMemFile 内存字体文件
type fontMemFile struct {
*bytes.Reader
+15 -2
View File
@@ -37,6 +37,7 @@ import (
)
// SignatureVerifyReport 签名验证报告
// Valid表示签名完整性及调用方指定的证书策略均通过
type SignatureVerifyReport struct {
ID string
BaseLoc string
@@ -67,6 +68,18 @@ type SignatureVerifyReport struct {
Error string
}
// IntegrityValid 判断签名完整性是否有效
// 返回: bool 是否有效
func (report SignatureVerifyReport) IntegrityValid() bool {
return report.Error == "" && report.DigestOK && report.DataHashOK && report.SignedValueOK && report.SealOK && report.SealMatchOK && report.CertOK
}
// TrustedValid 判断签名是否可信有效
// 返回: bool 签名完整性、证书信任及证书有效期是否均验证通过
func (report SignatureVerifyReport) TrustedValid() bool {
return report.IntegrityValid() && report.CertTrustChecked && report.CertTrustOK && report.CertTimeChecked && report.CertTimeOK
}
// SignatureCertInfo 签名证书信息
type SignatureCertInfo struct {
Subject string
@@ -267,7 +280,7 @@ func (r *Reader) verifySignature(sigListPath string, sigRef Signature, options *
report.SignCert = result.CertInfo
report.Signer = result.CertInfo.CommonName
report.applySignatureCertificatePolicy(options, result.SignerCerts, result.Certs)
report.Valid = report.DigestOK && report.DataHashOK && report.SignedValueOK && report.CertOK && report.certificatePolicyOK()
report.Valid = report.IntegrityValid() && report.certificatePolicyOK()
return report
case "", SignTypeSeal:
default:
@@ -299,7 +312,7 @@ func (r *Reader) verifySignature(sigListPath string, sigRef Signature, options *
}
report.SealMatchOK = bytes.Equal(sealData, sesResult.SealRaw)
}
report.Valid = report.DigestOK && report.DataHashOK && report.SignedValueOK && report.SealOK && report.SealMatchOK && report.CertOK && report.certificatePolicyOK()
report.Valid = report.IntegrityValid() && report.certificatePolicyOK()
return report
}