From 9391f6348a1d6e7bab099438440ea5b71f67878e Mon Sep 17 00:00:00 2001 From: kakwa Date: Sun, 4 Dec 2016 13:38:09 +0100 Subject: [PATCH] adding a few #define to handle multiple openssl API version --- inc/rfc3161.h | 11 +++++++++++ src/lib/rfc3161.c | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/inc/rfc3161.h b/inc/rfc3161.h index d86f3ec..aa7db08 100644 --- a/inc/rfc3161.h +++ b/inc/rfc3161.h @@ -11,6 +11,17 @@ #include #include #include +#include + +#if OPENSSL_VERSION_NUMBER < 0x10000000L +#error OpenSSL version too old +#endif +#if OPENSSL_VERSION_NUMBER < 0x10100000L && OPENSSL_VERSION_NUMBER >= 0x10000000L +#define OPENSSL_API_1_0 +#endif +#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#define OPENSSL_API_1_1 +#endif /* Name of config entry that defines the OID file. */ #define OID_SECTION "oids" diff --git a/src/lib/rfc3161.c b/src/lib/rfc3161.c index f38c79e..24afef0 100644 --- a/src/lib/rfc3161.c +++ b/src/lib/rfc3161.c @@ -260,6 +260,8 @@ end: char *serial_hex = NULL; *serial_id = calloc(SERIAL_ID_SIZE + 1, sizeof(char)); + +#ifdef OPENSSL_API_1_1 // if we have a proper response, we recover the serial to identify the logs if (TS_RESP_get_tst_info(ts_response) != NULL && TS_TST_INFO_get_serial(TS_RESP_get_tst_info(ts_response)) != NULL) { @@ -272,6 +274,19 @@ end: serial_hex = calloc(SERIAL_ID_SIZE, sizeof(char)); strncpy(serial_hex, " NO ID ", SERIAL_ID_SIZE + 2); } +#endif +#ifdef OPENSSL_API_1_0 + if (ts_response->tst_info != NULL && + ts_response->tst_info->serial != NULL) { + ASN1_INTEGER *serial = ts_response->tst_info->serial; + BIGNUM *serial_bn = ASN1_INTEGER_to_BN(serial, NULL); + serial_hex = BN_bn2hex(serial_bn); + BN_free(serial_bn); + } else { + serial_hex = calloc(SERIAL_ID_SIZE, sizeof(char)); + strncpy(serial_hex, " NO ID ", SERIAL_ID_SIZE + 2); + } +#endif // get a short version of the serial (150 bits in hexa is a bit long) strncpy(*serial_id, serial_hex, SERIAL_ID_SIZE); @@ -293,8 +308,13 @@ end: // emit logs according the return value // and set the return code +#ifdef OPENSSL_API_1_1 long status = ASN1_INTEGER_get( TS_STATUS_INFO_get0_status(TS_RESP_get_status_info(ts_response))); +#endif +#ifdef OPENSSL_API_1_0 + long status = ASN1_INTEGER_get(ts_response->status_info->status); +#endif switch (status) { case TS_STATUS_GRANTED: uts_logger(ct, LOG_DEBUG, "Request[%s], timestamp request granted",