UNPKG

@syncfusion/ej2-pdf

Version:

Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.

400 lines (399 loc) 16.9 kB
import { CryptographicStandard } from './../../../enumerator'; import { _PdfAbstractSyntaxElement } from '../asn1/abstract-syntax'; import { _PdfUniqueEncodingElement } from '../asn1/unique-encoding-element'; import { _PdfX509Certificate } from '../x509/x509-certificate'; import { _PdfMessageDigestAlgorithms } from './pdf-digest-algorithms'; import { _ICipherParam } from './pdf-interfaces'; import { PdfSignature } from './pdf-signature'; /** * Cryptographic Message Syntax signer helper that builds and parses PKCS#7/CMS * structures and provides signing utilities used by PDF signature creation. * * @private */ export declare class _PdfCryptographicMessageSyntaxSigner { /** * Message digest algorithm helpers used for hashing operations. */ private _digestAlgorithm; /** * Version of the signed-data structure. */ private _version; /** * Signer version number used in signer info. */ private _signerVersion; /** * Certificate chain used for signing. */ private _certificates; /** * Mapping of digest algorithm OIDs to values used in signed attributes. */ private _digestObjectIdentifier; /** * Object identifier string for the selected digest algorithm. */ private _digestAlgorithmObjectIdentifier; /** * The certificate used to sign the content. */ private _signatureCertificate; /** * Object identifier for the encryption/signature algorithm. */ private _encryptionAlgorithmObjectIdentifier; /** * Cached hash algorithm name derived from digest OID. */ private _hashAlgorithm; /** * RSA-related raw data used during signing. */ private _rsaData; /** * Raw signed data bytes when provided externally. */ private _signedData; /** * Raw signed RSA data bytes when provided externally. */ private _signedRsaData; /** * Cached digest used for signature generation. */ private _digest; /** * Indicates whether a timestamp token is present on the signature. * * @private */ _hasTimeStamp: boolean; /** * Raw timestamp token bytes when present. * * @private */ _timeStampTokenBytes: Uint8Array; /** * When true, the signer represents timestamp-only content. * * @private */ _isTimestampOnly: boolean; constructor(bytes: Uint8Array, subFilter: string); constructor(privateKey: _ICipherParam, certChain: _PdfX509Certificate[], hashAlgorithm: string, hasRsaData: boolean); /** * Initializes a CMS signer from raw bytes and a sub-filter identifier. * * @private * @param {Uint8Array} bytes Encoded CMS signer bytes. * @param {string} subFilter Sub-filter identifier (e.g., ETSI.RFC3161). * @returns {void} */ _initializeCmsSigner(bytes: Uint8Array, subFilter: string): void; /** * Extracts a signing-time timestamp token from signer info attributes if present. * * @private * @param {_PdfAbstractSyntaxElement} signerInfoSeq The signer info sequence to inspect. * @returns {{ hasTimeStamp: boolean; tokenBytes?: Uint8Array }} Timestamp presence and raw token bytes. // eslint-disable-line */ _getSignatureTimeStampToken(signerInfoSeq: _PdfAbstractSyntaxElement[]): { hasTimeStamp: boolean; tokenBytes?: Uint8Array; }; /** * Retrieves child elements for a container, trying abstract-set-of, sequence, or decoding content octets. * * @private * @param {_PdfAbstractSyntaxElement} element The container element. * @returns {_PdfAbstractSyntaxElement[]} Child elements. */ _getChildElement(element: _PdfAbstractSyntaxElement): _PdfAbstractSyntaxElement[]; /** * Determines whether the provided key parameter represents an RSA key. * * @private * @param {_ICipherParam} key The key parameter object. * @returns {boolean} True if the key appears to be RSA. */ _isRsaKey(key: _ICipherParam): boolean; /** * Returns the hash algorithm name corresponding to the configured digest OID. * * @private * @returns {string} The hash algorithm name. */ _getHashAlgorithm(): string; /** * Returns the internal digest algorithm helper. * * @private * @returns {_PdfMessageDigestAlgorithms} Digest algorithm helper instance. */ _getDigestAlgorithm(): _PdfMessageDigestAlgorithms; /** * Builds the authenticated attributes sequence (SET) including message digest and optional revocation info. * * @private * @param {Uint8Array} secondDigest The message digest to include. * @param {Uint8Array} [ocsp] Optional OCSP response bytes. * @param {Uint8Array[]} [crlBytes] Optional CRL bytes array. * @param {CryptographicStandard} [sigtype] Optional cryptographic standard (e.g., CAdES). * @returns {Uint8Array} Encoded attribute set bytes. */ _getSequenceDataSet(secondDigest: Uint8Array, ocsp?: Uint8Array, crlBytes?: Uint8Array[], sigtype?: CryptographicStandard): Uint8Array; /** * Creates a primitive OBJECT IDENTIFIER element for the provided OID string. * * @private * @param {string} oid Dot-delimited object identifier string. * @returns {_PdfUniqueEncodingElement} The created primitive OID element. */ _createPrimitiveOid(oid: string): _PdfUniqueEncodingElement; /** * Creates a primitive OCTET STRING element wrapping the provided bytes. * * @private * @param {Uint8Array} value Bytes to wrap. * @returns {_PdfUniqueEncodingElement} The created octet element. */ _createPrimitiveOctet(value: Uint8Array): _PdfUniqueEncodingElement; /** * Creates a constructed element with the given tag and child elements. * * @private * @param {number} tag The tag number for the constructed element. * @param {_PdfUniqueEncodingElement[]} elements Child elements to include. * @returns {_PdfUniqueEncodingElement} The constructed element. */ _createConstructed(tag: number, elements: _PdfUniqueEncodingElement[]): _PdfUniqueEncodingElement; /** * Encodes a dotted OID string into its ASN.1 byte representation. * * @private * @param {string} oidString Dot-delimited OID string. * @returns {Uint8Array} Encoded OID bytes. */ _encodeObjectIdentifier(oidString: string): Uint8Array; /** * Encodes an array of unique elements as a concatenated sequence payload. * * @private * @param {_PdfUniqueEncodingElement[]} elements Elements to encode. * @returns {Uint8Array} Concatenated encoded bytes. */ _encodeSequence(elements: _PdfUniqueEncodingElement[]): Uint8Array; /** * Serializes a `_PdfUniqueEncodingElement` into raw bytes including tag/length/value. * * @private * @param {_PdfUniqueEncodingElement} element Element to serialize. * @returns {Uint8Array} Serialized bytes. */ _encodeToUniqueElement(element: _PdfUniqueEncodingElement): Uint8Array; /** * Encodes a positive integer length into length octets for DER/BER. * * @private * @param {number} length The length to encode. * @returns {number[]} Array of octets representing the length. */ _encodeLength(length: number): number[]; /** * Computes the digest of a certificate using the configured hash algorithm. * * @private * @param {_PdfX509Certificate} certificate Certificate to hash. * @returns {Uint8Array} Digest bytes. */ _hashCertificate(certificate: _PdfX509Certificate): Uint8Array; /** * Sets precomputed signed data and selects encryption algorithm identifiers. * * @private * @param {Uint8Array} digest The digest bytes to set. * @param {Uint8Array} rsaData Optional RSA data bytes. * @param {string} digestEncryptionAlgorithm The encryption algorithm name (e.g., 'RSA'). * @returns {void} */ _setSignedData(digest: Uint8Array, rsaData: Uint8Array, digestEncryptionAlgorithm: string): void; /** * Encodes a sequence of certificate byte arrays into a constructed ASN.1 context element. * * @private * @param {Uint8Array[]} certificates Array of certificate byte arrays. * @returns {Uint8Array} Encoded constructed certificate set. */ _encodeCertificateSet(certificates: Uint8Array[]): Uint8Array; /** * Creates a primitive encoding element with the specified tag and raw value. * * @private * @param {number} tag The universal tag number. * @param {Uint8Array} value The raw value bytes. * @returns {_PdfUniqueEncodingElement} The created primitive element. */ _createPrimitive(tag: number, value: Uint8Array): _PdfUniqueEncodingElement; /** * Creates an ASN.1 constructed element (SEQUENCE) from provided elements. * * @private * @param {number} tag Tag number for the constructed element. * @param {_PdfUniqueEncodingElement[]} elements Child elements. * @returns {_PdfUniqueEncodingElement} The constructed element. */ _createAsn1Constructed(tag: number, elements: _PdfUniqueEncodingElement[]): _PdfUniqueEncodingElement; /** * Creates a context-specific constructed element with the given content. * * @private * @param {number} tag Context tag number. * @param {_PdfUniqueEncodingElement[]|Uint8Array} elements Child elements or raw bytes. * @returns {_PdfUniqueEncodingElement} The context-constructed element. */ _createContextConstructed(tag: number, elements: _PdfUniqueEncodingElement[] | Uint8Array): _PdfUniqueEncodingElement; /** * Produces a synchronous PKCS#7/CMS signature for the provided digest and returns encoded bytes. * * @private * @param {Uint8Array} secondDigest The digest to sign. * @param {Uint8Array} [timeStampResponse] Optional timestamp response bytes. * @param {Uint8Array} [revocation] Optional revocation data. * @param {Uint8Array[]} [bytes] Optional additional byte arrays. * @param {CryptographicStandard} [sigtype] Optional cryptographic standard selector. * @param {string} [hashAlgorithm] Optional hash algorithm override. * @returns {Uint8Array} Encoded PKCS#7/CMS signature bytes. */ _sign(secondDigest: Uint8Array, timeStampResponse?: Uint8Array, revocation?: Uint8Array, bytes?: Uint8Array[], sigtype?: CryptographicStandard, hashAlgorithm?: string): Uint8Array; /** * Builds the body elements array for SignedData including version, digest algorithms, contentInfo, certificates and signerInfo. * * @private * @param {number} version SignedData version. * @param {_PdfUniqueEncodingElement[]} digestAlgorithms Digest algorithm elements. * @param {_PdfUniqueEncodingElement} contentInfoSeq ContentInfo sequence element. * @param {_PdfAbstractSyntaxElement[]} certificateElements Certificate elements. * @param {_PdfUniqueEncodingElement} signerInfoSeq SignerInfo element. * @returns {_PdfUniqueEncodingElement[]} Array of body elements. */ _buildSignedDataBodyElements(version: number, digestAlgorithms: _PdfUniqueEncodingElement[], contentInfoSeq: _PdfUniqueEncodingElement, certificateElements: _PdfAbstractSyntaxElement[], signerInfoSeq: _PdfUniqueEncodingElement): _PdfUniqueEncodingElement[]; /** * Concatenates a mixture of unique elements and raw byte arrays into a single sequence payload. * * @private * @param {Array<_PdfUniqueEncodingElement|Uint8Array>} elements Elements to concatenate. * @returns {Uint8Array} Concatenated bytes. */ _concatAbstractSyntaxSequence(elements: Array<_PdfUniqueEncodingElement | Uint8Array>): Uint8Array; /** * Extracts the issuer element from a TBS certificate byte sequence. * * @private * @param {Uint8Array} tbsCertBytes The TBS certificate bytes. * @returns {_PdfUniqueEncodingElement} The issuer element. */ _getIssuer(tbsCertBytes: Uint8Array): _PdfUniqueEncodingElement; /** * Wraps a timestamp response into the appropriate attribute structure. * * @private * @param {Uint8Array} timeStampResponse Raw timestamp response bytes. * @returns {Uint8Array} Encoded timestamp attribute bytes. */ _getTimestampAttributes(timeStampResponse: Uint8Array): Uint8Array; /** * Produces an asynchronous PKCS#7/CMS signature, supporting timestamping via callbacks. * * @private * @param {Uint8Array} secondDigest The digest to sign. * @param {PdfSignature} signature Signature context containing callbacks. * @param {Uint8Array} [timeStampResponse] Optional timestamp response bytes. * @param {Uint8Array} [revocation] Optional revocation data. * @param {Uint8Array[]} [bytes] Optional additional byte arrays. * @param {CryptographicStandard} [sigtype] Optional cryptographic standard selector. * @returns {Promise<Uint8Array>} Encoded PKCS#7/CMS signature bytes. */ _signAsync(secondDigest: Uint8Array, signature: PdfSignature, timeStampResponse?: Uint8Array, revocation?: Uint8Array, bytes?: Uint8Array[], sigtype?: CryptographicStandard): Promise<Uint8Array>; /** * Maps a common algorithm name to its OID and canonical name. * * @private * @param {string} [requested] Optional requested algorithm name. * @returns {{ oid: string; name: string }} Object identifier and canonical name. // eslint-disable-line */ _getObjectIdentifierName(requested?: string): { oid: string; name: string; }; /** * Builds a timestamp-request structure using the specified hash and algorithm OID. * * @private * @param {Uint8Array} hash The message hash to include. * @param {string} algorithmIdentifier The algorithm OID string. * @returns {Uint8Array} Encoded timestamp request bytes. */ _createTimestampRequestWithAlgorithm(hash: Uint8Array, algorithmIdentifier: string): Uint8Array; /** * Attempts to re-encode a timestamp response into the expected attribute format. * * @private * @param {Uint8Array} timestampResponse Raw timestamp response bytes. * @returns {Uint8Array} Re-encoded timestamp attribute bytes or original input on failure. */ _reEncodeTimestampResponse(timestampResponse: Uint8Array): Uint8Array; /** * Encodes a sequence of ASN.1 elements representing a timestamp token sequence. * * @private * @param {_PdfAbstractSyntaxElement[]} elements Elements to include in the timestamp sequence. * @returns {Uint8Array} Encoded sequence bytes. */ _encodeTimeStampSequence(elements: _PdfAbstractSyntaxElement[]): Uint8Array; /** * Encodes a sequence length into BER/DER length bytes. * * @private * @param {number} length The length to encode. * @returns {Uint8Array} Encoded length bytes. */ _encodeSequenceLength(length: number): Uint8Array; /** * Builds an unsigned attribute containing a timestamp token. * * @private * @param {Uint8Array} tsTokenBytes Raw timestamp token bytes. * @returns {_PdfUniqueEncodingElement} The unsigned attribute element. */ _buildTimestampUnsignedAttribute(tsTokenBytes: Uint8Array): _PdfUniqueEncodingElement; /** * Obtains an encoded timestamp from the TSA using the provided callback on the `PdfSignature`. * * @private * @param {Uint8Array} secondDigest The digest to timestamp. * @param {PdfSignature} signature The signature context with timestamp callback. * @param {string} hashAlgorithm Hash algorithm name to use for TSA request. * @returns {Promise<Uint8Array>} Encoded timestamp bytes. */ _getEncodedTimestamp(secondDigest: Uint8Array, signature: PdfSignature, hashAlgorithm: string): Promise<Uint8Array>; /** * Creates a context-specific implicit element from raw timestamp value bytes. * * @private * @param {number} tagNumber The context tag number. * @param {Uint8Array} value Raw value bytes. * @returns {_PdfUniqueEncodingElement} The created element. */ _createContextImplicitFromTimestampValue(tagNumber: number, value: Uint8Array): _PdfUniqueEncodingElement; /** * Decodes child elements from content octets of an implicitly-tagged element. * * @private * @param {_PdfAbstractSyntaxElement} csImplicit Implicitly-tagged container element. * @returns {_PdfAbstractSyntaxElement[]} Decoded child elements. */ _decodeChildrenFromContentOctets(csImplicit: _PdfAbstractSyntaxElement): _PdfAbstractSyntaxElement[]; }