node-forge 0.7.0 → 0.7.4

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/CHANGELOG.md CHANGED
@@ -1,7 +1,38 @@
1
1
  Forge ChangeLog
2
2
  ===============
3
3
 
4
- ## 0.7.0 - 2017-??-??
4
+ ## 0.7.4 - 2018-03-07
5
+
6
+ ### Fixed
7
+ - Potential regex denial of service in form.js.
8
+
9
+ ### Added
10
+ - Support for ED25519.
11
+ - Support for baseN/base58.
12
+
13
+ ## 0.7.3 - 2018-03-05
14
+
15
+ - Re-publish with npm 5.6.0 due to file timestamp issues.
16
+
17
+ ## 0.7.2 - 2018-02-27
18
+
19
+ ### Added
20
+ - Support verification of SHA-384 certificates.
21
+ - `1.2.840.10040.4.3'`/`dsa-with-sha1` OID.
22
+
23
+ ### Fixed
24
+ - Support importing PKCS#7 data with no certificates. RFC 2315 sec 9.1 states
25
+ certificates are optional.
26
+ - `asn1.equals` loop bug.
27
+ - Fortuna implementation bugs.
28
+
29
+ ## 0.7.1 - 2017-03-27
30
+
31
+ ### Fixed
32
+
33
+ - Fix digestLength for hashes based on SHA-512.
34
+
35
+ ## 0.7.0 - 2017-02-07
5
36
 
6
37
  ### Fixed
7
38
 
package/README.md CHANGED
@@ -53,6 +53,7 @@ Documentation
53
53
 
54
54
  ### PKI
55
55
 
56
+ * [ED25519](#ed25519)
56
57
  * [RSA](#rsa)
57
58
  * [RSA-KEM](#rsakem)
58
59
  * [X.509](#x509)
@@ -94,8 +95,8 @@ Documentation
94
95
  Installation
95
96
  ------------
96
97
 
97
- Please see the [Security Considerations][] section before using packaging
98
- systems and pre-built files.
98
+ **Note**: Please see the [Security Considerations](#security-considerations)
99
+ section before using packaging systems and pre-built files.
99
100
 
100
101
  Forge uses a [CommonJS][] module structure with a build process for browser
101
102
  bundles. The older [0.6.x][] branch with standalone files is available but will
@@ -132,6 +133,22 @@ with [Bower][]:
132
133
 
133
134
  bower install forge
134
135
 
136
+ ### jsDelivr CDN
137
+
138
+ To use it via [jsDelivr](https://www.jsdelivr.com/package/npm/node-forge) include this in your html:
139
+
140
+ ```html
141
+ <script src="https://cdn.jsdelivr.net/npm/node-forge@0.7.0/dist/forge.min.js"></script>
142
+ ```
143
+
144
+ ### unpkg CDN
145
+
146
+ To use it via [unpkg](https://unpkg.com/#/) include this in your html:
147
+
148
+ ```html
149
+ <script src="https://unpkg.com/node-forge@0.7.0/dist/forge.min.js"></script>
150
+ ```
151
+
135
152
  ### Development Requirements
136
153
 
137
154
  The core JavaScript has the following requirements to build and test:
@@ -279,6 +296,7 @@ API
279
296
  ---
280
297
 
281
298
  <a name="options" />
299
+
282
300
  ### Options
283
301
 
284
302
  If at any time you wish to disable the use of native code, where available,
@@ -307,6 +325,7 @@ Transports
307
325
  ----------
308
326
 
309
327
  <a name="tls" />
328
+
310
329
  ### TLS
311
330
 
312
331
  Provides a native javascript client and server-side [TLS][] implementation.
@@ -517,6 +536,7 @@ socket.connect(443, 'google.com');
517
536
  ```
518
537
 
519
538
  <a name="http" />
539
+
520
540
  ### HTTP
521
541
 
522
542
  Provides a native [JavaScript][] mini-implementation of an http client that
@@ -552,6 +572,7 @@ var someAsyncDataHandler = function(bytes) {
552
572
  ```
553
573
 
554
574
  <a name="ssh" />
575
+
555
576
  ### SSH
556
577
 
557
578
  Provides some SSH utility functions.
@@ -576,6 +597,7 @@ forge.ssh.getPublicKeyFingerprint(key, {encoding: 'hex', delimiter: ':'});
576
597
  ```
577
598
 
578
599
  <a name="xhr" />
600
+
579
601
  ### XHR
580
602
 
581
603
  Provides an XmlHttpRequest implementation using forge.http as a backend.
@@ -587,6 +609,7 @@ __Examples__
587
609
  ```
588
610
 
589
611
  <a name="socket" />
612
+
590
613
  ### Sockets
591
614
 
592
615
  Provides an interface to create and use raw sockets provided via Flash.
@@ -601,6 +624,7 @@ Ciphers
601
624
  -------
602
625
 
603
626
  <a name="cipher" />
627
+
604
628
  ### CIPHER
605
629
 
606
630
  Provides a basic API for block encryption and decryption. There is built-in
@@ -654,10 +678,35 @@ console.log(encrypted.toHex());
654
678
  var decipher = forge.cipher.createDecipher('AES-CBC', key);
655
679
  decipher.start({iv: iv});
656
680
  decipher.update(encrypted);
657
- decipher.finish();
681
+ var result = decipher.finish(); // check 'result' for true/false
658
682
  // outputs decrypted hex
659
683
  console.log(decipher.output.toHex());
660
684
 
685
+ // decrypt bytes using CBC mode and streaming
686
+ // Performance can suffer for large multi-MB inputs due to buffer
687
+ // manipulations. Stream processing in chunks can offer significant
688
+ // improvement. CPU intensive update() calls could also be performed with
689
+ // setImmediate/setTimeout to avoid blocking the main browser UI thread (not
690
+ // shown here). Optimal block size depends on the JavaScript VM and other
691
+ // factors. Encryption can use a simple technique for increased performance.
692
+ var encryptedBytes = encrypted.bytes();
693
+ var decipher = forge.cipher.createDecipher('AES-CBC', key);
694
+ decipher.start({iv: iv});
695
+ var length = encryptedBytes.length;
696
+ var chunkSize = 1024 * 64;
697
+ var index = 0;
698
+ var decrypted = '';
699
+ do {
700
+ decrypted += decipher.output.getBytes();
701
+ var buf = forge.util.createBuffer(encryptedBytes.substr(index, chunkSize));
702
+ decipher.update(buf);
703
+ index += chunkSize;
704
+ } while(index < length);
705
+ var result = decipher.finish();
706
+ assert(result);
707
+ decrypted += decipher.output.getBytes();
708
+ console.log(forge.util.bytesToHex(decrypted));
709
+
661
710
  // encrypt some bytes using GCM mode
662
711
  var cipher = forge.cipher.createCipher('AES-GCM', key);
663
712
  cipher.start({
@@ -770,18 +819,21 @@ function decrypt(password) {
770
819
  ```
771
820
 
772
821
  <a name="aes" />
822
+
773
823
  ### AES
774
824
 
775
825
  Provides [AES][] encryption and decryption in [CBC][], [CFB][], [OFB][],
776
826
  [CTR][], and [GCM][] modes. See [CIPHER](#cipher) for examples.
777
827
 
778
828
  <a name="des" />
829
+
779
830
  ### DES
780
831
 
781
832
  Provides [3DES][] and [DES][] encryption and decryption in [ECB][] and
782
833
  [CBC][] modes. See [CIPHER](#cipher) for examples.
783
834
 
784
835
  <a name="rc2" />
836
+
785
837
  ### RC2
786
838
 
787
839
  __Examples__
@@ -812,10 +864,95 @@ console.log(cipher.output.toHex());
812
864
  PKI
813
865
  ---
814
866
 
815
- Provides [X.509][] certificate and RSA public and private key encoding,
816
- decoding, encryption/decryption, and signing/verifying.
867
+ Provides [X.509][] certificate support, ED25519 key generation and
868
+ signing/verifying, and RSA public and private key encoding, decoding,
869
+ encryption/decryption, and signing/verifying.
870
+
871
+ <a name="ed25519" />
872
+
873
+ ### ED25519
874
+
875
+ Special thanks to [TweetNaCl.js][] for providing the bulk of the implementation.
876
+
877
+ __Examples__
878
+
879
+ ```js
880
+ var ed25519 = forge.pki.ed25519;
881
+
882
+ // generate a random ED25519 keypair
883
+ var keypair = ed25519.generateKeyPair();
884
+ // `keypair.publicKey` is a node.js Buffer or Uint8Array
885
+ // `keypair.privateKey` is a node.js Buffer or Uint8Array
886
+
887
+ // generate a random ED25519 keypair based on a random 32-byte seed
888
+ var seed = forge.random.getBytesSync(32);
889
+ var keypair = ed25519.generateKeyPair({seed: seed});
890
+
891
+ // generate a random ED25519 keypair based on a "password" 32-byte seed
892
+ var password = 'Mai9ohgh6ahxee0jutheew0pungoozil';
893
+ var seed = new forge.util.ByteBuffer(password, 'utf8');
894
+ var keypair = ed25519.generateKeyPair({seed: seed});
895
+
896
+ // sign a UTF-8 message
897
+ var signature = ED25519.sign({
898
+ message: 'test',
899
+ // also accepts `binary` if you want to pass a binary string
900
+ encoding: 'utf8',
901
+ // node.js Buffer, Uint8Array, forge ByteBuffer, binary string
902
+ privateKey: privateKey
903
+ });
904
+ // `signature` is a node.js Buffer or Uint8Array
905
+
906
+ // sign a message passed as a buffer
907
+ var signature = ED25519.sign({
908
+ // also accepts a forge ByteBuffer or Uint8Array
909
+ message: new Buffer('test', 'utf8'),
910
+ privateKey: privateKey
911
+ });
912
+
913
+ // sign a message digest (shorter "message" == better performance)
914
+ var md = forge.md.sha256.create();
915
+ md.update('test', 'utf8');
916
+ var signature = ED25519.sign({
917
+ md: md,
918
+ privateKey: privateKey
919
+ });
920
+
921
+ // verify a signature on a UTF-8 message
922
+ var verified = ED25519.verify({
923
+ message: 'test',
924
+ encoding: 'utf8',
925
+ // node.js Buffer, Uint8Array, forge ByteBuffer, or binary string
926
+ signature: signature,
927
+ // node.js Buffer, Uint8Array, forge ByteBuffer, or binary string
928
+ publicKey: publicKey
929
+ });
930
+ // `verified` is true/false
931
+
932
+ // sign a message passed as a buffer
933
+ var verified = ED25519.verify({
934
+ // also accepts a forge ByteBuffer or Uint8Array
935
+ message: new Buffer('test', 'utf8'),
936
+ // node.js Buffer, Uint8Array, forge ByteBuffer, or binary string
937
+ signature: signature,
938
+ // node.js Buffer, Uint8Array, forge ByteBuffer, or binary string
939
+ publicKey: publicKey
940
+ });
941
+
942
+ // verify a signature on a message digest
943
+ var md = forge.md.sha256.create();
944
+ md.update('test', 'utf8');
945
+ var verified = ED25519.verify({
946
+ md: md,
947
+ // node.js Buffer, Uint8Array, forge ByteBuffer, or binary string
948
+ signature: signature,
949
+ // node.js Buffer, Uint8Array, forge ByteBuffer, or binary string
950
+ publicKey: publicKey
951
+ });
952
+ ```
817
953
 
818
954
  <a name="rsa" />
955
+
819
956
  ### RSA
820
957
 
821
958
  __Examples__
@@ -934,6 +1071,7 @@ var decrypted = privateKey.decrypt(encrypted, 'RSA-OAEP', {
934
1071
  ```
935
1072
 
936
1073
  <a name="rsakem" />
1074
+
937
1075
  ### RSA-KEM
938
1076
 
939
1077
  __Examples__
@@ -982,6 +1120,7 @@ if(pass) {
982
1120
  ```
983
1121
 
984
1122
  <a name="x509" />
1123
+
985
1124
  ### X.509
986
1125
 
987
1126
  __Examples__
@@ -1051,6 +1190,10 @@ var cert = pki.createCertificate();
1051
1190
  cert.publicKey = keys.publicKey;
1052
1191
  // alternatively set public key from a csr
1053
1192
  //cert.publicKey = csr.publicKey;
1193
+ // NOTE: serialNumber is the hex encoded value of an ASN.1 INTEGER.
1194
+ // Conforming CAs should ensure serialNumber is:
1195
+ // - no more than 20 octets
1196
+ // - non-negative (prefix a '00' if your value starts with a '1' bit)
1054
1197
  cert.serialNumber = '01';
1055
1198
  cert.validity.notBefore = new Date();
1056
1199
  cert.validity.notAfter = new Date();
@@ -1149,6 +1292,7 @@ var asn1Cert = pki.certificateToAsn1(cert);
1149
1292
  ```
1150
1293
 
1151
1294
  <a name="pkcs5" />
1295
+
1152
1296
  ### PKCS#5
1153
1297
 
1154
1298
  Provides the password-based key-derivation function from [PKCS#5][].
@@ -1169,6 +1313,7 @@ forge.pkcs5.pbkdf2('password', salt, numIterations, 16, function(err, derivedKey
1169
1313
  ```
1170
1314
 
1171
1315
  <a name="pkcs7" />
1316
+
1172
1317
  ### PKCS#7
1173
1318
 
1174
1319
  Provides cryptographically protected messages from [PKCS#7][].
@@ -1236,6 +1381,7 @@ var pem = forge.pkcs7.messageToPem(p7);
1236
1381
  ```
1237
1382
 
1238
1383
  <a name="pkcs8" />
1384
+
1239
1385
  ### PKCS#8
1240
1386
 
1241
1387
  __Examples__
@@ -1292,6 +1438,7 @@ var publicKey = pki.setRsaPublicKey(privateKey.n, privateKey.e);
1292
1438
  ```
1293
1439
 
1294
1440
  <a name="pkcs10" />
1441
+
1295
1442
  ### PKCS#10
1296
1443
 
1297
1444
  Provides certification requests or certificate signing requests (CSR) from
@@ -1371,6 +1518,7 @@ csr.getAttribute({name: 'extensionRequest'}).extensions;
1371
1518
  ```
1372
1519
 
1373
1520
  <a name="pkcs12" />
1521
+
1374
1522
  ### PKCS#12
1375
1523
 
1376
1524
  Provides the cryptographic archive file format from [PKCS#12][].
@@ -1462,6 +1610,7 @@ a.appendChild(document.createTextNode('Download'));
1462
1610
  ```
1463
1611
 
1464
1612
  <a name="asn" />
1613
+
1465
1614
  ### ASN.1
1466
1615
 
1467
1616
  Provides [ASN.1][] DER encoding and decoding.
@@ -1569,6 +1718,7 @@ Message Digests
1569
1718
  ----------------
1570
1719
 
1571
1720
  <a name="sha1" />
1721
+
1572
1722
  ### SHA1
1573
1723
 
1574
1724
  Provides [SHA-1][] message digests.
@@ -1583,6 +1733,7 @@ console.log(md.digest().toHex());
1583
1733
  ```
1584
1734
 
1585
1735
  <a name="sha256" />
1736
+
1586
1737
  ### SHA256
1587
1738
 
1588
1739
  Provides [SHA-256][] message digests.
@@ -1597,6 +1748,7 @@ console.log(md.digest().toHex());
1597
1748
  ```
1598
1749
 
1599
1750
  <a name="sha384" />
1751
+
1600
1752
  ### SHA384
1601
1753
 
1602
1754
  Provides [SHA-384][] message digests.
@@ -1611,6 +1763,7 @@ console.log(md.digest().toHex());
1611
1763
  ```
1612
1764
 
1613
1765
  <a name="sha512" />
1766
+
1614
1767
  ### SHA512
1615
1768
 
1616
1769
  Provides [SHA-512][] message digests.
@@ -1638,6 +1791,7 @@ console.log(md.digest().toHex());
1638
1791
  ```
1639
1792
 
1640
1793
  <a name="md5" />
1794
+
1641
1795
  ### MD5
1642
1796
 
1643
1797
  Provides [MD5][] message digests.
@@ -1652,6 +1806,7 @@ console.log(md.digest().toHex());
1652
1806
  ```
1653
1807
 
1654
1808
  <a name="hmac" />
1809
+
1655
1810
  ### HMAC
1656
1811
 
1657
1812
  Provides [HMAC][] w/any supported message digest algorithm.
@@ -1670,6 +1825,7 @@ Utilities
1670
1825
  ---------
1671
1826
 
1672
1827
  <a name="prime" />
1828
+
1673
1829
  ### Prime
1674
1830
 
1675
1831
  Provides an API for generating large, random, probable primes.
@@ -1698,6 +1854,7 @@ forge.prime.generateProbablePrime(bits, options, function(err, num) {
1698
1854
  ```
1699
1855
 
1700
1856
  <a name="prng" />
1857
+
1701
1858
  ### PRNG
1702
1859
 
1703
1860
  Provides a [Fortuna][]-based cryptographically-secure pseudo-random number
@@ -1746,6 +1903,7 @@ var myPrng = forge.random.createInstance();
1746
1903
  ```
1747
1904
 
1748
1905
  <a name="task" />
1906
+
1749
1907
  ### Tasks
1750
1908
 
1751
1909
  Provides queuing and synchronizing tasks in a web application.
@@ -1757,6 +1915,7 @@ __Examples__
1757
1915
  ```
1758
1916
 
1759
1917
  <a name="util" />
1918
+
1760
1919
  ### Utilities
1761
1920
 
1762
1921
  Provides utility functions, including byte buffer support, base64,
@@ -1813,6 +1972,7 @@ var parsed = forge.util.parseUrl('http://example.com/foo?bar=baz');
1813
1972
  ```
1814
1973
 
1815
1974
  <a name="log" />
1975
+
1816
1976
  ### Logging
1817
1977
 
1818
1978
  Provides logging to a javascript console using various categories and
@@ -1825,6 +1985,7 @@ __Examples__
1825
1985
  ```
1826
1986
 
1827
1987
  <a name="debug" />
1988
+
1828
1989
  ### Debugging
1829
1990
 
1830
1991
  Provides storage of debugging information normally inaccessible in
@@ -1837,6 +1998,7 @@ __Examples__
1837
1998
  ```
1838
1999
 
1839
2000
  <a name="flash" />
2001
+
1840
2002
  ### Flash Networking Support
1841
2003
 
1842
2004
  The [flash README](./flash/README.md) provides details on rebuilding the
@@ -1928,4 +2090,6 @@ Financial support is welcome and helps contribute to futher development:
1928
2090
  [UMD]: https://github.com/umdjs/umd
1929
2091
  [X.509]: http://en.wikipedia.org/wiki/X.509
1930
2092
  [freenode]: https://freenode.net/
2093
+ [unpkg]: https://unpkg.com/
1931
2094
  [webpack]: https://webpack.github.io/
2095
+ [TweetNaCl]: https://github.com/dchest/tweetnacl-js