Move macro replicas into C shim
This commit is contained in:
parent
d9337bf699
commit
d0b769c93c
|
|
@ -15,7 +15,7 @@ fn main() {
|
|||
|
||||
if lib_dir.is_none() && include_dir.is_none() {
|
||||
if let Ok(info) = pkg_config::find_library("openssl") {
|
||||
build_old_openssl_shim(&info.include_paths);
|
||||
build_openssl_shim(&info.include_paths);
|
||||
return;
|
||||
}
|
||||
if let Some(mingw_paths) = get_mingw_in_path() {
|
||||
|
|
@ -58,18 +58,18 @@ fn main() {
|
|||
include_dirs.push(PathBuf::from(&include_dir));
|
||||
}
|
||||
|
||||
build_old_openssl_shim(&include_dirs);
|
||||
build_openssl_shim(&include_dirs);
|
||||
}
|
||||
|
||||
fn build_old_openssl_shim(include_paths: &[PathBuf]) {
|
||||
fn build_openssl_shim(include_paths: &[PathBuf]) {
|
||||
let mut config = gcc::Config::new();
|
||||
|
||||
for path in include_paths {
|
||||
config.include(path);
|
||||
}
|
||||
|
||||
config.file("src/old_openssl_shim.c")
|
||||
.compile("libold_openssl_shim.a");
|
||||
config.file("src/openssl_shim.c")
|
||||
.compile("libopenssl_shim.a");
|
||||
}
|
||||
|
||||
fn get_mingw_in_path() -> Option<Vec<String>> {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ extern crate libressl_pnacl_sys;
|
|||
|
||||
use libc::{c_void, c_int, c_char, c_ulong, c_long, c_uint, c_uchar, size_t};
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
|
||||
|
|
@ -263,35 +262,6 @@ pub fn init() {
|
|||
}
|
||||
}
|
||||
|
||||
// Functions converted from macros
|
||||
pub unsafe fn BIO_eof(b: *mut BIO) -> bool {
|
||||
BIO_ctrl(b, BIO_CTRL_EOF, 0, ptr::null_mut()) == 1
|
||||
}
|
||||
|
||||
pub unsafe fn SSL_CTX_set_options(ssl: *mut SSL_CTX, op: c_long) -> c_long {
|
||||
SSL_CTX_ctrl(ssl, SSL_CTRL_OPTIONS, op, ptr::null_mut())
|
||||
}
|
||||
|
||||
pub unsafe fn BIO_set_mem_eof_return(b: *mut BIO, v: c_int) {
|
||||
BIO_ctrl(b, BIO_C_SET_BUF_MEM_EOF_RETURN, v as c_long, ptr::null_mut());
|
||||
}
|
||||
|
||||
pub unsafe fn SSL_CTX_get_options(ssl: *mut SSL_CTX) -> c_long {
|
||||
SSL_CTX_ctrl(ssl, SSL_CTRL_OPTIONS, 0, ptr::null_mut())
|
||||
}
|
||||
|
||||
pub unsafe fn SSL_CTX_clear_options(ssl: *mut SSL_CTX, op: c_long) -> c_long {
|
||||
SSL_CTX_ctrl(ssl, SSL_CTRL_CLEAR_OPTIONS, (op), ptr::null_mut())
|
||||
}
|
||||
|
||||
pub unsafe fn SSL_CTX_add_extra_chain_cert(ssl: *mut SSL_CTX, cert: *mut X509) -> c_long {
|
||||
SSL_CTX_ctrl(ssl, SSL_CTRL_EXTRA_CHAIN_CERT, 0, cert)
|
||||
}
|
||||
|
||||
pub unsafe fn SSL_CTX_set_read_ahead(ctx: *mut SSL_CTX, m: c_long) -> c_long {
|
||||
SSL_CTX_ctrl(ctx, SSL_CTRL_SET_READ_AHEAD, m, ptr::null_mut())
|
||||
}
|
||||
|
||||
// True functions
|
||||
extern "C" {
|
||||
pub fn ASN1_INTEGER_set(dest: *mut ASN1_INTEGER, value: c_long) -> c_int;
|
||||
|
|
@ -610,6 +580,22 @@ extern "C" {
|
|||
pub fn d2i_RSA_PUBKEY(k: *const *mut RSA, buf: *const *const u8, len: c_uint) -> *mut RSA;
|
||||
pub fn i2d_RSAPrivateKey(k: *mut RSA, buf: *const *mut u8) -> c_int;
|
||||
pub fn d2i_RSAPrivateKey(k: *const *mut RSA, buf: *const *const u8, len: c_uint) -> *mut RSA;
|
||||
|
||||
// These functions are defined in OpenSSL as macros, so we shim them
|
||||
#[link_name = "BIO_eof_shim"]
|
||||
pub fn BIO_eof(b: *mut BIO) -> c_int;
|
||||
#[link_name = "BIO_set_mem_eof_return_shim"]
|
||||
pub fn BIO_set_mem_eof_return(b: *mut BIO, v: c_int);
|
||||
#[link_name = "SSL_CTX_set_options_shim"]
|
||||
pub fn SSL_CTX_set_options(ctx: *mut SSL_CTX, options: c_long) -> c_long;
|
||||
#[link_name = "SSL_CTX_get_options_shim"]
|
||||
pub fn SSL_CTX_get_options(ctx: *mut SSL_CTX) -> c_long;
|
||||
#[link_name = "SSL_CTX_clear_options_shim"]
|
||||
pub fn SSL_CTX_clear_options(ctx: *mut SSL_CTX, options: c_long) -> c_long;
|
||||
#[link_name = "SSL_CTX_add_extra_chain_cert_shim"]
|
||||
pub fn SSL_CTX_add_extra_chain_cert(ctx: *mut SSL_CTX, x509: *mut X509) -> c_long;
|
||||
#[link_name = "SSL_CTX_set_read_ahead_shim"]
|
||||
pub fn SSL_CTX_set_read_ahead(ctx: *mut SSL_CTX, m: c_long) -> c_long;
|
||||
}
|
||||
|
||||
pub mod probe;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include <openssl/hmac.h>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x1000000L
|
||||
// Copied from openssl crypto/hmac/hmac.c
|
||||
|
|
@ -47,3 +48,33 @@ int HMAC_Final_shim(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) {
|
|||
return HMAC_Final(ctx, md, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
// shims for OpenSSL macros
|
||||
|
||||
int BIO_eof_shim(BIO *b) {
|
||||
return BIO_eof(b);
|
||||
}
|
||||
|
||||
void BIO_set_mem_eof_return_shim(BIO *b, int v) {
|
||||
BIO_set_mem_eof_return(b, v);
|
||||
}
|
||||
|
||||
long SSL_CTX_set_options_shim(SSL_CTX *ctx, long options) {
|
||||
return SSL_CTX_set_options(ctx, options);
|
||||
}
|
||||
|
||||
long SSL_CTX_get_options_shim(SSL_CTX *ctx) {
|
||||
return SSL_CTX_get_options(ctx);
|
||||
}
|
||||
|
||||
long SSL_CTX_clear_options_shim(SSL_CTX *ctx, long options) {
|
||||
return SSL_CTX_clear_options(ctx, options);
|
||||
}
|
||||
|
||||
long SSL_CTX_add_extra_chain_cert_shim(SSL_CTX *ctx, X509 *x509) {
|
||||
return SSL_CTX_add_extra_chain_cert(ctx, x509);
|
||||
}
|
||||
|
||||
long SSL_CTX_set_read_ahead_shim(SSL_CTX *ctx, long m) {
|
||||
return SSL_CTX_set_read_ahead(ctx, m);
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ impl Read for MemBio {
|
|||
|
||||
if ret <= 0 {
|
||||
let is_eof = unsafe { ffi::BIO_eof(self.bio) };
|
||||
if is_eof {
|
||||
if is_eof != 0 {
|
||||
Ok(0)
|
||||
} else {
|
||||
Err(io::Error::new(io::ErrorKind::Other,
|
||||
|
|
|
|||
Loading…
Reference in New Issue