Skip to content

Commit

Permalink
Merge pull request #291 from sabracrolleton/master
Browse files Browse the repository at this point in the history
Flagging potential man-in-the-middle attack
  • Loading branch information
sabracrolleton authored Nov 13, 2021
2 parents 9e5b10c + ff3fe26 commit dae8e12
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions cl-postgres/config.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ functionality, you will have to call LOG-QUERY from your callback function")
(defvar *retry-connect-delay* 0.5
"How many seconds to wait before trying to connect again. Borrowed from
pgloader")

(defparameter *on-evidence-of-man-in-the-middle-attack* :error
"If Postmodern sees evidence of an attempted man-in-the-middle attack,
what should Postmodern do? Acceptable values are :error, :warn or :ignore")
1 change: 1 addition & 0 deletions cl-postgres/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#:parameter-lists-match-oid-types-p
#:parameter-list-types
#:param-to-oid
#:*on-evidence-of-man-in-the-middle-attack*
#+(and sbcl unix) #:*unix-socket-dir*))

(defpackage :cl-postgres-error
Expand Down
20 changes: 13 additions & 7 deletions cl-postgres/protocol.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,19 @@ a condition."

(unless (eq use-ssl :no)
(if (eq use-ssl :try)
(let ((old-socket socket)
(new-socket (initiate-ssl socket nil nil nil)))
(if new-socket (setf socket new-socket)
(setf socket old-socket)))
(setf socket (initiate-ssl socket (member use-ssl '(:require :yes :full))
(member use-ssl '(:yes :full))
(if (eq use-ssl :full) hostname)))))
(let ((old-socket socket)
(new-socket (initiate-ssl socket nil nil nil)))
(if new-socket (setf socket new-socket)
(setf socket old-socket)))
(setf socket (initiate-ssl socket (member use-ssl '(:require :yes :full))
(member use-ssl '(:yes :full))
(if (eq use-ssl :full) hostname))))
(when (listen socket) ; checks for attempted man-in-the-middle attack
(ecase *on-evidence-of-man-in-the-middle-attack*
(:error (error 'database-error
:message "Postmodern received an unexpectedly large packet in response to the request to use ssl. This may be evidence of an attempt to run a man-in-the-middle type attack. If you want to retry the connect and not throw an error, please set cl-postgres:*on-evidence-of-man-in-the-middle-attack* to :warn or :ignore"))
(:warn (warn "Postmodern received an unexpectedly large packet in response to the request to use ssl. This may be evidence of an attempt to run a man-in-the-middle type attack. If you want to some response other than a warning, please set cl-postgres:*on-evidence-of-man-in-the-middle-attack* to :error or :ignore"))
(:ignore t))))
(when (equal application-name "") (setf application-name "postmodern-default"))
(startup-message socket user database application-name)
(force-output socket)
Expand Down
10 changes: 10 additions & 0 deletions doc/cl-postgres.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions doc/cl-postgres.org
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ will look for the socket file.
When using SSL (see open-database), these can be used to provide client key
and certificate files. They can be either NIL, for no file, or a pathname.

** variable =*on-evidence-of-man-in-the-middle-attack*=
:PROPERTIES:
:CUSTOM_ID: variable-on-evidence-of-man-in-the-middle-attack
:END:

When establishing an SSL connection, Postmodern will check to see if unexpected extra data was received prior to the connection being encrypted. Unexpected extra data may indicate an attempted man-in-the-middle attack. By default, this variable is set to :error. You can set the response to be a simple warning (by setting this to :warn) or you can set this to :ignore.

** variable =*retry-connect-times*= (5)
:PROPERTIES:
:CUSTOM_ID: variable-retry-connect-times
Expand Down

0 comments on commit dae8e12

Please sign in to comment.