From 4afd36c9fdd9145187dc13c546849f728e3db9ac Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 2 Mar 2011 10:59:39 -0700 Subject: [PATCH] openssl: use libcrypto and libssl version 1.0 if available and single point of control for all uses --- collects/openssl/libcrypto.rkt | 22 +++++++++++++++ collects/openssl/libssl.rkt | 25 +++++++++++++++++ collects/openssl/mzssl.rkt | 32 ++++------------------ collects/openssl/sha1.rkt | 17 ++---------- collects/web-server/stuffers/hmac-sha1.rkt | 10 +------ 5 files changed, 55 insertions(+), 51 deletions(-) create mode 100644 collects/openssl/libcrypto.rkt create mode 100644 collects/openssl/libssl.rkt diff --git a/collects/openssl/libcrypto.rkt b/collects/openssl/libcrypto.rkt new file mode 100644 index 0000000000..9ae1086097 --- /dev/null +++ b/collects/openssl/libcrypto.rkt @@ -0,0 +1,22 @@ +#lang racket/base +(require ffi/unsafe + racket/runtime-path + (for-syntax racket/base)) + +(provide libcrypto + libcrypto-load-fail-reason) + +(define libcrypto-load-fail-reason #f) + +;; We need to declare because they might be distributed with PLT Scheme +;; in which case they should get bundled with stand-alone executables: +(define-runtime-path libcrypto-so + (case (system-type) + [(windows) '(so "libeay32")] + [else '(so "libcrypto")])) + +(define libcrypto + (with-handlers ([exn:fail? (lambda (x) + (set! libcrypto-load-fail-reason (exn-message x)) + #f)]) + (ffi-lib libcrypto-so '("" "1.0" "0.9.8b" "0.9.8" "0.9.7")))) diff --git a/collects/openssl/libssl.rkt b/collects/openssl/libssl.rkt new file mode 100644 index 0000000000..c6d93e825a --- /dev/null +++ b/collects/openssl/libssl.rkt @@ -0,0 +1,25 @@ +#lang racket/base +(require ffi/unsafe + racket/runtime-path + (for-syntax racket/base) + "libcrypto.rkt") + +(provide libssl + libssl-load-fail-reason) + +(define libssl-load-fail-reason #f) + +;; We need to declare because they might be distributed with PLT Scheme +;; in which case they should get bundled with stand-alone executables: +(define-runtime-path libssl-so + (case (system-type) + [(windows) '(so "ssleay32")] + [else '(so "libssl")])) + +(define libssl + (and libcrypto + (with-handlers ([exn:fail? + (lambda (x) + (set! libssl-load-fail-reason (exn-message x)) + #f)]) + (ffi-lib libssl-so '("" "1.0" "1.0.0a" "0.9.8b" "0.9.8" "0.9.7"))))) diff --git a/collects/openssl/mzssl.rkt b/collects/openssl/mzssl.rkt index 6bfca6e48a..fb687dd040 100644 --- a/collects/openssl/mzssl.rkt +++ b/collects/openssl/mzssl.rkt @@ -17,7 +17,8 @@ (module mzssl scheme (require mzlib/foreign mzlib/port - mzlib/runtime-path) + "libcrypto.rkt" + "libssl.rkt") (provide ssl-available? ssl-load-fail-reason @@ -51,35 +52,12 @@ (unsafe!) - ;; We need to declare because they might be distributed with PLT Scheme - ;; in which case they should get bundled with stand-alone executables: - (define-runtime-path libcrypto-so - (case (system-type) - [(windows) '(so "libeay32")] - [else '(so "libcrypto")])) - (define-runtime-path libssl-so - (case (system-type) - [(windows) '(so "ssleay32")] - [else '(so "libssl")])) - - (define ssl-load-fail-reason #f) + (define ssl-load-fail-reason + (or libssl-load-fail-reason + libcrypto-load-fail-reason)) (define 3m? (eq? '3m (system-type 'gc))) - (define libcrypto - (with-handlers ([exn:fail? (lambda (x) - (set! ssl-load-fail-reason (exn-message x)) - #f)]) - (ffi-lib libcrypto-so '("" "0.9.8b" "0.9.8" "0.9.7")))) - - (define libssl - (and libcrypto - (with-handlers ([exn:fail? - (lambda (x) - (set! ssl-load-fail-reason (exn-message x)) - #f)]) - (ffi-lib libssl-so '("" "0.9.8b" "0.9.8" "0.9.7"))))) - (define libmz (ffi-lib #f)) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/collects/openssl/sha1.rkt b/collects/openssl/sha1.rkt index b8f31a50a5..67283b4779 100644 --- a/collects/openssl/sha1.rkt +++ b/collects/openssl/sha1.rkt @@ -2,26 +2,13 @@ (require ffi/unsafe racket/runtime-path (for-syntax racket/base) - (prefix-in r: file/sha1)) + (prefix-in r: file/sha1) + "libcrypto.rkt") (provide sha1 sha1-bytes (rename-out [r:bytes->hex-string bytes->hex-string])) -(define-runtime-path libcrypto-so - (case (system-type) - [(windows) '(so "libeay32")] - [else '(so "libcrypto")])) - -(define libcrypto - (with-handlers ([exn:fail? (lambda (exn) - (log-warning (format "warning: couldn't load OpenSSL library: ~a" - (if (exn? exn) - (exn-message exn) - exn))) - #f)]) - (ffi-lib libcrypto-so '("" "0.9.8b" "0.9.8" "0.9.7")))) - (define _SHA_CTX-pointer _pointer) (define SHA1_Init diff --git a/collects/web-server/stuffers/hmac-sha1.rkt b/collects/web-server/stuffers/hmac-sha1.rkt index 8d236f8366..c9ccbfa225 100644 --- a/collects/web-server/stuffers/hmac-sha1.rkt +++ b/collects/web-server/stuffers/hmac-sha1.rkt @@ -1,18 +1,10 @@ #lang racket (require web-server/stuffers/stuffer racket/runtime-path + openssl/libcrypto (rename-in ffi/unsafe [-> f->])) -(define-runtime-path libcrypto-so - (case (system-type) - [(windows) '(so "libeay32")] - [else '(so "libcrypto")])) - -(define libcrypto - (with-handlers ([exn:fail? (lambda (x) #f)]) - (ffi-lib libcrypto-so '("" "0.9.8b" "0.9.8" "0.9.7")))) - (define EVP_SHA1 (and libcrypto (get-ffi-obj 'EVP_sha1 libcrypto