Skip to content

Commit df54d0b

Browse files
committed
enhanced support for encrypted PKCS8
1 parent 59920c4 commit df54d0b

29 files changed

+1369
-325
lines changed

ChangeLog.txt

+24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11

22
ChangeLog for jsrsasign
33

4+
enhanced support for encrypted PKCS8
5+
* Changes from 10.8.6 to 10.9.0 (2023-Nov-27)
6+
- KEYUTIL.getPEM is updated not to use weak ciphers (#599)
7+
- default encryptionScheme is changed from des-EDE3-CBC to aes256-CBC
8+
- default prf is changed from hmacWithSHA1 to hmacWithSHA256
9+
- src/keyutil.js
10+
- more encrypted PKCS#8 private key support
11+
- KEYUTIL.getKey now supports encrypted PKCS#8 private key with
12+
aes128-CBC, aes256-CBC encrypted and using hmacWithSHA224/256/384/512 as
13+
psudorandom function.
14+
- KEYUTIL.getPEM now supports such as above encrypted PKCS#8 PEM
15+
priavte key.
16+
- src/crypto.js
17+
- Cipher.decrypt/encrypt now supports symmetric ciphers (des-EDE3-CBC,aes128-CBC,aes256-CBC)
18+
- src/base64x.js
19+
- function inttohex and twoscompl are added
20+
- src/asn1.js
21+
- ASN1Util.bigIntToMinTwosComplementsHex is now DEPRECATED. use twoscompl.
22+
- src/asn1x509.js
23+
- aes*-CBC and hmacWithSHA* OIDs are added
24+
- test/qunit-do-{base64x,crypto-cipher,keyutil-eprv,keyutil,keyutil-p8egen}.html
25+
- update and add some test cases for above
26+
- stop bower support (bower.json removed)
27+
428
X509.getExtSubjectDirectoryAttributes another bugfix
529
* Changes from 10.8.5 to 10.8.6 (2023-Apr-26)
630
- src/x509.js

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ gitadd-all-doc:
8888
git add api/*.html api/symbols/*.html api/symbols/src/*.html LICENSE.txt
8989

9090
gitadd-release:
91-
git add ChangeLog.txt Makefile bower.json jsrsasign-*-min.js min/*.js src/*.js npm/package.json npm/lib/jsrsasign*.js npm/lib/{header,footer,lib}.js src/*.js test/qunit-do-*.html test/x509crl.html README.md npm/README.md tool/*.html npm_util/*.* npm_util/lib/*.* npm/test/t_*.js
91+
git add ChangeLog.txt Makefile jsrsasign-*-min.js min/*.js src/*.js npm/package.json npm/lib/jsrsasign*.js npm/lib/{header,footer,lib}.js src/*.js test/qunit-do-*.html test/x509crl.html README.md npm/README.md tool/*.html npm_util/*.* npm_util/lib/*.* npm/test/t_*.js
9292

9393
gitadd: gitadd-all-doc gitadd-release
9494
@echo done

bower.json

-14
This file was deleted.

ext/cj/pbkdf2.js

+125-125
Original file line numberDiff line numberDiff line change
@@ -4,128 +4,128 @@ code.google.com/p/crypto-js
44
(c) 2009-2013 by Jeff Mott. All rights reserved.
55
code.google.com/p/crypto-js/wiki/License
66
*/
7-
(function () {
8-
// Shortcuts
9-
var C = CryptoJS;
10-
var C_lib = C.lib;
11-
var Base = C_lib.Base;
12-
var WordArray = C_lib.WordArray;
13-
var C_algo = C.algo;
14-
var SHA1 = C_algo.SHA1;
15-
var HMAC = C_algo.HMAC;
16-
17-
/**
18-
* Password-Based Key Derivation Function 2 algorithm.
19-
*/
20-
var PBKDF2 = C_algo.PBKDF2 = Base.extend({
21-
/**
22-
* Configuration options.
23-
*
24-
* @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
25-
* @property {Hasher} hasher The hasher to use. Default: SHA1
26-
* @property {number} iterations The number of iterations to perform. Default: 1
27-
*/
28-
cfg: Base.extend({
29-
keySize: 128/32,
30-
hasher: SHA1,
31-
iterations: 1
32-
}),
33-
34-
/**
35-
* Initializes a newly created key derivation function.
36-
*
37-
* @param {Object} cfg (Optional) The configuration options to use for the derivation.
38-
*
39-
* @example
40-
*
41-
* var kdf = CryptoJS.algo.PBKDF2.create();
42-
* var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
43-
* var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
44-
*/
45-
init: function (cfg) {
46-
this.cfg = this.cfg.extend(cfg);
47-
},
48-
49-
/**
50-
* Computes the Password-Based Key Derivation Function 2.
51-
*
52-
* @param {WordArray|string} password The password.
53-
* @param {WordArray|string} salt A salt.
54-
*
55-
* @return {WordArray} The derived key.
56-
*
57-
* @example
58-
*
59-
* var key = kdf.compute(password, salt);
60-
*/
61-
compute: function (password, salt) {
62-
// Shortcut
63-
var cfg = this.cfg;
64-
65-
// Init HMAC
66-
var hmac = HMAC.create(cfg.hasher, password);
67-
68-
// Initial values
69-
var derivedKey = WordArray.create();
70-
var blockIndex = WordArray.create([0x00000001]);
71-
72-
// Shortcuts
73-
var derivedKeyWords = derivedKey.words;
74-
var blockIndexWords = blockIndex.words;
75-
var keySize = cfg.keySize;
76-
var iterations = cfg.iterations;
77-
78-
// Generate key
79-
while (derivedKeyWords.length < keySize) {
80-
var block = hmac.update(salt).finalize(blockIndex);
81-
hmac.reset();
82-
83-
// Shortcuts
84-
var blockWords = block.words;
85-
var blockWordsLength = blockWords.length;
86-
87-
// Iterations
88-
var intermediate = block;
89-
for (var i = 1; i < iterations; i++) {
90-
intermediate = hmac.finalize(intermediate);
91-
hmac.reset();
92-
93-
// Shortcut
94-
var intermediateWords = intermediate.words;
95-
96-
// XOR intermediate with block
97-
for (var j = 0; j < blockWordsLength; j++) {
98-
blockWords[j] ^= intermediateWords[j];
99-
}
100-
}
101-
102-
derivedKey.concat(block);
103-
blockIndexWords[0]++;
104-
}
105-
derivedKey.sigBytes = keySize * 4;
106-
107-
return derivedKey;
108-
}
109-
});
110-
111-
/**
112-
* Computes the Password-Based Key Derivation Function 2.
113-
*
114-
* @param {WordArray|string} password The password.
115-
* @param {WordArray|string} salt A salt.
116-
* @param {Object} cfg (Optional) The configuration options to use for this computation.
117-
*
118-
* @return {WordArray} The derived key.
119-
*
120-
* @static
121-
*
122-
* @example
123-
*
124-
* var key = CryptoJS.PBKDF2(password, salt);
125-
* var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
126-
* var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
127-
*/
128-
C.PBKDF2 = function (password, salt, cfg) {
129-
return PBKDF2.create(cfg).compute(password, salt);
130-
};
131-
}());
7+
(function () {
8+
// Shortcuts
9+
var C = CryptoJS;
10+
var C_lib = C.lib;
11+
var Base = C_lib.Base;
12+
var WordArray = C_lib.WordArray;
13+
var C_algo = C.algo;
14+
var SHA1 = C_algo.SHA1;
15+
var HMAC = C_algo.HMAC;
16+
17+
/**
18+
* Password-Based Key Derivation Function 2 algorithm.
19+
*/
20+
var PBKDF2 = C_algo.PBKDF2 = Base.extend({
21+
/**
22+
* Configuration options.
23+
*
24+
* @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
25+
* @property {Hasher} hasher The hasher to use. Default: SHA1
26+
* @property {number} iterations The number of iterations to perform. Default: 1
27+
*/
28+
cfg: Base.extend({
29+
keySize: 128/32,
30+
hasher: SHA1,
31+
iterations: 1
32+
}),
33+
34+
/**
35+
* Initializes a newly created key derivation function.
36+
*
37+
* @param {Object} cfg (Optional) The configuration options to use for the derivation.
38+
*
39+
* @example
40+
*
41+
* var kdf = CryptoJS.algo.PBKDF2.create();
42+
* var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
43+
* var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
44+
*/
45+
init: function (cfg) {
46+
this.cfg = this.cfg.extend(cfg);
47+
},
48+
49+
/**
50+
* Computes the Password-Based Key Derivation Function 2.
51+
*
52+
* @param {WordArray|string} password The password.
53+
* @param {WordArray|string} salt A salt.
54+
*
55+
* @return {WordArray} The derived key.
56+
*
57+
* @example
58+
*
59+
* var key = kdf.compute(password, salt);
60+
*/
61+
compute: function (password, salt) {
62+
// Shortcut
63+
var cfg = this.cfg;
64+
65+
// Init HMAC
66+
var hmac = HMAC.create(cfg.hasher, password);
67+
68+
// Initial values
69+
var derivedKey = WordArray.create();
70+
var blockIndex = WordArray.create([0x00000001]);
71+
72+
// Shortcuts
73+
var derivedKeyWords = derivedKey.words;
74+
var blockIndexWords = blockIndex.words;
75+
var keySize = cfg.keySize;
76+
var iterations = cfg.iterations;
77+
78+
// Generate key
79+
while (derivedKeyWords.length < keySize) {
80+
var block = hmac.update(salt).finalize(blockIndex);
81+
hmac.reset();
82+
83+
// Shortcuts
84+
var blockWords = block.words;
85+
var blockWordsLength = blockWords.length;
86+
87+
// Iterations
88+
var intermediate = block;
89+
for (var i = 1; i < iterations; i++) {
90+
intermediate = hmac.finalize(intermediate);
91+
hmac.reset();
92+
93+
// Shortcut
94+
var intermediateWords = intermediate.words;
95+
96+
// XOR intermediate with block
97+
for (var j = 0; j < blockWordsLength; j++) {
98+
blockWords[j] ^= intermediateWords[j];
99+
}
100+
}
101+
102+
derivedKey.concat(block);
103+
blockIndexWords[0]++;
104+
}
105+
derivedKey.sigBytes = keySize * 4;
106+
107+
return derivedKey;
108+
}
109+
});
110+
111+
/**
112+
* Computes the Password-Based Key Derivation Function 2.
113+
*
114+
* @param {WordArray|string} password The password.
115+
* @param {WordArray|string} salt A salt.
116+
* @param {Object} cfg (Optional) The configuration options to use for this computation.
117+
*
118+
* @return {WordArray} The derived key.
119+
*
120+
* @static
121+
*
122+
* @example
123+
*
124+
* var key = CryptoJS.PBKDF2(password, salt);
125+
* var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
126+
* var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
127+
*/
128+
C.PBKDF2 = function (password, salt, cfg) {
129+
return PBKDF2.create(cfg).compute(password, salt);
130+
};
131+
}());

jsrsasign-all-min.js

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsrsasign-jwths-min.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsrsasign-rsa-min.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

min/asn1-1.0.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

min/asn1x509-1.0.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)