node-opcua-crypto-web 6.3.0 → 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 +72 -8
- package/dist/index_web.js +126 -25
- package/package.json +3 -3
package/dist/index_web.d.ts
CHANGED
|
@@ -259,6 +259,13 @@ declare function readExtension(buffer: Buffer, block: BlockInfo): {
|
|
|
259
259
|
[key: string]: string[];
|
|
260
260
|
};
|
|
261
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;
|
|
262
269
|
/** The family a certificate's public key belongs to. */
|
|
263
270
|
type PublicKeyType = "rsa" | "ec" | "ed25519" | "ed448" | "x25519" | "x448" | "unknown";
|
|
264
271
|
interface SubjectPublicKeyInfo {
|
|
@@ -476,8 +483,30 @@ interface ExtensionRequest {
|
|
|
476
483
|
subjectAltName: SubjectAltName;
|
|
477
484
|
}
|
|
478
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
|
+
*/
|
|
479
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;
|
|
480
502
|
}
|
|
503
|
+
/**
|
|
504
|
+
* CertificationRequestInfo ::= SEQUENCE {
|
|
505
|
+
* version INTEGER,
|
|
506
|
+
* subject Name,
|
|
507
|
+
* subjectPKInfo SubjectPublicKeyInfo,
|
|
508
|
+
* attributes [0] Attributes }
|
|
509
|
+
*/
|
|
481
510
|
declare function readCertificationRequestInfo(buffer: Buffer, block: BlockInfo): CertificateSigningRequestInfo;
|
|
482
511
|
declare function exploreCertificateSigningRequest(crl: Buffer): CertificateSigningRequestInfo;
|
|
483
512
|
|
|
@@ -559,6 +588,8 @@ type DERContentType = "X509Certificate" | "X509CertificateChain" | "CertificateR
|
|
|
559
588
|
*/
|
|
560
589
|
declare function identifyDERContent(buffer: Buffer): DERContentType;
|
|
561
590
|
|
|
591
|
+
declare function getCrypto(): Crypto$1 | typeof __crypto;
|
|
592
|
+
|
|
562
593
|
/**
|
|
563
594
|
* The signing algorithm a {@link CaSigner} operates under. This travels with
|
|
564
595
|
* the signer rather than being inferred from a key, because an HSM/KMS-backed
|
|
@@ -579,14 +610,21 @@ type CaSignAlgorithm = {
|
|
|
579
610
|
* *import* the signer's public key, and `importKey` cannot infer a
|
|
580
611
|
* curve it was not given. Declaring it wrong is safe: the SPKI
|
|
581
612
|
* bytes returned by {@link CaSigner.getPublicKey} state the real
|
|
582
|
-
* curve,
|
|
583
|
-
* 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.
|
|
584
615
|
*/
|
|
585
|
-
namedCurve:
|
|
616
|
+
namedCurve: EcdsaCurveName;
|
|
586
617
|
hash: {
|
|
587
618
|
name: "SHA-256" | "SHA-384" | "SHA-512";
|
|
588
619
|
};
|
|
589
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";
|
|
590
628
|
/**
|
|
591
629
|
* Abstraction over "something that can produce a certificate/CRL signature",
|
|
592
630
|
* without ever exposing private key material.
|
|
@@ -646,7 +684,7 @@ interface CaSigner {
|
|
|
646
684
|
* @param namedCurve the curve the signing key lives on, which fixes the
|
|
647
685
|
* width each coordinate is padded to
|
|
648
686
|
*/
|
|
649
|
-
declare function ecdsaSignatureDerToP1363(derSignature: BufferSource, namedCurve:
|
|
687
|
+
declare function ecdsaSignatureDerToP1363(derSignature: BufferSource, namedCurve: EcdsaCurveName): ArrayBuffer;
|
|
650
688
|
/**
|
|
651
689
|
* Adapts an in-process key pair (e.g. one produced by {@link generateKeyPair}
|
|
652
690
|
* or read from disk via {@link pemToPrivateKey}) to the {@link CaSigner}
|
|
@@ -685,8 +723,19 @@ interface WebCryptoFromSigner {
|
|
|
685
723
|
* anything other than the paired {@link crypto} object.
|
|
686
724
|
*/
|
|
687
725
|
privateKeyHandle: CryptoKey;
|
|
688
|
-
/**
|
|
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
|
+
*/
|
|
689
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;
|
|
690
739
|
}
|
|
691
740
|
/**
|
|
692
741
|
* Build a `Crypto`-shaped adapter that routes signing through `signer`
|
|
@@ -937,8 +986,6 @@ declare function verifyCertificateChain(certificateChain: Certificate[]): Promis
|
|
|
937
986
|
reason: string;
|
|
938
987
|
}>;
|
|
939
988
|
|
|
940
|
-
declare function getCrypto(): Crypto$1 | typeof __crypto;
|
|
941
|
-
|
|
942
989
|
/**
|
|
943
990
|
* Authority Key Identifier extension identifying the issuer by its public
|
|
944
991
|
* key (`keyid`), matching what {@link createSelfSignedCertificate} already
|
|
@@ -1082,11 +1129,28 @@ declare function createCrl(options: CreateCrlOptions): Promise<{
|
|
|
1082
1129
|
* OpenSSL uses and that `exploreCertificate` reports in `namedCurve`.
|
|
1083
1130
|
*/
|
|
1084
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";
|
|
1085
1139
|
/** Asks for an elliptic curve key where a number asks for an RSA key of that size. */
|
|
1086
1140
|
interface EcPrivateKeyAlgorithm {
|
|
1087
1141
|
type: "ec";
|
|
1088
1142
|
namedCurve: EcNamedCurve;
|
|
1089
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
|
+
}
|
|
1090
1154
|
type RsaModulusLength = 1024 | 2048 | 3072 | 4096;
|
|
1091
1155
|
|
|
1092
1156
|
/**
|
|
@@ -1359,4 +1423,4 @@ declare const asn1: {
|
|
|
1359
1423
|
readSignatureValueBin: typeof readSignatureValueBin;
|
|
1360
1424
|
};
|
|
1361
1425
|
|
|
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 };
|
|
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
|
@@ -47475,7 +47475,7 @@ function _readSubjectOtherPublicKeyInfo(buffer, block, algorithm) {
|
|
|
47475
47475
|
}
|
|
47476
47476
|
};
|
|
47477
47477
|
}
|
|
47478
|
-
function
|
|
47478
|
+
function readSubjectPublicKeyInfo(buffer, block) {
|
|
47479
47479
|
const inner_blocks = readStruct(buffer, block);
|
|
47480
47480
|
const what_type = readAlgorithmIdentifier(buffer, inner_blocks[0]).identifier;
|
|
47481
47481
|
switch (what_type) {
|
|
@@ -47506,7 +47506,7 @@ function readTbsCertificate(buffer, block) {
|
|
|
47506
47506
|
validity = _readValidity(buffer, blocks[3]);
|
|
47507
47507
|
subject = _readName(buffer, blocks[4]);
|
|
47508
47508
|
subjectFingerPrint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[4])));
|
|
47509
|
-
subjectPublicKeyInfo =
|
|
47509
|
+
subjectPublicKeyInfo = readSubjectPublicKeyInfo(buffer, blocks[5]);
|
|
47510
47510
|
extensions = null;
|
|
47511
47511
|
} else {
|
|
47512
47512
|
const version_block = findBlockAtIndex(blocks, 0);
|
|
@@ -47520,7 +47520,7 @@ function readTbsCertificate(buffer, block) {
|
|
|
47520
47520
|
validity = _readValidity(buffer, blocks[4]);
|
|
47521
47521
|
subject = _readName(buffer, blocks[5]);
|
|
47522
47522
|
subjectFingerPrint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[5])));
|
|
47523
|
-
subjectPublicKeyInfo =
|
|
47523
|
+
subjectPublicKeyInfo = readSubjectPublicKeyInfo(buffer, blocks[6]);
|
|
47524
47524
|
const extensionBlock = findBlockAtIndex(blocks, 3);
|
|
47525
47525
|
if (!extensionBlock) {
|
|
47526
47526
|
doDebug && console.log(`X509 certificate is invalid : cannot find extension block version = ${version_block}`);
|
|
@@ -47901,29 +47901,34 @@ function _readExtensionRequest(buffer) {
|
|
|
47901
47901
|
}
|
|
47902
47902
|
return result;
|
|
47903
47903
|
}
|
|
47904
|
-
function
|
|
47905
|
-
const
|
|
47906
|
-
|
|
47907
|
-
|
|
47908
|
-
|
|
47909
|
-
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;
|
|
47910
47909
|
}
|
|
47911
|
-
|
|
47912
|
-
|
|
47913
|
-
const identifier = readObjectIdentifier(buffer, blocks2[0]);
|
|
47914
|
-
if (identifier.name !== "extensionRequest") {
|
|
47915
|
-
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]));
|
|
47916
47912
|
}
|
|
47917
|
-
const buf = getBlock(buffer, blocks2[1]);
|
|
47918
|
-
const extensionRequest = _readExtensionRequest(buf);
|
|
47919
|
-
return { extensionRequest };
|
|
47920
47913
|
}
|
|
47921
|
-
|
|
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 };
|
|
47922
47926
|
}
|
|
47923
47927
|
function exploreCertificateSigningRequest(crl) {
|
|
47924
47928
|
const blockInfo = readTag(crl, 0);
|
|
47925
47929
|
const blocks = readStruct(crl, blockInfo);
|
|
47926
47930
|
const csrInfo = readCertificationRequestInfo(crl, blocks[0]);
|
|
47931
|
+
csrInfo.signatureAlgorithm = readAlgorithmIdentifier(crl, blocks[1]);
|
|
47927
47932
|
return csrInfo;
|
|
47928
47933
|
}
|
|
47929
47934
|
|
|
@@ -62249,6 +62254,19 @@ if (typeof window === "undefined") {
|
|
|
62249
62254
|
function getCrypto() {
|
|
62250
62255
|
return _crypto || crypto || node_crypto_shim_default;
|
|
62251
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
|
+
}
|
|
62252
62270
|
function ensurePemTrailingNewline(pem2) {
|
|
62253
62271
|
return pem2.endsWith("\n") ? pem2 : `${pem2}
|
|
62254
62272
|
`;
|
|
@@ -62327,8 +62345,14 @@ var webCryptoCurveNames = /* @__PURE__ */ new Map([
|
|
|
62327
62345
|
var hashOfCurve = /* @__PURE__ */ new Map([
|
|
62328
62346
|
["P-256", "SHA-256"],
|
|
62329
62347
|
["P-384", "SHA-384"],
|
|
62330
|
-
["P-521", "SHA-512"]
|
|
62348
|
+
["P-521", "SHA-512"],
|
|
62349
|
+
["brainpoolP256r1", "SHA-256"],
|
|
62350
|
+
["brainpoolP384r1", "SHA-384"],
|
|
62351
|
+
["brainpoolP512r1", "SHA-512"]
|
|
62331
62352
|
]);
|
|
62353
|
+
function isEcdsaCurveName(name) {
|
|
62354
|
+
return typeof name === "string" && hashOfCurve.has(name);
|
|
62355
|
+
}
|
|
62332
62356
|
function toWebCryptoCurveName(namedCurve) {
|
|
62333
62357
|
const name = webCryptoCurveNames.get(namedCurve);
|
|
62334
62358
|
if (!name) {
|
|
@@ -62370,8 +62394,18 @@ var ECDSA_COORDINATE_BYTES = {
|
|
|
62370
62394
|
"P-256": 32,
|
|
62371
62395
|
"P-384": 48,
|
|
62372
62396
|
// 521 bits is not a byte multiple, so each coordinate occupies 66 bytes
|
|
62373
|
-
"P-521": 66
|
|
62397
|
+
"P-521": 66,
|
|
62398
|
+
brainpoolP256r1: 32,
|
|
62399
|
+
brainpoolP384r1: 48,
|
|
62400
|
+
brainpoolP512r1: 64
|
|
62374
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
|
+
}
|
|
62375
62409
|
function asBytes(source) {
|
|
62376
62410
|
if (source instanceof Uint8Array) {
|
|
62377
62411
|
return source;
|
|
@@ -62471,9 +62505,26 @@ var LocalPrivateKeySigner = class {
|
|
|
62471
62505
|
return this.#crypto.subtle.sign(this.algorithm, this.#privateKey, tbs);
|
|
62472
62506
|
}
|
|
62473
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
|
+
}
|
|
62474
62518
|
async function webCryptoFromSigner(signer, baseCrypto = getCrypto()) {
|
|
62519
|
+
registerCurveSizes();
|
|
62475
62520
|
const publicKeyDer = await signer.getPublicKey();
|
|
62476
|
-
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"] };
|
|
62477
62528
|
const privateKeyHandle = {
|
|
62478
62529
|
type: "private",
|
|
62479
62530
|
extractable: false,
|
|
@@ -62491,6 +62542,17 @@ async function webCryptoFromSigner(signer, baseCrypto = getCrypto()) {
|
|
|
62491
62542
|
return signer.sign(bytes);
|
|
62492
62543
|
};
|
|
62493
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
|
+
}
|
|
62494
62556
|
const value = Reflect.get(target, prop, receiver);
|
|
62495
62557
|
return typeof value === "function" ? value.bind(target) : value;
|
|
62496
62558
|
}
|
|
@@ -62504,7 +62566,7 @@ async function webCryptoFromSigner(signer, baseCrypto = getCrypto()) {
|
|
|
62504
62566
|
return typeof value === "function" ? value.bind(target) : value;
|
|
62505
62567
|
}
|
|
62506
62568
|
});
|
|
62507
|
-
return { crypto: crypto4, privateKeyHandle, publicKey };
|
|
62569
|
+
return { crypto: crypto4, privateKeyHandle, publicKey, x509PublicKey };
|
|
62508
62570
|
}
|
|
62509
62571
|
function isCaSigner(value) {
|
|
62510
62572
|
return typeof value.sign === "function" && typeof value.getPublicKey === "function";
|
|
@@ -62648,6 +62710,7 @@ async function _coercePrivateKey(privateKey) {
|
|
|
62648
62710
|
|
|
62649
62711
|
// ../node-opcua-crypto/source/x509/create_certificate_from_csr.ts
|
|
62650
62712
|
init_inject_buffer();
|
|
62713
|
+
init_node_crypto_shim();
|
|
62651
62714
|
|
|
62652
62715
|
// ../node-opcua-crypto/source/x509/_get_attributes.ts
|
|
62653
62716
|
init_inject_buffer();
|
|
@@ -62695,10 +62758,45 @@ function getIssuedAttributes(purpose, keyType) {
|
|
|
62695
62758
|
usages: keyType === "ec" ? keyUsageIssuedApplicationEc : keyUsageIssuedApplication
|
|
62696
62759
|
};
|
|
62697
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
|
+
}
|
|
62698
62796
|
async function createCertificateFromCsr(options) {
|
|
62699
62797
|
const crypto4 = getCrypto();
|
|
62700
62798
|
const csr = new x509_es_exports.Pkcs10CertificateRequest(options.csr);
|
|
62701
|
-
const csrIsValid = await csr.verify(crypto4);
|
|
62799
|
+
const csrIsValid = verifyRequestSignatureWithOpenSSL(csr) ?? await csr.verify(crypto4);
|
|
62702
62800
|
if (!csrIsValid) {
|
|
62703
62801
|
throw new Error("createCertificateFromCsr: the CSR signature does not verify \u2014 refusing to sign an unproven key");
|
|
62704
62802
|
}
|
|
@@ -62886,8 +62984,10 @@ async function createSelfSignedCertificate({
|
|
|
62886
62984
|
// see RFC 5280 4.2.1.12 - an empty critical EKU is invalid
|
|
62887
62985
|
...keyUsageExtension.length > 0 ? [new x509_es_exports.ExtendedKeyUsageExtension(keyUsageExtension, true)] : [],
|
|
62888
62986
|
new x509_es_exports.KeyUsagesExtension(usages, true),
|
|
62889
|
-
|
|
62890
|
-
|
|
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),
|
|
62891
62991
|
new x509_es_exports.SubjectAlternativeNameExtension(alternativeNameExtensions)
|
|
62892
62992
|
]
|
|
62893
62993
|
},
|
|
@@ -63731,6 +63831,7 @@ export {
|
|
|
63731
63831
|
readCertificationRequestInfo,
|
|
63732
63832
|
readExtension,
|
|
63733
63833
|
readNameForCrl,
|
|
63834
|
+
readSubjectPublicKeyInfo,
|
|
63734
63835
|
readTbsCertificate,
|
|
63735
63836
|
reduceLength,
|
|
63736
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
|
}
|