Tcl
Tcl
Verify a CAdES-BES Signature and Examine Signature Contents
See more Digital Signatures Examples
Demonstrates how to validate a .p7m (.p7s) signature and examine the contents of the signature.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set crypt [new_CkCrypt2]
set outputFile "qa_output/original.xml"
set inFile "qa_data/p7m/fattura_signature.xml.p7m"
# Verify the signature and extract the contained file, which in this case is XML.
set success [CkCrypt2_VerifyP7M $crypt $inFile $outputFile]
if {$success == 0} then {
puts [CkCrypt2_lastErrorText $crypt]
delete_CkCrypt2 $crypt
exit
}
puts "Signature validated."
# Now let's examine the information about the signature.
set json [new_CkJsonObject]
CkCrypt2_GetLastJsonData $crypt $json
CkJsonObject_put_EmitCompact $json 0
puts [CkJsonObject_emit $json]
# Here's an example of the information about the signature:
# {
# "pkcs7": {
# "verify": {
# "certs": [
# {
# "issuerCN": "Xyz EU Qualified Certificates CA G1",
# "serial": "99A28A51AC389999"
# }
# ],
# "useConstructedOctets": true,
# "digestAlgorithms": [
# "sha256"
# ],
# "signerInfo": [
# {
# "cert": {
# "subjectKeyIdentifier": "5VM4x8AWnXf07yzbXuLtbb0U3yY=",
# "digestAlgOid": "2.16.840.1.101.3.4.2.1",
# "digestAlgName": "SHA256"
# },
# "signingAlgOid": "1.2.840.113549.1.1.11",
# "signingAlgName": "RSA-SHA256-PKCSV-1_5",
# "authAttr": {
# "1.2.840.113549.1.9.3": {
# "name": "contentType",
# "oid": "1.2.840.113549.1.7.1"
# },
# "1.2.840.113549.1.9.5": {
# "name": "signingTime",
# "utctime": "190901152340Z"
# },
# "1.2.840.113549.1.9.4": {
# "name": "messageDigest",
# "digest": "y+gd/zAQK33A//HInhaZba7w1fUJleV9AHbP1Ntx6U0="
# },
# "1.2.840.113549.1.9.16.2.47": {
# "name": "signingCertificateV2",
# "der": "MIH4MI..w4vv0="
# }
# }
# }
# ]
# }
# }
# }
# Use this online tool to generate parsing code from sample JSON:
# Generate Parsing Code from JSON
set authAttrSigningTimeUtctime [new_CkDtObj]
set i 0
set count_i [CkJsonObject_SizeOfArray $json "pkcs7.verify.certs"]
while {$i < $count_i} {
CkJsonObject_put_I $json $i
set issuerCN [CkJsonObject_stringOf $json "pkcs7.verify.certs[i].issuerCN"]
set serial [CkJsonObject_stringOf $json "pkcs7.verify.certs[i].serial"]
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $json "pkcs7.verify.digestAlgorithms"]
while {$i < $count_i} {
CkJsonObject_put_I $json $i
set strVal [CkJsonObject_stringOf $json "pkcs7.verify.digestAlgorithms[i]"]
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $json "pkcs7.verify.signerInfo"]
while {$i < $count_i} {
CkJsonObject_put_I $json $i
set certSubjectKeyIdentifier [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].cert.subjectKeyIdentifier"]
set certDigestAlgOid [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].cert.digestAlgOid"]
set certDigestAlgName [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].cert.digestAlgName"]
set signingAlgOid [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].signingAlgOid"]
set signingAlgName [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].signingAlgName"]
set authAttrContentTypeName [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].authAttr.\"1.2.840.113549.1.9.3\".name"]
set authAttrContentTypeOid [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].authAttr.\"1.2.840.113549.1.9.3\".oid"]
set authAttrSigningTimeName [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].authAttr.\"1.2.840.113549.1.9.5\".name"]
CkJsonObject_DtOf $json "pkcs7.verify.signerInfo[i].authAttr.\"1.2.840.113549.1.9.5\".utctime" 0 $authAttrSigningTimeUtctime
set authAttrMessageDigestName [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].authAttr.\"1.2.840.113549.1.9.4\".name"]
set authAttrMessageDigestDigest [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].authAttr.\"1.2.840.113549.1.9.4\".digest"]
set authAttrSigningCertificateV2Name [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].authAttr.\"1.2.840.113549.1.9.16.2.47\".name"]
set authAttrSigningCertificateV2Der [CkJsonObject_stringOf $json "pkcs7.verify.signerInfo[i].authAttr.\"1.2.840.113549.1.9.16.2.47\".der"]
set i [expr $i + 1]
}
delete_CkCrypt2 $crypt
delete_CkJsonObject $json
delete_CkDtObj $authAttrSigningTimeUtctime