Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ jobs:
with:
toolchain: ${{ matrix.rust }}

- uses: actions/cache@v5
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
key: cratesio-${{ runner.os }}-${{ hashFiles('Cargo.toml') }}

- name: Fix time MSRV
run: |
cargo update -p time --precise 0.3.41
Expand All @@ -51,6 +58,13 @@ jobs:
toolchain: stable
components: clippy, rustfmt

- uses: actions/cache@v5
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
key: cratesio-${{ runner.os }}-${{ hashFiles('Cargo.toml') }}

- name: DO NOT USE RUSTFMT
run: "if cargo fmt --quiet --check -- --config-path=/dev/null; then echo >&2 'Do not reformat the code with rustfmt. This project does not use rustfmt.'; fi"

Expand All @@ -73,6 +87,13 @@ jobs:
toolchain: stable
target: aarch64-apple-ios,x86_64-apple-darwin

- uses: actions/cache/restore@v5
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
key: cratesio-${{ runner.os }}-${{ hashFiles('Cargo.toml') }}

- name: Run check iOS
run: cargo check --all-features -p security-framework --target aarch64-apple-ios

Expand Down
4 changes: 2 additions & 2 deletions security-framework/src/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ mod test {
let (_, name) = X509Name::from_der(&issuer).unwrap();
let name_str = name.to_string_with_registry(oid_registry()).unwrap();
assert_eq!(
"C=US, ST=CALIFORNIA, L=PALO ALTO, O=FOOBAR LLC, OU=DEV LAND, CN=FOOBAR.COM",
"C=US, ST=California, L=Palo Alto, O=Foobar LLC, OU=Dev Land, CN=foobar.com",
name_str
);
}
Expand All @@ -268,7 +268,7 @@ mod test {
let (_, name) = X509Name::from_der(&subject).unwrap();
let name_str = name.to_string_with_registry(oid_registry()).unwrap();
assert_eq!(
"C=US, ST=CALIFORNIA, L=PALO ALTO, O=FOOBAR LLC, OU=DEV LAND, CN=FOOBAR.COM",
"C=US, ST=California, L=Palo Alto, O=Foobar LLC, OU=Dev Land, CN=foobar.com",
name_str
);
}
Expand Down
10 changes: 5 additions & 5 deletions security-framework/src/cms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ mod tests {
}

#[test]
fn test_decode_encrypted() {
fn test_decode_encrypted_with_keystore_identities() {
let _ = import_keystore();

let decoder = CMSDecoder::create().expect("create");
Expand All @@ -528,7 +528,7 @@ mod tests {
}

#[test]
fn test_decode_signed_and_encrypted() {
fn test_decode_signed_and_encrypted_with_keystore_identities() {
let _ = import_keystore();

let decoder = CMSDecoder::create().unwrap();
Expand All @@ -552,7 +552,7 @@ mod tests {
}

#[test]
fn test_encode_encrypted() {
fn test_encode_encrypted_with_keystore_identities() {
let identities = import_keystore();

let chain = identities
Expand All @@ -575,7 +575,7 @@ mod tests {
}

#[test]
fn test_encode_signed_encrypted() {
fn test_encode_signed_encrypted_with_keystore_identities() {
let identities = import_keystore();

let chain = identities
Expand Down Expand Up @@ -603,7 +603,7 @@ mod tests {
}

#[test]
fn test_encode_with_cms_encoder() {
fn test_encode_with_cms_encoder_with_keystore_identities() {
let identities = import_keystore();

let chain = identities
Expand Down
7 changes: 7 additions & 0 deletions security-framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ fn cvt(err: OSStatus) -> Result<()> {
mod test {
use crate::certificate::SecCertificate;

/// Returns the server certificate (for certificate parsing/identity tests)
pub fn certificate() -> SecCertificate {
let certificate = include_bytes!("../test/server.der");
p!(SecCertificate::from_der(certificate))
}

/// Returns the CA certificate (trust anchor for TLS verification)
pub fn ca_certificate() -> SecCertificate {
let certificate = include_bytes!("../test/ca.der");
p!(SecCertificate::from_der(certificate))
}
}
5 changes: 3 additions & 2 deletions security-framework/src/os/macos/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ mod test {
fn fingerprint() {
let certificate = certificate();
let fingerprint = p!(certificate.fingerprint());
assert_eq!("af9dd180a326ae08b37e6398f9262f8b9d4c55674a233a7c84975024f873655d", hex::encode(fingerprint));
assert_eq!(fingerprint.len(), 32);
}

#[test]
Expand All @@ -229,6 +229,7 @@ mod test {
PropertyType::String(ref s) => s.to_string(),
_ => panic!(),
};
assert_eq!(algorithm, "1.2.840.113549.1.1.5");
// 1.2.840.113549.1.1.11 = sha256WithRSAEncryption
assert_eq!(algorithm, "1.2.840.113549.1.1.11");
}
}
17 changes: 5 additions & 12 deletions security-framework/src/os/macos/import_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,12 @@ mod test {
.unwrap();

let data = include_bytes!("../../../test/server.p12");
let mut items = SecItems::default();
ImportOptions::new()
.filename("server.p12")
let identities = Pkcs12ImportOptions::new()
.passphrase("password123")
.items(&mut items)
.keychain(&keychain)
.keychain(keychain)
.import(data)
.unwrap();
assert_eq!(1, items.identities.len());
assert_eq!(0, items.certificates.len());
assert_eq!(0, items.keys.len());
assert_eq!(1, identities.len());
}

#[test]
Expand Down Expand Up @@ -357,9 +352,7 @@ mod test {
.keychain(keychain)
.import(data));
assert_eq!(1, identities.len());
assert_eq!(
hex::encode(identities[0].key_id.as_ref().unwrap()),
"ed6492936dcc8907e397e573b36e633458dc33f1"
);
assert!(identities[0].key_id.is_some());
assert_eq!(identities[0].key_id.as_ref().unwrap().len(), 20);
}
}
3 changes: 0 additions & 3 deletions security-framework/src/os/macos/passwords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ mod test {
}

#[test]
#[ignore]
fn default_keychain_test_missing_password_default() {
let service = "default_this_service_does_not_exist";
let account = "this_account_is_bogus";
Expand All @@ -404,7 +403,6 @@ mod test {
}

#[test]
#[ignore]
fn default_keychain_test_round_trip_password_default() {
let service = "test_round_trip_password_default";
let account = "this_is_the_test_account";
Expand Down Expand Up @@ -450,7 +448,6 @@ mod test {
}

#[test]
#[ignore]
fn default_keychain_test_change_password_default() {
let service = "test_change_password_default";
let account = "this_is_the_test_account";
Expand Down
21 changes: 8 additions & 13 deletions security-framework/src/os/macos/secure_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,9 @@ mod test {
use crate::cipher_suite::CipherSuite;
use crate::os::macos::test::identity;
use crate::secure_transport::*;
use crate::test::certificate;
use crate::test::ca_certificate;

#[test]
#[ignore = "needs certs re-generated"]
fn server_client() {
let listener = p!(TcpListener::bind("localhost:0"));
let port = p!(listener.local_addr()).port();
Expand Down Expand Up @@ -235,7 +234,7 @@ mod test {

assert!(stream.server_auth_completed());
let mut peer_trust = p!(stream.context().peer_trust2()).unwrap();
p!(peer_trust.set_anchor_certificates(&[certificate()]));
p!(peer_trust.set_anchor_certificates(&[ca_certificate()]));
p!(peer_trust.evaluate_with_error());

let mut stream = p!(stream.handshake());
Expand All @@ -245,7 +244,6 @@ mod test {
}

#[test]
#[ignore]
fn server_client_builders() {
let listener = p!(TcpListener::bind("localhost:0"));
let port = p!(listener.local_addr()).port();
Expand All @@ -266,7 +264,7 @@ mod test {

let stream = p!(TcpStream::connect(("localhost", port)));
let mut stream = p!(ClientBuilder::new()
.anchor_certificates(&[certificate()])
.anchor_certificates(&[ca_certificate()])
.handshake("foobar.com", stream));

p!(stream.write_all(b"hello world!"));
Expand Down Expand Up @@ -299,7 +297,6 @@ mod test {
}

#[test]
#[ignore]
fn client() {
let listener = p!(TcpListener::bind("localhost:0"));
let port = p!(listener.local_addr()).port();
Expand All @@ -321,7 +318,7 @@ mod test {

let stream = p!(TcpStream::connect(("localhost", port)));
let mut stream = p!(ClientBuilder::new()
.anchor_certificates(&[certificate()])
.anchor_certificates(&[ca_certificate()])
.handshake("foobar.com", stream));
p!(stream.write_all(b"hello world!"));

Expand Down Expand Up @@ -400,7 +397,7 @@ mod test {
let identity = identity(dir.path());
p!(ctx.set_certificate(&identity, &[]));
p!(ctx.set_client_side_authenticate(SslAuthenticate::TRY));
let cert = certificate();
let cert = ca_certificate();
p!(ctx.add_certificate_authorities(&[cert]));

let stream = p!(listener.accept()).0;
Expand Down Expand Up @@ -514,12 +511,11 @@ mod test {
fn certificate_authorities() {
let mut ctx = p!(SslContext::new(SslProtocolSide::SERVER, SslConnectionType::STREAM));
assert!(p!(ctx.certificate_authorities()).is_none());
p!(ctx.set_certificate_authorities(&[certificate()]));
p!(ctx.set_certificate_authorities(&[ca_certificate()]));
assert_eq!(p!(ctx.certificate_authorities()).unwrap().len(), 1);
}

#[test]
#[ignore]
fn close() {
let listener = p!(TcpListener::bind("localhost:0"));
let port = p!(listener.local_addr()).port();
Expand All @@ -537,7 +533,7 @@ mod test {

let stream = p!(TcpStream::connect(("localhost", port)));
let mut stream = p!(ClientBuilder::new()
.anchor_certificates(&[certificate()])
.anchor_certificates(&[ca_certificate()])
.handshake("foobar.com", stream));

let mut buf = [0; 1];
Expand All @@ -548,7 +544,6 @@ mod test {
}

#[test]
#[ignore]
fn short_read() {
let listener = p!(TcpListener::bind("localhost:0"));
let port = p!(listener.local_addr()).port();
Expand All @@ -569,7 +564,7 @@ mod test {

let stream = p!(TcpStream::connect(("localhost", port)));
let mut stream = p!(ClientBuilder::new()
.anchor_certificates(&[certificate()])
.anchor_certificates(&[ca_certificate()])
.handshake("foobar.com", stream));

let mut b = [0; 1];
Expand Down
10 changes: 6 additions & 4 deletions security-framework/src/trust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ mod test {
trust.evaluate().unwrap();

let count = trust.certificate_count();
assert_eq!(count, 1);
// 1 (self-signed) or 2 (CA-signed, macOS builds chain)
assert!(count >= 1);

let cert_bytes = trust.certificate_at_index(0).unwrap().to_der();
assert_eq!(cert_bytes, certificate().to_der());
Expand All @@ -328,7 +329,8 @@ mod test {
assert!(trust.evaluate_with_error().is_err());

let count = trust.certificate_count();
assert_eq!(count, 1);
// 1 (self-signed) or 2 (CA-signed, macOS builds chain)
assert!(count >= 1);

let cert_bytes = trust.certificate_at_index(0).unwrap().to_der();
assert_eq!(cert_bytes, certificate().to_der());
Expand All @@ -342,11 +344,11 @@ mod test {

let trust = SecTrust::create_with_certificates(std::slice::from_ref(&cert), std::slice::from_ref(&ssl_policy)).unwrap();
trust.evaluate().unwrap();
assert!(trust.certificate_at_index(1).is_none());
assert!(trust.certificate_at_index(10).is_none());

let trust = SecTrust::create_with_certificates(&[cert], &[ssl_policy]).unwrap();
assert!(trust.evaluate_with_error().is_err());
assert!(trust.certificate_at_index(1).is_none());
assert!(trust.certificate_at_index(10).is_none());
}

#[test]
Expand Down
Binary file added security-framework/test/ca.der
Binary file not shown.
Binary file modified security-framework/test/cms/encrypted.p7m
Binary file not shown.
Binary file modified security-framework/test/cms/keystore.p12
Binary file not shown.
Binary file modified security-framework/test/cms/signed-encrypted.p7m
Binary file not shown.
Binary file modified security-framework/test/cms/signed.p7m
Binary file not shown.
Loading
Loading