| 1 |
use anyhow::Result; |
| 2 |
|
| 3 |
use super::super::*; |
| 4 |
|
| 5 |
#[test] |
| 6 |
#[ntest::timeout(600000)] |
| 7 |
fn rsa2k_rsa2k() -> Result<()> { |
| 8 |
test_key("Key-Type: RSA |
| 9 |
Key-Length: 2048 |
| 10 |
Subkey-Type: RSA |
| 11 |
Subkey-Length: 2048 |
| 12 |
Name-Real: Name |
| 13 |
Name-Comment: Comment |
| 14 |
Name-Email: [email protected] |
| 15 |
Expire-Date: none |
| 16 |
%no-protection |
| 17 |
%commit |
| 18 |
", make_experiment!()?) |
| 19 |
} |
| 20 |
|
| 21 |
#[test] |
| 22 |
#[ntest::timeout(600000)] |
| 23 |
fn rsa2k_rsa2k_locked() -> Result<()> { |
| 24 |
test_key("Key-Type: RSA |
| 25 |
Key-Length: 2048 |
| 26 |
Subkey-Type: RSA |
| 27 |
Subkey-Length: 2048 |
| 28 |
Name-Real: Name |
| 29 |
Name-Comment: Comment |
| 30 |
Name-Email: [email protected] |
| 31 |
Expire-Date: none |
| 32 |
Passphrase: password |
| 33 |
%commit |
| 34 |
", make_experiment!()?) |
| 35 |
} |
| 36 |
|
| 37 |
#[test] |
| 38 |
#[ntest::timeout(600000)] |
| 39 |
fn dsa_rsa2k_by_id() -> Result<()> { |
| 40 |
test_key("Key-Type: 17 |
| 41 |
Key-Length: 2048 |
| 42 |
# XXX Key-Curve: IgnoredForNonECCTypes |
| 43 |
Subkey-Type: 1 |
| 44 |
Subkey-Length: 2048 |
| 45 |
Name-Real: Name |
| 46 |
Name-Comment: Comment |
| 47 |
Name-Email: [email protected] |
| 48 |
Expire-Date: none |
| 49 |
%no-protection |
| 50 |
%commit |
| 51 |
", make_experiment!()?) |
| 52 |
} |
| 53 |
|
| 54 |
#[test] |
| 55 |
#[ntest::timeout(600000)] |
| 56 |
fn eddsa_ecdh_25519() -> Result<()> { |
| 57 |
test_key("Key-Type: EDDSA |
| 58 |
Key-Curve: Ed25519 |
| 59 |
Subkey-Type: ECDH |
| 60 |
Subkey-Curve: Cv25519 |
| 61 |
Name-Real: Name |
| 62 |
Name-Comment: Comment |
| 63 |
Name-Email: [email protected] |
| 64 |
Expire-Date: none |
| 65 |
%no-protection |
| 66 |
%commit |
| 67 |
", make_experiment!()?) |
| 68 |
} |
| 69 |
|
| 70 |
#[test] |
| 71 |
#[ntest::timeout(600000)] |
| 72 |
fn ecdsa_ecdh_nistp256() -> Result<()> { |
| 73 |
test_key("Key-Type: ECDSA |
| 74 |
Key-Curve: nistp256 |
| 75 |
Subkey-Type: ECDH |
| 76 |
Subkey-Curve: nistp256 |
| 77 |
Name-Real: Name |
| 78 |
Name-Comment: Comment |
| 79 |
Name-Email: [email protected] |
| 80 |
Expire-Date: none |
| 81 |
%no-protection |
| 82 |
%commit |
| 83 |
", make_experiment!()?) |
| 84 |
} |
| 85 |
|
| 86 |
#[test] |
| 87 |
#[ntest::timeout(600000)] |
| 88 |
fn usage() -> Result<()> { |
| 89 |
test_key("Key-Type: EDDSA |
| 90 |
Key-Curve: Ed25519 |
| 91 |
Key-Usage: cert |
| 92 |
Subkey-Type: EDDSA |
| 93 |
Subkey-Curve: Ed25519 |
| 94 |
Subkey-Usage: sign |
| 95 |
Name-Real: Name |
| 96 |
Name-Comment: Comment |
| 97 |
Name-Email: [email protected] |
| 98 |
Expire-Date: none |
| 99 |
%no-protection |
| 100 |
%commit |
| 101 |
", make_experiment!()?) |
| 102 |
} |
| 103 |
|
| 104 |
#[test] |
| 105 |
#[ntest::timeout(600000)] |
| 106 |
fn creation_time() -> Result<()> { |
| 107 |
test_key("Key-Type: EDDSA |
| 108 |
Key-Curve: Ed25519 |
| 109 |
Subkey-Type: ECDH |
| 110 |
Subkey-Curve: Cv25519 |
| 111 |
Name-Real: Name |
| 112 |
Name-Comment: Comment |
| 113 |
Name-Email: [email protected] |
| 114 |
Expire-Date: none |
| 115 |
Creation-Date: 20220105T180052 |
| 116 |
%no-protection |
| 117 |
%commit |
| 118 |
", make_experiment!()?) |
| 119 |
} |
| 120 |
|
| 121 |
#[test] |
| 122 |
#[ntest::timeout(600000)] |
| 123 |
fn keyserver() -> Result<()> { |
| 124 |
test_key("Key-Type: EDDSA |
| 125 |
Key-Curve: Ed25519 |
| 126 |
Subkey-Type: ECDH |
| 127 |
Subkey-Curve: Cv25519 |
| 128 |
Name-Real: Name |
| 129 |
Name-Comment: Comment |
| 130 |
Name-Email: [email protected] |
| 131 |
Expire-Date: none |
| 132 |
Creation-Date: 20220105T180052 |
| 133 |
Keyserver: https://example.org/my/cert.pgp |
| 134 |
%no-protection |
| 135 |
%commit |
| 136 |
", make_experiment!()?) |
| 137 |
} |
| 138 |
|
| 139 |
#[test] |
| 140 |
#[ntest::timeout(600000)] |
| 141 |
fn preferences() -> Result<()> { |
| 142 |
test_key("Key-Type: EDDSA |
| 143 |
Key-Curve: Ed25519 |
| 144 |
Subkey-Type: ECDH |
| 145 |
Subkey-Curve: Cv25519 |
| 146 |
Name-Real: Name |
| 147 |
Name-Comment: Comment |
| 148 |
Name-Email: [email protected] |
| 149 |
Expire-Date: none |
| 150 |
Creation-Date: 20220105T180052 |
| 151 |
Preferences: Z0 bzip2 cAmEllIa256 h1 |
| 152 |
%no-protection |
| 153 |
%commit |
| 154 |
", make_experiment!()?) |
| 155 |
} |
| 156 |
|
| 157 |
#[test] |
| 158 |
#[ntest::timeout(600000)] |
| 159 |
fn comments_and_directives() -> Result<()> { |
| 160 |
test_key("# This is a comment |
| 161 |
%echo This prints a diagnostic. |
| 162 |
%secring /tmp/this/is/a/nop/nowadays |
| 163 |
# These are also NOPs with 2.1 and later |
| 164 |
%ask-passphrase |
| 165 |
%no-ask-passphrase |
| 166 |
Key-Type: EDDSA |
| 167 |
# ignored for ECC types: |
| 168 |
Key-Length: 2048 |
| 169 |
Key-Curve: Ed25519 |
| 170 |
Subkey-Type: ECDH |
| 171 |
Subkey-Curve: Cv25519 |
| 172 |
Name-Real: Name |
| 173 |
Name-Comment: Comment |
| 174 |
Name-Email: [email protected] |
| 175 |
Expire-Date: none |
| 176 |
%no-protection |
| 177 |
%transient-key |
| 178 |
%commit |
| 179 |
", make_experiment!()?) |
| 180 |
} |
| 181 |
|
| 182 |
fn test_key(parameters: &str, mut experiment: Experiment) -> Result<()> |
| 183 |
{ |
| 184 |
// Reduce noise. |
| 185 |
let diff = experiment.invoke(&[ |
| 186 |
"--list-keys", |
| 187 |
])?; |
| 188 |
diff.assert_success(); |
| 189 |
|
| 190 |
experiment.section("Generating key in batch mode..."); |
| 191 |
let diff = experiment.invoke(&[ |
| 192 |
"--status-fd=1", |
| 193 |
"--batch", |
| 194 |
"--generate-key", |
| 195 |
&experiment.store("parameters", parameters.as_bytes())?, |
| 196 |
])?.canonicalize_fingerprints(0)?; |
| 197 |
diff.assert_success(); |
| 198 |
diff.assert_equal_up_to(0, 0); |
| 199 |
|
| 200 |
// Reduce noise. |
| 201 |
let diff = experiment.invoke(&[ |
| 202 |
"--check-trustdb", |
| 203 |
])?; |
| 204 |
diff.assert_success(); |
| 205 |
|
| 206 |
test_key_generated(1, experiment) |
| 207 |
} |
| 208 |
|
| 209 |
fn test_key_generated(subkeys: usize, mut experiment: Experiment) |
| 210 |
-> Result<()> |
| 211 |
{ |
| 212 |
let mut diff = experiment.invoke(&[ |
| 213 |
"--list-keys", |
| 214 |
"--with-subkey-fingerprints", |
| 215 |
])?; |
| 216 |
for i in 0..subkeys { |
| 217 |
diff = diff.canonicalize_fingerprints(1 + i)?; |
| 218 |
} |
| 219 |
diff.assert_success(); |
| 220 |
diff.assert_equal_up_to(9, 0); |
| 221 |
|
| 222 |
let mut diff = experiment.invoke(&[ |
| 223 |
"--list-keys", |
| 224 |
"--with-keygrip", |
| 225 |
])?; |
| 226 |
for i in 0..1 + subkeys { |
| 227 |
diff = diff.canonicalize_fingerprints(i)?; |
| 228 |
} |
| 229 |
diff.assert_success(); |
| 230 |
diff.assert_equal_up_to(9, 0); |
| 231 |
|
| 232 |
let diff = experiment.invoke(&[ |
| 233 |
"--list-keys", |
| 234 |
"--with-colons", |
| 235 |
])?; |
| 236 |
diff.assert_success(); |
| 237 |
diff.assert_equal_up_to(5 + subkeys * 3, 0); |
| 238 |
|
| 239 |
let diff = experiment.invoke(&[ |
| 240 |
"--fingerprint", |
| 241 |
])?; |
| 242 |
diff.assert_success(); |
| 243 |
diff.assert_equal_up_to(9, 0); |
| 244 |
|
| 245 |
let diff = experiment.invoke(&[ |
| 246 |
"--fingerprint", |
| 247 |
"--fingerprint", |
| 248 |
])?; |
| 249 |
diff.assert_success(); |
| 250 |
diff.assert_equal_up_to(9, 0); |
| 251 |
|
| 252 |
let diff = experiment.invoke(&[ |
| 253 |
"--fingerprint", |
| 254 |
"--with-colons", |
| 255 |
])?; |
| 256 |
diff.assert_success(); |
| 257 |
diff.assert_equal_up_to(5 + subkeys * 3, 0); |
| 258 |
|
| 259 |
let diff = experiment.invoke(&[ |
| 260 |
"--list-keys", |
| 261 |
"--with-secret", |
| 262 |
])?; |
| 263 |
diff.assert_success(); |
| 264 |
diff.assert_equal_up_to(9, 0); |
| 265 |
|
| 266 |
let diff = experiment.invoke(&[ |
| 267 |
"--list-keys", |
| 268 |
"--with-secret", |
| 269 |
"--with-colons", |
| 270 |
])?; |
| 271 |
diff.assert_success(); |
| 272 |
diff.assert_equal_up_to(5 + subkeys * 3, 0); |
| 273 |
|
| 274 |
let diff = experiment.invoke(&[ |
| 275 |
"--list-secret-keys", |
| 276 |
])?; |
| 277 |
diff.assert_success(); |
| 278 |
diff.assert_equal_up_to(9, 0); |
| 279 |
|
| 280 |
let diff = experiment.invoke(&[ |
| 281 |
"--list-secret-keys", |
| 282 |
"--with-colons", |
| 283 |
])?; |
| 284 |
diff.assert_success(); |
| 285 |
diff.assert_equal_up_to(5 + subkeys * 3, 0); |
| 286 |
|
| 287 |
Ok(()) |
| 288 |
} |