Tcl
Tcl
Examine KeyInfo Certificate in XML Signature
See more XML Digital Signatures Examples
This example loads signed XML and gets the signing certificate, assuming the certificate is contained in X509Certificate within the KeyInfo.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 dsig [new_CkXmlDSig]
set sbXml [new_CkStringBuilder]
set success [CkStringBuilder_LoadFile $sbXml "c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml" "utf-8"]
if {$success != 1} then {
puts "Failed to load XML file."
delete_CkXmlDSig $dsig
delete_CkStringBuilder $sbXml
exit
}
set success [CkXmlDSig_LoadSignatureSb $dsig $sbXml]
if {$success != 1} then {
puts [CkXmlDSig_lastErrorText $dsig]
delete_CkXmlDSig $dsig
delete_CkStringBuilder $sbXml
exit
}
# Get the KeyInfo XML.
# xmlKeyInfo is a CkXml
set xmlKeyInfo [CkXmlDSig_GetKeyInfo $dsig]
if {[CkXmlDSig_get_LastMethodSuccess $dsig] != 1} then {
puts [CkXmlDSig_lastErrorText $dsig]
delete_CkXmlDSig $dsig
delete_CkStringBuilder $sbXml
exit
}
puts [CkXml_getXml $xmlKeyInfo]
puts "----"
# Assuming the X509Certificate is in the KeyInfo, it will look like this:
# <ds:KeyInfo Id="...">
# <ds:KeyValue>
# ...
# <ds:X509Data>
# <ds:X509Certificate>MIIHAz...</ds:X509Certificate>
# </ds:X509Data>
# </ds:KeyInfo>
set certBase64 [CkXml_getChildContent $xmlKeyInfo "*:X509Data|*:X509Certificate"]
if {[CkXml_get_LastMethodSuccess $xmlKeyInfo] != 1} then {
puts "No X509Certificate found in the KeyInfo."
delete_CkXmlDSig $dsig
delete_CkStringBuilder $sbXml
exit
}
# Load a certificate object w/ the base64.
set cert [new_CkCert]
set success [CkCert_LoadFromBase64 $cert $certBase64]
if {$success != 1} then {
puts [CkCert_lastErrorText $cert]
delete_CkXmlDSig $dsig
delete_CkStringBuilder $sbXml
delete_CkCert $cert
exit
}
# Examine the cert..
puts "SubjectDN: [CkCert_subjectDN $cert]"
puts "IssuerDN: [CkCert_issuerDN $cert]"
puts "SerialNumber as Decimal: [CkCert_serialDecimal $cert]"
delete_CkXml $xmlKeyInfo
delete_CkXmlDSig $dsig
delete_CkStringBuilder $sbXml
delete_CkCert $cert