| 1 |
use std::path::PathBuf; |
| 2 |
|
| 3 |
use sequoia_openpgp as openpgp; |
| 4 |
use openpgp::{ |
| 5 |
KeyHandle, |
| 6 |
Result, |
| 7 |
}; |
| 8 |
|
| 9 |
use chrono::Utc; |
| 10 |
use chrono::DateTime; |
| 11 |
|
| 12 |
use super::common::{Sq, artifact}; |
| 13 |
|
| 14 |
/// Returns the time formatted as an ISO 8106 string. |
| 15 |
pub fn time_as_string(t: DateTime<Utc>) -> String { |
| 16 |
t.format("%Y-%m-%dT%H:%M:%SZ").to_string() |
| 17 |
} |
| 18 |
|
| 19 |
#[test] |
| 20 |
fn sq_autocrypt_import() -> Result<()> |
| 21 |
{ |
| 22 |
let t = chrono::DateTime::parse_from_str("20240304T0100z", "%Y%m%dT%H%M%#z") |
| 23 |
.expect("valid date"); |
| 24 |
let sq = Sq::at(t.into()); |
| 25 |
|
| 26 |
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 27 |
let eml = manifest_dir.join("tests").join("data").join("autocrypt") |
| 28 |
.join("[email protected]"); |
| 29 |
|
| 30 |
// Import the message, first without being able to decrypt it. |
| 31 |
let mut cmd = sq.command(); |
| 32 |
cmd.arg("cert").arg("import") |
| 33 |
.arg(&eml); |
| 34 |
sq.run(cmd, true); |
| 35 |
|
| 36 |
// Check that the cert is imported. |
| 37 |
sq.cert_export("A614C91D0392D83EE6B1C4A4DD4147FEF78AD630".parse::<KeyHandle>()?); |
| 38 |
|
| 39 |
// We can now partially authenticate the sender. |
| 40 |
let mut cmd = sq.command(); |
| 41 |
cmd.arg("pki").arg("authenticate") |
| 42 |
.arg("--amount=40") |
| 43 |
.arg("--cert").arg("A614C91D0392D83EE6B1C4A4DD4147FEF78AD630") |
| 44 |
.arg("--email").arg("[email protected]"); |
| 45 |
eprintln!("Running: {:?}", cmd); |
| 46 |
eprintln!("pre: {}", time_as_string(std::time::SystemTime::now().into())); |
| 47 |
sq.run(cmd, true); |
| 48 |
eprintln!("post: {}", time_as_string(std::time::SystemTime::now().into())); |
| 49 |
|
| 50 |
// Import the message again, now with one of the recipient keys. |
| 51 |
sq.key_import(artifact("examples/alice-secret.pgp")); |
| 52 |
let mut cmd = sq.command(); |
| 53 |
cmd.arg("cert").arg("import") |
| 54 |
.arg(&eml); |
| 55 |
sq.run(cmd, true); |
| 56 |
|
| 57 |
// We can now weakly authenticate the peers. |
| 58 |
let mut cmd = sq.command(); |
| 59 |
cmd.arg("pki").arg("authenticate") |
| 60 |
.arg("--gossip") |
| 61 |
.arg("--cert").arg("CBCD8F030588653EEDD7E2659B7DD433F254904A") |
| 62 |
.arg("--email").arg("[email protected]"); |
| 63 |
sq.run(cmd, true); |
| 64 |
|
| 65 |
let mut cmd = sq.command(); |
| 66 |
cmd.arg("pki").arg("authenticate") |
| 67 |
.arg("--gossip") |
| 68 |
.arg("--cert").arg("BB6B7E5F8343B2BE990EB7A7F3AF066F267892C1") |
| 69 |
.arg("--email").arg("[email protected]"); |
| 70 |
sq.run(cmd, true); |
| 71 |
|
| 72 |
Ok(()) |
| 73 |
} |
| 74 |
|
| 75 |
#[test] |
| 76 |
fn sq_autocrypt_import_signed() -> Result<()> |
| 77 |
{ |
| 78 |
let t = chrono::DateTime::parse_from_str("20241214T0100z", "%Y%m%dT%H%M%#z") |
| 79 |
.expect("valid date"); |
| 80 |
let sq = Sq::at(t.into()); |
| 81 |
|
| 82 |
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 83 |
let eml = manifest_dir.join("tests").join("data").join("autocrypt") |
| 84 |
.join("signed.eml"); |
| 85 |
|
| 86 |
// Import the message. |
| 87 |
let mut cmd = sq.command(); |
| 88 |
cmd.arg("cert").arg("import").arg(&eml); |
| 89 |
sq.run(cmd, true); |
| 90 |
|
| 91 |
// Check that the cert is imported. |
| 92 |
sq.cert_export("64F4DD76866EA6896E4A869BA0FCAE2B43465576".parse::<KeyHandle>()?); |
| 93 |
|
| 94 |
// We can now partially authenticate the sender. |
| 95 |
let mut cmd = sq.command(); |
| 96 |
cmd.arg("pki").arg("authenticate") |
| 97 |
.arg("--amount=40") |
| 98 |
.arg("--cert").arg("64F4DD76866EA6896E4A869BA0FCAE2B43465576") |
| 99 |
.arg("--email").arg("[email protected]"); |
| 100 |
eprintln!("Running: {:?}", cmd); |
| 101 |
sq.run(cmd, true); |
| 102 |
|
| 103 |
Ok(()) |
| 104 |
} |