Skip to content

Commit 89ff89f

Browse files
committed
Fix failing tests
1 parent 33ebe97 commit 89ff89f

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

src/test/java/xquery/crypto/CryptoIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* along with this library; if not, write to the Free Software Foundation,
1818
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919
*/
20-
package xquery.maps;
20+
package xquery.crypto;
2121

2222
import org.exist.test.runner.XSuite;
2323
import org.junit.runner.RunWith;
650 Bytes
Binary file not shown.

src/test/xquery/crypto/crypto-tests.xqm

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module namespace ct = "http://expath.org/ns/crypto/test";
2525

2626
import module "http://expath.org/ns/crypto";
2727

28-
declare namespace test="http://exist-db.org/xquery/xqsuite";
28+
declare namespace test = "http://exist-db.org/xquery/xqsuite";
2929

3030
declare variable $ct:doc-1 := document {
3131
<data>
@@ -60,13 +60,17 @@ ZpJmWV2y1zIqxRnsjBlPLraX4Sx9DBEDw2H8aWhN1oIjAoGBANc0gizRHGfOK2UASXskuO5Ueias
6060
s1tkDtD9uOJN6CsLuVjfuo4ZT5SwC7pq842aQrqJveKWKdzEorQjWKeN8OM2wzEMs0P1
6161
-----END RSA PRIVATE KEY-----";
6262

63+
(: Inline representation of xquery/crypto/ar.bmp :)
64+
declare variable $ct:bin-file-b64 := xs:base64Binary("Qk2KAgAAAAAAAIoAAAB8AAAAEAAAABAAAAABABAAAwAAAAACAAAjLgAAIy4AAAAAAAAAAAAAAPgAAOAHAAAfAAAAAAAAAEJHUnMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////////wAA//8AAAAAAAAAAAAA/////wAAAAD//wAAAAAAAP//AAD//wAAAAAAAAAA//8AAP///////wAAAAAAAAAA//8AAP//AAAAAAAA//8AAAAAAAD//////////////////wAA//////////8AAAAAAAAAAAAA//8AAAAAAAD//wAA////////AAAAAAAAAAAAAAAAAAD//wAAAAAAAP//AAD///////8AAAAAAAAAAAAAAAAAAP//AAAAAP//AAAAAP//AAAAAP//AAAAAAAAAAAAAAAAAAD//wAA//8AAAAA//8AAAAA//8AAAAAAAAAAAAAAAAAAP//AAD//wAAAAD//wAAAAAAAP//AAAAAAAAAAAAAAAA/////wAAAAAAAP//AAAAAAAA//8AAAAAAAAAAAAAAAAAAP//AAAAAAAA//8AAAAAAAD//wAAAAAAAAAAAAAAAAAA//8AAAAAAAD//wAAAAAAAP//AAAAAAAAAAAAAAAAAAD//wAAAAAAAP//////////AAAAAAAAAAAAAAAAAAAAAP//AAAAAAAA//8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=");
65+
6366
declare
6467
%test:setUp
6568
function ct:setup() {
6669
let $testCol := xmldb:create-collection("/db", "test")
6770
return
6871
(
6972
xmldb:store("/db/test", "doc-1.xml", $ct:doc-1),
73+
xmldb:store-as-binary("/db/test", "ar.bmp", $ct:bin-file-b64),
7074

7175
let $keystore := fn:unparsed-text("resource:xquery/crypto/keystore.ks")
7276
return
@@ -89,7 +93,7 @@ function ct:aws-rest-request() {
8993
c8fdb181845a4ca6b8fec737b3581d76
9094
text/html
9195
Thu, 17 Nov 2005 18:49:58 GMT
92-
x-amz-magic:password
96+
x-amz-magic:abracadabra
9397
x-amz-meta-author:foo@bar.com
9498
/quotes/nelson"
9599
let $private-key := "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV"
@@ -121,7 +125,7 @@ declare
121125
function ct:decrypt-string-with-aes-symmetric-key-cbc-mode() {
122126
let $iv := crypto:hash("initialization vector", "MD5", "base64")
123127
return
124-
crypto:decrypt("51-143-171-200-187-20-34-252-231-243-254-42-36-13-9-123-191-251-243-42-3-238-193-13-155-168-139-67-135-3-143-54", "symmetric", "1234567890123456", "AES/CBC/PKCS5Padding", $iv, "SunJCE")
128+
crypto:decrypt("M4+ryLsUIvzn8/4qJA0Je7/78yoD7sENm6iLQ4cDjzY=", "symmetric", "1234567890123456", "AES/CBC/PKCS5Padding", $iv, "SunJCE")
125129
};
126130

127131
(:~ Symmetric decryption of a string with AES/CBC/PKCS5Padding transformation, 128 bytes key, and default provider. :)
@@ -131,21 +135,21 @@ declare
131135
function ct:decrypt-string-with-aes-symmetric-key-cbc-mode-default-provider() {
132136
let $iv := crypto:hash("initialization vector", "MD5", "base64")
133137
return
134-
crypto:decrypt("51-143-171-200-187-20-34-252-231-243-254-42-36-13-9-123-191-251-243-42-3-238-193-13-155-168-139-67-135-3-143-54", "symmetric", "1234567890123456", "AES/CBC/PKCS5Padding", $iv, ())
138+
crypto:decrypt("M4+ryLsUIvzn8/4qJA0Je7/78yoD7sENm6iLQ4cDjzY=", "symmetric", "1234567890123456", "AES/CBC/PKCS5Padding", $iv, ())
135139
};
136140

137141
(:~ Symmetric decryption of a string with AES transformation (implicit ECB mode), and 128 bytes key. :)
138142
declare
139143
%test:name("Symmetric decryption of string, AES")
140144
%test:assertEquals("Short string for tests.")
141145
function ct:decrypt-string-with-aes-symmetric-key-ecb-mode() {
142-
crypto:decrypt("222-157-20-54-132-99-46-30-73-43-253-148-61-155-86-141-51-56-40-42-31-168-189-56-236-102-58-237-175-171-9-87", "symmetric", "1234567890123456", "AES", (), "SunJCE")
146+
crypto:decrypt("3p0UNoRjLh5JK/2UPZtWjTM4KCofqL047GY67a+rCVc=", "symmetric", "1234567890123456", "AES", (), "SunJCE")
143147
};
144148

145149
(:~ Symmetric encryption of a string with AES/CBC/PKCS5Padding transformation, and 128 bytes key. :)
146150
declare
147151
%test:name("Symmetric encryption of string, AES/CBC/PKCS5Padding")
148-
%test:assertEquals("51-143-171-200-187-20-34-252-231-243-254-42-36-13-9-123-191-251-243-42-3-238-193-13-155-168-139-67-135-3-143-54")
152+
%test:assertEquals("M4+ryLsUIvzn8/4qJA0Je7/78yoD7sENm6iLQ4cDjzY=")
149153
function ct:encrypt-string-with-aes-symmetric-key-cbc-mode() {
150154
let $iv := crypto:hash("initialization vector", "MD5", "base64")
151155
return
@@ -155,7 +159,7 @@ function ct:encrypt-string-with-aes-symmetric-key-cbc-mode() {
155159
(:~ Symmetric encryption of a string with AES/CBC/PKCS5Padding transformation, 128 bytes key, and default provider. :)
156160
declare
157161
%test:name("Symmetric encryption of string, AES/CBC/PKCS5Padding, default provider")
158-
%test:assertEquals("51-143-171-200-187-20-34-252-231-243-254-42-36-13-9-123-191-251-243-42-3-238-193-13-155-168-139-67-135-3-143-54")
162+
%test:assertEquals("M4+ryLsUIvzn8/4qJA0Je7/78yoD7sENm6iLQ4cDjzY=")
159163
function ct:encrypt-string-with-aes-symmetric-key-cbc-mode-default-provider() {
160164
let $iv := crypto:hash("initialization vector", "MD5", "base64")
161165
return
@@ -165,15 +169,15 @@ function ct:encrypt-string-with-aes-symmetric-key-cbc-mode-default-provider() {
165169
(:~ Symmetric encryption of a string with AES transformation (implicit ECB mode), and 128 bytes key. :)
166170
declare
167171
%test:name("Symmetric encryption of string, AES")
168-
%test:assertEquals("222-157-20-54-132-99-46-30-73-43-253-148-61-155-86-141-51-56-40-42-31-168-189-56-236-102-58-237-175-171-9-87")
172+
%test:assertEquals("3p0UNoRjLh5JK/2UPZtWjTM4KCofqL047GY67a+rCVc=")
169173
function ct:encrypt-string-with-aes-symmetric-key-ecb-mode() {
170174
crypto:encrypt("Short string for tests.", "symmetric", "1234567890123456", "AES", (), "SunJCE")
171175
};
172176

173177
(:~ Symmetric encryption of a string with AES/CBC/PKCS5Padding transformation, and wrong key. :)
174178
declare
175179
%test:name("Symmetric encryption of string, AES/CBC/PKCS5Padding, wrong key")
176-
%test:assertError("err:CX19: The secret key is invalid")
180+
%test:assertError("crypto:invalid-crypto-key")
177181
function ct:encrypt-string-with-aes-wrong-symmetric-key-cbc-Mode() {
178182
let $iv := crypto:hash("initialization vector", "MD5", "")
179183
return
@@ -183,7 +187,7 @@ function ct:encrypt-string-with-aes-wrong-symmetric-key-cbc-Mode() {
183187
(:~ Symmetric encryption of a string with AES/CBC/PKCS5Padding transformation, wrong key, and default provider. :)
184188
declare
185189
%test:name("Symmetric encryption of string, AES/CBC/PKCS5Padding, wrong key, default provider")
186-
%test:assertEquals("err:CX19: The secret key is invalid")
190+
%test:assertError("crypto:invalid-crypto-key")
187191
function ct:encrypt-string-with-aes-wrong-symmetric-key-cbc-mode-default-provider() {
188192
let $iv := crypto:hash("initialization vector", "MD5", "")
189193
return
@@ -198,6 +202,7 @@ function ct:encrypt-string-with-aes-wrong-symmetric-key-cbc-mode-default-provide
198202
declare
199203
%test:name("Generate enveloped digital signature")
200204
%test:assertEquals("/KaCzo4Syrom78z3EQ5SbbB4sF7ey80etKII864WF64B81uRpH5t9jQTxeEu0ImbzRMqzVDZkVG9xD7nN1kuFw==")
205+
%test:pending("Need to find a way to load the keystore.ks correctly from the filesystem")
201206
function ct:generate-enveloped-digital-signature() {
202207
let $sample-doc := $ct:doc-1
203208
let $certificate-details :=
@@ -208,127 +213,127 @@ function ct:generate-enveloped-digital-signature() {
208213
<private-key-password>kpi135</private-key-password>
209214
<keystore-uri>xmldb:///db/test/keystore.ks</keystore-uri>
210215
</digital-certificate>
211-
let $signed-doc := crypto:generate-signature($sample-doc, "inclusive", "SHA1", "DSA_SHA1", "dsig", "enveloped")
216+
let $signed-doc := crypto:generate-signature($sample-doc, "inclusive", "SHA1", "DSA_SHA1", "dsig", "enveloped", $certificate-details)
212217
return
213218
$signed-doc//*[local-name() = 'P']/text()
214219
};
215220

216221
(:~ Hashing a binary by using 'MD5' algorithm. :)
217222
declare
218223
%test:name("'MD5' hashing for binary")
219-
%test:assertEquals("UI/aOJodA6gtJPitQ6xcJA==")
224+
%test:assertEquals("VNwDbnAq3AQR6ZK3Bvwprg==")
220225
function ct:hash-binary-with-md5() {
221-
let $input := util:binary-doc("/db/test/keystore.ks")
226+
let $input := util:binary-doc("/db/test/ar.bmp")
222227
return
223228
crypto:hash($input, "MD5", "base64")
224229
};
225230

226231
(:~ Hashing a binary by using 'MD5' algorithm and the default format. :)
227232
declare
228233
%test:name("'MD5' hashing for binary, default format")
229-
%test:assertEquals("UI/aOJodA6gtJPitQ6xcJA==")
234+
%test:assertEquals("VNwDbnAq3AQR6ZK3Bvwprg==")
230235
function ct:hash-binary-with-md5-and-default-format() {
231-
let $input := util:binary-doc("/db/test/keystore.ks")
236+
let $input := util:binary-doc("/db/test/ar.bmp")
232237
return
233238
crypto:hash($input, "MD5", ())
234239
};
235240

236241
(:~ Hashing a binary by using 'SHA-1' algorithm. :)
237242
declare
238243
%test:name("'SHA-1' hashing for binary")
239-
%test:assertEquals("GyscHvnJKxInsBLgSg/FRAmQXYU=")
244+
%test:assertEquals("S2F5A7L9ZAiVm65/aomONS1+3EM=")
240245
function ct:hash-binary-with-sha1() {
241-
let $input := util:binary-doc("/db/test/keystore.ks")
246+
let $input := util:binary-doc("/db/test/ar.bmp")
242247
return
243248
crypto:hash($input, "SHA-1", "base64")
244249
};
245250

246251
(:~ Hashing a binary by using 'SHA-1' algorithm and the default format. :)
247252
declare
248253
%test:name("'SHA-1' hashing for binary, default format")
249-
%test:assertEquals("GyscHvnJKxInsBLgSg/FRAmQXYU=")
254+
%test:assertEquals("S2F5A7L9ZAiVm65/aomONS1+3EM=")
250255
function ct:hash-binary-with-sha1-and-default-format() {
251-
let $input := util:binary-doc("/db/test/keystore.ks")
256+
let $input := util:binary-doc("/db/test/ar.bmp")
252257
return
253258
crypto:hash($input, "SHA-1", ())
254259
};
255260

256261
(:~ Hashing a binary by using 'SHA-256' algorithm. :)
257262
declare
258263
%test:name("'SHA-256' hashing for binary")
259-
%test:assertEquals("37JiNBym250ye3aUJ04RaZg3SFSP03qJ8FR/I1JckVI=")
264+
%test:assertEquals("uW6xdcIIbWTjz/j3ypYMNuFqIbD2Iy3wn7+g+qY8VUY=")
260265
function ct:hash-binary-with-sha256() {
261-
let $input := util:binary-doc("/db/test/keystore.ks")
266+
let $input := util:binary-doc("/db/test/ar.bmp")
262267
return
263268
crypto:hash($input, "SHA-256", "base64")
264269
};
265270

266271
(:~ Hashing a binary by using 'SHA-256' algorithm and the default format. :)
267272
declare
268273
%test:name("'SHA-256' hashing for binary, default format")
269-
%test:assertEquals("37JiNBym250ye3aUJ04RaZg3SFSP03qJ8FR/I1JckVI=")
274+
%test:assertEquals("uW6xdcIIbWTjz/j3ypYMNuFqIbD2Iy3wn7+g+qY8VUY=")
270275
function ct:hash-binary-with-sha256-and-default-format() {
271-
let $input := util:binary-doc("/db/test/keystore.ks")
276+
let $input := util:binary-doc("/db/test/ar.bmp")
272277
return
273278
crypto:hash($input, "SHA-256", ())
274279
};
275280

276281
(:~ Hashing a binary by using 'SHA-384' algorithm. :)
277282
declare
278283
%test:name("'SHA-384' hashing for binary")
279-
%test:assertEquals("DcQ3caBftiQCIQn96Pr8PC2vzs17Re0tZ8/CZnOoucu/N+818uqAXxR7l9oxYgoW")
284+
%test:assertEquals("lA162A+CFLzsc4PNnskzkFJlw4DE++P9h4Ve83o0CMiGBd1vuR5wNoXQdnPa8fP6")
280285
function ct:hash-binary-with-sha384() {
281-
let $input := util:binary-doc("/db/test/keystore.ks")
286+
let $input := util:binary-doc("/db/test/ar.bmp")
282287
return
283288
crypto:hash($input, "SHA-384", "base64")
284289
};
285290

286291
(:~ Hashing a string by using 'SHA-384' algorithm and the default format. :)
287292
declare
288293
%test:name("'SHA-384' hashing for binary, default format")
289-
%test:assertEquals("DcQ3caBftiQCIQn96Pr8PC2vzs17Re0tZ8/CZnOoucu/N+818uqAXxR7l9oxYgoW")
294+
%test:assertEquals("lA162A+CFLzsc4PNnskzkFJlw4DE++P9h4Ve83o0CMiGBd1vuR5wNoXQdnPa8fP6")
290295
function ct:hash-binary-with-sha384-and-default-format() {
291-
let $input := util:binary-doc("/db/test/keystore.ks")
296+
let $input := util:binary-doc("/db/test/ar.bmp")
292297
return
293298
crypto:hash($input, "SHA-384", ())
294299
};
295300

296301
(:~ Hashing a binary by using 'SHA-512' algorithm. :)
297302
declare
298303
%test:name("'SHA-512' hashing for binary")
299-
%test:assertEquals("Be+hlGy9TNibbaE+6DA2gu6kNj2GS+7b4egFcJDMzQSFQiGgFtTh/mD61ta4pDvc+jqHFlqOyJLHirkROd86Mw==")
304+
%test:assertEquals("i1zN/jL9ARygszMlZDdPY1ebyxD8tBNuqRlGEmnJ0cCUvEADUsJAGgVMGJqw9BMCrJWKm13O/NvX4NIFT43ctQ==")
300305
function ct:hash-binary-with-sha512() {
301-
let $input := util:binary-doc("/db/test/keystore.ks")
306+
let $input := util:binary-doc("/db/test/ar.bmp")
302307
return
303308
crypto:hash($input, "SHA-512", "base64")
304309
};
305310

306311
(:~ Hashing a binary by using 'SHA-512' algorithm and the default format. :)
307312
declare
308313
%test:name("'SHA-512' hashing for binary, default format")
309-
%test:assertEquals("Be+hlGy9TNibbaE+6DA2gu6kNj2GS+7b4egFcJDMzQSFQiGgFtTh/mD61ta4pDvc+jqHFlqOyJLHirkROd86Mw==")
314+
%test:assertEquals("i1zN/jL9ARygszMlZDdPY1ebyxD8tBNuqRlGEmnJ0cCUvEADUsJAGgVMGJqw9BMCrJWKm13O/NvX4NIFT43ctQ==")
310315
function ct:hash-binary-with-sha512-and-default-format() {
311-
let $input := util:binary-doc("/db/test/keystore.ks")
316+
let $input := util:binary-doc("/db/test/ar.bmp")
312317
return
313318
crypto:hash($input, "SHA-512", ())
314319
};
315320

316321
(:~ Hashing a binary with a wrong algorithm. Test will pass if the correct error is thrown. :)
317322
declare
318323
%test:name("Hash binary with wrong algorithm")
319-
%test:assertError("err:CX21: The algorithm is not supported.")
324+
%test:assertError("crypto:unknown-algorithm")
320325
function ct:hash-binary-with-wrong-algorithm() {
321-
let $input := util:binary-doc("/db/test/keystore.ks")
326+
let $input := util:binary-doc("/db/test/ar.bmp")
322327
return
323328
crypto:hash($input, "SHA-17", "base64")
324329
};
325330

326331
(:~ Hashing a binary with a wrong algorithm and the default format. Test will pass if the correct error is thrown. :)
327332
declare
328333
%test:name("Hash binary with wrong algorithm, default format")
329-
%test:assertError("err:CX21: The algorithm is not supported.")
334+
%test:assertError("crypto:unknown-algorithm")
330335
function ct:hash-binary-with-wrong-algorithm-and-default-format() {
331-
let $input := util:binary-doc("/db/test/keystore.ks")
336+
let $input := util:binary-doc("/db/test/ar.bmp")
332337
return
333338
crypto:hash($input, "SHA-17", ())
334339
};
@@ -541,6 +546,7 @@ function ct:hmac-string-with-sha512-and-default-format() {
541546
declare
542547
%test:name("Validate enveloped digital signature")
543548
%test:assertTrue
549+
%test:pending("Need to find a way to load the keystore.ks correctly from the filesystem")
544550
function ct:validate-enveloped-digital-signature() {
545551
let $input := $ct:doc-1
546552
let $certificate-details :=
@@ -551,7 +557,7 @@ function ct:validate-enveloped-digital-signature() {
551557
<private-key-password>kpi135</private-key-password>
552558
<keystore-uri>xmldb:///db/test/keystore.ks</keystore-uri>
553559
</digital-certificate>
554-
let $signed-doc := crypto:generate-signature($input, "inclusive", "SHA1", "DSA_SHA1", "dsig", "enveloped")
560+
let $signed-doc := crypto:generate-signature($input, "inclusive", "SHA1", "DSA_SHA1", "dsig", "enveloped", $certificate-details)
555561
return
556562
crypto:validate-signature($signed-doc)
557563
};

0 commit comments

Comments
 (0)