Changeset 50954 in vbox
- Timestamp:
- Apr 2, 2014 4:19:56 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/x509.h
r50835 r50954 38 38 */ 39 39 40 RTDECL(void) RTX509PrepareOpenSSL(); 40 /** 41 * Preparation before start to work with openssl 42 * 43 * @todo This should return a status and check that X509 code seems sane. This 44 * would allow dynamic linking if necessary at some point. 45 */ 46 RTDECL(int) RTX509PrepareOpenSSL(void); 47 41 48 /** 42 49 * Verify RSA signature for the given memory buffer. … … 64 71 RTDECL(int) RTX509CertificateVerify(void *pvBuf, unsigned int cbSize); 65 72 73 /** @todo document me. */ 66 74 RTDECL(unsigned long) RTX509GetErrorDescription(char** pErrorDesc); 67 75 -
trunk/src/VBox/Runtime/common/checksum/x509.cpp
r50904 r50954 30 30 *******************************************************************************/ 31 31 #include "internal/iprt.h" 32 33 #include <openssl/bio.h>34 #include <openssl/err.h>35 #include <openssl/pem.h>36 #include <openssl/x509.h>37 #include <openssl/x509v3.h>38 39 32 #include <iprt/x509.h> 33 40 34 #include <iprt/assert.h> 41 35 #include <iprt/mem.h> … … 45 39 #include <iprt/string.h> 46 40 41 #include <openssl/bio.h> 42 #include <openssl/err.h> 43 #include <openssl/pem.h> 44 #include <openssl/x509.h> 45 #include <openssl/x509v3.h> 46 47 47 48 /** 48 49 * Preparation before start to work with openssl 49 50 * 50 * @returns none 51 * 52 */ 53 RTDECL(void) RTX509PrepareOpenSSL() 51 * @returns IPRT status code. 52 */ 53 RTDECL(int) RTX509PrepareOpenSSL(void) 54 54 { 55 55 OpenSSL_add_all_digests(); 56 56 ERR_load_BIO_strings(); 57 57 ERR_load_crypto_strings(); 58 return VINF_SUCCESS; 58 59 } 59 60 RT_EXPORT_SYMBOL(RTX509PrepareOpenSSL); 60 61 62 61 63 /** 62 * Read X509 certificate from the given memory buffer into the 63 * internal structure. 64 * 65 * @returns iprt status code. 66 * 67 * @param pvBuf string representation 68 * containing X509 certificate 69 * in PEM format 70 * @param cbSize The amount of data (in bytes) 71 * @param out_cert pointer to the structure where 72 * the info about X509 73 * certificate will be stored 74 */ 75 static int RTX509ReadCertificateFromPEM(void *pvBuf, unsigned int cbSize, X509** out_cert) 76 { 77 int rc = VINF_SUCCESS; 78 79 BIO *bio_memory = BIO_new(BIO_s_mem()); 80 int cbytes = BIO_write(bio_memory,(const void*)pvBuf ,cbSize) ; 81 *out_cert = PEM_read_bio_X509(bio_memory,NULL,0,NULL); 82 BIO_free(bio_memory); 83 if(!*out_cert) 84 rc = VERR_X509_READING_CERT_FROM_BIO; 85 86 return rc; 87 } 64 * Read X509 certificate from the given memory buffer into the internal 65 * structure. 66 * 67 * @returns IPRT status code. 68 * 69 * @param pvBuf String representation containing X509 70 * certificate in PEM format. 71 * @param cbBuf The amount of data @a pvBuf points to. 72 * @param ppOutCert Where to store the pointer to the structure where 73 * the info about X509 certificate will be stored. 74 */ 75 static int rtX509ReadCertificateFromPEM(void const *pvPem, unsigned int cbPem, X509 **ppOutCert) 76 { 77 BIO *pBio = BIO_new(BIO_s_mem()); 78 if (!pBio) 79 return VERR_NO_MEMORY; 80 81 int cb = BIO_write(pBio, pvPem, cbPem); 82 *ppOutCert = PEM_read_bio_X509(pBio, NULL, 0, NULL); 83 BIO_free(pBio); 84 85 return *ppOutCert ? VINF_SUCCESS : VERR_X509_READING_CERT_FROM_BIO; 86 } 87 88 88 89 89 /** … … 194 194 } 195 195 196 rc = RTX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);196 rc = rtX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate); 197 197 if (RT_FAILURE(rc)) 198 198 { … … 267 267 BIO *bio_memory = NULL; 268 268 269 while (1)270 { 271 rc = RTX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);269 for (;;) 270 { 271 rc = rtX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate); 272 272 int loc = X509_get_ext_by_NID(certificate, NID_basic_constraints,-1); 273 273 … … 332 332 while(1) 333 333 { 334 rc = RTX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);334 rc = rtX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate); 335 335 if (RT_FAILURE(rc)) 336 336 { … … 384 384 return rc; 385 385 } 386 387 386 RT_EXPORT_SYMBOL(RTX509CertificateVerify); 387 388 388 389 389 RTDECL(unsigned long) RTX509GetErrorDescription(char** pErrorDesc)
Note:
See TracChangeset
for help on using the changeset viewer.