diff --git a/openssl/src/pkcs12.rs b/openssl/src/pkcs12.rs index 31aae536d4..bd42f20a7d 100644 --- a/openssl/src/pkcs12.rs +++ b/openssl/src/pkcs12.rs @@ -26,6 +26,7 @@ impl Pkcs12Ref { /// Extracts the contents of the `Pkcs12`. // FIXME should take an &[u8] + #[cfg(not(all(target_arch = "x86", target_os = "android")))] pub fn parse(&self, pass: &str) -> Result { unsafe { let pass = CString::new(pass).unwrap(); @@ -56,6 +57,38 @@ impl Pkcs12Ref { }) } } + + #[cfg(all(target_arch = "x86", target_os = "android"))] + pub fn parse(&self, pass: &str) -> Result { + unsafe { + let pass = CString::new(pass).unwrap(); + + let mut pkey = ptr::null_mut(); + let mut cert = ptr::null_mut(); + let mut chain = ptr::null_mut(); + + try!(cvt(ffi::PKCS12_parse(self.as_ptr(), + pass.as_ptr() as *const i8, + &mut pkey, + &mut cert, + &mut chain))); + + let pkey = PKey::from_ptr(pkey); + let cert = X509::from_ptr(cert); + + let chain = if chain.is_null() { + try!(Stack::new()) + } else { + Stack::from_ptr(chain) + }; + + Ok(ParsedPkcs12 { + pkey: pkey, + cert: cert, + chain: chain, + }) + } + } } impl Pkcs12 { diff --git a/openssl/src/string.rs b/openssl/src/string.rs index 4a1d347959..4f3858b454 100644 --- a/openssl/src/string.rs +++ b/openssl/src/string.rs @@ -47,12 +47,21 @@ impl Stackable for OpensslString { impl Deref for OpensslStringRef { type Target = str; + #[cfg(not(all(target_arch = "x86", target_os = "android")))] fn deref(&self) -> &str { unsafe { let slice = CStr::from_ptr(self.as_ptr()).to_bytes(); str::from_utf8_unchecked(slice) } } + + #[cfg(all(target_arch = "x86", target_os = "android"))] + fn deref(&self) -> &str { + unsafe { + let slice = CStr::from_ptr(self.as_ptr() as *const u8).to_bytes(); + str::from_utf8_unchecked(slice) + } + } } impl fmt::Display for OpensslStringRef { diff --git a/openssl/src/version.rs b/openssl/src/version.rs index bf47695b81..9298a8552b 100644 --- a/openssl/src/version.rs +++ b/openssl/src/version.rs @@ -53,30 +53,55 @@ pub fn number() -> i64 { /// The text variant of the version number and the release date. For example, "OpenSSL 0.9.5a 1 Apr 2000". +#[cfg(not(all(target_arch = "x86", target_os = "android")))] pub fn version() -> &'static str { unsafe { CStr::from_ptr(OpenSSL_version(OPENSSL_VERSION)).to_str().unwrap() } } +#[cfg(all(target_arch = "x86", target_os = "android"))] +pub fn version() -> &'static str { + unsafe { CStr::from_ptr(OpenSSL_version(OPENSSL_VERSION) as *const u8).to_str().unwrap() } +} /// The compiler flags set for the compilation process in the form "compiler: ..." if available or /// "compiler: information not available" otherwise. +#[cfg(not(all(target_arch = "x86", target_os = "android")))] pub fn c_flags() -> &'static str { unsafe { CStr::from_ptr(OpenSSL_version(OPENSSL_CFLAGS)).to_str().unwrap() } } +#[cfg(all(target_arch = "x86", target_os = "android"))] +pub fn c_flags() -> &'static str { + unsafe { CStr::from_ptr(OpenSSL_version(OPENSSL_CFLAGS) as *const u8).to_str().unwrap() } +} /// The date of the build process in the form "built on: ..." if available or "built on: date not available" otherwise. +#[cfg(not(all(target_arch = "x86", target_os = "android")))] pub fn built_on() -> &'static str { unsafe { CStr::from_ptr(OpenSSL_version(OPENSSL_BUILT_ON)).to_str().unwrap() } } +#[cfg(all(target_arch = "x86", target_os = "android"))] +pub fn built_on() -> &'static str { + unsafe { CStr::from_ptr(OpenSSL_version(OPENSSL_BUILT_ON) as *const u8).to_str().unwrap() } +} /// The "Configure" target of the library build in the form "platform: ..." if available or "platform: information not available" otherwise. +#[cfg(not(all(target_arch = "x86", target_os = "android")))] pub fn platform() -> &'static str { unsafe { CStr::from_ptr(OpenSSL_version(OPENSSL_PLATFORM)).to_str().unwrap() } } +#[cfg(all(target_arch = "x86", target_os = "android"))] +pub fn platform() -> &'static str { + unsafe { CStr::from_ptr(OpenSSL_version(OPENSSL_PLATFORM) as *const u8).to_str().unwrap() } +} /// The "OPENSSLDIR" setting of the library build in the form "OPENSSLDIR: "..."" if available or "OPENSSLDIR: N/A" otherwise. +#[cfg(not(all(target_arch = "x86", target_os = "android")))] pub fn dir() -> &'static str { unsafe { CStr::from_ptr(OpenSSL_version(OPENSSL_DIR)).to_str().unwrap() } } +#[cfg(all(target_arch = "x86", target_os = "android"))] +pub fn dir() -> &'static str { + unsafe { CStr::from_ptr(OpenSSL_version(OPENSSL_DIR) as *const u8).to_str().unwrap() } +} /// This test ensures that we do not segfault when calling the functions of this module /// and that the strings respect a reasonable format. diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index bab1d711a8..5731873478 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -723,12 +723,21 @@ impl X509Name { /// Loads subject names from a file containing PEM-formatted certificates. /// /// This is commonly used in conjunction with `SslContextBuilder::set_client_ca_list`. + #[cfg(not(all(target_arch = "x86", target_os = "android")))] pub fn load_client_ca_file>(file: P) -> Result, ErrorStack> { let file = CString::new(file.as_ref().as_os_str().to_str().unwrap()).unwrap(); unsafe { cvt_p(ffi::SSL_load_client_CA_file(file.as_ptr())).map(|p| Stack::from_ptr(p)) } } + + #[cfg(all(target_arch = "x86", target_os = "android"))] + pub fn load_client_ca_file>(file: P) -> Result, ErrorStack> { + let file = CString::new(file.as_ref().as_os_str().to_str().unwrap()).unwrap(); + unsafe { + cvt_p(ffi::SSL_load_client_CA_file(file.as_ptr() as *const i8)).map(|p| Stack::from_ptr(p)) + } + } } impl Stackable for X509Name { @@ -1013,6 +1022,7 @@ impl X509VerifyError { self.0 } + #[cfg(not(all(target_arch = "x86", target_os = "android")))] pub fn error_string(&self) -> &'static str { ffi::init(); @@ -1021,6 +1031,16 @@ impl X509VerifyError { str::from_utf8(CStr::from_ptr(s).to_bytes()).unwrap() } } + + #[cfg(all(target_arch = "x86", target_os = "android"))] + pub fn error_string(&self) -> &'static str { + ffi::init(); + + unsafe { + let s = ffi::X509_verify_cert_error_string(self.0); + str::from_utf8(CStr::from_ptr(s as *const u8).to_bytes()).unwrap() + } + } } foreign_type! {