node-opcua-crypto-web 5.8.0 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index_web.d.ts +323 -65
- package/dist/index_web.js +304 -2
- package/package.json +3 -3
package/dist/index_web.d.ts
CHANGED
|
@@ -429,6 +429,26 @@ interface PrivateKeyInternals {
|
|
|
429
429
|
exponent1: Buffer;
|
|
430
430
|
exponent2: Buffer;
|
|
431
431
|
}
|
|
432
|
+
interface ECPrivateKeyInternals {
|
|
433
|
+
version: Buffer;
|
|
434
|
+
/** the curve name, e.g. "prime256v1", resolved from the SEC1 ECParameters OID */
|
|
435
|
+
namedCurve: string;
|
|
436
|
+
/** the private scalar "d" */
|
|
437
|
+
privateKey: Buffer;
|
|
438
|
+
/** the uncompressed public point, when present in the key */
|
|
439
|
+
publicKey?: Buffer;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* explore the internal structure of an EC (SEC1) private key.
|
|
443
|
+
*
|
|
444
|
+
* ECPrivateKey ::= SEQUENCE {
|
|
445
|
+
* version INTEGER { ecPrivKeyVer1(1) },
|
|
446
|
+
* privateKey OCTET STRING,
|
|
447
|
+
* parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
|
|
448
|
+
* publicKey [1] BIT STRING OPTIONAL
|
|
449
|
+
* }
|
|
450
|
+
*/
|
|
451
|
+
declare function exploreEcPrivateKey(privateKey2: PrivateKey): ECPrivateKeyInternals;
|
|
432
452
|
/**
|
|
433
453
|
*
|
|
434
454
|
* @param privateKey RSAPrivateKey ::= SEQUENCE {
|
|
@@ -471,69 +491,6 @@ type DERContentType = "X509Certificate" | "X509CertificateChain" | "CertificateR
|
|
|
471
491
|
*/
|
|
472
492
|
declare function identifyDERContent(buffer: Buffer): DERContentType;
|
|
473
493
|
|
|
474
|
-
interface SubjectOptions {
|
|
475
|
-
commonName?: string;
|
|
476
|
-
organization?: string;
|
|
477
|
-
organizationalUnit?: string;
|
|
478
|
-
locality?: string;
|
|
479
|
-
state?: string;
|
|
480
|
-
country?: string;
|
|
481
|
-
domainComponent?: string;
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* subjectName The subject name to use for the Certificate.
|
|
485
|
-
* If not specified the ApplicationName and/or domainNames are used to create a suitable default value.
|
|
486
|
-
*/
|
|
487
|
-
declare class Subject implements SubjectOptions {
|
|
488
|
-
readonly commonName?: string;
|
|
489
|
-
readonly organization?: string;
|
|
490
|
-
readonly organizationalUnit?: string;
|
|
491
|
-
readonly locality?: string;
|
|
492
|
-
readonly state?: string;
|
|
493
|
-
readonly country?: string;
|
|
494
|
-
readonly domainComponent?: string;
|
|
495
|
-
constructor(options: SubjectOptions | string);
|
|
496
|
-
static parse(str: string): SubjectOptions;
|
|
497
|
-
toStringInternal(sep: string): string;
|
|
498
|
-
toStringForOPCUA(): string;
|
|
499
|
-
toString(): string;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
declare function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean;
|
|
503
|
-
declare function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean;
|
|
504
|
-
declare function verifyCertificateRevocationListSignature(certificateRevocationList: Certificate, parentCertificate: Certificate): boolean;
|
|
505
|
-
type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
|
|
506
|
-
declare function verifyCertificateChain(certificateChain: Certificate[]): Promise<{
|
|
507
|
-
status: _VerifyStatus;
|
|
508
|
-
reason: string;
|
|
509
|
-
}>;
|
|
510
|
-
|
|
511
|
-
declare function getCrypto(): Crypto$1 | typeof __crypto;
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* Authority Key Identifier extension identifying the issuer by its public
|
|
515
|
-
* key (`keyid`), matching what {@link createSelfSignedCertificate} already
|
|
516
|
-
* does for the self-signed case, and what openssl's
|
|
517
|
-
* `authorityKeyIdentifier = keyid:always` produces for the issued case.
|
|
518
|
-
*/
|
|
519
|
-
declare function buildAuthorityKeyIdentifierFromIssuer(issuerPublicKey: PublicKeyType, crypto?: Crypto): Promise<x509.AuthorityKeyIdentifierExtension>;
|
|
520
|
-
/** Opt-in CRL Distribution Point / Authority Info Access URLs for a certificate. */
|
|
521
|
-
interface RevocationExtensionsParams {
|
|
522
|
-
crlDistributionUrl?: string;
|
|
523
|
-
ocspResponderUrl?: string;
|
|
524
|
-
caIssuersUrl?: string;
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* Builds the CDP (`crlDistributionUrl`) and AIA (`ocspResponderUrl` /
|
|
528
|
-
* `caIssuersUrl`) extensions for a certificate, mirroring the
|
|
529
|
-
* `$ENV::CDP_URL` / `$ENV::AIA_VALUE` opt-in extensions the openssl-backed
|
|
530
|
-
* CA templates emit. Each extension is included only when at least one of
|
|
531
|
-
* its values is set.
|
|
532
|
-
*/
|
|
533
|
-
declare function buildRevocationExtensions(params: RevocationExtensionsParams): x509.Extension[];
|
|
534
|
-
/** The CRL Number extension (RFC 5280 §5.2.3), a plain monotonically-increasing counter. */
|
|
535
|
-
declare function buildCrlNumberExtension(crlNumber: number | bigint): x509.Extension;
|
|
536
|
-
|
|
537
494
|
/**
|
|
538
495
|
* The signing algorithm a {@link CaSigner} operates under. This travels with
|
|
539
496
|
* the signer rather than being inferred from a key, because an HSM/KMS-backed
|
|
@@ -548,6 +505,16 @@ type CaSignAlgorithm = {
|
|
|
548
505
|
};
|
|
549
506
|
} | {
|
|
550
507
|
name: "ECDSA";
|
|
508
|
+
/**
|
|
509
|
+
* The curve the key lives on. Required, unlike in most WebCrypto
|
|
510
|
+
* signing parameters, because {@link webCryptoFromSigner} has to
|
|
511
|
+
* *import* the signer's public key, and `importKey` cannot infer a
|
|
512
|
+
* curve it was not given. Declaring it wrong is safe: the SPKI
|
|
513
|
+
* bytes returned by {@link CaSigner.getPublicKey} state the real
|
|
514
|
+
* curve, so the import fails rather than producing a key that
|
|
515
|
+
* signs into the void.
|
|
516
|
+
*/
|
|
517
|
+
namedCurve: "P-256" | "P-384" | "P-521";
|
|
551
518
|
hash: {
|
|
552
519
|
name: "SHA-256" | "SHA-384" | "SHA-512";
|
|
553
520
|
};
|
|
@@ -570,10 +537,48 @@ interface CaSigner {
|
|
|
570
537
|
getPublicKey(): Promise<ArrayBuffer>;
|
|
571
538
|
/**
|
|
572
539
|
* Sign `tbs` (the to-be-signed bytes, e.g. a certificate or CRL's TBS
|
|
573
|
-
* DER encoding) and return the
|
|
540
|
+
* DER encoding) and return the signature.
|
|
541
|
+
*
|
|
542
|
+
* The signature must be encoded the way `SubtleCrypto.sign` encodes it,
|
|
543
|
+
* because that is what the certificate generators are given and what
|
|
544
|
+
* they know how to re-encode:
|
|
545
|
+
*
|
|
546
|
+
* - **RSA** - the signature bytes, with nothing to decide.
|
|
547
|
+
* - **ECDSA** - the fixed-width `r || s` pair of IEEE P1363, *not* the
|
|
548
|
+
* `SEQUENCE { r, s }` of DER. Certificates carry the DER form, but the
|
|
549
|
+
* conversion is done downstream; a signer that returns DER here
|
|
550
|
+
* produces a certificate whose signature will not verify.
|
|
551
|
+
*
|
|
552
|
+
* That distinction matters for KMS-backed signers: Google Cloud KMS,
|
|
553
|
+
* AWS KMS and most PKCS#11 tokens return ECDSA signatures already in
|
|
554
|
+
* DER, so their adapters have to convert to `r || s` before returning.
|
|
555
|
+
* {@link ecdsaSignatureDerToP1363} does that conversion.
|
|
574
556
|
*/
|
|
575
557
|
sign(tbs: Uint8Array): Promise<ArrayBuffer>;
|
|
576
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* Convert a DER-encoded ECDSA signature, `SEQUENCE { INTEGER r, INTEGER s }`,
|
|
561
|
+
* into the fixed-width `r || s` form that WebCrypto - and therefore
|
|
562
|
+
* {@link CaSigner.sign} - is defined to return.
|
|
563
|
+
*
|
|
564
|
+
* Use it when adapting a signer that hands back DER, which is what Google
|
|
565
|
+
* Cloud KMS, AWS KMS and most PKCS#11 tokens do:
|
|
566
|
+
*
|
|
567
|
+
* ```ts
|
|
568
|
+
* async sign(tbs: Uint8Array): Promise<ArrayBuffer> {
|
|
569
|
+
* const { signature } = await kms.asymmetricSign({ name: keyName, digest: { sha256: await sha256(tbs) } });
|
|
570
|
+
* return ecdsaSignatureDerToP1363(signature, "P-256");
|
|
571
|
+
* }
|
|
572
|
+
* ```
|
|
573
|
+
*
|
|
574
|
+
* Passing an already-converted signature is not silently tolerated: `r || s`
|
|
575
|
+
* is not valid DER, so it is rejected rather than corrupted further.
|
|
576
|
+
*
|
|
577
|
+
* @param derSignature the signature as `SEQUENCE { r, s }`
|
|
578
|
+
* @param namedCurve the curve the signing key lives on, which fixes the
|
|
579
|
+
* width each coordinate is padded to
|
|
580
|
+
*/
|
|
581
|
+
declare function ecdsaSignatureDerToP1363(derSignature: BufferSource, namedCurve: "P-256" | "P-384" | "P-521"): ArrayBuffer;
|
|
577
582
|
/**
|
|
578
583
|
* Adapts an in-process key pair (e.g. one produced by {@link generateKeyPair}
|
|
579
584
|
* or read from disk via {@link pemToPrivateKey}) to the {@link CaSigner}
|
|
@@ -663,6 +668,230 @@ interface ResolvedCaKeyPair {
|
|
|
663
668
|
*/
|
|
664
669
|
declare function resolveCaKeyPair(key: CryptoKey | CaSigner, baseCrypto?: Pick<Crypto, "subtle" | "getRandomValues">): Promise<ResolvedCaKeyPair>;
|
|
665
670
|
|
|
671
|
+
/**
|
|
672
|
+
* The signature scheme an {@link IKeyOperations.sign} call operates under.
|
|
673
|
+
*
|
|
674
|
+
* These are the schemes the OPC UA security policies need — PKCS#1 v1.5 for
|
|
675
|
+
* Basic128Rsa15 through Aes128_Sha256_RsaOaep, PSS for Aes256_Sha256_RsaPss —
|
|
676
|
+
* expressed as parameters rather than OPC UA algorithm URIs so this layer
|
|
677
|
+
* stays policy-agnostic. The mapping from a security policy to its parameters
|
|
678
|
+
* belongs to the caller.
|
|
679
|
+
*
|
|
680
|
+
* For `"RSA-PSS"` the salt length is fixed to the digest length
|
|
681
|
+
* (`RSA_PSS_SALTLEN_DIGEST`), which is what the OPC UA Aes256_Sha256_RsaPss
|
|
682
|
+
* profile — and WebCrypto's `saltLength: 32` convention for SHA-256 —
|
|
683
|
+
* expects. A remote signer whose backend salts differently (e.g. maximum
|
|
684
|
+
* salt) produces signatures peers cannot verify.
|
|
685
|
+
*/
|
|
686
|
+
interface AsymmetricSignParams {
|
|
687
|
+
padding: "RSA-PKCS1-v1_5" | "RSA-PSS";
|
|
688
|
+
hash: "SHA-1" | "SHA-256";
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* The decryption scheme an {@link IKeyOperations.decryptBlock} call operates
|
|
692
|
+
* under. `oaepHash` is required when `padding` is `"RSA-OAEP"` and names the
|
|
693
|
+
* hash used for both the OAEP digest and MGF1.
|
|
694
|
+
*/
|
|
695
|
+
interface AsymmetricDecryptParams {
|
|
696
|
+
padding: "RSA-PKCS1-v1_5" | "RSA-OAEP";
|
|
697
|
+
oaepHash?: "SHA-1" | "SHA-256";
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* The facts about a key that callers need before performing any operation
|
|
701
|
+
* with it — declared by the implementation, never inferred, because an
|
|
702
|
+
* HSM/KMS-held key exposes no material to inspect (the same reason
|
|
703
|
+
* {@link CaSignAlgorithm} travels with a {@link CaSigner}).
|
|
704
|
+
*
|
|
705
|
+
* Only RSA today. When EC security policies arrive, `keyType: "EC"` gains a
|
|
706
|
+
* `namedCurve` here and an ECDSA variant in {@link AsymmetricSignParams} —
|
|
707
|
+
* additive changes, not a second interface.
|
|
708
|
+
*/
|
|
709
|
+
interface KeyMetadata {
|
|
710
|
+
keyType: "RSA";
|
|
711
|
+
/**
|
|
712
|
+
* The RSA modulus size in **bytes** (256 for a 2048-bit key). For RSA
|
|
713
|
+
* this single number is also the signature length under both paddings
|
|
714
|
+
* and the cipher block size for {@link IKeyOperations.decryptBlock}.
|
|
715
|
+
*/
|
|
716
|
+
modulusLength: number;
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Opaque private-key operations: an object that can use a private key —
|
|
720
|
+
* sign, decrypt — without the key ever being obtainable through it.
|
|
721
|
+
*
|
|
722
|
+
* This is the secure-channel/session-side sibling of {@link CaSigner}
|
|
723
|
+
* (which covers X509 issuance and is sign-only): shaped after cloud
|
|
724
|
+
* KMS/HSM APIs, so the OPC UA application instance key can live in a TPM,
|
|
725
|
+
* HSM, KMS or OS keystore, non-exportable, while node-opcua drives it
|
|
726
|
+
* through this interface. Implementations wrap a local in-process key, a
|
|
727
|
+
* PKCS#11 token, a cloud KMS client — the caller cannot tell the
|
|
728
|
+
* difference, and this interface never asks for the key itself.
|
|
729
|
+
*
|
|
730
|
+
* The three required methods are asynchronous, because a remote key is.
|
|
731
|
+
* The optional `*Sync` trio is the fast path a local-key implementation
|
|
732
|
+
* provides so that code paths which are synchronous by contract (OPC UA
|
|
733
|
+
* chunk assembly) keep working unchanged with local keys; remote
|
|
734
|
+
* implementations simply omit them, and callers choose a path via
|
|
735
|
+
* {@link hasSyncKeyOperations}.
|
|
736
|
+
*/
|
|
737
|
+
interface IKeyOperations {
|
|
738
|
+
/** Sign `data` and return the signature (`modulusLength` bytes for RSA). */
|
|
739
|
+
sign(data: Uint8Array, params: AsymmetricSignParams): Promise<Buffer>;
|
|
740
|
+
/**
|
|
741
|
+
* Decrypt exactly ONE cipher block — `block.length` must equal
|
|
742
|
+
* {@link KeyMetadata.modulusLength} — and return the plaintext.
|
|
743
|
+
*
|
|
744
|
+
* One call is one HSM/KMS operation by design: callers own the
|
|
745
|
+
* multi-block loop (and may issue blocks concurrently), so a provider
|
|
746
|
+
* never has to reimplement it and round trips stay visible.
|
|
747
|
+
*/
|
|
748
|
+
decryptBlock(block: Uint8Array, params: AsymmetricDecryptParams): Promise<Buffer>;
|
|
749
|
+
/** The declared key facts. Stable for the lifetime of the object. */
|
|
750
|
+
getKeyMetadata(): Promise<KeyMetadata>;
|
|
751
|
+
/**
|
|
752
|
+
* The public half of the key, SPKI-encoded DER.
|
|
753
|
+
*
|
|
754
|
+
* Optional, but strongly recommended: certificate/key match checks and
|
|
755
|
+
* CSR generation over an opaque key both need it, and are unavailable
|
|
756
|
+
* (with a clear error) without it.
|
|
757
|
+
*/
|
|
758
|
+
getPublicKey?(): Promise<ArrayBuffer>;
|
|
759
|
+
/** Synchronous {@link sign}. Local keys only; remote providers omit it. */
|
|
760
|
+
signSync?(data: Uint8Array, params: AsymmetricSignParams): Buffer;
|
|
761
|
+
/** Synchronous {@link decryptBlock}. Local keys only. */
|
|
762
|
+
decryptBlockSync?(block: Uint8Array, params: AsymmetricDecryptParams): Buffer;
|
|
763
|
+
/** Synchronous {@link getKeyMetadata}. Local keys only. */
|
|
764
|
+
getKeyMetadataSync?(): KeyMetadata;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* True when `value` implements {@link IKeyOperations} — the three required
|
|
768
|
+
* methods are present — as opposed to being raw key material (a `PrivateKey`
|
|
769
|
+
* envelope, a `CryptoKey`, a PEM string), none of which carry methods.
|
|
770
|
+
*/
|
|
771
|
+
declare function isKeyOperations(value: unknown): value is IKeyOperations;
|
|
772
|
+
/**
|
|
773
|
+
* True when `ops` provides the complete synchronous fast path, so a caller
|
|
774
|
+
* on a synchronous code path can use it without ever awaiting. All three
|
|
775
|
+
* methods are required together — a partial sync surface would force
|
|
776
|
+
* callers to mix paths mid-operation.
|
|
777
|
+
*/
|
|
778
|
+
declare function hasSyncKeyOperations(ops: IKeyOperations): boolean;
|
|
779
|
+
/**
|
|
780
|
+
* Thrown by `getPrivateKey()`-style accessors when the key is opaque —
|
|
781
|
+
* held by an {@link IKeyOperations} implementation (HSM/KMS) and therefore
|
|
782
|
+
* deliberately not obtainable as material. Catching this specific error is
|
|
783
|
+
* how callers distinguish "the key exists but cannot be read" from "no key
|
|
784
|
+
* is configured".
|
|
785
|
+
*/
|
|
786
|
+
declare class PrivateKeyUnavailableError extends Error {
|
|
787
|
+
constructor(message?: string);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Expose an {@link IKeyOperations} as a {@link CaSigner}, so ONE HSM/KMS
|
|
792
|
+
* integration serves both worlds: the secure-channel/session operations
|
|
793
|
+
* (native shape) and X509 issuance — CSR, self-signed certificate, CRL —
|
|
794
|
+
* through the existing `CaSigner`-accepting primitives. The concrete use
|
|
795
|
+
* case is an OPC UA application whose instance key is opaque and that must
|
|
796
|
+
* still renew its certificate: a CSR over the existing key, signed through
|
|
797
|
+
* this adapter.
|
|
798
|
+
*
|
|
799
|
+
* RSASSA-PKCS1-v1_5 only — the signature scheme X509 issuance uses here —
|
|
800
|
+
* and SHA-256 only, {@link AsymmetricSignParams} not going higher today;
|
|
801
|
+
* the `hash` parameter exists so a future widening is additive.
|
|
802
|
+
*
|
|
803
|
+
* Requires {@link IKeyOperations.getPublicKey}: a `CaSigner` must produce
|
|
804
|
+
* its public half (a CSR embeds it, an issued certificate's AKI derives
|
|
805
|
+
* from it), and with an opaque key there is nowhere else it can come from.
|
|
806
|
+
*/
|
|
807
|
+
declare function caSignerFromKeyOperations(ops: IKeyOperations, hash?: "SHA-256"): CaSigner;
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Decrypt a multi-block ciphertext through an {@link IKeyOperations}.
|
|
811
|
+
*
|
|
812
|
+
* This is THE multi-block loop, shipped once so providers never reimplement
|
|
813
|
+
* it and only ever see one block per call — one call, one HSM/KMS operation.
|
|
814
|
+
* Blocks are decrypted concurrently (a remote provider's round trips
|
|
815
|
+
* overlap) and reassembled in order. `blockSize` is the cipher block size,
|
|
816
|
+
* i.e. {@link KeyMetadata.modulusLength}; the buffer must be a whole number
|
|
817
|
+
* of blocks — a partial trailing block is a framing error upstream and is
|
|
818
|
+
* rejected rather than papered over.
|
|
819
|
+
*
|
|
820
|
+
* A block that fails to decrypt rejects the whole call; the caller decides
|
|
821
|
+
* whether that surfaces or degrades (see {@link LocalKeyOperations} on
|
|
822
|
+
* anti-oracle behavior).
|
|
823
|
+
*/
|
|
824
|
+
declare function decryptLong(ops: IKeyOperations, buffer: Uint8Array, params: AsymmetricDecryptParams, blockSize: number): Promise<Buffer>;
|
|
825
|
+
/**
|
|
826
|
+
* Synchronous {@link decryptLong}, for callers that are synchronous by
|
|
827
|
+
* contract. Requires the sync fast path — check {@link hasSyncKeyOperations}
|
|
828
|
+
* first; an async-only provider is rejected with a clear error.
|
|
829
|
+
*/
|
|
830
|
+
declare function decryptLongSync(ops: IKeyOperations, buffer: Uint8Array, params: AsymmetricDecryptParams, blockSize: number): Buffer;
|
|
831
|
+
|
|
832
|
+
interface SubjectOptions {
|
|
833
|
+
commonName?: string;
|
|
834
|
+
organization?: string;
|
|
835
|
+
organizationalUnit?: string;
|
|
836
|
+
locality?: string;
|
|
837
|
+
state?: string;
|
|
838
|
+
country?: string;
|
|
839
|
+
domainComponent?: string;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* subjectName The subject name to use for the Certificate.
|
|
843
|
+
* If not specified the ApplicationName and/or domainNames are used to create a suitable default value.
|
|
844
|
+
*/
|
|
845
|
+
declare class Subject implements SubjectOptions {
|
|
846
|
+
readonly commonName?: string;
|
|
847
|
+
readonly organization?: string;
|
|
848
|
+
readonly organizationalUnit?: string;
|
|
849
|
+
readonly locality?: string;
|
|
850
|
+
readonly state?: string;
|
|
851
|
+
readonly country?: string;
|
|
852
|
+
readonly domainComponent?: string;
|
|
853
|
+
constructor(options: SubjectOptions | string);
|
|
854
|
+
static parse(str: string): SubjectOptions;
|
|
855
|
+
toStringInternal(sep: string): string;
|
|
856
|
+
toStringForOPCUA(): string;
|
|
857
|
+
toString(): string;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
declare function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean;
|
|
861
|
+
declare function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean;
|
|
862
|
+
declare function verifyCertificateRevocationListSignature(certificateRevocationList: Certificate, parentCertificate: Certificate): boolean;
|
|
863
|
+
type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
|
|
864
|
+
declare function verifyCertificateChain(certificateChain: Certificate[]): Promise<{
|
|
865
|
+
status: _VerifyStatus;
|
|
866
|
+
reason: string;
|
|
867
|
+
}>;
|
|
868
|
+
|
|
869
|
+
declare function getCrypto(): Crypto$1 | typeof __crypto;
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Authority Key Identifier extension identifying the issuer by its public
|
|
873
|
+
* key (`keyid`), matching what {@link createSelfSignedCertificate} already
|
|
874
|
+
* does for the self-signed case, and what openssl's
|
|
875
|
+
* `authorityKeyIdentifier = keyid:always` produces for the issued case.
|
|
876
|
+
*/
|
|
877
|
+
declare function buildAuthorityKeyIdentifierFromIssuer(issuerPublicKey: PublicKeyType, crypto?: Crypto): Promise<x509.AuthorityKeyIdentifierExtension>;
|
|
878
|
+
/** Opt-in CRL Distribution Point / Authority Info Access URLs for a certificate. */
|
|
879
|
+
interface RevocationExtensionsParams {
|
|
880
|
+
crlDistributionUrl?: string;
|
|
881
|
+
ocspResponderUrl?: string;
|
|
882
|
+
caIssuersUrl?: string;
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Builds the CDP (`crlDistributionUrl`) and AIA (`ocspResponderUrl` /
|
|
886
|
+
* `caIssuersUrl`) extensions for a certificate, mirroring the
|
|
887
|
+
* `$ENV::CDP_URL` / `$ENV::AIA_VALUE` opt-in extensions the openssl-backed
|
|
888
|
+
* CA templates emit. Each extension is included only when at least one of
|
|
889
|
+
* its values is set.
|
|
890
|
+
*/
|
|
891
|
+
declare function buildRevocationExtensions(params: RevocationExtensionsParams): x509.Extension[];
|
|
892
|
+
/** The CRL Number extension (RFC 5280 §5.2.3), a plain monotonically-increasing counter. */
|
|
893
|
+
declare function buildCrlNumberExtension(crlNumber: number | bigint): x509.Extension;
|
|
894
|
+
|
|
666
895
|
/**
|
|
667
896
|
* @param privateKeyInDerOrPem
|
|
668
897
|
* @param passphrase — required if the PEM is an encrypted PKCS#8 key
|
|
@@ -977,6 +1206,35 @@ declare function makeMessageChunkSignatureWithDerivedKeys(message: Buffer, deriv
|
|
|
977
1206
|
*/
|
|
978
1207
|
declare function verifyChunkSignatureWithDerivedKeys(chunk: Buffer, derivedKeys: DerivedKeys): boolean;
|
|
979
1208
|
|
|
1209
|
+
/**
|
|
1210
|
+
* Adapts an in-process private key — the {@link PrivateKey} envelope — to
|
|
1211
|
+
* {@link IKeyOperations}, sync fast path included, so callers only ever deal
|
|
1212
|
+
* with one key shape whether the key lives in memory or in an HSM.
|
|
1213
|
+
*
|
|
1214
|
+
* This class is intended to be the ONE place that dereferences
|
|
1215
|
+
* `privateKey.hidden`; everything above it should hold an
|
|
1216
|
+
* {@link IKeyOperations} and stay ignorant of key material.
|
|
1217
|
+
*
|
|
1218
|
+
* Failure behavior differs deliberately from `privateDecrypt_native`, which
|
|
1219
|
+
* swallows errors into a 1-byte buffer: {@link decryptBlock} throws, like any
|
|
1220
|
+
* remote provider would. A caller that needs the swallow-and-return-garbage
|
|
1221
|
+
* anti-oracle behavior implements it above this interface, uniformly for
|
|
1222
|
+
* local and remote keys.
|
|
1223
|
+
*/
|
|
1224
|
+
declare class LocalKeyOperations implements IKeyOperations {
|
|
1225
|
+
#private;
|
|
1226
|
+
constructor(privateKey: PrivateKey);
|
|
1227
|
+
getKeyMetadataSync(): KeyMetadata;
|
|
1228
|
+
getKeyMetadata(): Promise<KeyMetadata>;
|
|
1229
|
+
getPublicKey(): Promise<ArrayBuffer>;
|
|
1230
|
+
signSync(data: Uint8Array, params: AsymmetricSignParams): Buffer;
|
|
1231
|
+
sign(data: Uint8Array, params: AsymmetricSignParams): Promise<Buffer>;
|
|
1232
|
+
decryptBlockSync(block: Uint8Array, params: AsymmetricDecryptParams): Buffer;
|
|
1233
|
+
decryptBlock(block: Uint8Array, params: AsymmetricDecryptParams): Promise<Buffer>;
|
|
1234
|
+
}
|
|
1235
|
+
/** Wraps a {@link PrivateKey} envelope as {@link IKeyOperations}. */
|
|
1236
|
+
declare function keyOperationsFromPrivateKey(privateKey: PrivateKey): LocalKeyOperations;
|
|
1237
|
+
|
|
980
1238
|
declare function makePrivateKeyFromPem(privateKeyInPem: string): PrivateKey;
|
|
981
1239
|
|
|
982
1240
|
declare function makePrivateKeyThumbPrint(_privateKey: PrivateKey): Buffer;
|
|
@@ -992,4 +1250,4 @@ declare const asn1: {
|
|
|
992
1250
|
readSignatureValueBin: typeof readSignatureValueBin;
|
|
993
1251
|
};
|
|
994
1252
|
|
|
995
|
-
export { type AttributeTypeAndValue, type AuthorityInformationAccess, type AuthorityKeyIdentifier, type BasicConstraints, 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 DER, type DERContentType, type DerivedKeys, type DirectoryName, type DistinguishedNameAttribute, type ExtensionRequest, type Extensions, type KeyExportOptions, type KeyObject, LocalPrivateKeySigner, type Name, type Nonce, type PEM, PaddingAlgorithm, PfxIntegrityError, PfxMalformedError, Pkcs12UnsupportedAlgorithmError, type PrivateKey, type PrivateKeyInternals, type PrivateKeyPEM, PrivateKeyPassphraseRequiredError, 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, certificateMatchesPrivateKey, clearExploreCertificateCache, coerceCertificate, coerceCertificatePem, coercePEMorDerToPrivateKey, coercePrivateKeyPem, coercePublicKeyPem, coerceRsaPublicKeyPem, combine_der, computeDerivedKeys, computePaddingFooter, convertPEMtoDER, createCertificateFromCsr, createCertificateSigningRequest, createCrl, createPrivateKeyFromNodeJSCrypto, createSelfSignedCertificate, decryptBufferWithDerivedKeys, derToPrivateKey, encryptBufferWithDerivedKeys, exploreAsn1, exploreCertificate, exploreCertificateInfo, exploreCertificateRevocationList, exploreCertificateSigningRequest, explorePrivateKey, extractPublicKeyFromCertificate, extractPublicKeyFromCertificateSync, generateKeyPair, generatePrivateKey, getCrypto, hexDump, identifyDERContent, identifyPemType, isCaSigner, isCrlIssuedByCertificate, isKeyObject, 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 };
|
|
1253
|
+
export { type AsymmetricDecryptParams, type AsymmetricSignParams, type AttributeTypeAndValue, type AuthorityInformationAccess, type AuthorityKeyIdentifier, type BasicConstraints, 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 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 };
|
package/dist/index_web.js
CHANGED
|
@@ -47656,6 +47656,21 @@ function exploreCertificateRevocationList(crl) {
|
|
|
47656
47656
|
// ../node-opcua-crypto/source/verify_certificate_signature.ts
|
|
47657
47657
|
init_inject_buffer();
|
|
47658
47658
|
init_node_crypto_shim();
|
|
47659
|
+
var ECDSA_SIGNATURE_DIGESTS = {
|
|
47660
|
+
"1.2.840.10045.4.1": "sha1",
|
|
47661
|
+
"1.2.840.10045.4.3.1": "sha224",
|
|
47662
|
+
"1.2.840.10045.4.3.2": "sha256",
|
|
47663
|
+
"1.2.840.10045.4.3.3": "sha384",
|
|
47664
|
+
"1.2.840.10045.4.3.4": "sha512"
|
|
47665
|
+
};
|
|
47666
|
+
function digestForSignatureAlgorithm(identifier) {
|
|
47667
|
+
const ecdsaDigest = ECDSA_SIGNATURE_DIGESTS[identifier];
|
|
47668
|
+
if (ecdsaDigest) {
|
|
47669
|
+
return ecdsaDigest;
|
|
47670
|
+
}
|
|
47671
|
+
const named = /sha-?(1|224|256|384|512)/i.exec(identifier);
|
|
47672
|
+
return named ? `sha${named[1]}` : identifier;
|
|
47673
|
+
}
|
|
47659
47674
|
function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
47660
47675
|
const block_info = readTag(certificateOrCrl, 0);
|
|
47661
47676
|
const blocks = readStruct(certificateOrCrl, block_info);
|
|
@@ -47664,7 +47679,7 @@ function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
|
47664
47679
|
const signatureValue = readSignatureValueBin(certificateOrCrl, blocks[2]);
|
|
47665
47680
|
const p = split_der(parentCertificate)[0];
|
|
47666
47681
|
const certPem = toPem(p, "CERTIFICATE");
|
|
47667
|
-
const verify = createVerify(signatureAlgorithm.identifier);
|
|
47682
|
+
const verify = createVerify(digestForSignatureAlgorithm(signatureAlgorithm.identifier));
|
|
47668
47683
|
verify.update(bufferToBeSigned);
|
|
47669
47684
|
verify.end();
|
|
47670
47685
|
return verify.verify(certPem, signatureValue);
|
|
@@ -47839,11 +47854,45 @@ function exploreCertificateSigningRequest(crl) {
|
|
|
47839
47854
|
|
|
47840
47855
|
// ../node-opcua-crypto/source/explore_private_key.ts
|
|
47841
47856
|
init_inject_buffer();
|
|
47857
|
+
function toNodeKeyObject(privateKey2) {
|
|
47858
|
+
const hidden = privateKey2.hidden;
|
|
47859
|
+
return typeof hidden === "string" ? createPrivateKeyFromNodeJSCrypto(hidden) : hidden;
|
|
47860
|
+
}
|
|
47861
|
+
function exploreEcPrivateKey(privateKey2) {
|
|
47862
|
+
const keyObject = toNodeKeyObject(privateKey2);
|
|
47863
|
+
if (keyObject.asymmetricKeyType !== "ec") {
|
|
47864
|
+
throw new Error(`exploreEcPrivateKey: expecting an EC private key but got a "${keyObject.asymmetricKeyType}" key`);
|
|
47865
|
+
}
|
|
47866
|
+
const privateKey = keyObject.export({ format: "der", type: "sec1" });
|
|
47867
|
+
const block_info = readTag(privateKey, 0);
|
|
47868
|
+
const blocks = readStruct(privateKey, block_info);
|
|
47869
|
+
const version = getBlock(privateKey, blocks[0]);
|
|
47870
|
+
const d = getBlock(privateKey, blocks[1]);
|
|
47871
|
+
let namedCurve = "";
|
|
47872
|
+
let publicKey;
|
|
47873
|
+
for (let i = 2; i < blocks.length; i++) {
|
|
47874
|
+
const b = blocks[i];
|
|
47875
|
+
if (b.tag === 160 /* CONTEXT_SPECIFIC0 */) {
|
|
47876
|
+
const oidBlock = readTag(privateKey, b.position);
|
|
47877
|
+
namedCurve = readObjectIdentifier(privateKey, oidBlock).name;
|
|
47878
|
+
} else if (b.tag === 161 /* CONTEXT_SPECIFIC1 */) {
|
|
47879
|
+
const bitStringBlock = readTag(privateKey, b.position);
|
|
47880
|
+
publicKey = readBitString(privateKey, bitStringBlock).data;
|
|
47881
|
+
}
|
|
47882
|
+
}
|
|
47883
|
+
return { version, namedCurve, privateKey: d, publicKey };
|
|
47884
|
+
}
|
|
47842
47885
|
function f(buffer, b) {
|
|
47843
47886
|
return buffer.subarray(b.position + 1, b.position + b.length);
|
|
47844
47887
|
}
|
|
47845
47888
|
var doDebug2 = !!import_process.default.env.DEBUG;
|
|
47846
47889
|
function explorePrivateKey(privateKey2) {
|
|
47890
|
+
const keyType = toNodeKeyObject(privateKey2).asymmetricKeyType;
|
|
47891
|
+
if (keyType && keyType !== "rsa") {
|
|
47892
|
+
throw new Error(
|
|
47893
|
+
`explorePrivateKey: only RSA private keys are supported (got a "${keyType}" key). ` + (keyType === "ec" ? "Use exploreEcPrivateKey() instead." : "")
|
|
47894
|
+
);
|
|
47895
|
+
}
|
|
47847
47896
|
const privateKey1 = privateKey2.hidden;
|
|
47848
47897
|
const privateKey = typeof privateKey1 === "string" ? convertPEMtoDER(privateKey1) : privateKey1.export({ format: "der", type: "pkcs1" });
|
|
47849
47898
|
const block_info = readTag(privateKey, 0);
|
|
@@ -47987,6 +48036,75 @@ function identifyDERContent(buffer) {
|
|
|
47987
48036
|
}
|
|
47988
48037
|
}
|
|
47989
48038
|
|
|
48039
|
+
// ../node-opcua-crypto/source/key_operations/ca_signer_adapter.ts
|
|
48040
|
+
init_inject_buffer();
|
|
48041
|
+
function caSignerFromKeyOperations(ops, hash = "SHA-256") {
|
|
48042
|
+
const getPublicKey = ops.getPublicKey;
|
|
48043
|
+
if (typeof getPublicKey !== "function") {
|
|
48044
|
+
throw new Error(
|
|
48045
|
+
"caSignerFromKeyOperations requires a key-operations provider that implements getPublicKey(): a CaSigner must be able to produce its public key (SPKI DER), and an opaque key has no other source for it"
|
|
48046
|
+
);
|
|
48047
|
+
}
|
|
48048
|
+
return {
|
|
48049
|
+
algorithm: { name: "RSASSA-PKCS1-v1_5", hash: { name: hash } },
|
|
48050
|
+
getPublicKey: () => getPublicKey.call(ops),
|
|
48051
|
+
async sign(tbs) {
|
|
48052
|
+
const signature = await ops.sign(tbs, { padding: "RSA-PKCS1-v1_5", hash });
|
|
48053
|
+
const copy2 = new Uint8Array(signature.byteLength);
|
|
48054
|
+
copy2.set(signature);
|
|
48055
|
+
return copy2.buffer;
|
|
48056
|
+
}
|
|
48057
|
+
};
|
|
48058
|
+
}
|
|
48059
|
+
|
|
48060
|
+
// ../node-opcua-crypto/source/key_operations/decrypt_long.ts
|
|
48061
|
+
init_inject_buffer();
|
|
48062
|
+
function splitBlocks(buffer, blockSize) {
|
|
48063
|
+
if (!Number.isInteger(blockSize) || blockSize <= 0) {
|
|
48064
|
+
throw new Error(`invalid cipher block size ${blockSize}`);
|
|
48065
|
+
}
|
|
48066
|
+
if (buffer.length === 0 || buffer.length % blockSize !== 0) {
|
|
48067
|
+
throw new Error(`encrypted buffer length ${buffer.length} is not a whole number of ${blockSize}-byte cipher blocks`);
|
|
48068
|
+
}
|
|
48069
|
+
const blocks = [];
|
|
48070
|
+
for (let offset = 0; offset < buffer.length; offset += blockSize) {
|
|
48071
|
+
blocks.push(buffer.subarray(offset, offset + blockSize));
|
|
48072
|
+
}
|
|
48073
|
+
return blocks;
|
|
48074
|
+
}
|
|
48075
|
+
async function decryptLong(ops, buffer, params, blockSize) {
|
|
48076
|
+
const blocks = splitBlocks(buffer, blockSize);
|
|
48077
|
+
const decrypted = await Promise.all(blocks.map((block) => ops.decryptBlock(block, params)));
|
|
48078
|
+
return import_buffer.Buffer.concat(decrypted);
|
|
48079
|
+
}
|
|
48080
|
+
function decryptLongSync(ops, buffer, params, blockSize) {
|
|
48081
|
+
const decryptBlockSync = ops.decryptBlockSync;
|
|
48082
|
+
if (typeof decryptBlockSync !== "function") {
|
|
48083
|
+
throw new Error("decryptLongSync requires a key-operations provider with a synchronous fast path (decryptBlockSync)");
|
|
48084
|
+
}
|
|
48085
|
+
const blocks = splitBlocks(buffer, blockSize);
|
|
48086
|
+
return import_buffer.Buffer.concat(blocks.map((block) => decryptBlockSync.call(ops, block, params)));
|
|
48087
|
+
}
|
|
48088
|
+
|
|
48089
|
+
// ../node-opcua-crypto/source/key_operations/key_operations.ts
|
|
48090
|
+
init_inject_buffer();
|
|
48091
|
+
function isKeyOperations(value) {
|
|
48092
|
+
if (value === null || typeof value !== "object") {
|
|
48093
|
+
return false;
|
|
48094
|
+
}
|
|
48095
|
+
const candidate = value;
|
|
48096
|
+
return typeof candidate.sign === "function" && typeof candidate.decryptBlock === "function" && typeof candidate.getKeyMetadata === "function";
|
|
48097
|
+
}
|
|
48098
|
+
function hasSyncKeyOperations(ops) {
|
|
48099
|
+
return typeof ops.signSync === "function" && typeof ops.decryptBlockSync === "function" && typeof ops.getKeyMetadataSync === "function";
|
|
48100
|
+
}
|
|
48101
|
+
var PrivateKeyUnavailableError = class extends Error {
|
|
48102
|
+
constructor(message = "the private key is opaque: it is held by a key-operations provider and cannot be read") {
|
|
48103
|
+
super(message);
|
|
48104
|
+
this.name = "PrivateKeyUnavailableError";
|
|
48105
|
+
}
|
|
48106
|
+
};
|
|
48107
|
+
|
|
47990
48108
|
// ../node-opcua-crypto/source/subject.ts
|
|
47991
48109
|
init_inject_buffer();
|
|
47992
48110
|
var _keys = {
|
|
@@ -61752,6 +61870,93 @@ async function buildPublicKey(privateKey) {
|
|
|
61752
61870
|
}
|
|
61753
61871
|
|
|
61754
61872
|
// ../node-opcua-crypto/source/x509/ca_signer.ts
|
|
61873
|
+
var ECDSA_COORDINATE_BYTES = {
|
|
61874
|
+
"P-256": 32,
|
|
61875
|
+
"P-384": 48,
|
|
61876
|
+
// 521 bits is not a byte multiple, so each coordinate occupies 66 bytes
|
|
61877
|
+
"P-521": 66
|
|
61878
|
+
};
|
|
61879
|
+
function asBytes(source) {
|
|
61880
|
+
if (source instanceof Uint8Array) {
|
|
61881
|
+
return source;
|
|
61882
|
+
}
|
|
61883
|
+
if (ArrayBuffer.isView(source)) {
|
|
61884
|
+
return new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
61885
|
+
}
|
|
61886
|
+
return new Uint8Array(source);
|
|
61887
|
+
}
|
|
61888
|
+
function readDerLength(bytes, cursor) {
|
|
61889
|
+
const first = bytes[cursor.offset++];
|
|
61890
|
+
if (first === void 0) {
|
|
61891
|
+
throw new Error("malformed ECDSA signature: truncated length");
|
|
61892
|
+
}
|
|
61893
|
+
if (first < 128) {
|
|
61894
|
+
return first;
|
|
61895
|
+
}
|
|
61896
|
+
const byteCount = first & 127;
|
|
61897
|
+
if (byteCount === 0 || byteCount > 4) {
|
|
61898
|
+
throw new Error(`malformed ECDSA signature: unsupported length encoding (0x${first.toString(16)})`);
|
|
61899
|
+
}
|
|
61900
|
+
let length = 0;
|
|
61901
|
+
for (let index = 0; index < byteCount; index++) {
|
|
61902
|
+
const byte = bytes[cursor.offset++];
|
|
61903
|
+
if (byte === void 0) {
|
|
61904
|
+
throw new Error("malformed ECDSA signature: truncated length");
|
|
61905
|
+
}
|
|
61906
|
+
length = length * 256 + byte;
|
|
61907
|
+
}
|
|
61908
|
+
return length;
|
|
61909
|
+
}
|
|
61910
|
+
function readDerInteger(bytes, cursor) {
|
|
61911
|
+
if (bytes[cursor.offset++] !== 2) {
|
|
61912
|
+
throw new Error("malformed ECDSA signature: expected an INTEGER");
|
|
61913
|
+
}
|
|
61914
|
+
const length = readDerLength(bytes, cursor);
|
|
61915
|
+
const end = cursor.offset + length;
|
|
61916
|
+
if (length === 0 || end > bytes.length) {
|
|
61917
|
+
throw new Error("malformed ECDSA signature: INTEGER runs past the end");
|
|
61918
|
+
}
|
|
61919
|
+
const value = bytes.subarray(cursor.offset, end);
|
|
61920
|
+
cursor.offset = end;
|
|
61921
|
+
return value;
|
|
61922
|
+
}
|
|
61923
|
+
function toFixedWidth(value, size, label) {
|
|
61924
|
+
let start = 0;
|
|
61925
|
+
while (start < value.length - 1 && value[start] === 0) {
|
|
61926
|
+
start++;
|
|
61927
|
+
}
|
|
61928
|
+
const magnitude = value.subarray(start);
|
|
61929
|
+
if (magnitude.length > size) {
|
|
61930
|
+
throw new Error(`malformed ECDSA signature: ${label} is ${magnitude.length} bytes, too long for a ${size * 8}-bit curve`);
|
|
61931
|
+
}
|
|
61932
|
+
const padded = new Uint8Array(size);
|
|
61933
|
+
padded.set(magnitude, size - magnitude.length);
|
|
61934
|
+
return padded;
|
|
61935
|
+
}
|
|
61936
|
+
function ecdsaSignatureDerToP1363(derSignature, namedCurve) {
|
|
61937
|
+
const size = ECDSA_COORDINATE_BYTES[namedCurve];
|
|
61938
|
+
if (size === void 0) {
|
|
61939
|
+
throw new Error(`unsupported curve ${namedCurve}`);
|
|
61940
|
+
}
|
|
61941
|
+
const bytes = asBytes(derSignature);
|
|
61942
|
+
const cursor = { offset: 0 };
|
|
61943
|
+
if (bytes[cursor.offset++] !== 48) {
|
|
61944
|
+
throw new Error("malformed ECDSA signature: expected a SEQUENCE (is it already in r||s form?)");
|
|
61945
|
+
}
|
|
61946
|
+
const sequenceLength = readDerLength(bytes, cursor);
|
|
61947
|
+
if (cursor.offset + sequenceLength !== bytes.length) {
|
|
61948
|
+
throw new Error("malformed ECDSA signature: SEQUENCE length does not match the data");
|
|
61949
|
+
}
|
|
61950
|
+
const r = toFixedWidth(readDerInteger(bytes, cursor), size, "r");
|
|
61951
|
+
const s = toFixedWidth(readDerInteger(bytes, cursor), size, "s");
|
|
61952
|
+
if (cursor.offset !== bytes.length) {
|
|
61953
|
+
throw new Error("malformed ECDSA signature: trailing data after s");
|
|
61954
|
+
}
|
|
61955
|
+
const p1363 = new Uint8Array(size * 2);
|
|
61956
|
+
p1363.set(r, 0);
|
|
61957
|
+
p1363.set(s, size);
|
|
61958
|
+
return p1363.buffer;
|
|
61959
|
+
}
|
|
61755
61960
|
var LocalPrivateKeySigner = class {
|
|
61756
61961
|
algorithm;
|
|
61757
61962
|
#privateKey;
|
|
@@ -61958,6 +62163,18 @@ function getAttributes(purpose) {
|
|
|
61958
62163
|
}
|
|
61959
62164
|
|
|
61960
62165
|
// ../node-opcua-crypto/source/x509/create_certificate_from_csr.ts
|
|
62166
|
+
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;
|
|
62167
|
+
function getIssuedAttributes(purpose) {
|
|
62168
|
+
if (purpose === 1 /* ForCertificateAuthority */) {
|
|
62169
|
+
return getAttributes(purpose);
|
|
62170
|
+
}
|
|
62171
|
+
return {
|
|
62172
|
+
nsComment: "Certificate generated by Node-OPCUA Certificate utility V2",
|
|
62173
|
+
basicConstraints: new x509_es_exports.BasicConstraintsExtension(false, void 0, true),
|
|
62174
|
+
keyUsageExtension: [x509_es_exports.ExtendedKeyUsage.serverAuth, x509_es_exports.ExtendedKeyUsage.clientAuth],
|
|
62175
|
+
usages: keyUsageIssuedApplication
|
|
62176
|
+
};
|
|
62177
|
+
}
|
|
61961
62178
|
async function createCertificateFromCsr(options) {
|
|
61962
62179
|
const crypto4 = getCrypto();
|
|
61963
62180
|
const csr = new x509_es_exports.Pkcs10CertificateRequest(options.csr);
|
|
@@ -61965,7 +62182,7 @@ async function createCertificateFromCsr(options) {
|
|
|
61965
62182
|
if (!csrIsValid) {
|
|
61966
62183
|
throw new Error("createCertificateFromCsr: the CSR signature does not verify \u2014 refusing to sign an unproven key");
|
|
61967
62184
|
}
|
|
61968
|
-
const { basicConstraints, keyUsageExtension, usages } =
|
|
62185
|
+
const { basicConstraints, keyUsageExtension, usages } = getIssuedAttributes(options.purpose);
|
|
61969
62186
|
const alternativeNameExtensions = [];
|
|
61970
62187
|
for (const d of options.dns ?? []) {
|
|
61971
62188
|
alternativeNameExtensions.push({ type: "dns", value: d });
|
|
@@ -62344,6 +62561,81 @@ function verifyChunkSignatureWithDerivedKeys(chunk, derivedKeys) {
|
|
|
62344
62561
|
return computedSignature.toString("hex") === expectedSignature.toString("hex");
|
|
62345
62562
|
}
|
|
62346
62563
|
|
|
62564
|
+
// ../node-opcua-crypto/source/key_operations/local_key_operations.ts
|
|
62565
|
+
init_inject_buffer();
|
|
62566
|
+
init_node_crypto_shim();
|
|
62567
|
+
function toNodeHash(hash) {
|
|
62568
|
+
return hash === "SHA-1" ? "RSA-SHA1" : "RSA-SHA256";
|
|
62569
|
+
}
|
|
62570
|
+
var LocalKeyOperations = class {
|
|
62571
|
+
#key;
|
|
62572
|
+
#metadata;
|
|
62573
|
+
constructor(privateKey) {
|
|
62574
|
+
const hidden = privateKey.hidden;
|
|
62575
|
+
this.#key = typeof hidden === "string" ? createPrivateKey(hidden) : createPrivateKey({ key: hidden.export({ type: "pkcs8", format: "der" }), format: "der", type: "pkcs8" });
|
|
62576
|
+
if (this.#key.asymmetricKeyType !== "rsa") {
|
|
62577
|
+
throw new Error(`LocalKeyOperations supports RSA keys only for now, got a "${this.#key.asymmetricKeyType}" key`);
|
|
62578
|
+
}
|
|
62579
|
+
const modulusLength = this.#key.asymmetricKeyDetails?.modulusLength;
|
|
62580
|
+
if (!modulusLength) {
|
|
62581
|
+
throw new Error("cannot determine the modulus length of the private key");
|
|
62582
|
+
}
|
|
62583
|
+
this.#metadata = { keyType: "RSA", modulusLength: modulusLength / 8 };
|
|
62584
|
+
}
|
|
62585
|
+
getKeyMetadataSync() {
|
|
62586
|
+
return this.#metadata;
|
|
62587
|
+
}
|
|
62588
|
+
async getKeyMetadata() {
|
|
62589
|
+
return this.#metadata;
|
|
62590
|
+
}
|
|
62591
|
+
async getPublicKey() {
|
|
62592
|
+
const spki = createPublicKey(this.#key).export({ type: "spki", format: "der" });
|
|
62593
|
+
return spki.buffer.slice(spki.byteOffset, spki.byteOffset + spki.byteLength);
|
|
62594
|
+
}
|
|
62595
|
+
signSync(data, params) {
|
|
62596
|
+
const signer = createSign(toNodeHash(params.hash));
|
|
62597
|
+
signer.update(data);
|
|
62598
|
+
if (params.padding === "RSA-PSS") {
|
|
62599
|
+
return signer.sign({
|
|
62600
|
+
key: this.#key,
|
|
62601
|
+
padding: constants_default.RSA_PKCS1_PSS_PADDING,
|
|
62602
|
+
saltLength: constants_default.RSA_PSS_SALTLEN_DIGEST
|
|
62603
|
+
});
|
|
62604
|
+
}
|
|
62605
|
+
return signer.sign(this.#key);
|
|
62606
|
+
}
|
|
62607
|
+
async sign(data, params) {
|
|
62608
|
+
return this.signSync(data, params);
|
|
62609
|
+
}
|
|
62610
|
+
decryptBlockSync(block, params) {
|
|
62611
|
+
if (block.length !== this.#metadata.modulusLength) {
|
|
62612
|
+
throw new Error(
|
|
62613
|
+
`decryptBlock expects exactly one cipher block of ${this.#metadata.modulusLength} bytes, got ${block.length}`
|
|
62614
|
+
);
|
|
62615
|
+
}
|
|
62616
|
+
if (params.padding === "RSA-OAEP") {
|
|
62617
|
+
if (!params.oaepHash) {
|
|
62618
|
+
throw new Error("RSA-OAEP decryption requires an oaepHash");
|
|
62619
|
+
}
|
|
62620
|
+
return privateDecrypt(
|
|
62621
|
+
{
|
|
62622
|
+
key: this.#key,
|
|
62623
|
+
padding: constants_default.RSA_PKCS1_OAEP_PADDING,
|
|
62624
|
+
oaepHash: params.oaepHash === "SHA-256" ? "sha256" : "sha1"
|
|
62625
|
+
},
|
|
62626
|
+
block
|
|
62627
|
+
);
|
|
62628
|
+
}
|
|
62629
|
+
return privateDecrypt({ key: this.#key, padding: constants_default.RSA_PKCS1_PADDING }, block);
|
|
62630
|
+
}
|
|
62631
|
+
async decryptBlock(block, params) {
|
|
62632
|
+
return this.decryptBlockSync(block, params);
|
|
62633
|
+
}
|
|
62634
|
+
};
|
|
62635
|
+
function keyOperationsFromPrivateKey(privateKey) {
|
|
62636
|
+
return new LocalKeyOperations(privateKey);
|
|
62637
|
+
}
|
|
62638
|
+
|
|
62347
62639
|
// ../node-opcua-crypto/source/make_private_key_from_pem.ts
|
|
62348
62640
|
init_inject_buffer();
|
|
62349
62641
|
function makePrivateKeyFromPem(privateKeyInPem) {
|
|
@@ -62386,12 +62678,14 @@ function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
|
62386
62678
|
var asn1 = { readDirectoryName, readTag, readStruct, readAlgorithmIdentifier, readSignatureValueBin };
|
|
62387
62679
|
export {
|
|
62388
62680
|
CertificatePurpose,
|
|
62681
|
+
LocalKeyOperations,
|
|
62389
62682
|
LocalPrivateKeySigner,
|
|
62390
62683
|
PaddingAlgorithm,
|
|
62391
62684
|
PfxIntegrityError,
|
|
62392
62685
|
PfxMalformedError,
|
|
62393
62686
|
Pkcs12UnsupportedAlgorithmError,
|
|
62394
62687
|
PrivateKeyPassphraseRequiredError,
|
|
62688
|
+
PrivateKeyUnavailableError,
|
|
62395
62689
|
RSA_PKCS1_OAEP_PADDING,
|
|
62396
62690
|
RSA_PKCS1_PADDING,
|
|
62397
62691
|
Subject,
|
|
@@ -62400,6 +62694,7 @@ export {
|
|
|
62400
62694
|
buildAuthorityKeyIdentifierFromIssuer,
|
|
62401
62695
|
buildCrlNumberExtension,
|
|
62402
62696
|
buildRevocationExtensions,
|
|
62697
|
+
caSignerFromKeyOperations,
|
|
62403
62698
|
certificateMatchesPrivateKey,
|
|
62404
62699
|
clearExploreCertificateCache,
|
|
62405
62700
|
coerceCertificate,
|
|
@@ -62418,25 +62713,32 @@ export {
|
|
|
62418
62713
|
createPrivateKeyFromNodeJSCrypto,
|
|
62419
62714
|
createSelfSignedCertificate,
|
|
62420
62715
|
decryptBufferWithDerivedKeys,
|
|
62716
|
+
decryptLong,
|
|
62717
|
+
decryptLongSync,
|
|
62421
62718
|
derToPrivateKey,
|
|
62719
|
+
ecdsaSignatureDerToP1363,
|
|
62422
62720
|
encryptBufferWithDerivedKeys,
|
|
62423
62721
|
exploreAsn1,
|
|
62424
62722
|
exploreCertificate,
|
|
62425
62723
|
exploreCertificateInfo,
|
|
62426
62724
|
exploreCertificateRevocationList,
|
|
62427
62725
|
exploreCertificateSigningRequest,
|
|
62726
|
+
exploreEcPrivateKey,
|
|
62428
62727
|
explorePrivateKey,
|
|
62429
62728
|
extractPublicKeyFromCertificate,
|
|
62430
62729
|
extractPublicKeyFromCertificateSync,
|
|
62431
62730
|
generateKeyPair,
|
|
62432
62731
|
generatePrivateKey,
|
|
62433
62732
|
getCrypto,
|
|
62733
|
+
hasSyncKeyOperations,
|
|
62434
62734
|
hexDump,
|
|
62435
62735
|
identifyDERContent,
|
|
62436
62736
|
identifyPemType,
|
|
62437
62737
|
isCaSigner,
|
|
62438
62738
|
isCrlIssuedByCertificate,
|
|
62439
62739
|
isKeyObject,
|
|
62740
|
+
isKeyOperations,
|
|
62741
|
+
keyOperationsFromPrivateKey,
|
|
62440
62742
|
makeMessageChunkSignature,
|
|
62441
62743
|
makeMessageChunkSignatureWithDerivedKeys,
|
|
62442
62744
|
makePrivateKeyFromPem,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-crypto-web",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.10.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": "^5.
|
|
47
|
+
"node-opcua-crypto": "^5.10.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": "5ef0e4cd1d4b707dd182305ddfa964959954ecdf"
|
|
71
71
|
}
|