Add CryptoNative_X509UpRef
authorJeremy Barton <jbarton@microsoft.com>
Mon, 11 Jul 2016 23:02:55 +0000 (16:02 -0700)
committerJeremy Barton <jbarton@microsoft.com>
Mon, 11 Jul 2016 23:02:55 +0000 (16:02 -0700)
commita903dcbcd08892070004c5adcec7088c7721c9ae
tree4e5f5e6f1a570c1189e5953800fa1ac639ecbe57
parent4f37d90ee0e7e3125c1d8eeba187699e4f0107b7
Add CryptoNative_X509UpRef

Use X509UpRef instead of X509Duplicate

X509Duplicate copies the certificate data into new memory, but none of the
callers needed copy semantics, just ensuring that the native components
which also are using the same memory don't unexpectedly free the object.

Protection from early/double-free is what the native reference count field is
for, so use UpRef instead of Duplicate.

Since we are currently targeting OpenSSL 1.0.x X509Upref adds to
references directly, X509_up_ref does not exist in the 1.0.x ABI.

Microbenchmark:
Cloning a certificate 1000 times by cert.Handle, measuring maximum resident set:
X509Duplicate (before): 48213 +/- 1501KB
X509UpRef (after): 39208 +/- 1021KB
Memory reduction: 9005 +/- 1816KB

Commit migrated from https://github.com/dotnet/corefx/commit/8f5eac55eb498c3c94f5a89655f4d7ad79a8711a
12 files changed:
src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs
src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs
src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs
src/libraries/Common/src/System/Net/Security/CertificateValidation.Unix.cs
src/libraries/Common/src/System/Net/Security/Unix/SafeFreeSslCredentials.cs
src/libraries/Native/System.Security.Cryptography.Native/pal_x509.cpp
src/libraries/Native/System.Security.Cryptography.Native/pal_x509.h
src/libraries/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.ClientCertificateProvider.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/CertificatePal.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/ExportProvider.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/OpenSslPkcs12Reader.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/OpenSslX509CertificateReader.cs