Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OpenSSL ALPN array corruption #2235

Merged
merged 2 commits into from Nov 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions tls/vibe/stream/openssl.d
Expand Up @@ -47,7 +47,7 @@ version(VibeForceALPN) enum alpn_forced = true;
else enum alpn_forced = false;
enum haveALPN = OPENSSL_VERSION_NUMBER >= 0x10200000 || alpn_forced;

// openssl 1.1.0 hack: provides a 1.0.x API in terms of the 1.1.x API
// openssl/1.1.0 hack: provides a 1.0.x API in terms of the 1.1.x API
version (VibeUseOpenSSL11) {
extern(C) const(SSL_METHOD)* TLS_client_method();
alias SSLv23_client_method = TLS_client_method;
Expand Down Expand Up @@ -471,14 +471,17 @@ final class OpenSSLStream : TLSStream {
const {
static if (!haveALPN) assert(false, "OpenSSL support not compiled with ALPN enabled. Use VibeForceALPN.");
else {
char[32] data;
// modified since C functions expects a NULL pointer
const(ubyte)* data = null;
uint datalen;
string ret;

() @trusted { SSL_get0_alpn_selected(m_tls, cast(const char*) data.ptr, &datalen); } ();
logDebug("alpn selected: ", data.to!string);
if (datalen > 0)
return data[0..datalen].idup;
else return null;
() @trusted {
SSL_get0_alpn_selected(m_tls, &data, &datalen);
ret = cast(string)data[0 .. datalen].idup;
} ();
logDebug("alpn selected: ", ret);
return ret;
}
}

Expand Down Expand Up @@ -562,6 +565,7 @@ final class OpenSSLContext : TLSContext {
TLSALPNCallback m_alpnCallback;
}


this(TLSContextKind kind, TLSVersion ver = TLSVersion.any)
{
m_kind = kind;
Expand Down Expand Up @@ -1368,7 +1372,7 @@ static if (haveALPN) {
void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, ALPNCallback cb, void *arg);
int SSL_set_alpn_protos(SSL *ssl, const char *data, uint len);
int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const char* protos, uint protos_len);
void SSL_get0_alpn_selected(const SSL *ssl, const char* data, uint *len);
void SSL_get0_alpn_selected(const SSL *ssl, const ubyte** data, uint *len);
}
const(ssl_method_st)* TLSv1_2_server_method();