VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/crypto/store-internal.h

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: store-internal.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Cryptographic Store, Internal Header.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef IPRT_INCLUDED_SRC_common_crypto_store_internal_h
38#define IPRT_INCLUDED_SRC_common_crypto_store_internal_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43
44/**
45 * Internal certificate context.
46 *
47 * In addition to the externally visible structure (RTCRCERTCTX) this has the
48 * reference counter and store reference. (This structure may again be part of
49 * a larger structure internal to the store, depending on the source store.)
50 */
51typedef struct RTCRCERTCTXINT
52{
53 /** Magic number (RTCRCERTCTXINT_MAGIC). */
54 uint32_t u32Magic;
55 /** Reference counter. */
56 uint32_t volatile cRefs;
57 /**
58 * Destructor that gets called with cRefs reaches zero.
59 * @param pCertCtx The internal certificate context.
60 */
61 DECLCALLBACKMEMBER(void, pfnDtor,(struct RTCRCERTCTXINT *pCertCtx));
62 /** The public store context. */
63 RTCRCERTCTX Public;
64} RTCRCERTCTXINT;
65/** Pointer to an internal certificate context. */
66typedef RTCRCERTCTXINT *PRTCRCERTCTXINT;
67
68/** Magic value for RTCRCERTCTXINT::u32Magic (Alan Mathison Turing). */
69#define RTCRCERTCTXINT_MAGIC UINT32_C(0x19120623)
70/** Dead magic value for RTCRCERTCTXINT::u32Magic. */
71#define RTCRCERTCTXINT_MAGIC_DEAD UINT32_C(0x19540607)
72
73
74/**
75 * IPRT Cryptographic Store Provider.
76 *
77 * @remarks This is a very incomplete sketch.
78 */
79typedef struct RTCRSTOREPROVIDER
80{
81 /** The provider name. */
82 const char *pszName;
83
84 /**
85 * Called to destroy an open store.
86 *
87 * @param pvProvider The provider specific data.
88 */
89 DECLCALLBACKMEMBER(void, pfnDestroyStore,(void *pvProvider));
90
91 /**
92 * Queries the private key.
93 *
94 * @returns IPRT status code.
95 * @retval VERR_NOT_FOUND if not private key.
96 * @retval VERR_ACCESS_DENIED if the private key isn't allowed to leave the
97 * store. One would then have to use the pfnCertCtxSign method.
98 *
99 * @param pvProvider The provider specific data.
100 * @param pCertCtx The internal certificate context.
101 * @param pbKey Where to return the key bytes.
102 * @param cbKey The size of the buffer @a pbKey points to.
103 * @param pcbKeyRet Where to return the size of the returned key.
104 */
105 DECLCALLBACKMEMBER(int, pfnCertCtxQueryPrivateKey,(void *pvProvider, PRTCRCERTCTXINT pCertCtx,
106 uint8_t *pbKey, size_t cbKey, size_t *pcbKeyRet));
107
108 /**
109 * Open an enumeration of all certificates.
110 *
111 * @returns IPRT status code
112 * @param pvProvider The provider specific data.
113 * @param pSearch Pointer to opaque search state structure. The
114 * provider should initalize this on success.
115 */
116 DECLCALLBACKMEMBER(int, pfnCertFindAll,(void *pvProvider, PRTCRSTORECERTSEARCH pSearch));
117
118 /**
119 * Get the next certificate.
120 *
121 * @returns Reference to the next certificate context (must be released by
122 * caller). NULL if no more certificates in the search result.
123 * @param pvProvider The provider specific data.
124 * @param pSearch Pointer to opaque search state structure.
125 */
126 DECLCALLBACKMEMBER(PCRTCRCERTCTX, pfnCertSearchNext,(void *pvProvider, PRTCRSTORECERTSEARCH pSearch));
127
128 /**
129 * Closes a certficate search state.
130 *
131 * @param pvProvider The provider specific data.
132 * @param pSearch Pointer to opaque search state structure to destroy.
133 */
134 DECLCALLBACKMEMBER(void, pfnCertSearchDestroy,(void *pvProvider, PRTCRSTORECERTSEARCH pSearch));
135
136 /**
137 * Adds a certificate to the store.
138 *
139 * @returns IPRT status code.
140 * @retval VWRN_ALREADY_EXISTS if the certificate is already present and
141 * RTCRCERTCTX_F_ADD_IF_NOT_FOUND was specified.
142 * @param pvProvider The provider specific data.
143 * @param fFlags RTCRCERTCTX_F_XXX.
144 * @param pbEncoded The encoded certificate bytes.
145 * @param cbEncoded The size of the encoded certificate.
146 * @param pErrInfo Where to store extended error info. Optional.
147 */
148 DECLCALLBACKMEMBER(int, pfnCertAddEncoded,(void *pvProvider, uint32_t fFlags, uint8_t const *pbEncoded, uint32_t cbEncoded,
149 PRTERRINFO pErrInfo));
150
151
152 /* Optional: */
153
154 /**
155 * Find all certficates matching a given issuer and serial number.
156 *
157 * (Usually only one result.)
158 *
159 * @returns IPRT status code
160 * @param pvProvider The provider specific data.
161 * @param phSearch Pointer to a provider specific search handle.
162 */
163 DECLCALLBACKMEMBER(int, pfnCertFindByIssuerAndSerialNo,(void *pvProvider, PCRTCRX509NAME pIssuer, PCRTASN1INTEGER pSerialNo,
164 PRTCRSTORECERTSEARCH phSearch));
165 /** Non-zero end marker. */
166 uintptr_t uEndMarker;
167} RTCRSTOREPROVIDER;
168
169/** Pointer to a store provider call table. */
170typedef RTCRSTOREPROVIDER const *PCRTCRSTOREPROVIDER;
171
172
173DECLHIDDEN(int) rtCrStoreCreate(PCRTCRSTOREPROVIDER pProvider, void *pvProvider, PRTCRSTORE phStore);
174DECLHIDDEN(PCRTCRSTOREPROVIDER) rtCrStoreGetProvider(RTCRSTORE hStore, void **ppvProvider);
175
176#endif /* !IPRT_INCLUDED_SRC_common_crypto_store_internal_h */
177
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use