VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/crypto/iprt-openssl.cpp@ 60756

Last change on this file since 60756 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/* $Id: iprt-openssl.cpp 57358 2015-08-14 15:16:38Z vboxsync $ */
2/** @file
3 * IPRT - Crypto - OpenSSL Helpers.
4 */
5
6/*
7 * Copyright (C) 2006-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "internal/iprt.h"
32
33#ifdef IPRT_WITH_OPENSSL /* Whole file. */
34# include <iprt/err.h>
35# include <iprt/string.h>
36
37# include "internal/iprt-openssl.h"
38# include <openssl/x509.h>
39# include <openssl/err.h>
40
41
42DECLHIDDEN(void) rtCrOpenSslInit(void)
43{
44 static bool s_fOssInitalized;
45 if (!s_fOssInitalized)
46 {
47 OpenSSL_add_all_algorithms();
48 ERR_load_ERR_strings();
49 ERR_load_crypto_strings();
50
51 s_fOssInitalized = true;
52 }
53}
54
55
56DECLHIDDEN(int) rtCrOpenSslErrInfoCallback(const char *pach, size_t cch, void *pvUser)
57{
58 PRTERRINFO pErrInfo = (PRTERRINFO)pvUser;
59 size_t cchAlready = pErrInfo->fFlags & RTERRINFO_FLAGS_SET ? strlen(pErrInfo->pszMsg) : 0;
60 if (cchAlready + 1 < pErrInfo->cbMsg)
61 RTStrCopyEx(pErrInfo->pszMsg + cchAlready, pErrInfo->cbMsg - cchAlready, pach, cch);
62 return -1;
63}
64
65
66DECLHIDDEN(int) rtCrOpenSslAddX509CertToStack(void *pvOsslStack, PCRTCRX509CERTIFICATE pCert)
67{
68 int rc;
69 const unsigned char *pabEncoded = (const unsigned char *)RTASN1CORE_GET_RAW_ASN1_PTR(&pCert->SeqCore.Asn1Core);
70 uint32_t cbEncoded = RTASN1CORE_GET_RAW_ASN1_SIZE(&pCert->SeqCore.Asn1Core);
71 X509 *pOsslCert = NULL;
72 if (d2i_X509(&pOsslCert, &pabEncoded, cbEncoded) == pOsslCert)
73 {
74 if (sk_X509_push((STACK_OF(X509) *)pvOsslStack, pOsslCert))
75 rc = VINF_SUCCESS;
76 else
77 {
78 rc = VERR_NO_MEMORY;
79 X509_free(pOsslCert);
80 }
81 }
82 else
83 rc = VERR_CR_X509_OSSL_D2I_FAILED;
84 return rc;
85}
86
87#endif /* IPRT_WITH_OPENSSL */
88
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette