Coverage report: /home/ellis/.stash/lisp/cl-plus-ssl/src/reload.lisp

KindCoveredAll%
expression538 13.2
branch18 12.5
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*-
2
 ;;;
3
 ;;; Copyright (C) 2001, 2003  Eric Marsden
4
 ;;; Copyright (C) 2005  David Lichteblau
5
 ;;; "the conditions and ENSURE-SSL-FUNCALL are by Jochen Schmidt."
6
 ;;; Copyright (C) contributors as per cl+ssl git history
7
 ;;;
8
 ;;; See LICENSE for details.
9
 
10
 ;;; We do this in an extra file so that it happens
11
 ;;;   - before ssl.lisp is loaded, which needs the library at compilation
12
 ;;;     time on some implemenations
13
 ;;;   - but not every time ffi.lisp is re-loaded as would happen if we
14
 ;;;     put this directly into ffi.lisp
15
 
16
 (in-package :cl+ssl)
17
 
18
 ;; The default OS-X libssl seems have had insufficient crypto algos
19
 ;; (missing TLSv1_[1,2]_XXX methods,
20
 ;; see https://github.com/cl-plus-ssl/cl-plus-ssl/issues/56)
21
 ;; so first try to load possible custom installations of libssl.
22
 ;; However, macOS can crash the process if we try to load
23
 ;; an unexisting path, see
24
 ;; https://github.com/cl-plus-ssl/cl-plus-ssl/issues/138
25
 ;; and the discussion in
26
 ;; https://github.com/cl-plus-ssl/cl-plus-ssl/issues/114.
27
 ;; Therefore we first detect the presence of custom installations,
28
 ;; remember them as special *features* flags, which we then use
29
 ;; as conditions in the CFFI library definitions.
30
 
31
 (defun detect-macos-custom-openssl-installations ()
32
   (dolist (dir-feature '(("/opt/local/lib/" :cl+ssl-macports-found)
33
                          ("/sw/lib/" :cl+ssl-fink-found)
34
                          ("/usr/local/opt/openssl/lib/" :cl+ssl-homebrew-found)
35
                          ("/opt/homebrew/opt/openssl/lib/" :cl+ssl-homebrew-arm64-found)
36
                          ("/usr/local/lib/" :cl+ssl-personalized-install-found)))
37
     (destructuring-bind (dir feature) dir-feature
38
       (if (and (probe-file (concatenate 'string dir "libssl.dylib"))
39
                (probe-file (concatenate 'string dir "libcrypto.dylib")))
40
           (pushnew feature *features*)
41
           (setf *features* (remove feature *features*))))))
42
 
43
 (defun detect-custom-openssl-installations-if-macos ()
44
   ;; Instead of a read-time conditional we use
45
   ;; a run-time check, so that it works even
46
   ;; for compiled code or images built on another
47
   ;; platform and then reloaded on macOS.
48
   (when (member :darwin *features*)
49
     (detect-macos-custom-openssl-installations)))
50
 
51
 (detect-custom-openssl-installations-if-macos)
52
 
53
 #|
54
 
55
 A manual test that I used on Linux for the above
56
 macOS OpenSSL custom installation detection code.
57
 
58
 sudo mkdir -p /sw/lib
59
 sudo touch /sw/lib/libssl.dylib /sw/lib/libcrypto.dylib
60
 
61
 sudo touch /usr/local/lib/libcrypto.dylib /usr/local/lib/libssl.dylib
62
 
63
 (detect-macos-custom-openssl-installations)
64
 (remove-if-not (lambda (f) (search "cl+ssl" (string-downcase f)))
65
                *features*)
66
 
67
 sudo rm -rf /sw/
68
 sudo rm /usr/local/lib/libcrypto.dylib /usr/local/lib/libssl.dylib
69
 
70
 |#
71
 
72
 
73
 ;; Windows builds have been naming librypto and libssl DLLs
74
 ;; in several different ways:
75
 ;;
76
 ;; - libeay32.dll, libssl32.dll
77
 ;; - libeay32.dll, ssleay32.dll
78
 ;;
79
 ;; Note, the above names were used both for 32 and 64 -bit versions.
80
 ;;
81
 ;; - libcrypto-1_1-x64.dll, libssl-1_1-x64.dll
82
 ;;
83
 ;; The above are used for 64-bit only.
84
 ;;
85
 ;; - libcrypto-1_1.dll, libssl-1_1.dll
86
 ;;
87
 ;; These are 32-bit only.
88
 
89
 (unless cl+ssl/config::*libcrypto-override*
90
   (cffi:define-foreign-library libcrypto
91
     (:windows (:or #+(and windows x86-64) "libcrypto-3-x64.dll"
92
                    #+(and windows x86) "libcrypto-3.dll"
93
                    #+(and windows x86-64) "libcrypto-1_1-x64.dll"
94
                    #+(and windows x86) "libcrypto-1_1.dll"
95
                    "libeay32.dll"))
96
     ;; Unlike some other systems, OpenBSD linker,
97
     ;; when passed library name without versions at the end,
98
     ;; will locate the library with highest major.minor version,
99
     ;; so we can just use just "libssl.so".
100
     ;; More info at https://github.com/cl-plus-ssl/cl-plus-ssl/pull/2.
101
     (:openbsd "libcrypto.so")
102
 
103
     ((:and :darwin :cl+ssl-macports-found) "/opt/local/lib/libcrypto.dylib")
104
     ((:and :darwin :cl+ssl-fink-found) "/sw/lib/libcrypto.dylib")
105
     ((:and :darwin :arm64 :cl+ssl-homebrew-arm64-found) "/opt/homebrew/opt/openssl/lib/libcrypto.dylib")
106
     ((:and :darwin
107
            ;; despite Homebriew currently only
108
            ;; supports :arm64 and :x86-64,
109
            ;; we don't use the :x86-64 feature,
110
            ;; because the same directory prefix
111
            ;; seems to be used by Tigerbiew,
112
            ;; which supports PPC and :x86.
113
            (:not :arm64)
114
            :cl+ssl-homebrew-found) "/usr/local/opt/openssl/lib/libcrypto.dylib")
115
     ((:and :darwin :cl+ssl-personalized-install-found) "/usr/local/lib/libcrypto.dylib")
116
     (:darwin (:or ;; System-provided libraries. Must be loaded from files with
117
                   ;; names that include version explicitly, instead of any
118
                   ;; versionless symlink file. Otherwise macOS crushes the
119
                   ;; process (starting from macOS > 10.15 that was just a
120
                   ;; warning, and finally macOS >= 11 crashes the process with a
121
                   ;; fatal error) Please note that in macOS >= 11.0, these paths
122
                   ;; may not exist in the file system anymore, but trying to
123
                   ;; load them via dlopen will work. This is because macOS ships
124
                   ;; all system-provided libraries as a single dyld_shared_cache
125
                   ;; bundle.
126
                   "/usr/lib/libcrypto.46.dylib"
127
                   "/usr/lib/libcrypto.44.dylib"
128
                   "/usr/lib/libcrypto.42.dylib"
129
                   "/usr/lib/libcrypto.41.dylib"
130
                   "/usr/lib/libcrypto.35.dylib"
131
 
132
                   ;; The default old system libcrypto, versionless file name,
133
                   ;; which may have insufficient crypto and can cause process
134
                   ;; crash on macOS >= 11. Currently we are protected from the
135
                   ;; crash by the presence of the versioned paths above, but in
136
                   ;; a few years, when those versions are not available anymore,
137
                   ;; the crash may re-appear. So eventually we will need to
138
                   ;; delete the unversioned paths. Keeping them for a while for
139
                   ;; compatibility. See
140
                   ;; https://github.com/cl-plus-ssl/cl-plus-ssl/pull/115
141
                   "libcrypto.dylib"
142
                   "/usr/lib/libcrypto.dylib"))
143
     ((and :unix (not :cygwin)) (:or "libcrypto.so.3"
144
                                     "libcrypto.so.1.1"
145
                                     "libcrypto.so.1.0.0"
146
                                     "libcrypto.so"))
147
     (:cygwin (:or "cygcrypto-1.1.dll" "cygcrypto-1.0.0.dll"))))
148
 
149
 (unless cl+ssl/config::*libssl-override*
150
   (cffi:define-foreign-library libssl
151
     (:windows (:or #+(and windows x86-64) "libssl-3-x64.dll"
152
                    #+(and windows x86) "libssl-3.dll"
153
                    #+(and windows x86-64) "libssl-1_1-x64.dll"
154
                    #+(and windows x86) "libssl-1_1.dll"
155
                    "libssl32.dll"
156
                    "ssleay32.dll"))
157
 
158
     ((:and :darwin :cl+ssl-macports-found) "/opt/local/lib/libssl.dylib")
159
     ((:and :darwin :cl+ssl-fink-found) "/sw/lib/libssl.dylib")
160
     ((:and :darwin :x86-64 :cl+ssl-homebrew-found) "/usr/local/opt/openssl/lib/libssl.dylib")
161
     ((:and :darwin :arm64 :cl+ssl-homebrew-arm64-found) "/opt/homebrew/opt/openssl/lib/libssl.dylib")
162
     ((:and :darwin :cl+ssl-personalized-install-found) "/usr/local/lib/libssl.dylib")
163
     (:darwin (:or ;; System-provided libraries, with version in the file name.
164
                   ;; See the comment for the libcryto equivalents above.
165
                   "/usr/lib/libssl.48.dylib"
166
                   "/usr/lib/libssl.46.dylib"
167
                   "/usr/lib/libssl.44.dylib"
168
                   "/usr/lib/libssl.43.dylib"
169
                   "/usr/lib/libssl.35.dylib"
170
 
171
                   ;; Default system libssl, versionless file name.
172
                   ;; See the coment for the corresponding libcrypto.
173
                   "libssl.dylib"
174
                   "/usr/lib/libssl.dylib"))
175
     (:solaris (:or "/lib/64/libssl.so"
176
                    "libssl.so.0.9.8" "libssl.so" "libssl.so.4"))
177
     ;; Unlike some other systems, OpenBSD linker,
178
     ;; when passed library name without versions at the end,
179
     ;; will locate the library with highest major.minor version,
180
     ;; so we can just use just "libssl.so".
181
     ;; More info at https://github.com/cl-plus-ssl/cl-plus-ssl/pull/2.
182
     (:openbsd "libssl.so")
183
     ((and :unix (not :cygwin)) (:or "libssl.so.3"
184
                                     "libssl.so.1.1"
185
                                     "libssl.so.1.0.2m"
186
                                     "libssl.so.1.0.2k"
187
                                     "libssl.so.1.0.2"
188
                                     "libssl.so.1.0.1l"
189
                                     "libssl.so.1.0.1j"
190
                                     "libssl.so.1.0.1f"
191
                                     "libssl.so.1.0.1e"
192
                                     "libssl.so.1.0.1"
193
                                     "libssl.so.1.0.0q"
194
                                     "libssl.so.1.0.0"
195
                                     "libssl.so.0.9.8ze"
196
                                     "libssl.so.0.9.8"
197
                                     ;; That's probably version 1.0.
198
                                     ;; Added by https://github.com/lispnik
199
                                     ;; on Mar 20, 2016
200
                                     ;; (commit 4124b73) with comment saying
201
                                     ;; "(Fedora 23 requirement)"
202
                                     "libssl.so.10"
203
                                     ;; That's not version 4.0.
204
                                     ;; Added in on Sep 17, 2009
205
                                     ;; (commit 26774a0)
206
                                     ;; after Stian Sletner <stian@copyleft.no>
207
                                     ;; reported that it's needed to make it work
208
                                     ;; under FreeBSD 7.2.
209
                                     "libssl.so.4"
210
                                     "libssl.so"))
211
     (:cygwin (:or "cygssl-1.1.dll" "cygssl-1.0.0.dll"))
212
     (t (:default "libssl3"))))
213
 
214
 (unless (member :cl+ssl-foreign-libs-already-loaded
215
                 *features*)
216
   (cffi:use-foreign-library libcrypto)
217
   (cffi:use-foreign-library libssl))