XmlDSig C Reference Documentation

XmlDSig

Current Version: 9.5.0.97

An API for validating XML Digital Signatures. Use the XmlDSigGen class for creating XML Digital Signatures.

Create/Dispose

HCkXmlDSig instance = CkXmlDSig_Create();
// ...
CkXmlDSig_Dispose(instance);
HCkXmlDSig CkXmlDSig_Create(void);

Creates an instance of the HCkXmlDSig object and returns a handle ("void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.

void CkXmlDSig_Dispose(HCkXmlDSig handle);

Objects created by calling CkXmlDSig_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkXmlDSig_Dispose.

Properties

DebugLogFilePath
void CkXmlDSig_getDebugLogFilePath(HCkXmlDSig cHandle, HCkString retval);
void CkXmlDSig_putDebugLogFilePath(HCkXmlDSig cHandle, const char *newVal);
const char *CkXmlDSig_debugLogFilePath(HCkXmlDSig cHandle);

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

top
ExternalRefDirs
void CkXmlDSig_getExternalRefDirs(HCkXmlDSig cHandle, HCkString retval);
void CkXmlDSig_putExternalRefDirs(HCkXmlDSig cHandle, const char *newVal);
const char *CkXmlDSig_externalRefDirs(HCkXmlDSig cHandle);
Introduced in version 9.5.0.77

May contain a set of directory paths specifying where referenced external files are located. Directory paths should be separated using a semicolon character. The default value of this property is the empty string which means no directories are automatically searched.

This property can be used if the external file referenced in the XML signature has the same filename as the file in the local filesystem.

More Information and Examples
top
IgnoreExternalRefs
BOOL CkXmlDSig_getIgnoreExternalRefs(HCkXmlDSig cHandle);
void CkXmlDSig_putIgnoreExternalRefs(HCkXmlDSig cHandle, BOOL newVal);
Introduced in version 9.5.0.77

If TRUE, then ignore failures caused by external references not being available. This allows for the XML signature to be at least partially validated if the external referenced files are not available. The default value of this property is FALSE.

top
LastErrorHtml
void CkXmlDSig_getLastErrorHtml(HCkXmlDSig cHandle, HCkString retval);
const char *CkXmlDSig_lastErrorHtml(HCkXmlDSig cHandle);

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastErrorText
void CkXmlDSig_getLastErrorText(HCkXmlDSig cHandle, HCkString retval);
const char *CkXmlDSig_lastErrorText(HCkXmlDSig cHandle);

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastErrorXml
void CkXmlDSig_getLastErrorXml(HCkXmlDSig cHandle, HCkString retval);
const char *CkXmlDSig_lastErrorXml(HCkXmlDSig cHandle);

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastMethodSuccess
BOOL CkXmlDSig_getLastMethodSuccess(HCkXmlDSig cHandle);
void CkXmlDSig_putLastMethodSuccess(HCkXmlDSig cHandle, BOOL newVal);

Indicate whether the last method call succeeded or failed. A value of TRUE indicates success, a value of FALSE indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = TRUE and failure = FALSE.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to TRUE. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

top
NumReferences
int CkXmlDSig_getNumReferences(HCkXmlDSig cHandle);
Introduced in version 9.5.0.69

The number of data objects referenced in the XML digital signature. A data object may be self-contained within the loaded XML signature, or it may be an external URI reference. An application can check each reference to see if it's external by calling IsReferenceExternal, and can get each reference URI by calling ReferenceUri.

top
NumSignatures
int CkXmlDSig_getNumSignatures(HCkXmlDSig cHandle);
Introduced in version 9.5.0.69

The number of digital signatures found within the loaded XML. Each digital signature is composed of XML having the following structure:

  <Signature ID?> 
     <SignedInfo>
       <CanonicalizationMethod/>
       <SignatureMethod/>
       (<Reference URI? >
         (<Transforms>)?
         <DigestMethod>
         <DigestValue>
       </Reference>)+
     </SignedInfo>
     <SignatureValue> 
    (<KeyInfo>)?
    (<Object ID?>)*
 </Signature>
Note: The "Signature" and other XML tags may be namespace prefixed.

The Selector property is used to select which XML signature is in effect when validating or calling other methods or properties.

More Information and Examples
top
RefFailReason
int CkXmlDSig_getRefFailReason(HCkXmlDSig cHandle);
Introduced in version 9.5.0.77

Indicates the failure reason for the last call to VerifyReferenceDigest. Possible values are:

  • 0: No failure, the reference digest was valid.
  • 1: The computed digest differs from the digest stored in the XML.
  • 2: An external file is referenced, but it is unavailable for computing the digest.
  • 3: The index argument passed to VerifyReferenceDigest was out of range.
  • 4: Unable to find the Signature.
  • 5: A transformation specified some sort of XML canonicalization that is not supported.
  • 99: Unknown. (Should never get this value.)

top
Selector
int CkXmlDSig_getSelector(HCkXmlDSig cHandle);
void CkXmlDSig_putSelector(HCkXmlDSig cHandle, int newVal);
Introduced in version 9.5.0.69

If the loaded XML contains multiple signatures, this property can be set to specify which signature is in effect when calling other methods or properties. In most cases, the loaded XML contains a single signature and this property will remain at the default value of 0.

More Information and Examples
top
UncommonOptions
void CkXmlDSig_getUncommonOptions(HCkXmlDSig cHandle, HCkString retval);
void CkXmlDSig_putUncommonOptions(HCkXmlDSig cHandle, const char *newVal);
const char *CkXmlDSig_uncommonOptions(HCkXmlDSig cHandle);
Introduced in version 9.5.0.90

This is a catch-all property to be used for uncommon needs. This property defaults to the empty string, and should typically remain empty.

top
Utf8
BOOL CkXmlDSig_getUtf8(HCkXmlDSig cHandle);
void CkXmlDSig_putUtf8(HCkXmlDSig cHandle, BOOL newVal);

When set to TRUE, all "const char *" arguments are interpreted as utf-8 strings. If set to FALSE (the default), then "const char *" arguments are interpreted as ANSI strings. Also, when set to TRUE, and Chilkat method returning a "const char *" is returning the utf-8 representation. If set to FALSE, all "const char *" return values are ANSI strings.

top
VerboseLogging
BOOL CkXmlDSig_getVerboseLogging(HCkXmlDSig cHandle);
void CkXmlDSig_putVerboseLogging(HCkXmlDSig cHandle, BOOL newVal);

If set to TRUE, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is FALSE. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
void CkXmlDSig_getVersion(HCkXmlDSig cHandle, HCkString retval);
const char *CkXmlDSig_version(HCkXmlDSig cHandle);

Version of the component/library, such as "9.5.0.94"

More Information and Examples
top

Methods

AddEncapsulatedTimeStamp
BOOL CkXmlDSig_AddEncapsulatedTimeStamp(HCkXmlDSig cHandle, HCkJsonObject json, HCkStringBuilder sbOut);
Introduced in version 9.5.0.90

Adds an EncapsulatedTimeStamp to the signature indicated by the Selector property. The updated signed XML with the added EncapsulatedTimeStamp is returned in sbOut. See the example below for details.

Returns TRUE for success, FALSE for failure.

top
CanonicalizeFragment
BOOL CkXmlDSig_CanonicalizeFragment(HCkXmlDSig cHandle, const char *xml, const char *fragmentId, const char *version, const char *prefixList, BOOL withComments, HCkString outStr);
const char *CkXmlDSig_canonicalizeFragment(HCkXmlDSig cHandle, const char *xml, const char *fragmentId, const char *version, const char *prefixList, BOOL withComments);

Applies XML canonicalization to a fragment of the passed-in XML, and returns the canonicalized XML string. The fragmentId identifies the XML element where output begins. It is the XML element having an "id" attribute equal to fragmentId. The version may be one of the following:

  • "C14N" -- for Inclusive Canonical XML
  • "EXCL_C14N" -- for Exclusive Canonical XML

The prefixList only applies when the version is set to "EXCL_C14N". The prefixList may be an empty string, or a SPACE separated list of namespace prefixes. It is the InclusiveNamespaces PrefixList, which is the list of namespaces that are propagated from ancestor elements for canonicalization purposes.

If withComments is TRUE, then XML comments are included in the output. If withComments is FALSE, then XML comments are excluded from the output.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
CanonicalizeXml
BOOL CkXmlDSig_CanonicalizeXml(HCkXmlDSig cHandle, const char *xml, const char *version, BOOL withComments, HCkString outStr);
const char *CkXmlDSig_canonicalizeXml(HCkXmlDSig cHandle, const char *xml, const char *version, BOOL withComments);

Applies XML canonicalization to the passed-in XML, and returns the canonicalized XML string. The version may be one of the following:

  • "C14N" -- for Inclusive Canonical XML
  • "EXCL_C14N" -- for Exclusive Canonical XML

If withComments is TRUE, then XML comments are included in the output. If withComments is FALSE, then XML comments are excluded from the output.

Returns TRUE for success, FALSE for failure.

top
GetCerts
BOOL CkXmlDSig_GetCerts(HCkXmlDSig cHandle, HCkStringArray sa);
Introduced in version 9.5.0.76

Returns the certificates found in the signature indicated by the Selector property. The base64 representation of each certificate is returned.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
GetKeyInfo
HCkXml CkXmlDSig_GetKeyInfo(HCkXmlDSig cHandle);
Introduced in version 9.5.0.69

Returns the KeyInfo XML for the signature indicated by the Selector property. Returns NULL if no KeyInfo exists.

Returns NULL on failure

More Information and Examples
top
GetPublicKey
HCkPublicKey CkXmlDSig_GetPublicKey(HCkXmlDSig cHandle);
Introduced in version 9.5.0.69

Returns the public key from the KeyInfo XML for the signature indicated by the Selector property. Returns NULL if no KeyInfo exists, or if no public key is actually contained in the KeyInfo.

Returns NULL on failure

top
HasEncapsulatedTimeStamp
BOOL CkXmlDSig_HasEncapsulatedTimeStamp(HCkXmlDSig cHandle);
Introduced in version 9.5.0.90

Returns TRUE if the signature indicated by the Selector property contains an EncapsulatedTimeStamp. Otherwise returns FALSE.

top
IsReferenceExternal
BOOL CkXmlDSig_IsReferenceExternal(HCkXmlDSig cHandle, int index);
Introduced in version 9.5.0.69

Returns TRUE if the reference at index is external. Each external reference would first need to be provided by the application prior to validating the signature.

top
LoadSignature
BOOL CkXmlDSig_LoadSignature(HCkXmlDSig cHandle, const char *xmlSig);
Introduced in version 9.5.0.69

Loads an XML document containing 1 or more XML digital signatures. An application would first load XML containing digital signature(s), then validate. After loading, it is also possible to use various methods and properties to get information about the signature, such as the key info, references, etc. If external data is referenced by the signature, it may be necessary to provide the referenced data prior to validating.

Note: When loading an XML document, the Selector property is automatically reset to 0, and the NumSignatures property is set to the number of XML digital signatures found.

Returns TRUE for success, FALSE for failure.

top
LoadSignatureBd
BOOL CkXmlDSig_LoadSignatureBd(HCkXmlDSig cHandle, HCkBinData binData);
Introduced in version 9.5.0.69

Loads an XML document containing one or more XML digital signatures from the contents of a BinData object. An application would first load the XML, then validate. After loading, it is also possible to use various methods and properties to get information about the signature, such as the key info, references, etc. If external data is referenced by the signature, it may be necessary to provide the referenced data prior to validating.

Note: When loading an XML document, the Selector property is automatically reset to 0, and the NumSignatures property is set to the number of XML digital signatures found.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
LoadSignatureSb
BOOL CkXmlDSig_LoadSignatureSb(HCkXmlDSig cHandle, HCkStringBuilder sbXmlSig);
Introduced in version 9.5.0.69

Loads an XML document containing one or more XML digital signatures from the contents of a StringBuilder object. An application would first load the XML, then validate. After loading, it is also possible to use various methods and properties to get information about the signature, such as the key info, references, etc. If external data is referenced by the signature, it may be necessary to provide the referenced data prior to validating.

Note: When loading an XML document, the Selector property is automatically reset to 0, and the NumSignatures property is set to the number of XML digital signatures found.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
ReferenceUri
BOOL CkXmlDSig_ReferenceUri(HCkXmlDSig cHandle, int index, HCkString outStr);
const char *CkXmlDSig_referenceUri(HCkXmlDSig cHandle, int index);
Introduced in version 9.5.0.69

Returns the URI of the Nth reference specified by index. (The 1st reference is at index 0.) URI's beginning with a pound sign ('#') are internal references.

Returns TRUE for success, FALSE for failure.

top
SetHmacKey
BOOL CkXmlDSig_SetHmacKey(HCkXmlDSig cHandle, const char *key, const char *encoding);
Introduced in version 9.5.0.69

Sets the HMAC key to be used if the Signature used an HMAC signing algorithm. The encoding specifies the encoding of key, and can be "hex", "base64", "ascii", or any of the binary encodings supported by Chilkat in the link below.

Returns TRUE for success, FALSE for failure.

top
SetHttpObj
void CkXmlDSig_SetHttpObj(HCkXmlDSig cHandle, HCkHttp http);
Introduced in version 9.5.0.90

Sets the HTTP object to be used to communicate with OCSP responders, CRL distribution points, or timestamp authority (TSA) servers if needed. The http is used to send the requests, and it allows for connection related settings and timeouts to be set. For example, if HTTP or SOCKS proxies are required, these features can be specified on the http.

top
SetPublicKey
BOOL CkXmlDSig_SetPublicKey(HCkXmlDSig cHandle, HCkPublicKey pubKey);
Introduced in version 9.5.0.69

Sets the public key to be used for verifying the signature indicated by the Selector property. A public key only needs to be explicitly provided by the application for those XML signatures where the public key is not already available within the KeyInfo of the Signature. In some cases, the KeyInfo within the Signature contains information about what public key was used for signing. The application can use this information to retrieve the matching public key and provide it via this method.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
SetRefDataBd
BOOL CkXmlDSig_SetRefDataBd(HCkXmlDSig cHandle, int index, HCkBinData binData);
Introduced in version 9.5.0.69

Provides the binary data for the external reference at index.

top
SetRefDataFile
BOOL CkXmlDSig_SetRefDataFile(HCkXmlDSig cHandle, int index, const char *path);
Introduced in version 9.5.0.69

Provides the data for the external reference at index. When validating the signature, the data contained in path will be streamed to compute the digest for validation.

top
SetRefDataSb
BOOL CkXmlDSig_SetRefDataSb(HCkXmlDSig cHandle, int index, HCkStringBuilder sb, const char *charset);
Introduced in version 9.5.0.69

Provides the text data for the external reference at index. The charset specifies the byte representation of the text, such as "utf-8", "utf-16", "windows-1252", etc. (If in doubt, try utf-8 first.)

top
UseCertVault
BOOL CkXmlDSig_UseCertVault(HCkXmlDSig cHandle, HCkXmlCertVault certVault);
Introduced in version 9.5.0.69

Adds an XML certificate vault to the object's internal list of sources to be searched for certificates having public keys when verifying an XML signature. A single XML certificate vault may be used. If UseCertVault is called multiple times, only the last certificate vault will be used, as each call to UseCertVault will replace the certificate vault provided in previous calls.

Returns TRUE for success, FALSE for failure.

top
VerifyReferenceDigest
BOOL CkXmlDSig_VerifyReferenceDigest(HCkXmlDSig cHandle, int index);
Introduced in version 9.5.0.69

This method allows for an application to verify the digest for each reference separately. This can be helpful if the full XMLDSIG validation fails, then one can test each referenced data's digest to see which, if any, fail to match.

top
VerifySignature
BOOL CkXmlDSig_VerifySignature(HCkXmlDSig cHandle, BOOL verifyReferenceDigests);
Introduced in version 9.5.0.69

Verifies the signature indicated by the Selector property. If verifyReferenceDigests is TRUE, then the digest of each Reference within the signature's SignedInfo is also validated.

Returns TRUE for success, FALSE for failure.

top