@@ -57,7 +57,7 @@ describe("Crypto", () => {
57
57
it ( "with valid config with private keystore" , ( ) => {
58
58
const config = JSON . parse ( JSON . stringify ( testConfig ) ) ;
59
59
delete config . privateKey ;
60
- config . keyStore = "./test/res/test_key.p12" ;
60
+ config . keyStore = "./test/res/keys/pkcs12/ test_key.p12" ;
61
61
config . keyStoreAlias = "mykeyalias" ;
62
62
config . keyStorePassword = "Password1" ;
63
63
assert . doesNotThrow ( ( ) => {
@@ -66,6 +66,36 @@ describe("Crypto", () => {
66
66
) ;
67
67
} ) ;
68
68
69
+ it ( "with valid config with private pkcs1 pem keystore" , ( ) => {
70
+ const config = JSON . parse ( JSON . stringify ( testConfig ) ) ;
71
+ delete config . privateKey ;
72
+ config . keyStore = "./test/res/keys/pkcs1/test_key.pem" ;
73
+ assert . doesNotThrow ( ( ) => {
74
+ new Crypto ( config ) ;
75
+ }
76
+ ) ;
77
+ } ) ;
78
+
79
+ it ( "with valid config with private pkcs8 pem keystore" , ( ) => {
80
+ const config = JSON . parse ( JSON . stringify ( testConfig ) ) ;
81
+ delete config . privateKey ;
82
+ config . keyStore = "./test/res/keys/pkcs8/test_key.pem" ;
83
+ assert . doesNotThrow ( ( ) => {
84
+ new Crypto ( config ) ;
85
+ }
86
+ ) ;
87
+ } ) ;
88
+
89
+ it ( "with valid config with private pkcs8 der keystore" , ( ) => {
90
+ const config = JSON . parse ( JSON . stringify ( testConfig ) ) ;
91
+ delete config . privateKey ;
92
+ config . keyStore = "./test/res/keys/pkcs8/test_key.der" ;
93
+ assert . doesNotThrow ( ( ) => {
94
+ new Crypto ( config ) ;
95
+ }
96
+ ) ;
97
+ } ) ;
98
+
69
99
it ( "with valid config header" , ( ) => {
70
100
assert . doesNotThrow ( ( ) =>
71
101
new Crypto ( testConfigHeader )
@@ -233,8 +263,8 @@ describe("Crypto", () => {
233
263
} ) ;
234
264
} ) ;
235
265
236
- describe ( "#getPrivateKey " , ( ) => {
237
- const getPrivateKey = Crypto . __get__ ( "getPrivateKey " ) ;
266
+ describe ( "#getPrivateKey12 " , ( ) => {
267
+ const getPrivateKey = Crypto . __get__ ( "getPrivateKey12 " ) ;
238
268
239
269
it ( "not valid key" , ( ) => {
240
270
assert . throws ( ( ) => {
@@ -244,30 +274,65 @@ describe("Crypto", () => {
244
274
245
275
it ( "empty alias" , ( ) => {
246
276
assert . throws ( ( ) => {
247
- getPrivateKey ( "./test/res/test_key_container.p12" ) ;
277
+ getPrivateKey ( "./test/res/keys/pkcs12/ test_key_container.p12" ) ;
248
278
} , / K e y a l i a s i s n o t s e t / ) ;
249
279
} ) ;
250
280
251
281
it ( "empty password" , ( ) => {
252
282
assert . throws ( ( ) => {
253
- getPrivateKey ( "./test/res/test_key_container.p12" , "keyalias" ) ;
283
+ getPrivateKey ( "./test/res/keys/pkcs12/ test_key_container.p12" , "keyalias" ) ;
254
284
} , / K e y s t o r e p a s s w o r d i s n o t s e t / ) ;
255
285
} ) ;
256
286
257
287
it ( "valid p12" , ( ) => {
258
- const pk = getPrivateKey ( "./test/res/test_key_container.p12" , "mykeyalias" , "Password1" ) ;
288
+ const pk = getPrivateKey ( "./test/res/keys/pkcs12/ test_key_container.p12" , "mykeyalias" , "Password1" ) ;
259
289
assert . ok ( pk ) ;
260
290
} ) ;
261
291
262
292
it ( "valid p12, alias not found" , ( ) => {
263
293
assert . throws ( ( ) => {
264
- getPrivateKey ( "./test/res/test_key_container.p12" , "mykeyalias1" , "Password1" ) ;
294
+ getPrivateKey ( "./test/res/keys/pkcs12/ test_key_container.p12" , "mykeyalias1" , "Password1" ) ;
265
295
} , / N o k e y f o u n d f o r a l i a s \[ m y k e y a l i a s 1 \] / ) ;
266
296
} ) ;
267
297
} ) ;
268
298
299
+ describe ( "#getPrivateKeyPem" , ( ) => {
300
+ const getPrivateKeyPem = Crypto . __get__ ( "getPrivateKeyPem" ) ;
301
+
302
+ it ( "valid pkcs8 pem" , ( ) => {
303
+ const pk = getPrivateKeyPem ( "./test/res/keys/pkcs8/test_key.pem" ) ;
304
+ assert . ok ( pk ) ;
305
+ } ) ;
306
+
307
+ it ( "valid pkcs1 pem" , ( ) => {
308
+ const pk = getPrivateKeyPem ( "./test/res/keys/pkcs1/test_key.pem" ) ;
309
+ assert . ok ( pk ) ;
310
+ } ) ;
311
+
312
+ it ( "not valid key" , ( ) => {
313
+ assert . throws ( ( ) => {
314
+ getPrivateKeyPem ( "./test/res/empty.key" ) ;
315
+ } , / p e m k e y s t o r e c o n t e n t i s e m p t y / ) ;
316
+ } ) ;
317
+ } ) ;
318
+
319
+ describe ( "#getPrivateKeyDer" , ( ) => {
320
+ const getPrivateKeyDer = Crypto . __get__ ( "getPrivateKeyDer" ) ;
321
+
322
+ it ( "valid pkcs8 der" , ( ) => {
323
+ const pk = getPrivateKeyDer ( "./test/res/keys/pkcs8/test_key.der" ) ;
324
+ assert . ok ( pk ) ;
325
+ } ) ;
326
+
327
+ it ( "not valid key" , ( ) => {
328
+ assert . throws ( ( ) => {
329
+ getPrivateKeyDer ( "./test/res/empty.key" ) ;
330
+ } , / d e r k e y s t o r e c o n t e n t i s e m p t y / ) ;
331
+ } ) ;
332
+
333
+ } )
269
334
270
- describe ( "#newEncryptionParams" , ( ) => {
335
+ describe ( "#newEncryptionParams" , ( ) => {
271
336
let crypto ;
272
337
before ( ( ) => {
273
338
crypto = new Crypto ( testConfig ) ;
0 commit comments