node-opcua-crypto-web 6.2.4 → 6.3.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 +126 -35
- package/dist/index_web.js +211 -33
- 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,36 @@ declare function readExtension(buffer: Buffer, block: BlockInfo): {
|
|
|
284
259
|
[key: string]: string[];
|
|
285
260
|
};
|
|
286
261
|
};
|
|
262
|
+
/** The family a certificate's public key belongs to. */
|
|
263
|
+
type PublicKeyType = "rsa" | "ec" | "ed25519" | "ed448" | "x25519" | "x448" | "unknown";
|
|
287
264
|
interface SubjectPublicKeyInfo {
|
|
265
|
+
/**
|
|
266
|
+
* For an RSA key, "rsaEncryption". For an elliptic curve key, the name
|
|
267
|
+
* of the curve (see {@link namedCurve}). Otherwise the name of the
|
|
268
|
+
* algorithm, e.g. "Ed25519", or its OID when it has no known name.
|
|
269
|
+
*/
|
|
288
270
|
algorithm: string;
|
|
289
|
-
|
|
271
|
+
/**
|
|
272
|
+
* The family of the key. `exploreCertificate` always sets it; it is
|
|
273
|
+
* optional only so that an object built by hand stays valid.
|
|
274
|
+
*/
|
|
275
|
+
keyType?: PublicKeyType;
|
|
276
|
+
/** The curve of an elliptic curve key, e.g. "prime256v1" or "brainpoolP384r1". */
|
|
277
|
+
namedCurve?: string;
|
|
278
|
+
/**
|
|
279
|
+
* In bytes. RSA: the modulus. Elliptic curve: the two coordinates of the
|
|
280
|
+
* public point, so twice the size of the curve (64 for a 256-bit curve),
|
|
281
|
+
* also when the certificate stores the point compressed.
|
|
282
|
+
* Otherwise: the raw public key.
|
|
283
|
+
*
|
|
284
|
+
* The number alone does not tell the family of the key: 128 is an RSA
|
|
285
|
+
* 1024-bit key and also a brainpoolP512r1 key. Read {@link keyType}.
|
|
286
|
+
*/
|
|
287
|
+
keyLength: number;
|
|
288
|
+
/**
|
|
289
|
+
* RSA: the modulus. Otherwise the public key bits as the certificate
|
|
290
|
+
* stores them (for an elliptic curve, the point with its form byte).
|
|
291
|
+
*/
|
|
290
292
|
subjectPublicKey: SubjectPublicKey;
|
|
291
293
|
}
|
|
292
294
|
interface BasicConstraints {
|
|
@@ -366,6 +368,50 @@ declare function combine_der(certificates: Certificate[]): Certificate;
|
|
|
366
368
|
|
|
367
369
|
declare function exploreAsn1(buffer: Buffer): void;
|
|
368
370
|
|
|
371
|
+
/**
|
|
372
|
+
* The length, in bytes, of a public key that {@link exploreCertificateInfo}
|
|
373
|
+
* accepts: 128, 256, 384 or 512 for RSA (1024 to 4096 bits); 64, 96, 128 or
|
|
374
|
+
* 132 for an elliptic curve (twice the curve size); 32 or 57 for Ed25519 and
|
|
375
|
+
* Ed448.
|
|
376
|
+
*
|
|
377
|
+
* The number alone does not tell the family of the key: 128 is an RSA
|
|
378
|
+
* 1024-bit key and also a brainpoolP512r1 key. Read `keyType`.
|
|
379
|
+
*/
|
|
380
|
+
type PublicKeyLength = 32 | 57 | 64 | 96 | 128 | 132 | 256 | 384 | 512;
|
|
381
|
+
/**
|
|
382
|
+
* A structure exposing useful information about a certificate
|
|
383
|
+
*/
|
|
384
|
+
interface CertificateInfo {
|
|
385
|
+
/** the public key length in bytes, see {@link PublicKeyLength} */
|
|
386
|
+
publicKeyLength: PublicKeyLength;
|
|
387
|
+
/** the family of the public key; publicKeyLength does not tell it (128 is RSA 1024 and brainpoolP512r1) */
|
|
388
|
+
keyType?: PublicKeyType;
|
|
389
|
+
/** the curve of an elliptic curve key, e.g. "prime256v1" */
|
|
390
|
+
namedCurve?: string;
|
|
391
|
+
/** the date at which the certificate starts to be valid */
|
|
392
|
+
notBefore: Date;
|
|
393
|
+
/** the date after which the certificate is not valid any more */
|
|
394
|
+
notAfter: Date;
|
|
395
|
+
/** info about certificate owner */
|
|
396
|
+
subject: DirectoryName;
|
|
397
|
+
/** public key */
|
|
398
|
+
publicKey: SubjectPublicKey;
|
|
399
|
+
}
|
|
400
|
+
declare function coerceCertificate(certificate: Certificate | CertificatePEM): Certificate;
|
|
401
|
+
/**
|
|
402
|
+
* @method exploreCertificateInfo
|
|
403
|
+
* returns useful information about the certificate such as public key length, start date and end of validity date,
|
|
404
|
+
* and CN
|
|
405
|
+
*
|
|
406
|
+
* Throws when the public key is not one an application certificate can
|
|
407
|
+
* carry: an RSA key that is not 1024, 2048, 3072 or 4096 bits, an elliptic
|
|
408
|
+
* curve other than the NIST and brainpool curves of 256 bits and more, or
|
|
409
|
+
* an algorithm other than RSA, elliptic curve, Ed25519 and Ed448.
|
|
410
|
+
* `exploreCertificate` describes such a certificate without throwing.
|
|
411
|
+
* @param certificate the certificate to explore
|
|
412
|
+
*/
|
|
413
|
+
declare function exploreCertificateInfo(certificate: Certificate | CertificatePEM): CertificateInfo;
|
|
414
|
+
|
|
369
415
|
type Version = string;
|
|
370
416
|
/**
|
|
371
417
|
* A Name is an RDNSequence, not a string.
|
|
@@ -435,6 +481,11 @@ interface CertificateSigningRequestInfo {
|
|
|
435
481
|
declare function readCertificationRequestInfo(buffer: Buffer, block: BlockInfo): CertificateSigningRequestInfo;
|
|
436
482
|
declare function exploreCertificateSigningRequest(crl: Buffer): CertificateSigningRequestInfo;
|
|
437
483
|
|
|
484
|
+
/**
|
|
485
|
+
* The type of a private key, as Node names it: "rsa", "ec", "ed25519"...
|
|
486
|
+
* `undefined` when the platform cannot tell.
|
|
487
|
+
*/
|
|
488
|
+
declare function getPrivateKeyType(privateKey: PrivateKey): string | undefined;
|
|
438
489
|
interface PrivateKeyInternals {
|
|
439
490
|
/***/
|
|
440
491
|
version: Buffer;
|
|
@@ -679,7 +730,10 @@ interface ResolvedCaKeyPair {
|
|
|
679
730
|
* Resolves a `CryptoKey | CaSigner` into the key pair and per-call `crypto`
|
|
680
731
|
* a CSR or self-signed-certificate generator needs.
|
|
681
732
|
*
|
|
682
|
-
* For a raw `CryptoKey` the public half is derived from the private one
|
|
733
|
+
* For a raw `CryptoKey` the public half is derived from the private one,
|
|
734
|
+
* and the signing algorithm is read from the key: RSASSA-PKCS1-v1_5 with
|
|
735
|
+
* SHA-256 for an RSA key, ECDSA with the hash of its curve for an elliptic
|
|
736
|
+
* curve key.
|
|
683
737
|
* For a {@link CaSigner} it comes from `getPublicKey()` — the only way to
|
|
684
738
|
* obtain it when the private key lives in an HSM and cannot be exported.
|
|
685
739
|
*/
|
|
@@ -891,7 +945,7 @@ declare function getCrypto(): Crypto$1 | typeof __crypto;
|
|
|
891
945
|
* does for the self-signed case, and what openssl's
|
|
892
946
|
* `authorityKeyIdentifier = keyid:always` produces for the issued case.
|
|
893
947
|
*/
|
|
894
|
-
declare function buildAuthorityKeyIdentifierFromIssuer(issuerPublicKey: PublicKeyType, crypto?: Crypto): Promise<x509.AuthorityKeyIdentifierExtension>;
|
|
948
|
+
declare function buildAuthorityKeyIdentifierFromIssuer(issuerPublicKey: PublicKeyType$1, crypto?: Crypto): Promise<x509.AuthorityKeyIdentifierExtension>;
|
|
895
949
|
/** Opt-in CRL Distribution Point / Authority Info Access URLs for a certificate. */
|
|
896
950
|
interface RevocationExtensionsParams {
|
|
897
951
|
crlDistributionUrl?: string;
|
|
@@ -936,7 +990,7 @@ interface CreateCertificateFromCsrOptions {
|
|
|
936
990
|
*/
|
|
937
991
|
issuerName: x509.X509CertificateCreateParamsName;
|
|
938
992
|
/** The issuing CA's public key, used to derive the Authority Key Identifier extension. */
|
|
939
|
-
issuerPublicKey: PublicKeyType;
|
|
993
|
+
issuerPublicKey: PublicKeyType$1;
|
|
940
994
|
/** The issuing CA's signing key — a raw key, or an HSM/KMS-backed {@link CaSigner}. */
|
|
941
995
|
signingKey: CryptoKey | CaSigner;
|
|
942
996
|
signingAlgorithm: CaSignAlgorithm;
|
|
@@ -1003,7 +1057,7 @@ interface CreateCrlOptions {
|
|
|
1003
1057
|
*/
|
|
1004
1058
|
issuerName: x509.X509CertificateCreateParamsName;
|
|
1005
1059
|
/** The issuing CA's public key, used to derive the Authority Key Identifier extension. */
|
|
1006
|
-
issuerPublicKey: PublicKeyType;
|
|
1060
|
+
issuerPublicKey: PublicKeyType$1;
|
|
1007
1061
|
/** The issuing CA's signing key — a raw key, or an HSM/KMS-backed {@link CaSigner}. */
|
|
1008
1062
|
signingKey: CryptoKey | CaSigner;
|
|
1009
1063
|
signingAlgorithm: CaSignAlgorithm;
|
|
@@ -1023,11 +1077,30 @@ declare function createCrl(options: CreateCrlOptions): Promise<{
|
|
|
1023
1077
|
der: ArrayBuffer;
|
|
1024
1078
|
}>;
|
|
1025
1079
|
|
|
1026
|
-
declare function generateKeyPair(modulusLength?: 1024 | 2048 | 3072 | 4096): Promise<CryptoKeyPair>;
|
|
1027
1080
|
/**
|
|
1028
|
-
*
|
|
1081
|
+
* The elliptic curves a key can be generated on, under the names that
|
|
1082
|
+
* OpenSSL uses and that `exploreCertificate` reports in `namedCurve`.
|
|
1083
|
+
*/
|
|
1084
|
+
type EcNamedCurve = "prime256v1" | "secp384r1" | "secp521r1";
|
|
1085
|
+
/** Asks for an elliptic curve key where a number asks for an RSA key of that size. */
|
|
1086
|
+
interface EcPrivateKeyAlgorithm {
|
|
1087
|
+
type: "ec";
|
|
1088
|
+
namedCurve: EcNamedCurve;
|
|
1089
|
+
}
|
|
1090
|
+
type RsaModulusLength = 1024 | 2048 | 3072 | 4096;
|
|
1091
|
+
|
|
1092
|
+
/**
|
|
1093
|
+
* generate a pair of private/public keys.
|
|
1094
|
+
*
|
|
1095
|
+
* A number asks for an RSA key of that length in bits;
|
|
1096
|
+
* `{ type: "ec", namedCurve: "prime256v1" }` asks for an elliptic curve key.
|
|
1097
|
+
*/
|
|
1098
|
+
declare function generateKeyPair(keyAlgorithm?: RsaModulusLength | EcPrivateKeyAlgorithm): Promise<CryptoKeyPair>;
|
|
1099
|
+
/**
|
|
1100
|
+
* generate a private key: RSA of length 1024, 2048, 3072 or 4096 bits,
|
|
1101
|
+
* or on an elliptic curve (see {@link generateKeyPair})
|
|
1029
1102
|
*/
|
|
1030
|
-
declare function generatePrivateKey(
|
|
1103
|
+
declare function generatePrivateKey(keyAlgorithm?: RsaModulusLength | EcPrivateKeyAlgorithm): Promise<CryptoKey>;
|
|
1031
1104
|
/**
|
|
1032
1105
|
* convert a CryptoKey to a PEM string
|
|
1033
1106
|
*/
|
|
@@ -1035,6 +1108,10 @@ declare function privateKeyToPEM(privateKey: CryptoKey): Promise<{
|
|
|
1035
1108
|
privPem: string;
|
|
1036
1109
|
privDer: ArrayBuffer;
|
|
1037
1110
|
}>;
|
|
1111
|
+
/**
|
|
1112
|
+
* import a PKCS#8 private key. The key says itself whether it is an RSA key
|
|
1113
|
+
* or an elliptic curve one, and on which curve.
|
|
1114
|
+
*/
|
|
1038
1115
|
declare function derToPrivateKey(privDer: ArrayBuffer): Promise<CryptoKey>;
|
|
1039
1116
|
declare function pemToPrivateKey(pem: string): Promise<CryptoKey>;
|
|
1040
1117
|
|
|
@@ -1257,7 +1334,21 @@ declare function makePrivateKeyFromPem(privateKeyInPem: string): PrivateKey;
|
|
|
1257
1334
|
|
|
1258
1335
|
declare function makePrivateKeyThumbPrint(_privateKey: PrivateKey): Buffer;
|
|
1259
1336
|
|
|
1337
|
+
/**
|
|
1338
|
+
* Tell if the public key of the certificate is the public half of the
|
|
1339
|
+
* private key, by comparing the two (RSA modulus, or elliptic curve and
|
|
1340
|
+
* public point). A key of another type than the certificate's does not
|
|
1341
|
+
* match: the answer is false, not an exception. It throws when both are of
|
|
1342
|
+
* one type that is neither RSA nor elliptic curve.
|
|
1343
|
+
*/
|
|
1260
1344
|
declare function publicKeyAndPrivateKeyMatches(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
1345
|
+
/**
|
|
1346
|
+
* Tell if the certificate belongs to the private key, by using the two
|
|
1347
|
+
* together: an RSA key decrypts what the certificate encrypted, an elliptic
|
|
1348
|
+
* curve certificate verifies what the key signed. A key of another type than
|
|
1349
|
+
* the certificate's does not match: the answer is false, not an exception.
|
|
1350
|
+
* It throws when both are of one type that is neither RSA nor elliptic curve.
|
|
1351
|
+
*/
|
|
1261
1352
|
declare function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
1262
1353
|
|
|
1263
1354
|
declare const asn1: {
|
|
@@ -1268,4 +1359,4 @@ declare const asn1: {
|
|
|
1268
1359
|
readSignatureValueBin: typeof readSignatureValueBin;
|
|
1269
1360
|
};
|
|
1270
1361
|
|
|
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 };
|
|
1362
|
+
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 EcNamedCurve, type EcPrivateKeyAlgorithm, 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, 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 _readSubjectPublicKeyInfoOfAnyType(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 = _readSubjectPublicKeyInfoOfAnyType(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 = _readSubjectPublicKeyInfoOfAnyType(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
|
}
|
|
@@ -47881,6 +47933,9 @@ function toNodeKeyObject(privateKey2) {
|
|
|
47881
47933
|
const hidden = privateKey2.hidden;
|
|
47882
47934
|
return typeof hidden === "string" ? createPrivateKeyFromNodeJSCrypto(hidden) : hidden;
|
|
47883
47935
|
}
|
|
47936
|
+
function getPrivateKeyType(privateKey) {
|
|
47937
|
+
return toNodeKeyObject(privateKey).asymmetricKeyType;
|
|
47938
|
+
}
|
|
47884
47939
|
function exploreEcPrivateKey(privateKey2) {
|
|
47885
47940
|
const keyObject = toNodeKeyObject(privateKey2);
|
|
47886
47941
|
if (keyObject.asymmetricKeyType !== "ec") {
|
|
@@ -62236,6 +62291,14 @@ init_inject_buffer();
|
|
|
62236
62291
|
async function buildPublicKey(privateKey) {
|
|
62237
62292
|
const crypto4 = getCrypto();
|
|
62238
62293
|
const jwk = await crypto4.subtle.exportKey("jwk", privateKey);
|
|
62294
|
+
if (privateKey.algorithm.name === "ECDSA") {
|
|
62295
|
+
const { kty, crv, x, y } = jwk;
|
|
62296
|
+
const namedCurve = privateKey.algorithm.namedCurve;
|
|
62297
|
+
const ecPublicKey = await crypto4.subtle.importKey("jwk", { kty, crv, x, y }, { name: "ECDSA", namedCurve }, true, [
|
|
62298
|
+
"verify"
|
|
62299
|
+
]);
|
|
62300
|
+
return ecPublicKey;
|
|
62301
|
+
}
|
|
62239
62302
|
delete jwk.d;
|
|
62240
62303
|
delete jwk.dp;
|
|
62241
62304
|
delete jwk.dq;
|
|
@@ -62254,6 +62317,54 @@ async function buildPublicKey(privateKey) {
|
|
|
62254
62317
|
return publicKey;
|
|
62255
62318
|
}
|
|
62256
62319
|
|
|
62320
|
+
// ../node-opcua-crypto/source/x509/_key_algorithm.ts
|
|
62321
|
+
init_inject_buffer();
|
|
62322
|
+
var webCryptoCurveNames = /* @__PURE__ */ new Map([
|
|
62323
|
+
["prime256v1", "P-256"],
|
|
62324
|
+
["secp384r1", "P-384"],
|
|
62325
|
+
["secp521r1", "P-521"]
|
|
62326
|
+
]);
|
|
62327
|
+
var hashOfCurve = /* @__PURE__ */ new Map([
|
|
62328
|
+
["P-256", "SHA-256"],
|
|
62329
|
+
["P-384", "SHA-384"],
|
|
62330
|
+
["P-521", "SHA-512"]
|
|
62331
|
+
]);
|
|
62332
|
+
function toWebCryptoCurveName(namedCurve) {
|
|
62333
|
+
const name = webCryptoCurveNames.get(namedCurve);
|
|
62334
|
+
if (!name) {
|
|
62335
|
+
throw new Error(`Unsupported elliptic curve: ${namedCurve}`);
|
|
62336
|
+
}
|
|
62337
|
+
return name;
|
|
62338
|
+
}
|
|
62339
|
+
function signingAlgorithmOfKey(key) {
|
|
62340
|
+
if (key.algorithm.name !== "ECDSA") {
|
|
62341
|
+
return { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-256" } };
|
|
62342
|
+
}
|
|
62343
|
+
const namedCurve = key.algorithm.namedCurve;
|
|
62344
|
+
const hash2 = hashOfCurve.get(namedCurve);
|
|
62345
|
+
if (!hash2) {
|
|
62346
|
+
throw new Error(`Unsupported elliptic curve: ${namedCurve}`);
|
|
62347
|
+
}
|
|
62348
|
+
return { name: "ECDSA", namedCurve, hash: { name: hash2 } };
|
|
62349
|
+
}
|
|
62350
|
+
function keyTypeOfAlgorithm(algorithm) {
|
|
62351
|
+
return algorithm.name === "ECDSA" || algorithm.name === "ECDH" ? "ec" : "rsa";
|
|
62352
|
+
}
|
|
62353
|
+
function readPkcs8KeyAlgorithm(privDer) {
|
|
62354
|
+
try {
|
|
62355
|
+
const buffer = import_buffer.Buffer.from(privDer);
|
|
62356
|
+
const blocks = readStruct(buffer, readTag(buffer, 0));
|
|
62357
|
+
const parts = readStruct(buffer, blocks[1]);
|
|
62358
|
+
const algorithm = readObjectIdentifier(buffer, parts[0]).name;
|
|
62359
|
+
if (algorithm !== "ecPublicKey" || parts[1]?.tag !== 6 /* OBJECT_IDENTIFIER */) {
|
|
62360
|
+
return { algorithm };
|
|
62361
|
+
}
|
|
62362
|
+
return { algorithm, namedCurve: readObjectIdentifier(buffer, parts[1]).name };
|
|
62363
|
+
} catch {
|
|
62364
|
+
return void 0;
|
|
62365
|
+
}
|
|
62366
|
+
}
|
|
62367
|
+
|
|
62257
62368
|
// ../node-opcua-crypto/source/x509/ca_signer.ts
|
|
62258
62369
|
var ECDSA_COORDINATE_BYTES = {
|
|
62259
62370
|
"P-256": 32,
|
|
@@ -62417,7 +62528,7 @@ async function resolveCaKeyPair(key, baseCrypto = getCrypto()) {
|
|
|
62417
62528
|
return {
|
|
62418
62529
|
crypto: baseCrypto,
|
|
62419
62530
|
keys: { privateKey: key, publicKey: await buildPublicKey(key) },
|
|
62420
|
-
signingAlgorithm:
|
|
62531
|
+
signingAlgorithm: signingAlgorithmOfKey(key)
|
|
62421
62532
|
};
|
|
62422
62533
|
}
|
|
62423
62534
|
|
|
@@ -62427,8 +62538,17 @@ init_inject_buffer();
|
|
|
62427
62538
|
// ../node-opcua-crypto/source/x509/create_key_pair.ts
|
|
62428
62539
|
init_inject_buffer();
|
|
62429
62540
|
var ENCRYPTED_PEM_HEADER = "-----BEGIN ENCRYPTED PRIVATE KEY-----";
|
|
62430
|
-
|
|
62541
|
+
var SEC1_PEM_HEADER = "-----BEGIN EC PRIVATE KEY-----";
|
|
62542
|
+
async function generateKeyPair(keyAlgorithm = 2048) {
|
|
62431
62543
|
const crypto4 = getCrypto();
|
|
62544
|
+
if (typeof keyAlgorithm !== "number") {
|
|
62545
|
+
if (keyAlgorithm?.type !== "ec") {
|
|
62546
|
+
throw new Error(`generateKeyPair: unsupported key algorithm ${JSON.stringify(keyAlgorithm)}`);
|
|
62547
|
+
}
|
|
62548
|
+
const ecAlg = { name: "ECDSA", namedCurve: toWebCryptoCurveName(keyAlgorithm.namedCurve) };
|
|
62549
|
+
return await crypto4.subtle.generateKey(ecAlg, true, ["sign", "verify"]);
|
|
62550
|
+
}
|
|
62551
|
+
const modulusLength = keyAlgorithm;
|
|
62432
62552
|
const alg = {
|
|
62433
62553
|
name: "RSASSA-PKCS1-v1_5",
|
|
62434
62554
|
hash: { name: "SHA-256" },
|
|
@@ -62438,8 +62558,8 @@ async function generateKeyPair(modulusLength = 2048) {
|
|
|
62438
62558
|
const keys = await crypto4.subtle.generateKey(alg, true, ["sign", "verify"]);
|
|
62439
62559
|
return keys;
|
|
62440
62560
|
}
|
|
62441
|
-
async function generatePrivateKey(
|
|
62442
|
-
return (await generateKeyPair(
|
|
62561
|
+
async function generatePrivateKey(keyAlgorithm = 2048) {
|
|
62562
|
+
return (await generateKeyPair(keyAlgorithm)).privateKey;
|
|
62443
62563
|
}
|
|
62444
62564
|
async function privateKeyToPEM(privateKey) {
|
|
62445
62565
|
const crypto4 = getCrypto();
|
|
@@ -62449,6 +62569,14 @@ async function privateKeyToPEM(privateKey) {
|
|
|
62449
62569
|
}
|
|
62450
62570
|
async function derToPrivateKey(privDer) {
|
|
62451
62571
|
const crypto4 = getCrypto();
|
|
62572
|
+
const keyAlgorithm = readPkcs8KeyAlgorithm(privDer);
|
|
62573
|
+
if (keyAlgorithm?.algorithm === "ecPublicKey") {
|
|
62574
|
+
if (!keyAlgorithm.namedCurve) {
|
|
62575
|
+
throw new Error("derToPrivateKey: the elliptic curve key does not name its curve");
|
|
62576
|
+
}
|
|
62577
|
+
const ecAlg = { name: "ECDSA", namedCurve: toWebCryptoCurveName(keyAlgorithm.namedCurve) };
|
|
62578
|
+
return await crypto4.subtle.importKey("pkcs8", privDer, ecAlg, true, ["sign"]);
|
|
62579
|
+
}
|
|
62452
62580
|
const importedKey = await crypto4.subtle.importKey(
|
|
62453
62581
|
"pkcs8",
|
|
62454
62582
|
privDer,
|
|
@@ -62476,6 +62604,11 @@ async function pemToPrivateKey(pem2) {
|
|
|
62476
62604
|
"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
62605
|
);
|
|
62478
62606
|
}
|
|
62607
|
+
if (pem2.includes(SEC1_PEM_HEADER)) {
|
|
62608
|
+
throw new Error(
|
|
62609
|
+
"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()."
|
|
62610
|
+
);
|
|
62611
|
+
}
|
|
62479
62612
|
const privDer = x509_es_exports.PemConverter.decode(pem2);
|
|
62480
62613
|
return derToPrivateKey(privDer[0]);
|
|
62481
62614
|
}
|
|
@@ -62519,8 +62652,9 @@ init_inject_buffer();
|
|
|
62519
62652
|
// ../node-opcua-crypto/source/x509/_get_attributes.ts
|
|
62520
62653
|
init_inject_buffer();
|
|
62521
62654
|
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;
|
|
62655
|
+
var keyUsageApplicationEc = x509_es_exports.KeyUsageFlags.digitalSignature | x509_es_exports.KeyUsageFlags.nonRepudiation | x509_es_exports.KeyUsageFlags.keyAgreement | x509_es_exports.KeyUsageFlags.keyCertSign;
|
|
62522
62656
|
var keyUsageCA = x509_es_exports.KeyUsageFlags.keyCertSign | x509_es_exports.KeyUsageFlags.cRLSign;
|
|
62523
|
-
function getAttributes(purpose) {
|
|
62657
|
+
function getAttributes(purpose, keyType = "rsa") {
|
|
62524
62658
|
let basicConstraints;
|
|
62525
62659
|
let keyUsageExtension = [];
|
|
62526
62660
|
let usages;
|
|
@@ -62539,7 +62673,7 @@ function getAttributes(purpose) {
|
|
|
62539
62673
|
default:
|
|
62540
62674
|
_extension = "v3_selfsigned";
|
|
62541
62675
|
basicConstraints = new x509_es_exports.BasicConstraintsExtension(false, void 0, true);
|
|
62542
|
-
usages = keyUsageApplication;
|
|
62676
|
+
usages = keyType === "ec" ? keyUsageApplicationEc : keyUsageApplication;
|
|
62543
62677
|
keyUsageExtension = [x509_es_exports.ExtendedKeyUsage.serverAuth, x509_es_exports.ExtendedKeyUsage.clientAuth];
|
|
62544
62678
|
nsComment = "Self-signed certificate generated by Node-OPCUA Certificate utility V2";
|
|
62545
62679
|
break;
|
|
@@ -62549,7 +62683,8 @@ function getAttributes(purpose) {
|
|
|
62549
62683
|
|
|
62550
62684
|
// ../node-opcua-crypto/source/x509/create_certificate_from_csr.ts
|
|
62551
62685
|
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
|
-
|
|
62686
|
+
var keyUsageIssuedApplicationEc = x509_es_exports.KeyUsageFlags.digitalSignature | x509_es_exports.KeyUsageFlags.nonRepudiation | x509_es_exports.KeyUsageFlags.keyAgreement;
|
|
62687
|
+
function getIssuedAttributes(purpose, keyType) {
|
|
62553
62688
|
if (purpose === 1 /* ForCertificateAuthority */) {
|
|
62554
62689
|
return getAttributes(purpose);
|
|
62555
62690
|
}
|
|
@@ -62557,7 +62692,7 @@ function getIssuedAttributes(purpose) {
|
|
|
62557
62692
|
nsComment: "Certificate generated by Node-OPCUA Certificate utility V2",
|
|
62558
62693
|
basicConstraints: new x509_es_exports.BasicConstraintsExtension(false, void 0, true),
|
|
62559
62694
|
keyUsageExtension: [x509_es_exports.ExtendedKeyUsage.serverAuth, x509_es_exports.ExtendedKeyUsage.clientAuth],
|
|
62560
|
-
usages: keyUsageIssuedApplication
|
|
62695
|
+
usages: keyType === "ec" ? keyUsageIssuedApplicationEc : keyUsageIssuedApplication
|
|
62561
62696
|
};
|
|
62562
62697
|
}
|
|
62563
62698
|
async function createCertificateFromCsr(options) {
|
|
@@ -62567,7 +62702,10 @@ async function createCertificateFromCsr(options) {
|
|
|
62567
62702
|
if (!csrIsValid) {
|
|
62568
62703
|
throw new Error("createCertificateFromCsr: the CSR signature does not verify \u2014 refusing to sign an unproven key");
|
|
62569
62704
|
}
|
|
62570
|
-
const { basicConstraints, keyUsageExtension, usages } = getIssuedAttributes(
|
|
62705
|
+
const { basicConstraints, keyUsageExtension, usages } = getIssuedAttributes(
|
|
62706
|
+
options.purpose,
|
|
62707
|
+
keyTypeOfAlgorithm(csr.publicKey.algorithm)
|
|
62708
|
+
);
|
|
62571
62709
|
const alternativeNameExtensions = [];
|
|
62572
62710
|
for (const d of options.dns ?? []) {
|
|
62573
62711
|
alternativeNameExtensions.push({ type: "dns", value: d });
|
|
@@ -62635,7 +62773,7 @@ async function createCertificateSigningRequest({
|
|
|
62635
62773
|
if (applicationUri) {
|
|
62636
62774
|
alternativeNameExtensions.push({ type: "url", value: applicationUri });
|
|
62637
62775
|
}
|
|
62638
|
-
const { basicConstraints, usages } = getAttributes(purpose);
|
|
62776
|
+
const { basicConstraints, usages } = getAttributes(purpose, keyTypeOfAlgorithm(signingAlgorithm));
|
|
62639
62777
|
const s = new Subject(subject || "");
|
|
62640
62778
|
const s1 = s.toStringInternal(", ");
|
|
62641
62779
|
const name = s1;
|
|
@@ -62701,7 +62839,7 @@ async function createSelfSignedCertificate({
|
|
|
62701
62839
|
purpose
|
|
62702
62840
|
}) {
|
|
62703
62841
|
const { crypto: crypto4, keys, signingAlgorithm } = await resolveCaKeyPair(privateKey);
|
|
62704
|
-
const { nsComment, basicConstraints, keyUsageExtension, usages } = getAttributes(purpose);
|
|
62842
|
+
const { nsComment, basicConstraints, keyUsageExtension, usages } = getAttributes(purpose, keyTypeOfAlgorithm(signingAlgorithm));
|
|
62705
62843
|
notBefore = notBefore || /* @__PURE__ */ new Date();
|
|
62706
62844
|
validity = validity || 0;
|
|
62707
62845
|
if (!notAfter) {
|
|
@@ -62736,8 +62874,9 @@ async function createSelfSignedCertificate({
|
|
|
62736
62874
|
name,
|
|
62737
62875
|
notBefore,
|
|
62738
62876
|
notAfter,
|
|
62739
|
-
// for a raw key resolveCaKeyPair yields exactly the historical
|
|
62740
|
-
// RSASSA-PKCS1-v1_5/SHA-256
|
|
62877
|
+
// for a raw RSA key resolveCaKeyPair yields exactly the historical
|
|
62878
|
+
// RSASSA-PKCS1-v1_5/SHA-256, for a raw elliptic curve key ECDSA with
|
|
62879
|
+
// the hash of the curve; for a CaSigner, the signer's declared algorithm
|
|
62741
62880
|
signingAlgorithm,
|
|
62742
62881
|
keys,
|
|
62743
62882
|
extensions: [
|
|
@@ -63177,6 +63316,9 @@ function verifyChunkSignature(chunk, options) {
|
|
|
63177
63316
|
let signatureLength = options.signatureLength || 0;
|
|
63178
63317
|
if (signatureLength === 0) {
|
|
63179
63318
|
const cert = exploreCertificateInfo(options.publicKey);
|
|
63319
|
+
if (cert.keyType !== "rsa") {
|
|
63320
|
+
throw new Error(`verifyChunkSignature: signatureLength is required with a "${cert.keyType}" certificate`);
|
|
63321
|
+
}
|
|
63180
63322
|
signatureLength = cert.publicKeyLength || 0;
|
|
63181
63323
|
}
|
|
63182
63324
|
const block_to_verify = chunk.subarray(0, chunk.length - signatureLength);
|
|
@@ -63445,11 +63587,33 @@ function makePrivateKeyThumbPrint(_privateKey) {
|
|
|
63445
63587
|
|
|
63446
63588
|
// ../node-opcua-crypto/source/public_private_match.ts
|
|
63447
63589
|
init_inject_buffer();
|
|
63590
|
+
init_node_crypto_shim();
|
|
63591
|
+
function sharedKeyType(certificateKeyType, privateKey, caller) {
|
|
63592
|
+
const keyType = getPrivateKeyType(privateKey) ?? "rsa";
|
|
63593
|
+
if (certificateKeyType !== keyType) {
|
|
63594
|
+
return void 0;
|
|
63595
|
+
}
|
|
63596
|
+
if (keyType !== "rsa" && keyType !== "ec") {
|
|
63597
|
+
throw new Error(`${caller}: "${keyType}" keys are not supported`);
|
|
63598
|
+
}
|
|
63599
|
+
return keyType;
|
|
63600
|
+
}
|
|
63601
|
+
function ecPublicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
63602
|
+
const fromCertificate = createPublicKey(certificate);
|
|
63603
|
+
const fromPrivateKey = createPublicKey(privateKey.hidden);
|
|
63604
|
+
return fromCertificate.equals(fromPrivateKey);
|
|
63605
|
+
}
|
|
63448
63606
|
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
63449
|
-
const
|
|
63450
|
-
const
|
|
63451
|
-
|
|
63452
|
-
|
|
63607
|
+
const subjectPublicKeyInfo = exploreCertificate(certificate).tbsCertificate.subjectPublicKeyInfo;
|
|
63608
|
+
const keyType = sharedKeyType(subjectPublicKeyInfo.keyType, privateKey, "publicKeyAndPrivateKeyMatches");
|
|
63609
|
+
if (!keyType) {
|
|
63610
|
+
return false;
|
|
63611
|
+
}
|
|
63612
|
+
if (keyType === "ec") {
|
|
63613
|
+
return ecPublicKeyAndPrivateKeyMatches(toPem(certificate, "CERTIFICATE"), privateKey);
|
|
63614
|
+
}
|
|
63615
|
+
const modulus1 = subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
63616
|
+
const modulus2 = explorePrivateKey(privateKey).modulus;
|
|
63453
63617
|
if (modulus1.length !== modulus2.length) {
|
|
63454
63618
|
return false;
|
|
63455
63619
|
}
|
|
@@ -63462,10 +63626,23 @@ function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
|
63462
63626
|
const finalString = decryptedBuffer.toString("utf-8");
|
|
63463
63627
|
return initialBuffer.toString("utf-8") === finalString;
|
|
63464
63628
|
}
|
|
63629
|
+
function ecCertificateMatchesPrivateKey(certificate, privateKey) {
|
|
63630
|
+
const data = import_buffer.Buffer.from("Lorem Ipsum");
|
|
63631
|
+
const signature = createSign("sha256").update(data).sign(privateKey.hidden);
|
|
63632
|
+
return createVerify("sha256").update(data).verify(certificate, signature);
|
|
63633
|
+
}
|
|
63465
63634
|
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
63635
|
+
const subjectPublicKeyInfo = exploreCertificate(certificate).tbsCertificate.subjectPublicKeyInfo;
|
|
63636
|
+
const keyType = sharedKeyType(subjectPublicKeyInfo.keyType, privateKey, "certificateMatchesPrivateKey");
|
|
63637
|
+
if (!keyType) {
|
|
63638
|
+
return false;
|
|
63639
|
+
}
|
|
63640
|
+
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
63641
|
+
if (keyType === "ec") {
|
|
63642
|
+
return ecPublicKeyAndPrivateKeyMatches(certificatePEM, privateKey) && ecCertificateMatchesPrivateKey(certificatePEM, privateKey);
|
|
63643
|
+
}
|
|
63466
63644
|
const e = explorePrivateKey(privateKey);
|
|
63467
63645
|
const blockSize = e.modulus.length;
|
|
63468
|
-
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
63469
63646
|
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
63470
63647
|
}
|
|
63471
63648
|
|
|
@@ -63525,6 +63702,7 @@ export {
|
|
|
63525
63702
|
generateKeyPair,
|
|
63526
63703
|
generatePrivateKey,
|
|
63527
63704
|
getCrypto,
|
|
63705
|
+
getPrivateKeyType,
|
|
63528
63706
|
hasSyncKeyOperations,
|
|
63529
63707
|
hexDump,
|
|
63530
63708
|
identifyDERContent,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-crypto-web",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.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.3.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": "7b866baa874d2ce87f75518a953d9935a5ebf057"
|
|
71
71
|
}
|