|
1 | | -CREATE EXTENSION pg_pwhash; |
2 | | --- |
3 | | --- Try settings for pg_pwhash.argon2_default_backend |
4 | | --- |
5 | | --- should fail |
6 | | -SET pg_pwhash.argon2_default_backend = 'blabla'; |
7 | | -ERROR: invalid value for parameter "pg_pwhash.argon2_default_backend": "blabla" |
8 | | -HINT: Available values: openssl, libargon2. |
9 | | --- should succeed |
10 | | -SET pg_pwhash.argon2_default_backend = 'openssl'; |
11 | | -SHOW pg_pwhash.argon2_default_backend; |
12 | | - pg_pwhash.argon2_default_backend |
13 | | ----------------------------------- |
14 | | - openssl |
15 | | -(1 row) |
16 | | - |
17 | | -SET pg_pwhash.argon2_default_backend = 'libargon2'; |
18 | | -SHOW pg_pwhash.argon2_default_backend; |
19 | | - pg_pwhash.argon2_default_backend |
20 | | ----------------------------------- |
21 | | - libargon2 |
22 | | -(1 row) |
23 | | - |
24 | | --- back to default |
25 | | -RESET pg_pwhash.argon2_default_backend; |
26 | | -SHOW pg_pwhash.argon2_default_backend; |
27 | | - pg_pwhash.argon2_default_backend |
28 | | ----------------------------------- |
29 | | - libargon2 |
30 | | -(1 row) |
31 | | - |
32 | 1 | -- |
33 | 2 | -- Tests for argon2id |
34 | 3 | -- |
@@ -349,191 +318,3 @@ SELECT hash = pwhash_argon2(pw, salt) FROM pwhash_test_argon2; |
349 | 318 |
|
350 | 319 | RESET pg_pwhash.argon2_default_backend; |
351 | 320 | DROP TABLE pwhash_test_argon2; |
352 | | --- |
353 | | --- Checks for scrypt |
354 | | --- |
355 | | --- The hashes we compare here are derived via python's passlib again |
356 | | --- |
357 | | --- h = scrypt.using(salt=bytes("12345678", "utf-8")).hash("password") |
358 | | --- |
359 | | -SELECT pwhash_scrypt('password', '$scrypt$ln=16,r=8,p=1$MTIzNDU2Nzg$NuB+vs2zc0fb2UzIRwwAV6ZWb3St8+X9IedYI1gQsoo') = '$scrypt$ln=16,r=8,p=1$MTIzNDU2Nzg$NuB+vs2zc0fb2UzIRwwAV6ZWb3St8+X9IedYI1gQsoo'; |
360 | | -ERROR: this version of pg_pwhash was compiled without libscrypt support |
361 | | --- |
362 | | --- Check if parameters get applied |
363 | | --- |
364 | | --- h = scrypt.using(salt=bytes("12345678", "utf-8")).using=(rounds=8).using(block_size=16).hash("password") |
365 | | --- |
366 | | -SELECT pwhash_scrypt('password', '$scrypt$ln=8,r=16,p=1$MTIzNDU2Nzg$tEmA9TbF8lFDbMySWVfYoEqW2ywo6Qr8vu/sHHwVyDs') = '$scrypt$ln=8,r=16,p=1$MTIzNDU2Nzg$tEmA9TbF8lFDbMySWVfYoEqW2ywo6Qr8vu/sHHwVyDs'; |
367 | | -ERROR: this version of pg_pwhash was compiled without libscrypt support |
368 | | --- |
369 | | --- Check uneven base64 salt (needs padding) and is handled according to pg_pwhash.always_pad_base64 |
370 | | --- |
371 | | --- h = scrypt.using(salt=bytes("123456789", "utf-8")).hash("password") |
372 | | --- |
373 | | -SELECT pwhash_scrypt('password', '$scrypt$ln=16,r=8,p=1$MTIzNDU2Nzg5$owI4pAfxQFH5mayb2BJed7ltHms8Z+M1JEQ/PIvuW84') = '$scrypt$ln=16,r=8,p=1$MTIzNDU2Nzg5$owI4pAfxQFH5mayb2BJed7ltHms8Z+M1JEQ/PIvuW84'; |
374 | | -ERROR: this version of pg_pwhash was compiled without libscrypt support |
375 | | --- |
376 | | --- Check with crypt identifier |
377 | | --- |
378 | | --- Should fail, since scrypt ident is expected |
379 | | -SELECT pwhash_scrypt('password', '$7$ln=16,r=8,p=1$MTIzNDU2Nzg5$owI4pAfxQFH5mayb2BJed7ltHms8Z+M1JEQ/PIvuW84') = '$scrypt$ln=16,r=8,p=1$MTIzNDU2Nzg5$owI4pAfxQFH5mayb2BJed7ltHms8Z+M1JEQ/PIvuW84'; |
380 | | -ERROR: invalid magic byte in salt preamble, expected "$scrypt$" |
381 | | --- Same, but this time with correct identifier |
382 | | -SELECT pwhash_scrypt('password', '$scrypt$ln=16,r=8,p=1$MTIzNDU2Nzg5$owI4pAfxQFH5mayb2BJed7ltHms8Z+M1JEQ/PIvuW84') = '$scrypt$ln=16,r=8,p=1$MTIzNDU2Nzg5$owI4pAfxQFH5mayb2BJed7ltHms8Z+M1JEQ/PIvuW84'; |
383 | | -ERROR: this version of pg_pwhash was compiled without libscrypt support |
384 | | --- Same test, but this time with pg_pwhash.always_pad_base64 set to on (salt and password hash |
385 | | --- should be padded) |
386 | | -SET pg_pwhash.always_pad_base64 TO on; |
387 | | -SELECT pwhash_scrypt('password', '$scrypt$ln=16,r=8,p=1$MTIzNDU=$UrgkUooL3HseyjbLegKgNKz2B/0mlHRg+ZJu6DuXK00=') = '$scrypt$ln=16,r=8,p=1$MTIzNDU=$UrgkUooL3HseyjbLegKgNKz2B/0mlHRg+ZJu6DuXK00='; |
388 | | -ERROR: this version of pg_pwhash was compiled without libscrypt support |
389 | | -SET pg_pwhash.always_pad_base64 TO off; |
390 | | --- should fail, options string not present |
391 | | -SELECT pwhash_scrypt('password', '$scrypt$MTIzNDU=$UrgkUooL3HseyjbLegKgNKz2B/0mlHRg+ZJu6DuXK00'); |
392 | | -ERROR: invalid option name: "MTIzNDU" |
393 | | --- should fail, obscure option specification |
394 | | -SELECT pwhash_scrypt('password', '$scrypt$M$TIzNDU=$UrgkUooL3HseyjbLegKgNKz2B/0mlHRg+ZJu6DuXK00='); |
395 | | -ERROR: bogus option specified in salt |
396 | | --- |
397 | | --- Test crypt() implementation |
398 | | --- |
399 | | --- Should succeed |
400 | | -SELECT pwhash_scrypt_crypt('password', '$7$DU..../....OhzHZvHVazzr5gCG7jotQ0$aehDO6CrqD4ITgsiLqw3EmIYyulY/tZSF9ARYtZN4U/') = '$7$DU..../....OhzHZvHVazzr5gCG7jotQ0$aehDO6CrqD4ITgsiLqw3EmIYyulY/tZSF9ARYtZN4U/'; |
401 | | - ?column? |
402 | | ----------- |
403 | | - t |
404 | | -(1 row) |
405 | | - |
406 | | --- Should fail, obscure salt |
407 | | -SELECT pwhash_scrypt_crypt('password', '$7$abcdefghijkl'); |
408 | | -ERROR: error creating password hash with crypt() |
409 | | -DETAIL: Internal error using crypt(): Invalid argument |
410 | | --- ------------------------------------------------------------------------------------------------- |
411 | | --- Checks for yescrypt hashing |
412 | | --- |
413 | | --- Currently this is supported on platforms with advanced libxcrypt support only (Linux, BSD). |
414 | | --- So checks might fail in case support wasn't available during compilation of the extension |
415 | | --- ------------------------------------------------------------------------------------------------- |
416 | | --- |
417 | | --- Compare hashes derived via test/crypt_gensalt_yescrypt password '$y$jAT$ymqO.hmB133abiOGZqA4f/' |
418 | | --- (parameter rounds=6) |
419 | | --- |
420 | | -SELECT pwhash_yescrypt_crypt('password', '$y$jAT$ymqO.hmB133abiOGZqA4f/') = '$y$jAT$ymqO.hmB133abiOGZqA4f/$ff0GrluBLpVssGRjSIYMUG2E7JWH722mSyalZT3o3E3'; |
421 | | - ?column? |
422 | | ----------- |
423 | | - t |
424 | | -(1 row) |
425 | | - |
426 | | --- Following tests should fail |
427 | | --- Note: We need lc_messages set to C, otherwise we get localized errors from libxcrypt |
428 | | -SET lc_messages TO 'C'; |
429 | | -SELECT pwhash_yescrypt_crypt('password', '$y$'); |
430 | | -ERROR: error creating password hash with crypt() |
431 | | -DETAIL: Internal error using crypt(): Invalid argument |
432 | | -SELECT pwhash_yescrypt_crypt('password', '$y$$'); |
433 | | -ERROR: error creating password hash with crypt() |
434 | | -DETAIL: Internal error using crypt(): Invalid argument |
435 | | -SELECT pwhash_yescrypt_crypt('password', ''); |
436 | | -ERROR: invalid magic string for crypt() |
437 | | -RESET lc_messages; |
438 | | ----------------------------------------------------------- |
439 | | --- Test generating yescrypt hashes with pwhash_gen_salt() |
440 | | ----------------------------------------------------------- |
441 | | -CREATE TABLE pwhash_test_yescrypt(pw text NOT NULL, salt text NOT NULL, hash text); |
442 | | -INSERT INTO pwhash_test_yescrypt(pw, salt) VALUES('password', pwhash_gen_salt('yescrypt', 'rounds=3')); |
443 | | -UPDATE pwhash_test_yescrypt SET hash = pwhash_yescrypt_crypt('password', salt) WHERE pw = 'password'; |
444 | | -SELECT hash = pwhash_yescrypt_crypt(pw, salt) FROM pwhash_test_yescrypt; |
445 | | - ?column? |
446 | | ----------- |
447 | | - t |
448 | | -(1 row) |
449 | | - |
450 | | -DROP TABLE pwhash_test_yescrypt; |
451 | | --- ---------------------------------------------------- |
452 | | --- Test crypt() compatible interface pwhash_crypt() |
453 | | --- ---------------------------------------------------- |
454 | | --- |
455 | | --- scrypt via crypt() |
456 | | --- |
457 | | -SELECT pwhash_crypt('password', '$7$DU..../....OhzHZvHVazzr5gCG7jotQ0$') = '$7$DU..../....OhzHZvHVazzr5gCG7jotQ0$aehDO6CrqD4ITgsiLqw3EmIYyulY/tZSF9ARYtZN4U/' AS hash; |
458 | | - hash |
459 | | ------- |
460 | | - t |
461 | | -(1 row) |
462 | | - |
463 | | --- |
464 | | --- scrypt via libscrypt |
465 | | --- |
466 | | -SELECT pwhash_crypt('password', '$scrypt$ln=16,r=8,p=1$MTIzNDU2Nzg$NuB+vs2zc0fb2UzIRwwAV6ZWb3St8+X9IedYI1gQsoo') = '$scrypt$ln=16,r=8,p=1$MTIzNDU2Nzg$NuB+vs2zc0fb2UzIRwwAV6ZWb3St8+X9IedYI1gQsoo' AS hash; |
467 | | -ERROR: this version of pg_pwhash was compiled without libscrypt support |
468 | | --- |
469 | | --- scrypt via OpenSSL |
470 | | --- |
471 | | -SELECT pwhash_crypt('password', '$scrypt$ln=16,r=8,p=1,backend=openssl$MTIzNDU2Nzg$NuB+vs2zc0fb2UzIRwwAV6ZWb3St8+X9IedYI1gQsoo') = '$scrypt$ln=16,r=8,p=1$MTIzNDU2Nzg$NuB+vs2zc0fb2UzIRwwAV6ZWb3St8+X9IedYI1gQsoo' AS hash; |
472 | | - hash |
473 | | ------- |
474 | | - t |
475 | | -(1 row) |
476 | | - |
477 | | --- |
478 | | --- yescrypt via crypt() |
479 | | --- |
480 | | -SELECT pwhash_crypt('password', '$y$jAT$ymqO.hmB133abiOGZqA4f/') = '$y$jAT$ymqO.hmB133abiOGZqA4f/$ff0GrluBLpVssGRjSIYMUG2E7JWH722mSyalZT3o3E3' AS hash; |
481 | | - hash |
482 | | ------- |
483 | | - t |
484 | | -(1 row) |
485 | | - |
486 | | --- |
487 | | --- Argon2id via libargon2 |
488 | | --- |
489 | | -SELECT pwhash_crypt('password', '$argon2id$v=19$m=65536,t=3,p=4$u9ca4zxn7H0PISSE0HqP8Q$yeN3V5sfotE6xjbD+1oBNXyF6ZkgDAlsrnJvYbOgbY4') = '$argon2id$v=19$m=65536,t=3,p=4$u9ca4zxn7H0PISSE0HqP8Q$yeN3V5sfotE6xjbD+1oBNXyF6ZkgDAlsrnJvYbOgbY4' AS hash; |
490 | | - hash |
491 | | ------- |
492 | | - t |
493 | | -(1 row) |
494 | | - |
495 | | --- |
496 | | --- Argon2id with OpenSSL |
497 | | --- |
498 | | -SELECT pwhash_crypt('password', '$argon2id$v=19$m=65536,t=3,p=4,backend=openssl$u9ca4zxn7H0PISSE0HqP8Q$yeN3V5sfotE6xjbD+1oBNXyF6ZkgDAlsrnJvYbOgbY4') = '$argon2id$v=19$m=65536,t=3,p=4,backend=openssl$u9ca4zxn7H0PISSE0HqP8Q$yeN3V5sfotE6xjbD+1oBNXyF6ZkgDAlsrnJvYbOgbY4' AS hash; |
499 | | - hash |
500 | | ------- |
501 | | - t |
502 | | -(1 row) |
503 | | - |
504 | | --- |
505 | | --- Argon2d with libargon2 |
506 | | --- |
507 | | -SELECT pwhash_crypt('password', '$argon2d$v=19$m=65536,t=3,p=4$MTIzNDU2Nzg$h+HoUsia1leIw6QQtzEFgergF3Ccud96oLEaS0ZOnMU') = '$argon2d$v=19$m=65536,t=3,p=4$MTIzNDU2Nzg$h+HoUsia1leIw6QQtzEFgergF3Ccud96oLEaS0ZOnMU' AS hash; |
508 | | - hash |
509 | | ------- |
510 | | - t |
511 | | -(1 row) |
512 | | - |
513 | | --- |
514 | | --- Argon2d with OpenSSL |
515 | | --- |
516 | | -SELECT pwhash_crypt('password', '$argon2d$v=19$m=65536,t=3,p=4,backend=openssl$MTIzNDU2Nzg$h+HoUsia1leIw6QQtzEFgergF3Ccud96oLEaS0ZOnMU') = '$argon2d$v=19$m=65536,t=3,p=4,backend=openssl$MTIzNDU2Nzg$h+HoUsia1leIw6QQtzEFgergF3Ccud96oLEaS0ZOnMU' AS hash; |
517 | | - hash |
518 | | ------- |
519 | | - t |
520 | | -(1 row) |
521 | | - |
522 | | --- |
523 | | --- Argon2i with libargon2 |
524 | | --- |
525 | | -SELECT pwhash_crypt('password', '$argon2i$v=19$m=65536,t=3,p=4$MTIzNDU2Nzg$BvKUwNCmr7GPzmR+EyZJdBTOWvRPvaz2lNpZgWdAN3A') = '$argon2i$v=19$m=65536,t=3,p=4$MTIzNDU2Nzg$BvKUwNCmr7GPzmR+EyZJdBTOWvRPvaz2lNpZgWdAN3A' AS hash; |
526 | | - hash |
527 | | ------- |
528 | | - t |
529 | | -(1 row) |
530 | | - |
531 | | --- |
532 | | --- Argon2i with OpenSSL |
533 | | --- |
534 | | -SELECT pwhash_crypt('password', '$argon2i$v=19$m=65536,t=3,p=4,backend=openssl$MTIzNDU2Nzg$BvKUwNCmr7GPzmR+EyZJdBTOWvRPvaz2lNpZgWdAN3A') = '$argon2i$v=19$m=65536,t=3,p=4,backend=openssl$MTIzNDU2Nzg$BvKUwNCmr7GPzmR+EyZJdBTOWvRPvaz2lNpZgWdAN3A' AS hash; |
535 | | - hash |
536 | | ------- |
537 | | - t |
538 | | -(1 row) |
539 | | - |
0 commit comments