Juan Lang | 02cb0c7 | 2005-08-25 09:51:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2005 Juan Lang |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Juan Lang | 02cb0c7 | 2005-08-25 09:51:59 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #ifndef __CRYPT32_PRIVATE_H__ |
| 20 | #define __CRYPT32_PRIVATE_H__ |
| 21 | |
Juan Lang | f224b34 | 2006-05-15 17:01:28 -0700 | [diff] [blame] | 22 | /* a few asn.1 tags we need */ |
| 23 | #define ASN_BOOL (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x01) |
| 24 | #define ASN_BITSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x03) |
| 25 | #define ASN_ENUMERATED (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x0a) |
Juan Lang | ead2118 | 2006-07-19 07:44:48 -0700 | [diff] [blame] | 26 | #define ASN_UTF8STRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x0c) |
Juan Lang | f224b34 | 2006-05-15 17:01:28 -0700 | [diff] [blame] | 27 | #define ASN_SETOF (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x11) |
| 28 | #define ASN_NUMERICSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x12) |
| 29 | #define ASN_PRINTABLESTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x13) |
Juan Lang | dd4bd4a | 2006-06-02 13:20:13 -0700 | [diff] [blame] | 30 | #define ASN_T61STRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x14) |
Juan Lang | ead2118 | 2006-07-19 07:44:48 -0700 | [diff] [blame] | 31 | #define ASN_VIDEOTEXSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x15) |
Juan Lang | f224b34 | 2006-05-15 17:01:28 -0700 | [diff] [blame] | 32 | #define ASN_IA5STRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x16) |
| 33 | #define ASN_UTCTIME (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x17) |
| 34 | #define ASN_GENERALTIME (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x18) |
Juan Lang | ead2118 | 2006-07-19 07:44:48 -0700 | [diff] [blame] | 35 | #define ASN_GRAPHICSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x19) |
| 36 | #define ASN_VISIBLESTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x1a) |
| 37 | #define ASN_GENERALSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x1b) |
| 38 | #define ASN_UNIVERSALSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x1c) |
| 39 | #define ASN_BMPSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x1e) |
Juan Lang | f224b34 | 2006-05-15 17:01:28 -0700 | [diff] [blame] | 40 | |
Juan Lang | 48afa16 | 2007-07-12 14:09:00 -0700 | [diff] [blame] | 41 | BOOL CRYPT_EncodeLen(DWORD len, BYTE *pbEncoded, DWORD *pcbEncoded); |
| 42 | |
| 43 | typedef BOOL (WINAPI *CryptEncodeObjectExFunc)(DWORD, LPCSTR, const void *, |
| 44 | DWORD, PCRYPT_ENCODE_PARA, BYTE *, DWORD *); |
| 45 | |
| 46 | struct AsnEncodeSequenceItem |
| 47 | { |
| 48 | const void *pvStructInfo; |
| 49 | CryptEncodeObjectExFunc encodeFunc; |
| 50 | DWORD size; /* used during encoding, not for your use */ |
| 51 | }; |
| 52 | |
| 53 | BOOL WINAPI CRYPT_AsnEncodeSequence(DWORD dwCertEncodingType, |
| 54 | struct AsnEncodeSequenceItem items[], DWORD cItem, DWORD dwFlags, |
| 55 | PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded); |
| 56 | |
| 57 | struct AsnConstructedItem |
| 58 | { |
| 59 | BYTE tag; |
| 60 | const void *pvStructInfo; |
| 61 | CryptEncodeObjectExFunc encodeFunc; |
| 62 | }; |
| 63 | |
| 64 | BOOL WINAPI CRYPT_AsnEncodeConstructed(DWORD dwCertEncodingType, |
| 65 | LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, |
| 66 | PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded); |
Juan Lang | 48afa16 | 2007-07-12 14:09:00 -0700 | [diff] [blame] | 67 | BOOL WINAPI CRYPT_AsnEncodeOid(DWORD dwCertEncodingType, |
| 68 | LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, |
| 69 | PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded); |
Juan Lang | 8599fd7 | 2007-07-12 14:59:27 -0700 | [diff] [blame] | 70 | BOOL WINAPI CRYPT_AsnEncodeOctets(DWORD dwCertEncodingType, |
| 71 | LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, |
| 72 | PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded); |
Juan Lang | 48afa16 | 2007-07-12 14:09:00 -0700 | [diff] [blame] | 73 | |
Juan Lang | 703a0f6 | 2007-07-17 07:22:50 -0700 | [diff] [blame] | 74 | typedef struct _CRYPT_DIGESTED_DATA |
| 75 | { |
| 76 | DWORD version; |
| 77 | CRYPT_ALGORITHM_IDENTIFIER DigestAlgorithm; |
| 78 | CRYPT_CONTENT_INFO ContentInfo; |
| 79 | CRYPT_HASH_BLOB hash; |
| 80 | } CRYPT_DIGESTED_DATA; |
| 81 | |
Andrew Talbot | 465a583 | 2009-06-12 18:27:56 +0100 | [diff] [blame] | 82 | BOOL CRYPT_AsnEncodePKCSDigestedData(const CRYPT_DIGESTED_DATA *digestedData, |
Juan Lang | 703a0f6 | 2007-07-17 07:22:50 -0700 | [diff] [blame] | 83 | void *pvData, DWORD *pcbData); |
| 84 | |
Juan Lang | b80101e | 2007-07-23 18:11:17 -0700 | [diff] [blame] | 85 | typedef struct _CRYPT_SIGNED_INFO |
| 86 | { |
Juan Lang | 282eb73 | 2008-08-20 11:57:21 -0700 | [diff] [blame] | 87 | DWORD version; |
| 88 | DWORD cCertEncoded; |
| 89 | PCERT_BLOB rgCertEncoded; |
| 90 | DWORD cCrlEncoded; |
| 91 | PCRL_BLOB rgCrlEncoded; |
| 92 | CRYPT_CONTENT_INFO content; |
| 93 | DWORD cSignerInfo; |
| 94 | PCMSG_CMS_SIGNER_INFO rgSignerInfo; |
Juan Lang | b80101e | 2007-07-23 18:11:17 -0700 | [diff] [blame] | 95 | } CRYPT_SIGNED_INFO; |
| 96 | |
Juan Lang | 282eb73 | 2008-08-20 11:57:21 -0700 | [diff] [blame] | 97 | BOOL CRYPT_AsnEncodeCMSSignedInfo(CRYPT_SIGNED_INFO *, void *pvData, |
Juan Lang | b80101e | 2007-07-23 18:11:17 -0700 | [diff] [blame] | 98 | DWORD *pcbData); |
| 99 | |
Juan Lang | 282eb73 | 2008-08-20 11:57:21 -0700 | [diff] [blame] | 100 | BOOL CRYPT_AsnDecodeCMSSignedInfo(const BYTE *pbEncoded, DWORD cbEncoded, |
Juan Lang | 3a85fa6 | 2007-07-25 18:12:16 -0700 | [diff] [blame] | 101 | DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara, |
| 102 | CRYPT_SIGNED_INFO *signedInfo, DWORD *pcbSignedInfo); |
| 103 | |
Juan Lang | 48afa16 | 2007-07-12 14:09:00 -0700 | [diff] [blame] | 104 | /* Helper function to check *pcbEncoded, set it to the required size, and |
| 105 | * optionally to allocate memory. Assumes pbEncoded is not NULL. |
| 106 | * If CRYPT_ENCODE_ALLOC_FLAG is set in dwFlags, *pbEncoded will be set to a |
| 107 | * pointer to the newly allocated memory. |
| 108 | */ |
Andrew Talbot | 28e1ec4 | 2010-08-15 20:15:26 +0100 | [diff] [blame^] | 109 | BOOL CRYPT_EncodeEnsureSpace(DWORD dwFlags, const CRYPT_ENCODE_PARA *pEncodePara, |
Juan Lang | 48afa16 | 2007-07-12 14:09:00 -0700 | [diff] [blame] | 110 | BYTE *pbEncoded, DWORD *pcbEncoded, DWORD bytesNeeded); |
| 111 | |
Juan Lang | 35abf3a | 2007-07-17 07:25:31 -0700 | [diff] [blame] | 112 | BOOL CRYPT_AsnDecodePKCSDigestedData(const BYTE *pbEncoded, DWORD cbEncoded, |
| 113 | DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara, |
| 114 | CRYPT_DIGESTED_DATA *digestedData, DWORD *pcbDigestedData); |
| 115 | |
Juan Lang | d8ca5bc | 2009-10-20 13:29:03 -0700 | [diff] [blame] | 116 | BOOL WINAPI CRYPT_AsnEncodePubKeyInfoNoNull(DWORD dwCertEncodingType, |
| 117 | LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, |
| 118 | PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded); |
| 119 | |
Juan Lang | c3a1251 | 2006-03-03 10:48:52 -0800 | [diff] [blame] | 120 | /* The following aren't defined in wincrypt.h, as they're "reserved" */ |
| 121 | #define CERT_CERT_PROP_ID 32 |
| 122 | #define CERT_CRL_PROP_ID 33 |
| 123 | #define CERT_CTL_PROP_ID 34 |
| 124 | |
Juan Lang | 02cb0c7 | 2005-08-25 09:51:59 +0000 | [diff] [blame] | 125 | /* Returns a handle to the default crypto provider; loads it if necessary. |
| 126 | * Returns NULL on failure. |
| 127 | */ |
| 128 | HCRYPTPROV CRYPT_GetDefaultProvider(void); |
| 129 | |
Juan Lang | ab81dc1 | 2008-10-31 09:33:58 -0700 | [diff] [blame] | 130 | HINSTANCE hInstance; |
| 131 | |
| 132 | void crypt_oid_init(void); |
Juan Lang | 690f984 | 2006-02-23 13:18:13 -0800 | [diff] [blame] | 133 | void crypt_oid_free(void); |
Juan Lang | 19c3a09 | 2007-07-09 17:07:54 -0700 | [diff] [blame] | 134 | void crypt_sip_free(void); |
Juan Lang | 1dce5ed | 2007-10-18 21:50:46 -0700 | [diff] [blame] | 135 | void root_store_free(void); |
Juan Lang | 1626da2 | 2007-08-15 16:22:43 -0700 | [diff] [blame] | 136 | void default_chain_engine_free(void); |
Juan Lang | f702794 | 2005-12-02 11:28:09 +0100 | [diff] [blame] | 137 | |
Juan Lang | d9a0279 | 2006-05-18 07:31:53 -0700 | [diff] [blame] | 138 | /* Some typedefs that make it easier to abstract which type of context we're |
| 139 | * working with. |
| 140 | */ |
| 141 | typedef const void *(WINAPI *CreateContextFunc)(DWORD dwCertEncodingType, |
| 142 | const BYTE *pbCertEncoded, DWORD cbCertEncoded); |
| 143 | typedef BOOL (WINAPI *AddContextToStoreFunc)(HCERTSTORE hCertStore, |
| 144 | const void *context, DWORD dwAddDisposition, const void **ppStoreContext); |
| 145 | typedef BOOL (WINAPI *AddEncodedContextToStoreFunc)(HCERTSTORE hCertStore, |
| 146 | DWORD dwCertEncodingType, const BYTE *pbEncoded, DWORD cbEncoded, |
| 147 | DWORD dwAddDisposition, const void **ppContext); |
| 148 | typedef const void *(WINAPI *DuplicateContextFunc)(const void *context); |
| 149 | typedef const void *(WINAPI *EnumContextsInStoreFunc)(HCERTSTORE hCertStore, |
| 150 | const void *pPrevContext); |
Juan Lang | f94d49d | 2006-05-25 19:43:30 -0700 | [diff] [blame] | 151 | typedef DWORD (WINAPI *EnumPropertiesFunc)(const void *context, DWORD dwPropId); |
Juan Lang | d9a0279 | 2006-05-18 07:31:53 -0700 | [diff] [blame] | 152 | typedef BOOL (WINAPI *GetContextPropertyFunc)(const void *context, |
| 153 | DWORD dwPropID, void *pvData, DWORD *pcbData); |
| 154 | typedef BOOL (WINAPI *SetContextPropertyFunc)(const void *context, |
| 155 | DWORD dwPropID, DWORD dwFlags, const void *pvData); |
| 156 | typedef BOOL (WINAPI *SerializeElementFunc)(const void *context, DWORD dwFlags, |
| 157 | BYTE *pbElement, DWORD *pcbElement); |
| 158 | typedef BOOL (WINAPI *FreeContextFunc)(const void *context); |
| 159 | typedef BOOL (WINAPI *DeleteContextFunc)(const void *context); |
| 160 | |
| 161 | /* An abstract context (certificate, CRL, or CTL) interface */ |
| 162 | typedef struct _WINE_CONTEXT_INTERFACE |
| 163 | { |
| 164 | CreateContextFunc create; |
| 165 | AddContextToStoreFunc addContextToStore; |
| 166 | AddEncodedContextToStoreFunc addEncodedToStore; |
| 167 | DuplicateContextFunc duplicate; |
| 168 | EnumContextsInStoreFunc enumContextsInStore; |
Juan Lang | f94d49d | 2006-05-25 19:43:30 -0700 | [diff] [blame] | 169 | EnumPropertiesFunc enumProps; |
Juan Lang | d9a0279 | 2006-05-18 07:31:53 -0700 | [diff] [blame] | 170 | GetContextPropertyFunc getProp; |
| 171 | SetContextPropertyFunc setProp; |
| 172 | SerializeElementFunc serialize; |
| 173 | FreeContextFunc free; |
| 174 | DeleteContextFunc deleteFromStore; |
| 175 | } WINE_CONTEXT_INTERFACE, *PWINE_CONTEXT_INTERFACE; |
| 176 | typedef const WINE_CONTEXT_INTERFACE *PCWINE_CONTEXT_INTERFACE; |
| 177 | |
| 178 | extern PCWINE_CONTEXT_INTERFACE pCertInterface; |
| 179 | extern PCWINE_CONTEXT_INTERFACE pCRLInterface; |
| 180 | extern PCWINE_CONTEXT_INTERFACE pCTLInterface; |
| 181 | |
Juan Lang | adaaab9 | 2007-08-16 10:46:04 -0700 | [diff] [blame] | 182 | /* (Internal) certificate store types and functions */ |
| 183 | struct WINE_CRYPTCERTSTORE; |
| 184 | |
| 185 | typedef struct WINE_CRYPTCERTSTORE * (*StoreOpenFunc)(HCRYPTPROV hCryptProv, |
| 186 | DWORD dwFlags, const void *pvPara); |
| 187 | |
| 188 | /* Called to enumerate the next context in a store. */ |
| 189 | typedef void * (*EnumFunc)(struct WINE_CRYPTCERTSTORE *store, void *pPrev); |
| 190 | |
| 191 | /* Called to add a context to a store. If toReplace is not NULL, |
| 192 | * context replaces toReplace in the store, and access checks should not be |
| 193 | * performed. Otherwise context is a new context, and it should only be |
| 194 | * added if the store allows it. If ppStoreContext is not NULL, the added |
| 195 | * context should be returned in *ppStoreContext. |
| 196 | */ |
| 197 | typedef BOOL (*AddFunc)(struct WINE_CRYPTCERTSTORE *store, void *context, |
| 198 | void *toReplace, const void **ppStoreContext); |
| 199 | |
| 200 | typedef BOOL (*DeleteFunc)(struct WINE_CRYPTCERTSTORE *store, void *context); |
| 201 | |
| 202 | typedef struct _CONTEXT_FUNCS |
| 203 | { |
| 204 | AddFunc addContext; |
| 205 | EnumFunc enumContext; |
| 206 | DeleteFunc deleteContext; |
| 207 | } CONTEXT_FUNCS, *PCONTEXT_FUNCS; |
| 208 | |
| 209 | typedef enum _CertStoreType { |
| 210 | StoreTypeMem, |
| 211 | StoreTypeCollection, |
| 212 | StoreTypeProvider, |
| 213 | } CertStoreType; |
| 214 | |
| 215 | struct _CONTEXT_PROPERTY_LIST; |
| 216 | typedef struct _CONTEXT_PROPERTY_LIST *PCONTEXT_PROPERTY_LIST; |
| 217 | |
| 218 | #define WINE_CRYPTCERTSTORE_MAGIC 0x74726563 |
| 219 | |
| 220 | /* A cert store is polymorphic through the use of function pointers. A type |
| 221 | * is still needed to distinguish collection stores from other types. |
| 222 | * On the function pointers: |
| 223 | * - closeStore is called when the store's ref count becomes 0 |
| 224 | * - control is optional, but should be implemented by any store that supports |
| 225 | * persistence |
| 226 | */ |
| 227 | typedef struct WINE_CRYPTCERTSTORE |
| 228 | { |
| 229 | DWORD dwMagic; |
| 230 | LONG ref; |
| 231 | DWORD dwOpenFlags; |
Juan Lang | adaaab9 | 2007-08-16 10:46:04 -0700 | [diff] [blame] | 232 | CertStoreType type; |
| 233 | PFN_CERT_STORE_PROV_CLOSE closeStore; |
| 234 | CONTEXT_FUNCS certs; |
| 235 | CONTEXT_FUNCS crls; |
Juan Lang | caf6a7d | 2008-08-29 07:31:53 -0700 | [diff] [blame] | 236 | CONTEXT_FUNCS ctls; |
Juan Lang | adaaab9 | 2007-08-16 10:46:04 -0700 | [diff] [blame] | 237 | PFN_CERT_STORE_PROV_CONTROL control; /* optional */ |
| 238 | PCONTEXT_PROPERTY_LIST properties; |
| 239 | } WINECRYPT_CERTSTORE, *PWINECRYPT_CERTSTORE; |
| 240 | |
Juan Lang | 1d53424 | 2007-08-17 11:59:28 -0700 | [diff] [blame] | 241 | void CRYPT_InitStore(WINECRYPT_CERTSTORE *store, DWORD dwFlags, |
| 242 | CertStoreType type); |
Juan Lang | 9f85156 | 2007-08-16 10:49:33 -0700 | [diff] [blame] | 243 | void CRYPT_FreeStore(PWINECRYPT_CERTSTORE store); |
Juan Lang | 8894496 | 2007-10-18 11:11:54 -0700 | [diff] [blame] | 244 | BOOL WINAPI I_CertUpdateStore(HCERTSTORE store1, HCERTSTORE store2, DWORD unk0, |
| 245 | DWORD unk1); |
Juan Lang | 9f85156 | 2007-08-16 10:49:33 -0700 | [diff] [blame] | 246 | |
| 247 | PWINECRYPT_CERTSTORE CRYPT_CollectionOpenStore(HCRYPTPROV hCryptProv, |
| 248 | DWORD dwFlags, const void *pvPara); |
Juan Lang | 1d53424 | 2007-08-17 11:59:28 -0700 | [diff] [blame] | 249 | PWINECRYPT_CERTSTORE CRYPT_ProvCreateStore(DWORD dwFlags, |
| 250 | PWINECRYPT_CERTSTORE memStore, const CERT_STORE_PROV_INFO *pProvInfo); |
Juan Lang | 131f1d2 | 2007-08-16 10:50:33 -0700 | [diff] [blame] | 251 | PWINECRYPT_CERTSTORE CRYPT_ProvOpenStore(LPCSTR lpszStoreProvider, |
| 252 | DWORD dwEncodingType, HCRYPTPROV hCryptProv, DWORD dwFlags, |
| 253 | const void *pvPara); |
Juan Lang | 0070d82 | 2007-08-16 10:54:03 -0700 | [diff] [blame] | 254 | PWINECRYPT_CERTSTORE CRYPT_RegOpenStore(HCRYPTPROV hCryptProv, DWORD dwFlags, |
| 255 | const void *pvPara); |
Juan Lang | 71dffce | 2007-08-16 10:54:52 -0700 | [diff] [blame] | 256 | PWINECRYPT_CERTSTORE CRYPT_FileOpenStore(HCRYPTPROV hCryptProv, DWORD dwFlags, |
| 257 | const void *pvPara); |
| 258 | PWINECRYPT_CERTSTORE CRYPT_FileNameOpenStoreA(HCRYPTPROV hCryptProv, |
| 259 | DWORD dwFlags, const void *pvPara); |
| 260 | PWINECRYPT_CERTSTORE CRYPT_FileNameOpenStoreW(HCRYPTPROV hCryptProv, |
| 261 | DWORD dwFlags, const void *pvPara); |
Juan Lang | 9663f94 | 2007-09-10 09:46:56 -0700 | [diff] [blame] | 262 | PWINECRYPT_CERTSTORE CRYPT_RootOpenStore(HCRYPTPROV hCryptProv, DWORD dwFlags); |
Juan Lang | 9f85156 | 2007-08-16 10:49:33 -0700 | [diff] [blame] | 263 | |
Juan Lang | 391f826 | 2007-09-10 09:33:39 -0700 | [diff] [blame] | 264 | /* Allocates and initializes a certificate chain engine, but without creating |
| 265 | * the root store. Instead, it uses root, and assumes the caller has done any |
| 266 | * checking necessary. |
| 267 | */ |
| 268 | HCERTCHAINENGINE CRYPT_CreateChainEngine(HCERTSTORE root, |
| 269 | PCERT_CHAIN_ENGINE_CONFIG pConfig); |
| 270 | |
Juan Lang | c3a1251 | 2006-03-03 10:48:52 -0800 | [diff] [blame] | 271 | /* Helper function for store reading functions and |
| 272 | * CertAddSerializedElementToStore. Returns a context of the appropriate type |
| 273 | * if it can, or NULL otherwise. Doesn't validate any of the properties in |
| 274 | * the serialized context (for example, bad hashes are retained.) |
| 275 | * *pdwContentType is set to the type of the returned context. |
| 276 | */ |
| 277 | const void *CRYPT_ReadSerializedElement(const BYTE *pbElement, |
| 278 | DWORD cbElement, DWORD dwContextTypeFlags, DWORD *pdwContentType); |
| 279 | |
Juan Lang | 6e23b4a | 2006-07-25 16:29:50 -0700 | [diff] [blame] | 280 | /* Reads contexts serialized in the file into the memory store. Returns FALSE |
| 281 | * if the file is not of the expected format. |
| 282 | */ |
Juan Lang | bc81929 | 2007-09-27 11:54:24 -0700 | [diff] [blame] | 283 | BOOL CRYPT_ReadSerializedStoreFromFile(HANDLE file, HCERTSTORE store); |
Juan Lang | 6e23b4a | 2006-07-25 16:29:50 -0700 | [diff] [blame] | 284 | |
Juan Lang | 9928e2e | 2009-10-29 16:48:52 -0700 | [diff] [blame] | 285 | /* Reads contexts serialized in the blob into the memory store. Returns FALSE |
| 286 | * if the file is not of the expected format. |
| 287 | */ |
| 288 | BOOL CRYPT_ReadSerializedStoreFromBlob(const CRYPT_DATA_BLOB *blob, |
| 289 | HCERTSTORE store); |
| 290 | |
Francois Gouget | c4b1195 | 2007-10-23 15:30:30 +0200 | [diff] [blame] | 291 | /* Fixes up the pointers in info, where info is assumed to be a |
Juan Lang | 30bf5d9 | 2006-07-17 23:02:57 -0700 | [diff] [blame] | 292 | * CRYPT_KEY_PROV_INFO, followed by its container name, provider name, and any |
| 293 | * provider parameters, in a contiguous buffer, but where info's pointers are |
| 294 | * assumed to be invalid. Upon return, info's pointers point to the |
| 295 | * appropriate memory locations. |
| 296 | */ |
| 297 | void CRYPT_FixKeyProvInfoPointers(PCRYPT_KEY_PROV_INFO info); |
| 298 | |
Juan Lang | 91b80fc | 2006-03-09 19:06:42 -0800 | [diff] [blame] | 299 | /** |
Juan Lang | e9352b9 | 2008-11-14 09:59:00 -0800 | [diff] [blame] | 300 | * String functions |
| 301 | */ |
| 302 | |
| 303 | DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indent, |
Juan Lang | 1a19444 | 2009-10-23 13:51:02 -0700 | [diff] [blame] | 304 | const CERT_NAME_BLOB *pName, DWORD dwStrType, LPWSTR psz, DWORD csz); |
Juan Lang | e9352b9 | 2008-11-14 09:59:00 -0800 | [diff] [blame] | 305 | |
| 306 | /** |
Juan Lang | e48a0a3 | 2006-05-22 13:59:52 -0700 | [diff] [blame] | 307 | * Context functions |
Juan Lang | 91b80fc | 2006-03-09 19:06:42 -0800 | [diff] [blame] | 308 | */ |
Juan Lang | e48a0a3 | 2006-05-22 13:59:52 -0700 | [diff] [blame] | 309 | |
| 310 | /* Allocates a new data context, a context which owns properties directly. |
| 311 | * contextSize is the size of the public data type associated with context, |
| 312 | * which should be one of CERT_CONTEXT, CRL_CONTEXT, or CTL_CONTEXT. |
| 313 | * Free with Context_Release. |
| 314 | */ |
| 315 | void *Context_CreateDataContext(size_t contextSize); |
| 316 | |
| 317 | /* Creates a new link context with extra bytes. The context refers to linked |
| 318 | * rather than owning its own properties. If addRef is TRUE (which ordinarily |
| 319 | * it should be) linked is addref'd. |
| 320 | * Free with Context_Release. |
| 321 | */ |
Alexandre Julliard | dbd473f | 2006-06-13 14:14:00 +0200 | [diff] [blame] | 322 | void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned int extra, |
Juan Lang | e48a0a3 | 2006-05-22 13:59:52 -0700 | [diff] [blame] | 323 | BOOL addRef); |
| 324 | |
| 325 | /* Returns a pointer to the extra bytes allocated with context, which must be |
| 326 | * a link context. |
| 327 | */ |
| 328 | void *Context_GetExtra(const void *context, size_t contextSize); |
| 329 | |
| 330 | /* Gets the context linked to by context, which must be a link context. */ |
| 331 | void *Context_GetLinkedContext(void *context, size_t contextSize); |
| 332 | |
Juan Lang | dc660a8 | 2006-05-26 09:41:37 -0700 | [diff] [blame] | 333 | /* Copies properties from fromContext to toContext. */ |
| 334 | void Context_CopyProperties(const void *to, const void *from, |
| 335 | size_t contextSize); |
| 336 | |
Juan Lang | e48a0a3 | 2006-05-22 13:59:52 -0700 | [diff] [blame] | 337 | /* Returns context's properties, or the linked context's properties if context |
| 338 | * is a link context. |
| 339 | */ |
Alexandre Julliard | 8926dce | 2008-01-02 12:22:16 +0100 | [diff] [blame] | 340 | PCONTEXT_PROPERTY_LIST Context_GetProperties(const void *context, size_t contextSize); |
Juan Lang | e48a0a3 | 2006-05-22 13:59:52 -0700 | [diff] [blame] | 341 | |
| 342 | void Context_AddRef(void *context, size_t contextSize); |
| 343 | |
| 344 | typedef void (*ContextFreeFunc)(void *context); |
| 345 | |
| 346 | /* Decrements context's ref count. If context is a link context, releases its |
| 347 | * linked context as well. |
| 348 | * If a data context has its ref count reach 0, calls dataContextFree on it. |
Juan Lang | 40855ca | 2009-10-30 15:06:39 -0700 | [diff] [blame] | 349 | * Returns FALSE if the reference count is <= 0 when called. |
Juan Lang | e48a0a3 | 2006-05-22 13:59:52 -0700 | [diff] [blame] | 350 | */ |
Juan Lang | 40855ca | 2009-10-30 15:06:39 -0700 | [diff] [blame] | 351 | BOOL Context_Release(void *context, size_t contextSize, |
Juan Lang | e48a0a3 | 2006-05-22 13:59:52 -0700 | [diff] [blame] | 352 | ContextFreeFunc dataContextFree); |
| 353 | |
| 354 | /** |
| 355 | * Context property list functions |
| 356 | */ |
| 357 | |
Juan Lang | 91b80fc | 2006-03-09 19:06:42 -0800 | [diff] [blame] | 358 | PCONTEXT_PROPERTY_LIST ContextPropertyList_Create(void); |
| 359 | |
| 360 | /* Searches for the property with ID id in the context. Returns TRUE if found, |
| 361 | * and copies the property's length and a pointer to its data to blob. |
| 362 | * Otherwise returns FALSE. |
| 363 | */ |
| 364 | BOOL ContextPropertyList_FindProperty(PCONTEXT_PROPERTY_LIST list, DWORD id, |
| 365 | PCRYPT_DATA_BLOB blob); |
| 366 | |
| 367 | BOOL ContextPropertyList_SetProperty(PCONTEXT_PROPERTY_LIST list, DWORD id, |
| 368 | const BYTE *pbData, size_t cbData); |
| 369 | |
| 370 | void ContextPropertyList_RemoveProperty(PCONTEXT_PROPERTY_LIST list, DWORD id); |
| 371 | |
| 372 | DWORD ContextPropertyList_EnumPropIDs(PCONTEXT_PROPERTY_LIST list, DWORD id); |
| 373 | |
| 374 | void ContextPropertyList_Copy(PCONTEXT_PROPERTY_LIST to, |
| 375 | PCONTEXT_PROPERTY_LIST from); |
| 376 | |
| 377 | void ContextPropertyList_Free(PCONTEXT_PROPERTY_LIST list); |
| 378 | |
Juan Lang | e48a0a3 | 2006-05-22 13:59:52 -0700 | [diff] [blame] | 379 | /** |
| 380 | * Context list functions. A context list is a simple list of link contexts. |
| 381 | */ |
| 382 | struct ContextList; |
| 383 | |
| 384 | struct ContextList *ContextList_Create( |
| 385 | PCWINE_CONTEXT_INTERFACE contextInterface, size_t contextSize); |
| 386 | |
| 387 | void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace); |
| 388 | |
| 389 | void *ContextList_Enum(struct ContextList *list, void *pPrev); |
| 390 | |
Juan Lang | 108f30b | 2009-10-30 19:06:44 -0700 | [diff] [blame] | 391 | /* Removes a context from the list. Returns TRUE if the context was removed, |
| 392 | * or FALSE if not. (The context may have been duplicated, so subsequent |
| 393 | * removes have no effect.) |
| 394 | */ |
| 395 | BOOL ContextList_Remove(struct ContextList *list, void *context); |
Juan Lang | e48a0a3 | 2006-05-22 13:59:52 -0700 | [diff] [blame] | 396 | |
Juan Lang | e48a0a3 | 2006-05-22 13:59:52 -0700 | [diff] [blame] | 397 | void ContextList_Free(struct ContextList *list); |
| 398 | |
Michael Stefaniuc | c48c5c8 | 2008-11-07 01:01:39 +0100 | [diff] [blame] | 399 | /** |
| 400 | * Utilities. |
| 401 | */ |
| 402 | |
| 403 | /* Align up to a DWORD_PTR boundary |
| 404 | */ |
| 405 | #define ALIGN_DWORD_PTR(x) (((x) + sizeof(DWORD_PTR) - 1) & ~(sizeof(DWORD_PTR) - 1)) |
| 406 | #define POINTER_ALIGN_DWORD_PTR(p) ((LPVOID)ALIGN_DWORD_PTR((DWORD_PTR)(p))) |
| 407 | |
Michael Stefaniuc | 0a866d0 | 2010-01-29 01:39:26 +0100 | [diff] [blame] | 408 | /* Check if the OID is a small int |
| 409 | */ |
| 410 | #define IS_INTOID(x) (((ULONG_PTR)(x) >> 16) == 0) |
| 411 | |
Juan Lang | 02cb0c7 | 2005-08-25 09:51:59 +0000 | [diff] [blame] | 412 | #endif |