Skip to content

fix cross compile with target i686-linux-android #626

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

Closed
wants to merge 2 commits 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: 33 additions & 0 deletions openssl/src/pkcs12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParsedPkcs12, ErrorStack> {
unsafe {
let pass = CString::new(pass).unwrap();
Expand Down Expand Up @@ -56,6 +57,38 @@ impl Pkcs12Ref {
})
}
}

#[cfg(all(target_arch = "x86", target_os = "android"))]
pub fn parse(&self, pass: &str) -> Result<ParsedPkcs12, ErrorStack> {
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 {
Expand Down
9 changes: 9 additions & 0 deletions openssl/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions openssl/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions openssl/src/x509/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: AsRef<Path>>(file: P) -> Result<Stack<X509Name>, 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<P: AsRef<Path>>(file: P) -> Result<Stack<X509Name>, 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 {
Expand Down Expand Up @@ -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();

Expand All @@ -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! {
Expand Down