Skip to content

Commit a8c1173

Browse files
committed
ssl: Make SSL{_CTX}_[gs]et_options compatible accross all versions
See the comment in the code. The struct seems immensely outdated and probably needs an overhaul, but one problem at at time.
1 parent c1a7f79 commit a8c1173

File tree

1 file changed

+55
-14
lines changed
  • source/deimos/openssl

1 file changed

+55
-14
lines changed

source/deimos/openssl/ssl.d

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -662,32 +662,73 @@ enum SSL_MODE_SEND_SERVERHELLO_TIME = 0x00000040L;
662662
/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
663663
* they cannot be used to clear bits. */
664664

665-
c_ulong SSL_CTX_get_options(const SSL_CTX *ctx);
666-
c_ulong SSL_get_options(const SSL *s);
667-
c_ulong SSL_CTX_clear_options(SSL_CTX *ctx, c_ulong op);
668-
c_ulong SSL_clear_options(SSL *s, c_ulong op);
669-
c_ulong SSL_CTX_set_options(SSL_CTX *ctx, c_ulong op);
670-
c_ulong SSL_set_options(SSL *s, c_ulong op);
671-
672-
auto SSL_CTX_set_mode()(SSL_CTX* ctx, c_long op) {
665+
static if (OPENSSL_VERSION_AT_LEAST(1, 1, 0))
666+
{
667+
static if (OPENSSL_VERSION_AT_LEAST(3, 0, 0))
668+
{
669+
// The argument type for `SSL_[CTX_][gs]et_options was changed between 1.1.1
670+
// and 3.0.0, from `c_long` to `uint64_t`. See below commit.
671+
// https://github.com/openssl/openssl/commit/56bd17830f2d5855b533d923d4e0649d3ed61d11
672+
private alias SSLOptionType = ulong;
673+
}
674+
else
675+
{
676+
// Note: Despite the manuals listing the return type (as well as parameter)
677+
// as 'long', the `.h` was `unsigned long`.
678+
private alias SSLOptionType = c_ulong;
679+
}
680+
SSLOptionType SSL_CTX_get_options(const SSL_CTX* ctx);
681+
SSLOptionType SSL_get_options(const SSL* ssl);
682+
SSLOptionType SSL_CTX_clear_options(SSL_CTX* ctx, SSLOptionType op);
683+
SSLOptionType SSL_clear_options(SSL* ssl, SSLOptionType op);
684+
SSLOptionType SSL_CTX_set_options(SSL_CTX* ctx, SSLOptionType op);
685+
SSLOptionType SSL_set_options(SSL* ssl, SSLOptionType op);
686+
}
687+
else
688+
{
689+
// Before v1.1.0, those were macros. See below commit.
690+
// https://github.com/openssl/openssl/commit/8106cb8b6d706079cbcabd4631f05e4526a316e1
691+
private alias SSLOptionType = c_ulong;
692+
693+
SSLOptionType SSL_CTX_set_options()(SSL_CTX* ctx, SSLOptionType op) {
694+
return SSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, op, null);
695+
}
696+
SSLOptionType SSL_CTX_clear_options()(SSL_CTX* ctx, SSLOptionType op) {
697+
return SSL_CTX_ctrl(ctx, SSL_CTRL_CLEAR_OPTIONS, op, null);
698+
}
699+
SSLOptionType SSL_CTX_get_options()(SSL_CTX* ctx) {
700+
return SSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, 0, null);
701+
}
702+
SSLOptionType SSL_set_options()(SSL* ssl, SSLOptionType op) {
703+
return SSL_ctrl(ssl, SSL_CTRL_OPTIONS, op, null);
704+
}
705+
SSLOptionType SSL_clear_options()(SSL* ssl, SSLOptionType op) {
706+
return SSL_ctrl(ssl, SSL_CTRL_CLEAR_OPTIONS, op, null);
707+
}
708+
SSLOptionType SSL_get_options()(SSL* ssl) {
709+
return SSL_ctrl(ssl, SSL_CTRL_OPTIONS, 0, null);
710+
}
711+
}
712+
713+
auto SSL_CTX_set_mode()(SSL_CTX* ctx, SSLOptionType op) {
673714
return SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,op,null);
674715
}
675-
auto SSL_CTX_clear_mode()(SSL_CTX* ctx, c_long op) {
716+
auto SSL_CTX_clear_mode()(SSL_CTX* ctx, SSLOptionType op) {
676717
return SSL_CTX_ctrl(ctx,SSL_CTRL_CLEAR_MODE,op,null);
677718
}
678719
auto SSL_CTX_get_mode()(SSL_CTX* ctx) {
679720
return SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,0,null);
680721
}
681-
auto SSL_clear_mode()(SSL* ssl, c_long op) {
722+
auto SSL_clear_mode()(SSL* ssl, SSLOptionType op) {
682723
return SSL_ctrl(ssl,SSL_CTRL_CLEAR_MODE,op,null);
683724
}
684-
auto SSL_set_mode()(SSL* ssl, c_long op) {
725+
auto SSL_set_mode()(SSL* ssl, SSLOptionType op) {
685726
return SSL_ctrl(ssl,SSL_CTRL_MODE,op,null);
686727
}
687728
auto SSL_get_mode()(SSL* ssl) {
688729
return SSL_ctrl(ssl,SSL_CTRL_MODE,0,null);
689730
}
690-
auto SSL_set_mtu()(SSL* ssl, c_long mtu) {
731+
auto SSL_set_mtu()(SSL* ssl, SSLOptionType mtu) {
691732
return SSL_ctrl(ssl,SSL_CTRL_MTU,mtu,null);
692733
}
693734

@@ -898,7 +939,7 @@ struct ssl_ctx_st
898939

899940
/* Default values to use in SSL structures follow (these are copied by SSL_new) */
900941

901-
c_ulong options;
942+
SSLOptionType options;
902943
c_ulong mode;
903944
c_long max_cert_list;
904945

@@ -1317,7 +1358,7 @@ version(OPENSSL_NO_PSK) {} else {
13171358
STACK_OF!(X509_NAME) *client_CA;
13181359

13191360
int references;
1320-
c_ulong options; /* protocol behaviour */
1361+
SSLOptionType options; /* protocol behaviour */
13211362
c_ulong mode; /* API behaviour */
13221363
c_long max_cert_list;
13231364
int first_packet;

0 commit comments

Comments
 (0)