node-opcua-crypto 4.9.4 → 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,523 +1,8 @@
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';
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_web.js';
3
+ import 'crypto';
4
+ import '@peculiar/x509';
5
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;
6
+ declare function exploreAsn1(buffer: Buffer): void;
59
7
 
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
- A3 = 163
152
- }
153
- interface BlockInfo {
154
- tag: TagType | number;
155
- position: number;
156
- length: number;
157
- }
158
- declare function readTag(buf: Buffer, pos: number): BlockInfo;
159
- declare function _readStruct(buf: Buffer, blockInfo: BlockInfo): BlockInfo[];
160
- declare function parseBitString(buffer: Buffer, start: number, end: number, maxLength: number): string;
161
- interface BitString {
162
- lengthInBits: number;
163
- lengthInBytes: number;
164
- data: Buffer;
165
- debug?: any;
166
- }
167
- declare function _readBitString(buffer: Buffer, block: BlockInfo): BitString;
168
- declare function formatBuffer2DigitHexWithColum(buffer: Buffer): string;
169
- declare function _readOctetString(buffer: Buffer, block: BlockInfo): Buffer;
170
- declare function _getBlock(buffer: Buffer, block: BlockInfo): Buffer;
171
- interface AlgorithmIdentifier {
172
- identifier: string;
173
- }
174
- declare function _readIntegerAsByteString(buffer: Buffer, block: BlockInfo): Buffer;
175
- declare function _readListOfInteger(buffer: Buffer): Buffer[];
176
- declare function _readObjectIdentifier(buffer: Buffer, block: BlockInfo): {
177
- oid: string;
178
- name: string;
179
- };
180
- declare function _readAlgorithmIdentifier(buffer: Buffer, block: BlockInfo): AlgorithmIdentifier;
181
- declare function _readECCAlgorithmIdentifier(buffer: Buffer, block: BlockInfo): AlgorithmIdentifier;
182
- type SignatureValue = string;
183
- declare function _readSignatureValueBin(buffer: Buffer, block: BlockInfo): Buffer;
184
- declare function _readSignatureValue(buffer: Buffer, block: BlockInfo): SignatureValue;
185
- declare function _readLongIntegerValue(buffer: Buffer, block: BlockInfo): Buffer;
186
- declare function _readIntegerValue(buffer: Buffer, block: BlockInfo): number;
187
- declare function _readBooleanValue(buffer: Buffer, block: BlockInfo): boolean;
188
- declare function _readVersionValue(buffer: Buffer, block: BlockInfo): number;
189
- declare function _readValue(buffer: Buffer, block: BlockInfo): any;
190
- interface DirectoryName {
191
- stateOrProvinceName?: string;
192
- localityName?: string;
193
- organizationName?: string;
194
- organizationUnitName?: string;
195
- commonName?: string;
196
- countryName?: string;
197
- }
198
- declare function compactDirectoryName(d: DirectoryName): string;
199
- declare function _readDirectoryName(buffer: Buffer, block: BlockInfo): DirectoryName;
200
- declare function _findBlockAtIndex(blocks: BlockInfo[], index: number): BlockInfo | null;
201
- declare function _readTime(buffer: Buffer, block: BlockInfo): any;
202
-
203
- /**
204
- * @module node_opcua_crypto
205
- */
206
-
207
- interface AttributeTypeAndValue {
208
- [key: string]: any;
209
- }
210
- interface Validity {
211
- notBefore: Date;
212
- notAfter: Date;
213
- }
214
- interface X509KeyUsage {
215
- digitalSignature: boolean;
216
- nonRepudiation: boolean;
217
- keyEncipherment: boolean;
218
- dataEncipherment: boolean;
219
- keyAgreement: boolean;
220
- keyCertSign: boolean;
221
- cRLSign: boolean;
222
- encipherOnly: boolean;
223
- decipherOnly: boolean;
224
- }
225
- interface X509ExtKeyUsage {
226
- clientAuth: boolean;
227
- serverAuth: boolean;
228
- codeSigning: boolean;
229
- emailProtection: boolean;
230
- timeStamping: boolean;
231
- ocspSigning: boolean;
232
- ipsecEndSystem: boolean;
233
- ipsecTunnel: boolean;
234
- ipsecUser: boolean;
235
- }
236
- interface SubjectPublicKey {
237
- modulus: Buffer;
238
- }
239
- declare function _readExtension(buffer: Buffer, block: BlockInfo): {
240
- identifier: {
241
- oid: string;
242
- name: string;
243
- };
244
- value: any;
245
- };
246
- interface SubjectPublicKeyInfo {
247
- algorithm: string;
248
- keyLength: PublicKeyLength;
249
- subjectPublicKey: SubjectPublicKey;
250
- }
251
- interface BasicConstraints {
252
- critical: boolean;
253
- cA: boolean;
254
- pathLengthConstraint?: number;
255
- }
256
- interface AuthorityKeyIdentifier {
257
- keyIdentifier: string | null;
258
- authorityCertIssuer: DirectoryName | null;
259
- authorityCertIssuerFingerPrint: string;
260
- serial: string | null;
261
- }
262
- interface CertificateExtension {
263
- basicConstraints: BasicConstraints;
264
- subjectKeyIdentifier?: string;
265
- authorityKeyIdentifier?: AuthorityKeyIdentifier;
266
- keyUsage?: X509KeyUsage;
267
- extKeyUsage?: X509ExtKeyUsage;
268
- subjectAltName?: any;
269
- }
270
- interface TbsCertificate {
271
- version: number;
272
- serialNumber: string;
273
- issuer: any;
274
- signature: AlgorithmIdentifier;
275
- validity: Validity;
276
- subject: DirectoryName;
277
- subjectFingerPrint: string;
278
- subjectPublicKeyInfo: SubjectPublicKeyInfo;
279
- extensions: CertificateExtension | null;
280
- }
281
- declare function readTbsCertificate(buffer: Buffer, block: BlockInfo): TbsCertificate;
282
- interface CertificateInternals {
283
- tbsCertificate: TbsCertificate;
284
- signatureAlgorithm: AlgorithmIdentifier;
285
- signatureValue: SignatureValue;
286
- }
287
- /**
288
- * explore a certificate structure
289
- * @param certificate
290
- * @returns a json object that exhibits the internal data of the certificate
291
- */
292
- declare function exploreCertificate(certificate: Certificate): CertificateInternals;
293
- /**
294
- * @method split_der
295
- * split a multi chain certificates
296
- * @param certificateChain the certificate chain in der (binary) format}
297
- * @returns an array of Der , each element of the array is one certificate of the chain
298
- */
299
- declare function split_der(certificateChain: Certificate): Certificate[];
300
- /**
301
- * @method combine_der
302
- * combine an array of certificates into a single blob
303
- * @param certificates a array with the individual DER certificates of the chain
304
- * @return a concatenated buffer containing the certificates
305
- */
306
- declare function combine_der(certificates: Certificate[]): Certificate;
307
-
308
- type PublicKeyLength = 64 | 96 | 128 | 256 | 384 | 512;
309
- /**
310
- * A structure exposing useful information about a certificate
311
- */
312
- interface CertificateInfo {
313
- /** the public key length in bits */
314
- publicKeyLength: PublicKeyLength;
315
- /** the date at which the certificate starts to be valid */
316
- notBefore: Date;
317
- /** the date after which the certificate is not valid any more */
318
- notAfter: Date;
319
- /** info about certificate owner */
320
- subject: DirectoryName;
321
- /** public key */
322
- publicKey: SubjectPublicKey;
323
- }
324
- declare function coerceCertificate(certificate: Certificate | CertificatePEM): Certificate;
325
- /**
326
- * @method exploreCertificateInfo
327
- * returns useful information about the certificate such as public key length, start date and end of validity date,
328
- * and CN
329
- * @param certificate the certificate to explore
330
- */
331
- declare function exploreCertificateInfo(certificate: Certificate | CertificatePEM): CertificateInfo;
332
-
333
- /***
334
- * @method rsaLengthPrivateKey
335
- * A very expensive way to determine the rsa key length ( i.e 2048bits or 1024bits)
336
- * @param key a PEM public key or a PEM rsa private key
337
- * @return the key length in bytes.
338
- */
339
- declare function rsaLengthPrivateKey(key: PrivateKey): number;
340
- /**
341
- * @method toPem2
342
- * @param raw_key
343
- * @param pem
344
- *
345
- *
346
- * @return a PEM string containing the Private Key
347
- *
348
- * Note: a Pem key can be converted back to a private key object using coercePrivateKey
349
- *
350
- */
351
- declare function toPem2(raw_key: Buffer | string | KeyObject | PrivateKey, pem: string): string;
352
- declare function coercePrivateKeyPem(privateKey: PrivateKey): PrivateKeyPEM;
353
- declare function coercePublicKeyPem(publicKey: PublicKey | PublicKeyPEM): PublicKeyPEM;
354
- declare function coerceRsaPublicKeyPem(publicKey: PublicKey | KeyObject | PublicKeyPEM): PublicKeyPEM;
355
- declare function rsaLengthPublicKey(key: PublicKeyPEM | PublicKey): number;
356
- declare function rsaLengthRsaPublicKey(key: PublicKeyPEM | PublicKey): number;
357
-
358
- declare function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean;
359
- declare function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean;
360
- declare function verifyCertificateRevocationListSignature(certificateRevocationList: Certificate, parentCertificate: Certificate): boolean;
361
- type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
362
- declare function verifyCertificateChain(certificateChain: Certificate[]): Promise<{
363
- status: _VerifyStatus;
364
- reason: string;
365
- }>;
366
-
367
- type Version = string;
368
- type Name = string;
369
- type CertificateSerialNumber = string;
370
- type Extensions = Record<string, unknown>;
371
- interface RevokedCertificate {
372
- userCertificate: CertificateSerialNumber;
373
- revocationDate: Date;
374
- crlEntryExtensions?: Extensions;
375
- }
376
- interface TBSCertList {
377
- version?: Version;
378
- signature: AlgorithmIdentifier;
379
- issuer: Name;
380
- issuerFingerprint: string;
381
- thisUpdate: Date;
382
- nextUpdate?: Date;
383
- revokedCertificates: RevokedCertificate[];
384
- }
385
- interface CertificateRevocationListInfo {
386
- tbsCertList: TBSCertList;
387
- signatureAlgorithm: AlgorithmIdentifier;
388
- signatureValue: Buffer;
389
- }
390
- declare function readNameForCrl(buffer: Buffer, block: BlockInfo): DirectoryName;
391
- declare function exploreCertificateRevocationList(crl: CertificateRevocationList): CertificateRevocationListInfo;
392
-
393
- interface ExtensionRequest {
394
- basicConstraints: BasicConstraints;
395
- keyUsage: X509KeyUsage;
396
- subjectAltName: any;
397
- }
398
- interface CertificateSigningRequestInfo {
399
- extensionRequest: ExtensionRequest;
400
- }
401
- declare function readCertificationRequestInfo(buffer: Buffer, block: BlockInfo): CertificateSigningRequestInfo;
402
- declare function exploreCertificateSigningRequest(crl: Buffer): CertificateSigningRequestInfo;
403
-
404
- interface PrivateKeyInternals {
405
- /***/
406
- version: Buffer;
407
- modulus: Buffer;
408
- publicExponent: Buffer;
409
- privateExponent: Buffer;
410
- prime1: Buffer;
411
- prime2: Buffer;
412
- exponent1: Buffer;
413
- exponent2: Buffer;
414
- }
415
- /**
416
- *
417
- * @param privateKey RSAPrivateKey ::= SEQUENCE {
418
- * version Version,
419
- * modulus INTEGER, -- n
420
- * publicExponent INTEGER, -- e
421
- * privateExponent INTEGER, -- d
422
- * prime1 INTEGER, -- p
423
- * prime2 INTEGER, -- q
424
- * exponent1 INTEGER, -- d mod (p-1)
425
- * exponent2 INTEGER, -- d mod (q-1)
426
- * coefficient INTEGER, -- (inverse of q) mod p
427
- * otherPrimeInfos OtherPrimeInfos OPTIONAL
428
- }
429
- */
430
- declare function explorePrivateKey(privateKey2: PrivateKey): PrivateKeyInternals;
431
-
432
- declare function publicKeyAndPrivateKeyMatches(certificate: Certificate, privateKey: PrivateKey): boolean;
433
- declare function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean;
434
-
435
- declare function generateKeyPair(modulusLength?: 1024 | 2048 | 3072 | 4096): Promise<CryptoKeyPair>;
436
- /**
437
- * generate a pair of private/public keys of length 1024,2048, 3072, or 4096 bits
438
- */
439
- declare function generatePrivateKey(modulusLength?: 1024 | 2048 | 3072 | 4096): Promise<CryptoKey>;
440
- /**
441
- * convert a CryptoKey to a PEM string
442
- */
443
- declare function privateKeyToPEM(privateKey: CryptoKey): Promise<{
444
- privPem: string;
445
- privDer: ArrayBuffer;
446
- }>;
447
- declare function derToPrivateKey(privDer: ArrayBuffer): Promise<CryptoKey>;
448
- declare function pemToPrivateKey(pem: string): Promise<CryptoKey>;
449
-
450
- interface CreateCertificateSigningRequestOptions {
451
- privateKey: CryptoKey;
452
- notBefore?: Date;
453
- notAfter?: Date;
454
- validity?: number;
455
- subject?: string;
456
- dns?: string[];
457
- ip?: string[];
458
- applicationUri?: string;
459
- purpose: CertificatePurpose;
460
- }
461
- declare function createCertificateSigningRequest({ privateKey, subject, dns, ip, applicationUri, purpose, }: CreateCertificateSigningRequestOptions): Promise<{
462
- csr: string;
463
- der: x509.Pkcs10CertificateRequest;
464
- }>;
465
-
466
- interface CreateSelfSignCertificateOptions {
467
- privateKey: CryptoKey;
468
- notBefore?: Date;
469
- notAfter?: Date;
470
- validity?: number;
471
- subject?: string;
472
- dns?: string[];
473
- ip?: string[];
474
- applicationUri?: string;
475
- purpose: CertificatePurpose;
476
- }
477
- /**
478
- *
479
- * construct a self-signed certificate
480
- */
481
- declare function createSelfSignedCertificate({ privateKey, notAfter, notBefore, validity, subject, dns, ip, applicationUri, purpose, }: CreateSelfSignCertificateOptions): Promise<{
482
- cert: string;
483
- der: x509.X509Certificate;
484
- }>;
485
-
486
- declare function coercePEMorDerToPrivateKey(privateKeyInDerOrPem: string | Buffer): PrivateKey;
487
- /**
488
- *
489
- * @private
490
- */
491
- declare function _coercePrivateKey(privateKey: any): Promise<KeyObject>;
492
-
493
- interface SubjectOptions {
494
- commonName?: string;
495
- organization?: string;
496
- organizationalUnit?: string;
497
- locality?: string;
498
- state?: string;
499
- country?: string;
500
- domainComponent?: string;
501
- }
502
- /**
503
- * subjectName The subject name to use for the Certificate.
504
- * If not specified the ApplicationName and/or domainNames are used to create a suitable default value.
505
- */
506
- declare class Subject implements SubjectOptions {
507
- readonly commonName?: string;
508
- readonly organization?: string;
509
- readonly organizationalUnit?: string;
510
- readonly locality?: string;
511
- readonly state?: string;
512
- readonly country?: string;
513
- readonly domainComponent?: string;
514
- constructor(options: SubjectOptions | string);
515
- static parse(str: string): SubjectOptions;
516
- toStringInternal(sep: string): string;
517
- toStringForOPCUA(): string;
518
- toString(): string;
519
- }
520
-
521
- declare function makePrivateKeyFromPem(privateKeyInPem: string): PrivateKey;
522
-
523
- 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 };
8
+ export { exploreAsn1 };
@@ -75,6 +75,7 @@ __export(source_exports, {
75
75
  decryptBufferWithDerivedKeys: () => decryptBufferWithDerivedKeys,
76
76
  derToPrivateKey: () => derToPrivateKey,
77
77
  encryptBufferWithDerivedKeys: () => encryptBufferWithDerivedKeys,
78
+ exploreAsn1: () => exploreAsn1,
78
79
  exploreCertificate: () => exploreCertificate,
79
80
  exploreCertificateInfo: () => exploreCertificateInfo,
80
81
  exploreCertificateRevocationList: () => exploreCertificateRevocationList,
@@ -229,6 +230,7 @@ var oid_map = {
229
230
  "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
231
  "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
232
  "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)" },
233
+ "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
234
  "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
235
  "1.3.6.1.5.5.7.3.1": { d: "serverAuth", c: "PKIX key purpose" },
234
236
  "1.3.6.1.5.5.7.3.2": { d: "clientAuth", c: "PKIX key purpose" },
@@ -488,12 +490,15 @@ var TagType = /* @__PURE__ */ ((TagType3) => {
488
490
  TagType3[TagType3["BMPString"] = 30] = "BMPString";
489
491
  TagType3[TagType3["SEQUENCE"] = 48] = "SEQUENCE";
490
492
  TagType3[TagType3["SET"] = 49] = "SET";
491
- TagType3[TagType3["A3"] = 163] = "A3";
493
+ TagType3[TagType3["CONTEXT_SPECIFIC0"] = 160] = "CONTEXT_SPECIFIC0";
494
+ TagType3[TagType3["CONTEXT_SPECIFIC1"] = 161] = "CONTEXT_SPECIFIC1";
495
+ TagType3[TagType3["CONTEXT_SPECIFIC2"] = 162] = "CONTEXT_SPECIFIC2";
496
+ TagType3[TagType3["CONTEXT_SPECIFIC3"] = 163] = "CONTEXT_SPECIFIC3";
497
+ TagType3[TagType3["A4"] = 164] = "A4";
492
498
  return TagType3;
493
499
  })(TagType || {});
494
500
  function readTag(buf, pos) {
495
- (0, import_assert.default)(buf instanceof Buffer);
496
- (0, import_assert.default)(Number.isFinite(pos) && pos >= 0);
501
+ const start = pos;
497
502
  if (buf.length <= pos) {
498
503
  throw new Error("Invalid position : buf.length=" + buf.length + " pos =" + pos);
499
504
  }
@@ -509,7 +514,7 @@ function readTag(buf, pos) {
509
514
  pos += 1;
510
515
  }
511
516
  }
512
- return { tag, position: pos, length };
517
+ return { start, tag, position: pos, length };
513
518
  }
514
519
  function _readStruct(buf, blockInfo) {
515
520
  const length = blockInfo.length;
@@ -574,8 +579,8 @@ function _readIntegerAsByteString(buffer, block) {
574
579
  function _readListOfInteger(buffer) {
575
580
  const block = readTag(buffer, 0);
576
581
  const inner_blocks = _readStruct(buffer, block);
577
- return inner_blocks.map((bblock) => {
578
- return _readIntegerAsByteString(buffer, bblock);
582
+ return inner_blocks.map((innerBlock) => {
583
+ return _readIntegerAsByteString(buffer, innerBlock);
579
584
  });
580
585
  }
581
586
  function parseOID(buffer, start, end) {
@@ -838,7 +843,8 @@ function _readGeneralNames(buffer, block) {
838
843
  5: { name: "ediPartyName", type: "EDIPartyName" },
839
844
  6: { name: "uniformResourceIdentifier", type: "IA5String" },
840
845
  7: { name: "iPAddress", type: "OCTET_STRING" },
841
- 8: { name: "registeredID", type: "OBJECT_IDENTIFIER" }
846
+ 8: { name: "registeredID", type: "OBJECT_IDENTIFIER" },
847
+ 32: { name: "otherName", type: "AnotherName" }
842
848
  };
843
849
  const blocks = _readStruct(buffer, block);
844
850
  function _readFromType(buffer2, block2, type) {
@@ -852,13 +858,28 @@ function _readGeneralNames(buffer, block) {
852
858
  const n = {};
853
859
  for (const block2 of blocks) {
854
860
  (0, import_assert2.default)((block2.tag & 128) === 128);
855
- const t = block2.tag & 127;
856
- const type = _data[t];
861
+ const t2 = block2.tag & 127;
862
+ const type = _data[t2];
857
863
  if (!type) {
858
- throw new Error(" INVALID TYPE => " + t + "0x" + t.toString(16));
864
+ console.log("_readGeneralNames: INVALID TYPE => " + t2 + " 0x" + t2.toString(16));
865
+ continue;
866
+ }
867
+ if (t2 == 32) {
868
+ n[type.name] = n[type.name] || [];
869
+ const blocks2 = _readStruct(buffer, block2);
870
+ const name = _readObjectIdentifier(buffer, blocks2[0]).name;
871
+ const buf = _getBlock(buffer, blocks2[1]);
872
+ const b = readTag(buf, 0);
873
+ const nn = _readValue(buf, b);
874
+ const data = {
875
+ identifier: name,
876
+ value: nn
877
+ };
878
+ n[type.name].push(data.value);
879
+ } else {
880
+ n[type.name] = n[type.name] || [];
881
+ n[type.name].push(_readFromType(buffer, block2, type.type));
859
882
  }
860
- n[type.name] = n[type.name] || [];
861
- n[type.name].push(_readFromType(buffer, block2, type.type));
862
883
  }
863
884
  return n;
864
885
  }
@@ -1895,8 +1916,8 @@ var Subject = class _Subject {
1895
1916
  return this.toStringInternal("/");
1896
1917
  }
1897
1918
  toString() {
1898
- const t = this.toStringForOPCUA();
1899
- return t ? "/" + t : t;
1919
+ const t2 = this.toStringForOPCUA();
1920
+ return t2 ? "/" + t2 : t2;
1900
1921
  }
1901
1922
  };
1902
1923
 
@@ -6194,6 +6215,33 @@ async function _coercePrivateKey(privateKey) {
6194
6215
  throw new Error("Invalid privateKey");
6195
6216
  }
6196
6217
 
6218
+ // source/explore_asn1.ts
6219
+ function t(tag) {
6220
+ return TagType[tag];
6221
+ }
6222
+ function bi(blockInfo, depth) {
6223
+ const indent = " ".repeat(depth);
6224
+ const hl = blockInfo.position - blockInfo.start;
6225
+ return `${blockInfo.start.toString().padStart(5, " ")}:d=${depth} hl=${hl.toString().padEnd(3, " ")} l=${blockInfo.length.toString().padStart(6, " ")} ${blockInfo.tag.toString(16).padEnd(2, " ")} ${indent} ${t(blockInfo.tag)}`;
6226
+ }
6227
+ function exploreAsn1(buffer) {
6228
+ console.log(hexDump(buffer));
6229
+ function dump(offset, depth) {
6230
+ const blockInfo = readTag(buffer, offset);
6231
+ dumpBlock(blockInfo, depth);
6232
+ function dumpBlock(blockInfo2, depth2) {
6233
+ console.log(bi(blockInfo2, depth2));
6234
+ if (blockInfo2.tag === 48 /* SEQUENCE */ || blockInfo2.tag === 49 /* SET */ || blockInfo2.tag >= 160 /* CONTEXT_SPECIFIC0 */) {
6235
+ const blocks = _readStruct(buffer, blockInfo2);
6236
+ for (const block of blocks) {
6237
+ dumpBlock(block, depth2 + 1);
6238
+ }
6239
+ }
6240
+ }
6241
+ }
6242
+ dump(0, 0);
6243
+ }
6244
+
6197
6245
  // source/make_private_key_from_pem.ts
6198
6246
  function makePrivateKeyFromPem(privateKeyInPem) {
6199
6247
  return { hidden: privateKeyInPem };
@@ -6245,6 +6293,7 @@ function makePrivateKeyFromPem(privateKeyInPem) {
6245
6293
  decryptBufferWithDerivedKeys,
6246
6294
  derToPrivateKey,
6247
6295
  encryptBufferWithDerivedKeys,
6296
+ exploreAsn1,
6248
6297
  exploreCertificate,
6249
6298
  exploreCertificateInfo,
6250
6299
  exploreCertificateRevocationList,