Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 5 | Cu.import("resource://services-common/utils.js"); |
michael@0 | 6 | Cu.import("resource://services-crypto/utils.js"); |
michael@0 | 7 | |
michael@0 | 8 | function run_test() { |
michael@0 | 9 | initTestLogging(); |
michael@0 | 10 | |
michael@0 | 11 | run_next_test(); |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | add_test(function test_sha1() { |
michael@0 | 15 | _("Ensure HTTP MAC SHA1 generation works as expected."); |
michael@0 | 16 | |
michael@0 | 17 | let id = "vmo1txkttblmn51u2p3zk2xiy16hgvm5ok8qiv1yyi86ffjzy9zj0ez9x6wnvbx7"; |
michael@0 | 18 | let key = "b8u1cc5iiio5o319og7hh8faf2gi5ym4aq0zwf112cv1287an65fudu5zj7zo7dz"; |
michael@0 | 19 | let ts = 1329181221; |
michael@0 | 20 | let method = "GET"; |
michael@0 | 21 | let nonce = "wGX71"; |
michael@0 | 22 | let uri = CommonUtils.makeURI("http://10.250.2.176/alias/"); |
michael@0 | 23 | |
michael@0 | 24 | let result = CryptoUtils.computeHTTPMACSHA1(id, key, method, uri, |
michael@0 | 25 | {ts: ts, nonce: nonce}); |
michael@0 | 26 | |
michael@0 | 27 | do_check_eq(btoa(result.mac), "jzh5chjQc2zFEvLbyHnPdX11Yck="); |
michael@0 | 28 | |
michael@0 | 29 | do_check_eq(result.getHeader(), |
michael@0 | 30 | 'MAC id="vmo1txkttblmn51u2p3zk2xiy16hgvm5ok8qiv1yyi86ffjzy9zj0ez9x6wnvbx7", ' + |
michael@0 | 31 | 'ts="1329181221", nonce="wGX71", mac="jzh5chjQc2zFEvLbyHnPdX11Yck="'); |
michael@0 | 32 | |
michael@0 | 33 | let ext = "EXTRA DATA; foo,bar=1"; |
michael@0 | 34 | |
michael@0 | 35 | let result = CryptoUtils.computeHTTPMACSHA1(id, key, method, uri, |
michael@0 | 36 | {ts: ts, nonce: nonce, ext: ext}); |
michael@0 | 37 | do_check_eq(btoa(result.mac), "bNf4Fnt5k6DnhmyipLPkuZroH68="); |
michael@0 | 38 | do_check_eq(result.getHeader(), |
michael@0 | 39 | 'MAC id="vmo1txkttblmn51u2p3zk2xiy16hgvm5ok8qiv1yyi86ffjzy9zj0ez9x6wnvbx7", ' + |
michael@0 | 40 | 'ts="1329181221", nonce="wGX71", mac="bNf4Fnt5k6DnhmyipLPkuZroH68=", ' + |
michael@0 | 41 | 'ext="EXTRA DATA; foo,bar=1"'); |
michael@0 | 42 | |
michael@0 | 43 | run_next_test(); |
michael@0 | 44 | }); |
michael@0 | 45 | |
michael@0 | 46 | add_test(function test_nonce_length() { |
michael@0 | 47 | _("Ensure custom nonce lengths are honoured."); |
michael@0 | 48 | |
michael@0 | 49 | function get_mac(length) { |
michael@0 | 50 | let uri = CommonUtils.makeURI("http://example.com/"); |
michael@0 | 51 | return CryptoUtils.computeHTTPMACSHA1("foo", "bar", "GET", uri, { |
michael@0 | 52 | nonce_bytes: length |
michael@0 | 53 | }); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | let result = get_mac(12); |
michael@0 | 57 | do_check_eq(12, atob(result.nonce).length); |
michael@0 | 58 | |
michael@0 | 59 | let result = get_mac(2); |
michael@0 | 60 | do_check_eq(2, atob(result.nonce).length); |
michael@0 | 61 | |
michael@0 | 62 | let result = get_mac(0); |
michael@0 | 63 | do_check_eq(8, atob(result.nonce).length); |
michael@0 | 64 | |
michael@0 | 65 | let result = get_mac(-1); |
michael@0 | 66 | do_check_eq(8, atob(result.nonce).length); |
michael@0 | 67 | |
michael@0 | 68 | run_next_test(); |
michael@0 | 69 | }); |