60#include <openssl/ssl.h>
61#include <openssl/conf.h>
63#include <openssl/engine.h>
65#include <openssl/x509v3.h>
158 "SSL_read failed but did not provide error information\n");
182 "\tThis probably means the server terminated abnormally\n"
183 "\tbefore or while processing the request.");
260 "SSL_write failed but did not provide error information\n");
288 "\tThis probably means the server terminated abnormally\n"
289 "\tbefore or while processing the request.");
361#if HAVE_X509_GET_SIGNATURE_INFO
435#ifdef HAVE_SSL_CTX_SET_CERT_CB
688#ifdef HAVE_SSL_CTX_SET_KEYLOG_CALLBACK
800#ifdef HAVE_SSL_CTX_SET_CERT_CB
900 else if (
fnbuf[0] !=
'\0' &&
934 if ((fname ||
dname) &&
960 if (
fnbuf[0] ==
'\0')
962 "Either provide the file, use the system's trusted roots with sslrootcert=system, or change sslmode to disable server certificate verification.");
965 "Either provide the file, use the system's trusted roots with sslrootcert=system, or change sslmode to disable server certificate verification.",
fnbuf);
985 else if (
fnbuf[0] ==
'\0')
1054#ifdef HAVE_SSL_CTX_SET_KEYLOG_CALLBACK
1057#ifdef LIBRESSL_VERSION_NUMBER
1082 if (host && host[0] &&
1121#ifdef USE_SSL_ENGINE
1264#if !defined(WIN32) && !defined(__CYGWIN__)
1265 if (
buf.st_uid == 0 ?
1270 "private key file \"%s\" has group or world access; file must have permissions u=rw (0600) or less if owned by the current user, or permissions u=rw,g=r (0640) or less if owned by root",
1349 unsigned long ecode;
1363 unsigned long vcode;
1420#ifdef SSL_R_VERSION_TOO_HIGH
1449 const unsigned char *selected;
1454 if (selected ==
NULL)
1527#ifdef USE_SSL_ENGINE
1549static char ssl_nomem[] =
"out of memory allocating error description";
1551#define SSL_ERR_LEN 128
1556 const char *errreason;
1568 if (errreason !=
NULL)
1582#ifdef SSL_AD_NO_APPLICATION_PROTOCOL
1598#ifdef ERR_SYSTEM_ERROR
1709 const unsigned char *
data;
1754#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
1787#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
1911 buf[size - 1] =
'\0';
1965#ifdef TLS1_1_VERSION
1970#ifdef TLS1_2_VERSION
1975#ifdef TLS1_3_VERSION
static SSL_CTX * SSL_context
#define Assert(condition)
#define fprintf(file, fmt, msg)
void err(int eval, const char *fmt,...)
bool pqGetHomeDirectory(char *buf, int bufsize)
int pq_verify_peer_name_matches_certificate_name(PGconn *conn, const char *namedata, size_t namelen, char **store_name)
int pq_verify_peer_name_matches_certificate_ip(PGconn *conn, const unsigned char *ipdata, size_t iplen, char **store_name)
bool pq_verify_peer_name_matches_certificate(PGconn *conn)
static BIO_METHOD * pgconn_bio_method_ptr
static int ssl_protocol_version_to_openssl(const char *protocol)
void * PQgetssl(PGconn *conn)
static void SSLerrfree(char *buf)
PQsslKeyPassHook_OpenSSL_type PQgetSSLKeyPassHook_OpenSSL(void)
void * PQsslStruct(PGconn *conn, const char *struct_name)
int pgtls_verify_peer_name_matches_certificate_guts(PGconn *conn, int *names_examined, char **first_name)
PostgresPollingStatusType pgtls_open_client(PGconn *conn)
bool pgtls_read_pending(PGconn *conn)
int PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn)
static int pgconn_bio_read(BIO *h, char *buf, int size)
static int openssl_verify_peer_name_matches_certificate_name(PGconn *conn, ASN1_STRING *name_entry, char **store_name)
ssize_t pgtls_read(PGconn *conn, void *ptr, size_t len)
static long pgconn_bio_ctrl(BIO *h, int cmd, long num, void *ptr)
static int pgconn_bio_write(BIO *h, const char *buf, int size)
ssize_t pgtls_write(PGconn *conn, const void *ptr, size_t len)
static PQsslKeyPassHook_OpenSSL_type PQsslKeyPassHook
char * pgtls_get_peer_certificate_hash(PGconn *conn, size_t *len)
const char * PQsslAttribute(PGconn *conn, const char *attribute_name)
static int initialize_SSL(PGconn *conn)
static pthread_mutex_t ssl_config_mutex
static int verify_cb(int ok, X509_STORE_CTX *ctx)
static int PQssl_passwd_cb(char *buf, int size, int rwflag, void *userdata)
static char * SSLerrmessage(unsigned long ecode)
static int openssl_verify_peer_name_matches_certificate_ip(PGconn *conn, ASN1_OCTET_STRING *addr_entry, char **store_name)
static PostgresPollingStatusType open_client_SSL(PGconn *conn)
static unsigned char alpn_protos[]
static int ssl_set_pgconn_bio(PGconn *conn)
void pgtls_close(PGconn *conn)
const char *const * PQsslAttributeNames(PGconn *conn)
void PQsetSSLKeyPassHook_OpenSSL(PQsslKeyPassHook_OpenSSL_type hook)
static BIO_METHOD * pgconn_bio_method(void)
static bool is_ip_address(const char *host)
ssize_t pqsecure_raw_read(PGconn *conn, void *ptr, size_t len)
ssize_t pqsecure_raw_write(PGconn *conn, const void *ptr, size_t len)
int(* PQsslKeyPassHook_OpenSSL_type)(char *buf, int size, PGconn *conn)
PostgresPollingStatusType
#define SOCK_ERRNO_SET(e)
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define PG_STRERROR_R_BUFLEN
int pg_strcasecmp(const char *s1, const char *s2)
int inet_aton(const char *cp, struct in_addr *addr)
size_t strlcpy(char *dst, const char *src, size_t siz)
#define PG_ALPN_PROTOCOL_VECTOR
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
static int fd(const char *x, int i)
int pthread_mutex_unlock(pthread_mutex_t *mp)
int pthread_mutex_lock(pthread_mutex_t *mp)
#define PTHREAD_MUTEX_INITIALIZER
static unsigned hash(unsigned *uv, int n)
char * ssl_max_protocol_version
char * ssl_min_protocol_version
PQExpBufferData errorMessage
bool ssl_handshake_started