2 * Copyright 2005 Juan Lang
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.
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.
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
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef __CRYPT32_PRIVATE_H__
20 #define __CRYPT32_PRIVATE_H__
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)
26 #define ASN_SETOF (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x11)
27 #define ASN_NUMERICSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x12)
28 #define ASN_PRINTABLESTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x13)
29 #define ASN_IA5STRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x16)
30 #define ASN_UTCTIME (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x17)
31 #define ASN_GENERALTIME (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x18)
33 /* The following aren't defined in wincrypt.h, as they're "reserved" */
34 #define CERT_CERT_PROP_ID 32
35 #define CERT_CRL_PROP_ID 33
36 #define CERT_CTL_PROP_ID 34
38 /* Returns a handle to the default crypto provider; loads it if necessary.
39 * Returns NULL on failure.
41 HCRYPTPROV CRYPT_GetDefaultProvider(void);
43 void crypt_oid_init(HINSTANCE hinst);
44 void crypt_oid_free(void);
46 /* Some typedefs that make it easier to abstract which type of context we're
49 typedef const void *(WINAPI *CreateContextFunc)(DWORD dwCertEncodingType,
50 const BYTE *pbCertEncoded, DWORD cbCertEncoded);
51 typedef BOOL (WINAPI *AddContextToStoreFunc)(HCERTSTORE hCertStore,
52 const void *context, DWORD dwAddDisposition, const void **ppStoreContext);
53 typedef BOOL (WINAPI *AddEncodedContextToStoreFunc)(HCERTSTORE hCertStore,
54 DWORD dwCertEncodingType, const BYTE *pbEncoded, DWORD cbEncoded,
55 DWORD dwAddDisposition, const void **ppContext);
56 typedef const void *(WINAPI *DuplicateContextFunc)(const void *context);
57 typedef const void *(WINAPI *EnumContextsInStoreFunc)(HCERTSTORE hCertStore,
58 const void *pPrevContext);
59 typedef DWORD (WINAPI *EnumPropertiesFunc)(const void *context, DWORD dwPropId);
60 typedef BOOL (WINAPI *GetContextPropertyFunc)(const void *context,
61 DWORD dwPropID, void *pvData, DWORD *pcbData);
62 typedef BOOL (WINAPI *SetContextPropertyFunc)(const void *context,
63 DWORD dwPropID, DWORD dwFlags, const void *pvData);
64 typedef BOOL (WINAPI *SerializeElementFunc)(const void *context, DWORD dwFlags,
65 BYTE *pbElement, DWORD *pcbElement);
66 typedef BOOL (WINAPI *FreeContextFunc)(const void *context);
67 typedef BOOL (WINAPI *DeleteContextFunc)(const void *context);
69 /* An abstract context (certificate, CRL, or CTL) interface */
70 typedef struct _WINE_CONTEXT_INTERFACE
72 CreateContextFunc create;
73 AddContextToStoreFunc addContextToStore;
74 AddEncodedContextToStoreFunc addEncodedToStore;
75 DuplicateContextFunc duplicate;
76 EnumContextsInStoreFunc enumContextsInStore;
77 EnumPropertiesFunc enumProps;
78 GetContextPropertyFunc getProp;
79 SetContextPropertyFunc setProp;
80 SerializeElementFunc serialize;
82 DeleteContextFunc deleteFromStore;
83 } WINE_CONTEXT_INTERFACE, *PWINE_CONTEXT_INTERFACE;
84 typedef const WINE_CONTEXT_INTERFACE *PCWINE_CONTEXT_INTERFACE;
86 extern PCWINE_CONTEXT_INTERFACE pCertInterface;
87 extern PCWINE_CONTEXT_INTERFACE pCRLInterface;
88 extern PCWINE_CONTEXT_INTERFACE pCTLInterface;
90 /* Helper function for store reading functions and
91 * CertAddSerializedElementToStore. Returns a context of the appropriate type
92 * if it can, or NULL otherwise. Doesn't validate any of the properties in
93 * the serialized context (for example, bad hashes are retained.)
94 * *pdwContentType is set to the type of the returned context.
96 const void *CRYPT_ReadSerializedElement(const BYTE *pbElement,
97 DWORD cbElement, DWORD dwContextTypeFlags, DWORD *pdwContentType);
99 DWORD CertStore_GetAccessState(HCERTSTORE hCertStore);
105 /* Allocates a new data context, a context which owns properties directly.
106 * contextSize is the size of the public data type associated with context,
107 * which should be one of CERT_CONTEXT, CRL_CONTEXT, or CTL_CONTEXT.
108 * Free with Context_Release.
110 void *Context_CreateDataContext(size_t contextSize);
112 /* Creates a new link context with extra bytes. The context refers to linked
113 * rather than owning its own properties. If addRef is TRUE (which ordinarily
114 * it should be) linked is addref'd.
115 * Free with Context_Release.
117 void *Context_CreateLinkContext(size_t contextSize, void *linked, size_t extra,
120 /* Returns a pointer to the extra bytes allocated with context, which must be
123 void *Context_GetExtra(const void *context, size_t contextSize);
125 /* Gets the context linked to by context, which must be a link context. */
126 void *Context_GetLinkedContext(void *context, size_t contextSize);
128 /* Copies properties from fromContext to toContext. */
129 void Context_CopyProperties(const void *to, const void *from,
132 struct _CONTEXT_PROPERTY_LIST;
133 typedef struct _CONTEXT_PROPERTY_LIST *PCONTEXT_PROPERTY_LIST;
135 /* Returns context's properties, or the linked context's properties if context
138 PCONTEXT_PROPERTY_LIST Context_GetProperties(void *context, size_t contextSize);
140 void Context_AddRef(void *context, size_t contextSize);
142 typedef void (*ContextFreeFunc)(void *context);
144 /* Decrements context's ref count. If context is a link context, releases its
145 * linked context as well.
146 * If a data context has its ref count reach 0, calls dataContextFree on it.
148 void Context_Release(void *context, size_t contextSize,
149 ContextFreeFunc dataContextFree);
152 * Context property list functions
155 PCONTEXT_PROPERTY_LIST ContextPropertyList_Create(void);
157 /* Searches for the property with ID id in the context. Returns TRUE if found,
158 * and copies the property's length and a pointer to its data to blob.
159 * Otherwise returns FALSE.
161 BOOL ContextPropertyList_FindProperty(PCONTEXT_PROPERTY_LIST list, DWORD id,
162 PCRYPT_DATA_BLOB blob);
164 BOOL ContextPropertyList_SetProperty(PCONTEXT_PROPERTY_LIST list, DWORD id,
165 const BYTE *pbData, size_t cbData);
167 void ContextPropertyList_RemoveProperty(PCONTEXT_PROPERTY_LIST list, DWORD id);
169 DWORD ContextPropertyList_EnumPropIDs(PCONTEXT_PROPERTY_LIST list, DWORD id);
171 void ContextPropertyList_Copy(PCONTEXT_PROPERTY_LIST to,
172 PCONTEXT_PROPERTY_LIST from);
174 void ContextPropertyList_Free(PCONTEXT_PROPERTY_LIST list);
177 * Context list functions. A context list is a simple list of link contexts.
181 struct ContextList *ContextList_Create(
182 PCWINE_CONTEXT_INTERFACE contextInterface, size_t contextSize);
184 void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace);
186 void *ContextList_Enum(struct ContextList *list, void *pPrev);
188 void ContextList_Delete(struct ContextList *list, void *context);
190 void ContextList_Empty(struct ContextList *list);
192 void ContextList_Free(struct ContextList *list);