#if OPENSSL_VERSION_NUMBER < 0x0090800 || !defined(SHA256_DIGEST_LENGTH)
#error Your OpenSSL is too old, need 0.9.8 or newer with SHA256
#endif
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
#define HMAC_setup(ctx, key, len) HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, key, len, EVP_sha256(), 0)
#define HMAC_crunch(ctx, buf, len) HMAC_Update(&ctx, buf, len)
#define HMAC_finish(ctx, dig, dlen) HMAC_Final(&ctx, dig, &dlen); HMAC_CTX_cleanup(&ctx)
+#else
+#define HMAC_setup(ctx, key, len)ctx=HMAC_CTX_new(); HMAC_Init_ex(ctx, key, len, EVP_sha256(), 0)
+#define HMAC_crunch(ctx, buf, len)HMAC_Update(ctx, buf, len)
+#define HMAC_finish(ctx, dig, dlen) HMAC_Final(ctx, dig, &dlen); HMAC_CTX_free(ctx)
+#endif
#define FP10
#define RTMP_SIG_SIZE 1536
static void HMACsha256(const uint8_t *message, size_t messageLen, const uint8_t *key, size_t keylen, uint8_t *digest)
{
unsigned int digestLen;
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX ctx;
-
+#else
+ HMAC_CTX *ctx;
+#endif
+
HMAC_setup(ctx, key, (int)keylen);
HMAC_crunch(ctx, message, messageLen);
HMAC_finish(ctx, digest, digestLen);
////////////
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
static BIO_METHOD dtls_bio_filter_methods;
+#else
+static BIO_METHOD *dtls_bio_filter_methods;
+#endif
BIO_METHOD *BIO_dtls_filter(void) {
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
return(&dtls_bio_filter_methods);
+#else
+ return(dtls_bio_filter_methods);
+#endif
}
typedef struct packet_list_s {
switch_mutex_init(&filter->mutex, SWITCH_MUTEX_NESTED, filter->pool);
/* Set the BIO as initialized */
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
bio->init = 1;
bio->ptr = filter;
bio->flags = 0;
-
+#else
+ BIO_set_init(bio, 1);
+ BIO_set_data(bio, filter);
+ BIO_clear_flags(bio, ~0);
+#endif
+
return 1;
}
}
/* Get rid of the filter state */
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
filter = (dtls_bio_filter *)bio->ptr;
+#else
+ filter = (dtls_bio_filter *)BIO_get_data(bio);
+#endif
if (filter != NULL) {
switch_memory_pool_t *pool = filter->pool;
filter = NULL;
}
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
bio->ptr = NULL;
bio->init = 0;
bio->flags = 0;
+#else
+ BIO_set_init(bio, 0);
+ BIO_set_data(bio, NULL);
+ BIO_clear_flags(bio, ~0);
+#endif
return 1;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "dtls_bio_filter_write: %p, %d\n", (void *)in, inl);
/* Forward data to the write BIO */
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
ret = BIO_write(bio->next_bio, in, inl);
+#else
+ ret = BIO_write(BIO_next(bio), in, inl);
+#endif
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, " -- %ld\n", ret);
/* Keep track of the packet, as we'll advertize them one by one after a pending check */
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
filter = (dtls_bio_filter *)bio->ptr;
+#else
+ filter = (dtls_bio_filter *)BIO_get_data(bio);
+#endif
if (filter != NULL) {
packet_list_t *node;
}
static long dtls_bio_filter_ctrl(BIO *bio, int cmd, long num, void *ptr) {
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
dtls_bio_filter *filter = (dtls_bio_filter *)bio->ptr;
+#else
+ dtls_bio_filter *filter = (dtls_bio_filter *)BIO_get_data(bio);
+#endif
switch(cmd) {
case BIO_CTRL_DGRAM_GET_FALLBACK_MTU:
return 0;
}
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
static BIO_METHOD dtls_bio_filter_methods = {
BIO_TYPE_FILTER,
"DTLS filter",
dtls_bio_filter_free,
NULL
};
-
+#else
+static BIO_METHOD *dtls_bio_filter_methods = NULL;
+#endif
///////////
dtls->ca = switch_core_sprintf(rtp_session->pool, "%s%sca-bundle.crt", SWITCH_GLOBAL_dirs.certs_dir, SWITCH_PATH_SEPARATOR);
+#if OPENSSL_VERSION_NUMBER >= 0x10100000
+ dtls->ssl_ctx = SSL_CTX_new((type & DTLS_TYPE_SERVER) ? DTLS_server_method() : DTLS_client_method());
+#else
dtls->ssl_ctx = SSL_CTX_new((type & DTLS_TYPE_SERVER) ? DTLSv1_server_method() : DTLSv1_client_method());
+#endif
switch_assert(dtls->ssl_ctx);
bio = BIO_new_file(dtls->pem, "r");
dtls->ssl = SSL_new(dtls->ssl_ctx);
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
dtls->filter_bio = BIO_new(BIO_dtls_filter());
+#else
+ dtls_bio_filter_methods = BIO_meth_new(BIO_TYPE_FILTER | BIO_get_new_index(), "DTLS filter");
+ BIO_meth_set_write(dtls_bio_filter_methods, dtls_bio_filter_write);
+ BIO_meth_set_ctrl(dtls_bio_filter_methods, dtls_bio_filter_ctrl);
+ BIO_meth_set_create(dtls_bio_filter_methods, dtls_bio_filter_new);
+ BIO_meth_set_destroy(dtls_bio_filter_methods, dtls_bio_filter_free);
+ dtls->filter_bio = BIO_new(dtls_bio_filter_methods);
+#endif
+
switch_assert(dtls->filter_bio);
BIO_push(dtls->filter_bio, dtls->write_bio);