ezxmldsig for Node.js - v2.0.0
    Preparing search index...

    Class XMLDSigToken

    An XML token: an enveloping XML digital signature that holds timestamped user data, optionally encrypted. The counterpart of the class XMLDSigToken of the PHP library ezxmldsig: both create and verify the same tokens.

    Get an instance with one of the factories, createXMLToken() to create a token, analyzeXMLToken() to analyze one. An analysis requires a trust anchor (options caCertPath and/or signerCertPath): without it, no token is valid.

    isSignatureValid() checks neither the freshness of the token nor whether it is replayed. Before trusting the data of a received token, the receiver must check that isSignatureValid() returns true, that isOutOfDate(ttl) returns false, and that the identifier returned by getTokenId() has not been accepted before (store it atomically, and refuse the token if it already is).

    Index
    AES128_CBC: "http://www.w3.org/2001/04/xmlenc#aes128-cbc" = alg.AES128_CBC

    AES-128-CBC, without integrity.

    AES128_GCM: "http://www.w3.org/2009/xmlenc11#aes128-gcm" = alg.AES128_GCM

    AES-128-GCM.

    AES192_CBC: "http://www.w3.org/2001/04/xmlenc#aes192-cbc" = alg.AES192_CBC

    AES-192-CBC, without integrity.

    AES192_GCM: "http://www.w3.org/2009/xmlenc11#aes192-gcm" = alg.AES192_GCM

    AES-192-GCM.

    AES256_CBC: "http://www.w3.org/2001/04/xmlenc#aes256-cbc" = alg.AES256_CBC

    AES-256-CBC, without integrity.

    AES256_GCM: "http://www.w3.org/2009/xmlenc11#aes256-gcm" = alg.AES256_GCM

    AES-256-GCM (default).

    C14N: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" = alg.C14N

    Inclusive canonicalization (default).

    C14N_COMMENTS: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" = alg.C14N_COMMENTS

    Inclusive canonicalization, with comments.

    DESYNC_TOLERANCE: 30

    The clock offset (in seconds) allowed by isOutOfDate() for a token whose timestamp is in the future.

    EXC_C14N: "http://www.w3.org/2001/10/xml-exc-c14n#" = alg.EXC_C14N

    Exclusive canonicalization.

    EXC_C14N_COMMENTS: "http://www.w3.org/2001/10/xml-exc-c14n#WithComments" = alg.EXC_C14N_COMMENTS

    Exclusive canonicalization, with comments.

    RIPEMD160: "http://www.w3.org/2001/04/xmlenc#ripemd160" = alg.RIPEMD160

    RIPEMD-160.

    RSA_OAEP_MGF1P: "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" = alg.RSA_OAEP_MGF1P

    RSA-OAEP with MGF1-SHA1 (default key transport).

    RSA_SHA1: "http://www.w3.org/2000/09/xmldsig#rsa-sha1" = alg.RSA_SHA1

    RSA-SHA1.

    RSA_SHA256: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" = alg.RSA_SHA256

    RSA-SHA256 (default).

    RSA_SHA384: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384" = alg.RSA_SHA384

    RSA-SHA384.

    RSA_SHA512: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512" = alg.RSA_SHA512

    RSA-SHA512.

    SHA1: "http://www.w3.org/2000/09/xmldsig#sha1" = alg.SHA1

    SHA-1.

    SHA256: "http://www.w3.org/2001/04/xmlenc#sha256" = alg.SHA256

    SHA-256 (default).

    SHA384: "http://www.w3.org/2001/04/xmldsig-more#sha384" = alg.SHA384

    SHA-384.

    SHA512: "http://www.w3.org/2001/04/xmlenc#sha512" = alg.SHA512

    SHA-512.

    TOKEN_AUDIENCE_NAME: "TokenAudience" = TOKEN_AUDIENCE_NAME

    The name of the node that holds one audience of the token.

    TOKEN_DATA_NAME: "TokenData" = TOKEN_DATA_NAME

    The name of the token data node.

    TOKEN_DEFAULT_TTL: 60

    The default time to live (in seconds) used by isOutOfDate().

    TOKEN_EXPIRY_NAME: "TokenExpiry" = TOKEN_EXPIRY_NAME

    The name of the token expiry node.

    TOKEN_ID_BYTES: 16 = TOKEN_ID_BYTES

    The number of random bytes of the token identifier, written in hexadecimal (see getTokenId()).

    TOKEN_ID_NAME: "TokenId" = TOKEN_ID_NAME

    The name of the token identifier node.

    TOKEN_NAME: "Token" = TOKEN_NAME

    The name of the token node.

    TOKEN_TIMESTAMP_FORMAT: "Y-m-d\\TH:i:s\\Z" = 'Y-m-d\\TH:i:s\\Z'

    The format of the token timestamp, in the notation of PHP (YYYY-MM-DDThh:mm:ssZ, in UTC).

    TOKEN_TIMESTAMP_NAME: "TokenTimestamp" = TOKEN_TIMESTAMP_NAME

    The name of the token timestamp node.

    TRIPLEDES_CBC: "http://www.w3.org/2001/04/xmlenc#tripledes-cbc" = alg.TRIPLEDES_CBC

    Triple DES CBC, without integrity.

    XMLDSIG_NS_PREFIX: "ds" = 'ds'

    The default XMLDSIG namespace prefix used in the XML digital signature.

    • What console.log() and util.inspect() show: the results of the analysis, without the keys.

      Returns object

    • Gets the anomalies detected by the analysis.

      Returns string[]

    • Gets the audiences of a valid token, or null if it names none.

      Returns string[] | null

    • Gets the Distinguished Name of the certificate of the token (see X509Cert.getDN()).

      Returns string | null

    • Gets the X.509 certificate of the token, in PEM format.

      Returns string | null

    • Gets the fields of the issuer of the certificate of the token.

      Returns NameFields | null

    • Gets the fields of the subject of the certificate of the token.

      Returns NameFields | null

    • Gets the date from which the certificate of the token is valid.

      Returns string | null

    • Gets the date until which the certificate of the token is valid.

      Returns string | null

    • Gets the token data. They can only be trusted if isSignatureValid() returns true (and the token is neither out of date nor replayed). Values written empty are not read back, as with the PHP library.

      Returns ReadTokenData | null

    • Gets the error of the analysis, or null.

      Returns string | null

    • Gets the expiry of a valid token (YYYY-MM-DDThh:mm:ssZ, UTC), or null if it has none.

      Returns string | null

    • Gets the XML token in a readable form, for display only: use getXML() to get the token to work with. The signature value, the certificate and the encrypted values are split into lines of 64 characters, and the elements are indented by 2 spaces. The result is the one of getPrettyXML() of the PHP library, whose steps it follows. A token that is not an XML document is returned as it is, one line per line.

      Returns string | null

    • Gets the timestamp of a valid token (YYYY-MM-DDThh:mm:ssZ, UTC).

      Returns string | null

    • Gets the identifier of a valid token: 128 random bits, in 32 lowercase hexadecimal characters, covered by the signature. The library keeps no list of the tokens it analyzed: refuse a token whose identifier you have already accepted, and keep each one at least ttl + DESYNC_TOLERANCE seconds.

      Returns string | null

    • Gets the XML token.

      Returns string | null

    • Indicates whether the certificate of the token is out of date (true without certificate).

      Returns boolean

    • Indicates whether the signing certificate is trusted, according to the trust anchor of the analysis; null if it could not be evaluated.

      Returns boolean | null

    • Indicates whether the token data are encrypted; null if it could not be evaluated.

      Returns boolean | null

    • Indicates whether the digest of the token has been verified and is valid; null if it could not be evaluated.

      Returns boolean | null

    • Indicates whether the token is out of date: its timestamp is more than ttl seconds in the past, or more than DESYNC_TOLERANCE seconds in the future, or it has no valid timestamp, or its expiry, if any, is passed (or could not be read).

      Parameters

      • ttl: number = XMLDSigToken.TOKEN_DEFAULT_TTL

        The time to live (in seconds) allowed for the token.

      Returns boolean

    • Indicates whether the XML token is valid: no error and no anomaly, the digest and the signature verified, the signing certificate trusted (see isCertTrusted()), and the token addressed to the expected audience. Without a trust anchor given to the analysis, it returns false.

      It checks neither the freshness of the token nor whether it is replayed: see isOutOfDate() and getTokenId().

      Returns boolean

    • Indicates whether the signature of the digest has been verified and is valid; null if it could not be evaluated.

      Returns boolean | null

    • Checks that the certificate of the token was issued by the given CA certificate (only this link: see X509Cert.isValidCA()). isSignatureValid() verifies the whole chain against the trust anchor.

      Parameters

      • caCertPath: PemSource

        The CA certificate, in PEM format: the path of its file, or its content.

      Returns boolean

    • Checks that the issuer of the certificate of the token has the given fields. This only compares names, which any certificate can copy: isSignatureValid() verifies the certificate against the trust anchor.

      Parameters

      • expectedIssuerInfo: Record<string, string | string[]>

        The fields the issuer must have, e.g. { O: 'Lothbrok Ltd', OU: 'Shield Wall Dept' }.

      Returns boolean

    • Analyzes an XML token whose data are encrypted, with the private key of the recipient. An unencrypted token can also be analyzed this way.

      The token is only decrypted once its structure, its algorithms, its digest, its signature and the trust in its certificate have been verified, and every failure of the decryption gives the same error, Token decryption failed!.

      Parameters

      • xml: string | Uint8Array<ArrayBufferLike>

        The XML token, as a string or as the bytes of its UTF-8 encoding.

      • cryptKeyPath: PemSource

        The private key of the recipient, in PEM format: the path of its file, or its content.

      • cryptKeyPassword: string | null = null

        The password of this key, if any.

      • options: TokenOptions = {}

        The options, trust anchor included (see the README).

      Returns XMLDSigToken

    • Analyzes an XML token.

      The options must hold a trust anchor, caCertPath and/or signerCertPath; without it, isSignatureValid() returns false. If the token is not valid, getError() tells why; an option that is refused throws.

      Parameters

      • xml: string | Uint8Array<ArrayBufferLike>

        The XML token, as a string or as the bytes of its UTF-8 encoding.

      • options: TokenOptions = {}

        The options, trust anchor included (see the README).

      Returns XMLDSigToken

    • Creates a signed token whose data are encrypted for the owner of the encryption certificate: only the private key of this certificate decrypts them. The sender does not need this private key: pass null as cryptKeyPath.

      The created token is checked right away. Without cryptKeyPath, the check covers everything that can be verified without decrypting the token (structure, algorithms, digest, signature, trust in the signing certificate): isSignatureValid() and isDataEncrypted() return true, while getData(), getTimestamp(), getTokenId(), getAudience() and getExpiry() return null. With cryptKeyPath, the token is also decrypted and its content read.

      Parameters

      • data: TokenData

        The token data (see createXMLToken()).

      • signKeyPath: PemSource

        The private key that signs the token, in PEM format.

      • signCertPath: PemSource

        The X.509 certificate of this key, in PEM format.

      • cryptKeyPath: PemSource | null

        The private key of the recipient, in PEM format, to check the content of the created token; null without it.

      • cryptCertPath: PemSource

        The encryption certificate of the recipient, in PEM format.

      • signKeyPassword: string | null = null

        The password of the signing key, if any.

      • cryptKeyPassword: string | null = null

        The password of the private key of the recipient, if any (null without cryptKeyPath).

      • options: TokenOptions = {}

        The options (see the README).

      Returns XMLDSigToken

    • Creates an XML token for the given user data.

      The created token is analyzed right away to check it, with the certificate of its own signing key as trust anchor. If it cannot be created, getError() tells why; a parameter or an option that is refused throws.

      Parameters

      • data: TokenData

        The token data: named values, nested at will. A value is a string, a number, a boolean, null (written as an empty string), or bytes (a Uint8Array).

      • signKeyPath: PemSource

        The private key that signs the token, in PEM format: the path of its file, or its content.

      • signCertPath: PemSource

        The X.509 certificate of this key, in PEM format, included in the token: the path of its file, or its content.

      • signKeyPassword: string | null = null

        The password of the private key, if any.

      • options: TokenOptions = {}

        The options (see the README).

      Returns XMLDSigToken