VirtualBox

source: vbox/trunk/src/VBox/Runtime/generic/RTCrStoreCreateSnapshotById-generic.cpp@ 57681

Last change on this file since 57681 was 57681, checked in by vboxsync, 10 years ago

RTCrStoreCreateSnapshotById-generic.cpp: Oracle Linux 5 update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/* $Id: RTCrStoreCreateSnapshotById-generic.cpp 57681 2015-09-09 22:09:44Z vboxsync $ */
2/** @file
3 * IPRT - Generic RTCrStoreCreateSnapshotById implementation.
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.215389.xyz. 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 <iprt/crypto/store.h>
32#include "internal/iprt.h"
33
34#include <iprt/assert.h>
35#include <iprt/err.h>
36#include <iprt/file.h>
37#include <iprt/dir.h>
38
39
40/*********************************************************************************************************************************
41* Defined Constants And Macros *
42*********************************************************************************************************************************/
43/** Unix root prefix. */
44#ifdef RT_OS_OS2
45# define UNIX_ROOT "/@unixroot@"
46#elif defined(RT_OS_WINDOWS)
47# define UNIX_ROOT "C:/cygwin"
48#else
49# define UNIX_ROOT
50#endif
51
52
53/*********************************************************************************************************************************
54* Global Variables *
55*********************************************************************************************************************************/
56/** System PEM files worth looking at.
57 * @remarks Several of these could be symlinks to one of the others.
58 */
59static const char *g_apszSystemPemFiles[] =
60{
61 UNIX_ROOT "/etc/ssl/certs/ca-certificates.crt",
62 UNIX_ROOT "/etc/ssl/cert.pem",
63 UNIX_ROOT "/etc/ca-certificates/extracted/tls-ca-bundle.pem", /* Arch linux (ca 2015-08-xx) */
64 UNIX_ROOT "/etc/ca-certificates/extracted/email-ca-bundle.pem",
65 UNIX_ROOT "/etc/ca-certificates/extracted/objsign-ca-bundle.pem",
66 UNIX_ROOT "/etc/ca-certificates/extracted/ca-bundle.trust.crt",
67 UNIX_ROOT "/etc/ca-certificates/extracted/ca-bundle.trust.crt",
68 UNIX_ROOT "/etc/pki/tls/certs/ca-bundle.crt", /* Oracle Linux 5 */
69 UNIX_ROOT "/etc/pki/tls/cert.pem",
70 UNIX_ROOT "/etc/curl/curlCA",
71};
72
73/**
74 * System directories containing lots of pem/crt files.
75 */
76static const char *g_apszSystemPemDirs[] =
77{
78 UNIX_ROOT "/etc/openssl/certs/",
79 UNIX_ROOT "/etc/ssl/certs/",
80 UNIX_ROOT "/etc/ca-certificates/extracted/cadir/",
81};
82
83
84RTDECL(int) RTCrStoreCreateSnapshotById(PRTCRSTORE phStore, RTCRSTOREID enmStoreId, PRTERRINFO pErrInfo)
85{
86 AssertReturn(enmStoreId > RTCRSTOREID_INVALID && enmStoreId < RTCRSTOREID_END, VERR_INVALID_PARAMETER);
87
88 /*
89 * Create an empty in-memory store.
90 */
91 RTCRSTORE hStore;
92 uint32_t cExpected = enmStoreId == RTCRSTOREID_SYSTEM_TRUSTED_CAS_AND_CERTIFICATES ? 256 : 0;
93 int rc = RTCrStoreCreateInMem(&hStore, cExpected);
94 if (RT_SUCCESS(rc))
95 {
96 *phStore = hStore;
97
98 /*
99 * Add system certificates if part of the given store ID.
100 */
101 bool fFound = false;
102 rc = VINF_SUCCESS;
103 if (enmStoreId == RTCRSTOREID_SYSTEM_TRUSTED_CAS_AND_CERTIFICATES)
104 {
105 for (uint32_t i = 0; i < RT_ELEMENTS(g_apszSystemPemFiles); i++)
106 if (RTFileExists(g_apszSystemPemFiles[i]))
107 {
108 fFound = true;
109 int rc2 = RTCrStoreCertAddFromFile(hStore,
110 RTCRCERTCTX_F_ADD_IF_NOT_FOUND | RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR,
111 g_apszSystemPemFiles[i], pErrInfo);
112 if (RT_FAILURE(rc2))
113 rc = -rc2;
114 }
115
116 /*
117 * If we didn't find any of the certificate collection files, go hunting
118 * for directories containing PEM/CRT files with single certificates.
119 */
120 if (!fFound)
121 for (uint32_t i = 0; i < RT_ELEMENTS(g_apszSystemPemDirs); i++)
122 if (RTDirExists(g_apszSystemPemDirs[i]))
123 {
124 static RTSTRTUPLE const s_aSuffixes[] =
125 {
126 { RT_STR_TUPLE(".crt") },
127 { RT_STR_TUPLE(".pem") },
128 { RT_STR_TUPLE(".PEM") },
129 { RT_STR_TUPLE(".CRT") },
130 };
131 fFound = true;
132 int rc2 = RTCrStoreCertAddFromDir(hStore,
133 RTCRCERTCTX_F_ADD_IF_NOT_FOUND | RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR,
134 g_apszSystemPemDirs[i], &s_aSuffixes[0], RT_ELEMENTS(s_aSuffixes),
135 pErrInfo);
136 if (RT_FAILURE(rc2))
137 rc = -rc2;
138 }
139 }
140 }
141 else
142 RTErrInfoAdd(pErrInfo, rc, " RTCrStoreCreateInMem failed");
143 return rc;
144}
145RT_EXPORT_SYMBOL(RTCrStoreCreateSnapshotById);
146
Note: See TracBrowser for help on using the repository browser.

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