ソースを参照

add: 添加签名验证

liutian 11 ヶ月 前
コミット
2949e3b281
2 ファイル変更21 行追加15 行削除
  1. 1 1
      packages/core/src/index.js
  2. 20 14
      packages/core/src/worker/compdfkit_worker.js

+ 1 - 1
packages/core/src/index.js

@@ -1073,7 +1073,7 @@ class ComPDFKitViewer {
     }
 
     const signatures = await this.messageHandler.sendWithPromise('GetSignatures', {
-      doc: this.doc
+      doc: this.doc,
     })
 
     this.pdfViewer.pagesPtr = this.pagesPtr

+ 20 - 14
packages/core/src/worker/compdfkit_worker.js

@@ -2381,8 +2381,8 @@ function getWidgetAnnotation({
   return annotation
 }
 
-function getSignatures({
-  doc
+async function getSignatures({
+  doc,
 }) {
   const signatureList = []
   const count = Module._GetSignatureCount(doc)
@@ -2410,25 +2410,31 @@ function getSignatures({
           const signer = {
             signerPtr,
             isSignVerified: false,
-            isCertValid: false,
+            isCertTrusted: false,
             certificateList
           }
 
           const certPtr = Module._GetSignCert(signerPtr)
 
           console.log('certPtr', certPtr)
-          const result = false
+          let result = false
           if (certPtr) {
             // TODO: 验证证书
-            // result = Module._VerifyGetChain(signerPtr, certPtr, 0, 10000)
-            // if (result === 1) {
-            //   signer.IsCertTrusted = true
-            //   for (let f = 0; f < signer.certificateList.length; f++) {
-            //     signer.certificateList[f].IsTrusted = true
-            //   }
-            // } else {
-            //   needCheck = true
-            // }
+            CertArray = []
+            Module._ExportToFilePath(certPtr, 1)
+            ComPDFKitJS.opened_cert[0] = CertArray[0]
+            result = Module._VerifyGetChain(signerPtr, certPtr, 0, CertArray[0].length)
+            if (result === 1) {
+              signer.isCertTrusted = true
+              for (let f = 0; f < signer.certificateList.length; f++) {
+                signer.certificateList[f].IsTrusted = true
+              }
+            } else {
+              needCheck = true
+            }
+
+            const len = ComPDFKitJS.opened_files[0].length
+            result = Module._VerifyDocument(doc, signaturePtr, 0, len)
 
             CertArray = []
             Module._GetSignCertChain(certPtr)
@@ -2448,7 +2454,7 @@ function getSignatures({
           const timeSpanPtr = Module._GetTimeStampSignature(signerPtr)
           if (timeSpanPtr) {
             // TODO: 验证时间戳
-            // result = Module._VerifyTimestamp(signaturePtr, signerPtr, 0, 10000)
+            // result = Module._VerifyTimestamp(signaturePtr, signerPtr, 0, 0)
             // if (result == 1) {
             //   signer.IsSignVerified = true;
             // } else {