public void Dispose() { if (_caStackHandle != null) { _caStackHandle.Dispose(); _caStackHandle = null; } if (_x509Handle != null) { _x509Handle.Dispose(); _x509Handle = null; } if (_evpPkeyHandle != null) { _evpPkeyHandle.Dispose(); _evpPkeyHandle = null; } if (_pkcs12Handle != null) { _pkcs12Handle.Dispose(); } }
internal static extern SafePkcs12Handle PKCS12_create( string pass, string name, SafeEvpPkeyHandle pkey, SafeX509Handle cert, SafeX509StackHandle ca, int nid_key, int nid_cert, int iter, int mac_iter, int keytype);
internal OpenSslX509CertificateReader DuplicateHandles() { SafeX509Handle certHandle = Interop.libcrypto.X509_dup(_cert); OpenSslX509CertificateReader duplicate = new OpenSslX509CertificateReader(certHandle); if (_privateKey != null) { SafeEvpPkeyHandle keyHandle = SafeEvpPkeyHandle.DuplicateHandle(_privateKey); duplicate.SetPrivateKey(keyHandle); } return(duplicate); }
public void Dispose() { if (_privateKey != null) { _privateKey.Dispose(); _privateKey = null; } if (_cert != null) { _cert.Dispose(); _cert = null; } }
public List <OpenSslX509CertificateReader> ReadCertificates() { var certs = new List <OpenSslX509CertificateReader>(); if (_caStackHandle != null && !_caStackHandle.IsInvalid) { int caCertCount = Interop.Crypto.GetX509StackFieldCount(_caStackHandle); for (int i = 0; i < caCertCount; i++) { IntPtr certPtr = Interop.Crypto.GetX509StackField(_caStackHandle, i); if (certPtr != IntPtr.Zero) { // The STACK_OF(X509) still needs to be cleaned up, so duplicate the handle out of it. certs.Add(new OpenSslX509CertificateReader(Interop.libcrypto.X509_dup(certPtr))); } } } if (_x509Handle != null && !_x509Handle.IsInvalid) { // The certificate and (if applicable) private key handles will be given over // to the OpenSslX509CertificateReader, and the fields here are thus nulled out to // prevent double-Dispose. OpenSslX509CertificateReader reader = new OpenSslX509CertificateReader(_x509Handle); _x509Handle = null; if (_evpPkeyHandle != null && !_evpPkeyHandle.IsInvalid) { reader.SetPrivateKey(_evpPkeyHandle); _evpPkeyHandle = null; } certs.Add(reader); } return(certs); }
internal void SetPrivateKey(SafeEvpPkeyHandle privateKey) { _privateKey = privateKey; }
internal static extern bool PKCS12_parse(SafePkcs12Handle p12, string pass, out SafeEvpPkeyHandle pkey, out SafeX509Handle cert, out SafeX509StackHandle ca);
internal static extern int UpRefEvpPkey(SafeEvpPkeyHandle handle);
internal static extern SafeRsaHandle EVP_PKEY_get1_RSA(SafeEvpPkeyHandle pkey);