node-opcua-crypto 1.7.1 → 1.7.5

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.
Files changed (49) hide show
  1. package/.fossa.yml +18 -18
  2. package/.github/workflows/main.yml +32 -0
  3. package/.prettierrc.js +6 -6
  4. package/dist/source/asn1.d.ts +6 -2
  5. package/dist/source/asn1.js +13 -1
  6. package/dist/source/asn1.js.map +1 -1
  7. package/dist/source/buffer_utils.d.ts +1 -2
  8. package/dist/source/crypto_explore_certificate.js +94 -63
  9. package/dist/source/crypto_explore_certificate.js.map +1 -1
  10. package/dist/source/crypto_utils.js +10 -10
  11. package/dist/source/crypto_utils.js.map +1 -1
  12. package/dist/source/derived_keys.js +9 -6
  13. package/dist/source/derived_keys.js.map +1 -1
  14. package/dist/source/explore_certificate.d.ts +1 -1
  15. package/dist/source/explore_certificate.js +2 -2
  16. package/dist/source/explore_certificate.js.map +1 -1
  17. package/dist/source/explore_certificate_revocation_list.js +16 -16
  18. package/dist/source/explore_certificate_revocation_list.js.map +1 -1
  19. package/dist/source/explore_certificate_signing_request.js +11 -11
  20. package/dist/source/explore_certificate_signing_request.js.map +1 -1
  21. package/dist/source/explore_private_key.js +4 -4
  22. package/dist/source/explore_private_key.js.map +1 -1
  23. package/dist/source/oid_map.js +42 -0
  24. package/dist/source/oid_map.js.map +1 -1
  25. package/dist/source/public_private_match.js +2 -2
  26. package/dist/source/public_private_match.js.map +1 -1
  27. package/dist/source/verify_certificate_signature.js +8 -8
  28. package/dist/source/verify_certificate_signature.js.map +1 -1
  29. package/dist/source_nodejs/read.js +2 -2
  30. package/dist/source_nodejs/read.js.map +1 -1
  31. package/dist/source_nodejs/read_certificate_revocation_list.js +2 -2
  32. package/dist/source_nodejs/read_certificate_revocation_list.js.map +1 -1
  33. package/dist/source_nodejs/read_certificate_signing_request.js +2 -2
  34. package/dist/source_nodejs/read_certificate_signing_request.js.map +1 -1
  35. package/index.d.ts +2 -2
  36. package/package.json +16 -19
  37. package/source/asn1.ts +404 -393
  38. package/source/buffer_utils.ts +18 -18
  39. package/source/common.ts +13 -13
  40. package/source/crypto_explore_certificate.ts +38 -4
  41. package/source/crypto_utils.ts +3 -3
  42. package/source/derived_keys.ts +287 -284
  43. package/source/explore_certificate.ts +1 -1
  44. package/source/explore_certificate_revocation_list.ts +93 -93
  45. package/source/oid_map.ts +310 -265
  46. package/source/verify_certificate_signature.ts +105 -105
  47. package/source_nodejs/read.ts +95 -95
  48. package/source_nodejs/read_certificate_revocation_list.ts +14 -14
  49. package/test_certificate.ts +34 -34
@@ -1,18 +1,18 @@
1
- //
2
- // note: new Buffer(size)# is deprecated since: v6.0. and is replaced with Buffer.allocUnsafe
3
- // to ensure backward compatibility we have to replace
4
- // new Buffer(size) with createFastUninitializedBuffer(size)
5
- //
6
- // Buffer.alloc and Buffer.allocUnsafe have been introduced in nodejs 5.1.0
7
- // in node 0.11 new Buffer
8
- //
9
- /**
10
- * @internal
11
- * @private
12
- */
13
- export const createFastUninitializedBuffer = Buffer.allocUnsafe
14
- ? Buffer.allocUnsafe
15
- : (size: number): Buffer => {
16
- // istanbul ignore next
17
- return new Buffer(size);
18
- };
1
+ //
2
+ // note: new Buffer(size)# is deprecated since: v6.0. and is replaced with Buffer.allocUnsafe
3
+ // to ensure backward compatibility we have to replace
4
+ // new Buffer(size) with createFastUninitializedBuffer(size)
5
+ //
6
+ // Buffer.alloc and Buffer.allocUnsafe have been introduced in nodejs 5.1.0
7
+ // in node 0.11 new Buffer
8
+ //
9
+ /**
10
+ * @internal
11
+ * @private
12
+ */
13
+ export const createFastUninitializedBuffer = Buffer.allocUnsafe
14
+ ? Buffer.allocUnsafe
15
+ : (size: number): Buffer => {
16
+ // istanbul ignore next
17
+ return new Buffer(size);
18
+ };
package/source/common.ts CHANGED
@@ -1,13 +1,13 @@
1
- export type Nonce = Buffer;
2
-
3
- export type PEM = string;
4
- export type DER = Buffer;
5
- export type Certificate = DER;
6
- export type CertificatePEM = PEM; // certificate as a PEM string
7
- export type PrivateKey = DER;
8
- export type PrivateKeyPEM = PEM;
9
- export type PublicKey = DER;
10
- export type PublicKeyPEM = PEM;
11
-
12
- export type Signature = Buffer;
13
- export type CertificateRevocationList = Buffer;
1
+ export type Nonce = Buffer;
2
+
3
+ export type PEM = string;
4
+ export type DER = Buffer;
5
+ export type Certificate = DER;
6
+ export type CertificatePEM = PEM; // certificate as a PEM string
7
+ export type PrivateKey = DER;
8
+ export type PrivateKeyPEM = PEM;
9
+ export type PublicKey = DER;
10
+ export type PublicKeyPEM = PEM;
11
+
12
+ export type Signature = Buffer;
13
+ export type CertificateRevocationList = Buffer;
@@ -67,6 +67,7 @@ import {
67
67
  _readListOfInteger,
68
68
  _readObjectIdentifier,
69
69
  _readAlgorithmIdentifier,
70
+ _readECCAlgorithmIdentifier,
70
71
  _readBooleanValue,
71
72
  _readIntegerValue,
72
73
  _readLongIntegerValue,
@@ -506,7 +507,6 @@ export function _readExtension(buffer: Buffer, block: BlockInfo): { identifier:
506
507
  // Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
507
508
  function _readExtensions(buffer: Buffer, block: BlockInfo): CertificateExtension {
508
509
  assert(block.tag === 0xa3);
509
-
510
510
  let inner_blocks = _readStruct(buffer, block);
511
511
  inner_blocks = _readStruct(buffer, inner_blocks[0]);
512
512
 
@@ -565,6 +565,26 @@ function _readSubjectPublicKeyInfo(buffer: Buffer, block: BlockInfo): SubjectPub
565
565
  };
566
566
  }
567
567
 
568
+ function _readSubjectECCPublicKeyInfo(buffer: Buffer, block: BlockInfo): SubjectPublicKeyInfo {
569
+ const inner_blocks = _readStruct(buffer, block);
570
+
571
+ // first parameter is the second element of the first block, which is why we have another algorithm
572
+ const algorithm = _readECCAlgorithmIdentifier(buffer, inner_blocks[0]);
573
+
574
+ // the public key is already in bit format, we just need to read it
575
+ const subjectPublicKey = _readBitString(buffer, inner_blocks[1]);
576
+
577
+ // take out the data which is the entirity of our public key
578
+ const data = subjectPublicKey.data;
579
+ return {
580
+ algorithm: algorithm.identifier,
581
+ keyLength: (data.length - 1) as PublicKeyLength,
582
+ subjectPublicKey: {
583
+ modulus: data
584
+ }
585
+ };
586
+ }
587
+
568
588
  export interface SubjectPublicKeyInfo {
569
589
  algorithm: string;
570
590
  keyLength: PublicKeyLength;
@@ -608,7 +628,8 @@ export interface TbsCertificate {
608
628
  export function readTbsCertificate(buffer: Buffer, block: BlockInfo): TbsCertificate {
609
629
  const blocks = _readStruct(buffer, block);
610
630
 
611
- let version, serialNumber, signature, issuer, validity, subject, subjectFingerPrint, subjectPublicKeyInfo, extensions;
631
+ let version, serialNumber, signature, issuer, validity, subject, subjectFingerPrint, extensions;
632
+ let subjectPublicKeyInfo: SubjectPublicKeyInfo;
612
633
 
613
634
  if (blocks.length === 6) {
614
635
  // X509 Version 1:
@@ -625,7 +646,6 @@ export function readTbsCertificate(buffer: Buffer, block: BlockInfo): TbsCertifi
625
646
  extensions = null;
626
647
  } else {
627
648
  // X509 Version 3:
628
-
629
649
  const version_block = _findBlockAtIndex(blocks, 0);
630
650
  if (!version_block) {
631
651
  throw new Error("cannot find version block");
@@ -637,7 +657,21 @@ export function readTbsCertificate(buffer: Buffer, block: BlockInfo): TbsCertifi
637
657
  validity = _readValidity(buffer, blocks[4]);
638
658
  subject = _readName(buffer, blocks[5]);
639
659
  subjectFingerPrint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[5])));
640
- subjectPublicKeyInfo = _readSubjectPublicKeyInfo(buffer, blocks[6]);
660
+
661
+ const inner_block = _readStruct(buffer, blocks[6])
662
+ const what_type = _readAlgorithmIdentifier(buffer, inner_block[0]).identifier
663
+
664
+ switch (what_type) {
665
+ case "rsaEncryption": {
666
+ subjectPublicKeyInfo = _readSubjectPublicKeyInfo(buffer, blocks[6]);
667
+ break;
668
+ }
669
+ case "ecPublicKey":
670
+ default: {
671
+ subjectPublicKeyInfo = _readSubjectECCPublicKeyInfo(buffer, blocks[6]);
672
+ break;
673
+ }
674
+ }
641
675
 
642
676
  const extensionBlock = _findBlockAtIndex(blocks, 3);
643
677
  if (!extensionBlock) {
@@ -12,7 +12,7 @@ import { hexy } from "hexy";
12
12
 
13
13
  const jsrsasign = require("jsrsasign");
14
14
 
15
- const PEM_REGEX = /^(-----BEGIN (.*)-----\r?\n([\/+=a-zA-Z0-9\r\n]*)\r?\n-----END \2-----\r?\n)/gm;
15
+ const PEM_REGEX = /^(-----BEGIN (.*)-----\r?\n([/+=a-zA-Z0-9\r\n]*)\r?\n-----END \2-----\r?\n)/gm;
16
16
 
17
17
  const PEM_TYPE_REGEX = /^(-----BEGIN (.*)-----)/m;
18
18
  // Copyright 2012 The Obvious Corporation.
@@ -106,7 +106,7 @@ interface MakeMessageChunkSignatureOptions {
106
106
  * @return - the signature
107
107
  */
108
108
  export function makeMessageChunkSignature(chunk: Buffer, options: MakeMessageChunkSignatureOptions): Buffer {
109
- assert(options.hasOwnProperty("algorithm"));
109
+ assert(Object.prototype.hasOwnProperty.call(options,"algorithm"));
110
110
  assert(chunk instanceof Buffer);
111
111
  assert(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(options.privateKey) as string) >= 0);
112
112
  // signature length = 128 bytes
@@ -114,7 +114,7 @@ export function makeMessageChunkSignature(chunk: Buffer, options: MakeMessageChu
114
114
  signer.update(chunk);
115
115
  const signature = signer.sign(options.privateKey);
116
116
  assert(!options.signatureLength || signature.length === options.signatureLength);
117
- return signature as Buffer; // Buffer
117
+ return signature;
118
118
  }
119
119
 
120
120
  export interface VerifyMessageChunkSignatureOptions {