node-forge 0.8.1 → 0.8.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.
- package/CHANGELOG.md +23 -0
- package/README.md +4 -4
- package/dist/forge.all.min.js +1 -1
- package/dist/forge.min.js +1 -1
- package/flash/package.json +28 -0
- package/lib/aes.js +4 -4
- package/lib/aesCipherSuites.js +2 -4
- package/lib/asn1.js +1 -1
- package/lib/cipherModes.js +1 -1
- package/lib/des.js +2 -1
- package/lib/ed25519.js +2 -2
- package/lib/pbkdf2.js +2 -2
- package/lib/pkcs1.js +1 -1
- package/lib/pkcs12.js +1 -1
- package/lib/rsa.js +42 -42
- package/lib/sha1.js +6 -6
- package/lib/sha512.js +1 -1
- package/lib/tls.js +2 -2
- package/lib/x509.js +254 -246
- package/package.json +8 -11
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-forge-flash",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Flash build support for Forge.",
|
|
6
|
+
"homepage": "https://github.com/digitalbazaar/forge",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Digital Bazaar, Inc.",
|
|
9
|
+
"email": "support@digitalbazaar.com",
|
|
10
|
+
"url": "http://digitalbazaar.com/"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"flex-sdk": ""
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/digitalbazaar/forge"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/digitalbazaar/forge/issues",
|
|
21
|
+
"email": "support@digitalbazaar.com"
|
|
22
|
+
},
|
|
23
|
+
"license": "(BSD-3-Clause OR GPL-2.0)",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "mxmlc -debug=false -define=CONFIG::debugging,false -define=CONFIG::release,true -compiler.source-path=. -static-link-runtime-shared-libraries -output=swf/SocketPool.swf SocketPool.as",
|
|
26
|
+
"build-debug": "mxmlc -debug=true -define=CONFIG::debugging,true -define=CONFIG::release,false -compiler.source-path=. -static-link-runtime-shared-libraries -output=swf/SocketPool.swf SocketPool.as"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/lib/aes.js
CHANGED
|
@@ -648,7 +648,7 @@ function initialize() {
|
|
|
648
648
|
* of Nb*(Nr + 1) words: the algorithm requires an initial set of Nb words,
|
|
649
649
|
* and each of the Nr rounds requires Nb words of key data. The resulting
|
|
650
650
|
* key schedule consists of a linear array of 4-byte words, denoted [wi ],
|
|
651
|
-
* with i in the range 0
|
|
651
|
+
* with i in the range 0 <= i < Nb(Nr + 1).
|
|
652
652
|
*
|
|
653
653
|
* KeyExpansion(byte key[4*Nk], word w[Nb*(Nr+1)], Nk)
|
|
654
654
|
* AES-128 (Nb=4, Nk=4, Nr=10)
|
|
@@ -704,7 +704,7 @@ function _expandKey(key, decrypt) {
|
|
|
704
704
|
w[i] = w[i - Nk] ^ temp;
|
|
705
705
|
}
|
|
706
706
|
|
|
707
|
-
|
|
707
|
+
/* When we are updating a cipher block we always use the code path for
|
|
708
708
|
encryption whether we are decrypting or not (to shorten code and
|
|
709
709
|
simplify the generation of look up tables). However, because there
|
|
710
710
|
are differences in the decryption algorithm, other than just swapping
|
|
@@ -805,7 +805,7 @@ function _updateBlock(w, input, output, decrypt) {
|
|
|
805
805
|
byte state[4,Nb]
|
|
806
806
|
state = in
|
|
807
807
|
AddRoundKey(state, w[0, Nb-1])
|
|
808
|
-
for round = 1 step 1 to Nr
|
|
808
|
+
for round = 1 step 1 to Nr-1
|
|
809
809
|
SubBytes(state)
|
|
810
810
|
ShiftRows(state)
|
|
811
811
|
MixColumns(state)
|
|
@@ -1017,7 +1017,7 @@ function _updateBlock(w, input, output, decrypt) {
|
|
|
1017
1017
|
InvSubBytes(state)
|
|
1018
1018
|
AddRoundKey(state, w[0, Nb-1])
|
|
1019
1019
|
*/
|
|
1020
|
-
|
|
1020
|
+
// Note: rows are shifted inline
|
|
1021
1021
|
output[0] =
|
|
1022
1022
|
(sub[a >>> 24] << 24) ^
|
|
1023
1023
|
(sub[b >>> 16 & 255] << 16) ^
|
package/lib/aesCipherSuites.js
CHANGED
|
@@ -16,7 +16,7 @@ var tls = module.exports = forge.tls;
|
|
|
16
16
|
* Supported cipher suites.
|
|
17
17
|
*/
|
|
18
18
|
tls.CipherSuites['TLS_RSA_WITH_AES_128_CBC_SHA'] = {
|
|
19
|
-
id: [0x00,0x2f],
|
|
19
|
+
id: [0x00, 0x2f],
|
|
20
20
|
name: 'TLS_RSA_WITH_AES_128_CBC_SHA',
|
|
21
21
|
initSecurityParameters: function(sp) {
|
|
22
22
|
sp.bulk_cipher_algorithm = tls.BulkCipherAlgorithm.aes;
|
|
@@ -32,7 +32,7 @@ tls.CipherSuites['TLS_RSA_WITH_AES_128_CBC_SHA'] = {
|
|
|
32
32
|
initConnectionState: initConnectionState
|
|
33
33
|
};
|
|
34
34
|
tls.CipherSuites['TLS_RSA_WITH_AES_256_CBC_SHA'] = {
|
|
35
|
-
id: [0x00,0x35],
|
|
35
|
+
id: [0x00, 0x35],
|
|
36
36
|
name: 'TLS_RSA_WITH_AES_256_CBC_SHA',
|
|
37
37
|
initSecurityParameters: function(sp) {
|
|
38
38
|
sp.bulk_cipher_algorithm = tls.BulkCipherAlgorithm.aes;
|
|
@@ -199,10 +199,8 @@ function decrypt_aes_cbc_sha1_padding(blockSize, output, decrypt) {
|
|
|
199
199
|
*
|
|
200
200
|
* @return true on success, false on failure.
|
|
201
201
|
*/
|
|
202
|
-
var count = 0;
|
|
203
202
|
function decrypt_aes_cbc_sha1(record, s) {
|
|
204
203
|
var rval = false;
|
|
205
|
-
++count;
|
|
206
204
|
|
|
207
205
|
var iv;
|
|
208
206
|
if(record.version.minor === tls.Versions.TLS_1_0.minor) {
|
package/lib/asn1.js
CHANGED
|
@@ -619,7 +619,7 @@ function _fromDer(bytes, remaining, depth, options) {
|
|
|
619
619
|
}
|
|
620
620
|
|
|
621
621
|
// add BIT STRING contents if available
|
|
622
|
-
var asn1Options = bitStringContents === undefined ?
|
|
622
|
+
var asn1Options = bitStringContents === undefined ? null : {
|
|
623
623
|
bitStringContents: bitStringContents
|
|
624
624
|
};
|
|
625
625
|
|
package/lib/cipherModes.js
CHANGED
|
@@ -652,7 +652,7 @@ modes.gcm.prototype.encrypt = function(input, output, finish) {
|
|
|
652
652
|
this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]);
|
|
653
653
|
}
|
|
654
654
|
|
|
655
|
-
if(partialBytes
|
|
655
|
+
if(partialBytes <= 0 || finish) {
|
|
656
656
|
// handle overflow prior to hashing
|
|
657
657
|
if(finish) {
|
|
658
658
|
// get block overflow
|
package/lib/des.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* Paul Tero, July 2001
|
|
8
8
|
* http://www.tero.co.uk/des/
|
|
9
9
|
*
|
|
10
|
-
* Optimised for performance with large blocks by
|
|
10
|
+
* Optimised for performance with large blocks by
|
|
11
|
+
* Michael Hayworth, November 2001
|
|
11
12
|
* http://www.netdealing.com
|
|
12
13
|
*
|
|
13
14
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND
|
package/lib/ed25519.js
CHANGED
|
@@ -168,7 +168,7 @@ function messageToNativeBuffer(options) {
|
|
|
168
168
|
|
|
169
169
|
if(typeof message === 'string') {
|
|
170
170
|
if(typeof Buffer !== 'undefined') {
|
|
171
|
-
return
|
|
171
|
+
return Buffer.from(message, encoding);
|
|
172
172
|
}
|
|
173
173
|
message = new ByteBuffer(message, encoding);
|
|
174
174
|
} else if(!(message instanceof ByteBuffer)) {
|
|
@@ -217,7 +217,7 @@ function sha512(msg, msgLen) {
|
|
|
217
217
|
md.update(buffer.getBytes(msgLen), 'binary');
|
|
218
218
|
var hash = md.digest().getBytes();
|
|
219
219
|
if(typeof Buffer !== 'undefined') {
|
|
220
|
-
return
|
|
220
|
+
return Buffer.from(hash, 'binary');
|
|
221
221
|
}
|
|
222
222
|
var out = new NativeBuffer(ed25519.constants.HASH_BYTE_LENGTH);
|
|
223
223
|
for(var i = 0; i < 64; ++i) {
|
package/lib/pbkdf2.js
CHANGED
|
@@ -51,8 +51,8 @@ module.exports = forge.pbkdf2 = pkcs5.pbkdf2 = function(
|
|
|
51
51
|
// default prf to SHA-1
|
|
52
52
|
md = 'sha1';
|
|
53
53
|
}
|
|
54
|
-
p =
|
|
55
|
-
s =
|
|
54
|
+
p = Buffer.from(p, 'binary');
|
|
55
|
+
s = Buffer.from(s, 'binary');
|
|
56
56
|
if(!callback) {
|
|
57
57
|
if(crypto.pbkdf2Sync.length === 4) {
|
|
58
58
|
return crypto.pbkdf2Sync(p, s, c, dkLen).toString('binary');
|
package/lib/pkcs1.js
CHANGED
package/lib/pkcs12.js
CHANGED
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
* PKCS12Attribute ::= SEQUENCE {
|
|
69
69
|
* attrId ATTRIBUTE.&id ({PKCS12AttrSet}),
|
|
70
70
|
* attrValues SET OF ATTRIBUTE.&Type ({PKCS12AttrSet}{@attrId})
|
|
71
|
-
* } -- This type is compatible with the X.500 type
|
|
71
|
+
* } -- This type is compatible with the X.500 type 'Attribute'
|
|
72
72
|
*
|
|
73
73
|
* PKCS12AttrSet ATTRIBUTE ::= {
|
|
74
74
|
* friendlyName | -- from PKCS #9
|
package/lib/rsa.js
CHANGED
|
@@ -89,7 +89,6 @@ forge.pki = forge.pki || {};
|
|
|
89
89
|
module.exports = forge.pki.rsa = forge.rsa = forge.rsa || {};
|
|
90
90
|
var pki = forge.pki;
|
|
91
91
|
|
|
92
|
-
|
|
93
92
|
// for finding primes, which are 30k+i for i = 1, 7, 11, 13, 17, 19, 23, 29
|
|
94
93
|
var GCD_30_DELTA = [6, 4, 2, 4, 2, 4, 6, 2];
|
|
95
94
|
|
|
@@ -688,7 +687,7 @@ pki.rsa.stepKeyPairGenerationState = function(state, n) {
|
|
|
688
687
|
var THIRTY = new BigInteger(null);
|
|
689
688
|
THIRTY.fromInt(30);
|
|
690
689
|
var deltaIdx = 0;
|
|
691
|
-
var op_or = function(x, y) {
|
|
690
|
+
var op_or = function(x, y) {return x | y;};
|
|
692
691
|
|
|
693
692
|
// keep stepping until time limit is reached or done
|
|
694
693
|
var t1 = +new Date();
|
|
@@ -737,7 +736,7 @@ pki.rsa.stepKeyPairGenerationState = function(state, n) {
|
|
|
737
736
|
// ensure number is coprime with e
|
|
738
737
|
state.pqState =
|
|
739
738
|
(state.num.subtract(BigInteger.ONE).gcd(state.e)
|
|
740
|
-
|
|
739
|
+
.compareTo(BigInteger.ONE) === 0) ? 3 : 0;
|
|
741
740
|
} else if(state.pqState === 3) {
|
|
742
741
|
// store p or q
|
|
743
742
|
state.pqState = 0;
|
|
@@ -907,7 +906,7 @@ pki.rsa.generateKeyPair = function(bits, e, options, callback) {
|
|
|
907
906
|
format: 'pem'
|
|
908
907
|
}
|
|
909
908
|
}, function(err, pub, priv) {
|
|
910
|
-
if
|
|
909
|
+
if(err) {
|
|
911
910
|
return callback(err);
|
|
912
911
|
}
|
|
913
912
|
callback(null, {
|
|
@@ -916,7 +915,8 @@ pki.rsa.generateKeyPair = function(bits, e, options, callback) {
|
|
|
916
915
|
});
|
|
917
916
|
});
|
|
918
917
|
}
|
|
919
|
-
if(_detectSubtleCrypto('generateKey') &&
|
|
918
|
+
if(_detectSubtleCrypto('generateKey') &&
|
|
919
|
+
_detectSubtleCrypto('exportKey')) {
|
|
920
920
|
// use standard native generateKey
|
|
921
921
|
return util.globalScope.crypto.subtle.generateKey({
|
|
922
922
|
name: 'RSASSA-PKCS1-v1_5',
|
|
@@ -1054,7 +1054,7 @@ pki.setRsaPublicKey = pki.rsa.setPublicKey = function(n, e) {
|
|
|
1054
1054
|
}
|
|
1055
1055
|
};
|
|
1056
1056
|
} else if(['RAW', 'NONE', 'NULL', null].indexOf(scheme) !== -1) {
|
|
1057
|
-
scheme = {
|
|
1057
|
+
scheme = {encode: function(e) {return e;}};
|
|
1058
1058
|
} else if(typeof scheme === 'string') {
|
|
1059
1059
|
throw new Error('Unsupported encryption scheme: "' + scheme + '".');
|
|
1060
1060
|
}
|
|
@@ -1095,37 +1095,37 @@ pki.setRsaPublicKey = pki.rsa.setPublicKey = function(n, e) {
|
|
|
1095
1095
|
*
|
|
1096
1096
|
* @return true if the signature was verified, false if not.
|
|
1097
1097
|
*/
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1098
|
+
key.verify = function(digest, signature, scheme) {
|
|
1099
|
+
if(typeof scheme === 'string') {
|
|
1100
|
+
scheme = scheme.toUpperCase();
|
|
1101
|
+
} else if(scheme === undefined) {
|
|
1102
|
+
scheme = 'RSASSA-PKCS1-V1_5';
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
if(scheme === 'RSASSA-PKCS1-V1_5') {
|
|
1106
|
+
scheme = {
|
|
1107
|
+
verify: function(digest, d) {
|
|
1108
|
+
// remove padding
|
|
1109
|
+
d = _decodePkcs1_v1_5(d, key, true);
|
|
1110
|
+
// d is ASN.1 BER-encoded DigestInfo
|
|
1111
|
+
var obj = asn1.fromDer(d);
|
|
1112
|
+
// compare the given digest to the decrypted one
|
|
1113
|
+
return digest === obj.value[1].value;
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
} else if(scheme === 'NONE' || scheme === 'NULL' || scheme === null) {
|
|
1117
|
+
scheme = {
|
|
1118
|
+
verify: function(digest, d) {
|
|
1119
|
+
// remove padding
|
|
1120
|
+
d = _decodePkcs1_v1_5(d, key, true);
|
|
1121
|
+
return digest === d;
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// do rsa decryption w/o any decoding, then verify -- which does decoding
|
|
1127
|
+
var d = pki.rsa.decrypt(signature, key, true, false);
|
|
1128
|
+
return scheme.verify(digest, d, key.n.bitLength());
|
|
1129
1129
|
};
|
|
1130
1130
|
|
|
1131
1131
|
return key;
|
|
@@ -1183,7 +1183,7 @@ pki.setRsaPrivateKey = pki.rsa.setPrivateKey = function(
|
|
|
1183
1183
|
var d = pki.rsa.decrypt(data, key, false, false);
|
|
1184
1184
|
|
|
1185
1185
|
if(scheme === 'RSAES-PKCS1-V1_5') {
|
|
1186
|
-
scheme = {
|
|
1186
|
+
scheme = {decode: _decodePkcs1_v1_5};
|
|
1187
1187
|
} else if(scheme === 'RSA-OAEP' || scheme === 'RSAES-OAEP') {
|
|
1188
1188
|
scheme = {
|
|
1189
1189
|
decode: function(d, key) {
|
|
@@ -1191,7 +1191,7 @@ pki.setRsaPrivateKey = pki.rsa.setPrivateKey = function(
|
|
|
1191
1191
|
}
|
|
1192
1192
|
};
|
|
1193
1193
|
} else if(['RAW', 'NONE', 'NULL', null].indexOf(scheme) !== -1) {
|
|
1194
|
-
scheme = {
|
|
1194
|
+
scheme = {decode: function(d) {return d;}};
|
|
1195
1195
|
} else {
|
|
1196
1196
|
throw new Error('Unsupported encryption scheme: "' + scheme + '".');
|
|
1197
1197
|
}
|
|
@@ -1233,10 +1233,10 @@ pki.setRsaPrivateKey = pki.rsa.setPrivateKey = function(
|
|
|
1233
1233
|
}
|
|
1234
1234
|
|
|
1235
1235
|
if(scheme === undefined || scheme === 'RSASSA-PKCS1-V1_5') {
|
|
1236
|
-
scheme = {
|
|
1236
|
+
scheme = {encode: emsaPkcs1v15encode};
|
|
1237
1237
|
bt = 0x01;
|
|
1238
1238
|
} else if(scheme === 'NONE' || scheme === 'NULL' || scheme === null) {
|
|
1239
|
-
scheme = {
|
|
1239
|
+
scheme = {encode: function() {return md;}};
|
|
1240
1240
|
bt = 0x01;
|
|
1241
1241
|
}
|
|
1242
1242
|
|
|
@@ -1271,7 +1271,7 @@ pki.wrapRsaPrivateKey = function(rsaKey) {
|
|
|
1271
1271
|
// PrivateKey
|
|
1272
1272
|
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
|
|
1273
1273
|
asn1.toDer(rsaKey).getBytes())
|
|
1274
|
-
|
|
1274
|
+
]);
|
|
1275
1275
|
};
|
|
1276
1276
|
|
|
1277
1277
|
/**
|
package/lib/sha1.js
CHANGED
|
@@ -113,12 +113,12 @@ sha1.create = function() {
|
|
|
113
113
|
return md;
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Produces the digest.
|
|
118
|
+
*
|
|
119
|
+
* @return a byte buffer containing the digest value.
|
|
120
|
+
*/
|
|
121
|
+
md.digest = function() {
|
|
122
122
|
/* Note: Here we copy the remaining bytes in the input buffer and
|
|
123
123
|
add the appropriate SHA-1 padding. Then we do the final update
|
|
124
124
|
on a copy of the state so that if the user wants to get
|
package/lib/sha512.js
CHANGED
package/lib/tls.js
CHANGED
|
@@ -3528,7 +3528,7 @@ var _alertDescToCertError = function(desc) {
|
|
|
3528
3528
|
*/
|
|
3529
3529
|
tls.verifyCertificateChain = function(c, chain) {
|
|
3530
3530
|
try {
|
|
3531
|
-
// Make a copy of c.verifyOptions so that we can modify options.verify
|
|
3531
|
+
// Make a copy of c.verifyOptions so that we can modify options.verify
|
|
3532
3532
|
// without modifying c.verifyOptions.
|
|
3533
3533
|
var options = {};
|
|
3534
3534
|
for (var key in c.verifyOptions) {
|
|
@@ -3726,7 +3726,7 @@ tls.createConnection = function(options) {
|
|
|
3726
3726
|
virtualHost: options.virtualHost || null,
|
|
3727
3727
|
verifyClient: options.verifyClient || false,
|
|
3728
3728
|
verify: options.verify || function(cn, vfd, dpth, cts) {return vfd;},
|
|
3729
|
-
verifyOptions: options.verifyOptions ||
|
|
3729
|
+
verifyOptions: options.verifyOptions || {},
|
|
3730
3730
|
getCertificate: options.getCertificate || null,
|
|
3731
3731
|
getPrivateKey: options.getPrivateKey || null,
|
|
3732
3732
|
getSignature: options.getSignature || null,
|