@@ -8,110 +8,55 @@ var xpath = require('xpath');
8
8
9
9
describe ( 'encrypt' , function ( ) {
10
10
11
- it ( 'should encrypt and decrypt xml (aes256-cbc)' , function ( done ) {
12
- // cert created with:
13
- // openssl req -x509 -new -newkey rsa:2048 -nodes -subj '/CN=auth0.auth0.com/O=Auth0 LLC/C=US/ST=Washington/L=Redmond' -keyout auth0.key -out auth0.pem
14
- // pub key extracted from (only the RSA public key between BEGIN PUBLIC KEY and END PUBLIC KEY)
15
- // openssl x509 -in "test-auth0.pem" -pubkey
16
-
17
- var options = {
18
- rsa_pub : fs . readFileSync ( __dirname + '/test-auth0_rsa.pub' ) ,
19
- pem : fs . readFileSync ( __dirname + '/test-auth0.pem' ) ,
20
- key : fs . readFileSync ( __dirname + '/test-auth0.key' ) ,
11
+ var algorithms = [ {
12
+ name : 'aes-256-cbc' ,
13
+ encryptionOptions : {
21
14
encryptionAlgorithm : 'http://www.w3.org/2001/04/xmlenc#aes256-cbc' ,
22
15
keyEncryptionAlgorighm : 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p'
23
- } ;
24
-
25
- xmlenc . encrypt ( 'content to encrypt' , options , function ( err , result ) {
26
- xmlenc . decrypt ( result , { key : fs . readFileSync ( __dirname + '/test-auth0.key' ) } , function ( err , decrypted ) {
27
- assert . equal ( decrypted , 'content to encrypt' ) ;
28
- done ( ) ;
29
- } ) ;
30
- } ) ;
31
- } ) ;
32
-
33
- it ( 'should encrypt and decrypt xml (aes256-cbc with utf8 chars)' , function ( done ) {
34
- // cert created with:
35
- // openssl req -x509 -new -newkey rsa:2048 -nodes -subj '/CN=auth0.auth0.com/O=Auth0 LLC/C=US/ST=Washington/L=Redmond' -keyout auth0.key -out auth0.pem
36
- // pub key extracted from (only the RSA public key between BEGIN PUBLIC KEY and END PUBLIC KEY)
37
- // openssl x509 -in "test-auth0.pem" -pubkey
38
-
39
- var options = {
40
- rsa_pub : fs . readFileSync ( __dirname + '/test-auth0_rsa.pub' ) ,
41
- pem : fs . readFileSync ( __dirname + '/test-auth0.pem' ) ,
42
- key : fs . readFileSync ( __dirname + '/test-auth0.key' ) ,
43
- encryptionAlgorithm : 'http://www.w3.org/2001/04/xmlenc#aes256-cbc' ,
44
- keyEncryptionAlgorighm : 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p'
45
- } ;
46
-
47
- xmlenc . encrypt ( 'Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge' , options , function ( err , result ) {
48
- xmlenc . decrypt ( result , { key : fs . readFileSync ( __dirname + '/test-auth0.key' ) } , function ( err , decrypted ) {
49
- assert . equal ( decrypted , 'Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge' ) ;
50
- done ( ) ;
51
- } ) ;
52
- } ) ;
53
- } ) ;
54
-
55
- it ( 'should encrypt and decrypt xml (aes128-cbc) with utf8 chars' , function ( done ) {
56
- // cert created with:
57
- // openssl req -x509 -new -newkey rsa:2048 -nodes -subj '/CN=auth0.auth0.com/O=Auth0 LLC/C=US/ST=Washington/L=Redmond' -keyout auth0.key -out auth0.pem
58
- // pub key extracted from (only the RSA public key between BEGIN PUBLIC KEY and END PUBLIC KEY)
59
- // openssl x509 -in "test-auth0.pem" -pubkey
60
-
61
- var options = {
62
- rsa_pub : fs . readFileSync ( __dirname + '/test-auth0_rsa.pub' ) ,
63
- pem : fs . readFileSync ( __dirname + '/test-auth0.pem' ) ,
64
- key : fs . readFileSync ( __dirname + '/test-auth0.key' ) ,
16
+ }
17
+ } , {
18
+ name : 'aes-128-cbc' ,
19
+ encryptionOptions : {
65
20
encryptionAlgorithm : 'http://www.w3.org/2001/04/xmlenc#aes128-cbc' ,
66
21
keyEncryptionAlgorighm : 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p'
67
- } ;
22
+ }
23
+ } , {
24
+ name : 'des-ede3-cbc' ,
25
+ encryptionOptions : {
26
+ encryptionAlgorithm : 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc' ,
27
+ keyEncryptionAlgorighm : 'http://www.w3.org/2001/04/xmlenc#rsa-1_5'
28
+ }
29
+ } ] ;
68
30
69
- xmlenc . encrypt ( 'Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge' , options , function ( err , result ) {
70
- xmlenc . decrypt ( result , { key : fs . readFileSync ( __dirname + '/test-auth0.key' ) } , function ( err , decrypted ) {
71
- assert . equal ( decrypted , 'Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge' ) ;
72
- done ( ) ;
31
+ algorithms . forEach ( function ( algorithm ) {
32
+ describe ( algorithm . name , function ( ) {
33
+ it ( 'should encrypt and decrypt xml' , function ( done ) {
34
+ _shouldEncryptAndDecrypt ( 'content to encrypt' , algorithm . encryptionOptions , done ) ;
73
35
} ) ;
74
- } ) ;
75
- } ) ;
76
-
77
- it ( 'should encrypt and decrypt xml (aes128-cbc)' , function ( done ) {
78
- var options = {
79
- rsa_pub : fs . readFileSync ( __dirname + '/test-auth0_rsa.pub' ) ,
80
- pem : fs . readFileSync ( __dirname + '/test-auth0.pem' ) ,
81
- key : fs . readFileSync ( __dirname + '/test-auth0.key' ) ,
82
- encryptionAlgorithm : 'http://www.w3.org/2001/04/xmlenc#aes128-cbc' ,
83
- keyEncryptionAlgorighm : 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p'
84
- } ;
85
36
86
- xmlenc . encrypt ( 'content to encrypt' , options , function ( err , result ) {
87
- xmlenc . decrypt ( result , { key : fs . readFileSync ( __dirname + '/test-auth0.key' ) } , function ( err , decrypted ) {
88
- assert . equal ( decrypted , 'content to encrypt' ) ;
89
- done ( ) ;
37
+ it ( 'should encrypt and decrypt xml with utf8 chars' , function ( done ) {
38
+ _shouldEncryptAndDecrypt ( 'Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge Gnügge' , algorithm . encryptionOptions , done ) ;
90
39
} ) ;
91
40
} ) ;
92
41
} ) ;
93
42
94
- it ( 'should encrypt and decrypt xml (encryption: http://www.w3.org/2001/04/xmlenc#tripledes-cbc, keyEncryption: http://www.w3.org/2001/04/xmlenc#rsa-1_5)' , function ( done ) {
43
+ function _shouldEncryptAndDecrypt ( content , options , done ) {
95
44
// cert created with:
96
45
// openssl req -x509 -new -newkey rsa:2048 -nodes -subj '/CN=auth0.auth0.com/O=Auth0 LLC/C=US/ST=Washington/L=Redmond' -keyout auth0.key -out auth0.pem
97
46
// pub key extracted from (only the RSA public key between BEGIN PUBLIC KEY and END PUBLIC KEY)
98
- // openssl x509 -in "test-auth0.pem" -pubkey
47
+ // openssl x509 -in "test-auth0.pem" -pubkey
99
48
100
- var options = {
101
- rsa_pub : fs . readFileSync ( __dirname + '/test-auth0_rsa.pub' ) ,
102
- pem : fs . readFileSync ( __dirname + '/test-auth0.pem' ) ,
103
- key : fs . readFileSync ( __dirname + '/test-auth0.key' ) ,
104
- encryptionAlgorithm : 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc' ,
105
- keyEncryptionAlgorighm : 'http://www.w3.org/2001/04/xmlenc#rsa-1_5'
106
- } ;
49
+ options . rsa_pub = fs . readFileSync ( __dirname + '/test-auth0_rsa.pub' ) ,
50
+ options . pem = fs . readFileSync ( __dirname + '/test-auth0.pem' ) ,
51
+ options . key = fs . readFileSync ( __dirname + '/test-auth0.key' ) ,
107
52
108
- xmlenc . encrypt ( ' content to encrypt' , options , function ( err , result ) {
109
- xmlenc . decrypt ( result , { key : fs . readFileSync ( __dirname + '/test-auth0.key' ) } , function ( err , decrypted ) {
110
- assert . equal ( decrypted , ' content to encrypt' ) ;
53
+ xmlenc . encrypt ( content , options , function ( err , result ) {
54
+ xmlenc . decrypt ( result , { key : fs . readFileSync ( __dirname + '/test-auth0.key' ) } , function ( err , decrypted ) {
55
+ assert . equal ( decrypted , content ) ;
111
56
done ( ) ;
112
57
} ) ;
113
58
} ) ;
114
- } ) ;
59
+ }
115
60
116
61
it ( 'should encrypt and decrypt keyinfo' , function ( done ) {
117
62
var options = {
@@ -122,7 +67,7 @@ describe('encrypt', function() {
122
67
123
68
crypto . randomBytes ( 32 , function ( err , randomBytes ) {
124
69
if ( err ) return done ( err ) ;
125
- xmlenc . encryptKeyInfo ( randomBytes , options , function ( err , result ) {
70
+ xmlenc . encryptKeyInfo ( randomBytes , options , function ( err , result ) {
126
71
if ( err ) return done ( err ) ;
127
72
var decryptedRandomBytes = xmlenc . decryptKeyInfo ( result , { key : fs . readFileSync ( __dirname + '/test-auth0.key' ) } ) ;
128
73
0 commit comments