ntdll: Load .so builtin modules without using libwine.
[wine/zf.git] / dlls / cryptnet / cryptnet_main.c
blob2e0ab21f89b3fdec9f42841bd63e7f7657935097
1 /*
2 * Copyright (C) 2006 Maarten Lankhorst
3 * Copyright 2007 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #define CERT_REVOCATION_PARA_HAS_EXTRA_FIELDS
24 #include <stdio.h>
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnt.h"
30 #include "winnls.h"
31 #include "wininet.h"
32 #include "objbase.h"
33 #include "wincrypt.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(cryptnet);
39 #define IS_INTOID(x) (((ULONG_PTR)(x) >> 16) == 0)
41 static const WCHAR cryptNet[] = { 'c','r','y','p','t','n','e','t','.',
42 'd','l','l',0 };
44 /***********************************************************************
45 * DllRegisterServer (CRYPTNET.@)
47 HRESULT WINAPI DllRegisterServer(void)
49 TRACE("\n");
50 CryptRegisterDefaultOIDFunction(X509_ASN_ENCODING,
51 CRYPT_OID_VERIFY_REVOCATION_FUNC, 0, cryptNet);
52 CryptRegisterOIDFunction(0, CRYPT_OID_OPEN_STORE_PROV_FUNC, "Ldap",
53 cryptNet, "LdapProvOpenStore");
54 CryptRegisterOIDFunction(0, CRYPT_OID_OPEN_STORE_PROV_FUNC,
55 CERT_STORE_PROV_LDAP_W, cryptNet, "LdapProvOpenStore");
56 return S_OK;
59 /***********************************************************************
60 * DllUnregisterServer (CRYPTNET.@)
62 HRESULT WINAPI DllUnregisterServer(void)
64 TRACE("\n");
65 CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
66 CRYPT_OID_VERIFY_REVOCATION_FUNC, cryptNet);
67 CryptUnregisterOIDFunction(0, CRYPT_OID_OPEN_STORE_PROV_FUNC, "Ldap");
68 CryptUnregisterOIDFunction(0, CRYPT_OID_OPEN_STORE_PROV_FUNC,
69 CERT_STORE_PROV_LDAP_W);
70 return S_OK;
73 static const char *url_oid_to_str(LPCSTR oid)
75 if (IS_INTOID(oid))
77 static char buf[10];
79 switch (LOWORD(oid))
81 #define _x(oid) case LOWORD(oid): return #oid
82 _x(URL_OID_CERTIFICATE_ISSUER);
83 _x(URL_OID_CERTIFICATE_CRL_DIST_POINT);
84 _x(URL_OID_CTL_ISSUER);
85 _x(URL_OID_CTL_NEXT_UPDATE);
86 _x(URL_OID_CRL_ISSUER);
87 _x(URL_OID_CERTIFICATE_FRESHEST_CRL);
88 _x(URL_OID_CRL_FRESHEST_CRL);
89 _x(URL_OID_CROSS_CERT_DIST_POINT);
90 #undef _x
91 default:
92 snprintf(buf, sizeof(buf), "%d", LOWORD(oid));
93 return buf;
96 else
97 return oid;
100 typedef BOOL (WINAPI *UrlDllGetObjectUrlFunc)(LPCSTR, LPVOID, DWORD,
101 PCRYPT_URL_ARRAY, DWORD *, PCRYPT_URL_INFO, DWORD *, LPVOID);
103 static BOOL WINAPI CRYPT_GetUrlFromCertificateIssuer(LPCSTR pszUrlOid,
104 LPVOID pvPara, DWORD dwFlags, PCRYPT_URL_ARRAY pUrlArray, DWORD *pcbUrlArray,
105 PCRYPT_URL_INFO pUrlInfo, DWORD *pcbUrlInfo, LPVOID pvReserved)
107 PCCERT_CONTEXT cert = pvPara;
108 PCERT_EXTENSION ext;
109 BOOL ret = FALSE;
111 /* The only applicable flag is CRYPT_GET_URL_FROM_EXTENSION */
112 if (dwFlags && !(dwFlags & CRYPT_GET_URL_FROM_EXTENSION))
114 SetLastError(CRYPT_E_NOT_FOUND);
115 return FALSE;
117 if ((ext = CertFindExtension(szOID_AUTHORITY_INFO_ACCESS,
118 cert->pCertInfo->cExtension, cert->pCertInfo->rgExtension)))
120 CERT_AUTHORITY_INFO_ACCESS *aia;
121 DWORD size;
123 ret = CryptDecodeObjectEx(X509_ASN_ENCODING, X509_AUTHORITY_INFO_ACCESS,
124 ext->Value.pbData, ext->Value.cbData, CRYPT_DECODE_ALLOC_FLAG, NULL,
125 &aia, &size);
126 if (ret)
128 DWORD i, cUrl, bytesNeeded = sizeof(CRYPT_URL_ARRAY);
130 for (i = 0, cUrl = 0; i < aia->cAccDescr; i++)
131 if (!strcmp(aia->rgAccDescr[i].pszAccessMethod,
132 szOID_PKIX_CA_ISSUERS))
134 if (aia->rgAccDescr[i].AccessLocation.dwAltNameChoice ==
135 CERT_ALT_NAME_URL)
137 if (aia->rgAccDescr[i].AccessLocation.u.pwszURL)
139 cUrl++;
140 bytesNeeded += sizeof(LPWSTR) +
141 (lstrlenW(aia->rgAccDescr[i].AccessLocation.u.
142 pwszURL) + 1) * sizeof(WCHAR);
145 else
146 FIXME("unsupported alt name type %d\n",
147 aia->rgAccDescr[i].AccessLocation.dwAltNameChoice);
149 if (!pcbUrlArray)
151 SetLastError(E_INVALIDARG);
152 ret = FALSE;
154 else if (!pUrlArray)
155 *pcbUrlArray = bytesNeeded;
156 else if (*pcbUrlArray < bytesNeeded)
158 SetLastError(ERROR_MORE_DATA);
159 *pcbUrlArray = bytesNeeded;
160 ret = FALSE;
162 else
164 LPWSTR nextUrl;
166 *pcbUrlArray = bytesNeeded;
167 pUrlArray->cUrl = 0;
168 pUrlArray->rgwszUrl =
169 (LPWSTR *)((BYTE *)pUrlArray + sizeof(CRYPT_URL_ARRAY));
170 nextUrl = (LPWSTR)((BYTE *)pUrlArray + sizeof(CRYPT_URL_ARRAY)
171 + cUrl * sizeof(LPWSTR));
172 for (i = 0; i < aia->cAccDescr; i++)
173 if (!strcmp(aia->rgAccDescr[i].pszAccessMethod,
174 szOID_PKIX_CA_ISSUERS))
176 if (aia->rgAccDescr[i].AccessLocation.dwAltNameChoice
177 == CERT_ALT_NAME_URL)
179 if (aia->rgAccDescr[i].AccessLocation.u.pwszURL)
181 lstrcpyW(nextUrl,
182 aia->rgAccDescr[i].AccessLocation.u.pwszURL);
183 pUrlArray->rgwszUrl[pUrlArray->cUrl++] =
184 nextUrl;
185 nextUrl += (lstrlenW(nextUrl) + 1);
190 if (ret)
192 if (pcbUrlInfo)
194 FIXME("url info: stub\n");
195 if (!pUrlInfo)
196 *pcbUrlInfo = sizeof(CRYPT_URL_INFO);
197 else if (*pcbUrlInfo < sizeof(CRYPT_URL_INFO))
199 *pcbUrlInfo = sizeof(CRYPT_URL_INFO);
200 SetLastError(ERROR_MORE_DATA);
201 ret = FALSE;
203 else
205 *pcbUrlInfo = sizeof(CRYPT_URL_INFO);
206 memset(pUrlInfo, 0, sizeof(CRYPT_URL_INFO));
210 LocalFree(aia);
213 else
214 SetLastError(CRYPT_E_NOT_FOUND);
215 return ret;
218 static BOOL CRYPT_GetUrlFromCRLDistPointsExt(const CRYPT_DATA_BLOB *value,
219 PCRYPT_URL_ARRAY pUrlArray, DWORD *pcbUrlArray, PCRYPT_URL_INFO pUrlInfo,
220 DWORD *pcbUrlInfo)
222 BOOL ret;
223 CRL_DIST_POINTS_INFO *info;
224 DWORD size;
226 ret = CryptDecodeObjectEx(X509_ASN_ENCODING, X509_CRL_DIST_POINTS,
227 value->pbData, value->cbData, CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &size);
228 if (ret)
230 DWORD i, cUrl, bytesNeeded = sizeof(CRYPT_URL_ARRAY);
232 for (i = 0, cUrl = 0; i < info->cDistPoint; i++)
233 if (info->rgDistPoint[i].DistPointName.dwDistPointNameChoice
234 == CRL_DIST_POINT_FULL_NAME)
236 DWORD j;
237 CERT_ALT_NAME_INFO *name =
238 &info->rgDistPoint[i].DistPointName.u.FullName;
240 for (j = 0; j < name->cAltEntry; j++)
241 if (name->rgAltEntry[j].dwAltNameChoice ==
242 CERT_ALT_NAME_URL)
244 if (name->rgAltEntry[j].u.pwszURL)
246 cUrl++;
247 bytesNeeded += sizeof(LPWSTR) +
248 (lstrlenW(name->rgAltEntry[j].u.pwszURL) + 1)
249 * sizeof(WCHAR);
253 if (!pcbUrlArray)
255 SetLastError(E_INVALIDARG);
256 ret = FALSE;
258 else if (!pUrlArray)
259 *pcbUrlArray = bytesNeeded;
260 else if (*pcbUrlArray < bytesNeeded)
262 SetLastError(ERROR_MORE_DATA);
263 *pcbUrlArray = bytesNeeded;
264 ret = FALSE;
266 else
268 LPWSTR nextUrl;
270 *pcbUrlArray = bytesNeeded;
271 pUrlArray->cUrl = 0;
272 pUrlArray->rgwszUrl =
273 (LPWSTR *)((BYTE *)pUrlArray + sizeof(CRYPT_URL_ARRAY));
274 nextUrl = (LPWSTR)((BYTE *)pUrlArray + sizeof(CRYPT_URL_ARRAY)
275 + cUrl * sizeof(LPWSTR));
276 for (i = 0; i < info->cDistPoint; i++)
277 if (info->rgDistPoint[i].DistPointName.dwDistPointNameChoice
278 == CRL_DIST_POINT_FULL_NAME)
280 DWORD j;
281 CERT_ALT_NAME_INFO *name =
282 &info->rgDistPoint[i].DistPointName.u.FullName;
284 for (j = 0; j < name->cAltEntry; j++)
285 if (name->rgAltEntry[j].dwAltNameChoice ==
286 CERT_ALT_NAME_URL)
288 if (name->rgAltEntry[j].u.pwszURL)
290 lstrcpyW(nextUrl,
291 name->rgAltEntry[j].u.pwszURL);
292 pUrlArray->rgwszUrl[pUrlArray->cUrl++] =
293 nextUrl;
294 nextUrl +=
295 (lstrlenW(name->rgAltEntry[j].u.pwszURL) + 1);
300 if (ret)
302 if (pcbUrlInfo)
304 FIXME("url info: stub\n");
305 if (!pUrlInfo)
306 *pcbUrlInfo = sizeof(CRYPT_URL_INFO);
307 else if (*pcbUrlInfo < sizeof(CRYPT_URL_INFO))
309 *pcbUrlInfo = sizeof(CRYPT_URL_INFO);
310 SetLastError(ERROR_MORE_DATA);
311 ret = FALSE;
313 else
315 *pcbUrlInfo = sizeof(CRYPT_URL_INFO);
316 memset(pUrlInfo, 0, sizeof(CRYPT_URL_INFO));
320 LocalFree(info);
322 return ret;
325 static BOOL WINAPI CRYPT_GetUrlFromCertificateCRLDistPoint(LPCSTR pszUrlOid,
326 LPVOID pvPara, DWORD dwFlags, PCRYPT_URL_ARRAY pUrlArray, DWORD *pcbUrlArray,
327 PCRYPT_URL_INFO pUrlInfo, DWORD *pcbUrlInfo, LPVOID pvReserved)
329 PCCERT_CONTEXT cert = pvPara;
330 PCERT_EXTENSION ext;
331 BOOL ret = FALSE;
333 /* The only applicable flag is CRYPT_GET_URL_FROM_EXTENSION */
334 if (dwFlags && !(dwFlags & CRYPT_GET_URL_FROM_EXTENSION))
336 SetLastError(CRYPT_E_NOT_FOUND);
337 return FALSE;
339 if ((ext = CertFindExtension(szOID_CRL_DIST_POINTS,
340 cert->pCertInfo->cExtension, cert->pCertInfo->rgExtension)))
341 ret = CRYPT_GetUrlFromCRLDistPointsExt(&ext->Value, pUrlArray,
342 pcbUrlArray, pUrlInfo, pcbUrlInfo);
343 else
344 SetLastError(CRYPT_E_NOT_FOUND);
345 return ret;
348 /***********************************************************************
349 * CryptGetObjectUrl (CRYPTNET.@)
351 BOOL WINAPI CryptGetObjectUrl(LPCSTR pszUrlOid, LPVOID pvPara, DWORD dwFlags,
352 PCRYPT_URL_ARRAY pUrlArray, DWORD *pcbUrlArray, PCRYPT_URL_INFO pUrlInfo,
353 DWORD *pcbUrlInfo, LPVOID pvReserved)
355 UrlDllGetObjectUrlFunc func = NULL;
356 HCRYPTOIDFUNCADDR hFunc = NULL;
357 BOOL ret = FALSE;
359 TRACE("(%s, %p, %08x, %p, %p, %p, %p, %p)\n", debugstr_a(pszUrlOid),
360 pvPara, dwFlags, pUrlArray, pcbUrlArray, pUrlInfo, pcbUrlInfo, pvReserved);
362 if (IS_INTOID(pszUrlOid))
364 switch (LOWORD(pszUrlOid))
366 case LOWORD(URL_OID_CERTIFICATE_ISSUER):
367 func = CRYPT_GetUrlFromCertificateIssuer;
368 break;
369 case LOWORD(URL_OID_CERTIFICATE_CRL_DIST_POINT):
370 func = CRYPT_GetUrlFromCertificateCRLDistPoint;
371 break;
372 default:
373 FIXME("unimplemented for %s\n", url_oid_to_str(pszUrlOid));
374 SetLastError(ERROR_FILE_NOT_FOUND);
377 else
379 static HCRYPTOIDFUNCSET set = NULL;
381 if (!set)
382 set = CryptInitOIDFunctionSet(URL_OID_GET_OBJECT_URL_FUNC, 0);
383 CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, pszUrlOid, 0,
384 (void **)&func, &hFunc);
386 if (func)
387 ret = func(pszUrlOid, pvPara, dwFlags, pUrlArray, pcbUrlArray,
388 pUrlInfo, pcbUrlInfo, pvReserved);
389 if (hFunc)
390 CryptFreeOIDFunctionAddress(hFunc, 0);
391 return ret;
394 /***********************************************************************
395 * CryptRetrieveObjectByUrlA (CRYPTNET.@)
397 BOOL WINAPI CryptRetrieveObjectByUrlA(LPCSTR pszURL, LPCSTR pszObjectOid,
398 DWORD dwRetrievalFlags, DWORD dwTimeout, LPVOID *ppvObject,
399 HCRYPTASYNC hAsyncRetrieve, PCRYPT_CREDENTIALS pCredentials, LPVOID pvVerify,
400 PCRYPT_RETRIEVE_AUX_INFO pAuxInfo)
402 BOOL ret = FALSE;
403 int len;
405 TRACE("(%s, %s, %08x, %d, %p, %p, %p, %p, %p)\n", debugstr_a(pszURL),
406 debugstr_a(pszObjectOid), dwRetrievalFlags, dwTimeout, ppvObject,
407 hAsyncRetrieve, pCredentials, pvVerify, pAuxInfo);
409 if (!pszURL)
411 SetLastError(ERROR_INVALID_PARAMETER);
412 return FALSE;
414 len = MultiByteToWideChar(CP_ACP, 0, pszURL, -1, NULL, 0);
415 if (len)
417 LPWSTR url = CryptMemAlloc(len * sizeof(WCHAR));
419 if (url)
421 MultiByteToWideChar(CP_ACP, 0, pszURL, -1, url, len);
422 ret = CryptRetrieveObjectByUrlW(url, pszObjectOid,
423 dwRetrievalFlags, dwTimeout, ppvObject, hAsyncRetrieve,
424 pCredentials, pvVerify, pAuxInfo);
425 CryptMemFree(url);
427 else
428 SetLastError(ERROR_OUTOFMEMORY);
430 return ret;
433 static void WINAPI CRYPT_FreeBlob(LPCSTR pszObjectOid,
434 PCRYPT_BLOB_ARRAY pObject, void *pvFreeContext)
436 DWORD i;
438 for (i = 0; i < pObject->cBlob; i++)
439 CryptMemFree(pObject->rgBlob[i].pbData);
440 CryptMemFree(pObject->rgBlob);
443 static BOOL CRYPT_GetObjectFromFile(HANDLE hFile, PCRYPT_BLOB_ARRAY pObject)
445 BOOL ret;
446 LARGE_INTEGER size;
448 if ((ret = GetFileSizeEx(hFile, &size)))
450 if (size.u.HighPart)
452 WARN("file too big\n");
453 SetLastError(ERROR_INVALID_DATA);
454 ret = FALSE;
456 else
458 CRYPT_DATA_BLOB blob;
460 blob.pbData = CryptMemAlloc(size.u.LowPart);
461 if (blob.pbData)
463 ret = ReadFile(hFile, blob.pbData, size.u.LowPart, &blob.cbData,
464 NULL);
465 if (ret)
467 pObject->rgBlob = CryptMemAlloc(sizeof(CRYPT_DATA_BLOB));
468 if (pObject->rgBlob)
470 pObject->cBlob = 1;
471 memcpy(pObject->rgBlob, &blob, sizeof(CRYPT_DATA_BLOB));
473 else
475 SetLastError(ERROR_OUTOFMEMORY);
476 ret = FALSE;
479 if (!ret)
480 CryptMemFree(blob.pbData);
482 else
484 SetLastError(ERROR_OUTOFMEMORY);
485 ret = FALSE;
489 return ret;
492 static BOOL CRYPT_GetObjectFromCache(LPCWSTR pszURL, PCRYPT_BLOB_ARRAY pObject,
493 PCRYPT_RETRIEVE_AUX_INFO pAuxInfo)
495 BOOL ret = FALSE;
496 INTERNET_CACHE_ENTRY_INFOW *pCacheInfo = NULL;
497 DWORD size = 0;
499 TRACE("(%s, %p, %p)\n", debugstr_w(pszURL), pObject, pAuxInfo);
501 RetrieveUrlCacheEntryFileW(pszURL, NULL, &size, 0);
502 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
503 return FALSE;
505 pCacheInfo = CryptMemAlloc(size);
506 if (!pCacheInfo)
508 SetLastError(ERROR_OUTOFMEMORY);
509 return FALSE;
512 if ((ret = RetrieveUrlCacheEntryFileW(pszURL, pCacheInfo, &size, 0)))
514 FILETIME ft;
516 GetSystemTimeAsFileTime(&ft);
517 if (CompareFileTime(&pCacheInfo->ExpireTime, &ft) >= 0)
519 HANDLE hFile = CreateFileW(pCacheInfo->lpszLocalFileName, GENERIC_READ,
520 FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
522 if (hFile != INVALID_HANDLE_VALUE)
524 if ((ret = CRYPT_GetObjectFromFile(hFile, pObject)))
526 if (pAuxInfo && pAuxInfo->cbSize >=
527 offsetof(CRYPT_RETRIEVE_AUX_INFO,
528 pLastSyncTime) + sizeof(PFILETIME) &&
529 pAuxInfo->pLastSyncTime)
530 memcpy(pAuxInfo->pLastSyncTime,
531 &pCacheInfo->LastSyncTime,
532 sizeof(FILETIME));
534 CloseHandle(hFile);
536 else
538 DeleteUrlCacheEntryW(pszURL);
539 ret = FALSE;
542 else
544 DeleteUrlCacheEntryW(pszURL);
545 ret = FALSE;
547 UnlockUrlCacheEntryFileW(pszURL, 0);
549 CryptMemFree(pCacheInfo);
550 TRACE("returning %d\n", ret);
551 return ret;
554 /* Parses the URL, and sets components' lpszHostName and lpszUrlPath members
555 * to NULL-terminated copies of those portions of the URL (to be freed with
556 * CryptMemFree.)
558 static BOOL CRYPT_CrackUrl(LPCWSTR pszURL, URL_COMPONENTSW *components)
560 BOOL ret;
562 TRACE("(%s, %p)\n", debugstr_w(pszURL), components);
564 memset(components, 0, sizeof(*components));
565 components->dwStructSize = sizeof(*components);
566 components->lpszHostName = CryptMemAlloc(INTERNET_MAX_HOST_NAME_LENGTH * sizeof(WCHAR));
567 components->dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
568 if (!components->lpszHostName)
570 SetLastError(ERROR_OUTOFMEMORY);
571 return FALSE;
573 components->lpszUrlPath = CryptMemAlloc(INTERNET_MAX_PATH_LENGTH * sizeof(WCHAR));
574 components->dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
575 if (!components->lpszUrlPath)
577 CryptMemFree(components->lpszHostName);
578 SetLastError(ERROR_OUTOFMEMORY);
579 return FALSE;
582 ret = InternetCrackUrlW(pszURL, 0, ICU_DECODE, components);
583 if (ret)
585 switch (components->nScheme)
587 case INTERNET_SCHEME_FTP:
588 if (!components->nPort)
589 components->nPort = INTERNET_DEFAULT_FTP_PORT;
590 break;
591 case INTERNET_SCHEME_HTTP:
592 if (!components->nPort)
593 components->nPort = INTERNET_DEFAULT_HTTP_PORT;
594 break;
595 default:
596 ; /* do nothing */
599 TRACE("returning %d\n", ret);
600 return ret;
603 struct InetContext
605 HANDLE event;
606 DWORD timeout;
607 DWORD error;
610 static struct InetContext *CRYPT_MakeInetContext(DWORD dwTimeout)
612 struct InetContext *context = CryptMemAlloc(sizeof(struct InetContext));
614 if (context)
616 context->event = CreateEventW(NULL, FALSE, FALSE, NULL);
617 if (!context->event)
619 CryptMemFree(context);
620 context = NULL;
622 else
624 context->timeout = dwTimeout;
625 context->error = ERROR_SUCCESS;
628 return context;
631 static BOOL CRYPT_DownloadObject(DWORD dwRetrievalFlags, HINTERNET hHttp,
632 struct InetContext *context, PCRYPT_BLOB_ARRAY pObject,
633 PCRYPT_RETRIEVE_AUX_INFO pAuxInfo)
635 CRYPT_DATA_BLOB object = { 0, NULL };
636 DWORD bytesAvailable;
637 BOOL ret;
639 do {
640 if ((ret = InternetQueryDataAvailable(hHttp, &bytesAvailable, 0, 0)))
642 if (bytesAvailable)
644 if (object.pbData)
645 object.pbData = CryptMemRealloc(object.pbData,
646 object.cbData + bytesAvailable);
647 else
648 object.pbData = CryptMemAlloc(bytesAvailable);
649 if (object.pbData)
651 INTERNET_BUFFERSA buffer = { sizeof(buffer), 0 };
653 buffer.dwBufferLength = bytesAvailable;
654 buffer.lpvBuffer = object.pbData + object.cbData;
655 if (!(ret = InternetReadFileExA(hHttp, &buffer, IRF_NO_WAIT,
656 (DWORD_PTR)context)))
658 if (GetLastError() == ERROR_IO_PENDING)
660 if (WaitForSingleObject(context->event,
661 context->timeout) == WAIT_TIMEOUT)
662 SetLastError(ERROR_TIMEOUT);
663 else if (context->error)
664 SetLastError(context->error);
665 else
666 ret = TRUE;
669 if (ret)
670 object.cbData += buffer.dwBufferLength;
672 else
674 SetLastError(ERROR_OUTOFMEMORY);
675 ret = FALSE;
679 else if (GetLastError() == ERROR_IO_PENDING)
681 if (WaitForSingleObject(context->event, context->timeout) ==
682 WAIT_TIMEOUT)
683 SetLastError(ERROR_TIMEOUT);
684 else
685 ret = TRUE;
687 } while (ret && bytesAvailable);
688 if (ret)
690 pObject->rgBlob = CryptMemAlloc(sizeof(CRYPT_DATA_BLOB));
691 if (!pObject->rgBlob)
693 CryptMemFree(object.pbData);
694 SetLastError(ERROR_OUTOFMEMORY);
695 ret = FALSE;
697 else
699 pObject->rgBlob[0].cbData = object.cbData;
700 pObject->rgBlob[0].pbData = object.pbData;
701 pObject->cBlob = 1;
704 TRACE("returning %d\n", ret);
705 return ret;
708 /* Finds the object specified by pszURL in the cache. If it's not found,
709 * creates a new cache entry for the object and writes the object to it.
710 * Sets the expiration time of the cache entry to expires.
712 static void CRYPT_CacheURL(LPCWSTR pszURL, const CRYPT_BLOB_ARRAY *pObject,
713 DWORD dwRetrievalFlags, FILETIME expires)
715 WCHAR cacheFileName[MAX_PATH];
716 HANDLE hCacheFile;
717 DWORD size = 0, entryType;
718 FILETIME ft;
720 GetUrlCacheEntryInfoW(pszURL, NULL, &size);
721 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
723 INTERNET_CACHE_ENTRY_INFOW *info = CryptMemAlloc(size);
725 if (!info)
727 ERR("out of memory\n");
728 return;
731 if (GetUrlCacheEntryInfoW(pszURL, info, &size))
733 lstrcpyW(cacheFileName, info->lpszLocalFileName);
734 /* Check if the existing cache entry is up to date. If it isn't,
735 * remove the existing cache entry, and create a new one with the
736 * new value.
738 GetSystemTimeAsFileTime(&ft);
739 if (CompareFileTime(&info->ExpireTime, &ft) < 0)
741 DeleteUrlCacheEntryW(pszURL);
743 else
745 info->ExpireTime = expires;
746 SetUrlCacheEntryInfoW(pszURL, info, CACHE_ENTRY_EXPTIME_FC);
747 CryptMemFree(info);
748 return;
751 CryptMemFree(info);
754 if (!CreateUrlCacheEntryW(pszURL, pObject->rgBlob[0].cbData, NULL, cacheFileName, 0))
755 return;
757 hCacheFile = CreateFileW(cacheFileName, GENERIC_WRITE, 0,
758 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
759 if(hCacheFile == INVALID_HANDLE_VALUE)
760 return;
762 WriteFile(hCacheFile, pObject->rgBlob[0].pbData,
763 pObject->rgBlob[0].cbData, &size, NULL);
764 CloseHandle(hCacheFile);
766 if (!(dwRetrievalFlags & CRYPT_STICKY_CACHE_RETRIEVAL))
767 entryType = NORMAL_CACHE_ENTRY;
768 else
769 entryType = STICKY_CACHE_ENTRY;
770 memset(&ft, 0, sizeof(ft));
771 CommitUrlCacheEntryW(pszURL, cacheFileName, expires, ft, entryType,
772 NULL, 0, NULL, NULL);
775 static void CALLBACK CRYPT_InetStatusCallback(HINTERNET hInt,
776 DWORD_PTR dwContext, DWORD status, void *statusInfo, DWORD statusInfoLen)
778 struct InetContext *context = (struct InetContext *)dwContext;
779 LPINTERNET_ASYNC_RESULT result;
781 switch (status)
783 case INTERNET_STATUS_REQUEST_COMPLETE:
784 result = statusInfo;
785 context->error = result->dwError;
786 SetEvent(context->event);
790 static BOOL CRYPT_Connect(const URL_COMPONENTSW *components,
791 struct InetContext *context, PCRYPT_CREDENTIALS pCredentials,
792 HINTERNET *phInt, HINTERNET *phHost)
794 BOOL ret;
796 TRACE("(%s:%d, %p, %p, %p, %p)\n", debugstr_w(components->lpszHostName),
797 components->nPort, context, pCredentials, phInt, phInt);
799 *phHost = NULL;
800 *phInt = InternetOpenW(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL,
801 context ? INTERNET_FLAG_ASYNC : 0);
802 if (*phInt)
804 DWORD service;
806 if (context)
807 InternetSetStatusCallbackW(*phInt, CRYPT_InetStatusCallback);
808 switch (components->nScheme)
810 case INTERNET_SCHEME_FTP:
811 service = INTERNET_SERVICE_FTP;
812 break;
813 case INTERNET_SCHEME_HTTP:
814 service = INTERNET_SERVICE_HTTP;
815 break;
816 default:
817 service = 0;
819 /* FIXME: use pCredentials for username/password */
820 *phHost = InternetConnectW(*phInt, components->lpszHostName,
821 components->nPort, NULL, NULL, service, 0, (DWORD_PTR)context);
822 if (!*phHost)
824 InternetCloseHandle(*phInt);
825 *phInt = NULL;
826 ret = FALSE;
828 else
829 ret = TRUE;
831 else
832 ret = FALSE;
833 TRACE("returning %d\n", ret);
834 return ret;
837 static BOOL WINAPI FTP_RetrieveEncodedObjectW(LPCWSTR pszURL,
838 LPCSTR pszObjectOid, DWORD dwRetrievalFlags, DWORD dwTimeout,
839 PCRYPT_BLOB_ARRAY pObject, PFN_FREE_ENCODED_OBJECT_FUNC *ppfnFreeObject,
840 void **ppvFreeContext, HCRYPTASYNC hAsyncRetrieve,
841 PCRYPT_CREDENTIALS pCredentials, PCRYPT_RETRIEVE_AUX_INFO pAuxInfo)
843 FIXME("(%s, %s, %08x, %d, %p, %p, %p, %p, %p, %p)\n", debugstr_w(pszURL),
844 debugstr_a(pszObjectOid), dwRetrievalFlags, dwTimeout, pObject,
845 ppfnFreeObject, ppvFreeContext, hAsyncRetrieve, pCredentials, pAuxInfo);
847 pObject->cBlob = 0;
848 pObject->rgBlob = NULL;
849 *ppfnFreeObject = CRYPT_FreeBlob;
850 *ppvFreeContext = NULL;
851 return FALSE;
854 static const WCHAR x509cacert[] = { 'a','p','p','l','i','c','a','t','i','o','n',
855 '/','x','-','x','5','0','9','-','c','a','-','c','e','r','t',0 };
856 static const WCHAR x509emailcert[] = { 'a','p','p','l','i','c','a','t','i','o',
857 'n','/','x','-','x','5','0','9','-','e','m','a','i','l','-','c','e','r','t',
858 0 };
859 static const WCHAR x509servercert[] = { 'a','p','p','l','i','c','a','t','i','o',
860 'n','/','x','-','x','5','0','9','-','s','e','r','v','e','r','-','c','e','r',
861 't',0 };
862 static const WCHAR x509usercert[] = { 'a','p','p','l','i','c','a','t','i','o',
863 'n','/','x','-','x','5','0','9','-','u','s','e','r','-','c','e','r','t',0 };
864 static const WCHAR pkcs7cert[] = { 'a','p','p','l','i','c','a','t','i','o','n',
865 '/','x','-','p','k','c','s','7','-','c','e','r','t','i','f','c','a','t','e',
866 's',0 };
867 static const WCHAR pkixCRL[] = { 'a','p','p','l','i','c','a','t','i','o','n',
868 '/','p','k','i','x','-','c','r','l',0 };
869 static const WCHAR pkcs7CRL[] = { 'a','p','p','l','i','c','a','t','i','o','n',
870 '/','x','-','p','k','c','s','7','-','c','r','l',0 };
871 static const WCHAR pkcs7sig[] = { 'a','p','p','l','i','c','a','t','i','o','n',
872 '/','x','-','p','k','c','s','7','-','s','i','g','n','a','t','u','r','e',0 };
873 static const WCHAR pkcs7mime[] = { 'a','p','p','l','i','c','a','t','i','o','n',
874 '/','x','-','p','k','c','s','7','-','m','i','m','e',0 };
876 static BOOL WINAPI HTTP_RetrieveEncodedObjectW(LPCWSTR pszURL,
877 LPCSTR pszObjectOid, DWORD dwRetrievalFlags, DWORD dwTimeout,
878 PCRYPT_BLOB_ARRAY pObject, PFN_FREE_ENCODED_OBJECT_FUNC *ppfnFreeObject,
879 void **ppvFreeContext, HCRYPTASYNC hAsyncRetrieve,
880 PCRYPT_CREDENTIALS pCredentials, PCRYPT_RETRIEVE_AUX_INFO pAuxInfo)
882 BOOL ret = FALSE;
884 TRACE("(%s, %s, %08x, %d, %p, %p, %p, %p, %p, %p)\n", debugstr_w(pszURL),
885 debugstr_a(pszObjectOid), dwRetrievalFlags, dwTimeout, pObject,
886 ppfnFreeObject, ppvFreeContext, hAsyncRetrieve, pCredentials, pAuxInfo);
888 pObject->cBlob = 0;
889 pObject->rgBlob = NULL;
890 *ppfnFreeObject = CRYPT_FreeBlob;
891 *ppvFreeContext = NULL;
893 if (!(dwRetrievalFlags & CRYPT_WIRE_ONLY_RETRIEVAL))
894 ret = CRYPT_GetObjectFromCache(pszURL, pObject, pAuxInfo);
895 if (!ret && (!(dwRetrievalFlags & CRYPT_CACHE_ONLY_RETRIEVAL) ||
896 (dwRetrievalFlags & CRYPT_WIRE_ONLY_RETRIEVAL)))
898 URL_COMPONENTSW components;
900 if ((ret = CRYPT_CrackUrl(pszURL, &components)))
902 HINTERNET hInt, hHost;
903 struct InetContext *context = NULL;
905 if (dwTimeout)
906 context = CRYPT_MakeInetContext(dwTimeout);
907 ret = CRYPT_Connect(&components, context, pCredentials, &hInt,
908 &hHost);
909 if (ret)
911 static LPCWSTR types[] = { x509cacert, x509emailcert,
912 x509servercert, x509usercert, pkcs7cert, pkixCRL, pkcs7CRL,
913 pkcs7sig, pkcs7mime, NULL };
914 HINTERNET hHttp = HttpOpenRequestW(hHost, NULL,
915 components.lpszUrlPath, NULL, NULL, types,
916 INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_UI,
917 (DWORD_PTR)context);
919 if (hHttp)
921 if (dwTimeout)
923 InternetSetOptionW(hHttp,
924 INTERNET_OPTION_RECEIVE_TIMEOUT, &dwTimeout,
925 sizeof(dwTimeout));
926 InternetSetOptionW(hHttp, INTERNET_OPTION_SEND_TIMEOUT,
927 &dwTimeout, sizeof(dwTimeout));
929 ret = HttpSendRequestExW(hHttp, NULL, NULL, 0,
930 (DWORD_PTR)context);
931 if (!ret && GetLastError() == ERROR_IO_PENDING)
933 if (WaitForSingleObject(context->event,
934 context->timeout) == WAIT_TIMEOUT)
935 SetLastError(ERROR_TIMEOUT);
936 else
937 ret = TRUE;
939 if (ret &&
940 !(ret = HttpEndRequestW(hHttp, NULL, 0, (DWORD_PTR)context)) &&
941 GetLastError() == ERROR_IO_PENDING)
943 if (WaitForSingleObject(context->event,
944 context->timeout) == WAIT_TIMEOUT)
945 SetLastError(ERROR_TIMEOUT);
946 else
947 ret = TRUE;
949 if (ret)
950 ret = CRYPT_DownloadObject(dwRetrievalFlags, hHttp,
951 context, pObject, pAuxInfo);
952 if (ret && !(dwRetrievalFlags & CRYPT_DONT_CACHE_RESULT))
954 SYSTEMTIME st;
955 FILETIME ft;
956 DWORD len = sizeof(st);
958 if (HttpQueryInfoW(hHttp, HTTP_QUERY_EXPIRES | HTTP_QUERY_FLAG_SYSTEMTIME,
959 &st, &len, NULL) && SystemTimeToFileTime(&st, &ft))
960 CRYPT_CacheURL(pszURL, pObject, dwRetrievalFlags, ft);
962 InternetCloseHandle(hHttp);
964 InternetCloseHandle(hHost);
965 InternetCloseHandle(hInt);
967 if (context)
969 CloseHandle(context->event);
970 CryptMemFree(context);
972 CryptMemFree(components.lpszUrlPath);
973 CryptMemFree(components.lpszHostName);
976 TRACE("returning %d\n", ret);
977 return ret;
980 static BOOL WINAPI File_RetrieveEncodedObjectW(LPCWSTR pszURL,
981 LPCSTR pszObjectOid, DWORD dwRetrievalFlags, DWORD dwTimeout,
982 PCRYPT_BLOB_ARRAY pObject, PFN_FREE_ENCODED_OBJECT_FUNC *ppfnFreeObject,
983 void **ppvFreeContext, HCRYPTASYNC hAsyncRetrieve,
984 PCRYPT_CREDENTIALS pCredentials, PCRYPT_RETRIEVE_AUX_INFO pAuxInfo)
986 URL_COMPONENTSW components = { sizeof(components), 0 };
987 BOOL ret;
989 TRACE("(%s, %s, %08x, %d, %p, %p, %p, %p, %p, %p)\n", debugstr_w(pszURL),
990 debugstr_a(pszObjectOid), dwRetrievalFlags, dwTimeout, pObject,
991 ppfnFreeObject, ppvFreeContext, hAsyncRetrieve, pCredentials, pAuxInfo);
993 pObject->cBlob = 0;
994 pObject->rgBlob = NULL;
995 *ppfnFreeObject = CRYPT_FreeBlob;
996 *ppvFreeContext = NULL;
998 components.lpszUrlPath = CryptMemAlloc(INTERNET_MAX_PATH_LENGTH * sizeof(WCHAR));
999 components.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
1000 if (!components.lpszUrlPath)
1002 SetLastError(ERROR_OUTOFMEMORY);
1003 return FALSE;
1006 ret = InternetCrackUrlW(pszURL, 0, ICU_DECODE, &components);
1007 if (ret)
1009 LPWSTR path;
1011 /* 3 == lstrlenW(L"c:") + 1 */
1012 path = CryptMemAlloc((components.dwUrlPathLength + 3) * sizeof(WCHAR));
1013 if (path)
1015 HANDLE hFile;
1017 /* Try to create the file directly - Wine handles / in pathnames */
1018 lstrcpynW(path, components.lpszUrlPath,
1019 components.dwUrlPathLength + 1);
1020 hFile = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ,
1021 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1022 if (hFile == INVALID_HANDLE_VALUE)
1024 /* Try again on the current drive */
1025 GetCurrentDirectoryW(components.dwUrlPathLength, path);
1026 if (path[1] == ':')
1028 lstrcpynW(path + 2, components.lpszUrlPath,
1029 components.dwUrlPathLength + 1);
1030 hFile = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ,
1031 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1033 if (hFile == INVALID_HANDLE_VALUE)
1035 /* Try again on the Windows drive */
1036 GetWindowsDirectoryW(path, components.dwUrlPathLength);
1037 if (path[1] == ':')
1039 lstrcpynW(path + 2, components.lpszUrlPath,
1040 components.dwUrlPathLength + 1);
1041 hFile = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ,
1042 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1046 if (hFile != INVALID_HANDLE_VALUE)
1048 if ((ret = CRYPT_GetObjectFromFile(hFile, pObject)))
1050 if (pAuxInfo && pAuxInfo->cbSize >=
1051 offsetof(CRYPT_RETRIEVE_AUX_INFO,
1052 pLastSyncTime) + sizeof(PFILETIME) &&
1053 pAuxInfo->pLastSyncTime)
1054 GetFileTime(hFile, NULL, NULL,
1055 pAuxInfo->pLastSyncTime);
1057 CloseHandle(hFile);
1059 else
1060 ret = FALSE;
1061 CryptMemFree(path);
1063 else
1065 SetLastError(ERROR_OUTOFMEMORY);
1066 ret = FALSE;
1069 CryptMemFree(components.lpszUrlPath);
1070 return ret;
1073 typedef BOOL (WINAPI *SchemeDllRetrieveEncodedObjectW)(LPCWSTR pwszUrl,
1074 LPCSTR pszObjectOid, DWORD dwRetrievalFlags, DWORD dwTimeout,
1075 PCRYPT_BLOB_ARRAY pObject, PFN_FREE_ENCODED_OBJECT_FUNC *ppfnFreeObject,
1076 void **ppvFreeContext, HCRYPTASYNC hAsyncRetrieve,
1077 PCRYPT_CREDENTIALS pCredentials, PCRYPT_RETRIEVE_AUX_INFO pAuxInfo);
1079 static BOOL CRYPT_GetRetrieveFunction(LPCWSTR pszURL,
1080 SchemeDllRetrieveEncodedObjectW *pFunc, HCRYPTOIDFUNCADDR *phFunc)
1082 URL_COMPONENTSW components = { sizeof(components), 0 };
1083 BOOL ret;
1085 TRACE("(%s, %p, %p)\n", debugstr_w(pszURL), pFunc, phFunc);
1087 *pFunc = NULL;
1088 *phFunc = 0;
1089 components.dwSchemeLength = 1;
1090 ret = InternetCrackUrlW(pszURL, 0, 0, &components);
1091 if (ret)
1093 /* Microsoft always uses CryptInitOIDFunctionSet/
1094 * CryptGetOIDFunctionAddress, but there doesn't seem to be a pressing
1095 * reason to do so for builtin schemes.
1097 switch (components.nScheme)
1099 case INTERNET_SCHEME_FTP:
1100 *pFunc = FTP_RetrieveEncodedObjectW;
1101 break;
1102 case INTERNET_SCHEME_HTTP:
1103 *pFunc = HTTP_RetrieveEncodedObjectW;
1104 break;
1105 case INTERNET_SCHEME_FILE:
1106 *pFunc = File_RetrieveEncodedObjectW;
1107 break;
1108 default:
1110 int len = WideCharToMultiByte(CP_ACP, 0, components.lpszScheme,
1111 components.dwSchemeLength, NULL, 0, NULL, NULL);
1113 if (len)
1115 LPSTR scheme = CryptMemAlloc(len);
1117 if (scheme)
1119 static HCRYPTOIDFUNCSET set = NULL;
1121 if (!set)
1122 set = CryptInitOIDFunctionSet(
1123 SCHEME_OID_RETRIEVE_ENCODED_OBJECTW_FUNC, 0);
1124 WideCharToMultiByte(CP_ACP, 0, components.lpszScheme,
1125 components.dwSchemeLength, scheme, len, NULL, NULL);
1126 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING,
1127 scheme, 0, (void **)pFunc, phFunc);
1128 CryptMemFree(scheme);
1130 else
1132 SetLastError(ERROR_OUTOFMEMORY);
1133 ret = FALSE;
1136 else
1137 ret = FALSE;
1141 TRACE("returning %d\n", ret);
1142 return ret;
1145 static BOOL WINAPI CRYPT_CreateBlob(LPCSTR pszObjectOid,
1146 DWORD dwRetrievalFlags, const CRYPT_BLOB_ARRAY *pObject, void **ppvContext)
1148 DWORD size, i;
1149 CRYPT_BLOB_ARRAY *context;
1150 BOOL ret = FALSE;
1152 size = sizeof(CRYPT_BLOB_ARRAY) + pObject->cBlob * sizeof(CRYPT_DATA_BLOB);
1153 for (i = 0; i < pObject->cBlob; i++)
1154 size += pObject->rgBlob[i].cbData;
1155 context = CryptMemAlloc(size);
1156 if (context)
1158 LPBYTE nextData;
1160 context->cBlob = 0;
1161 context->rgBlob =
1162 (CRYPT_DATA_BLOB *)((LPBYTE)context + sizeof(CRYPT_BLOB_ARRAY));
1163 nextData =
1164 (LPBYTE)context->rgBlob + pObject->cBlob * sizeof(CRYPT_DATA_BLOB);
1165 for (i = 0; i < pObject->cBlob; i++)
1167 memcpy(nextData, pObject->rgBlob[i].pbData,
1168 pObject->rgBlob[i].cbData);
1169 context->rgBlob[i].pbData = nextData;
1170 context->rgBlob[i].cbData = pObject->rgBlob[i].cbData;
1171 nextData += pObject->rgBlob[i].cbData;
1172 context->cBlob++;
1174 *ppvContext = context;
1175 ret = TRUE;
1177 return ret;
1180 typedef BOOL (WINAPI *AddContextToStore)(HCERTSTORE hCertStore,
1181 const void *pContext, DWORD dwAddDisposition, const void **ppStoreContext);
1183 static BOOL decode_base64_blob( const CRYPT_DATA_BLOB *in, CRYPT_DATA_BLOB *out )
1185 BOOL ret;
1186 DWORD len = in->cbData;
1188 while (len && !in->pbData[len - 1]) len--;
1189 if (!CryptStringToBinaryA( (char *)in->pbData, len, CRYPT_STRING_BASE64_ANY,
1190 NULL, &out->cbData, NULL, NULL )) return FALSE;
1192 if (!(out->pbData = CryptMemAlloc( out->cbData ))) return FALSE;
1193 ret = CryptStringToBinaryA( (char *)in->pbData, len, CRYPT_STRING_BASE64_ANY,
1194 out->pbData, &out->cbData, NULL, NULL );
1195 if (!ret) CryptMemFree( out->pbData );
1196 return ret;
1199 static BOOL CRYPT_CreateContext(const CRYPT_BLOB_ARRAY *pObject,
1200 DWORD dwExpectedContentTypeFlags, AddContextToStore addFunc, void **ppvContext)
1202 BOOL ret = TRUE;
1203 CRYPT_DATA_BLOB blob;
1205 if (!pObject->cBlob)
1207 SetLastError(ERROR_INVALID_DATA);
1208 *ppvContext = NULL;
1209 ret = FALSE;
1211 else if (pObject->cBlob == 1)
1213 if (decode_base64_blob(&pObject->rgBlob[0], &blob))
1215 ret = CryptQueryObject(CERT_QUERY_OBJECT_BLOB, &blob,
1216 dwExpectedContentTypeFlags, CERT_QUERY_FORMAT_FLAG_BINARY, 0,
1217 NULL, NULL, NULL, NULL, NULL, (const void **)ppvContext);
1218 CryptMemFree(blob.pbData);
1220 else
1222 ret = CryptQueryObject(CERT_QUERY_OBJECT_BLOB, &pObject->rgBlob[0],
1223 dwExpectedContentTypeFlags, CERT_QUERY_FORMAT_FLAG_BINARY, 0,
1224 NULL, NULL, NULL, NULL, NULL, (const void **)ppvContext);
1226 if (!ret)
1228 SetLastError(CRYPT_E_NO_MATCH);
1229 ret = FALSE;
1232 else
1234 HCERTSTORE store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
1235 CERT_STORE_CREATE_NEW_FLAG, NULL);
1237 if (store)
1239 DWORD i;
1240 const void *context;
1242 for (i = 0; i < pObject->cBlob; i++)
1244 if (decode_base64_blob(&pObject->rgBlob[i], &blob))
1246 ret = CryptQueryObject(CERT_QUERY_OBJECT_BLOB, &blob,
1247 dwExpectedContentTypeFlags, CERT_QUERY_FORMAT_FLAG_BINARY,
1248 0, NULL, NULL, NULL, NULL, NULL, &context);
1249 CryptMemFree(blob.pbData);
1251 else
1253 ret = CryptQueryObject(CERT_QUERY_OBJECT_BLOB,
1254 &pObject->rgBlob[i], dwExpectedContentTypeFlags,
1255 CERT_QUERY_FORMAT_FLAG_BINARY, 0, NULL, NULL, NULL, NULL,
1256 NULL, &context);
1258 if (ret)
1260 if (!addFunc(store, context, CERT_STORE_ADD_ALWAYS, NULL))
1261 ret = FALSE;
1263 else
1265 SetLastError(CRYPT_E_NO_MATCH);
1266 ret = FALSE;
1270 else
1271 ret = FALSE;
1272 *ppvContext = store;
1274 return ret;
1277 static BOOL WINAPI CRYPT_CreateCert(LPCSTR pszObjectOid,
1278 DWORD dwRetrievalFlags, const CRYPT_BLOB_ARRAY *pObject, void **ppvContext)
1280 return CRYPT_CreateContext(pObject, CERT_QUERY_CONTENT_FLAG_CERT,
1281 (AddContextToStore)CertAddCertificateContextToStore, ppvContext);
1284 static BOOL WINAPI CRYPT_CreateCRL(LPCSTR pszObjectOid,
1285 DWORD dwRetrievalFlags, const CRYPT_BLOB_ARRAY *pObject, void **ppvContext)
1287 return CRYPT_CreateContext(pObject, CERT_QUERY_CONTENT_FLAG_CRL,
1288 (AddContextToStore)CertAddCRLContextToStore, ppvContext);
1291 static BOOL WINAPI CRYPT_CreateCTL(LPCSTR pszObjectOid,
1292 DWORD dwRetrievalFlags, const CRYPT_BLOB_ARRAY *pObject, void **ppvContext)
1294 return CRYPT_CreateContext(pObject, CERT_QUERY_CONTENT_FLAG_CTL,
1295 (AddContextToStore)CertAddCTLContextToStore, ppvContext);
1298 static BOOL WINAPI CRYPT_CreatePKCS7(LPCSTR pszObjectOid,
1299 DWORD dwRetrievalFlags, const CRYPT_BLOB_ARRAY *pObject, void **ppvContext)
1301 BOOL ret;
1303 if (!pObject->cBlob)
1305 SetLastError(ERROR_INVALID_DATA);
1306 *ppvContext = NULL;
1307 ret = FALSE;
1309 else if (pObject->cBlob == 1)
1310 ret = CryptQueryObject(CERT_QUERY_OBJECT_BLOB, &pObject->rgBlob[0],
1311 CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED |
1312 CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED, CERT_QUERY_FORMAT_FLAG_BINARY,
1313 0, NULL, NULL, NULL, ppvContext, NULL, NULL);
1314 else
1316 FIXME("multiple messages unimplemented\n");
1317 ret = FALSE;
1319 return ret;
1322 static BOOL WINAPI CRYPT_CreateAny(LPCSTR pszObjectOid,
1323 DWORD dwRetrievalFlags, const CRYPT_BLOB_ARRAY *pObject, void **ppvContext)
1325 BOOL ret;
1327 if (!pObject->cBlob)
1329 SetLastError(ERROR_INVALID_DATA);
1330 *ppvContext = NULL;
1331 ret = FALSE;
1333 else
1335 HCERTSTORE store = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
1336 CERT_STORE_CREATE_NEW_FLAG, NULL);
1338 if (store)
1340 HCERTSTORE memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
1341 CERT_STORE_CREATE_NEW_FLAG, NULL);
1343 if (memStore)
1345 CertAddStoreToCollection(store, memStore,
1346 CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
1347 CertCloseStore(memStore, 0);
1349 else
1351 CertCloseStore(store, 0);
1352 store = NULL;
1355 if (store)
1357 DWORD i;
1359 ret = TRUE;
1360 for (i = 0; i < pObject->cBlob; i++)
1362 DWORD contentType, expectedContentTypes =
1363 CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED |
1364 CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED |
1365 CERT_QUERY_CONTENT_FLAG_CERT |
1366 CERT_QUERY_CONTENT_FLAG_CRL |
1367 CERT_QUERY_CONTENT_FLAG_CTL;
1368 HCERTSTORE contextStore;
1369 const void *context;
1371 if (CryptQueryObject(CERT_QUERY_OBJECT_BLOB,
1372 &pObject->rgBlob[i], expectedContentTypes,
1373 CERT_QUERY_FORMAT_FLAG_BINARY, 0, NULL, &contentType, NULL,
1374 &contextStore, NULL, &context))
1376 switch (contentType)
1378 case CERT_QUERY_CONTENT_CERT:
1379 if (!CertAddCertificateContextToStore(store,
1380 context, CERT_STORE_ADD_ALWAYS, NULL))
1381 ret = FALSE;
1382 CertFreeCertificateContext(context);
1383 break;
1384 case CERT_QUERY_CONTENT_CRL:
1385 if (!CertAddCRLContextToStore(store,
1386 context, CERT_STORE_ADD_ALWAYS, NULL))
1387 ret = FALSE;
1388 CertFreeCRLContext(context);
1389 break;
1390 case CERT_QUERY_CONTENT_CTL:
1391 if (!CertAddCTLContextToStore(store,
1392 context, CERT_STORE_ADD_ALWAYS, NULL))
1393 ret = FALSE;
1394 CertFreeCTLContext(context);
1395 break;
1396 default:
1397 CertAddStoreToCollection(store, contextStore, 0, 0);
1399 CertCloseStore(contextStore, 0);
1401 else
1402 ret = FALSE;
1405 else
1406 ret = FALSE;
1407 *ppvContext = store;
1409 return ret;
1412 typedef BOOL (WINAPI *ContextDllCreateObjectContext)(LPCSTR pszObjectOid,
1413 DWORD dwRetrievalFlags, const CRYPT_BLOB_ARRAY *pObject, void **ppvContext);
1415 static BOOL CRYPT_GetCreateFunction(LPCSTR pszObjectOid,
1416 ContextDllCreateObjectContext *pFunc, HCRYPTOIDFUNCADDR *phFunc)
1418 BOOL ret = TRUE;
1420 TRACE("(%s, %p, %p)\n", debugstr_a(pszObjectOid), pFunc, phFunc);
1422 *pFunc = NULL;
1423 *phFunc = 0;
1424 if (IS_INTOID(pszObjectOid))
1426 switch (LOWORD(pszObjectOid))
1428 case 0:
1429 *pFunc = CRYPT_CreateBlob;
1430 break;
1431 case LOWORD(CONTEXT_OID_CERTIFICATE):
1432 *pFunc = CRYPT_CreateCert;
1433 break;
1434 case LOWORD(CONTEXT_OID_CRL):
1435 *pFunc = CRYPT_CreateCRL;
1436 break;
1437 case LOWORD(CONTEXT_OID_CTL):
1438 *pFunc = CRYPT_CreateCTL;
1439 break;
1440 case LOWORD(CONTEXT_OID_PKCS7):
1441 *pFunc = CRYPT_CreatePKCS7;
1442 break;
1443 case LOWORD(CONTEXT_OID_CAPI2_ANY):
1444 *pFunc = CRYPT_CreateAny;
1445 break;
1448 if (!*pFunc)
1450 static HCRYPTOIDFUNCSET set = NULL;
1452 if (!set)
1453 set = CryptInitOIDFunctionSet(
1454 CONTEXT_OID_CREATE_OBJECT_CONTEXT_FUNC, 0);
1455 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, pszObjectOid,
1456 0, (void **)pFunc, phFunc);
1458 TRACE("returning %d\n", ret);
1459 return ret;
1462 static BOOL CRYPT_GetExpiration(const void *object, const char *pszObjectOid, FILETIME *expiration)
1464 if (!IS_INTOID(pszObjectOid))
1465 return FALSE;
1467 switch (LOWORD(pszObjectOid)) {
1468 case LOWORD(CONTEXT_OID_CERTIFICATE):
1469 *expiration = ((const CERT_CONTEXT*)object)->pCertInfo->NotAfter;
1470 return TRUE;
1471 case LOWORD(CONTEXT_OID_CRL):
1472 *expiration = ((const CRL_CONTEXT*)object)->pCrlInfo->NextUpdate;
1473 return TRUE;
1474 case LOWORD(CONTEXT_OID_CTL):
1475 *expiration = ((const CTL_CONTEXT*)object)->pCtlInfo->NextUpdate;
1476 return TRUE;
1479 return FALSE;
1482 /***********************************************************************
1483 * CryptRetrieveObjectByUrlW (CRYPTNET.@)
1485 BOOL WINAPI CryptRetrieveObjectByUrlW(LPCWSTR pszURL, LPCSTR pszObjectOid,
1486 DWORD dwRetrievalFlags, DWORD dwTimeout, LPVOID *ppvObject,
1487 HCRYPTASYNC hAsyncRetrieve, PCRYPT_CREDENTIALS pCredentials, LPVOID pvVerify,
1488 PCRYPT_RETRIEVE_AUX_INFO pAuxInfo)
1490 BOOL ret;
1491 SchemeDllRetrieveEncodedObjectW retrieve;
1492 ContextDllCreateObjectContext create;
1493 HCRYPTOIDFUNCADDR hRetrieve = 0, hCreate = 0;
1495 TRACE("(%s, %s, %08x, %d, %p, %p, %p, %p, %p)\n", debugstr_w(pszURL),
1496 debugstr_a(pszObjectOid), dwRetrievalFlags, dwTimeout, ppvObject,
1497 hAsyncRetrieve, pCredentials, pvVerify, pAuxInfo);
1499 if (!pszURL)
1501 SetLastError(ERROR_INVALID_PARAMETER);
1502 return FALSE;
1504 ret = CRYPT_GetRetrieveFunction(pszURL, &retrieve, &hRetrieve);
1505 if (ret)
1506 ret = CRYPT_GetCreateFunction(pszObjectOid, &create, &hCreate);
1507 if (ret)
1509 CRYPT_BLOB_ARRAY object = { 0, NULL };
1510 PFN_FREE_ENCODED_OBJECT_FUNC freeObject;
1511 void *freeContext;
1512 FILETIME expires;
1514 ret = retrieve(pszURL, pszObjectOid, dwRetrievalFlags, dwTimeout,
1515 &object, &freeObject, &freeContext, hAsyncRetrieve, pCredentials,
1516 pAuxInfo);
1517 if (ret)
1519 ret = create(pszObjectOid, dwRetrievalFlags, &object, ppvObject);
1520 if (ret && !(dwRetrievalFlags & CRYPT_DONT_CACHE_RESULT) &&
1521 CRYPT_GetExpiration(*ppvObject, pszObjectOid, &expires))
1523 CRYPT_CacheURL(pszURL, &object, dwRetrievalFlags, expires);
1525 freeObject(pszObjectOid, &object, freeContext);
1528 if (hCreate)
1529 CryptFreeOIDFunctionAddress(hCreate, 0);
1530 if (hRetrieve)
1531 CryptFreeOIDFunctionAddress(hRetrieve, 0);
1532 TRACE("returning %d\n", ret);
1533 return ret;
1536 static DWORD verify_cert_revocation_with_crl_online(PCCERT_CONTEXT cert,
1537 PCCRL_CONTEXT crl, DWORD index, FILETIME *pTime,
1538 PCERT_REVOCATION_STATUS pRevStatus)
1540 DWORD error;
1541 PCRL_ENTRY entry = NULL;
1543 CertFindCertificateInCRL(cert, crl, 0, NULL, &entry);
1544 if (entry)
1546 error = CRYPT_E_REVOKED;
1547 pRevStatus->dwIndex = index;
1549 else
1551 /* Since the CRL was retrieved for the cert being checked, then it's
1552 * guaranteed to be fresh, and the cert is not revoked.
1554 error = ERROR_SUCCESS;
1556 return error;
1559 static DWORD verify_cert_revocation_from_dist_points_ext(
1560 const CRYPT_DATA_BLOB *value, PCCERT_CONTEXT cert, DWORD index,
1561 FILETIME *pTime, DWORD dwFlags, const CERT_REVOCATION_PARA *pRevPara,
1562 PCERT_REVOCATION_STATUS pRevStatus)
1564 DWORD error = ERROR_SUCCESS, cbUrlArray;
1566 if (CRYPT_GetUrlFromCRLDistPointsExt(value, NULL, &cbUrlArray, NULL, NULL))
1568 CRYPT_URL_ARRAY *urlArray = CryptMemAlloc(cbUrlArray);
1570 if (urlArray)
1572 DWORD j, retrievalFlags = 0, startTime, endTime, timeout;
1573 BOOL ret;
1575 ret = CRYPT_GetUrlFromCRLDistPointsExt(value, urlArray,
1576 &cbUrlArray, NULL, NULL);
1577 if (dwFlags & CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION)
1578 retrievalFlags |= CRYPT_CACHE_ONLY_RETRIEVAL;
1579 if (dwFlags & CERT_VERIFY_REV_ACCUMULATIVE_TIMEOUT_FLAG &&
1580 pRevPara && pRevPara->cbSize >= offsetof(CERT_REVOCATION_PARA,
1581 dwUrlRetrievalTimeout) + sizeof(DWORD))
1583 startTime = GetTickCount();
1584 endTime = startTime + pRevPara->dwUrlRetrievalTimeout;
1585 timeout = pRevPara->dwUrlRetrievalTimeout;
1587 else
1588 endTime = timeout = 0;
1589 if (!ret)
1590 error = GetLastError();
1591 /* continue looping if one was offline; break if revoked or timed out */
1592 for (j = 0; (!error || error == CRYPT_E_REVOCATION_OFFLINE) && j < urlArray->cUrl; j++)
1594 PCCRL_CONTEXT crl;
1596 ret = CryptRetrieveObjectByUrlW(urlArray->rgwszUrl[j],
1597 CONTEXT_OID_CRL, retrievalFlags, timeout, (void **)&crl,
1598 NULL, NULL, NULL, NULL);
1599 if (ret)
1601 error = verify_cert_revocation_with_crl_online(cert, crl,
1602 index, pTime, pRevStatus);
1603 if (!error && timeout)
1605 DWORD time = GetTickCount();
1607 if ((int)(endTime - time) <= 0)
1609 error = ERROR_TIMEOUT;
1610 pRevStatus->dwIndex = index;
1612 else
1613 timeout = endTime - time;
1615 CertFreeCRLContext(crl);
1617 else
1618 error = CRYPT_E_REVOCATION_OFFLINE;
1620 CryptMemFree(urlArray);
1622 else
1624 error = ERROR_OUTOFMEMORY;
1625 pRevStatus->dwIndex = index;
1628 else
1630 error = GetLastError();
1631 pRevStatus->dwIndex = index;
1633 return error;
1636 static DWORD verify_cert_revocation_from_aia_ext(
1637 const CRYPT_DATA_BLOB *value, PCCERT_CONTEXT cert, DWORD index,
1638 FILETIME *pTime, DWORD dwFlags, PCERT_REVOCATION_PARA pRevPara,
1639 PCERT_REVOCATION_STATUS pRevStatus)
1641 BOOL ret;
1642 DWORD error, size;
1643 CERT_AUTHORITY_INFO_ACCESS *aia;
1645 ret = CryptDecodeObjectEx(X509_ASN_ENCODING, X509_AUTHORITY_INFO_ACCESS,
1646 value->pbData, value->cbData, CRYPT_DECODE_ALLOC_FLAG, NULL, &aia, &size);
1647 if (ret)
1649 DWORD i;
1651 for (i = 0; i < aia->cAccDescr; i++)
1652 if (!strcmp(aia->rgAccDescr[i].pszAccessMethod,
1653 szOID_PKIX_OCSP))
1655 if (aia->rgAccDescr[i].AccessLocation.dwAltNameChoice ==
1656 CERT_ALT_NAME_URL)
1657 FIXME("OCSP URL = %s\n",
1658 debugstr_w(aia->rgAccDescr[i].AccessLocation.u.pwszURL));
1659 else
1660 FIXME("unsupported AccessLocation type %d\n",
1661 aia->rgAccDescr[i].AccessLocation.dwAltNameChoice);
1663 LocalFree(aia);
1664 /* FIXME: lie and pretend OCSP validated the cert */
1665 error = ERROR_SUCCESS;
1667 else
1668 error = GetLastError();
1669 return error;
1672 static DWORD verify_cert_revocation_with_crl_offline(PCCERT_CONTEXT cert,
1673 PCCRL_CONTEXT crl, DWORD index, FILETIME *pTime,
1674 PCERT_REVOCATION_STATUS pRevStatus)
1676 DWORD error;
1677 LONG valid;
1679 valid = CompareFileTime(pTime, &crl->pCrlInfo->ThisUpdate);
1680 if (valid <= 0)
1682 /* If this CRL is not older than the time being verified, there's no
1683 * way to know whether the certificate was revoked.
1685 TRACE("CRL not old enough\n");
1686 error = CRYPT_E_REVOCATION_OFFLINE;
1688 else
1690 PCRL_ENTRY entry = NULL;
1692 CertFindCertificateInCRL(cert, crl, 0, NULL, &entry);
1693 if (entry)
1695 error = CRYPT_E_REVOKED;
1696 pRevStatus->dwIndex = index;
1698 else
1700 /* Since the CRL was not retrieved for the cert being checked,
1701 * there's no guarantee it's fresh, so the cert *might* be okay,
1702 * but it's safer not to guess.
1704 TRACE("certificate not found\n");
1705 error = CRYPT_E_REVOCATION_OFFLINE;
1708 return error;
1711 static DWORD verify_cert_revocation(PCCERT_CONTEXT cert, DWORD index,
1712 FILETIME *pTime, DWORD dwFlags, PCERT_REVOCATION_PARA pRevPara,
1713 PCERT_REVOCATION_STATUS pRevStatus)
1715 DWORD error = ERROR_SUCCESS;
1716 PCERT_EXTENSION ext;
1718 if ((ext = CertFindExtension(szOID_CRL_DIST_POINTS,
1719 cert->pCertInfo->cExtension, cert->pCertInfo->rgExtension)))
1720 error = verify_cert_revocation_from_dist_points_ext(&ext->Value, cert,
1721 index, pTime, dwFlags, pRevPara, pRevStatus);
1722 else if ((ext = CertFindExtension(szOID_AUTHORITY_INFO_ACCESS,
1723 cert->pCertInfo->cExtension, cert->pCertInfo->rgExtension)))
1724 error = verify_cert_revocation_from_aia_ext(&ext->Value, cert,
1725 index, pTime, dwFlags, pRevPara, pRevStatus);
1726 else
1728 if (pRevPara && pRevPara->hCrlStore && pRevPara->pIssuerCert)
1730 PCCRL_CONTEXT crl = NULL;
1731 BOOL canSignCRLs;
1733 /* If the caller told us about the issuer, make sure the issuer
1734 * can sign CRLs before looking for one.
1736 if ((ext = CertFindExtension(szOID_KEY_USAGE,
1737 pRevPara->pIssuerCert->pCertInfo->cExtension,
1738 pRevPara->pIssuerCert->pCertInfo->rgExtension)))
1740 CRYPT_BIT_BLOB usage;
1741 DWORD size = sizeof(usage);
1743 if (!CryptDecodeObjectEx(cert->dwCertEncodingType, X509_BITS,
1744 ext->Value.pbData, ext->Value.cbData,
1745 CRYPT_DECODE_NOCOPY_FLAG, NULL, &usage, &size))
1746 canSignCRLs = FALSE;
1747 else if (usage.cbData > 2)
1749 /* The key usage extension only defines 9 bits => no more
1750 * than 2 bytes are needed to encode all known usages.
1752 canSignCRLs = FALSE;
1754 else
1756 BYTE usageBits = usage.pbData[usage.cbData - 1];
1758 canSignCRLs = usageBits & CERT_CRL_SIGN_KEY_USAGE;
1761 else
1762 canSignCRLs = TRUE;
1763 if (canSignCRLs)
1765 /* If the caller was helpful enough to tell us where to find a
1766 * CRL for the cert, look for one and check it.
1768 crl = CertFindCRLInStore(pRevPara->hCrlStore,
1769 cert->dwCertEncodingType,
1770 CRL_FIND_ISSUED_BY_SIGNATURE_FLAG |
1771 CRL_FIND_ISSUED_BY_AKI_FLAG,
1772 CRL_FIND_ISSUED_BY, pRevPara->pIssuerCert, NULL);
1774 if (crl)
1776 error = verify_cert_revocation_with_crl_offline(cert, crl,
1777 index, pTime, pRevStatus);
1778 CertFreeCRLContext(crl);
1780 else
1782 TRACE("no CRL found\n");
1783 error = CRYPT_E_NO_REVOCATION_CHECK;
1784 pRevStatus->dwIndex = index;
1787 else
1789 if (!pRevPara)
1790 WARN("no CERT_REVOCATION_PARA\n");
1791 else if (!pRevPara->hCrlStore)
1792 WARN("no dist points/aia extension and no CRL store\n");
1793 else if (!pRevPara->pIssuerCert)
1794 WARN("no dist points/aia extension and no issuer\n");
1795 error = CRYPT_E_NO_REVOCATION_CHECK;
1796 pRevStatus->dwIndex = index;
1799 return error;
1802 typedef struct _CERT_REVOCATION_PARA_NO_EXTRA_FIELDS {
1803 DWORD cbSize;
1804 PCCERT_CONTEXT pIssuerCert;
1805 DWORD cCertStore;
1806 HCERTSTORE *rgCertStore;
1807 HCERTSTORE hCrlStore;
1808 LPFILETIME pftTimeToUse;
1809 } CERT_REVOCATION_PARA_NO_EXTRA_FIELDS;
1811 typedef struct _OLD_CERT_REVOCATION_STATUS {
1812 DWORD cbSize;
1813 DWORD dwIndex;
1814 DWORD dwError;
1815 DWORD dwReason;
1816 } OLD_CERT_REVOCATION_STATUS;
1818 /***********************************************************************
1819 * CertDllVerifyRevocation (CRYPTNET.@)
1821 BOOL WINAPI CertDllVerifyRevocation(DWORD dwEncodingType, DWORD dwRevType,
1822 DWORD cContext, PVOID rgpvContext[], DWORD dwFlags,
1823 PCERT_REVOCATION_PARA pRevPara, PCERT_REVOCATION_STATUS pRevStatus)
1825 DWORD error = 0, i;
1826 FILETIME now;
1827 LPFILETIME pTime = NULL;
1829 TRACE("(%08x, %d, %d, %p, %08x, %p, %p)\n", dwEncodingType, dwRevType,
1830 cContext, rgpvContext, dwFlags, pRevPara, pRevStatus);
1832 if (pRevStatus->cbSize != sizeof(OLD_CERT_REVOCATION_STATUS) &&
1833 pRevStatus->cbSize != sizeof(CERT_REVOCATION_STATUS))
1835 SetLastError(E_INVALIDARG);
1836 return FALSE;
1838 if (!cContext)
1840 SetLastError(E_INVALIDARG);
1841 return FALSE;
1843 if (pRevPara && pRevPara->cbSize >=
1844 sizeof(CERT_REVOCATION_PARA_NO_EXTRA_FIELDS))
1845 pTime = pRevPara->pftTimeToUse;
1846 if (!pTime)
1848 GetSystemTimeAsFileTime(&now);
1849 pTime = &now;
1851 memset(&pRevStatus->dwIndex, 0, pRevStatus->cbSize - sizeof(DWORD));
1852 if (dwRevType != CERT_CONTEXT_REVOCATION_TYPE)
1853 error = CRYPT_E_NO_REVOCATION_CHECK;
1854 else
1856 for (i = 0; !error && i < cContext; i++)
1857 error = verify_cert_revocation(rgpvContext[i], i, pTime, dwFlags,
1858 pRevPara, pRevStatus);
1860 if (error)
1862 SetLastError(error);
1863 pRevStatus->dwError = error;
1865 TRACE("returning %d (%08x)\n", !error, error);
1866 return !error;