mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 06:26:14 -05:00
refactor: replace OpenSSL transports and certificate imports
This commit is contained in:
59 files changed
+1072
-1151
No files matched your search
@@ -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,32 @@ 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-{1023,1024}.pem` | Same encryption with 1023- and 1024-byte passwords; both import without executable line limits |
|
||||
| `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.
|
||||
PBES2, including scrypt, stays in Rust. 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"))
|
||||
@@ -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.
Reference in new issue
Block a user