node-opcua-crypto-web 6.2.5 → 6.4.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.
- package/dist/index_web.d.ts +197 -42
- package/dist/index_web.js +333 -54
- package/package.json +3 -3
package/dist/index_web.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import __crypto, { KeyLike } from 'node:crypto';
|
|
2
2
|
import * as x509 from '@peculiar/x509';
|
|
3
|
-
import { PublicKeyType, X509CrlReason } from '@peculiar/x509';
|
|
3
|
+
import { PublicKeyType as PublicKeyType$1, X509CrlReason } from '@peculiar/x509';
|
|
4
4
|
export { x509 };
|
|
5
5
|
import { Crypto as Crypto$1 } from '@peculiar/webcrypto';
|
|
6
6
|
|
|
@@ -208,31 +208,6 @@ declare function readAlgorithmIdentifier(buffer: Buffer, block: BlockInfo): Algo
|
|
|
208
208
|
type SignatureValue = string;
|
|
209
209
|
declare function readSignatureValueBin(buffer: Buffer, block: BlockInfo): Buffer;
|
|
210
210
|
|
|
211
|
-
type PublicKeyLength = 64 | 96 | 128 | 256 | 384 | 512;
|
|
212
|
-
/**
|
|
213
|
-
* A structure exposing useful information about a certificate
|
|
214
|
-
*/
|
|
215
|
-
interface CertificateInfo {
|
|
216
|
-
/** the public key length in bits */
|
|
217
|
-
publicKeyLength: PublicKeyLength;
|
|
218
|
-
/** the date at which the certificate starts to be valid */
|
|
219
|
-
notBefore: Date;
|
|
220
|
-
/** the date after which the certificate is not valid any more */
|
|
221
|
-
notAfter: Date;
|
|
222
|
-
/** info about certificate owner */
|
|
223
|
-
subject: DirectoryName;
|
|
224
|
-
/** public key */
|
|
225
|
-
publicKey: SubjectPublicKey;
|
|
226
|
-
}
|
|
227
|
-
declare function coerceCertificate(certificate: Certificate | CertificatePEM): Certificate;
|
|
228
|
-
/**
|
|
229
|
-
* @method exploreCertificateInfo
|
|
230
|
-
* returns useful information about the certificate such as public key length, start date and end of validity date,
|
|
231
|
-
* and CN
|
|
232
|
-
* @param certificate the certificate to explore
|
|
233
|
-
*/
|
|
234
|
-
declare function exploreCertificateInfo(certificate: Certificate | CertificatePEM): CertificateInfo;
|
|
235
|
-
|
|
236
211
|
/**
|
|
237
212
|
* @module node_opcua_crypto
|
|
238
213
|
*/
|
|
@@ -284,9 +259,43 @@ declare function readExtension(buffer: Buffer, block: BlockInfo): {
|
|
|
284
259
|
[key: string]: string[];
|
|
285
260
|
};
|
|
286
261
|
};
|
|
262
|
+
/**
|
|
263
|
+
* Read a SubjectPublicKeyInfo, whatever the algorithm of the key: its type,
|
|
264
|
+
* its curve when it has one, and its length. `block` is the block of the
|
|
265
|
+
* SubjectPublicKeyInfo SEQUENCE in `buffer`, as a certificate and a
|
|
266
|
+
* certificate signing request both carry one.
|
|
267
|
+
*/
|
|
268
|
+
declare function readSubjectPublicKeyInfo(buffer: Buffer, block: BlockInfo): SubjectPublicKeyInfo;
|
|
269
|
+
/** The family a certificate's public key belongs to. */
|
|
270
|
+
type PublicKeyType = "rsa" | "ec" | "ed25519" | "ed448" | "x25519" | "x448" | "unknown";
|
|
287
271
|
interface SubjectPublicKeyInfo {
|
|
272
|
+
/**
|
|
273
|
+
* For an RSA key, "rsaEncryption". For an elliptic curve key, the name
|
|
274
|
+
* of the curve (see {@link namedCurve}). Otherwise the name of the
|
|
275
|
+
* algorithm, e.g. "Ed25519", or its OID when it has no known name.
|
|
276
|
+
*/
|
|
288
277
|
algorithm: string;
|
|
289
|
-
|
|
278
|
+
/**
|
|
279
|
+
* The family of the key. `exploreCertificate` always sets it; it is
|
|
280
|
+
* optional only so that an object built by hand stays valid.
|
|
281
|
+
*/
|
|
282
|
+
keyType?: PublicKeyType;
|
|
283
|
+
/** The curve of an elliptic curve key, e.g. "prime256v1" or "brainpoolP384r1". */
|
|
284
|
+
namedCurve?: string;
|
|
285
|
+
/**
|
|
286
|
+
* In bytes. RSA: the modulus. Elliptic curve: the two coordinates of the
|
|
287
|
+
* public point, so twice the size of the curve (64 for a 256-bit curve),
|
|
288
|
+
* also when the certificate stores the point compressed.
|
|
289
|
+
* Otherwise: the raw public key.
|
|
290
|
+
*
|
|
291
|
+
* The number alone does not tell the family of the key: 128 is an RSA
|
|
292
|
+
* 1024-bit key and also a brainpoolP512r1 key. Read {@link keyType}.
|
|
293
|
+
*/
|
|
294
|
+
keyLength: number;
|
|
295
|
+
/**
|
|
296
|
+
* RSA: the modulus. Otherwise the public key bits as the certificate
|
|
297
|
+
* stores them (for an elliptic curve, the point with its form byte).
|
|
298
|
+
*/
|
|
290
299
|
subjectPublicKey: SubjectPublicKey;
|
|
291
300
|
}
|
|
292
301
|
interface BasicConstraints {
|
|
@@ -366,6 +375,50 @@ declare function combine_der(certificates: Certificate[]): Certificate;
|
|
|
366
375
|
|
|
367
376
|
declare function exploreAsn1(buffer: Buffer): void;
|
|
368
377
|
|
|
378
|
+
/**
|
|
379
|
+
* The length, in bytes, of a public key that {@link exploreCertificateInfo}
|
|
380
|
+
* accepts: 128, 256, 384 or 512 for RSA (1024 to 4096 bits); 64, 96, 128 or
|
|
381
|
+
* 132 for an elliptic curve (twice the curve size); 32 or 57 for Ed25519 and
|
|
382
|
+
* Ed448.
|
|
383
|
+
*
|
|
384
|
+
* The number alone does not tell the family of the key: 128 is an RSA
|
|
385
|
+
* 1024-bit key and also a brainpoolP512r1 key. Read `keyType`.
|
|
386
|
+
*/
|
|
387
|
+
type PublicKeyLength = 32 | 57 | 64 | 96 | 128 | 132 | 256 | 384 | 512;
|
|
388
|
+
/**
|
|
389
|
+
* A structure exposing useful information about a certificate
|
|
390
|
+
*/
|
|
391
|
+
interface CertificateInfo {
|
|
392
|
+
/** the public key length in bytes, see {@link PublicKeyLength} */
|
|
393
|
+
publicKeyLength: PublicKeyLength;
|
|
394
|
+
/** the family of the public key; publicKeyLength does not tell it (128 is RSA 1024 and brainpoolP512r1) */
|
|
395
|
+
keyType?: PublicKeyType;
|
|
396
|
+
/** the curve of an elliptic curve key, e.g. "prime256v1" */
|
|
397
|
+
namedCurve?: string;
|
|
398
|
+
/** the date at which the certificate starts to be valid */
|
|
399
|
+
notBefore: Date;
|
|
400
|
+
/** the date after which the certificate is not valid any more */
|
|
401
|
+
notAfter: Date;
|
|
402
|
+
/** info about certificate owner */
|
|
403
|
+
subject: DirectoryName;
|
|
404
|
+
/** public key */
|
|
405
|
+
publicKey: SubjectPublicKey;
|
|
406
|
+
}
|
|
407
|
+
declare function coerceCertificate(certificate: Certificate | CertificatePEM): Certificate;
|
|
408
|
+
/**
|
|
409
|
+
* @method exploreCertificateInfo
|
|
410
|
+
* returns useful information about the certificate such as public key length, start date and end of validity date,
|
|
411
|
+
* and CN
|
|
412
|
+
*
|
|
413
|
+
* Throws when the public key is not one an application certificate can
|
|
414
|
+
* carry: an RSA key that is not 1024, 2048, 3072 or 4096 bits, an elliptic
|
|
415
|
+
* curve other than the NIST and brainpool curves of 256 bits and more, or
|
|
416
|
+
* an algorithm other than RSA, elliptic curve, Ed25519 and Ed448.
|
|
417
|
+
* `exploreCertificate` describes such a certificate without throwing.
|
|
418
|
+
* @param certificate the certificate to explore
|
|
419
|
+
*/
|
|
420
|
+
declare function exploreCertificateInfo(certificate: Certificate | CertificatePEM): CertificateInfo;
|
|
421
|
+
|
|
369
422
|
type Version = string;
|
|
370
423
|
/**
|
|
371
424
|
* A Name is an RDNSequence, not a string.
|
|
@@ -430,11 +483,38 @@ interface ExtensionRequest {
|
|
|
430
483
|
subjectAltName: SubjectAltName;
|
|
431
484
|
}
|
|
432
485
|
interface CertificateSigningRequestInfo {
|
|
486
|
+
/**
|
|
487
|
+
* The extensions the requester asks for. A request can carry none: the
|
|
488
|
+
* object is then empty, and so are its three members.
|
|
489
|
+
*/
|
|
433
490
|
extensionRequest: ExtensionRequest;
|
|
491
|
+
/** The subject the requester asks for. */
|
|
492
|
+
subject: DirectoryName;
|
|
493
|
+
/** The public key of the requester: its type, its curve, its length. */
|
|
494
|
+
subjectPublicKeyInfo: SubjectPublicKeyInfo;
|
|
495
|
+
/**
|
|
496
|
+
* The algorithm of the signature the request carries over itself, e.g.
|
|
497
|
+
* "ecdsaWithSHA384". {@link exploreCertificateSigningRequest} sets it;
|
|
498
|
+
* {@link readCertificationRequestInfo} reads the inner part only, which
|
|
499
|
+
* does not hold it.
|
|
500
|
+
*/
|
|
501
|
+
signatureAlgorithm?: AlgorithmIdentifier;
|
|
434
502
|
}
|
|
503
|
+
/**
|
|
504
|
+
* CertificationRequestInfo ::= SEQUENCE {
|
|
505
|
+
* version INTEGER,
|
|
506
|
+
* subject Name,
|
|
507
|
+
* subjectPKInfo SubjectPublicKeyInfo,
|
|
508
|
+
* attributes [0] Attributes }
|
|
509
|
+
*/
|
|
435
510
|
declare function readCertificationRequestInfo(buffer: Buffer, block: BlockInfo): CertificateSigningRequestInfo;
|
|
436
511
|
declare function exploreCertificateSigningRequest(crl: Buffer): CertificateSigningRequestInfo;
|
|
437
512
|
|
|
513
|
+
/**
|
|
514
|
+
* The type of a private key, as Node names it: "rsa", "ec", "ed25519"...
|
|
515
|
+
* `undefined` when the platform cannot tell.
|
|
516
|
+
*/
|
|
517
|
+
declare function getPrivateKeyType(privateKey: PrivateKey): string | undefined;
|
|
438
518
|
interface PrivateKeyInternals {
|
|
439
519
|
/***/
|
|
440
520
|
version: Buffer;
|
|
@@ -508,6 +588,8 @@ type DERContentType = "X509Certificate" | "X509CertificateChain" | "CertificateR
|
|
|
508
588
|
*/
|
|
509
589
|
declare function identifyDERContent(buffer: Buffer): DERContentType;
|
|
510
590
|
|
|
591
|
+
declare function getCrypto(): Crypto$1 | typeof __crypto;
|
|
592
|
+
|
|
511
593
|
/**
|
|
512
594
|
* The signing algorithm a {@link CaSigner} operates under. This travels with
|
|
513
595
|
* the signer rather than being inferred from a key, because an HSM/KMS-backed
|
|
@@ -528,14 +610,21 @@ type CaSignAlgorithm = {
|
|
|
528
610
|
* *import* the signer's public key, and `importKey` cannot infer a
|
|
529
611
|
* curve it was not given. Declaring it wrong is safe: the SPKI
|
|
530
612
|
* bytes returned by {@link CaSigner.getPublicKey} state the real
|
|
531
|
-
* curve,
|
|
532
|
-
* signs into the void.
|
|
613
|
+
* curve, and a signer whose key is on another curve is refused
|
|
614
|
+
* rather than producing a key that signs into the void.
|
|
533
615
|
*/
|
|
534
|
-
namedCurve:
|
|
616
|
+
namedCurve: EcdsaCurveName;
|
|
535
617
|
hash: {
|
|
536
618
|
name: "SHA-256" | "SHA-384" | "SHA-512";
|
|
537
619
|
};
|
|
538
620
|
};
|
|
621
|
+
/**
|
|
622
|
+
* The curves an ECDSA {@link CaSigner} can declare: the NIST curves under
|
|
623
|
+
* their WebCrypto names, and the brainpool curves of the OPC UA ECC security
|
|
624
|
+
* policies. WebCrypto knows the NIST curves only, so a brainpool signer is
|
|
625
|
+
* always backed by something else (`node:crypto`, an HSM).
|
|
626
|
+
*/
|
|
627
|
+
type EcdsaCurveName = "P-256" | "P-384" | "P-521" | "brainpoolP256r1" | "brainpoolP384r1" | "brainpoolP512r1";
|
|
539
628
|
/**
|
|
540
629
|
* Abstraction over "something that can produce a certificate/CRL signature",
|
|
541
630
|
* without ever exposing private key material.
|
|
@@ -595,7 +684,7 @@ interface CaSigner {
|
|
|
595
684
|
* @param namedCurve the curve the signing key lives on, which fixes the
|
|
596
685
|
* width each coordinate is padded to
|
|
597
686
|
*/
|
|
598
|
-
declare function ecdsaSignatureDerToP1363(derSignature: BufferSource, namedCurve:
|
|
687
|
+
declare function ecdsaSignatureDerToP1363(derSignature: BufferSource, namedCurve: EcdsaCurveName): ArrayBuffer;
|
|
599
688
|
/**
|
|
600
689
|
* Adapts an in-process key pair (e.g. one produced by {@link generateKeyPair}
|
|
601
690
|
* or read from disk via {@link pemToPrivateKey}) to the {@link CaSigner}
|
|
@@ -634,8 +723,19 @@ interface WebCryptoFromSigner {
|
|
|
634
723
|
* anything other than the paired {@link crypto} object.
|
|
635
724
|
*/
|
|
636
725
|
privateKeyHandle: CryptoKey;
|
|
637
|
-
/**
|
|
726
|
+
/**
|
|
727
|
+
* The signer's public key, to pass as `keys.publicKey` to a generator
|
|
728
|
+
* together with the paired {@link crypto} object.
|
|
729
|
+
*
|
|
730
|
+
* For an RSA key or a key on a NIST curve it is a real `CryptoKey`,
|
|
731
|
+
* imported from the signer's SPKI bytes. WebCrypto cannot import a key
|
|
732
|
+
* on a brainpool curve: it is then an opaque handle, which the paired
|
|
733
|
+
* {@link crypto} object knows how to export and nothing else can use.
|
|
734
|
+
* Code that needs the key itself reads {@link x509PublicKey}.
|
|
735
|
+
*/
|
|
638
736
|
publicKey: CryptoKey;
|
|
737
|
+
/** The signer's public key as `@peculiar/x509` reads it from the SPKI bytes, for every key type. */
|
|
738
|
+
x509PublicKey: x509.PublicKey;
|
|
639
739
|
}
|
|
640
740
|
/**
|
|
641
741
|
* Build a `Crypto`-shaped adapter that routes signing through `signer`
|
|
@@ -679,7 +779,10 @@ interface ResolvedCaKeyPair {
|
|
|
679
779
|
* Resolves a `CryptoKey | CaSigner` into the key pair and per-call `crypto`
|
|
680
780
|
* a CSR or self-signed-certificate generator needs.
|
|
681
781
|
*
|
|
682
|
-
* For a raw `CryptoKey` the public half is derived from the private one
|
|
782
|
+
* For a raw `CryptoKey` the public half is derived from the private one,
|
|
783
|
+
* and the signing algorithm is read from the key: RSASSA-PKCS1-v1_5 with
|
|
784
|
+
* SHA-256 for an RSA key, ECDSA with the hash of its curve for an elliptic
|
|
785
|
+
* curve key.
|
|
683
786
|
* For a {@link CaSigner} it comes from `getPublicKey()` — the only way to
|
|
684
787
|
* obtain it when the private key lives in an HSM and cannot be exported.
|
|
685
788
|
*/
|
|
@@ -883,15 +986,13 @@ declare function verifyCertificateChain(certificateChain: Certificate[]): Promis
|
|
|
883
986
|
reason: string;
|
|
884
987
|
}>;
|
|
885
988
|
|
|
886
|
-
declare function getCrypto(): Crypto$1 | typeof __crypto;
|
|
887
|
-
|
|
888
989
|
/**
|
|
889
990
|
* Authority Key Identifier extension identifying the issuer by its public
|
|
890
991
|
* key (`keyid`), matching what {@link createSelfSignedCertificate} already
|
|
891
992
|
* does for the self-signed case, and what openssl's
|
|
892
993
|
* `authorityKeyIdentifier = keyid:always` produces for the issued case.
|
|
893
994
|
*/
|
|
894
|
-
declare function buildAuthorityKeyIdentifierFromIssuer(issuerPublicKey: PublicKeyType, crypto?: Crypto): Promise<x509.AuthorityKeyIdentifierExtension>;
|
|
995
|
+
declare function buildAuthorityKeyIdentifierFromIssuer(issuerPublicKey: PublicKeyType$1, crypto?: Crypto): Promise<x509.AuthorityKeyIdentifierExtension>;
|
|
895
996
|
/** Opt-in CRL Distribution Point / Authority Info Access URLs for a certificate. */
|
|
896
997
|
interface RevocationExtensionsParams {
|
|
897
998
|
crlDistributionUrl?: string;
|
|
@@ -936,7 +1037,7 @@ interface CreateCertificateFromCsrOptions {
|
|
|
936
1037
|
*/
|
|
937
1038
|
issuerName: x509.X509CertificateCreateParamsName;
|
|
938
1039
|
/** The issuing CA's public key, used to derive the Authority Key Identifier extension. */
|
|
939
|
-
issuerPublicKey: PublicKeyType;
|
|
1040
|
+
issuerPublicKey: PublicKeyType$1;
|
|
940
1041
|
/** The issuing CA's signing key — a raw key, or an HSM/KMS-backed {@link CaSigner}. */
|
|
941
1042
|
signingKey: CryptoKey | CaSigner;
|
|
942
1043
|
signingAlgorithm: CaSignAlgorithm;
|
|
@@ -1003,7 +1104,7 @@ interface CreateCrlOptions {
|
|
|
1003
1104
|
*/
|
|
1004
1105
|
issuerName: x509.X509CertificateCreateParamsName;
|
|
1005
1106
|
/** The issuing CA's public key, used to derive the Authority Key Identifier extension. */
|
|
1006
|
-
issuerPublicKey: PublicKeyType;
|
|
1107
|
+
issuerPublicKey: PublicKeyType$1;
|
|
1007
1108
|
/** The issuing CA's signing key — a raw key, or an HSM/KMS-backed {@link CaSigner}. */
|
|
1008
1109
|
signingKey: CryptoKey | CaSigner;
|
|
1009
1110
|
signingAlgorithm: CaSignAlgorithm;
|
|
@@ -1023,11 +1124,47 @@ declare function createCrl(options: CreateCrlOptions): Promise<{
|
|
|
1023
1124
|
der: ArrayBuffer;
|
|
1024
1125
|
}>;
|
|
1025
1126
|
|
|
1026
|
-
declare function generateKeyPair(modulusLength?: 1024 | 2048 | 3072 | 4096): Promise<CryptoKeyPair>;
|
|
1027
1127
|
/**
|
|
1028
|
-
*
|
|
1128
|
+
* The elliptic curves a key can be generated on, under the names that
|
|
1129
|
+
* OpenSSL uses and that `exploreCertificate` reports in `namedCurve`.
|
|
1130
|
+
*/
|
|
1131
|
+
type EcNamedCurve = "prime256v1" | "secp384r1" | "secp521r1";
|
|
1132
|
+
/**
|
|
1133
|
+
* The brainpool curves of the OPC UA ECC security policies. WebCrypto does
|
|
1134
|
+
* not know them, so a key on one of them is made and used through
|
|
1135
|
+
* `node:crypto`: see `generatePrivateKeyFile` and `caSignerFromPrivateKey`
|
|
1136
|
+
* of the Node.js build.
|
|
1137
|
+
*/
|
|
1138
|
+
type BrainpoolNamedCurve = "brainpoolP256r1" | "brainpoolP384r1" | "brainpoolP512r1";
|
|
1139
|
+
/** Asks for an elliptic curve key where a number asks for an RSA key of that size. */
|
|
1140
|
+
interface EcPrivateKeyAlgorithm {
|
|
1141
|
+
type: "ec";
|
|
1142
|
+
namedCurve: EcNamedCurve;
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Asks for an elliptic curve key on any curve a certificate key can be on:
|
|
1146
|
+
* a NIST curve or a brainpool one. `generatePrivateKeyFile` of the Node.js
|
|
1147
|
+
* build takes it; `generateKeyPair`, which works through WebCrypto, takes
|
|
1148
|
+
* the narrower {@link EcPrivateKeyAlgorithm}.
|
|
1149
|
+
*/
|
|
1150
|
+
interface AnyCurvePrivateKeyAlgorithm {
|
|
1151
|
+
type: "ec";
|
|
1152
|
+
namedCurve: EcNamedCurve | BrainpoolNamedCurve;
|
|
1153
|
+
}
|
|
1154
|
+
type RsaModulusLength = 1024 | 2048 | 3072 | 4096;
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* generate a pair of private/public keys.
|
|
1158
|
+
*
|
|
1159
|
+
* A number asks for an RSA key of that length in bits;
|
|
1160
|
+
* `{ type: "ec", namedCurve: "prime256v1" }` asks for an elliptic curve key.
|
|
1161
|
+
*/
|
|
1162
|
+
declare function generateKeyPair(keyAlgorithm?: RsaModulusLength | EcPrivateKeyAlgorithm): Promise<CryptoKeyPair>;
|
|
1163
|
+
/**
|
|
1164
|
+
* generate a private key: RSA of length 1024, 2048, 3072 or 4096 bits,
|
|
1165
|
+
* or on an elliptic curve (see {@link generateKeyPair})
|
|
1029
1166
|
*/
|
|
1030
|
-
declare function generatePrivateKey(
|
|
1167
|
+
declare function generatePrivateKey(keyAlgorithm?: RsaModulusLength | EcPrivateKeyAlgorithm): Promise<CryptoKey>;
|
|
1031
1168
|
/**
|
|
1032
1169
|
* convert a CryptoKey to a PEM string
|
|
1033
1170
|
*/
|
|
@@ -1035,6 +1172,10 @@ declare function privateKeyToPEM(privateKey: CryptoKey): Promise<{
|
|
|
1035
1172
|
privPem: string;
|
|
1036
1173
|
privDer: ArrayBuffer;
|
|
1037
1174
|
}>;
|
|
1175
|
+
/**
|
|
1176
|
+
* import a PKCS#8 private key. The key says itself whether it is an RSA key
|
|
1177
|
+
* or an elliptic curve one, and on which curve.
|
|
1178
|
+
*/
|
|
1038
1179
|
declare function derToPrivateKey(privDer: ArrayBuffer): Promise<CryptoKey>;
|
|
1039
1180
|
declare function pemToPrivateKey(pem: string): Promise<CryptoKey>;
|
|
1040
1181
|
|
|
@@ -1257,7 +1398,21 @@ declare function makePrivateKeyFromPem(privateKeyInPem: string): PrivateKey;
|
|
|
1257
1398
|
|
|
1258
1399
|
declare function makePrivateKeyThumbPrint(_privateKey: PrivateKey): Buffer;
|
|
1259
1400
|
|
|
1401
|
+
/**
|
|
1402
|
+
* Tell if the public key of the certificate is the public half of the
|
|
1403
|
+
* private key, by comparing the two (RSA modulus, or elliptic curve and
|
|
1404
|
+
* public point). A key of another type than the certificate's does not
|
|
1405
|
+
* match: the answer is false, not an exception. It throws when both are of
|
|
1406
|
+
* one type that is neither RSA nor elliptic curve.
|
|
1407
|
+
*/
|
|
1260
1408
|
declare function publicKeyAndPrivateKeyMatches(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
1409
|
+
/**
|
|
1410
|
+
* Tell if the certificate belongs to the private key, by using the two
|
|
1411
|
+
* together: an RSA key decrypts what the certificate encrypted, an elliptic
|
|
1412
|
+
* curve certificate verifies what the key signed. A key of another type than
|
|
1413
|
+
* the certificate's does not match: the answer is false, not an exception.
|
|
1414
|
+
* It throws when both are of one type that is neither RSA nor elliptic curve.
|
|
1415
|
+
*/
|
|
1261
1416
|
declare function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
1262
1417
|
|
|
1263
1418
|
declare const asn1: {
|
|
@@ -1268,4 +1423,4 @@ declare const asn1: {
|
|
|
1268
1423
|
readSignatureValueBin: typeof readSignatureValueBin;
|
|
1269
1424
|
};
|
|
1270
1425
|
|
|
1271
|
-
export { type AsymmetricDecryptParams, type AsymmetricSignParams, type AttributeTypeAndValue, type AuthorityInformationAccess, type AuthorityKeyIdentifier, type BasicConstraints, type CRLReason, type CaSignAlgorithm, type CaSigner, type Certificate, type CertificateExtension, type CertificateInfo, type CertificateInternals, type CertificatePEM, CertificatePurpose, type CertificateRevocationList, type CertificateRevocationListInfo, type CertificateSerialNumber, type CertificateSigningRequestInfo, type ComputeDerivedKeysOptions, type CreateCertificateFromCsrOptions, type CreateCrlEntryOptions, type CreateCrlOptions, type CreateSelfSignCertificateOptions, type CrlEntryExtensions, type DER, type DERContentType, type DerivedKeys, type DirectoryName, type DistinguishedNameAttribute, type ECPrivateKeyInternals, type ExtensionRequest, type Extensions, type IKeyOperations, type KeyExportOptions, type KeyMetadata, type KeyObject, LocalKeyOperations, LocalPrivateKeySigner, type Name, type Nonce, type PEM, PaddingAlgorithm, PfxIntegrityError, PfxMalformedError, Pkcs12UnsupportedAlgorithmError, type PrivateKey, type PrivateKeyInternals, type PrivateKeyPEM, PrivateKeyPassphraseRequiredError, PrivateKeyUnavailableError, type PublicKey, type PublicKeyLength, type PublicKeyPEM, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, type ResolvedCaKeyPair, type ResolvedCaSigningKey, type RevocationExtensionsParams, type RevokedCertificate, type Signature, Subject, type SubjectAltName, type SubjectOptions, type SubjectPublicKey, type SubjectPublicKeyInfo, type TBSCertList, type TbsCertificate, type Validity, type VerifyChunkSignatureOptions, type VerifyMessageChunkSignatureOptions, type Version, type WebCryptoFromSigner, type X509ExtKeyUsage, type X509KeyUsage, type _VerifyStatus, _coercePrivateKey, asn1, buildAuthorityKeyIdentifierFromIssuer, buildCrlNumberExtension, buildRevocationExtensions, caSignerFromKeyOperations, certificateMatchesPrivateKey, clearExploreCertificateCache, coerceCertificate, coerceCertificatePem, coercePEMorDerToPrivateKey, coercePrivateKeyPem, coercePublicKeyPem, coerceRsaPublicKeyPem, combine_der, computeDerivedKeys, computePaddingFooter, convertPEMtoDER, createCertificateFromCsr, createCertificateSigningRequest, createCrl, createPrivateKeyFromNodeJSCrypto, createSelfSignedCertificate, decryptBufferWithDerivedKeys, decryptLong, decryptLongSync, derToPrivateKey, ecdsaSignatureDerToP1363, encryptBufferWithDerivedKeys, exploreAsn1, exploreCertificate, exploreCertificateInfo, exploreCertificateRevocationList, exploreCertificateSigningRequest, exploreEcPrivateKey, explorePrivateKey, extractPublicKeyFromCertificate, extractPublicKeyFromCertificateSync, generateKeyPair, generatePrivateKey, getCrypto, hasSyncKeyOperations, hexDump, identifyDERContent, identifyPemType, isCaSigner, isCrlIssuedByCertificate, isKeyObject, isKeyOperations, keyOperationsFromPrivateKey, makeMessageChunkSignature, makeMessageChunkSignatureWithDerivedKeys, makePrivateKeyFromPem, makePrivateKeyThumbPrint, makePseudoRandomBuffer, makeSHA1Thumbprint, pemToPrivateKey, privateDecrypt, privateDecrypt_long, privateDecrypt_native, privateKeyToCryptoKey, privateKeyToPEM, publicEncrypt, publicEncrypt_long, publicEncrypt_native, publicKeyAndPrivateKeyMatches, readCertificationRequestInfo, readExtension, readNameForCrl, readTbsCertificate, reduceLength, removePadding, removeTrailingLF, resolveCaKeyPair, resolveCaSigningKey, rsaLengthPrivateKey, rsaLengthPublicKey, rsaLengthRsaPublicKey, split_der, toPem, toPem2, verifyCertificateChain, verifyCertificateOrClrSignature, verifyCertificateRevocationListSignature, verifyCertificateSignature, verifyChunkSignature, verifyChunkSignatureWithDerivedKeys, verifyCrlIssuedByCertificate, verifyMessageChunkSignature, verify_certificate_der_structure, webCryptoFromSigner };
|
|
1426
|
+
export { type AnyCurvePrivateKeyAlgorithm, type AsymmetricDecryptParams, type AsymmetricSignParams, type AttributeTypeAndValue, type AuthorityInformationAccess, type AuthorityKeyIdentifier, type BasicConstraints, type BrainpoolNamedCurve, type CRLReason, type CaSignAlgorithm, type CaSigner, type Certificate, type CertificateExtension, type CertificateInfo, type CertificateInternals, type CertificatePEM, CertificatePurpose, type CertificateRevocationList, type CertificateRevocationListInfo, type CertificateSerialNumber, type CertificateSigningRequestInfo, type ComputeDerivedKeysOptions, type CreateCertificateFromCsrOptions, type CreateCrlEntryOptions, type CreateCrlOptions, type CreateSelfSignCertificateOptions, type CrlEntryExtensions, type DER, type DERContentType, type DerivedKeys, type DirectoryName, type DistinguishedNameAttribute, type ECPrivateKeyInternals, type EcNamedCurve, type EcPrivateKeyAlgorithm, type EcdsaCurveName, type ExtensionRequest, type Extensions, type IKeyOperations, type KeyExportOptions, type KeyMetadata, type KeyObject, LocalKeyOperations, LocalPrivateKeySigner, type Name, type Nonce, type PEM, PaddingAlgorithm, PfxIntegrityError, PfxMalformedError, Pkcs12UnsupportedAlgorithmError, type PrivateKey, type PrivateKeyInternals, type PrivateKeyPEM, PrivateKeyPassphraseRequiredError, PrivateKeyUnavailableError, type PublicKey, type PublicKeyLength, type PublicKeyPEM, type PublicKeyType, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, type ResolvedCaKeyPair, type ResolvedCaSigningKey, type RevocationExtensionsParams, type RevokedCertificate, type RsaModulusLength, type Signature, Subject, type SubjectAltName, type SubjectOptions, type SubjectPublicKey, type SubjectPublicKeyInfo, type TBSCertList, type TbsCertificate, type Validity, type VerifyChunkSignatureOptions, type VerifyMessageChunkSignatureOptions, type Version, type WebCryptoFromSigner, type X509ExtKeyUsage, type X509KeyUsage, type _VerifyStatus, _coercePrivateKey, asn1, buildAuthorityKeyIdentifierFromIssuer, buildCrlNumberExtension, buildRevocationExtensions, caSignerFromKeyOperations, certificateMatchesPrivateKey, clearExploreCertificateCache, coerceCertificate, coerceCertificatePem, coercePEMorDerToPrivateKey, coercePrivateKeyPem, coercePublicKeyPem, coerceRsaPublicKeyPem, combine_der, computeDerivedKeys, computePaddingFooter, convertPEMtoDER, createCertificateFromCsr, createCertificateSigningRequest, createCrl, createPrivateKeyFromNodeJSCrypto, createSelfSignedCertificate, decryptBufferWithDerivedKeys, decryptLong, decryptLongSync, derToPrivateKey, ecdsaSignatureDerToP1363, encryptBufferWithDerivedKeys, exploreAsn1, exploreCertificate, exploreCertificateInfo, exploreCertificateRevocationList, exploreCertificateSigningRequest, exploreEcPrivateKey, explorePrivateKey, extractPublicKeyFromCertificate, extractPublicKeyFromCertificateSync, generateKeyPair, generatePrivateKey, getCrypto, getPrivateKeyType, hasSyncKeyOperations, hexDump, identifyDERContent, identifyPemType, isCaSigner, isCrlIssuedByCertificate, isKeyObject, isKeyOperations, keyOperationsFromPrivateKey, makeMessageChunkSignature, makeMessageChunkSignatureWithDerivedKeys, makePrivateKeyFromPem, makePrivateKeyThumbPrint, makePseudoRandomBuffer, makeSHA1Thumbprint, pemToPrivateKey, privateDecrypt, privateDecrypt_long, privateDecrypt_native, privateKeyToCryptoKey, privateKeyToPEM, publicEncrypt, publicEncrypt_long, publicEncrypt_native, publicKeyAndPrivateKeyMatches, readCertificationRequestInfo, readExtension, readNameForCrl, readSubjectPublicKeyInfo, readTbsCertificate, reduceLength, removePadding, removeTrailingLF, resolveCaKeyPair, resolveCaSigningKey, rsaLengthPrivateKey, rsaLengthPublicKey, rsaLengthRsaPublicKey, split_der, toPem, toPem2, verifyCertificateChain, verifyCertificateOrClrSignature, verifyCertificateRevocationListSignature, verifyCertificateSignature, verifyChunkSignature, verifyChunkSignatureWithDerivedKeys, verifyCrlIssuedByCertificate, verifyMessageChunkSignature, verify_certificate_der_structure, webCryptoFromSigner };
|
package/dist/index_web.js
CHANGED
|
@@ -46150,6 +46150,11 @@ var oid_map = {
|
|
|
46150
46150
|
"1.2.840.10045.3.1.5": { d: "prime239v2", c: "ANSI X9.62 named elliptic curve" },
|
|
46151
46151
|
"1.2.840.10045.3.1.6": { d: "prime239v3", c: "ANSI X9.62 named elliptic curve" },
|
|
46152
46152
|
"1.2.840.10045.3.1.7": { d: "prime256v1", c: "ANSI X9.62 named elliptic curve" },
|
|
46153
|
+
"1.2.840.10045.4.1": { d: "ecdsaWithSHA1", c: "ANSI X9.62 ECDSA algorithm with SHA1" },
|
|
46154
|
+
"1.2.840.10045.4.3.1": { d: "ecdsaWithSHA224", c: "ANSI X9.62 ECDSA algorithm with SHA224" },
|
|
46155
|
+
"1.2.840.10045.4.3.2": { d: "ecdsaWithSHA256", c: "ANSI X9.62 ECDSA algorithm with SHA256" },
|
|
46156
|
+
"1.2.840.10045.4.3.3": { d: "ecdsaWithSHA384", c: "ANSI X9.62 ECDSA algorithm with SHA384" },
|
|
46157
|
+
"1.2.840.10045.4.3.4": { d: "ecdsaWithSHA512", c: "ANSI X9.62 ECDSA algorithm with SHA512" },
|
|
46153
46158
|
"1.2.840.113549.1.1": { d: "pkcs-1", c: "", w: false },
|
|
46154
46159
|
"1.2.840.113549.1.1.1": { d: "rsaEncryption", c: "PKCS #1", w: false },
|
|
46155
46160
|
"1.2.840.113549.1.1.2": { d: "md2WithRSAEncryption", c: "PKCS #1", w: false },
|
|
@@ -46216,6 +46221,14 @@ var oid_map = {
|
|
|
46216
46221
|
"1.3.36.3.3.2.8.1.1.12": { d: "brainpoolP384t1", c: "ECC Brainpool Standard Curves and Curve Generation" },
|
|
46217
46222
|
"1.3.36.3.3.2.8.1.1.13": { d: "brainpoolP512r1", c: "ECC Brainpool Standard Curves and Curve Generation" },
|
|
46218
46223
|
"1.3.36.3.3.2.8.1.1.14": { d: "brainpoolP512t1", c: "ECC Brainpool Standard Curves and Curve Generation" },
|
|
46224
|
+
"1.3.101.110": { d: "X25519", c: "RFC 8410 key agreement algorithm" },
|
|
46225
|
+
"1.3.101.111": { d: "X448", c: "RFC 8410 key agreement algorithm" },
|
|
46226
|
+
"1.3.101.112": { d: "Ed25519", c: "RFC 8410 signature algorithm" },
|
|
46227
|
+
"1.3.101.113": { d: "Ed448", c: "RFC 8410 signature algorithm" },
|
|
46228
|
+
"1.3.132.0.10": { d: "secp256k1", c: "SECG (Certicom) named elliptic curve" },
|
|
46229
|
+
"1.3.132.0.33": { d: "secp224r1", c: "SECG (Certicom) named elliptic curve" },
|
|
46230
|
+
"1.3.132.0.34": { d: "secp384r1", c: "SECG (Certicom) named elliptic curve" },
|
|
46231
|
+
"1.3.132.0.35": { d: "secp521r1", c: "SECG (Certicom) named elliptic curve" },
|
|
46219
46232
|
"2.5.4.0": { d: "objectClass", c: "X.520 DN component", w: false },
|
|
46220
46233
|
"2.5.4.1": { d: "aliasedEntryName", c: "X.520 DN component", w: false },
|
|
46221
46234
|
"2.5.4.2": { d: "knowledgeInformation", c: "X.520 DN component", w: false },
|
|
@@ -47420,6 +47433,7 @@ function _readSubjectPublicKeyInfo(buffer, block) {
|
|
|
47420
47433
|
const values = readListOfInteger(data);
|
|
47421
47434
|
return {
|
|
47422
47435
|
algorithm: algorithm.identifier,
|
|
47436
|
+
keyType: "rsa",
|
|
47423
47437
|
keyLength: values[0].length - 1,
|
|
47424
47438
|
subjectPublicKey: _readSubjectPublicKey(subjectPublicKey.data)
|
|
47425
47439
|
//xx values: values,
|
|
@@ -47431,14 +47445,48 @@ function _readSubjectECCPublicKeyInfo(buffer, block) {
|
|
|
47431
47445
|
const algorithm = readECCAlgorithmIdentifier(buffer, inner_blocks[0]);
|
|
47432
47446
|
const subjectPublicKey = readBitString(buffer, inner_blocks[1]);
|
|
47433
47447
|
const data = subjectPublicKey.data;
|
|
47448
|
+
const coordinateLength = data.length - 1;
|
|
47449
|
+
const isCompressed = data[0] === 2 || data[0] === 3;
|
|
47434
47450
|
return {
|
|
47435
47451
|
algorithm: algorithm.identifier,
|
|
47436
|
-
|
|
47452
|
+
keyType: "ec",
|
|
47453
|
+
namedCurve: algorithm.identifier,
|
|
47454
|
+
keyLength: isCompressed ? coordinateLength * 2 : coordinateLength,
|
|
47437
47455
|
subjectPublicKey: {
|
|
47438
47456
|
modulus: data
|
|
47439
47457
|
}
|
|
47440
47458
|
};
|
|
47441
47459
|
}
|
|
47460
|
+
var RFC8410_KEY_TYPES = {
|
|
47461
|
+
Ed25519: "ed25519",
|
|
47462
|
+
Ed448: "ed448",
|
|
47463
|
+
X25519: "x25519",
|
|
47464
|
+
X448: "x448"
|
|
47465
|
+
};
|
|
47466
|
+
function _readSubjectOtherPublicKeyInfo(buffer, block, algorithm) {
|
|
47467
|
+
const inner_blocks = readStruct(buffer, block);
|
|
47468
|
+
const data = readBitString(buffer, inner_blocks[1]).data;
|
|
47469
|
+
return {
|
|
47470
|
+
algorithm,
|
|
47471
|
+
keyType: RFC8410_KEY_TYPES[algorithm] ?? "unknown",
|
|
47472
|
+
keyLength: data.length,
|
|
47473
|
+
subjectPublicKey: {
|
|
47474
|
+
modulus: data
|
|
47475
|
+
}
|
|
47476
|
+
};
|
|
47477
|
+
}
|
|
47478
|
+
function readSubjectPublicKeyInfo(buffer, block) {
|
|
47479
|
+
const inner_blocks = readStruct(buffer, block);
|
|
47480
|
+
const what_type = readAlgorithmIdentifier(buffer, inner_blocks[0]).identifier;
|
|
47481
|
+
switch (what_type) {
|
|
47482
|
+
case "rsaEncryption":
|
|
47483
|
+
return _readSubjectPublicKeyInfo(buffer, block);
|
|
47484
|
+
case "ecPublicKey":
|
|
47485
|
+
return _readSubjectECCPublicKeyInfo(buffer, block);
|
|
47486
|
+
default:
|
|
47487
|
+
return _readSubjectOtherPublicKeyInfo(buffer, block, what_type);
|
|
47488
|
+
}
|
|
47489
|
+
}
|
|
47442
47490
|
function readTbsCertificate(buffer, block) {
|
|
47443
47491
|
const blocks = readStruct(buffer, block);
|
|
47444
47492
|
let _version;
|
|
@@ -47458,7 +47506,7 @@ function readTbsCertificate(buffer, block) {
|
|
|
47458
47506
|
validity = _readValidity(buffer, blocks[3]);
|
|
47459
47507
|
subject = _readName(buffer, blocks[4]);
|
|
47460
47508
|
subjectFingerPrint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[4])));
|
|
47461
|
-
subjectPublicKeyInfo =
|
|
47509
|
+
subjectPublicKeyInfo = readSubjectPublicKeyInfo(buffer, blocks[5]);
|
|
47462
47510
|
extensions = null;
|
|
47463
47511
|
} else {
|
|
47464
47512
|
const version_block = findBlockAtIndex(blocks, 0);
|
|
@@ -47472,19 +47520,7 @@ function readTbsCertificate(buffer, block) {
|
|
|
47472
47520
|
validity = _readValidity(buffer, blocks[4]);
|
|
47473
47521
|
subject = _readName(buffer, blocks[5]);
|
|
47474
47522
|
subjectFingerPrint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[5])));
|
|
47475
|
-
|
|
47476
|
-
const what_type = readAlgorithmIdentifier(buffer, inner_block[0]).identifier;
|
|
47477
|
-
switch (what_type) {
|
|
47478
|
-
case "rsaEncryption": {
|
|
47479
|
-
subjectPublicKeyInfo = _readSubjectPublicKeyInfo(buffer, blocks[6]);
|
|
47480
|
-
break;
|
|
47481
|
-
}
|
|
47482
|
-
default: {
|
|
47483
|
-
(0, import_node_assert4.default)(what_type === "ecPublicKey");
|
|
47484
|
-
subjectPublicKeyInfo = _readSubjectECCPublicKeyInfo(buffer, blocks[6]);
|
|
47485
|
-
break;
|
|
47486
|
-
}
|
|
47487
|
-
}
|
|
47523
|
+
subjectPublicKeyInfo = readSubjectPublicKeyInfo(buffer, blocks[6]);
|
|
47488
47524
|
const extensionBlock = findBlockAtIndex(blocks, 3);
|
|
47489
47525
|
if (!extensionBlock) {
|
|
47490
47526
|
doDebug && console.log(`X509 certificate is invalid : cannot find extension block version = ${version_block}`);
|
|
@@ -47802,6 +47838,7 @@ function exploreAsn1(buffer) {
|
|
|
47802
47838
|
// ../node-opcua-crypto/source/explore_certificate.ts
|
|
47803
47839
|
init_inject_buffer();
|
|
47804
47840
|
var import_node_assert5 = __toESM(require_assert(), 1);
|
|
47841
|
+
var SUPPORTED_CURVES = /* @__PURE__ */ new Set(["prime256v1", "secp384r1", "secp521r1", "brainpoolP256r1", "brainpoolP384r1", "brainpoolP512r1"]);
|
|
47805
47842
|
function coerceCertificate(certificate) {
|
|
47806
47843
|
if (typeof certificate === "string") {
|
|
47807
47844
|
certificate = convertPEMtoDER(certificate);
|
|
@@ -47812,13 +47849,28 @@ function coerceCertificate(certificate) {
|
|
|
47812
47849
|
function exploreCertificateInfo(certificate) {
|
|
47813
47850
|
certificate = coerceCertificate(certificate);
|
|
47814
47851
|
const certInfo = exploreCertificate(certificate);
|
|
47852
|
+
const { keyType, namedCurve } = certInfo.tbsCertificate.subjectPublicKeyInfo;
|
|
47815
47853
|
const data = {
|
|
47816
47854
|
publicKeyLength: certInfo.tbsCertificate.subjectPublicKeyInfo.keyLength,
|
|
47855
|
+
keyType,
|
|
47856
|
+
...namedCurve ? { namedCurve } : {},
|
|
47817
47857
|
notBefore: certInfo.tbsCertificate.validity.notBefore,
|
|
47818
47858
|
notAfter: certInfo.tbsCertificate.validity.notAfter,
|
|
47819
47859
|
publicKey: certInfo.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey,
|
|
47820
47860
|
subject: certInfo.tbsCertificate.subject
|
|
47821
47861
|
};
|
|
47862
|
+
if (keyType === "ec") {
|
|
47863
|
+
if (!namedCurve || !SUPPORTED_CURVES.has(namedCurve)) {
|
|
47864
|
+
throw new Error(`Unsupported elliptic curve: ${namedCurve}`);
|
|
47865
|
+
}
|
|
47866
|
+
return data;
|
|
47867
|
+
}
|
|
47868
|
+
if (keyType === "ed25519" || keyType === "ed448") {
|
|
47869
|
+
return data;
|
|
47870
|
+
}
|
|
47871
|
+
if (keyType !== "rsa") {
|
|
47872
|
+
throw new Error(`Unsupported public key algorithm: ${certInfo.tbsCertificate.subjectPublicKeyInfo.algorithm}`);
|
|
47873
|
+
}
|
|
47822
47874
|
if (!(data.publicKeyLength === 512 || data.publicKeyLength === 384 || data.publicKeyLength === 256 || data.publicKeyLength === 128)) {
|
|
47823
47875
|
throw new Error(`Invalid public key length (expecting 128,256,384 or 512): ${data.publicKeyLength}`);
|
|
47824
47876
|
}
|
|
@@ -47849,29 +47901,34 @@ function _readExtensionRequest(buffer) {
|
|
|
47849
47901
|
}
|
|
47850
47902
|
return result;
|
|
47851
47903
|
}
|
|
47852
|
-
function
|
|
47853
|
-
const
|
|
47854
|
-
|
|
47855
|
-
|
|
47856
|
-
|
|
47857
|
-
throw new Error("cannot find extensionRequest block");
|
|
47904
|
+
function _findExtensionRequest(buffer, attributesBlock) {
|
|
47905
|
+
for (const attribute of readStruct(buffer, attributesBlock)) {
|
|
47906
|
+
const parts = readStruct(buffer, attribute);
|
|
47907
|
+
if (parts.length < 2 || parts[0].tag !== 6 /* OBJECT_IDENTIFIER */) {
|
|
47908
|
+
continue;
|
|
47858
47909
|
}
|
|
47859
|
-
|
|
47860
|
-
|
|
47861
|
-
const identifier = readObjectIdentifier(buffer, blocks2[0]);
|
|
47862
|
-
if (identifier.name !== "extensionRequest") {
|
|
47863
|
-
throw new Error(" Cannot find extension Request in ASN1 block");
|
|
47910
|
+
if (readObjectIdentifier(buffer, parts[0]).name === "extensionRequest") {
|
|
47911
|
+
return _readExtensionRequest(getBlock(buffer, parts[1]));
|
|
47864
47912
|
}
|
|
47865
|
-
const buf = getBlock(buffer, blocks2[1]);
|
|
47866
|
-
const extensionRequest = _readExtensionRequest(buf);
|
|
47867
|
-
return { extensionRequest };
|
|
47868
47913
|
}
|
|
47869
|
-
|
|
47914
|
+
return {};
|
|
47915
|
+
}
|
|
47916
|
+
function readCertificationRequestInfo(buffer, block) {
|
|
47917
|
+
const blocks = readStruct(buffer, block);
|
|
47918
|
+
if (blocks.length < 3 || blocks.length > 4) {
|
|
47919
|
+
throw new Error("Invalid certificate signing request: CertificationRequestInfo must have 3 or 4 elements");
|
|
47920
|
+
}
|
|
47921
|
+
const subject = readDirectoryName(buffer, blocks[1]);
|
|
47922
|
+
const subjectPublicKeyInfo = readSubjectPublicKeyInfo(buffer, blocks[2]);
|
|
47923
|
+
const attributesBlock = findBlockAtIndex(blocks, 0);
|
|
47924
|
+
const extensionRequest = attributesBlock ? _findExtensionRequest(buffer, attributesBlock) : {};
|
|
47925
|
+
return { extensionRequest, subject, subjectPublicKeyInfo };
|
|
47870
47926
|
}
|
|
47871
47927
|
function exploreCertificateSigningRequest(crl) {
|
|
47872
47928
|
const blockInfo = readTag(crl, 0);
|
|
47873
47929
|
const blocks = readStruct(crl, blockInfo);
|
|
47874
47930
|
const csrInfo = readCertificationRequestInfo(crl, blocks[0]);
|
|
47931
|
+
csrInfo.signatureAlgorithm = readAlgorithmIdentifier(crl, blocks[1]);
|
|
47875
47932
|
return csrInfo;
|
|
47876
47933
|
}
|
|
47877
47934
|
|
|
@@ -47881,6 +47938,9 @@ function toNodeKeyObject(privateKey2) {
|
|
|
47881
47938
|
const hidden = privateKey2.hidden;
|
|
47882
47939
|
return typeof hidden === "string" ? createPrivateKeyFromNodeJSCrypto(hidden) : hidden;
|
|
47883
47940
|
}
|
|
47941
|
+
function getPrivateKeyType(privateKey) {
|
|
47942
|
+
return toNodeKeyObject(privateKey).asymmetricKeyType;
|
|
47943
|
+
}
|
|
47884
47944
|
function exploreEcPrivateKey(privateKey2) {
|
|
47885
47945
|
const keyObject = toNodeKeyObject(privateKey2);
|
|
47886
47946
|
if (keyObject.asymmetricKeyType !== "ec") {
|
|
@@ -62194,6 +62254,19 @@ if (typeof window === "undefined") {
|
|
|
62194
62254
|
function getCrypto() {
|
|
62195
62255
|
return _crypto || crypto || node_crypto_shim_default;
|
|
62196
62256
|
}
|
|
62257
|
+
function hasOpenSSL() {
|
|
62258
|
+
return typeof node_crypto_shim_default.KeyObject === "function";
|
|
62259
|
+
}
|
|
62260
|
+
function assertUsablePublicKey(spki, what) {
|
|
62261
|
+
if (!hasOpenSSL()) {
|
|
62262
|
+
return;
|
|
62263
|
+
}
|
|
62264
|
+
try {
|
|
62265
|
+
node_crypto_shim_default.createPublicKey({ key: import_buffer.Buffer.from(spki), format: "der", type: "spki" });
|
|
62266
|
+
} catch (err) {
|
|
62267
|
+
throw new Error(`${what}: ${err.message}`);
|
|
62268
|
+
}
|
|
62269
|
+
}
|
|
62197
62270
|
function ensurePemTrailingNewline(pem2) {
|
|
62198
62271
|
return pem2.endsWith("\n") ? pem2 : `${pem2}
|
|
62199
62272
|
`;
|
|
@@ -62236,6 +62309,14 @@ init_inject_buffer();
|
|
|
62236
62309
|
async function buildPublicKey(privateKey) {
|
|
62237
62310
|
const crypto4 = getCrypto();
|
|
62238
62311
|
const jwk = await crypto4.subtle.exportKey("jwk", privateKey);
|
|
62312
|
+
if (privateKey.algorithm.name === "ECDSA") {
|
|
62313
|
+
const { kty, crv, x, y } = jwk;
|
|
62314
|
+
const namedCurve = privateKey.algorithm.namedCurve;
|
|
62315
|
+
const ecPublicKey = await crypto4.subtle.importKey("jwk", { kty, crv, x, y }, { name: "ECDSA", namedCurve }, true, [
|
|
62316
|
+
"verify"
|
|
62317
|
+
]);
|
|
62318
|
+
return ecPublicKey;
|
|
62319
|
+
}
|
|
62239
62320
|
delete jwk.d;
|
|
62240
62321
|
delete jwk.dp;
|
|
62241
62322
|
delete jwk.dq;
|
|
@@ -62254,13 +62335,77 @@ async function buildPublicKey(privateKey) {
|
|
|
62254
62335
|
return publicKey;
|
|
62255
62336
|
}
|
|
62256
62337
|
|
|
62338
|
+
// ../node-opcua-crypto/source/x509/_key_algorithm.ts
|
|
62339
|
+
init_inject_buffer();
|
|
62340
|
+
var webCryptoCurveNames = /* @__PURE__ */ new Map([
|
|
62341
|
+
["prime256v1", "P-256"],
|
|
62342
|
+
["secp384r1", "P-384"],
|
|
62343
|
+
["secp521r1", "P-521"]
|
|
62344
|
+
]);
|
|
62345
|
+
var hashOfCurve = /* @__PURE__ */ new Map([
|
|
62346
|
+
["P-256", "SHA-256"],
|
|
62347
|
+
["P-384", "SHA-384"],
|
|
62348
|
+
["P-521", "SHA-512"],
|
|
62349
|
+
["brainpoolP256r1", "SHA-256"],
|
|
62350
|
+
["brainpoolP384r1", "SHA-384"],
|
|
62351
|
+
["brainpoolP512r1", "SHA-512"]
|
|
62352
|
+
]);
|
|
62353
|
+
function isEcdsaCurveName(name) {
|
|
62354
|
+
return typeof name === "string" && hashOfCurve.has(name);
|
|
62355
|
+
}
|
|
62356
|
+
function toWebCryptoCurveName(namedCurve) {
|
|
62357
|
+
const name = webCryptoCurveNames.get(namedCurve);
|
|
62358
|
+
if (!name) {
|
|
62359
|
+
throw new Error(`Unsupported elliptic curve: ${namedCurve}`);
|
|
62360
|
+
}
|
|
62361
|
+
return name;
|
|
62362
|
+
}
|
|
62363
|
+
function signingAlgorithmOfKey(key) {
|
|
62364
|
+
if (key.algorithm.name !== "ECDSA") {
|
|
62365
|
+
return { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-256" } };
|
|
62366
|
+
}
|
|
62367
|
+
const namedCurve = key.algorithm.namedCurve;
|
|
62368
|
+
const hash2 = hashOfCurve.get(namedCurve);
|
|
62369
|
+
if (!hash2) {
|
|
62370
|
+
throw new Error(`Unsupported elliptic curve: ${namedCurve}`);
|
|
62371
|
+
}
|
|
62372
|
+
return { name: "ECDSA", namedCurve, hash: { name: hash2 } };
|
|
62373
|
+
}
|
|
62374
|
+
function keyTypeOfAlgorithm(algorithm) {
|
|
62375
|
+
return algorithm.name === "ECDSA" || algorithm.name === "ECDH" ? "ec" : "rsa";
|
|
62376
|
+
}
|
|
62377
|
+
function readPkcs8KeyAlgorithm(privDer) {
|
|
62378
|
+
try {
|
|
62379
|
+
const buffer = import_buffer.Buffer.from(privDer);
|
|
62380
|
+
const blocks = readStruct(buffer, readTag(buffer, 0));
|
|
62381
|
+
const parts = readStruct(buffer, blocks[1]);
|
|
62382
|
+
const algorithm = readObjectIdentifier(buffer, parts[0]).name;
|
|
62383
|
+
if (algorithm !== "ecPublicKey" || parts[1]?.tag !== 6 /* OBJECT_IDENTIFIER */) {
|
|
62384
|
+
return { algorithm };
|
|
62385
|
+
}
|
|
62386
|
+
return { algorithm, namedCurve: readObjectIdentifier(buffer, parts[1]).name };
|
|
62387
|
+
} catch {
|
|
62388
|
+
return void 0;
|
|
62389
|
+
}
|
|
62390
|
+
}
|
|
62391
|
+
|
|
62257
62392
|
// ../node-opcua-crypto/source/x509/ca_signer.ts
|
|
62258
62393
|
var ECDSA_COORDINATE_BYTES = {
|
|
62259
62394
|
"P-256": 32,
|
|
62260
62395
|
"P-384": 48,
|
|
62261
62396
|
// 521 bits is not a byte multiple, so each coordinate occupies 66 bytes
|
|
62262
|
-
"P-521": 66
|
|
62397
|
+
"P-521": 66,
|
|
62398
|
+
brainpoolP256r1: 32,
|
|
62399
|
+
brainpoolP384r1: 48,
|
|
62400
|
+
brainpoolP512r1: 64
|
|
62263
62401
|
};
|
|
62402
|
+
var WEBCRYPTO_CURVES = /* @__PURE__ */ new Set(["P-256", "P-384", "P-521"]);
|
|
62403
|
+
function registerCurveSizes() {
|
|
62404
|
+
const sizes = x509_es_exports.AsnEcSignatureFormatter.namedCurveSize;
|
|
62405
|
+
for (const [namedCurve, size] of Object.entries(ECDSA_COORDINATE_BYTES)) {
|
|
62406
|
+
sizes.set(namedCurve, size);
|
|
62407
|
+
}
|
|
62408
|
+
}
|
|
62264
62409
|
function asBytes(source) {
|
|
62265
62410
|
if (source instanceof Uint8Array) {
|
|
62266
62411
|
return source;
|
|
@@ -62360,9 +62505,26 @@ var LocalPrivateKeySigner = class {
|
|
|
62360
62505
|
return this.#crypto.subtle.sign(this.algorithm, this.#privateKey, tbs);
|
|
62361
62506
|
}
|
|
62362
62507
|
};
|
|
62508
|
+
function assertDeclaredCurveIsTheKeyCurve(algorithm, publicKey) {
|
|
62509
|
+
if (algorithm.name !== "ECDSA") {
|
|
62510
|
+
return;
|
|
62511
|
+
}
|
|
62512
|
+
const keyAlgorithm = publicKey.algorithm;
|
|
62513
|
+
if (keyAlgorithm.name !== "ECDSA" || keyAlgorithm.namedCurve !== algorithm.namedCurve) {
|
|
62514
|
+
const actual = keyAlgorithm.namedCurve ?? keyAlgorithm.name;
|
|
62515
|
+
throw new Error(`the signer declares an ECDSA key on ${algorithm.namedCurve}, but its public key is on ${actual}`);
|
|
62516
|
+
}
|
|
62517
|
+
}
|
|
62363
62518
|
async function webCryptoFromSigner(signer, baseCrypto = getCrypto()) {
|
|
62519
|
+
registerCurveSizes();
|
|
62364
62520
|
const publicKeyDer = await signer.getPublicKey();
|
|
62365
|
-
const
|
|
62521
|
+
const x509PublicKey = new x509_es_exports.PublicKey(publicKeyDer);
|
|
62522
|
+
assertDeclaredCurveIsTheKeyCurve(signer.algorithm, x509PublicKey);
|
|
62523
|
+
const importable = signer.algorithm.name !== "ECDSA" || WEBCRYPTO_CURVES.has(signer.algorithm.namedCurve);
|
|
62524
|
+
if (!importable) {
|
|
62525
|
+
assertUsablePublicKey(publicKeyDer, "the public key of the signer is not a usable key");
|
|
62526
|
+
}
|
|
62527
|
+
const publicKey = importable ? await baseCrypto.subtle.importKey("spki", publicKeyDer, signer.algorithm, true, ["verify"]) : { type: "public", extractable: true, algorithm: signer.algorithm, usages: ["verify"] };
|
|
62366
62528
|
const privateKeyHandle = {
|
|
62367
62529
|
type: "private",
|
|
62368
62530
|
extractable: false,
|
|
@@ -62380,6 +62542,17 @@ async function webCryptoFromSigner(signer, baseCrypto = getCrypto()) {
|
|
|
62380
62542
|
return signer.sign(bytes);
|
|
62381
62543
|
};
|
|
62382
62544
|
}
|
|
62545
|
+
if (prop === "exportKey" && !importable) {
|
|
62546
|
+
return async (format4, key) => {
|
|
62547
|
+
if (key !== publicKey) {
|
|
62548
|
+
return target.exportKey(format4, key);
|
|
62549
|
+
}
|
|
62550
|
+
if (format4 !== "spki") {
|
|
62551
|
+
throw new Error(`the public key of this signer can be exported as spki only, not as ${format4}`);
|
|
62552
|
+
}
|
|
62553
|
+
return new Uint8Array(publicKeyDer).slice().buffer;
|
|
62554
|
+
};
|
|
62555
|
+
}
|
|
62383
62556
|
const value = Reflect.get(target, prop, receiver);
|
|
62384
62557
|
return typeof value === "function" ? value.bind(target) : value;
|
|
62385
62558
|
}
|
|
@@ -62393,7 +62566,7 @@ async function webCryptoFromSigner(signer, baseCrypto = getCrypto()) {
|
|
|
62393
62566
|
return typeof value === "function" ? value.bind(target) : value;
|
|
62394
62567
|
}
|
|
62395
62568
|
});
|
|
62396
|
-
return { crypto: crypto4, privateKeyHandle, publicKey };
|
|
62569
|
+
return { crypto: crypto4, privateKeyHandle, publicKey, x509PublicKey };
|
|
62397
62570
|
}
|
|
62398
62571
|
function isCaSigner(value) {
|
|
62399
62572
|
return typeof value.sign === "function" && typeof value.getPublicKey === "function";
|
|
@@ -62417,7 +62590,7 @@ async function resolveCaKeyPair(key, baseCrypto = getCrypto()) {
|
|
|
62417
62590
|
return {
|
|
62418
62591
|
crypto: baseCrypto,
|
|
62419
62592
|
keys: { privateKey: key, publicKey: await buildPublicKey(key) },
|
|
62420
|
-
signingAlgorithm:
|
|
62593
|
+
signingAlgorithm: signingAlgorithmOfKey(key)
|
|
62421
62594
|
};
|
|
62422
62595
|
}
|
|
62423
62596
|
|
|
@@ -62427,8 +62600,17 @@ init_inject_buffer();
|
|
|
62427
62600
|
// ../node-opcua-crypto/source/x509/create_key_pair.ts
|
|
62428
62601
|
init_inject_buffer();
|
|
62429
62602
|
var ENCRYPTED_PEM_HEADER = "-----BEGIN ENCRYPTED PRIVATE KEY-----";
|
|
62430
|
-
|
|
62603
|
+
var SEC1_PEM_HEADER = "-----BEGIN EC PRIVATE KEY-----";
|
|
62604
|
+
async function generateKeyPair(keyAlgorithm = 2048) {
|
|
62431
62605
|
const crypto4 = getCrypto();
|
|
62606
|
+
if (typeof keyAlgorithm !== "number") {
|
|
62607
|
+
if (keyAlgorithm?.type !== "ec") {
|
|
62608
|
+
throw new Error(`generateKeyPair: unsupported key algorithm ${JSON.stringify(keyAlgorithm)}`);
|
|
62609
|
+
}
|
|
62610
|
+
const ecAlg = { name: "ECDSA", namedCurve: toWebCryptoCurveName(keyAlgorithm.namedCurve) };
|
|
62611
|
+
return await crypto4.subtle.generateKey(ecAlg, true, ["sign", "verify"]);
|
|
62612
|
+
}
|
|
62613
|
+
const modulusLength = keyAlgorithm;
|
|
62432
62614
|
const alg = {
|
|
62433
62615
|
name: "RSASSA-PKCS1-v1_5",
|
|
62434
62616
|
hash: { name: "SHA-256" },
|
|
@@ -62438,8 +62620,8 @@ async function generateKeyPair(modulusLength = 2048) {
|
|
|
62438
62620
|
const keys = await crypto4.subtle.generateKey(alg, true, ["sign", "verify"]);
|
|
62439
62621
|
return keys;
|
|
62440
62622
|
}
|
|
62441
|
-
async function generatePrivateKey(
|
|
62442
|
-
return (await generateKeyPair(
|
|
62623
|
+
async function generatePrivateKey(keyAlgorithm = 2048) {
|
|
62624
|
+
return (await generateKeyPair(keyAlgorithm)).privateKey;
|
|
62443
62625
|
}
|
|
62444
62626
|
async function privateKeyToPEM(privateKey) {
|
|
62445
62627
|
const crypto4 = getCrypto();
|
|
@@ -62449,6 +62631,14 @@ async function privateKeyToPEM(privateKey) {
|
|
|
62449
62631
|
}
|
|
62450
62632
|
async function derToPrivateKey(privDer) {
|
|
62451
62633
|
const crypto4 = getCrypto();
|
|
62634
|
+
const keyAlgorithm = readPkcs8KeyAlgorithm(privDer);
|
|
62635
|
+
if (keyAlgorithm?.algorithm === "ecPublicKey") {
|
|
62636
|
+
if (!keyAlgorithm.namedCurve) {
|
|
62637
|
+
throw new Error("derToPrivateKey: the elliptic curve key does not name its curve");
|
|
62638
|
+
}
|
|
62639
|
+
const ecAlg = { name: "ECDSA", namedCurve: toWebCryptoCurveName(keyAlgorithm.namedCurve) };
|
|
62640
|
+
return await crypto4.subtle.importKey("pkcs8", privDer, ecAlg, true, ["sign"]);
|
|
62641
|
+
}
|
|
62452
62642
|
const importedKey = await crypto4.subtle.importKey(
|
|
62453
62643
|
"pkcs8",
|
|
62454
62644
|
privDer,
|
|
@@ -62476,6 +62666,11 @@ async function pemToPrivateKey(pem2) {
|
|
|
62476
62666
|
"This private key is encrypted (PKCS#8 ENCRYPTED PRIVATE KEY). Encrypted private keys are not supported by the WebCrypto-based browser build; use the Node.js build's readPrivateKey()/readPrivateKeyAsync() with a passphrase instead."
|
|
62477
62667
|
);
|
|
62478
62668
|
}
|
|
62669
|
+
if (pem2.includes(SEC1_PEM_HEADER)) {
|
|
62670
|
+
throw new Error(
|
|
62671
|
+
"This elliptic curve private key is in the SEC1 form (EC PRIVATE KEY), which WebCrypto cannot import; convert it to PKCS#8 first (openssl pkcs8 -topk8 -nocrypt), or use the Node.js build's readPrivateKey()/readPrivateKeyAsync()."
|
|
62672
|
+
);
|
|
62673
|
+
}
|
|
62479
62674
|
const privDer = x509_es_exports.PemConverter.decode(pem2);
|
|
62480
62675
|
return derToPrivateKey(privDer[0]);
|
|
62481
62676
|
}
|
|
@@ -62515,12 +62710,14 @@ async function _coercePrivateKey(privateKey) {
|
|
|
62515
62710
|
|
|
62516
62711
|
// ../node-opcua-crypto/source/x509/create_certificate_from_csr.ts
|
|
62517
62712
|
init_inject_buffer();
|
|
62713
|
+
init_node_crypto_shim();
|
|
62518
62714
|
|
|
62519
62715
|
// ../node-opcua-crypto/source/x509/_get_attributes.ts
|
|
62520
62716
|
init_inject_buffer();
|
|
62521
62717
|
var keyUsageApplication = x509_es_exports.KeyUsageFlags.keyEncipherment | x509_es_exports.KeyUsageFlags.nonRepudiation | x509_es_exports.KeyUsageFlags.dataEncipherment | x509_es_exports.KeyUsageFlags.keyCertSign | x509_es_exports.KeyUsageFlags.digitalSignature;
|
|
62718
|
+
var keyUsageApplicationEc = x509_es_exports.KeyUsageFlags.digitalSignature | x509_es_exports.KeyUsageFlags.nonRepudiation | x509_es_exports.KeyUsageFlags.keyAgreement | x509_es_exports.KeyUsageFlags.keyCertSign;
|
|
62522
62719
|
var keyUsageCA = x509_es_exports.KeyUsageFlags.keyCertSign | x509_es_exports.KeyUsageFlags.cRLSign;
|
|
62523
|
-
function getAttributes(purpose) {
|
|
62720
|
+
function getAttributes(purpose, keyType = "rsa") {
|
|
62524
62721
|
let basicConstraints;
|
|
62525
62722
|
let keyUsageExtension = [];
|
|
62526
62723
|
let usages;
|
|
@@ -62539,7 +62736,7 @@ function getAttributes(purpose) {
|
|
|
62539
62736
|
default:
|
|
62540
62737
|
_extension = "v3_selfsigned";
|
|
62541
62738
|
basicConstraints = new x509_es_exports.BasicConstraintsExtension(false, void 0, true);
|
|
62542
|
-
usages = keyUsageApplication;
|
|
62739
|
+
usages = keyType === "ec" ? keyUsageApplicationEc : keyUsageApplication;
|
|
62543
62740
|
keyUsageExtension = [x509_es_exports.ExtendedKeyUsage.serverAuth, x509_es_exports.ExtendedKeyUsage.clientAuth];
|
|
62544
62741
|
nsComment = "Self-signed certificate generated by Node-OPCUA Certificate utility V2";
|
|
62545
62742
|
break;
|
|
@@ -62549,7 +62746,8 @@ function getAttributes(purpose) {
|
|
|
62549
62746
|
|
|
62550
62747
|
// ../node-opcua-crypto/source/x509/create_certificate_from_csr.ts
|
|
62551
62748
|
var keyUsageIssuedApplication = x509_es_exports.KeyUsageFlags.digitalSignature | x509_es_exports.KeyUsageFlags.nonRepudiation | x509_es_exports.KeyUsageFlags.keyEncipherment | x509_es_exports.KeyUsageFlags.dataEncipherment | x509_es_exports.KeyUsageFlags.keyAgreement;
|
|
62552
|
-
|
|
62749
|
+
var keyUsageIssuedApplicationEc = x509_es_exports.KeyUsageFlags.digitalSignature | x509_es_exports.KeyUsageFlags.nonRepudiation | x509_es_exports.KeyUsageFlags.keyAgreement;
|
|
62750
|
+
function getIssuedAttributes(purpose, keyType) {
|
|
62553
62751
|
if (purpose === 1 /* ForCertificateAuthority */) {
|
|
62554
62752
|
return getAttributes(purpose);
|
|
62555
62753
|
}
|
|
@@ -62557,17 +62755,55 @@ function getIssuedAttributes(purpose) {
|
|
|
62557
62755
|
nsComment: "Certificate generated by Node-OPCUA Certificate utility V2",
|
|
62558
62756
|
basicConstraints: new x509_es_exports.BasicConstraintsExtension(false, void 0, true),
|
|
62559
62757
|
keyUsageExtension: [x509_es_exports.ExtendedKeyUsage.serverAuth, x509_es_exports.ExtendedKeyUsage.clientAuth],
|
|
62560
|
-
usages: keyUsageIssuedApplication
|
|
62758
|
+
usages: keyType === "ec" ? keyUsageIssuedApplicationEc : keyUsageIssuedApplication
|
|
62561
62759
|
};
|
|
62562
62760
|
}
|
|
62761
|
+
var OPENSSL_DIGESTS = {
|
|
62762
|
+
"SHA-1": "sha1",
|
|
62763
|
+
"SHA-256": "sha256",
|
|
62764
|
+
"SHA-384": "sha384",
|
|
62765
|
+
"SHA-512": "sha512"
|
|
62766
|
+
};
|
|
62767
|
+
function verifyRequestSignatureWithOpenSSL(csr) {
|
|
62768
|
+
if (!hasOpenSSL()) {
|
|
62769
|
+
return void 0;
|
|
62770
|
+
}
|
|
62771
|
+
const algorithm = csr.signatureAlgorithm;
|
|
62772
|
+
const digest = algorithm.hash && OPENSSL_DIGESTS[algorithm.hash.name];
|
|
62773
|
+
if (!digest) {
|
|
62774
|
+
return void 0;
|
|
62775
|
+
}
|
|
62776
|
+
const keyAlgorithm = csr.publicKey.algorithm;
|
|
62777
|
+
const isRsaRequest = algorithm.name === "RSASSA-PKCS1-v1_5" && keyAlgorithm.name === "RSASSA-PKCS1-v1_5";
|
|
62778
|
+
const isEcdsaRequest = algorithm.name === "ECDSA" && keyAlgorithm.name === "ECDSA" && isEcdsaCurveName(keyAlgorithm.namedCurve);
|
|
62779
|
+
if (!isRsaRequest && !isEcdsaRequest) {
|
|
62780
|
+
return void 0;
|
|
62781
|
+
}
|
|
62782
|
+
const toBeSigned = csr.tbs;
|
|
62783
|
+
if (!toBeSigned || typeof toBeSigned.byteLength !== "number") {
|
|
62784
|
+
return void 0;
|
|
62785
|
+
}
|
|
62786
|
+
try {
|
|
62787
|
+
const verify = createVerify(digest);
|
|
62788
|
+
verify.update(new Uint8Array(toBeSigned));
|
|
62789
|
+
verify.end();
|
|
62790
|
+
const publicKeyPem = toPem(import_buffer.Buffer.from(csr.publicKey.rawData), "PUBLIC KEY");
|
|
62791
|
+
return verify.verify(publicKeyPem, new Uint8Array(csr.signature));
|
|
62792
|
+
} catch {
|
|
62793
|
+
return false;
|
|
62794
|
+
}
|
|
62795
|
+
}
|
|
62563
62796
|
async function createCertificateFromCsr(options) {
|
|
62564
62797
|
const crypto4 = getCrypto();
|
|
62565
62798
|
const csr = new x509_es_exports.Pkcs10CertificateRequest(options.csr);
|
|
62566
|
-
const csrIsValid = await csr.verify(crypto4);
|
|
62799
|
+
const csrIsValid = verifyRequestSignatureWithOpenSSL(csr) ?? await csr.verify(crypto4);
|
|
62567
62800
|
if (!csrIsValid) {
|
|
62568
62801
|
throw new Error("createCertificateFromCsr: the CSR signature does not verify \u2014 refusing to sign an unproven key");
|
|
62569
62802
|
}
|
|
62570
|
-
const { basicConstraints, keyUsageExtension, usages } = getIssuedAttributes(
|
|
62803
|
+
const { basicConstraints, keyUsageExtension, usages } = getIssuedAttributes(
|
|
62804
|
+
options.purpose,
|
|
62805
|
+
keyTypeOfAlgorithm(csr.publicKey.algorithm)
|
|
62806
|
+
);
|
|
62571
62807
|
const alternativeNameExtensions = [];
|
|
62572
62808
|
for (const d of options.dns ?? []) {
|
|
62573
62809
|
alternativeNameExtensions.push({ type: "dns", value: d });
|
|
@@ -62635,7 +62871,7 @@ async function createCertificateSigningRequest({
|
|
|
62635
62871
|
if (applicationUri) {
|
|
62636
62872
|
alternativeNameExtensions.push({ type: "url", value: applicationUri });
|
|
62637
62873
|
}
|
|
62638
|
-
const { basicConstraints, usages } = getAttributes(purpose);
|
|
62874
|
+
const { basicConstraints, usages } = getAttributes(purpose, keyTypeOfAlgorithm(signingAlgorithm));
|
|
62639
62875
|
const s = new Subject(subject || "");
|
|
62640
62876
|
const s1 = s.toStringInternal(", ");
|
|
62641
62877
|
const name = s1;
|
|
@@ -62701,7 +62937,7 @@ async function createSelfSignedCertificate({
|
|
|
62701
62937
|
purpose
|
|
62702
62938
|
}) {
|
|
62703
62939
|
const { crypto: crypto4, keys, signingAlgorithm } = await resolveCaKeyPair(privateKey);
|
|
62704
|
-
const { nsComment, basicConstraints, keyUsageExtension, usages } = getAttributes(purpose);
|
|
62940
|
+
const { nsComment, basicConstraints, keyUsageExtension, usages } = getAttributes(purpose, keyTypeOfAlgorithm(signingAlgorithm));
|
|
62705
62941
|
notBefore = notBefore || /* @__PURE__ */ new Date();
|
|
62706
62942
|
validity = validity || 0;
|
|
62707
62943
|
if (!notAfter) {
|
|
@@ -62736,8 +62972,9 @@ async function createSelfSignedCertificate({
|
|
|
62736
62972
|
name,
|
|
62737
62973
|
notBefore,
|
|
62738
62974
|
notAfter,
|
|
62739
|
-
// for a raw key resolveCaKeyPair yields exactly the historical
|
|
62740
|
-
// RSASSA-PKCS1-v1_5/SHA-256
|
|
62975
|
+
// for a raw RSA key resolveCaKeyPair yields exactly the historical
|
|
62976
|
+
// RSASSA-PKCS1-v1_5/SHA-256, for a raw elliptic curve key ECDSA with
|
|
62977
|
+
// the hash of the curve; for a CaSigner, the signer's declared algorithm
|
|
62741
62978
|
signingAlgorithm,
|
|
62742
62979
|
keys,
|
|
62743
62980
|
extensions: [
|
|
@@ -62747,8 +62984,10 @@ async function createSelfSignedCertificate({
|
|
|
62747
62984
|
// see RFC 5280 4.2.1.12 - an empty critical EKU is invalid
|
|
62748
62985
|
...keyUsageExtension.length > 0 ? [new x509_es_exports.ExtendedKeyUsageExtension(keyUsageExtension, true)] : [],
|
|
62749
62986
|
new x509_es_exports.KeyUsagesExtension(usages, true),
|
|
62750
|
-
|
|
62751
|
-
|
|
62987
|
+
// with the crypto of the key: a signer's public key can be a
|
|
62988
|
+
// handle that only its own crypto object knows how to export
|
|
62989
|
+
await x509_es_exports.SubjectKeyIdentifierExtension.create(keys.publicKey, false, crypto4),
|
|
62990
|
+
await x509_es_exports.AuthorityKeyIdentifierExtension.create(keys.publicKey, false, crypto4),
|
|
62752
62991
|
new x509_es_exports.SubjectAlternativeNameExtension(alternativeNameExtensions)
|
|
62753
62992
|
]
|
|
62754
62993
|
},
|
|
@@ -63177,6 +63416,9 @@ function verifyChunkSignature(chunk, options) {
|
|
|
63177
63416
|
let signatureLength = options.signatureLength || 0;
|
|
63178
63417
|
if (signatureLength === 0) {
|
|
63179
63418
|
const cert = exploreCertificateInfo(options.publicKey);
|
|
63419
|
+
if (cert.keyType !== "rsa") {
|
|
63420
|
+
throw new Error(`verifyChunkSignature: signatureLength is required with a "${cert.keyType}" certificate`);
|
|
63421
|
+
}
|
|
63180
63422
|
signatureLength = cert.publicKeyLength || 0;
|
|
63181
63423
|
}
|
|
63182
63424
|
const block_to_verify = chunk.subarray(0, chunk.length - signatureLength);
|
|
@@ -63445,11 +63687,33 @@ function makePrivateKeyThumbPrint(_privateKey) {
|
|
|
63445
63687
|
|
|
63446
63688
|
// ../node-opcua-crypto/source/public_private_match.ts
|
|
63447
63689
|
init_inject_buffer();
|
|
63690
|
+
init_node_crypto_shim();
|
|
63691
|
+
function sharedKeyType(certificateKeyType, privateKey, caller) {
|
|
63692
|
+
const keyType = getPrivateKeyType(privateKey) ?? "rsa";
|
|
63693
|
+
if (certificateKeyType !== keyType) {
|
|
63694
|
+
return void 0;
|
|
63695
|
+
}
|
|
63696
|
+
if (keyType !== "rsa" && keyType !== "ec") {
|
|
63697
|
+
throw new Error(`${caller}: "${keyType}" keys are not supported`);
|
|
63698
|
+
}
|
|
63699
|
+
return keyType;
|
|
63700
|
+
}
|
|
63701
|
+
function ecPublicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
63702
|
+
const fromCertificate = createPublicKey(certificate);
|
|
63703
|
+
const fromPrivateKey = createPublicKey(privateKey.hidden);
|
|
63704
|
+
return fromCertificate.equals(fromPrivateKey);
|
|
63705
|
+
}
|
|
63448
63706
|
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
63449
|
-
const
|
|
63450
|
-
const
|
|
63451
|
-
|
|
63452
|
-
|
|
63707
|
+
const subjectPublicKeyInfo = exploreCertificate(certificate).tbsCertificate.subjectPublicKeyInfo;
|
|
63708
|
+
const keyType = sharedKeyType(subjectPublicKeyInfo.keyType, privateKey, "publicKeyAndPrivateKeyMatches");
|
|
63709
|
+
if (!keyType) {
|
|
63710
|
+
return false;
|
|
63711
|
+
}
|
|
63712
|
+
if (keyType === "ec") {
|
|
63713
|
+
return ecPublicKeyAndPrivateKeyMatches(toPem(certificate, "CERTIFICATE"), privateKey);
|
|
63714
|
+
}
|
|
63715
|
+
const modulus1 = subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
63716
|
+
const modulus2 = explorePrivateKey(privateKey).modulus;
|
|
63453
63717
|
if (modulus1.length !== modulus2.length) {
|
|
63454
63718
|
return false;
|
|
63455
63719
|
}
|
|
@@ -63462,10 +63726,23 @@ function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
|
63462
63726
|
const finalString = decryptedBuffer.toString("utf-8");
|
|
63463
63727
|
return initialBuffer.toString("utf-8") === finalString;
|
|
63464
63728
|
}
|
|
63729
|
+
function ecCertificateMatchesPrivateKey(certificate, privateKey) {
|
|
63730
|
+
const data = import_buffer.Buffer.from("Lorem Ipsum");
|
|
63731
|
+
const signature = createSign("sha256").update(data).sign(privateKey.hidden);
|
|
63732
|
+
return createVerify("sha256").update(data).verify(certificate, signature);
|
|
63733
|
+
}
|
|
63465
63734
|
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
63735
|
+
const subjectPublicKeyInfo = exploreCertificate(certificate).tbsCertificate.subjectPublicKeyInfo;
|
|
63736
|
+
const keyType = sharedKeyType(subjectPublicKeyInfo.keyType, privateKey, "certificateMatchesPrivateKey");
|
|
63737
|
+
if (!keyType) {
|
|
63738
|
+
return false;
|
|
63739
|
+
}
|
|
63740
|
+
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
63741
|
+
if (keyType === "ec") {
|
|
63742
|
+
return ecPublicKeyAndPrivateKeyMatches(certificatePEM, privateKey) && ecCertificateMatchesPrivateKey(certificatePEM, privateKey);
|
|
63743
|
+
}
|
|
63466
63744
|
const e = explorePrivateKey(privateKey);
|
|
63467
63745
|
const blockSize = e.modulus.length;
|
|
63468
|
-
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
63469
63746
|
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
63470
63747
|
}
|
|
63471
63748
|
|
|
@@ -63525,6 +63802,7 @@ export {
|
|
|
63525
63802
|
generateKeyPair,
|
|
63526
63803
|
generatePrivateKey,
|
|
63527
63804
|
getCrypto,
|
|
63805
|
+
getPrivateKeyType,
|
|
63528
63806
|
hasSyncKeyOperations,
|
|
63529
63807
|
hexDump,
|
|
63530
63808
|
identifyDERContent,
|
|
@@ -63553,6 +63831,7 @@ export {
|
|
|
63553
63831
|
readCertificationRequestInfo,
|
|
63554
63832
|
readExtension,
|
|
63555
63833
|
readNameForCrl,
|
|
63834
|
+
readSubjectPublicKeyInfo,
|
|
63556
63835
|
readTbsCertificate,
|
|
63557
63836
|
reduceLength,
|
|
63558
63837
|
removePadding,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-crypto-web",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Pre-bundled, zero-config browser build of node-opcua-crypto",
|
|
6
6
|
"//why": "This package exists so node-opcua-crypto can stay lean for Node. The pre-bundled browser build inlines its polyfills (crypto-browserify, stream-browserify, ...) and weighs ~344 KB gzip - more than the entire node-opcua-crypto tarball. Shipping it there would make every Node consumer download a browser bundle they never import. Browser consumers install this package explicitly, or let node-opcua-crypto's \"browser\" export condition redirect to it (see node-opcua-crypto/browser/index.js).",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"crypto-browserify": "^3.12.1",
|
|
45
45
|
"esbuild": "^0.28.2",
|
|
46
46
|
"events": "^3.3.0",
|
|
47
|
-
"node-opcua-crypto": "^6.
|
|
47
|
+
"node-opcua-crypto": "^6.4.0",
|
|
48
48
|
"path-browserify": "^1.0.1",
|
|
49
49
|
"process": "^0.11.10",
|
|
50
50
|
"stream-browserify": "^3.0.0",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"LICENSE",
|
|
68
68
|
"README.md"
|
|
69
69
|
],
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "def704287e8c85f51cc715592391542683719ccd"
|
|
71
71
|
}
|