mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
feat: release GP Connect 3.3.0 with Native Shell support
This commit is contained in:
226 files changed
+7700
-5225
No files matched your search
@@ -1,4 +1,4 @@
|
||||
//! Public identity compatibility and native import behavior.
|
||||
//! Public identity compatibility and owned material lifecycle.
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use gpapi::utils::request::{ClientIdentity, RequestIdentityError};
|
||||
@@ -31,23 +31,9 @@ fn rsa_pkcs8_loads_without_a_password() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ec_pkcs8_records_native_import_compatibility() {
|
||||
let result = load("ec-cert.pem", "ec-pkcs8.pem", None);
|
||||
if cfg!(target_os = "macos") {
|
||||
// Apple native-tls import currently rejects this P-256 PKCS#8 fixture.
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.downcast_ref::<reqwest::Error>()
|
||||
.unwrap()
|
||||
.is_builder()
|
||||
);
|
||||
} else {
|
||||
assert_eq!(
|
||||
result.unwrap().key_data().unwrap(),
|
||||
fs::read(fixture("ec-pkcs8.pem")).unwrap()
|
||||
);
|
||||
}
|
||||
fn ec_pkcs8_loads_on_every_platform() {
|
||||
let identity = load("ec-cert.pem", "ec-pkcs8.pem", None).unwrap();
|
||||
assert_eq!(identity.key_data().unwrap(), fs::read(fixture("ec-pkcs8.pem")).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -63,23 +49,13 @@ fn encrypted_pkcs8_keys_normalize_to_the_same_private_key() {
|
||||
("ec-pbes2.pem", "ec-pkcs8.pem", "ec-cert.pem"),
|
||||
] {
|
||||
let result = load(certificate, key, Some(PASSWORD));
|
||||
if cfg!(target_os = "macos") && certificate == "ec-cert.pem" {
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.downcast_ref::<reqwest::Error>()
|
||||
.unwrap()
|
||||
.is_builder()
|
||||
);
|
||||
} else {
|
||||
let identity = result.unwrap_or_else(|error| panic!("{key}: {error}"));
|
||||
assert_eq!(
|
||||
identity.key_data().unwrap(),
|
||||
fs::read(fixture(expected)).unwrap(),
|
||||
"{key}"
|
||||
);
|
||||
assert!(identity.key_password().is_none());
|
||||
}
|
||||
let identity = result.unwrap_or_else(|error| panic!("{key}: {error}"));
|
||||
assert_eq!(
|
||||
identity.key_data().unwrap(),
|
||||
fs::read(fixture(expected)).unwrap(),
|
||||
"{key}"
|
||||
);
|
||||
assert!(identity.key_password().is_none());
|
||||
for (password, missing) in [(None, true), (Some("incorrect"), false)] {
|
||||
let error = load(certificate, key, password).unwrap_err();
|
||||
match error.downcast_ref::<RequestIdentityError>() {
|
||||
@@ -128,7 +104,7 @@ fn rsa_pkcs1_normalizes_to_pkcs8_in_separate_and_combined_files() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_rsa_pkcs1_is_rejected_by_native_import() {
|
||||
fn malformed_rsa_pkcs1_is_rejected_before_connection() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let source = directory.path().join("invalid-key.pem");
|
||||
fs::write(&source, pem::encode(&pem::Pem::new("RSA PRIVATE KEY", vec![0x30, 0]))).unwrap();
|
||||
@@ -138,7 +114,11 @@ fn malformed_rsa_pkcs1_is_rejected_by_native_import() {
|
||||
None,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(error.downcast_ref::<reqwest::Error>().is_some());
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("Check that the private key matches the certificate")
|
||||
);
|
||||
}
|
||||
|
||||
fn check_archive(name: &str, password: &str) {
|
||||
@@ -211,15 +191,12 @@ fn pkcs12_password_errors_explain_how_to_recover() {
|
||||
assert!(message.contains("PKCS#12"), "{message}");
|
||||
assert!(message.contains("password") && message.contains("file"), "{message}");
|
||||
assert!(!format!("{error:?}").contains("incorrect"));
|
||||
assert!(error.chain().any(|cause| cause.is::<reqwest::Error>()));
|
||||
assert!(error.chain().any(|cause| cause.is::<p12_keystore::error::Error>()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
// Apple's native importer rejects this empty-password fixture; its native
|
||||
// compatibility decision is covered by archive_snapshot_and_pfx_preserve_native_import_contract.
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
fn empty_pkcs12_password_survives_loading_and_transport() {
|
||||
let archive = fs::read(fixture("empty-password.p12")).unwrap();
|
||||
for password in [None, Some("")] {
|
||||
@@ -239,26 +216,6 @@ fn pkcs12_accepts_non_ascii_passwords() {
|
||||
|
||||
#[test]
|
||||
fn legacy_rc2_pkcs12_checks_password_and_archive_integrity() {
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
if std::env::var_os("GP_IDENTITY_LEGACY_TEST_CHILD").is_none() {
|
||||
// OpenSSL providers are process-global. Exercise the existing legacy-mode
|
||||
// configuration in an isolated process, without affecting parallel tests.
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let config = directory.path().join("openssl.cnf");
|
||||
fs::write(&config, gpapi::utils::openssl::openssl_conf()).unwrap();
|
||||
let status = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args([
|
||||
"--exact",
|
||||
"legacy_rc2_pkcs12_checks_password_and_archive_integrity",
|
||||
"--nocapture",
|
||||
])
|
||||
.env("OPENSSL_CONF", config)
|
||||
.env("GP_IDENTITY_LEGACY_TEST_CHILD", "1")
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(status.success());
|
||||
return;
|
||||
}
|
||||
check_archive("legacy-rc2.p12", PASSWORD);
|
||||
}
|
||||
|
||||
@@ -307,6 +264,12 @@ fn pbes2_legacy_ciphers_remain_supported() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
fn legacy_pkcs8_conversion_preserves_the_key_and_password_errors() {
|
||||
let identity = load("rsa-cert.pem", "rsa-pbes1-3des.pem", Some(PASSWORD)).unwrap();
|
||||
assert_eq!(
|
||||
@@ -325,117 +288,70 @@ fn legacy_pkcs8_conversion_preserves_the_key_and_password_errors() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
fn legacy_pkcs8_matches_previous_linux_openssl_processing() {
|
||||
let encrypted = fs::read(fixture("rsa-pbes1-3des.pem")).unwrap();
|
||||
let previous = openssl::pkey::PKey::private_key_from_pem_passphrase(&encrypted, PASSWORD.as_bytes())
|
||||
.unwrap()
|
||||
.private_key_to_pem_pkcs8()
|
||||
.unwrap();
|
||||
let identity = load("rsa-cert.pem", "rsa-pbes1-3des.pem", Some(PASSWORD)).unwrap();
|
||||
assert_eq!(identity.key_data().unwrap(), previous);
|
||||
assert!(openssl::pkey::PKey::private_key_from_pem_passphrase(&encrypted, b"incorrect").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_pkcs8_converter_failures_are_terminal_and_modern_keys_need_no_executable() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
const CHILD: &str = "GP_LEGACY_CONVERTER_TEST";
|
||||
if let Ok(case) = std::env::var(CHILD) {
|
||||
let started = std::time::Instant::now();
|
||||
let error = load("rsa-cert.pem", "rsa-pbes1-3des.pem", Some(PASSWORD)).unwrap_err();
|
||||
assert!(
|
||||
started.elapsed() < std::time::Duration::from_secs(12),
|
||||
"conversion exceeded its deadline"
|
||||
);
|
||||
assert!(
|
||||
matches!(
|
||||
error.downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::LegacyKeyConversion(_))
|
||||
),
|
||||
"{error:?}"
|
||||
);
|
||||
let message = format!("{error:?}");
|
||||
assert!(message.contains("Convert the key to modern PKCS#8"));
|
||||
assert!(!message.contains(PASSWORD));
|
||||
assert!(!message.contains("PRIVATE KEY"));
|
||||
if case == "missing" {
|
||||
assert!(message.contains("unavailable"));
|
||||
} else if case.starts_with("timeout") {
|
||||
assert!(message.contains("timed out"));
|
||||
}
|
||||
for key in ["rsa-pkcs8.pem", "rsa-pbes2-sha256.pem"] {
|
||||
let identity = load("rsa-cert.pem", key, Some(PASSWORD)).unwrap();
|
||||
assert_eq!(
|
||||
identity.key_data().unwrap(),
|
||||
fs::read(fixture("rsa-pkcs8.pem")).unwrap()
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// PATH is process-global; isolate executable discovery from parallel tests.
|
||||
for (case, script) in [
|
||||
("missing", None),
|
||||
(
|
||||
"unsupported",
|
||||
Some("#!/bin/sh\nprintf 'unsupported: fixture-password PRIVATE KEY' >&2\nexit 1\n"),
|
||||
),
|
||||
("invalid-output", Some("#!/bin/sh\nprintf 'invalid converted key'\n")),
|
||||
("timeout-wrapper", Some("#!/bin/sh\n/bin/sleep 14\n")),
|
||||
("timeout-exited-wrapper", Some("#!/bin/sh\n/bin/sleep 14 &\nexit 0\n")),
|
||||
] {
|
||||
#[cfg(any(
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
fn identity_import_does_not_use_converter_executables() {
|
||||
const CHILD: &str = "GP_IDENTITY_NO_COMMANDS";
|
||||
if std::env::var_os(CHILD).is_none() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
if let Some(script) = script {
|
||||
let executable = directory.path().join("openssl");
|
||||
fs::write(&executable, script).unwrap();
|
||||
fs::set_permissions(executable, fs::Permissions::from_mode(0o700)).unwrap();
|
||||
}
|
||||
let status = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args([
|
||||
"--exact",
|
||||
"legacy_pkcs8_converter_failures_are_terminal_and_modern_keys_need_no_executable",
|
||||
"--nocapture",
|
||||
])
|
||||
.args(["--exact", "identity_import_does_not_use_converter_executables"])
|
||||
.env(CHILD, "1")
|
||||
.env("PATH", directory.path())
|
||||
.env(CHILD, case)
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(status.success(), "converter case: {case}");
|
||||
assert!(status.success());
|
||||
return;
|
||||
}
|
||||
for key in ["rsa-pkcs8.pem", "rsa-traditional-aes256.pem", "rsa-pbes1-3des.pem"] {
|
||||
let identity = load("rsa-cert.pem", key, Some(PASSWORD)).unwrap();
|
||||
assert_eq!(
|
||||
identity.key_data().unwrap(),
|
||||
fs::read(fixture("rsa-pkcs8.pem")).unwrap()
|
||||
);
|
||||
}
|
||||
check_archive("legacy-rc2.p12", PASSWORD);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_converter_reports_its_password_length_limit_without_requesting_a_retry() {
|
||||
let password = "x".repeat(1024);
|
||||
let encrypted = fs::read(fixture("rsa-pbes1-3des-password-1024.pem")).unwrap();
|
||||
// The previous linked API accepted this boundary. The CLI cannot carry it;
|
||||
// report that limitation rather than calling the correct password wrong.
|
||||
openssl::pkey::PKey::private_key_from_pem_passphrase(&encrypted, password.as_bytes()).unwrap();
|
||||
let error = load("rsa-cert.pem", "rsa-pbes1-3des-password-1024.pem", Some(&password)).unwrap_err();
|
||||
assert!(
|
||||
matches!(
|
||||
error.downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::LegacyKeyConversion(_))
|
||||
),
|
||||
"{error:?}"
|
||||
);
|
||||
assert!(error.to_string().contains("1023-byte"));
|
||||
let accepted = load(
|
||||
#[cfg(any(
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
fn legacy_key_import_handles_the_supported_password_boundary() {
|
||||
let identity = load(
|
||||
"rsa-cert.pem",
|
||||
"rsa-pbes1-3des-password-1023.pem",
|
||||
Some(&"x".repeat(1023)),
|
||||
"rsa-pbes1-3des-password-127.pem",
|
||||
Some(&"x".repeat(127)),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
accepted.key_data().unwrap(),
|
||||
identity.key_data().unwrap(),
|
||||
fs::read(fixture("rsa-pkcs8.pem")).unwrap()
|
||||
);
|
||||
let password = "x".repeat(128);
|
||||
let error = load("rsa-cert.pem", "rsa-pbes1-3des-password-128.pem", Some(&password)).unwrap_err();
|
||||
assert_eq!(
|
||||
error.to_string(),
|
||||
"Password is too long for this legacy key format. Re-export the key with modern encryption"
|
||||
);
|
||||
assert!(!format!("{error:?}").contains(&password));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_conversion_keeps_original_files_and_rejects_line_breaks_in_passwords() {
|
||||
#[cfg(any(
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
fn encrypted_key_import_keeps_original_files_and_redacts_passwords() {
|
||||
let original = fs::read(fixture("rsa-pbes1-3des.pem")).unwrap();
|
||||
for password in [
|
||||
PASSWORD,
|
||||
@@ -447,16 +363,15 @@ fn legacy_conversion_keeps_original_files_and_rejects_line_breaks_in_passwords()
|
||||
let result = load("rsa-cert.pem", "rsa-pbes1-3des.pem", Some(password));
|
||||
if password == PASSWORD {
|
||||
result.unwrap();
|
||||
} else if password != "incorrect" {
|
||||
assert!(matches!(
|
||||
result.unwrap_err().downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::LegacyKeyConversion(_))
|
||||
));
|
||||
} else {
|
||||
assert!(matches!(
|
||||
result.unwrap_err().downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::DecryptError("PEM"))
|
||||
));
|
||||
let error = result.unwrap_err();
|
||||
assert!(!format!("{error:?}").contains(password));
|
||||
if !password.contains('\0') {
|
||||
assert!(matches!(
|
||||
error.downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::DecryptError("PEM"))
|
||||
));
|
||||
}
|
||||
}
|
||||
assert_eq!(fs::read(fixture("rsa-pbes1-3des.pem")).unwrap(), original);
|
||||
}
|
||||
@@ -530,7 +445,7 @@ fn prepared_pem_round_trip_retains_snapshot_and_private_file_lifecycle() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn archive_snapshot_and_pfx_preserve_native_import_contract() {
|
||||
fn archive_snapshot_and_pfx_preserve_prepared_identity() {
|
||||
use zeroize::Zeroizing;
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("identity.pfx");
|
||||
@@ -549,12 +464,7 @@ fn archive_snapshot_and_pfx_preserve_native_import_contract() {
|
||||
assert!(restored.key_data().is_none());
|
||||
assert!(!format!("{restored:?}").contains(PASSWORD));
|
||||
let empty = fs::read(fixture("empty-password.p12")).unwrap();
|
||||
// Preserve the native backend's existing empty-password decision.
|
||||
let expected = reqwest::Identity::from_pkcs12_der(&empty, "").is_ok();
|
||||
assert_eq!(
|
||||
ClientIdentity::from_data(Zeroizing::new(empty), None, Some("")).is_ok(),
|
||||
expected
|
||||
);
|
||||
assert!(ClientIdentity::from_data(Zeroizing::new(empty), None, Some("")).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -706,3 +616,66 @@ fn mismatched_certificate_key_is_rejected_before_request_client_creation() {
|
||||
.contains("Check that the private key matches the certificate")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pkcs12_without_bag_ids_or_mac_matches_the_key_instead_of_bag_order() {
|
||||
let data = fs::read(fixture("no-bag-ids.p12")).unwrap();
|
||||
let archive = p12_keystore::Pkcs12Archive::from_pkcs12(&data, "").unwrap();
|
||||
assert!(archive.keys[0].local_key_id.is_none());
|
||||
assert!(archive.certs.iter().all(|bag| bag.local_key_id.is_none()));
|
||||
assert_eq!(
|
||||
archive.certs[0].cert.as_der(),
|
||||
pem::parse(fs::read(fixture("root.pem")).unwrap()).unwrap().contents()
|
||||
);
|
||||
for password in [None, Some("")] {
|
||||
let identity = ClientIdentity::from_data(data.clone().into(), None, password).unwrap();
|
||||
assert_eq!(identity.certificate_data(), data);
|
||||
assert!(identity.key_data().is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pkcs12_rejects_mismatched_and_multiple_identities() {
|
||||
for (name, ambiguous) in [("mismatched.p12", false), ("multiple-identities.p12", true)] {
|
||||
let error = ClientIdentity::load(fixture(name).to_str().unwrap(), None, None).unwrap_err();
|
||||
match error.downcast_ref::<RequestIdentityError>() {
|
||||
Some(RequestIdentityError::AmbiguousPkcs12) => assert!(ambiguous),
|
||||
Some(RequestIdentityError::InvalidCertificate) => assert!(!ambiguous),
|
||||
other => panic!("{name}: unexpected archive error: {other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn owned_identity_accepts_certificate_pem_without_a_final_newline() {
|
||||
let certificate = fs::read(fixture("rsa-cert.pem")).unwrap();
|
||||
let certificate = certificate.trim_ascii_end().to_vec();
|
||||
let key = fs::read(fixture("rsa-pkcs8.pem")).unwrap();
|
||||
let identity = ClientIdentity::from_data(
|
||||
zeroize::Zeroizing::new(certificate.clone()),
|
||||
Some(zeroize::Zeroizing::new(key)),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(identity.certificate_data(), certificate);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retained_pkcs12_password_rejects_nul_before_native_tunnel_setup() {
|
||||
let password = "private\0password";
|
||||
let error = ClientIdentity::load(fixture("no-bag-ids.p12").to_str().unwrap(), None, Some(password)).unwrap_err();
|
||||
assert!(error.to_string().contains("NUL"));
|
||||
assert!(!format!("{error:?}").contains(password));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
#[test]
|
||||
fn ios_reports_unsupported_legacy_encryption_without_a_native_importer() {
|
||||
for key in ["rsa-pbes1-3des.pem", "rsa-traditional-aes256.pem"] {
|
||||
let error = load("rsa-cert.pem", key, Some(PASSWORD)).unwrap_err();
|
||||
assert!(matches!(
|
||||
error.downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::UnsupportedEncryption)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
These generated keys and certificates are **public test data**, never production
|
||||
credentials. Passwords are `fixture-password`, except `unicode-password.p12`,
|
||||
which uses `pässword-密码`, and the `rsa-pbes1-3des-password-{1023,1024}.pem`
|
||||
which uses `pässword-密码`, and the `rsa-pbes1-3des-password-{127,128}.pem`
|
||||
fixtures, which use `x` repeated the indicated number of bytes.
|
||||
|
||||
Regenerate intentionally with OpenSSL 3:
|
||||
@@ -12,9 +12,9 @@ OPENSSL_BIN=/path/to/openssl bash generate.sh
|
||||
```
|
||||
|
||||
Generation is random; it replaces the keys, certificates, and archives together.
|
||||
The test runner reads checked-in files. Legacy standalone conversion tests
|
||||
require an `openssl` executable on PATH (OpenSSL or compatible LibreSSL).
|
||||
No fixture generation is needed to run the tests.
|
||||
The test runner reads checked-in files and needs no converter executable.
|
||||
No fixture generation is needed to run the tests. OpenSSL is used only by the
|
||||
optional fixture-generation script, not identity import.
|
||||
|
||||
| Files | Contents |
|
||||
| --- | --- |
|
||||
@@ -24,38 +24,36 @@ No fixture generation is needed to run the tests.
|
||||
| `{rsa,ec}-traditional-{aes128,aes192,aes256,des3}.pem` | Traditional encrypted PEM with AES-CBC or 3DES-CBC; password `fixture-password` |
|
||||
| `rsa-pbes2-sha1.pem`, `rsa-pbes2-sha256.pem` | Encrypted PKCS#8, AES256-CBC/PBKDF2 with SHA1 or SHA256 PRF |
|
||||
| `rsa-pbes2-aes-{128,192}-cbc-{sha1,sha256}.pem` | AES128/192-CBC with PBKDF2 SHA1/SHA256 |
|
||||
| `rsa-pbes2-des3-{sha1,sha256}.pem` | PBES2 3DES-CBC with PBKDF2 SHA1/SHA256; distinct from the legacy PBE scheme handled by optional conversion |
|
||||
| `rsa-pbes2-des3-{sha1,sha256}.pem` | PBES2 3DES-CBC with PBKDF2 SHA1/SHA256; distinct from the PKCS#12 PBE scheme handled by GnuTLS |
|
||||
| `rsa-pbes2-des.pem` | PBES2 DES-CBC/PBKDF2-SHA256; Rust processing requires no native legacy provider |
|
||||
| `rsa-pbes2-scrypt.pem` | PBES2 AES256-CBC with scrypt |
|
||||
| `rsa-pbes1-3des-password-{1023,1024}.pem` | Same legacy encryption with passwords at the CLI input boundary; the linked importer accepts 1024 bytes, while the converter reports its 1023-byte limit explicitly |
|
||||
| `rsa-pbes1-3des.pem` | Legacy PKCS#12 SHA1/3DES scheme inside standalone encrypted PKCS#8; optional OpenSSL executable conversion case |
|
||||
| `empty-password.p12` | RSA leaf/key/root with an empty password, preserving native backend acceptance |
|
||||
| `rsa-pbes1-3des-password-{127,128}.pem` | Legacy password boundary: 127 ASCII characters import; 128 report the supported limit |
|
||||
| `rsa-pbes1-3des.pem` | Legacy PKCS#12 SHA1/3DES scheme inside standalone encrypted PKCS#8; private GnuTLS import case |
|
||||
| `empty-password.p12` | RSA leaf/key/root with an empty password, accepted with omitted or empty password |
|
||||
| `ec-pbes2.pem` | Encrypted EC PKCS#8, AES256-CBC/PBKDF2-SHA256 |
|
||||
| `modern.p12`, `unicode-password.p12` | Leaf/key/root, AES256-CBC/PBKDF2-SHA256, SHA256 MAC; RSA and EC respectively |
|
||||
| `certificate-only.pfx`, `key-only.pfx` | Incomplete PKCS#12 archives: certificate without key, and key without certificate; password `fixture-password` |
|
||||
| `legacy-rc2.p12` | Issue #437 case: RC2-40 certificate bags, SHA1/3DES key bag, SHA1 MAC |
|
||||
|
||||
`tests/client_identity.rs` records native import compatibility and the owned
|
||||
identity lifecycle. `tests/identity_encoding.rs` covers container normalization:
|
||||
DER certificates and keys, RSA PKCS#1, Linux/BSD EC SEC1 and traditional encrypted
|
||||
PEM, first-key selection, malformed encryption headers, and archive extension
|
||||
capitalization. macOS rejects SEC1 and traditional encrypted PEM before password
|
||||
handling. Its native importer also rejects the P-256 PKCS#8 PEM fixture, although
|
||||
its native PKCS#12 import accepts the EC archive. Legacy-provider setup is isolated
|
||||
in a child process on Linux/BSD.
|
||||
`tests/client_identity.rs` covers all supported key families, password failures,
|
||||
archive integrity, certificate/key matching, retained snapshots, private-file
|
||||
permissions and cleanup. `tests/identity_encoding.rs` covers PEM/DER, RSA PKCS#1,
|
||||
EC SEC1, traditional encrypted PEM, first-key selection, malformed encryption
|
||||
headers and archive extension capitalization. Rustls validates RSA and EC keys
|
||||
on all supported targets; desktop legacy encrypted-key imports use GnuTLS.
|
||||
Legacy PKCS#12 SHA1/3DES keys use a consistent limit of 127 UTF-16 code units
|
||||
(256 bytes including the terminator), matching older supported GnuTLS releases.
|
||||
Longer passwords report a clear error without exposing the password.
|
||||
PBES2, including scrypt, stays in Rust and does not use this limit. The
|
||||
no-executable child test runs with an empty PATH and imports both legacy key
|
||||
families and RC2 PKCS#12.
|
||||
|
||||
Standalone PKCS#8 PBE-SHA1-3DES uses optional OpenSSL executable conversion,
|
||||
with missing/wrong passwords preserving the old Linux prompt/retry contract.
|
||||
Other unsupported schemes retain explicit conversion guidance. PBES2 DES/3DES
|
||||
use Rust processing and need no executable. Child-process tests isolate PATH
|
||||
for absent/unsupported/stalled converters, invalid output, and secret-free errors.
|
||||
Timeout coverage includes wrappers whose descendants retain pipes after the
|
||||
wrapper exits or is killed; all pipe I/O shares the process deadline.
|
||||
Linux/BSD additionally compare the result with the former linked OpenSSL importer.
|
||||
Archive integrity checks change the UTF-16 friendly name without changing the
|
||||
MAC. Decrypted output is compared with independent plaintext fixture keys.
|
||||
Unit tests in `utils/request.rs` cover missing keys, large local files and request
|
||||
client construction.
|
||||
|
||||
The tests check archive integrity by changing the UTF-16 friendly name without
|
||||
changing the MAC, and compare normalized PEM output against the independent
|
||||
checked-in plaintext key. Public integration tests cover first-key selection,
|
||||
retained snapshots, private-file permissions and cleanup, `.pfx`, empty-password
|
||||
backend behavior, and chain retention. Unit tests in `utils/request.rs` cover
|
||||
missing keys, large local files, and native request-client construction.
|
||||
The unencrypted, MAC-less `no-bag-ids.p12`, `mismatched.p12`, and
|
||||
`multiple-identities.p12` contain only the same public test keys/certificates.
|
||||
They exercise PKCS#12 bags without optional attributes, reversed certificate
|
||||
order/unrelated certificates, and terminal mismatched/ambiguous identities.
|
||||
@@ -0,0 +1,53 @@
|
||||
"""Assemble public, unencrypted PKCS#12 fixtures; no cryptography is performed."""
|
||||
import base64
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def pem(name):
|
||||
lines = (ROOT / name).read_text().splitlines()
|
||||
return base64.b64decode("".join(line for line in lines if not line.startswith("-----")))
|
||||
|
||||
|
||||
def tlv(tag, content):
|
||||
length = len(content)
|
||||
encoded = length.to_bytes(max(1, (length.bit_length() + 7) // 8), "big")
|
||||
prefix = bytes([length]) if length < 128 else bytes([128 + len(encoded)]) + encoded
|
||||
return bytes([tag]) + prefix + content
|
||||
|
||||
|
||||
def sequence(*items):
|
||||
return tlv(0x30, b"".join(items))
|
||||
|
||||
|
||||
def oid(value):
|
||||
return tlv(6, bytes.fromhex(value))
|
||||
|
||||
|
||||
def explicit(content):
|
||||
return tlv(0xA0, content)
|
||||
|
||||
|
||||
def data(content):
|
||||
return sequence(oid("2a864886f70d010701"), explicit(tlv(4, content)))
|
||||
|
||||
|
||||
def key(name):
|
||||
return sequence(oid("2a864886f70d010c0a0101"), explicit(pem(name)))
|
||||
|
||||
|
||||
def certificate(name):
|
||||
cert_bag = sequence(oid("2a864886f70d01091601"), explicit(tlv(4, pem(name))))
|
||||
return sequence(oid("2a864886f70d010c0a0103"), explicit(cert_bag))
|
||||
|
||||
|
||||
def archive(name, *bags):
|
||||
(ROOT / name).write_bytes(sequence(tlv(2, b"\x03"), data(sequence(data(sequence(*bags))))))
|
||||
|
||||
|
||||
archive("no-bag-ids.p12", certificate("root.pem"), certificate("ec-cert.pem"),
|
||||
key("rsa-pkcs8.pem"), certificate("rsa-cert.pem"))
|
||||
archive("mismatched.p12", key("rsa-pkcs8.pem"), certificate("ec-cert.pem"), certificate("root.pem"))
|
||||
archive("multiple-identities.p12", key("rsa-pkcs8.pem"), key("ec-pkcs8.pem"),
|
||||
certificate("rsa-cert.pem"), certificate("ec-cert.pem"))
|
||||
@@ -49,7 +49,7 @@ done
|
||||
-passout pass:fixture-password -out rsa-pbes2-scrypt.pem
|
||||
"$openssl_bin" pkcs8 -topk8 -in rsa-pkcs8.pem -v1 PBE-SHA1-3DES \
|
||||
-passout pass:fixture-password -out rsa-pbes1-3des.pem
|
||||
for length in 1023 1024; do
|
||||
for length in 127 128; do
|
||||
printf -v password '%*s' "$length" ''
|
||||
password=${password// /x}
|
||||
"$openssl_bin" pkcs8 -topk8 -in rsa-pkcs8.pem -v1 PBE-SHA1-3DES \
|
||||
@@ -75,3 +75,6 @@ done
|
||||
-name fixture -passout pass:fixture-password -out certificate-only.pfx
|
||||
"$openssl_bin" pkcs12 -export -nocerts -inkey rsa-pkcs8.pem \
|
||||
-name fixture -passout pass:fixture-password -out key-only.pfx
|
||||
|
||||
# Plain PKCS#12 bags let the import tests omit optional IDs and reorder bags.
|
||||
python3 "$(dirname "$0")/generate-plain-pfx.py"
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,29 +0,0 @@
|
||||
-----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
MIIE6jAcBgoqhkiG9w0BDAEDMA4ECLOZZqD+VLtQAgIIAASCBMiGiqam4dNtVdxD
|
||||
KpskK3iDnYL00TNXKNeHM/vwsJp1J9l1oIUq9ftWd3hFucd3tfTBIyE3BB6tCxDh
|
||||
D3EJWeIvgIfsKLCX7vB4GJhUTBA4zVwKgdvr61RYpwd2MfJYXN3d3u0BkUDhyoSz
|
||||
lTheKH4Ip+/GG3jpyq2pbDjHTBEFW7b3JuM3nvnC6hDiVXtjFhfGKWwa/sOpfmyf
|
||||
20Nj0RGP0eIlVz9XGXuZ23VWk8u9oF3rVY18qRThyNSCPJG+qAgyuKioKqw1MOKZ
|
||||
1RjD1kiDwSnz+aDDSI8y5/XE883Nawd3Gvi3SyZXd4FWwd6G49zoPdyJsODZt04G
|
||||
DzdT0jeaCaPNkGO1xoZ2VVmlRhC7sB3Bf69kKsZOryLMuKGm9CLDWH78i6TjoQV+
|
||||
oVJjna1liFcw9ws1sZxagNsr1JxPuOTzNk9hzgBKl5LUUloIL1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HNEuOEpX
|
||||
GtM1QzGta4GbVNVue7XIRjiY/XPzQ1RmZPwOCzBi03PFwbt7zti13v0oQs49W7Yh
|
||||
5E+yu7PQPKxr1WbmmU8e0U5NF0bkPsFVauUKFCOC164nEn0zGZRSyFL54O7+lF+b
|
||||
zAPRM0zYEVbCkkQsF87ToGwPRY9LoNikP14MV1npujkWIK1wZ/eysBACDCdW8mxR
|
||||
X2ONO70h8TsO1R6KS5Y=
|
||||
-----END ENCRYPTED PRIVATE KEY-----
|
||||
@@ -1,29 +0,0 @@
|
||||
-----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
MIIE6jAcBgoqhkiG9w0BDAEDMA4ECOIH1TuPOHfxAgIIAASCBMgcv+kci9FRoLjr
|
||||
zYevFdoYS66/aUAy0V/173CuRMb1hzwsxfXeoRzTgXaWXUOExJX2PSCIai2cwCcj
|
||||
SvZUXPSQz+9aWrZjO/R+tWfKW0ttmT6Et2Kfps6MkJpRK/jbmaYOISpNa/8ROCty
|
||||
A7P6f4KNFeRhU89TgLqegm+so4un7d/n9vwYQBC1oCaRuCvxuNIugbnVKJkJ2RMx
|
||||
e7JLk16HVox8UGb66knS5kvaFVZZzJasmxN/tLg9kyomzopOMQZJ5E5uLD2CyndV
|
||||
Wh8OTwHbH6MOGOfhSi7eETWaveUvR9CMfm5YwTLM9RJHGlhl6J0NO8eZBd+IyA08
|
||||
jP2UYtLo2Lgx0ZobAUCfx9ZWFmQH//wnOyyiU4HzmIrUVUFPj2LsnYUyypAl54lp
|
||||
hFLf0P5oPFdNc1GfYEW7REBrJilj+4R1ycY1jw2o/WYntJUyFSYJ4rUXadzpv7el
|
||||
BGvbob04atktipdFF7Y/OfcOk0kuf/BdLNchayUYAHMNv8V+BB7c2EuiHA4Rg5sv
|
||||
J6egzKEpyJmdhvAWiEZavDpr0mz0KjZQVSGDmZ//ZWWponR/8vWhT2HRjFd6UAeP
|
||||
YFAnH+Hk8JlsGKcsrQMybECQTsyGNnUDlAZhu6doiWPGn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
||||
7gRfkOUwSwgzBYFu/2g=
|
||||
-----END ENCRYPTED PRIVATE KEY-----
|
||||
@@ -0,0 +1,29 @@
|
||||
-----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
MIIE6jAcBgoqhkiG9w0BDAEDMA4ECIxo5EM1S2OsAgIIAASCBMjM2XZlCdMDSMOP
|
||||
xn4TbkBNa5RKs5aZYMg+24UtEOjE2CB7ucX82FXDR3Q3SQklXW/8Fy7Gp5DNAqz2
|
||||
rFA8xzbawoFkQQyjOxCbJFqTqZfUgmxy5zhpZvBTLuP63FmMgRT0FRVDaCsXl0kd
|
||||
oWUd02YiM5PpRETM0dslck1IOib6GH7g699834LvMvYDeTp5N+ZWKgCAWAJUn1hs
|
||||
Xo5oBAaWhQGO4+B0gkAKZ34Wj1a6ebPVILngsF4ClLiUxMY0HoKwrEQHGqGj3piD
|
||||
VEWYwg6BoMerDro3fQXiu+K7uaqAAVh73aPikbfKubGhuWxt/BeFzYpkXZYt3q9C
|
||||
jbQUkyg3VUnPcRInjykH+7UzzcjDcyDaxmkdZIph9RdSgYr0aM0BSrcaDJv9uSDT
|
||||
wKCO0TDeEpCprTbMeu1NOiGANbZ4pfQpfbfSHd6eFsIEz8C/5/v6S/SIT0lh890t
|
||||
I878fj+EplQ0NX6oJFh4AYfO7U89R4OWq/xZ8jjx85USS7Jzgcl9kz5LgbTCLFXi
|
||||
GUMWmHop3AZhve2L2KXprEUrClVFS2V/PrfWf9aley0wkCBBLaLKsGz9xxh7Hv+D
|
||||
87q1WMP9Z+4/LMeihUmtun7cYYh/uYIGilvuxVmwchmmbge51sj8BBe2Kd6MQ8LB
|
||||
jlqLbhNY4AdiRq7rqyOasYoH2kKhVTSvP3x7NRDt1bgdK5BFtdbsy8LyfXCJfiBo
|
||||
zQBXRhfUsquuTLvt/1RMyygJlpihNET2hEvBz/dqCCumqgFZOBMBbOE9vxWQvFlL
|
||||
6c6/VtNw4eHaCe6OJF0zYRcPsZCknj/mxgU9zVHK+a7T3x+MjsjS4yTn637luDIV
|
||||
0p/7AJgjuzO9KnmMgL8ZY34aSazx908shnpLX/yFA4GSQ4kqqQ580bjz7kMHTS9b
|
||||
gGS5/uwywoG1n7m6VITZ1iLDAXvKu+s5rsR9y+fOn5LMpSAiQ/VMlgst9985XEYr
|
||||
L5CjfR6pThOjAgoBZfvVN6WjrQnc7NGEbfBc8o5BgR2xX0I8Z1o3lsDGB0eSEWA3
|
||||
iaTa2Y2UCKq241X2oKV3wIvFLQdsyP+JTdZGLgZCH8IiV+/6v2R95K/IOIzyl1LY
|
||||
smqU4YIBPFep2gK9YPOXl0/3r3o8RCqkE3TngM4MyAWT0qgaUpp+S/B+5k8VXeuK
|
||||
oJJnDaleq/6IIVljtP2Fz03oiykU0qfZy/xoW40GVAmB/grVMFnozinc8YJ7W/GC
|
||||
/wnz6ugOuJuOFB1c7RhyiqR8ioOxUWYs9iXA5CQqMIqxKLq2GI6ZgU08pGIFa85W
|
||||
TACqSCTS18otIWOPHcWH4Eait/MiMds78f+aizmq0ZYwGZac79sRByobIZzU/6q/
|
||||
wb/HQgwJD+AJDYMrUsTsrRIIAy9Qvq8MDsf9HDHCKXCWbew6hIoZJ8c/sZryKHnj
|
||||
lwCMJMHAjM1nDcdWOj6euF/3jA5gh9etxkpNw/gm8i2a1nRQtjWkAcICoTFl1QRX
|
||||
KfQv8URpe0XiNbBs26ABGJUKZHY+wCkWeE2AztR3cFf2AGDB7xI1OXK75BXOJiqC
|
||||
GYAuzRayZzXlPMWl4kEHQH8iGR5rI4LF/d72f3GTcof6IruSgj/Dk+i4e+JBMqth
|
||||
TPaNQWDea8ALdu0ZitE=
|
||||
-----END ENCRYPTED PRIVATE KEY-----
|
||||
@@ -0,0 +1,29 @@
|
||||
-----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
MIIE6jAcBgoqhkiG9w0BDAEDMA4ECJYKMPRWT41NAgIIAASCBMi9nkicRojhOxI4
|
||||
UZwVAHF0n4L0oWQFUCYyRjg8b7/ntN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IMO8KsOV/A969HtuXeXWu
|
||||
g5RIuFvJ0DTvuBNzknzgJWyhafyW/+4tPaUHR+Wf8dwAr36tkH06ZfOVTA96nIZ4
|
||||
z0tF896B8eEmXqwaGbRR6KcAYidGU9aubx0gjbowZwKjGmkoGzhk7cjUr3wE+bqD
|
||||
tlBnH9AA03sE3GAQ61TDTzHE3UMYKT/zkl03DGcMeoTi8H6y8Jn7GFlJVtj2IRGo
|
||||
ByBSZxDr0ylKB12+RQsgICJ0dIR/XF1ljdxgB8QOCPOAgL1GxrYpSvBoTLTr/YxX
|
||||
uqwUFYUO/HBiWk9t1tnBGAn3kvb9sOGm/lhME2TMNrzN1dMVUJVbFDz2cuIpo/i+
|
||||
GjCr3Cwh8Rx+uRHvuYrljWQQXaN2xOApGySsTZhavnVoBUQHq/X56MVgib8/nAYh
|
||||
Fc/T856Bx3fVe/HD8VPPl33iDylmoihjzFPhPkfTrCMk2nMYxWVLoxhjmkynPikR
|
||||
FR9sVUo/NwDzAnk0gykjiQ62AptceTW8k3Rl7eCctytUyFlsjkcFW43kgYOUhE9a
|
||||
rv6/PzRmYOjN27OIKIJ8SHhBhLKu5mH4QciH+QGRSLeAGNi+vN1SzuHBBuL1jKg7
|
||||
WEYP/1MOSL1b6UNPLhc=
|
||||
-----END ENCRYPTED PRIVATE KEY-----
|
||||
@@ -65,41 +65,40 @@ fn encrypted_der_preserves_password_errors() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ec_sec1_normalizes_on_linux_and_bsd_and_is_terminal_on_macos() {
|
||||
fn ec_sec1_pem_and_der_are_portable() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let key = directory.path().join("ec.der");
|
||||
fs::write(&key, pem::parse(bytes("ec-sec1.pem")).unwrap().contents()).unwrap();
|
||||
for source in [fixture("ec-sec1.pem"), key] {
|
||||
for password in [None, Some(PASSWORD)] {
|
||||
let result = load(&fixture("ec-cert.pem"), &source, password);
|
||||
if cfg!(target_os = "macos") {
|
||||
assert!(matches!(
|
||||
result.unwrap_err().downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::UnsupportedKeyFormat)
|
||||
));
|
||||
} else {
|
||||
assert_eq!(result.unwrap().key_data().unwrap(), bytes("ec-pkcs8.pem"));
|
||||
}
|
||||
let identity = load(&fixture("ec-cert.pem"), &source, password).unwrap();
|
||||
assert_eq!(identity.key_data().unwrap(), bytes("ec-sec1.pem"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn traditional_encrypted_pem_has_platform_specific_support_and_password_errors() {
|
||||
#[cfg(any(
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
fn traditional_encrypted_pem_preserves_password_errors() {
|
||||
for algorithm in ["rsa", "ec"] {
|
||||
for cipher in ["aes128", "aes192", "aes256", "des3"] {
|
||||
let certificate = fixture(&format!("{algorithm}-cert.pem"));
|
||||
let key = fixture(&format!("{algorithm}-traditional-{cipher}.pem"));
|
||||
for password in [None, Some("incorrect"), Some(PASSWORD)] {
|
||||
let result = load(&certificate, &key, password);
|
||||
if cfg!(target_os = "macos") {
|
||||
assert!(matches!(
|
||||
result.unwrap_err().downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::UnsupportedEncryption)
|
||||
));
|
||||
} else if password == Some(PASSWORD) {
|
||||
if password == Some(PASSWORD) {
|
||||
let identity = result.unwrap_or_else(|error| panic!("{key:?}: {error}"));
|
||||
assert_eq!(identity.key_data().unwrap(), bytes(&format!("{algorithm}-pkcs8.pem")));
|
||||
let actual = openssl::pkey::PKey::private_key_from_pem(identity.key_data().unwrap()).unwrap();
|
||||
let expected = openssl::pkey::PKey::private_key_from_pem(&bytes(&format!("{algorithm}-pkcs8.pem"))).unwrap();
|
||||
assert!(
|
||||
actual.public_eq(&expected),
|
||||
"{key:?}: imported key differs from the fixture"
|
||||
);
|
||||
assert!(identity.key_password().is_none());
|
||||
} else {
|
||||
let error = result.unwrap_err();
|
||||
@@ -115,7 +114,12 @@ fn traditional_encrypted_pem_has_platform_specific_support_and_password_errors()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
#[cfg(any(
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
fn traditional_passphrase_with_nul_returns_a_redacted_terminal_error() {
|
||||
let error = load(
|
||||
&fixture("rsa-cert.pem"),
|
||||
@@ -130,11 +134,16 @@ fn traditional_passphrase_with_nul_returns_a_redacted_terminal_error() {
|
||||
for diagnostic in [error.to_string(), format!("{error:?}")] {
|
||||
assert!(!diagnostic.contains("secret-password"));
|
||||
assert!(!diagnostic.contains("do-not-log"));
|
||||
assert!(!diagnostic.contains("115, 101, 99, 114, 101, 116"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
fn first_traditional_encrypted_key_controls_combined_pem_loading() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let source = directory.path().join("combined.pem");
|
||||
@@ -144,24 +153,14 @@ fn first_traditional_encrypted_key_controls_combined_pem_loading() {
|
||||
combined.extend(bytes("rsa-traditional-aes256.pem"));
|
||||
combined.extend(bytes("rsa-pkcs8.pem"));
|
||||
fs::write(&source, &combined).unwrap();
|
||||
for password in [None, Some(PASSWORD)] {
|
||||
let result = ClientIdentity::load(source.to_str().unwrap(), None, password);
|
||||
if cfg!(target_os = "macos") {
|
||||
assert!(matches!(
|
||||
result.unwrap_err().downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::UnsupportedEncryption)
|
||||
));
|
||||
} else if password.is_none() {
|
||||
assert!(matches!(
|
||||
result.unwrap_err().downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::NoPassphrase("PEM"))
|
||||
));
|
||||
} else {
|
||||
let identity = result.unwrap();
|
||||
assert_eq!(identity.certificate_data(), chain);
|
||||
assert_eq!(identity.key_data().unwrap(), bytes("rsa-pkcs8.pem"));
|
||||
}
|
||||
}
|
||||
let error = ClientIdentity::load(source.to_str().unwrap(), None, None).unwrap_err();
|
||||
assert!(matches!(
|
||||
error.downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::NoPassphrase("PEM"))
|
||||
));
|
||||
let identity = ClientIdentity::load(source.to_str().unwrap(), None, Some(PASSWORD)).unwrap();
|
||||
assert_eq!(identity.certificate_data(), chain);
|
||||
assert_eq!(identity.key_data().unwrap(), bytes("rsa-pkcs8.pem"));
|
||||
assert_eq!(fs::read(source).unwrap(), combined);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
use gpapi::{
|
||||
credential::{Credential, PasswordCredential},
|
||||
error::AuthenticationRejected,
|
||||
gateway::GatewayLoginClient,
|
||||
gp_params::GpParams,
|
||||
os_profile::{ClientOs, HostIdentity, HostSnapshot, OsProfile},
|
||||
portal,
|
||||
};
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
net::TcpListener,
|
||||
};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
#[tokio::test]
|
||||
async fn explicit_rejection_is_typed_for_ios_without_changing_desktop_errors() {
|
||||
for os in [ClientOs::Ios, ClientOs::Linux, ClientOs::Mac, ClientOs::Windows] {
|
||||
for status in [401, 403, 503] {
|
||||
for gateway in [false, true] {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let origin = format!("http://{}", listener.local_addr().unwrap());
|
||||
let server = tokio::spawn(async move {
|
||||
let (mut socket, _) = listener.accept().await.unwrap();
|
||||
let mut request = Vec::new();
|
||||
loop {
|
||||
let mut chunk = [0; 4096];
|
||||
let count = socket.read(&mut chunk).await.unwrap();
|
||||
if count == 0 {
|
||||
break;
|
||||
}
|
||||
request.extend_from_slice(&chunk[..count]);
|
||||
if let Some(end) = request.windows(4).position(|v| v == b"\r\n\r\n") {
|
||||
let headers = String::from_utf8_lossy(&request[..end]).to_lowercase();
|
||||
let length: usize = headers
|
||||
.lines()
|
||||
.find_map(|line| line.strip_prefix("content-length:").and_then(|s| s.trim().parse().ok()))
|
||||
.unwrap_or(0);
|
||||
if request.len() >= end + 4 + length {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
socket
|
||||
.write_all(format!("HTTP/1.1 {status} Test\r\nContent-Length: 0\r\nConnection: close\r\n\r\n").as_bytes())
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
let profile = OsProfile::builder(os).build(HostSnapshot {
|
||||
runtime_os: os,
|
||||
identity: HostIdentity::application("fixture".into(), "fixture-id".into()),
|
||||
os_version: "fixture".into(),
|
||||
software_version: String::new(),
|
||||
});
|
||||
let params = GpParams::builder(profile).build();
|
||||
let credential = Credential::Password(PasswordCredential::new("fixture", "fixture-password"));
|
||||
let token = CancellationToken::new();
|
||||
let error = if gateway {
|
||||
GatewayLoginClient::new(&origin, params)
|
||||
.unwrap()
|
||||
.login(&credential, None, &token)
|
||||
.await
|
||||
.err()
|
||||
.unwrap()
|
||||
} else {
|
||||
portal::retrieve_config(&origin, &credential, ¶ms, &token)
|
||||
.await
|
||||
.err()
|
||||
.unwrap()
|
||||
};
|
||||
server.await.unwrap();
|
||||
assert_eq!(
|
||||
error.is::<AuthenticationRejected>(),
|
||||
os == ClientOs::Ios && status != 503,
|
||||
"os={os:?}, status={status}, gateway={gateway}"
|
||||
);
|
||||
if os != ClientOs::Ios {
|
||||
let prefix = if gateway {
|
||||
"Gateway login error:"
|
||||
} else {
|
||||
"Portal config error:"
|
||||
};
|
||||
assert!(error.to_string().starts_with(prefix));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
use gpapi::{
|
||||
gp_params::GpParams,
|
||||
os_profile::{ClientOs, HostIdentity, OsProfile},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn mobile_profile_preserves_supplied_identity_without_hardware_claims() {
|
||||
let profile = OsProfile::builder(ClientOs::Ios).build(gpapi::os_profile::HostSnapshot {
|
||||
runtime_os: ClientOs::Ios,
|
||||
identity: HostIdentity::application("Phone".into(), "installation-id".into()),
|
||||
os_version: "Apple iOS 27.0.1".into(),
|
||||
software_version: String::new(),
|
||||
});
|
||||
assert_eq!(profile.client_os().as_str(), "iOS");
|
||||
assert_eq!(profile.client_os().to_openconnect_os(), "apple-ios");
|
||||
assert_eq!(profile.host_id(), "installation-id");
|
||||
assert_eq!(profile.computer(), "Phone");
|
||||
assert_eq!(profile.os_version(), "Apple iOS 27.0.1");
|
||||
assert!(profile.serialno().is_empty());
|
||||
assert!(profile.mac_addr().is_empty());
|
||||
assert!(!GpParams::builder(profile).build().ignore_tls_errors());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reported_profile_does_not_change_runtime_platform() {
|
||||
let profile = OsProfile::builder(ClientOs::Mac).build(gpapi::os_profile::HostSnapshot {
|
||||
runtime_os: ClientOs::Ios,
|
||||
identity: HostIdentity::application("Phone".into(), "installation-id".into()),
|
||||
os_version: "Apple iOS 27.0.1".into(),
|
||||
software_version: String::new(),
|
||||
});
|
||||
assert!(!profile.is_native());
|
||||
assert!(profile.os_version().starts_with("Apple Mac OS X "));
|
||||
assert_eq!(profile.host_identity().host_id(), "installation-id");
|
||||
}
|
||||
Reference in new issue
Block a user