1 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 // Tests that the SDR implementation is able to decrypt strings encrypted using
9 // a preexisting NSS key database. Creating the database is straight-forward:
10 // simply run Firefox (or xpcshell) and encrypt something using
11 // nsISecretDecoderRing (e.g. by saving a password or directly using the
12 // interface). The resulting key4.db file (in the profile directory) now
13 // contains the private key used to encrypt the data.
16 const keyDBName = "key4.db";
17 let profile = do_get_profile();
18 let keyDBFile = do_get_file(`test_sdr_preexisting/${keyDBName}`);
19 keyDBFile.copyTo(profile, keyDBName);
21 let sdr = Cc["@mozilla.org/security/sdr;1"].getService(
22 Ci.nsISecretDecoderRing
26 // a full padding block
29 "MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECGeDHwVfyFqzBBAYvqMq/kDMsrARVNdC1C8d",
30 plaintext: "password",
35 "MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECCAzLDVmYG2/BAh3IoIsMmT8dQ==",
41 "MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECPN8zlZzn8FdBAiu2acpT8UHsg==",
47 "MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECD5px1eMKkJQBAgUPp35GlrDvQ==",
53 "MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECMh0hLtKDyUdBAixw9UZsMt+vA==",
56 // long plaintext requiring more than two blocks
59 "MFoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECDRX1qi+/FX1BDATFIcIneQjvBuq3wdFxzllJt2VtUD69ACdOKAXH3eA87oHDvuHqOeCDwRy4UzoG5s=",
60 plaintext: "thisismuchlongerandsotakesupmultipleblocks",
62 // this differs from the previous ciphertext by one bit and demonstrates
63 // that this implementation does not enforce message integrity
66 "MFoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECDRX1qi+/FX1BDAbFIcIneQjvBuq3wdFxzllJt2VtUD69ACdOKAXH3eA87oHDvuHqOeCDwRy4UzoG5s=",
67 plaintext: "nnLbuwLRkhlongerandsotakesupmultipleblocks",
71 for (let testcase of testcases) {
72 let decrypted = sdr.decryptString(testcase.ciphertext);
76 "decrypted ciphertext should match expected plaintext"