* creating, using and closing TLS/SSL connections.
*
* Copyright : Written by and Copyright (c) 2020 Maxim Antonov <mantonov@gmail.com>
+ * Copyright (C) 2017 Vaclav Svec. FIT CVUT.
+ * Copyright (C) 2018-2020 by Fabian Keil <fk@fabiankeil.de>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
static int ssl_inited = 0;
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#define X509_set1_notBefore X509_set_notBefore
+#define X509_set1_notAfter X509_set_notAfter
+#define X509_get0_serialNumber X509_get_serialNumber
+#define X509_get0_notBefore X509_get_notBefore
+#define X509_get0_notAfter X509_get_notAfter
+#endif
+
/*********************************************************************
*
* Function : openssl_init
*
- * Description : INitializes OpenSSL library once
+ * Description : Initializes OpenSSL library once
*
* Parameters : N/A
*
* or has not yet been sent by the remote end.
*
* Parameters :
- * 1 : ssl = SSL context to test
+ * 1 : ssl_attr = SSL context to test
*
* Returns : 0 => No data are pending
* >0 => Pending data length
* connection context.
*
* Parameters :
- * 1 : ssl = SSL context to send data to
+ * 1 : ssl_attr = SSL context to send data to
* 2 : buf = Pointer to data to be sent
* 3 : len = Length of data to be sent to the SSL context
*
* it into buffer.
*
* Parameters :
- * 1 : ssl = SSL context to receive data from
+ * 1 : ssl_attr = SSL context to receive data from
* 2 : buf = Pointer to buffer where data will be written
* 3 : max_length = Maximum number of bytes to read
*
char *encoded_text;
long l;
const ASN1_INTEGER *bs;
+#if OPENSSL_VERSION_NUMBER > 0x10100000L
const X509_ALGOR *tsig_alg;
+#endif
int loc;
if (!bio)
goto exit;
}
+#if OPENSSL_VERSION_NUMBER > 0x10100000L
if (BIO_puts(bio, "\nsigned using : ") <= 0)
{
log_ssl_errors(LOG_LEVEL_ERROR, "BIO_puts() for signed using failed");
ret = -1;
goto exit;
}
+#endif
pkey = X509_get_pubkey(crt);
if (!pkey)
{
/*
* Set the hostname to check against the received server certificate
*/
+#if OPENSSL_VERSION_NUMBER > 0x10100000L
if (!SSL_set1_host(ssl, csp->http->host))
{
log_ssl_errors(LOG_LEVEL_ERROR, "SSL_set1_host failed");
ret = -1;
goto exit;
}
-
+#else
+ if (host_is_ip_address(csp->http->host))
+ {
+ if (X509_VERIFY_PARAM_set1_ip_asc(ssl->param, csp->http->host) != 1)
+ {
+ log_ssl_errors(LOG_LEVEL_ERROR,
+ "X509_VERIFY_PARAM_set1_ip_asc() failed");
+ ret = -1;
+ goto exit;
+ }
+ }
+ else
+ {
+ if (X509_VERIFY_PARAM_set1_host(ssl->param, csp->http->host, 0) != 1)
+ {
+ log_ssl_errors(LOG_LEVEL_ERROR,
+ "X509_VERIFY_PARAM_set1_host() failed");
+ ret = -1;
+ goto exit;
+ }
+ }
+#endif
/* SNI extension */
if (!SSL_set_tlsext_host_name(ssl, csp->http->host))
{
* 1 : cert = The certificate to modify
* 2 : issuer = Issuer certificate
* 3 : nid = OpenSSL NID
- * 2 : data = extension value
+ * 4 : value = extension value
*
* Returns : 0 => Error while setting extensuon data
* 1 => It worked
*
*********************************************************************/
-static int set_x509_ext(X509 *cert, X509 *issuer, int nid, const char *value)
+static int set_x509_ext(X509 *cert, X509 *issuer, int nid, char *value)
{
X509_EXTENSION *ext = NULL;
X509V3_CTX ctx;
* Parameters :
* 1 : cert = The certificate to modify
* 2 : issuer = Issuer certificate
- * 2 : hostname = The hostname to add
+ * 3 : hostname = The hostname to add
*
* Returns : 0 => Error while creating certificate.
* 1 => It worked