From f95b91c547c1ba7491f493693dafcd7c2b7c6251 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Fri, 8 Dec 2006 13:07:06 +0000 Subject: [PATCH] Fixed invalid reuse of cert with gnutls_x509_crt_import (thanks to Benjamin Biron). --- src/security/cert/X509Certificate.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/security/cert/X509Certificate.cpp b/src/security/cert/X509Certificate.cpp index 65de1093..03af4efe 100644 --- a/src/security/cert/X509Certificate.cpp +++ b/src/security/cert/X509Certificate.cpp @@ -94,19 +94,21 @@ ref X509Certificate::import(utility::inputStream& is) ref X509Certificate::import (const byte_t* data, const unsigned int length) { - ref cert = vmime::create (); - gnutls_datum buffer; buffer.data = const_cast (data); buffer.size = length; // Try DER format - if (gnutls_x509_crt_import(cert->m_data->cert, &buffer, GNUTLS_X509_FMT_DER) >= 0) - return cert; + ref derCert = vmime::create (); + + if (gnutls_x509_crt_import(derCert->m_data->cert, &buffer, GNUTLS_X509_FMT_DER) >= 0) + return derCert; // Try PEM format - if (gnutls_x509_crt_import(cert->m_data->cert, &buffer, GNUTLS_X509_FMT_PEM) >= 0) - return cert; + ref pemCert = vmime::create (); + + if (gnutls_x509_crt_import(pemCert->m_data->cert, &buffer, GNUTLS_X509_FMT_PEM) >= 0) + return pemCert; return NULL; }