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

Delayed client certificate #54692

Merged
merged 34 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2677a3b
initial prototype
wfurt May 12, 2021
a244b9b
Merge remote-tracking branch 'upstream/main' into renegoLinuxPoC
Jun 9, 2021
38007a6
Restore TLS 1.2 renegotiation
Jun 18, 2021
28dc58c
First windows functionality merge
Jun 22, 2021
42468df
reenable client certificate
Jun 23, 2021
50b4b67
Merge remote-tracking branch 'origin/renegoLinuxPoC' into renegoLinuxPoC
Jun 23, 2021
93d101b
Add more renegotiate tests
Jun 23, 2021
89e570e
Merge remote-tracking branch 'upstream/main' into jajajhoda/tlsrenego…
Jun 24, 2021
4d31737
Remove client certificates
Jun 24, 2021
400a656
Cleanup
Jun 24, 2021
9cc6f06
add test log
Jun 25, 2021
f0d658f
Merge remote-tracking branch 'upstream/main' into renegoLinuxPoC
Jun 25, 2021
e648618
Apply PR comments
Jun 25, 2021
793a2cd
Merge commit '9cc6f069046622540c1aea947f66f92df4bf8f3a' into renegoLi…
Jun 25, 2021
e05ffdb
Add Data frame test
Jun 25, 2021
7a9aadb
Add drain buffer test
Jun 28, 2021
71191e5
Fix tls 1.3 incomming app data frame
Jun 29, 2021
5d09969
Restore verify callback
Jun 29, 2021
50dd05e
Remove debug log
Jun 30, 2021
5be4566
Remove keylog callback and unused method
Jun 30, 2021
65c143f
Fix test build
Jun 30, 2021
2b95c9e
Merge remote-tracking branch 'upstream/main' into renegoLinuxPoC
Jun 30, 2021
6798888
Attempt to fix openssl version api difference
Jun 30, 2021
09fd4c6
Sort shim
Jun 30, 2021
9b28f70
fix build
wfurt Jun 30, 2021
7bfe54f
CI log
Jul 1, 2021
d86628b
Restore mac tests
Jul 1, 2021
100bb82
Add logs
Jul 1, 2021
ca00e71
Merge branch 'renegoLinuxPoC' of github.com:aik-jahoda/runtime into r…
Jul 1, 2021
f7bc9f3
fix test runs on old openssl
wfurt Jul 7, 2021
2ac5726
Merge branch 'renegoLinuxPoC' of https://github.com/aik-jahoda/runtim…
wfurt Jul 7, 2021
e7a4e79
fix tests
wfurt Jul 8, 2021
b9b797a
fix w7 condition
wfurt Jul 9, 2021
86b9809
feedback from review
wfurt Jul 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -223,6 +224,19 @@ internal static SafeSslHandle AllocateSslContext(SslProtocols protocols, SafeX50
return context;
}

internal static SecurityStatusPal SslRenegotiate(SafeSslHandle sslContext, out byte[]? outputBuffer)
{
int ret = Interop.Ssl.SslRenegotiate(sslContext);

outputBuffer = Array.Empty<byte>();
if (ret != 1)
{
GetSslError(sslContext, ret, out Exception? exception);
return new SecurityStatusPal(SecurityStatusPalErrorCode.InternalError, exception);
}
return new SecurityStatusPal(SecurityStatusPalErrorCode.OK);
}

internal static bool DoSslHandshake(SafeSslHandle context, ReadOnlySpan<byte> input, out byte[]? sendBuf, out int sendCount)
{
sendBuf = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ internal static partial class Ssl
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslRead", SetLastError = true)]
internal static extern int SslRead(SafeSslHandle ssl, ref byte buf, int num);

[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslRenegotiate")]
internal static extern int SslRenegotiate(SafeSslHandle ssl);

[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_IsSslRenegotiatePending")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool IsSslRenegotiatePending(SafeSslHandle ssl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,13 @@ unsigned long local_SSL_CTX_set_options(SSL_CTX* ctx, unsigned long options)
return (unsigned long)SSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, (long)options, NULL);
}

unsigned long local_SSL_set_options(SSL* ssl, unsigned long options)
{
// SSL_ctrl is signed long in and signed long out; but SSL_set_options,
// which was a macro call to SSL_ctrl in 1.0, is unsigned/unsigned.
return (unsigned long)SSL_ctrl(ssl, SSL_CTRL_OPTIONS, (long)options, NULL);
}

int local_SSL_session_reused(SSL* ssl)
{
return (int)SSL_ctrl(ssl, SSL_CTRL_GET_SESSION_REUSED, 0, NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int32_t local_RSA_pkey_ctx_ctrl(EVP_PKEY_CTX* ctx, int32_t optype, int32_t cmd,
int32_t local_SSL_is_init_finished(const SSL* ssl);
int32_t local_SSL_CTX_config(SSL_CTX* ctx, const char* name);
unsigned long local_SSL_CTX_set_options(SSL_CTX* ctx, unsigned long options);
unsigned long local_SSL_set_options(SSL* ssl, unsigned long options);
void local_SSL_CTX_set_security_level(SSL_CTX* ctx, int32_t level);
int local_SSL_session_reused(SSL* ssl);
int32_t local_X509_check_host(X509* x509, const char* name, size_t namelen, unsigned int flags, char** peername);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ static const Entry s_cryptoNative[] =
DllImportEntry(CryptoNative_BioWrite)
DllImportEntry(CryptoNative_EnsureLibSslInitialized)
DllImportEntry(CryptoNative_GetOpenSslCipherSuiteName)
DllImportEntry(CryptoNative_SslRenegotiate)
DllImportEntry(CryptoNative_IsSslRenegotiatePending)
DllImportEntry(CryptoNative_IsSslStateOK)
DllImportEntry(CryptoNative_SetCiphers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ const EVP_CIPHER* EVP_chacha20_poly1305(void);
REQUIRED_FUNCTION(SSL_CTX_new) \
LIGHTUP_FUNCTION(SSL_CTX_set_alpn_protos) \
LIGHTUP_FUNCTION(SSL_CTX_set_alpn_select_cb) \
REQUIRED_FUNCTION(SSL_CTX_set_cert_verify_callback) \
REQUIRED_FUNCTION(SSL_CTX_set_cipher_list) \
LIGHTUP_FUNCTION(SSL_CTX_set_ciphersuites) \
REQUIRED_FUNCTION(SSL_CTX_set_client_cert_cb) \
Expand All @@ -484,12 +483,16 @@ const EVP_CIPHER* EVP_chacha20_poly1305(void);
LEGACY_FUNCTION(SSL_library_init) \
LEGACY_FUNCTION(SSL_load_error_strings) \
REQUIRED_FUNCTION(SSL_new) \
REQUIRED_FUNCTION(SSL_peek) \
REQUIRED_FUNCTION(SSL_read) \
REQUIRED_FUNCTION(SSL_renegotiate) \
REQUIRED_FUNCTION(SSL_renegotiate_pending) \
FALLBACK_FUNCTION(SSL_session_reused) \
REQUIRED_FUNCTION(SSL_set_accept_state) \
REQUIRED_FUNCTION(SSL_set_bio) \
REQUIRED_FUNCTION(SSL_set_connect_state) \
FALLBACK_FUNCTION(SSL_set_options) \
REQUIRED_FUNCTION(SSL_set_verify) \
REQUIRED_FUNCTION(SSL_shutdown) \
LEGACY_FUNCTION(SSL_state) \
LEGACY_FUNCTION(SSLeay) \
Expand Down Expand Up @@ -895,7 +898,6 @@ FOR_ALL_OPENSSL_FUNCTIONS
#define SSL_CTX_new SSL_CTX_new_ptr
#define SSL_CTX_set_alpn_protos SSL_CTX_set_alpn_protos_ptr
#define SSL_CTX_set_alpn_select_cb SSL_CTX_set_alpn_select_cb_ptr
#define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_callback_ptr
#define SSL_CTX_set_cipher_list SSL_CTX_set_cipher_list_ptr
#define SSL_CTX_set_ciphersuites SSL_CTX_set_ciphersuites_ptr
#define SSL_CTX_set_client_cert_cb SSL_CTX_set_client_cert_cb_ptr
Expand All @@ -922,12 +924,18 @@ FOR_ALL_OPENSSL_FUNCTIONS
#define SSL_library_init SSL_library_init_ptr
#define SSL_load_error_strings SSL_load_error_strings_ptr
#define SSL_new SSL_new_ptr
#define SSL_peek SSL_peek_ptr
#define SSL_state_string_long SSL_state_string_long_ptr
#define SSL_read SSL_read_ptr
#define ERR_print_errors_fp ERR_print_errors_fp_ptr
#define SSL_renegotiate SSL_renegotiate_ptr
#define SSL_renegotiate_pending SSL_renegotiate_pending_ptr
#define SSL_session_reused SSL_session_reused_ptr
#define SSL_set_accept_state SSL_set_accept_state_ptr
#define SSL_set_bio SSL_set_bio_ptr
#define SSL_set_connect_state SSL_set_connect_state_ptr
#define SSL_set_options SSL_set_options_ptr
#define SSL_set_verify SSL_set_verify_ptr
#define SSL_shutdown SSL_shutdown_ptr
#define SSL_state SSL_state_ptr
#define SSLeay SSLeay_ptr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "pal_types.h"

#undef SSL_CTX_set_options
#undef SSL_set_options
#undef SSL_session_reused

typedef struct ossl_init_settings_st OPENSSL_INIT_SETTINGS;
Expand Down Expand Up @@ -56,6 +57,7 @@ int SSL_CTX_config(SSL_CTX* ctx, const char* name);
unsigned long SSL_CTX_set_options(SSL_CTX* ctx, unsigned long options);
void SSL_CTX_set_security_level(SSL_CTX* ctx, int32_t level);
int32_t SSL_is_init_finished(SSL* ssl);
unsigned long SSL_set_options(SSL* ctx, unsigned long options);
int SSL_session_reused(SSL* ssl);
const SSL_METHOD* TLS_method(void);
const ASN1_TIME* X509_CRL_get0_nextUpdate(const X509_CRL* crl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,36 @@ int32_t CryptoNative_SslRead(SSL* ssl, void* buf, int32_t num)
return SSL_read(ssl, buf, num);
}

static int verify_callback(int preverify_ok, X509_STORE_CTX* store)
{
(void)preverify_ok;
(void)store;
// We don't care. Real verification happens in managed code.
return 1;
}

int32_t CryptoNative_SslRenegotiate(SSL* ssl)
{
// The openssl context is destroyed so we can't use ticket or session resumption.
SSL_set_options(ssl, SSL_OP_NO_TICKET | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);

int pending = SSL_renegotiate_pending(ssl);
if (!pending)
{
SSL_set_verify(ssl, SSL_VERIFY_PEER, verify_callback);
int ret = SSL_renegotiate(ssl);
if(ret != 1)
return ret;

return SSL_do_handshake(ssl);
}

return 0;
}

int32_t CryptoNative_IsSslRenegotiatePending(SSL* ssl)
{
SSL_peek(ssl, NULL, 0);
return SSL_renegotiate_pending(ssl) != 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ when an error is encountered.
*/
PALEXPORT int32_t CryptoNative_SslRead(SSL* ssl, void* buf, int32_t num);

/*
Shims the SSL_renegotiate method.

Returns 1 when renegotiation started; 0 on error.
*/
PALEXPORT int32_t CryptoNative_SslRenegotiate(SSL* ssl);

/*
Shims the SSL_renegotiate_pending method.

Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Net.Security/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@
<data name="net_ssl_renegotiate_data" xml:space="preserve">
<value>Received data during renegotiation.</value>
</data>
<data name="net_ssl_renegotiate_buffer" xml:space="preserve">
<value>Client stream needs to be drained before renegotiation.</value>
</data>
<data name="net_android_ssl_api_level_unsupported" xml:space="preserve">
<value>Setting an SNI hostname is not supported on this API level.</value>
</data>
Expand Down
Loading