function ValidatePades: TPadesValidationResult;
從原始載入的位元組剖析內嵌簽章字典,檢查其結構是否符合 PAdES baseline,並將簽章位移與用於目錄與 DSS 查閱的展開物件串流檢視分開處理
必要的簽章項目只在最上層字典計數,因此重複的 Contents、ByteRange、SubFilter、Filter 或 Type 鍵無法藉由剖析器挑選的值隱藏,而巢狀字典與陣列中的同名鍵則保持獨立
簽章探索採用線性詞彙掃描,略過串流主體、字串、十六進位值與註解,解碼 #xx 名稱跳脫,且不受巢狀字典出現在簽章項目之前或之後的影響
被排除的 /ByteRange 間距必須等於完整的直接十六進位 /Contents 語彙單元(含其分隔符),且每個被涵蓋的修訂版都必須結束於完整的 PDF 修訂邊界
在 Windows 上,一般的分離式 CMS 簽章會直接對照兩段原始 /ByteRange 區段進行驗證,包括 CMS 簽章屬性、密碼學簽章值,以及 SHA-256 signing-certificate-v2 繫結
每個簽署者還會取得從 CMS 與 X.509 識別碼剖析的演算法設定檔,並依 ISO/TS 32002 檢查支援的 NIST 與 Brainpool 曲線、Ed25519、Ed448、摘要一致性、具名曲線參數與 SHAKE256 輸出長度
Active 為 TrueTPadesValidationResult 記錄,詳述達到的 PAdES 符合等級(B-B、B-T、B-LT、B-LTA)與偵測到的驗證問題集合TPdf.ValidatePadesTrust 及其 TimeStampStatus、CmsSignatureStatus 與 CertificateTrustStatus 值確認TPadesValidationResult.Issues 集合可包含下列任一 TPadesValidationIssue 值,按主題分組;簽章存在性與字典基數:ppeiNoSignature(找不到帶 /ByteRange 的簽章字典)、ppeiDuplicateContents(/Contents 鍵重複)、ppeiDuplicateByteRange(/ByteRange 鍵重複)、ppeiDuplicateSubFilter(/SubFilter 鍵重複)、ppeiDuplicateFilter(/Filter 鍵重複)、ppeiDuplicateSignatureType(/Type 鍵重複)、ppeiMissingFilter(缺少 /Filter)、ppeiBadFilter(/Filter 沒有有效的名稱值)、ppeiBadSignatureType(一般簽章的 /Type 不是 Sig)、ppeiBadDtsType(Document Time-stamp 的 /Type 不是 DocTimeStamp);子篩選器與位元組範圍:ppeiBadSubFilter(/SubFilter 不是公認的 PAdES 子篩選器)、ppeiForbiddenSubFilter(舊式 adbe.pkcs7.sha1 或 adbe.x509.rsa_sha1)、ppeiMissingByteRange(缺少 /ByteRange)、ppeiBadByteRangeShape(不是恰好四個整數的 [0 a b c])、ppeiByteRangeNotCoveringFile(未涵蓋扣除 /Contents 之外的整個檔案);分離內容:ppeiMissingContents(缺少 /Contents 或長度為零)、ppeiBadContentsShape(不是 DER CMS SignedData 或 RFC3161 TimeStampToken)、ppeiZeroPaddedContents(全部為零位元組)、ppeiForbiddenCertKey(存在 /Cert);CMS SignedData 結構:ppeiNotSignedData(頂層 SEQUENCE 未包覆 id-signedData)、ppeiBadSignedDataVersion(version 欄位缺少或超出範圍)、ppeiSingleSignerViolation(signerInfos 不是恰好一個 SignerInfo)、ppeiDetachedContentViolation(存在 encapContentInfo.eContent);已簽署屬性與演算法:ppeiMissingContentType(缺少 content-type 已簽署屬性)、ppeiMissingMessageDigest(缺少 message-digest 已簽署屬性)、ppeiMissingSigningCertificate(signing-certificate 與 signing-certificate-v2 皆無)、ppeiBadDigestAlgorithm(以 MD5 或 SHA-1 做為摘要)、ppeiSignatureAlgorithmMismatch(橢圓曲線、摘要或 AlgorithmIdentifier 不相符);承諾與信任:ppeiReasonCommitmentConflict(/Reason 與 commitment-type-indication 並存)、ppeiMissingTrustedTime(保留欄位:B-T 由時間戳記是否存在推得,所以沒有時間戳記的文件停在 B-B,由 Result.Level 回報這一點,而不是另發一個 issue)、ppeiMissingDss(目錄缺少 /DSS)、ppeiDssMissingCerts(/DSS /Certs 缺少或為空)、ppeiMissingExtensions(目錄缺少 /Extensions /ESIC Level 1 標記);文件時間戳記:ppeiMissingDocTimeStamp(沒有 Document Time-stamp 簽章字典)、ppeiMissingExtensionsL2(缺少 /Extensions /ESIC Level 2 標記)、ppeiBadDtsSubFilter(/DocTimeStamp 字典帶了 ETSI.RFC3161 以外的 /SubFilter)、ppeiForbiddenDtsKey(條款 5.4.3 的 should-not 鍵存在:/Name、/M、/Location、/ContactInfo)、ppeiForbiddenDtsKeyStrict(條款 5.4.3 的 shall-not 鍵存在:/Cert、/Reference、/Changes、/R、/Prop_AuthTime、/Prop_AuthType)、ppeiBadDtsVersion(Document Time-stamp 的 /V 存在且不為 0)、ppeiMissingSigningTime(簽章字典缺少非空的 /M,條款 6.3 Table 1)、ppeiForbiddenCmsSigningTime(CMS 已簽署屬性攜帶被禁的簽章時間屬性)、ppeiMissingSignedDataCertificates(SignedData.certificates 缺少或為空)、ppeiCmsAlgorithmProtectionMismatch(現存的 algorithm-protection 與 SignerInfo 不相符);DSS 與 VRI 結構(條款 5.4.2):ppeiDssStructureMalformed(DSS 陣列元素不是間接參照,或 /VRI 值不是讀取器跟得到的字典)、ppeiDssVriKeyMalformed(/VRI 鍵不是 40 個 base-16 數字,或拼成小寫)、ppeiDssVriKeyUnmatched(/VRI 鍵不符合任何簽章 /Contents 的 SHA-1)、ppeiDssVriEmptyArray(Signature VRI 的 Cert、CRL 或 OCSP 陣列存在但為空)、ppeiDssVriTuTsConflict(Signature VRI 同時攜帶 /TU 與 /TS)、ppeiDssVriArrayNotInDss(Signature VRI 陣列指名了相符文件層級陣列沒列的串流)、ppeiTooManySignatures(文件含超過 32 個簽章字典;只驗證前 32 個,信任驗證會把完整性回報為未定)SourceStatus 為 pvssOriginalBytes;未完成的漸進式來源為 pvssIncomplete;未保留原始位元組時為 pvssUnavailableSourceStatus 為 pvssOriginalBytes,否則 IsCompliant 與 IsCompliantAt 傳回 FalseIntegrityStatus 彙總一般簽章的完整性,而 Signatures 分別回報每個 ByteRange、CMS 簽章、演算法政策、簽署者憑證繫結、系統信任、撤銷與時間戳記狀態AlgorithmInfo 公開摘要、簽章、公鑰與具名曲線 OID,而 AlgorithmPolicyStatus 會區分有效的設定檔、畸形的組合、不支援的曲線或演算法,以及無法取得的憑證證據pcsInvalid;SHA-1 與 SHA-224 這類 112 位元摘要為 pcsIndeterminate,因為它們已不再列入現行驗證的認可範圍;digestAlgorithm 與簽章演算法固定的摘要不一致,或 RSA 演算法用在非 RSA 金鑰上,為 pcsInvalid 並引發 ppeiSignatureAlgorithmMismatchid-shake256-lenppeiSignatureAlgorithmMismatchIsCryptographicallyValid 才傳回 TrueCertificateTrustStatus 使用僅限快取的 Windows 系統信任評估;在執行那些獨立檢查之前,RevocationStatus 與 TimeStampStatus 維持 pcsNotChecked 或 pcsUnsupported%%EOF 結尾的較早完整修訂版;後續的漸進式 DSS、時間戳記或簽章修訂版不會使較早的範圍在結構上失效Filter 必須恰好出現一次且帶有名稱值;選用的一般簽章 Type 必須是 Sig,而文件時間戳記則需要恰好一個 Type /DocTimeStamp 與 SubFilter /ETSI.RFC3161Contents 值、額外的排除位元組,或不一致的簽章型別與子篩選器值,都會阻止晉升至 PAdES B-BplUnknown;plNone 保留給未偵測到任何簽章字典的文件pcsUnsupported,而不是從結構檢查推斷
var
Res: TPadesValidationResult;
begin
if not Pdf1.Active then Exit;
Res := Pdf1.ValidatePades;
if Res.IsCryptographicallyValid then
ShowMessage('PAdES signature integrity passed');
end;