2 * Copyright 2002 Mike McCormack for CodeWeavers
3 * Copyright 2004,2005 Juan Lang
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/debug.h"
25 #include "crypt32_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
29 #define WINE_CRYPTCERTSTORE_MAGIC 0x74726563
31 typedef struct WINE_CRYPTCERTSTORE
34 } WINECRYPT_CERTSTORE;
41 * HKLM\\Software\\Microsoft\\SystemCertificates\\CA\\
42 * Certificates\\<compressed guid>
44 * CRLs\\<compressed guid>
46 * CTLs\\<compressed guid>
49 HCERTSTORE WINAPI CertOpenStore( LPCSTR lpszStoreProvider,
50 DWORD dwMsgAndCertEncodingType, HCRYPTPROV hCryptProv,
51 DWORD dwFlags, const void* pvPara )
53 WINECRYPT_CERTSTORE *hcs;
55 FIXME("%s %08lx %08lx %08lx %p stub\n", debugstr_a(lpszStoreProvider),
56 dwMsgAndCertEncodingType, hCryptProv, dwFlags, pvPara);
58 if( lpszStoreProvider == CERT_STORE_PROV_SYSTEM_A )
60 FIXME("pvPara = %s\n", debugstr_a( (LPCSTR) pvPara ) );
62 else if ( lpszStoreProvider == CERT_STORE_PROV_SYSTEM_W )
64 FIXME("pvPara = %s\n", debugstr_w( (LPCWSTR) pvPara ) );
67 hcs = HeapAlloc( GetProcessHeap(), 0, sizeof (WINECRYPT_CERTSTORE) );
71 hcs->dwMagic = WINE_CRYPTCERTSTORE_MAGIC;
73 return (HCERTSTORE) hcs;
76 HCERTSTORE WINAPI CertOpenSystemStoreA(HCRYPTPROV hProv,
77 LPCSTR szSubSystemProtocol)
79 return CertOpenStore( CERT_STORE_PROV_SYSTEM_A, 0, 0,
80 CERT_SYSTEM_STORE_CURRENT_USER | CERT_SYSTEM_STORE_LOCAL_MACHINE |
81 CERT_SYSTEM_STORE_USERS, szSubSystemProtocol );
84 HCERTSTORE WINAPI CertOpenSystemStoreW(HCRYPTPROV hProv,
85 LPCWSTR szSubSystemProtocol)
87 return CertOpenStore( CERT_STORE_PROV_SYSTEM_W, 0, 0,
88 CERT_SYSTEM_STORE_CURRENT_USER | CERT_SYSTEM_STORE_LOCAL_MACHINE |
89 CERT_SYSTEM_STORE_USERS, szSubSystemProtocol );
92 PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
94 FIXME("(%p,%p)\n", hCertStore, pPrev);
98 BOOL WINAPI CertSaveStore(HCERTSTORE hCertStore, DWORD dwMsgAndCertEncodingType,
99 DWORD dwSaveAs, DWORD dwSaveTo, void* pvSaveToPara, DWORD dwFlags)
101 FIXME("(%p,%ld,%ld,%ld,%p,%08lx) stub!\n", hCertStore,
102 dwMsgAndCertEncodingType, dwSaveAs, dwSaveTo, pvSaveToPara, dwFlags);
106 PCCRL_CONTEXT WINAPI CertCreateCRLContext( DWORD dwCertEncodingType,
107 const BYTE* pbCrlEncoded, DWORD cbCrlEncoded)
112 TRACE("%08lx %p %08lx\n", dwCertEncodingType, pbCrlEncoded, cbCrlEncoded);
114 pcrl = HeapAlloc( GetProcessHeap(), 0, sizeof (CRL_CONTEXT) );
118 data = HeapAlloc( GetProcessHeap(), 0, cbCrlEncoded );
121 HeapFree( GetProcessHeap(), 0, pcrl );
125 pcrl->dwCertEncodingType = dwCertEncodingType;
126 pcrl->pbCrlEncoded = data;
127 pcrl->cbCrlEncoded = cbCrlEncoded;
128 pcrl->pCrlInfo = NULL;
129 pcrl->hCertStore = 0;
134 BOOL WINAPI CertAddCRLContextToStore( HCERTSTORE hCertStore,
135 PCCRL_CONTEXT pCrlContext, DWORD dwAddDisposition,
136 PCCRL_CONTEXT* ppStoreContext )
138 FIXME("%p %p %08lx %p\n", hCertStore, pCrlContext,
139 dwAddDisposition, ppStoreContext);
143 BOOL WINAPI CertFreeCRLContext( PCCRL_CONTEXT pCrlContext)
145 FIXME("%p\n", pCrlContext );
150 BOOL WINAPI CertCloseStore( HCERTSTORE hCertStore, DWORD dwFlags )
152 WINECRYPT_CERTSTORE *hcs = (WINECRYPT_CERTSTORE *) hCertStore;
154 FIXME("%p %08lx\n", hCertStore, dwFlags );
158 if ( hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC )
162 HeapFree( GetProcessHeap(), 0, hCertStore );
167 BOOL WINAPI CertFreeCertificateContext( PCCERT_CONTEXT pCertContext )
169 FIXME("%p stub\n", pCertContext);
173 PCCERT_CONTEXT WINAPI CertFindCertificateInStore(HCERTSTORE hCertStore,
174 DWORD dwCertEncodingType, DWORD dwFlags, DWORD dwType,
175 const void *pvPara, PCCERT_CONTEXT pPrevCertContext)
177 FIXME("stub: %p %ld %ld %ld %p %p\n", hCertStore, dwCertEncodingType,
178 dwFlags, dwType, pvPara, pPrevCertContext);
179 SetLastError(CRYPT_E_NOT_FOUND);
183 PCRYPT_ATTRIBUTE WINAPI CertFindAttribute(LPCSTR pszObjId, DWORD cAttr,
184 CRYPT_ATTRIBUTE rgAttr[])
186 PCRYPT_ATTRIBUTE ret = NULL;
189 TRACE("%s %ld %p\n", debugstr_a(pszObjId), cAttr, rgAttr);
195 SetLastError(ERROR_INVALID_PARAMETER);
199 for (i = 0; !ret && i < cAttr; i++)
200 if (rgAttr[i].pszObjId && !strcmp(pszObjId, rgAttr[i].pszObjId))
205 PCERT_EXTENSION WINAPI CertFindExtension(LPCSTR pszObjId, DWORD cExtensions,
206 CERT_EXTENSION rgExtensions[])
208 PCERT_EXTENSION ret = NULL;
211 TRACE("%s %ld %p\n", debugstr_a(pszObjId), cExtensions, rgExtensions);
217 SetLastError(ERROR_INVALID_PARAMETER);
221 for (i = 0; !ret && i < cExtensions; i++)
222 if (rgExtensions[i].pszObjId && !strcmp(pszObjId,
223 rgExtensions[i].pszObjId))
224 ret = &rgExtensions[i];
228 PCERT_RDN_ATTR WINAPI CertFindRDNAttr(LPCSTR pszObjId, PCERT_NAME_INFO pName)
230 PCERT_RDN_ATTR ret = NULL;
233 TRACE("%s %p\n", debugstr_a(pszObjId), pName);
237 SetLastError(ERROR_INVALID_PARAMETER);
241 for (i = 0; !ret && i < pName->cRDN; i++)
242 for (j = 0; !ret && j < pName->rgRDN[i].cRDNAttr; j++)
243 if (pName->rgRDN[i].rgRDNAttr[j].pszObjId && !strcmp(pszObjId,
244 pName->rgRDN[i].rgRDNAttr[j].pszObjId))
245 ret = &pName->rgRDN[i].rgRDNAttr[j];
249 LONG WINAPI CertVerifyTimeValidity(LPFILETIME pTimeToVerify,
250 PCERT_INFO pCertInfo)
259 GetSystemTime(&sysTime);
260 SystemTimeToFileTime(&sysTime, &fileTime);
261 pTimeToVerify = &fileTime;
263 if ((ret = CompareFileTime(pTimeToVerify, &pCertInfo->NotBefore)) >= 0)
265 ret = CompareFileTime(pTimeToVerify, &pCertInfo->NotAfter);
272 BOOL WINAPI CryptHashCertificate(HCRYPTPROV hCryptProv, ALG_ID Algid,
273 DWORD dwFlags, const BYTE *pbEncoded, DWORD cbEncoded, BYTE *pbComputedHash,
274 DWORD *pcbComputedHash)
277 HCRYPTHASH hHash = 0;
279 TRACE("(%ld, %d, %08lx, %p, %ld, %p, %p)\n", hCryptProv, Algid, dwFlags,
280 pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash);
283 hCryptProv = CRYPT_GetDefaultProvider();
288 ret = CryptCreateHash(hCryptProv, Algid, 0, 0, &hHash);
291 ret = CryptHashData(hHash, pbEncoded, cbEncoded, 0);
293 ret = CryptGetHashParam(hHash, HP_HASHVAL, pbComputedHash,
295 CryptDestroyHash(hHash);