Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: use DEFAULT_CIPHER_SUITES if none are specified #165

Closed
wants to merge 1 commit into from
Closed
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
33 changes: 20 additions & 13 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use libc::{c_char, size_t};
use rustls::client::{ResolvesClientCert, ServerCertVerified, ServerCertVerifier};
use rustls::{
sign::CertifiedKey, Certificate, ClientConfig, ClientConnection, ProtocolVersion,
RootCertStore, SupportedCipherSuite, WantsVerifier, ALL_CIPHER_SUITES,
RootCertStore, SupportedCipherSuite, WantsVerifier, ALL_CIPHER_SUITES, DEFAULT_CIPHER_SUITES,
};

use crate::cipher::{rustls_certified_key, rustls_root_cert_store, rustls_supported_ciphersuite};
Expand Down Expand Up @@ -110,10 +110,11 @@ impl rustls_client_config_builder {
/// Create a rustls_client_config_builder. Caller owns the memory and must
/// eventually call rustls_client_config_builder_build, then free the
/// resulting rustls_client_config. Specify cipher suites in preference
/// order; the `cipher_suites` parameter must point to an array containing
/// `len` pointers to `rustls_supported_ciphersuite` previously obtained
/// from `rustls_all_ciphersuites_get_entry()`. Set the TLS protocol
/// versions to use when negotiating a TLS session.
/// order; the `cipher_suites` parameter must either be null (default
/// suites will be used) or point to an array containing `len` pointers
/// to `rustls_supported_ciphersuite` objects previously obtained from
/// `rustls_all_ciphersuites_get_entry()`. Set the TLS protocol versions to
/// use when negotiating a TLS session.
///
/// `tls_version` is the version of the protocol, as defined in rfc8446,
/// ch. 4.2.1 and end of ch. 5.1. Some values are defined in
Expand All @@ -130,15 +131,21 @@ impl rustls_client_config_builder {
builder_out: *mut *mut rustls_client_config_builder,
) -> rustls_result {
ffi_panic_boundary! {
let cipher_suites: &[*const rustls_supported_ciphersuite] = try_slice!(cipher_suites, cipher_suites_len);
let mut cs_vec: Vec<SupportedCipherSuite> = Vec::new();
for &cs in cipher_suites.iter() {
let cs = try_ref_from_ptr!(cs);
match ALL_CIPHER_SUITES.iter().find(|&acs| cs.eq(acs)) {
Some(scs) => cs_vec.push(*scs),
None => return InvalidParameter,
let cs_vec: Vec<SupportedCipherSuite> = match cipher_suites.is_null() {
true => DEFAULT_CIPHER_SUITES.to_vec(),
false => {
let cipher_suites: &[*const rustls_supported_ciphersuite] = try_slice!(cipher_suites, cipher_suites_len);
let mut cs_vec = Vec::new();
for &cs in cipher_suites.iter() {
let cs = try_ref_from_ptr!(cs);
match ALL_CIPHER_SUITES.iter().find(|&acs| cs.eq(acs)) {
Some(scs) => cs_vec.push(*scs),
None => return InvalidParameter,
}
}
cs_vec
}
}
};

let tls_versions: &[u16] = try_slice!(tls_versions, tls_versions_len);
let mut versions = vec![];
Expand Down
9 changes: 5 additions & 4 deletions src/rustls.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,11 @@ struct rustls_client_config_builder *rustls_client_config_builder_new(void);
* Create a rustls_client_config_builder. Caller owns the memory and must
* eventually call rustls_client_config_builder_build, then free the
* resulting rustls_client_config. Specify cipher suites in preference
* order; the `cipher_suites` parameter must point to an array containing
* `len` pointers to `rustls_supported_ciphersuite` previously obtained
* from `rustls_all_ciphersuites_get_entry()`. Set the TLS protocol
* versions to use when negotiating a TLS session.
* order; the `cipher_suites` parameter must either be null (default
* suites will be used) or point to an array containing `len` pointers
* to `rustls_supported_ciphersuite` objects previously obtained from
* `rustls_all_ciphersuites_get_entry()`. Set the TLS protocol versions to
* use when negotiating a TLS session.
*
* `tls_version` is the version of the protocol, as defined in rfc8446,
* ch. 4.2.1 and end of ch. 5.1. Some values are defined in
Expand Down