packages
The Louise packages, each released on its own
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#28 · main · 3 min 34 s
0Étoiles
0Forks
3Issues
| 1 | // The SCRAM-SHA-256 exchange against RFC 7677's recorded one (password |
| 2 | // "pencil"), plus the failure modes. |
| 3 | |
| 4 | import scram |
| 5 | import std/bytes |
| 6 | import std/test.{assert, assert_equal} |
| 7 | |
| 8 | @test |
| 9 | fn the_rfcs_exchange :: |
| 10 | { |
| 11 | // RFC 7677's exchange (password "pencil"), with PostgreSQL's |
| 12 | // convention of an empty `n=` (the user goes in the startup message, |
| 13 | // as libpq does): the expected values below are the RFC's exchange |
| 14 | // adjusted for that, computed independently with Python's hashlib. |
| 15 | // (With `n=user` instead, the proof is the RFC's own |
| 16 | // `p=dHzbZapWIk4jUhN+Ute9ytag9zjfMHgsqmmiz7AndVQ=`.) |
| 17 | let (state, first) = scram.client_first "rOprNGfwEbeRWgbNEkqO" |
| 18 | assert_equal (debug_bytes first) "n,,n=,r=rOprNGfwEbeRWgbNEkqO" |
| 19 | match scram.client_final |
| 20 | state |
| 21 | "pencil" |
| 22 | "r=rOprNGfwEbeRWgbNEkqO%hvYDpWUa2RaTCAfuxFIlj)hNlF$k0,s=W22ZaJ0SNY7soEsUEjb6gQ==,i=4096" |
| 23 | { Ok((state, reply)) -> |
| 24 | { |
| 25 | assert_equal |
| 26 | reply |
| 27 | "c=biws,r=rOprNGfwEbeRWgbNEkqO%hvYDpWUa2RaTCAfuxFIlj)hNlF$k0,p=qvT2SWdEH5Q06albL+hjSYuUhCG7VndFyzIb7CK4n9k=" |
| 28 | assert_equal |
| 29 | ( scram.verify_server |
| 30 | state |
| 31 | "v=3HO6Qt1M4MKJrmlKaoOqLAI0/0TV0HZe7J9H3MBtSOg=" |
| 32 | ) |
| 33 | Ok(()) |
| 34 | } |
| 35 | , Error(e) -> panic e |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | @test |
| 40 | fn a_server_nonce_that_does_not_extend_ours_is_rejected :: |
| 41 | { |
| 42 | let (state, _) = scram.client_first "clientnonce" |
| 43 | match scram.client_final |
| 44 | state |
| 45 | "pencil" |
| 46 | "r=other,s=W22ZaJ0SNY7soEsUEjb6gQ==,i=4096" |
| 47 | { Error(_) -> (), Ok(_) -> panic "a nonce not extending ours must fail" } |
| 48 | } |
| 49 | |
| 50 | @test |
| 51 | fn a_wrong_server_signature_is_rejected :: |
| 52 | { |
| 53 | let (state, _) = scram.client_first "rOprNGfwEbeRWgbNEkqO" |
| 54 | match scram.client_final |
| 55 | state |
| 56 | "pencil" |
| 57 | "r=rOprNGfwEbeRWgbNEkqO%hvYDpWUa2RaTCAfuxFIlj)hNlF$k0,s=W22ZaJ0SNY7soEsUEjb6gQ==,i=4096" |
| 58 | { Ok |
| 59 | ( (state, _) |
| 60 | ) -> match scram.verify_server |
| 61 | state |
| 62 | "v=AAAATRBi23WpRR/wtup+mMhUZUn/dB5nLTJRsjl95u4=" |
| 63 | { Error(_) -> (), Ok(()) -> panic "a wrong server signature must fail" } |
| 64 | , Error(e) -> panic e |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | fn debug_bytes :: b: Bytes -> String |
| 69 | { |
| 70 | match bytes.to_string b { Ok(s) -> s, Error(e) -> panic e } |
| 71 | } |