openssl: use libcrypto and libssl version 1.0 if available

and single point of control for all uses
This commit is contained in:
Matthew Flatt 2011-03-02 10:59:39 -07:00
parent ec2a917749
commit 4afd36c9fd
5 changed files with 55 additions and 51 deletions

View File

@ -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"))))

View File

@ -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")))))

View File

@ -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))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -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

View File

@ -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