node-opcua-crypto 4.9.3 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,528 @@
1
- export { C as Certificate, d as CertificatePEM, h as CertificatePurpose, g as CertificateRevocationList, D as DER, K as KeyObject, N as Nonce, b as PEM, P as PrivateKey, e as PrivateKeyPEM, a as PublicKey, f as PublicKeyPEM, S as Signature, c as createPrivateKeyFromNodeJSCrypto, i as isKeyObject } from '../common-CFr95Map.js';
2
- export { AlgorithmIdentifier, AttributeTypeAndValue, AuthorityKeyIdentifier, BasicConstraints, BitString, BlockInfo, CertificateExtension, CertificateInfo, CertificateInternals, CertificateRevocationListInfo, CertificateSerialNumber, CertificateSigningRequestInfo, ComputeDerivedKeysOptions, CreateSelfSignCertificateOptions, DerivedKeys, DirectoryName, ExtensionRequest, Extensions, Name, PaddingAlgorithm, PrivateKeyInternals, PublicKeyLength, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, RevokedCertificate, SignatureValue, Subject, SubjectOptions, SubjectPublicKey, SubjectPublicKeyInfo, TBSCertList, TagType, TbsCertificate, Validity, VerifyChunkSignatureOptions, VerifyMessageChunkSignatureOptions, Version, X509ExtKeyUsage, X509KeyUsage, _VerifyStatus, _coercePrivateKey, _findBlockAtIndex, _getBlock, _readAlgorithmIdentifier, _readBitString, _readBooleanValue, _readDirectoryName, _readECCAlgorithmIdentifier, _readExtension, _readIntegerAsByteString, _readIntegerValue, _readListOfInteger, _readLongIntegerValue, _readObjectIdentifier, _readOctetString, _readSignatureValue, _readSignatureValueBin, _readStruct, _readTime, _readValue, _readVersionValue, certificateMatchesPrivateKey, coerceCertificate, coerceCertificatePem, coercePEMorDerToPrivateKey, coercePrivateKeyPem, coercePublicKeyPem, coerceRsaPublicKeyPem, combine_der, compactDirectoryName, computeDerivedKeys, computePaddingFooter, convertPEMtoDER, createCertificateSigningRequest, createSelfSignedCertificate, decryptBufferWithDerivedKeys, derToPrivateKey, encryptBufferWithDerivedKeys, exploreCertificate, exploreCertificateInfo, exploreCertificateRevocationList, exploreCertificateSigningRequest, explorePrivateKey, extractPublicKeyFromCertificate, extractPublicKeyFromCertificateSync, formatBuffer2DigitHexWithColum, generateKeyPair, generatePrivateKey, hexDump, identifyPemType, makeMessageChunkSignature, makeMessageChunkSignatureWithDerivedKeys, makePrivateKeyFromPem, makePseudoRandomBuffer, makeSHA1Thumbprint, parseBitString, pemToPrivateKey, privateDecrypt, privateDecrypt_long, privateDecrypt_native, privateKeyToPEM, publicEncrypt, publicEncrypt_long, publicEncrypt_native, publicKeyAndPrivateKeyMatches, readCertificationRequestInfo, readNameForCrl, readTag, readTbsCertificate, reduceLength, removePadding, removeTrailingLF, rsaLengthPrivateKey, rsaLengthPublicKey, rsaLengthRsaPublicKey, split_der, toPem, toPem2, verifyCertificateChain, verifyCertificateOrClrSignature, verifyCertificateRevocationListSignature, verifyCertificateSignature, verifyChunkSignature, verifyChunkSignatureWithDerivedKeys, verifyMessageChunkSignature } from './index.js';
3
- import 'crypto';
4
- import '@peculiar/x509';
1
+ import { b as PEM, D as DER, f as PublicKeyPEM, S as Signature, P as PrivateKey, C as Certificate, d as CertificatePEM, N as Nonce, K as KeyObject, e as PrivateKeyPEM, a as PublicKey, g as CertificateRevocationList, h as CertificatePurpose } from '../common-CFr95Map.js';
2
+ export { c as createPrivateKeyFromNodeJSCrypto, i as isKeyObject } from '../common-CFr95Map.js';
3
+ import { KeyLike } from 'crypto';
4
+ import * as x509 from '@peculiar/x509';
5
+
6
+ declare function identifyPemType(rawKey: Buffer | string): undefined | string;
7
+ declare function removeTrailingLF(str: string): string;
8
+ declare function toPem(raw_key: Buffer | string, pem: string): string;
9
+ declare function convertPEMtoDER(raw_key: PEM): DER;
10
+ declare function hexDump(buffer: Buffer, width?: number): string;
11
+ interface MakeMessageChunkSignatureOptions {
12
+ signatureLength: number;
13
+ algorithm: string;
14
+ privateKey: PrivateKey;
15
+ }
16
+ declare function makeMessageChunkSignature(chunk: Buffer, options: MakeMessageChunkSignatureOptions): Buffer;
17
+ interface VerifyMessageChunkSignatureOptions {
18
+ signatureLength?: number;
19
+ algorithm: string;
20
+ publicKey: PublicKeyPEM;
21
+ }
22
+ /**
23
+ * @method verifyMessageChunkSignature
24
+ *
25
+ * const signer = {
26
+ * signatureLength : 128,
27
+ * algorithm : "RSA-SHA256",
28
+ * publicKey: "qsdqsdqsd"
29
+ * };
30
+ * @param blockToVerify
31
+ * @param signature
32
+ * @param options
33
+ * @param options.signatureLength
34
+ * @param options.algorithm for example "RSA-SHA256"
35
+ * @param options.publicKey
36
+ * @return true if the signature is valid
37
+ */
38
+ declare function verifyMessageChunkSignature(blockToVerify: Buffer, signature: Signature, options: VerifyMessageChunkSignatureOptions): boolean;
39
+ declare function makeSHA1Thumbprint(buffer: Buffer): Signature;
40
+ declare const RSA_PKCS1_OAEP_PADDING: number;
41
+ declare const RSA_PKCS1_PADDING: number;
42
+ declare enum PaddingAlgorithm {
43
+ RSA_PKCS1_OAEP_PADDING = 4,
44
+ RSA_PKCS1_PADDING = 1
45
+ }
46
+ declare function publicEncrypt_native(buffer: Buffer, publicKey: KeyLike, algorithm?: PaddingAlgorithm): Buffer;
47
+ declare function privateDecrypt_native(buffer: Buffer, privateKey: PrivateKey, algorithm?: PaddingAlgorithm): Buffer;
48
+ declare const publicEncrypt: typeof publicEncrypt_native;
49
+ declare const privateDecrypt: typeof privateDecrypt_native;
50
+ declare function publicEncrypt_long(buffer: Buffer, publicKey: KeyLike, blockSize: number, padding?: number, paddingAlgorithm?: PaddingAlgorithm): Buffer;
51
+ declare function privateDecrypt_long(buffer: Buffer, privateKey: PrivateKey, blockSize: number, paddingAlgorithm?: number): Buffer;
52
+ declare function coerceCertificatePem(certificate: Certificate | CertificatePEM): CertificatePEM;
53
+ declare function extractPublicKeyFromCertificateSync(certificate: Certificate | CertificatePEM): PublicKeyPEM;
54
+ /**
55
+ * extract the publickey from a certificate
56
+ * @async
57
+ */
58
+ declare function extractPublicKeyFromCertificate(certificate: CertificatePEM | Certificate, callback: (err: Error | null, publicKeyPEM?: PublicKeyPEM) => void): void;
59
+
60
+ declare function makePseudoRandomBuffer(secret: Nonce, seed: Nonce, minLength: number, sha1or256: "SHA1" | "SHA256"): Buffer;
61
+ interface ComputeDerivedKeysOptions {
62
+ signatureLength: number;
63
+ signingKeyLength: number;
64
+ encryptingKeyLength: number;
65
+ encryptingBlockSize: number;
66
+ algorithm: string;
67
+ sha1or256?: "SHA1" | "SHA256";
68
+ }
69
+ interface DerivedKeys extends ComputeDerivedKeysOptions {
70
+ signatureLength: number;
71
+ signingKeyLength: number;
72
+ encryptingKeyLength: number;
73
+ encryptingBlockSize: number;
74
+ algorithm: string;
75
+ sha1or256: "SHA1" | "SHA256";
76
+ signingKey: Buffer;
77
+ encryptingKey: Buffer;
78
+ initializationVector: Buffer;
79
+ }
80
+ declare function computeDerivedKeys(secret: Nonce, seed: Nonce, options: ComputeDerivedKeysOptions): DerivedKeys;
81
+ /**
82
+ * @method reduceLength
83
+ * @param buffer
84
+ * @param byteToRemove
85
+ * @return buffer
86
+ */
87
+ declare function reduceLength(buffer: Buffer, byteToRemove: number): Buffer;
88
+ /**
89
+ * @method removePadding
90
+ * @param buffer
91
+ * @return buffer with padding removed
92
+ */
93
+ declare function removePadding(buffer: Buffer): Buffer;
94
+ type VerifyChunkSignatureOptions = VerifyMessageChunkSignatureOptions;
95
+ /**
96
+ * @method verifyChunkSignature
97
+ *
98
+ * const signer = {
99
+ * signatureLength : 128,
100
+ * algorithm : "RSA-SHA256",
101
+ * public_key: "qsdqsdqsd"
102
+ * };
103
+ *
104
+ * @param chunk The message chunk to verify.
105
+ * @param options
106
+ * @param options.signatureLength
107
+ * @param options.algorithm the algorithm.
108
+ * @param options.publicKey
109
+ * @return {*}
110
+ */
111
+ declare function verifyChunkSignature(chunk: Buffer, options: VerifyChunkSignatureOptions): boolean;
112
+ declare function computePaddingFooter(buffer: Buffer, derivedKeys: DerivedKeys): Buffer;
113
+ declare function encryptBufferWithDerivedKeys(buffer: Buffer, derivedKeys: DerivedKeys): Buffer;
114
+ declare function decryptBufferWithDerivedKeys(buffer: Buffer, derivedKeys: DerivedKeys): Buffer;
115
+ /**
116
+ * @method makeMessageChunkSignatureWithDerivedKeys
117
+ * @param message
118
+ * @param derivedKeys
119
+ * @return
120
+ */
121
+ declare function makeMessageChunkSignatureWithDerivedKeys(message: Buffer, derivedKeys: DerivedKeys): Buffer;
122
+ /**
123
+ * @method verifyChunkSignatureWithDerivedKeys
124
+ * @param chunk
125
+ * @param derivedKeys
126
+ * @return
127
+ */
128
+ declare function verifyChunkSignatureWithDerivedKeys(chunk: Buffer, derivedKeys: DerivedKeys): boolean;
129
+
130
+ declare enum TagType {
131
+ BOOLEAN = 1,
132
+ INTEGER = 2,
133
+ BIT_STRING = 3,
134
+ OCTET_STRING = 4,
135
+ NULL = 5,
136
+ OBJECT_IDENTIFIER = 6,
137
+ UTF8String = 12,
138
+ NumericString = 18,
139
+ PrintableString = 19,
140
+ TeletexString = 20,
141
+ IA5String = 22,
142
+ UTCTime = 23,
143
+ GeneralizedTime = 24,
144
+ GraphicString = 25,
145
+ VisibleString = 26,
146
+ GeneralString = 27,
147
+ UniversalString = 28,
148
+ BMPString = 30,
149
+ SEQUENCE = 48,
150
+ SET = 49,
151
+ CONTEXT_SPECIFIC0 = 160,
152
+ CONTEXT_SPECIFIC1 = 161,
153
+ CONTEXT_SPECIFIC2 = 162,
154
+ CONTEXT_SPECIFIC3 = 163,
155
+ A4 = 164
156
+ }
157
+ interface BlockInfo {
158
+ tag: TagType | number;
159
+ position: number;
160
+ length: number;
161
+ start: number;
162
+ }
163
+ declare function readTag(buf: Buffer, pos: number): BlockInfo;
164
+ declare function _readStruct(buf: Buffer, blockInfo: BlockInfo): BlockInfo[];
165
+ declare function parseBitString(buffer: Buffer, start: number, end: number, maxLength: number): string;
166
+ interface BitString {
167
+ lengthInBits: number;
168
+ lengthInBytes: number;
169
+ data: Buffer;
170
+ debug?: any;
171
+ }
172
+ declare function _readBitString(buffer: Buffer, block: BlockInfo): BitString;
173
+ declare function formatBuffer2DigitHexWithColum(buffer: Buffer): string;
174
+ declare function _readOctetString(buffer: Buffer, block: BlockInfo): Buffer;
175
+ declare function _getBlock(buffer: Buffer, block: BlockInfo): Buffer;
176
+ interface AlgorithmIdentifier {
177
+ identifier: string;
178
+ }
179
+ declare function _readIntegerAsByteString(buffer: Buffer, block: BlockInfo): Buffer;
180
+ declare function _readListOfInteger(buffer: Buffer): Buffer[];
181
+ declare function _readObjectIdentifier(buffer: Buffer, block: BlockInfo): {
182
+ oid: string;
183
+ name: string;
184
+ };
185
+ declare function _readAlgorithmIdentifier(buffer: Buffer, block: BlockInfo): AlgorithmIdentifier;
186
+ declare function _readECCAlgorithmIdentifier(buffer: Buffer, block: BlockInfo): AlgorithmIdentifier;
187
+ type SignatureValue = string;
188
+ declare function _readSignatureValueBin(buffer: Buffer, block: BlockInfo): Buffer;
189
+ declare function _readSignatureValue(buffer: Buffer, block: BlockInfo): SignatureValue;
190
+ declare function _readLongIntegerValue(buffer: Buffer, block: BlockInfo): Buffer;
191
+ declare function _readIntegerValue(buffer: Buffer, block: BlockInfo): number;
192
+ declare function _readBooleanValue(buffer: Buffer, block: BlockInfo): boolean;
193
+ declare function _readVersionValue(buffer: Buffer, block: BlockInfo): number;
194
+ declare function _readValue(buffer: Buffer, block: BlockInfo): any;
195
+ interface DirectoryName {
196
+ stateOrProvinceName?: string;
197
+ localityName?: string;
198
+ organizationName?: string;
199
+ organizationUnitName?: string;
200
+ commonName?: string;
201
+ countryName?: string;
202
+ }
203
+ declare function compactDirectoryName(d: DirectoryName): string;
204
+ declare function _readDirectoryName(buffer: Buffer, block: BlockInfo): DirectoryName;
205
+ declare function _findBlockAtIndex(blocks: BlockInfo[], index: number): BlockInfo | null;
206
+ declare function _readTime(buffer: Buffer, block: BlockInfo): any;
207
+
208
+ /**
209
+ * @module node_opcua_crypto
210
+ */
211
+
212
+ interface AttributeTypeAndValue {
213
+ [key: string]: any;
214
+ }
215
+ interface Validity {
216
+ notBefore: Date;
217
+ notAfter: Date;
218
+ }
219
+ interface X509KeyUsage {
220
+ digitalSignature: boolean;
221
+ nonRepudiation: boolean;
222
+ keyEncipherment: boolean;
223
+ dataEncipherment: boolean;
224
+ keyAgreement: boolean;
225
+ keyCertSign: boolean;
226
+ cRLSign: boolean;
227
+ encipherOnly: boolean;
228
+ decipherOnly: boolean;
229
+ }
230
+ interface X509ExtKeyUsage {
231
+ clientAuth: boolean;
232
+ serverAuth: boolean;
233
+ codeSigning: boolean;
234
+ emailProtection: boolean;
235
+ timeStamping: boolean;
236
+ ocspSigning: boolean;
237
+ ipsecEndSystem: boolean;
238
+ ipsecTunnel: boolean;
239
+ ipsecUser: boolean;
240
+ }
241
+ interface SubjectPublicKey {
242
+ modulus: Buffer;
243
+ }
244
+ declare function _readExtension(buffer: Buffer, block: BlockInfo): {
245
+ identifier: {
246
+ oid: string;
247
+ name: string;
248
+ };
249
+ value: any;
250
+ };
251
+ interface SubjectPublicKeyInfo {
252
+ algorithm: string;
253
+ keyLength: PublicKeyLength;
254
+ subjectPublicKey: SubjectPublicKey;
255
+ }
256
+ interface BasicConstraints {
257
+ critical: boolean;
258
+ cA: boolean;
259
+ pathLengthConstraint?: number;
260
+ }
261
+ interface AuthorityKeyIdentifier {
262
+ keyIdentifier: string | null;
263
+ authorityCertIssuer: DirectoryName | null;
264
+ authorityCertIssuerFingerPrint: string;
265
+ serial: string | null;
266
+ }
267
+ interface CertificateExtension {
268
+ basicConstraints: BasicConstraints;
269
+ subjectKeyIdentifier?: string;
270
+ authorityKeyIdentifier?: AuthorityKeyIdentifier;
271
+ keyUsage?: X509KeyUsage;
272
+ extKeyUsage?: X509ExtKeyUsage;
273
+ subjectAltName?: any;
274
+ }
275
+ interface TbsCertificate {
276
+ version: number;
277
+ serialNumber: string;
278
+ issuer: any;
279
+ signature: AlgorithmIdentifier;
280
+ validity: Validity;
281
+ subject: DirectoryName;
282
+ subjectFingerPrint: string;
283
+ subjectPublicKeyInfo: SubjectPublicKeyInfo;
284
+ extensions: CertificateExtension | null;
285
+ }
286
+ declare function readTbsCertificate(buffer: Buffer, block: BlockInfo): TbsCertificate;
287
+ interface CertificateInternals {
288
+ tbsCertificate: TbsCertificate;
289
+ signatureAlgorithm: AlgorithmIdentifier;
290
+ signatureValue: SignatureValue;
291
+ }
292
+ /**
293
+ * explore a certificate structure
294
+ * @param certificate
295
+ * @returns a json object that exhibits the internal data of the certificate
296
+ */
297
+ declare function exploreCertificate(certificate: Certificate): CertificateInternals;
298
+ /**
299
+ * @method split_der
300
+ * split a multi chain certificates
301
+ * @param certificateChain the certificate chain in der (binary) format}
302
+ * @returns an array of Der , each element of the array is one certificate of the chain
303
+ */
304
+ declare function split_der(certificateChain: Certificate): Certificate[];
305
+ /**
306
+ * @method combine_der
307
+ * combine an array of certificates into a single blob
308
+ * @param certificates a array with the individual DER certificates of the chain
309
+ * @return a concatenated buffer containing the certificates
310
+ */
311
+ declare function combine_der(certificates: Certificate[]): Certificate;
312
+
313
+ type PublicKeyLength = 64 | 96 | 128 | 256 | 384 | 512;
314
+ /**
315
+ * A structure exposing useful information about a certificate
316
+ */
317
+ interface CertificateInfo {
318
+ /** the public key length in bits */
319
+ publicKeyLength: PublicKeyLength;
320
+ /** the date at which the certificate starts to be valid */
321
+ notBefore: Date;
322
+ /** the date after which the certificate is not valid any more */
323
+ notAfter: Date;
324
+ /** info about certificate owner */
325
+ subject: DirectoryName;
326
+ /** public key */
327
+ publicKey: SubjectPublicKey;
328
+ }
329
+ declare function coerceCertificate(certificate: Certificate | CertificatePEM): Certificate;
330
+ /**
331
+ * @method exploreCertificateInfo
332
+ * returns useful information about the certificate such as public key length, start date and end of validity date,
333
+ * and CN
334
+ * @param certificate the certificate to explore
335
+ */
336
+ declare function exploreCertificateInfo(certificate: Certificate | CertificatePEM): CertificateInfo;
337
+
338
+ /***
339
+ * @method rsaLengthPrivateKey
340
+ * A very expensive way to determine the rsa key length ( i.e 2048bits or 1024bits)
341
+ * @param key a PEM public key or a PEM rsa private key
342
+ * @return the key length in bytes.
343
+ */
344
+ declare function rsaLengthPrivateKey(key: PrivateKey): number;
345
+ /**
346
+ * @method toPem2
347
+ * @param raw_key
348
+ * @param pem
349
+ *
350
+ *
351
+ * @return a PEM string containing the Private Key
352
+ *
353
+ * Note: a Pem key can be converted back to a private key object using coercePrivateKey
354
+ *
355
+ */
356
+ declare function toPem2(raw_key: Buffer | string | KeyObject | PrivateKey, pem: string): string;
357
+ declare function coercePrivateKeyPem(privateKey: PrivateKey): PrivateKeyPEM;
358
+ declare function coercePublicKeyPem(publicKey: PublicKey | PublicKeyPEM): PublicKeyPEM;
359
+ declare function coerceRsaPublicKeyPem(publicKey: PublicKey | KeyObject | PublicKeyPEM): PublicKeyPEM;
360
+ declare function rsaLengthPublicKey(key: PublicKeyPEM | PublicKey): number;
361
+ declare function rsaLengthRsaPublicKey(key: PublicKeyPEM | PublicKey): number;
362
+
363
+ declare function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean;
364
+ declare function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean;
365
+ declare function verifyCertificateRevocationListSignature(certificateRevocationList: Certificate, parentCertificate: Certificate): boolean;
366
+ type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
367
+ declare function verifyCertificateChain(certificateChain: Certificate[]): Promise<{
368
+ status: _VerifyStatus;
369
+ reason: string;
370
+ }>;
371
+
372
+ type Version = string;
373
+ type Name = string;
374
+ type CertificateSerialNumber = string;
375
+ type Extensions = Record<string, unknown>;
376
+ interface RevokedCertificate {
377
+ userCertificate: CertificateSerialNumber;
378
+ revocationDate: Date;
379
+ crlEntryExtensions?: Extensions;
380
+ }
381
+ interface TBSCertList {
382
+ version?: Version;
383
+ signature: AlgorithmIdentifier;
384
+ issuer: Name;
385
+ issuerFingerprint: string;
386
+ thisUpdate: Date;
387
+ nextUpdate?: Date;
388
+ revokedCertificates: RevokedCertificate[];
389
+ }
390
+ interface CertificateRevocationListInfo {
391
+ tbsCertList: TBSCertList;
392
+ signatureAlgorithm: AlgorithmIdentifier;
393
+ signatureValue: Buffer;
394
+ }
395
+ declare function readNameForCrl(buffer: Buffer, block: BlockInfo): DirectoryName;
396
+ declare function exploreCertificateRevocationList(crl: CertificateRevocationList): CertificateRevocationListInfo;
397
+
398
+ interface ExtensionRequest {
399
+ basicConstraints: BasicConstraints;
400
+ keyUsage: X509KeyUsage;
401
+ subjectAltName: any;
402
+ }
403
+ interface CertificateSigningRequestInfo {
404
+ extensionRequest: ExtensionRequest;
405
+ }
406
+ declare function readCertificationRequestInfo(buffer: Buffer, block: BlockInfo): CertificateSigningRequestInfo;
407
+ declare function exploreCertificateSigningRequest(crl: Buffer): CertificateSigningRequestInfo;
408
+
409
+ interface PrivateKeyInternals {
410
+ /***/
411
+ version: Buffer;
412
+ modulus: Buffer;
413
+ publicExponent: Buffer;
414
+ privateExponent: Buffer;
415
+ prime1: Buffer;
416
+ prime2: Buffer;
417
+ exponent1: Buffer;
418
+ exponent2: Buffer;
419
+ }
420
+ /**
421
+ *
422
+ * @param privateKey RSAPrivateKey ::= SEQUENCE {
423
+ * version Version,
424
+ * modulus INTEGER, -- n
425
+ * publicExponent INTEGER, -- e
426
+ * privateExponent INTEGER, -- d
427
+ * prime1 INTEGER, -- p
428
+ * prime2 INTEGER, -- q
429
+ * exponent1 INTEGER, -- d mod (p-1)
430
+ * exponent2 INTEGER, -- d mod (q-1)
431
+ * coefficient INTEGER, -- (inverse of q) mod p
432
+ * otherPrimeInfos OtherPrimeInfos OPTIONAL
433
+ }
434
+ */
435
+ declare function explorePrivateKey(privateKey2: PrivateKey): PrivateKeyInternals;
436
+
437
+ declare function publicKeyAndPrivateKeyMatches(certificate: Certificate, privateKey: PrivateKey): boolean;
438
+ declare function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean;
439
+
440
+ declare function generateKeyPair(modulusLength?: 1024 | 2048 | 3072 | 4096): Promise<CryptoKeyPair>;
441
+ /**
442
+ * generate a pair of private/public keys of length 1024,2048, 3072, or 4096 bits
443
+ */
444
+ declare function generatePrivateKey(modulusLength?: 1024 | 2048 | 3072 | 4096): Promise<CryptoKey>;
445
+ /**
446
+ * convert a CryptoKey to a PEM string
447
+ */
448
+ declare function privateKeyToPEM(privateKey: CryptoKey): Promise<{
449
+ privPem: string;
450
+ privDer: ArrayBuffer;
451
+ }>;
452
+ declare function derToPrivateKey(privDer: ArrayBuffer): Promise<CryptoKey>;
453
+ declare function pemToPrivateKey(pem: string): Promise<CryptoKey>;
454
+
455
+ interface CreateCertificateSigningRequestOptions {
456
+ privateKey: CryptoKey;
457
+ notBefore?: Date;
458
+ notAfter?: Date;
459
+ validity?: number;
460
+ subject?: string;
461
+ dns?: string[];
462
+ ip?: string[];
463
+ applicationUri?: string;
464
+ purpose: CertificatePurpose;
465
+ }
466
+ declare function createCertificateSigningRequest({ privateKey, subject, dns, ip, applicationUri, purpose, }: CreateCertificateSigningRequestOptions): Promise<{
467
+ csr: string;
468
+ der: x509.Pkcs10CertificateRequest;
469
+ }>;
470
+
471
+ interface CreateSelfSignCertificateOptions {
472
+ privateKey: CryptoKey;
473
+ notBefore?: Date;
474
+ notAfter?: Date;
475
+ validity?: number;
476
+ subject?: string;
477
+ dns?: string[];
478
+ ip?: string[];
479
+ applicationUri?: string;
480
+ purpose: CertificatePurpose;
481
+ }
482
+ /**
483
+ *
484
+ * construct a self-signed certificate
485
+ */
486
+ declare function createSelfSignedCertificate({ privateKey, notAfter, notBefore, validity, subject, dns, ip, applicationUri, purpose, }: CreateSelfSignCertificateOptions): Promise<{
487
+ cert: string;
488
+ der: x509.X509Certificate;
489
+ }>;
490
+
491
+ declare function coercePEMorDerToPrivateKey(privateKeyInDerOrPem: string | Buffer): PrivateKey;
492
+ /**
493
+ *
494
+ * @private
495
+ */
496
+ declare function _coercePrivateKey(privateKey: any): Promise<KeyObject>;
497
+
498
+ interface SubjectOptions {
499
+ commonName?: string;
500
+ organization?: string;
501
+ organizationalUnit?: string;
502
+ locality?: string;
503
+ state?: string;
504
+ country?: string;
505
+ domainComponent?: string;
506
+ }
507
+ /**
508
+ * subjectName The subject name to use for the Certificate.
509
+ * If not specified the ApplicationName and/or domainNames are used to create a suitable default value.
510
+ */
511
+ declare class Subject implements SubjectOptions {
512
+ readonly commonName?: string;
513
+ readonly organization?: string;
514
+ readonly organizationalUnit?: string;
515
+ readonly locality?: string;
516
+ readonly state?: string;
517
+ readonly country?: string;
518
+ readonly domainComponent?: string;
519
+ constructor(options: SubjectOptions | string);
520
+ static parse(str: string): SubjectOptions;
521
+ toStringInternal(sep: string): string;
522
+ toStringForOPCUA(): string;
523
+ toString(): string;
524
+ }
525
+
526
+ declare function makePrivateKeyFromPem(privateKeyInPem: string): PrivateKey;
527
+
528
+ export { type AlgorithmIdentifier, type AttributeTypeAndValue, type AuthorityKeyIdentifier, type BasicConstraints, type BitString, type BlockInfo, Certificate, type CertificateExtension, type CertificateInfo, type CertificateInternals, CertificatePEM, CertificatePurpose, CertificateRevocationList, type CertificateRevocationListInfo, type CertificateSerialNumber, type CertificateSigningRequestInfo, type ComputeDerivedKeysOptions, type CreateSelfSignCertificateOptions, DER, type DerivedKeys, type DirectoryName, type ExtensionRequest, type Extensions, KeyObject, type Name, Nonce, PEM, PaddingAlgorithm, PrivateKey, type PrivateKeyInternals, PrivateKeyPEM, PublicKey, type PublicKeyLength, PublicKeyPEM, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, type RevokedCertificate, Signature, type SignatureValue, Subject, type SubjectOptions, type SubjectPublicKey, type SubjectPublicKeyInfo, type TBSCertList, TagType, type TbsCertificate, type Validity, type VerifyChunkSignatureOptions, type VerifyMessageChunkSignatureOptions, type Version, type X509ExtKeyUsage, type X509KeyUsage, type _VerifyStatus, _coercePrivateKey, _findBlockAtIndex, _getBlock, _readAlgorithmIdentifier, _readBitString, _readBooleanValue, _readDirectoryName, _readECCAlgorithmIdentifier, _readExtension, _readIntegerAsByteString, _readIntegerValue, _readListOfInteger, _readLongIntegerValue, _readObjectIdentifier, _readOctetString, _readSignatureValue, _readSignatureValueBin, _readStruct, _readTime, _readValue, _readVersionValue, certificateMatchesPrivateKey, coerceCertificate, coerceCertificatePem, coercePEMorDerToPrivateKey, coercePrivateKeyPem, coercePublicKeyPem, coerceRsaPublicKeyPem, combine_der, compactDirectoryName, computeDerivedKeys, computePaddingFooter, convertPEMtoDER, createCertificateSigningRequest, createSelfSignedCertificate, decryptBufferWithDerivedKeys, derToPrivateKey, encryptBufferWithDerivedKeys, exploreCertificate, exploreCertificateInfo, exploreCertificateRevocationList, exploreCertificateSigningRequest, explorePrivateKey, extractPublicKeyFromCertificate, extractPublicKeyFromCertificateSync, formatBuffer2DigitHexWithColum, generateKeyPair, generatePrivateKey, hexDump, identifyPemType, makeMessageChunkSignature, makeMessageChunkSignatureWithDerivedKeys, makePrivateKeyFromPem, makePseudoRandomBuffer, makeSHA1Thumbprint, parseBitString, pemToPrivateKey, privateDecrypt, privateDecrypt_long, privateDecrypt_native, privateKeyToPEM, publicEncrypt, publicEncrypt_long, publicEncrypt_native, publicKeyAndPrivateKeyMatches, readCertificationRequestInfo, readNameForCrl, readTag, readTbsCertificate, reduceLength, removePadding, removeTrailingLF, rsaLengthPrivateKey, rsaLengthPublicKey, rsaLengthRsaPublicKey, split_der, toPem, toPem2, verifyCertificateChain, verifyCertificateOrClrSignature, verifyCertificateRevocationListSignature, verifyCertificateSignature, verifyChunkSignature, verifyChunkSignatureWithDerivedKeys, verifyMessageChunkSignature };
@@ -229,6 +229,7 @@ var oid_map = {
229
229
  "1.3.6.1.4.1.311.2.1.22": { d: "1.3.6.1.4.1.311.2.1.22", c: "SPC_COMMERCIAL_SP_KEY_PURPOSE_OBJID" },
230
230
  "1.3.6.1.4.1.311.10.3.1": { d: "1.3.6.1.4.1.311.10.3.1", c: "Signer of CTLs -- szOID_KP_CTL_USAGE_SIGNING" },
231
231
  "1.3.6.1.4.1.311.10.3.4": { d: "1.3.6.1.4.1.311.10.3.4", c: "szOID_EFS_RECOVERY (Encryption File System)" },
232
+ "1.3.6.1.4.1.311.20.2.3": { d: "1.3.6.1.4.1.311.20.2.3", c: "id-on-personalData" },
232
233
  "1.3.6.1.5.5.7.3.17": { d: "1.3.6.1.5.5.7.3.17", c: "Internet Key Exchange (IKE)" },
233
234
  "1.3.6.1.5.5.7.3.1": { d: "serverAuth", c: "PKIX key purpose" },
234
235
  "1.3.6.1.5.5.7.3.2": { d: "clientAuth", c: "PKIX key purpose" },
@@ -488,12 +489,15 @@ var TagType = /* @__PURE__ */ ((TagType3) => {
488
489
  TagType3[TagType3["BMPString"] = 30] = "BMPString";
489
490
  TagType3[TagType3["SEQUENCE"] = 48] = "SEQUENCE";
490
491
  TagType3[TagType3["SET"] = 49] = "SET";
491
- TagType3[TagType3["A3"] = 163] = "A3";
492
+ TagType3[TagType3["CONTEXT_SPECIFIC0"] = 160] = "CONTEXT_SPECIFIC0";
493
+ TagType3[TagType3["CONTEXT_SPECIFIC1"] = 161] = "CONTEXT_SPECIFIC1";
494
+ TagType3[TagType3["CONTEXT_SPECIFIC2"] = 162] = "CONTEXT_SPECIFIC2";
495
+ TagType3[TagType3["CONTEXT_SPECIFIC3"] = 163] = "CONTEXT_SPECIFIC3";
496
+ TagType3[TagType3["A4"] = 164] = "A4";
492
497
  return TagType3;
493
498
  })(TagType || {});
494
499
  function readTag(buf, pos) {
495
- (0, import_assert.default)(buf instanceof Buffer);
496
- (0, import_assert.default)(Number.isFinite(pos) && pos >= 0);
500
+ const start = pos;
497
501
  if (buf.length <= pos) {
498
502
  throw new Error("Invalid position : buf.length=" + buf.length + " pos =" + pos);
499
503
  }
@@ -509,7 +513,7 @@ function readTag(buf, pos) {
509
513
  pos += 1;
510
514
  }
511
515
  }
512
- return { tag, position: pos, length };
516
+ return { start, tag, position: pos, length };
513
517
  }
514
518
  function _readStruct(buf, blockInfo) {
515
519
  const length = blockInfo.length;
@@ -574,8 +578,8 @@ function _readIntegerAsByteString(buffer, block) {
574
578
  function _readListOfInteger(buffer) {
575
579
  const block = readTag(buffer, 0);
576
580
  const inner_blocks = _readStruct(buffer, block);
577
- return inner_blocks.map((bblock) => {
578
- return _readIntegerAsByteString(buffer, bblock);
581
+ return inner_blocks.map((innerBlock) => {
582
+ return _readIntegerAsByteString(buffer, innerBlock);
579
583
  });
580
584
  }
581
585
  function parseOID(buffer, start, end) {
@@ -838,7 +842,8 @@ function _readGeneralNames(buffer, block) {
838
842
  5: { name: "ediPartyName", type: "EDIPartyName" },
839
843
  6: { name: "uniformResourceIdentifier", type: "IA5String" },
840
844
  7: { name: "iPAddress", type: "OCTET_STRING" },
841
- 8: { name: "registeredID", type: "OBJECT_IDENTIFIER" }
845
+ 8: { name: "registeredID", type: "OBJECT_IDENTIFIER" },
846
+ 32: { name: "otherName", type: "AnotherName" }
842
847
  };
843
848
  const blocks = _readStruct(buffer, block);
844
849
  function _readFromType(buffer2, block2, type) {
@@ -855,10 +860,25 @@ function _readGeneralNames(buffer, block) {
855
860
  const t = block2.tag & 127;
856
861
  const type = _data[t];
857
862
  if (!type) {
858
- throw new Error(" INVALID TYPE => " + t + "0x" + t.toString(16));
863
+ console.log("_readGeneralNames: INVALID TYPE => " + t + " 0x" + t.toString(16));
864
+ continue;
865
+ }
866
+ if (t == 32) {
867
+ n[type.name] = n[type.name] || [];
868
+ const blocks2 = _readStruct(buffer, block2);
869
+ const name = _readObjectIdentifier(buffer, blocks2[0]).name;
870
+ const buf = _getBlock(buffer, blocks2[1]);
871
+ const b = readTag(buf, 0);
872
+ const nn = _readValue(buf, b);
873
+ const data = {
874
+ identifier: name,
875
+ value: nn
876
+ };
877
+ n[type.name].push(data.value);
878
+ } else {
879
+ n[type.name] = n[type.name] || [];
880
+ n[type.name].push(_readFromType(buffer, block2, type.type));
859
881
  }
860
- n[type.name] = n[type.name] || [];
861
- n[type.name].push(_readFromType(buffer, block2, type.type));
862
882
  }
863
883
  return n;
864
884
  }
@@ -1744,19 +1764,20 @@ var x509 = __toESM(require("@peculiar/x509"));
1744
1764
  var import_webcrypto = require("@peculiar/webcrypto");
1745
1765
  var import_crypto5 = __toESM(require("crypto"));
1746
1766
  var x5092 = __toESM(require("@peculiar/x509"));
1767
+ var doDebug3 = false;
1747
1768
  var _crypto;
1748
1769
  var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
1749
1770
  if (typeof window === "undefined") {
1750
1771
  _crypto = import_crypto5.default;
1751
1772
  if (!_crypto?.subtle || ignoreCrypto) {
1752
1773
  _crypto = new import_webcrypto.Crypto();
1753
- console.warn("using @peculiar/webcrypto");
1774
+ doDebug3 && console.warn("using @peculiar/webcrypto");
1754
1775
  } else {
1755
- console.warn("using nodejs crypto (native)");
1776
+ doDebug3 && console.warn("using nodejs crypto (native)");
1756
1777
  }
1757
1778
  x509.cryptoProvider.set(_crypto);
1758
1779
  } else {
1759
- console.warn("using browser crypto (native)");
1780
+ doDebug3 && console.warn("using browser crypto (native)");
1760
1781
  _crypto = crypto;
1761
1782
  x509.cryptoProvider.set(crypto);
1762
1783
  }
@@ -6166,7 +6187,7 @@ async function createSelfSignedCertificate({
6166
6187
 
6167
6188
  // source/x509/coerce_private_key.ts
6168
6189
  var crypto2 = getCrypto();
6169
- var doDebug3 = false;
6190
+ var doDebug4 = false;
6170
6191
  function coercePEMorDerToPrivateKey(privateKeyInDerOrPem) {
6171
6192
  if (typeof privateKeyInDerOrPem === "string") {
6172
6193
  const hidden = createPrivateKeyFromNodeJSCrypto(privateKeyInDerOrPem);
@@ -6184,7 +6205,7 @@ async function _coercePrivateKey(privateKey) {
6184
6205
  const privateKey1 = await pemToPrivateKey(privateKey);
6185
6206
  return KeyObject4.from(privateKey1);
6186
6207
  } catch (err) {
6187
- doDebug3 && console.log(privateKey);
6208
+ doDebug4 && console.log(privateKey);
6188
6209
  throw err;
6189
6210
  }
6190
6211
  } else if (privateKey instanceof KeyObject4) {