mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
Compare commits
2
Commits
19fadab4ad
...
5b0da8f06b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b0da8f06b | ||
|
|
4cc24722c2 |
@@ -1668,7 +1668,7 @@ function renderSignatures() {
|
||||
const fragment = document.createDocumentFragment();
|
||||
for (const signature of signatures) {
|
||||
const row = document.createElement("div");
|
||||
row.className = `signature-row ${signature.valid ? "valid" : "invalid"}`;
|
||||
row.className = `signature-row ${signature.integrityValid ? "valid" : "invalid"}`;
|
||||
|
||||
const head = document.createElement("div");
|
||||
head.className = "signature-head";
|
||||
@@ -1677,7 +1677,7 @@ function renderSignatures() {
|
||||
|
||||
const badges = document.createElement("div");
|
||||
badges.className = "signature-badges";
|
||||
badges.append(fontBadge(signature.valid ? "有效" : "无效", signature.valid ? "valid" : "invalid"));
|
||||
badges.append(fontBadge(signature.integrityValid ? "完整" : "异常", signature.integrityValid ? "valid" : "invalid"));
|
||||
|
||||
head.append(name, badges);
|
||||
row.append(head);
|
||||
@@ -1713,7 +1713,7 @@ function signatureSummary(signatures) {
|
||||
if (!signatures.length) {
|
||||
return "0";
|
||||
}
|
||||
const invalid = signatures.filter((signature) => !signature.valid).length;
|
||||
const invalid = signatures.filter((signature) => !signature.integrityValid).length;
|
||||
if (invalid) {
|
||||
return `${signatures.length} · 异常 ${invalid}`;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ type FontInfo = ofdgo.FontInfo
|
||||
type SignatureInfo struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Valid bool `json:"valid"`
|
||||
IntegrityValid bool `json:"integrityValid"`
|
||||
Version string `json:"version,omitempty"`
|
||||
SealType string `json:"sealType,omitempty"`
|
||||
Signer string `json:"signer,omitempty"`
|
||||
@@ -346,7 +346,7 @@ func signatureInfo(report ofdgo.SignatureVerifyReport) SignatureInfo {
|
||||
return SignatureInfo{
|
||||
ID: report.ID,
|
||||
Type: string(report.Type),
|
||||
Valid: report.Valid,
|
||||
IntegrityValid: report.IntegrityValid(),
|
||||
Version: report.Provider.Version,
|
||||
SealType: report.SealType,
|
||||
Signer: signatureSigner(report),
|
||||
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user