VirtualBox

source: vbox/trunk/include/iprt/crypto/store.h@ 57613

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

IPRT,UINetworkReply.cpp: Added RTPathGlob, a set of RTCrStoreCertAddWantedDir/File/Store, a RTCrStoreCertAddWantedFromFishingExpedition, RTCrStoreCertCheckWanted, RTCrStoreCertCount, RTFsIsCaseSensitive and RTFileOpenTemp. Reworked some RTHttp bits and UINetworkReply stuff - this needs testing.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.7 KB
Line 
1/** @file
2 * IPRT - Cryptographic (Certificate) Store.
3 */
4
5/*
6 * Copyright (C) 2006-2015 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_crypto_store_h
27#define ___iprt_crypto_store_h
28
29#include <iprt/crypto/x509.h>
30#include <iprt/crypto/taf.h>
31#include <iprt/sha.h>
32
33
34RT_C_DECLS_BEGIN
35
36/** @defgroup grp_rt_crstore RTCrStore - Crypotgraphic (Certificate) Store.
37 * @ingroup grp_rt_crypto
38 * @{
39 */
40
41
42/**
43 * A certificate store search.
44 *
45 * Used by the store provider to keep track of the current location of a
46 * certificate search.
47 */
48typedef struct RTCRSTORECERTSEARCH
49{
50 /** Opaque provider specific storage.
51 *
52 * Provider restriction: The provider is only allowed to use the two first
53 * entries for the find-all searches, because the front-end API may want the
54 * last two for implementing specific searches on top of it. */
55 uintptr_t auOpaque[4];
56} RTCRSTORECERTSEARCH;
57/** Pointer to a certificate store search. */
58typedef RTCRSTORECERTSEARCH *PRTCRSTORECERTSEARCH;
59
60
61/**
62 * Info about a wanted certificate.
63 *
64 * All the search criteria are optional, but for a safe and efficient search
65 * it's recommended to specify all possible ones. If none are given, the search
66 * function will fail.
67 *
68 * For use with RTCrStoreCertAddFromFishingExpedition and others.
69 */
70typedef struct RTCRCERTWANTED
71{
72 /** The certificate subject name, optional.
73 * The format is: "C=US, ST=California, L=Redwood Shores, O=Oracle Corporation" */
74 const char *pszSubject;
75 /** The size of the DER (ASN.1) encoded certificate, optional (0). */
76 uint16_t cbEncoded;
77 /** Set if abSha1 contains a valid SHA-1 fingerprint. */
78 bool fSha1Fingerprint;
79 /** Set if abSha512 contains a valid SHA-512 fingerprint. */
80 bool fSha512Fingerprint;
81 /** The SHA-1 fingerprint (of the encoded data). */
82 uint8_t abSha1[RTSHA1_HASH_SIZE];
83 /** The SHA-512 fingerprint (of the encoded data). */
84 uint8_t abSha512[RTSHA512_HASH_SIZE];
85 /** User pointer for directly associating other data with the entry.
86 * Subclassing the structure isn't possible because it's passed as an array. */
87 void const *pvUser;
88} RTCRCERTWANTED;
89/** Pointer to a const certificat wanted structure. */
90typedef RTCRCERTWANTED const *PCRTCRCERTWANTED;
91
92
93/**
94 * Standard store identifiers.
95 *
96 * This is a least common denominator approach to system specific certificate
97 * stores, could be extended to include things other than certificates later if
98 * we need it.
99 *
100 * Windows has lots of different stores, they'll be combined by the
101 * implementation, possibly leading to duplicates. The user stores on Windows
102 * seems to be unioned with the system (machine) stores.
103 *
104 * Linux may have different stores depending on the distro/version/installation,
105 * in which case we'll combine them, which will most likely lead to
106 * duplicates just like on windows. Haven't found any easily accessible
107 * per-user certificate stores on linux yet, so they'll all be empty.
108 *
109 * Mac OS X seems a lot simpler, at least from the GUI point of view. Each
110 * keychains as a "Certificates" folder (the "My Certificates" folder seems to
111 * only be a matching of "Keys" and "Certificates"). However, there are two
112 * system keychains that we need to combine, "System" and "System Roots". As
113 * with Windows and Linux, there is a possibility for duplicates here.
114 *
115 * On solaris we have currently no idea where to look for a certificate store,
116 * so that doesn't yet work.
117 *
118 * Because of the OS X setup, we do not provide any purpose specific
119 */
120typedef enum RTCRSTOREID
121{
122 /** Mandatory invalid zero value. */
123 RTCRSTOREID_INVALID = 0,
124 /** Open the certificate store of the current user containing trusted
125 * CAs and certificates.
126 * @remarks This may or may not include all the certificates in the system
127 * store, that's host dependent. So, you better look in both. */
128 RTCRSTOREID_USER_TRUSTED_CAS_AND_CERTIFICATES,
129 /** Open the certificate store of the system containg trusted CAs
130 * and certificates. */
131 RTCRSTOREID_SYSTEM_TRUSTED_CAS_AND_CERTIFICATES,
132 /** End of valid values. */
133 RTCRSTOREID_END,
134 /** Traditional enum type compression prevention hack. */
135 RTCRSTOREID_32BIT_HACK = 0x7fffffff
136} RTCRSTOREID;
137
138/**
139 * Creates a snapshot of a standard store.
140 *
141 * This will return an in-memory store containing all data from the given store.
142 * There will be no duplicates in this one.
143 *
144 * @returns IPRT status code.
145 * @retval VWRN_ALREADY_EXISTS if the certificate is already present and
146 * RTCRCERTCTX_F_ADD_IF_NOT_FOUND was specified.
147 * @param phStore Where to return the store handle. Use
148 * RTCrStoreRelease to release it.
149 * @param enmStoreId The store to snapshot.
150 * @param pErrInfo Where to return additional error/warning info.
151 * Optional.
152 */
153RTDECL(int) RTCrStoreCreateSnapshotById(PRTCRSTORE phStore, RTCRSTOREID enmStoreId, PRTERRINFO pErrInfo);
154
155RTDECL(int) RTCrStoreCreateInMem(PRTCRSTORE phStore, uint32_t cSizeHint);
156
157RTDECL(uint32_t) RTCrStoreRetain(RTCRSTORE hStore);
158RTDECL(uint32_t) RTCrStoreRelease(RTCRSTORE hStore);
159RTDECL(PCRTCRCERTCTX) RTCrStoreCertByIssuerAndSerialNo(RTCRSTORE hStore, PCRTCRX509NAME pIssuer, PCRTASN1INTEGER pSerialNo);
160
161/**
162 * Add a certificate to the store.
163 *
164 * @returns IPRT status code.
165 * @retval VWRN_ALREADY_EXISTS if the certificate is already present and
166 * RTCRCERTCTX_F_ADD_IF_NOT_FOUND was specified.
167 * @retval VERR_WRITE_PROTECT if the store doesn't support adding.
168 * @param hStore The store to add the certificate to.
169 * @param fFlags RTCRCERTCTX_F_XXX. Encoding must be specified.
170 * RTCRCERTCTX_F_ADD_IF_NOT_FOUND is supported.
171 * @param pvSrc The encoded certificate bytes.
172 * @param cbSrc The size of the encoded certificate.
173 * @param pErrInfo Where to return additional error/warning info.
174 * Optional.
175 */
176RTDECL(int) RTCrStoreCertAddEncoded(RTCRSTORE hStore, uint32_t fFlags, void const *pvSrc, size_t cbSrc, PRTERRINFO pErrInfo);
177
178/**
179 * Adds certificates from files in the specified directory.
180 *
181 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is
182 * used, an error is returned as an error (and not a warning).
183 *
184 * @param hStore The store to add the certificate(s) to.
185 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or
186 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR.
187 * @param pszDir The path to the directory.
188 * @param paSuffixes List of suffixes of files to process.
189 * @param cSuffixes Number of suffixes. If this is 0, all files are
190 * processed.
191 * @param pErrInfo Where to return additional error/warning info.
192 * Optional.
193 */
194RTDECL(int) RTCrStoreCertAddFromDir(RTCRSTORE hStore, uint32_t fFlags, const char *pszDir,
195 PCRTSTRTUPLE paSuffixes, size_t cSuffixes, PRTERRINFO pErrInfo);
196
197RTDECL(int) RTCrStoreCertAddWantedFromDir(RTCRSTORE hStore, uint32_t fFlags,
198 const char *pszDir, PCRTSTRTUPLE paSuffixes, size_t cSuffixes,
199 PCRTCRCERTWANTED paWanted, size_t cWanted, bool *pafFound, PRTERRINFO pErrInfo);
200
201/**
202 * Adds certificates from the specified file.
203 *
204 * The supported file formats are:
205 * - PEM (base 64 blobs wrapped in -----BEGIN / END----). Support multiple
206 * certificates in one file.
207 * - Binary DER ASN.1 certificate. Only one per file.
208 * - Java key store version 2.
209 *
210 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is
211 * used, an error is returned as an error (and not a warning).
212 *
213 * @param hStore The store to add the certificate(s) to.
214 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or
215 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR.
216 * @param pszFilename The filename.
217 * @param pErrInfo Where to return additional error/warning info.
218 * Optional.
219 */
220RTDECL(int) RTCrStoreCertAddFromFile(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo);
221
222RTDECL(int) RTCrStoreCertAddWantedFromFile(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename,
223 PCRTCRCERTWANTED paWanted, size_t cWanted, bool *pafFound, PRTERRINFO pErrInfo);
224
225/**
226 * Adds certificates from the specified java key store file.
227 *
228 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is
229 * used, an error is returned as an error (and not a warning).
230 *
231 * @param hStore The store to add the certificate(s) to.
232 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or
233 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR.
234 * @param pszFilename The path to the JKS file.
235 * @param pErrInfo Where to return additional error/warning info.
236 * Optional.
237 */
238RTDECL(int) RTCrStoreCertAddFromJavaKeyStore(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo);
239
240/**
241 * Adds certificates from an in-memory java key store.
242 *
243 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is
244 * used, an error is returned as an error (and not a warning).
245 *
246 * @param hStore The store to add the certificate(s) to.
247 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or
248 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR.
249 * @param pvContent Pointer to the key store bytes.
250 * @param cbContent The size of the key store.
251 * @param pszErrorName The file name or whatever helpful indicator the
252 * caller want in the error messages.
253 * @param pErrInfo Where to return additional error/warning info.
254 * Optional.
255 */
256RTDECL(int) RTCrStoreCertAddFromJavaKeyStoreInMem(RTCRSTORE hStore, uint32_t fFlags, void const *pvContent, size_t cbContent,
257 const char *pszErrorName, PRTERRINFO pErrInfo);
258
259/**
260 * Adds all certificates from @a hStoreSrc into @a hStore.
261 *
262 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is
263 * used, an error is returned as an error (and not a warning).
264 *
265 * @param hStore The destination store.
266 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or
267 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR.
268 * @param hStoreSrc The source store.
269 */
270RTDECL(int) RTCrStoreCertAddFromStore(RTCRSTORE hStore, uint32_t fFlags, RTCRSTORE hStoreSrc);
271
272RTDECL(int) RTCrStoreCertAddWantedFromStore(RTCRSTORE hStore, uint32_t fFlags, RTCRSTORE hSrcStore,
273 PCRTCRCERTWANTED paWanted, size_t cWanted, bool *pafFound);
274
275RTDECL(int) RTCrStoreCertCheckWanted(RTCRSTORE hStore, PCRTCRCERTWANTED paWanted, size_t cWanted, bool *pafFound);
276
277
278RTDECL(int) RTCrStoreCertAddWantedFromFishingExpedition(RTCRSTORE hStore, uint32_t fFlags,
279 PCRTCRCERTWANTED paWanted, size_t cWanted,
280 bool *pafFound, PRTERRINFO pErrInfo);
281
282/**
283 * Exports the certificates in the store to a PEM file
284 *
285 * @returns IPRT status code.
286 * @param hStore The store which certificates should be exported.
287 * @param fFlags Reserved for the future, MBZ.
288 * @param pszFilename The name of the destination PEM file. This will
289 * be truncated.
290 */
291RTDECL(int) RTCrStoreCertExportAsPem(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename);
292
293/**
294 * Counts the number of certificates in the store.
295 *
296 * @returns Certificate count on success, UINT32_MAX on failure.
297 * @param hStore The store which certificates should be counted.
298 */
299RTDECL(uint32_t) RTCrStoreCertCount(RTCRSTORE hStore);
300
301RTDECL(int) RTCrStoreCertFindAll(RTCRSTORE hStore, PRTCRSTORECERTSEARCH pSearch);
302RTDECL(int) RTCrStoreCertFindBySubjectOrAltSubjectByRfc5280(RTCRSTORE hStore, PCRTCRX509NAME pSubject,
303 PRTCRSTORECERTSEARCH pSearch);
304RTDECL(PCRTCRCERTCTX) RTCrStoreCertSearchNext(RTCRSTORE hStore, PRTCRSTORECERTSEARCH pSearch);
305RTDECL(int) RTCrStoreCertSearchDestroy(RTCRSTORE hStore, PRTCRSTORECERTSEARCH pSearch);
306
307RTDECL(int) RTCrStoreConvertToOpenSslCertStore(RTCRSTORE hStore, uint32_t fFlags, void **ppvOpenSslStore);
308RTDECL(int) RTCrStoreConvertToOpenSslCertStack(RTCRSTORE hStore, uint32_t fFlags, void **ppvOpenSslStack);
309
310
311/** @} */
312
313
314/** @defgroup grp_rt_crcertctx RTCrCertCtx - (Store) Certificate Context.
315 * @{ */
316
317
318/**
319 * Certificate context.
320 *
321 * This is returned by the certificate store APIs and is part of a larger
322 * reference counted structure. All the data is read only.
323 */
324typedef struct RTCRCERTCTX
325{
326 /** Flags, RTCRCERTCTX_F_XXX. */
327 uint32_t fFlags;
328 /** The size of the (DER) encoded certificate. */
329 uint32_t cbEncoded;
330 /** Pointer to the (DER) encoded certificate. */
331 uint8_t const *pabEncoded;
332 /** Pointer to the decoded X.509 representation of the certificate.
333 * This can be NULL when pTaInfo is present. */
334 PCRTCRX509CERTIFICATE pCert;
335 /** Pointer to the decoded TrustAnchorInfo for the certificate. This can be
336 * NULL, even for trust anchors, as long as pCert isn't. */
337 PCRTCRTAFTRUSTANCHORINFO pTaInfo;
338 /** Reserved for future use. */
339 void *paReserved[2];
340} RTCRCERTCTX;
341
342/** @name RTCRCERTCTX_F_XXX.
343 * @{ */
344/** Encoding mask. */
345#define RTCRCERTCTX_F_ENC_MASK UINT32_C(0x000000ff)
346/** X.509 certificate, DER encoded. */
347#define RTCRCERTCTX_F_ENC_X509_DER UINT32_C(0x00000000)
348/** RTF-5914 trust anchor info, DER encoded. */
349#define RTCRCERTCTX_F_ENC_TAF_DER UINT32_C(0x00000001)
350#if 0
351/** Extended certificate, DER encoded. */
352#define RTCRCERTCTX_F_ENC_PKCS6_DER UINT32_C(0x00000002)
353#endif
354/** Mask containing the flags that ends up in the certificate context. */
355#define RTCRCERTCTX_F_MASK UINT32_C(0x000000ff)
356
357/** Add APIs: Add the certificate if not found. */
358#define RTCRCERTCTX_F_ADD_IF_NOT_FOUND UINT32_C(0x00010000)
359/** Add APIs: Continue on error when possible. */
360#define RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR UINT32_C(0x00020000)
361/** @} */
362
363
364RTDECL(uint32_t) RTCrCertCtxRetain(PCRTCRCERTCTX pCertCtx);
365RTDECL(uint32_t) RTCrCertCtxRelease(PCRTCRCERTCTX pCertCtx);
366
367/** @} */
368
369RT_C_DECLS_END
370
371#endif
372
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