UNPKG

@syncfusion/ej2-pdf

Version:

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

271 lines (270 loc) 9.67 kB
import { _PdfBigInt } from './pdf-big-integer'; import { _PdfCertificateIdentifier } from './pdf-certificate-identifier'; import { _PdfCertificateTable } from './pdf-certificate-table'; import { _PdfSubjectKeyIdentifier } from './pdf-key-identifier'; import { _PdfX509Certificates } from './x509/x509-certificate'; import { _PdfCipherParameter } from './x509/x509-cipher-handler'; import { _PdfAbstractSyntaxElement } from './asn1/abstract-syntax'; export interface _PdfKeyEntry { privateKey: any; attributes: Record<string, any>; } /** * PKCS#7 / PKCS#12 certificate and key container helper with parsing and extraction utilities. * * @private */ export declare class _PdfPublicKeyCryptographyCertificate { /** * Raw ASN.1 certificate chain elements extracted from the container. * * @private * @type {_PdfAbstractSyntaxElement[]} */ _certificateChain: _PdfAbstractSyntaxElement[]; /** * Map of key identifiers/names to key entries or private key structures. * * @private * @type {Map<string, any>} */ _keys: Map<string, any>; /** * Mapping of local identifier strings to hex key names. * * @private * @type {Map<string,string>} */ _localIdentifiers: Map<string, string>; /** * OID for data content type. * * @private * @type {string} */ _data: string; /** * OID for encrypted data content type. * * @private * @type {string} */ _encryptedData: string; /** * OID for certificate bag in PKCS#12. * * @private * @type {string} */ _certificateBag: string; /** * OID for shroudedKeyBag in PKCS#12. * * @private * @type {string} */ _shroudedKeyBag: string; /** * OID for keyBag in PKCS#12. * * @private * @type {string} */ _keyBag: string; /** * Attributes parsed from the container metadata. * * @private * @type {Record<string, any>} */ _attributes: Record<string, any>; /** * Table of named certificates (used for lookup by friendly name). * * @private * @type {_PdfCertificateTable} */ _certificates: _PdfCertificateTable; /** * Map from certificate identifier to parsed certificate chain container. * * @private * @type {Map<_PdfCertificateIdentifier,_PdfX509Certificates>} */ _chainCertificates: Map<_PdfCertificateIdentifier, _PdfX509Certificates>; /** * Map from key hex name to parsed certificates for that key. * * @private * @type {Map<string,_PdfX509Certificates>} */ _keyCertificates: Map<string, _PdfX509Certificates>; /** * Cached public key string representation when parsed. * * @private * @type {string} */ _publicKeyString: string; /** * True when a private key was encountered without a local identifier. * * @private * @type {boolean} */ _isUnMarkedKey: boolean; constructor(input?: Uint8Array, password?: string); /** * Create a subject key identifier helper from the provided public key parameters. * * @private * @param {_PdfCipherParameter} publicKey - Parsed public key parameters. * @param {Uint8Array} id - Raw key identifier bytes. * @returns {_PdfSubjectKeyIdentifier} Constructed subject key identifier helper. */ _createSubjectKeyID(publicKey: _PdfCipherParameter, id: Uint8Array): _PdfSubjectKeyIdentifier; /** * Load and parse a PKCS container (PFX/P12) from bytes using the provided password. * * @private * @param {Uint8Array} input - The container bytes. * @param {string} password - Password to decrypt the container. * @returns {void} */ _loadCertificate(input: Uint8Array, password: string): void; /** * Process and index a collection of ASN.1 certificate entries extracted from the container. * * @private * @param {any[]} certificateChain - Array of ASN.1 certificate elements. * @returns {void} */ _processCertificateCollection(certificateChain: any[]): void; /** * Process a PKCS Data content element, extracting keys and certificates. * * @private * @param {_PdfAbstractSyntaxElement} contentElement - ASN.1 content element. * @param {string} password - Password for encrypted entries. * @returns {void} */ _processData(contentElement: _PdfAbstractSyntaxElement, password: string): void; private _parseAndDecrypt; private _decodeDecryptedBytes; private _handleCertificateBag; private _extractPrivateKeyFromKeyInfo; private _extractLocalIdentifiers; private _storeKeyEntry; private _handleShroudedKeyBag; private _handleKeyBag; /** * Process an EncryptedData content element, dispatching to appropriate handlers. * * @private * @param {_PdfAbstractSyntaxElement} contentElement - EncryptedData ASN.1 element. * @param {string} password - Password used for decryption. * @returns {void} */ _processEncryptedData(contentElement: _PdfAbstractSyntaxElement, password: string): void; /** * Construct a JavaScript private key object from raw RSA components. * * @private * @param {Uint8Array} modulus - RSA modulus bytes. * @param {Uint8Array} publicExponent - RSA public exponent bytes. * @param {Uint8Array} privateExponent - RSA private exponent bytes. * @param {Uint8Array} p - RSA prime1 bytes. * @param {Uint8Array} q - RSA prime2 bytes. * @param {Uint8Array} dP - RSA exponent1 bytes. * @param {Uint8Array} dQ - RSA exponent2 bytes. * @param {Uint8Array} inverse - RSA coefficient (qInv) bytes. * @returns {any} An object representing the private key and accessors. */ _createPrivateKey(modulus: Uint8Array, publicExponent: Uint8Array, privateExponent: Uint8Array, p: Uint8Array, q: Uint8Array, dP: Uint8Array, dQ: Uint8Array, inverse: Uint8Array): any; /** * Validate that an RSA parameter value is present. * * @private * @param {string} name - Parameter name for error messages. * @param {_PdfBigInt} value - The big integer value to validate. * @returns {void} */ _validateValue(name: string, value: _PdfBigInt): void; /** * Convert a Uint8Array containing big-endian bytes into a `_PdfBigInt` helper. * * @private * @param {Uint8Array} bytes - Big-endian byte sequence. * @returns {_PdfBigInt} The constructed big-integer helper. */ _uint8ArrayToBigInt(bytes: Uint8Array): _PdfBigInt; /** * Encode a UTF-16BE password string into the byte format expected by PKCS#12. * * @private * @param {string} password - Password to encode. * @returns {Uint8Array} Encoded password bytes. */ _getPassword(password: string): Uint8Array; /** * Decrypt encrypted content using the specified algorithm sequence and password. * * @private * @param {_PdfAbstractSyntaxElement[]} algorithmSeq - ASN.1 algorithm parameters sequence. * @param {Uint8Array} encryptedData - Encrypted payload bytes. * @param {string} password - Password used to derive keys. * @returns {Uint8Array} Decrypted bytes. */ _getCryptographicData(algorithmSeq: _PdfAbstractSyntaxElement[], encryptedData: Uint8Array, password: string): Uint8Array; /** * Generate a derived key using PBKDF/PBE style iteration per PKCS specs. * * @private * @param {Uint8Array} password - Password bytes. * @param {Uint8Array} salt - Salt bytes. * @param {number} id - Diversifier id. * @param {number} iterations - Iteration count. * @param {number} n - Desired key length in bytes. * @param {{ hash(data: Uint8Array): Uint8Array; u: number; v: number }} hashValues - Hash function metadata. * @returns {Uint8Array} Derived key of length `n`. */ _generateDerivedKey(password: Uint8Array, salt: Uint8Array, id: number, iterations: number, n: number, hashValues: { hash(data: Uint8Array): Uint8Array; u: number; v: number; }): Uint8Array; /** * Internal helper used by the key derivation routine to add blocks. * * @private * @param {Uint8Array} I - Buffer being adjusted. * @param {number} offset - Offset within I to apply the adjustment. * @param {Uint8Array} B - Block to add. * @returns {void} */ _adjust(I: Uint8Array, offset: number, B: Uint8Array): void; /** * Retrieve certificates associated with the provided key or friendly name. * * @private * @param {string} certificateKey - Friendly name or identifier to lookup. * @returns {_PdfX509Certificates} Matching certificates container or undefined. */ _getCertificate(certificateKey: string): _PdfX509Certificates; /** * Parse raw RSA private key octets into component byte arrays. * * @private * @param {Uint8Array} privateKeyOctets - DER-encoded RSA private key octets. * @returns {Record<string,Uint8Array>} Map of RSA component names to bytes. */ _parsePrivateKey(privateKeyOctets: Uint8Array): Record<string, Uint8Array>; /** * Build the certificate chain for a given certificate key/name. * * @private * @param {string} key - Certificate key or friendly name. * @returns {_PdfX509Certificates[]|null} Array of certificate containers or null. */ _getCertificateChain(key: string): _PdfX509Certificates[]; }