| 1 |
use anyhow::Result; |
| 2 |
|
| 3 |
use sequoia_openpgp as openpgp; |
| 4 |
use openpgp::{ |
| 5 |
cert::prelude::*, |
| 6 |
parse::Parse, |
| 7 |
serialize::{ |
| 8 |
Serialize, |
| 9 |
SerializeInto, |
| 10 |
}, |
| 11 |
}; |
| 12 |
|
| 13 |
use super::super::*; |
| 14 |
|
| 15 |
#[test] |
| 16 |
#[ntest::timeout(600000)] |
| 17 |
fn ciphersuite_cv25519() -> Result<()> { |
| 18 |
ciphersuite(CipherSuite::Cv25519) |
| 19 |
} |
| 20 |
|
| 21 |
#[test] |
| 22 |
#[ntest::timeout(600000)] |
| 23 |
fn ciphersuite_rsa2k() -> Result<()> { |
| 24 |
ciphersuite(CipherSuite::RSA2k) |
| 25 |
} |
| 26 |
|
| 27 |
#[test] |
| 28 |
#[ntest::timeout(600000)] |
| 29 |
fn ciphersuite_rsa3k() -> Result<()> { |
| 30 |
ciphersuite(CipherSuite::RSA3k) |
| 31 |
} |
| 32 |
|
| 33 |
#[test] |
| 34 |
#[ntest::timeout(600000)] |
| 35 |
fn ciphersuite_rsa4k() -> Result<()> { |
| 36 |
ciphersuite(CipherSuite::RSA4k) |
| 37 |
} |
| 38 |
|
| 39 |
#[test] |
| 40 |
#[ntest::timeout(600000)] |
| 41 |
fn ciphersuite_p256() -> Result<()> { |
| 42 |
ciphersuite(CipherSuite::P256) |
| 43 |
} |
| 44 |
|
| 45 |
#[test] |
| 46 |
#[ntest::timeout(600000)] |
| 47 |
fn ciphersuite_p384() -> Result<()> { |
| 48 |
ciphersuite(CipherSuite::P384) |
| 49 |
} |
| 50 |
|
| 51 |
#[test] |
| 52 |
#[ntest::timeout(600000)] |
| 53 |
fn ciphersuite_p521() -> Result<()> { |
| 54 |
ciphersuite(CipherSuite::P521) |
| 55 |
} |
| 56 |
|
| 57 |
fn ciphersuite(cs: CipherSuite) -> Result<()> { |
| 58 |
let mut experiment = make_experiment!(format!("{:?}", cs))?; |
| 59 |
let cert = experiment.artifact( |
| 60 |
"cert", |
| 61 |
|| CertBuilder::new() |
| 62 |
.set_cipher_suite(cs) |
| 63 |
.add_userid("Alice Lovelace <[email protected]>") |
| 64 |
.set_creation_time(Experiment::now()) |
| 65 |
.add_authentication_subkey() |
| 66 |
.generate() |
| 67 |
.map(|(cert, _rev)| cert), |
| 68 |
|a, f| a.as_tsk().serialize(f), |
| 69 |
|b| Cert::from_bytes(&b))?; |
| 70 |
|
| 71 |
test_key(cert, experiment, true) |
| 72 |
} |
| 73 |
|
| 74 |
#[test] |
| 75 |
#[ntest::timeout(600000)] |
| 76 |
fn no_authentication_subkey() -> Result<()> { |
| 77 |
let mut experiment = make_experiment!()?; |
| 78 |
let cert = experiment.artifact( |
| 79 |
"cert", |
| 80 |
|| CertBuilder::new() |
| 81 |
.add_userid("Alice Lovelace <[email protected]>") |
| 82 |
.set_creation_time(Experiment::now()) |
| 83 |
.generate() |
| 84 |
.map(|(cert, _rev)| cert), |
| 85 |
|a, f| a.as_tsk().serialize(f), |
| 86 |
|b| Cert::from_bytes(&b))?; |
| 87 |
|
| 88 |
test_key(cert, experiment, false) |
| 89 |
} |
| 90 |
|
| 91 |
fn test_key(cert: Cert, mut experiment: Experiment, expect_success: bool) |
| 92 |
-> Result<()> |
| 93 |
{ |
| 94 |
experiment.section("Importing cert..."); |
| 95 |
let diff = experiment.invoke(&[ |
| 96 |
"--import", |
| 97 |
&experiment.store("cert", &cert.to_vec()?)?, |
| 98 |
])?; |
| 99 |
diff.assert_success(); |
| 100 |
|
| 101 |
let primary = cert.fingerprint().to_string(); |
| 102 |
let diff = experiment.invoke(&[ |
| 103 |
"--export-ssh-key", &primary, |
| 104 |
])?; |
| 105 |
if expect_success { |
| 106 |
diff.assert_success(); |
| 107 |
diff.assert_limits(0, 0, 0); |
| 108 |
} else { |
| 109 |
diff.assert_failure(); |
| 110 |
diff.assert_limits(0, 0, 7); |
| 111 |
} |
| 112 |
|
| 113 |
if let Some(subkey) = |
| 114 |
cert.keys().subkeys().nth(0).map(|k| k.key().fingerprint().to_string()) |
| 115 |
{ |
| 116 |
let diff = experiment.invoke(&[ |
| 117 |
"--export-ssh-key", &subkey, |
| 118 |
])?; |
| 119 |
if expect_success { |
| 120 |
diff.assert_success(); |
| 121 |
diff.assert_limits(0, 0, 0); |
| 122 |
} else { |
| 123 |
diff.assert_failure(); |
| 124 |
diff.assert_limits(0, 0, 7); |
| 125 |
} |
| 126 |
|
| 127 |
let diff = experiment.invoke(&[ |
| 128 |
"--export-ssh-key", &format!("{}!", &subkey), |
| 129 |
])?; |
| 130 |
diff.assert_success(); |
| 131 |
diff.assert_limits(0, 0, 0); |
| 132 |
} else { |
| 133 |
let diff = experiment.invoke(&[ |
| 134 |
"--export-ssh-key", &format!("{}!", &primary), |
| 135 |
])?; |
| 136 |
diff.assert_success(); |
| 137 |
diff.assert_limits(0, 0, 0); |
| 138 |
} |
| 139 |
|
| 140 |
Ok(()) |
| 141 |
} |