Skip to content

Commit 16dda01

Browse files
committed
Deal with SSL verify error the wrong way.
This patch adds an option --no-ssl-cert-verification that allows bypassing OpenSSL server certificate verification. It's hopefully a temporary measure that we set up in order to make progress when confronted to: SSL verify error: 20 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY The real solution is of course to install the SSL certificates at a place where pgloader will look for them, which defaults to ~/.postgresql/postgresql.crt at the moment. It's not clear what the story is with the defaults from /etc/ssl, or how to make things happen in a better way. See #648, See #679, See #768, See #748, See #775.
1 parent 5ecf04a commit 16dda01

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

src/main.lisp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
("on-error-stop" :type boolean
5252
:documentation "Refrain from handling errors properly.")
5353

54+
("no-ssl-cert-verification"
55+
:type boolean
56+
:documentation "Instruct OpenSSL to bypass verifying certificates.")
57+
5458
(("context" #\C) :type string :documentation "Command Context Variables")
5559

5660
(("with") :type string :list t :optional t
@@ -197,6 +201,7 @@
197201
client-min-messages log-min-messages summary
198202
root-dir self-upgrade
199203
with set field cast type encoding before after
204+
no-ssl-cert-verification
200205
regress)
201206
options
202207

@@ -249,11 +254,15 @@
249254
(lisp-implementation-type)
250255
(lisp-implementation-version)))
251256

252-
(when help
257+
(when (or help)
253258
(usage argv))
254259

255260
(when (or help version) (uiop:quit +os-code-success+))
256261

262+
(when (null arguments)
263+
(usage argv)
264+
(uiop:quit +os-code-error-usage+))
265+
257266
(when list-encodings
258267
(show-encodings)
259268
(uiop:quit +os-code-success+))
@@ -316,6 +325,9 @@
316325
(uiop:native-namestring *log-filename*))
317326
(log-message :log "Data errors in '~a'~%" *root-dir*)
318327

328+
(when no-ssl-cert-verification
329+
(setf cl+ssl:*make-ssl-client-stream-verify-default* nil))
330+
319331
(cond
320332
((and regress (= 1 (length arguments)))
321333
(process-regression-test (first arguments)))

src/pgsql/connection.lisp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,19 @@
118118
(uiop:native-namestring crt-file)))
119119
(pomo::*ssl-key-file* (when (and (ssl-enable-p pgconn)
120120
(probe-file key-file))
121-
(uiop:native-namestring key-file))))
121+
(uiop:native-namestring key-file)))
122+
;;
123+
;; It's ok to set :verify-mode to NONE here because
124+
;; cl+ssl:*make-ssl-client-stream-verify-default* defaults to
125+
;; :require and takes precedence.
126+
;;
127+
;; Only when --no-ssl-cert-verification is passed as a command line
128+
;; option do we set cl+ssl:*make-ssl-client-stream-verify-default*
129+
;; to NIL, then allowing the NONE behaviour set here.
130+
;;
131+
(ssl-context
132+
(CL+SSL:MAKE-CONTEXT :disabled-protocols nil
133+
:verify-mode CL+SSL:+SSL-VERIFY-NONE+)))
122134
(flet ((connect (pgconn username)
123135
(handler-case
124136
;; in some cases (client_min_messages set to debug5
@@ -128,20 +140,29 @@
128140
#'(lambda (w)
129141
(log-message :warning "~a" w)
130142
(muffle-warning))))
131-
(pomo:connect (db-name pgconn)
132-
(or username (db-user pgconn))
133-
(db-pass pgconn)
134-
(let ((host (db-host pgconn)))
135-
(if (and (consp host) (eq :unix (car host)))
136-
:unix
137-
host))
138-
:port (db-port pgconn)
139-
:use-ssl (or (pgconn-use-ssl pgconn) :no)))
143+
(CL+SSL:WITH-GLOBAL-CONTEXT (ssl-context :auto-free-p t)
144+
(pomo:connect (db-name pgconn)
145+
(or username (db-user pgconn))
146+
(db-pass pgconn)
147+
(let ((host (db-host pgconn)))
148+
(if (and (consp host) (eq :unix (car host)))
149+
:unix
150+
host))
151+
:port (db-port pgconn)
152+
:use-ssl (or (pgconn-use-ssl pgconn) :no))))
153+
140154
((or too-many-connections configuration-limit-exceeded) (e)
141155
(log-message :error
142156
"Failed to connect to ~a: ~a; will try again in ~fs"
143157
pgconn e *retry-connect-delay*)
144-
(sleep *retry-connect-delay*)))))
158+
(sleep *retry-connect-delay*))
159+
160+
(CL+SSL:SSL-ERROR-VERIFY (e)
161+
(log-message :error
162+
"Connecting to PostgreSQL ~a: ~a"
163+
(db-host pgconn) e)
164+
(log-message :log "You may try --no-ssl-cert-verification")
165+
(error e)))))
145166
(loop :while (null (conn-handle pgconn))
146167
:repeat *retry-connect-times*
147168
:do (setf (conn-handle pgconn) (connect pgconn username))))

src/utils/threads.lisp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
;; bindings updates for libs
2929
;; CFFI is used by the SQLite lib
3030
(cffi:*default-foreign-encoding*
31-
. ,cffi:*default-foreign-encoding*))))
31+
. ,cffi:*default-foreign-encoding*)
32+
33+
;; CL+SSL can be picky about verifying certs
34+
(cl+ssl:*make-ssl-client-stream-verify-default*
35+
. ,cl+ssl:*make-ssl-client-stream-verify-default*))))
3236
"Wrapper around lparallel:make-kernel that sets our usual bindings."
3337
(lp:make-kernel worker-count :bindings bindings))

0 commit comments

Comments
 (0)