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
22 #include "wine/port.h"
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
26 #define CERT_REVOCATION_PARA_HAS_EXTRA_FIELDS
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(cryptnet
);
43 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
45 TRACE("(0x%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
48 case DLL_PROCESS_ATTACH
:
49 DisableThreadLibraryCalls(hinstDLL
);
51 case DLL_PROCESS_DETACH
:
52 /* Do uninitialisation here */
59 static const WCHAR cryptNet
[] = { 'c','r','y','p','t','n','e','t','.',
61 static const WCHAR ldapProvOpenStore
[] = { 'L','d','a','p','P','r','o','v',
62 'O','p','e','S','t','o','r','e',0 };
64 /***********************************************************************
65 * DllRegisterServer (CRYPTNET.@)
67 HRESULT WINAPI
DllRegisterServer(void)
70 CryptRegisterDefaultOIDFunction(X509_ASN_ENCODING
,
71 CRYPT_OID_VERIFY_REVOCATION_FUNC
, 0, cryptNet
);
72 CryptRegisterOIDFunction(0, CRYPT_OID_OPEN_STORE_PROV_FUNC
, "Ldap",
73 cryptNet
, "LdapProvOpenStore");
74 CryptRegisterOIDFunction(0, CRYPT_OID_OPEN_STORE_PROV_FUNC
,
75 CERT_STORE_PROV_LDAP_W
, cryptNet
, "LdapProvOpenStore");
79 /***********************************************************************
80 * DllUnregisterServer (CRYPTNET.@)
82 HRESULT WINAPI
DllUnregisterServer(void)
85 CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING
,
86 CRYPT_OID_VERIFY_REVOCATION_FUNC
, cryptNet
);
87 CryptUnregisterOIDFunction(0, CRYPT_OID_OPEN_STORE_PROV_FUNC
, "Ldap");
88 CryptUnregisterOIDFunction(0, CRYPT_OID_OPEN_STORE_PROV_FUNC
,
89 CERT_STORE_PROV_LDAP_W
);
93 static const char *url_oid_to_str(LPCSTR oid
)
103 #define _x(oid) case LOWORD(oid): return #oid
104 _x(URL_OID_CERTIFICATE_ISSUER
);
105 _x(URL_OID_CERTIFICATE_CRL_DIST_POINT
);
106 _x(URL_OID_CTL_ISSUER
);
107 _x(URL_OID_CTL_NEXT_UPDATE
);
108 _x(URL_OID_CRL_ISSUER
);
109 _x(URL_OID_CERTIFICATE_FRESHEST_CRL
);
110 _x(URL_OID_CRL_FRESHEST_CRL
);
111 _x(URL_OID_CROSS_CERT_DIST_POINT
);
114 snprintf(buf
, sizeof(buf
), "%d", LOWORD(oid
));
120 typedef BOOL (WINAPI
*UrlDllGetObjectUrlFunc
)(LPCSTR
, LPVOID
, DWORD
,
121 PCRYPT_URL_ARRAY
, DWORD
*, PCRYPT_URL_INFO
, DWORD
*, LPVOID
);
123 static BOOL WINAPI
CRYPT_GetUrlFromCertificateIssuer(LPCSTR pszUrlOid
,
124 LPVOID pvPara
, DWORD dwFlags
, PCRYPT_URL_ARRAY pUrlArray
, DWORD
*pcbUrlArray
,
125 PCRYPT_URL_INFO pUrlInfo
, DWORD
*pcbUrlInfo
, LPVOID pvReserved
)
127 /* FIXME: This depends on the AIA (authority info access) extension being
128 * supported in crypt32.
131 SetLastError(CRYPT_E_NOT_FOUND
);
135 static BOOL WINAPI
CRYPT_GetUrlFromCertificateCRLDistPoint(LPCSTR pszUrlOid
,
136 LPVOID pvPara
, DWORD dwFlags
, PCRYPT_URL_ARRAY pUrlArray
, DWORD
*pcbUrlArray
,
137 PCRYPT_URL_INFO pUrlInfo
, DWORD
*pcbUrlInfo
, LPVOID pvReserved
)
139 PCCERT_CONTEXT cert
= pvPara
;
143 /* The only applicable flag is CRYPT_GET_URL_FROM_EXTENSION */
144 if (dwFlags
&& !(dwFlags
& CRYPT_GET_URL_FROM_EXTENSION
))
146 SetLastError(CRYPT_E_NOT_FOUND
);
149 if ((ext
= CertFindExtension(szOID_CRL_DIST_POINTS
,
150 cert
->pCertInfo
->cExtension
, cert
->pCertInfo
->rgExtension
)))
152 CRL_DIST_POINTS_INFO
*info
;
155 ret
= CryptDecodeObjectEx(X509_ASN_ENCODING
, X509_CRL_DIST_POINTS
,
156 ext
->Value
.pbData
, ext
->Value
.cbData
, CRYPT_DECODE_ALLOC_FLAG
, NULL
,
160 DWORD i
, cUrl
, bytesNeeded
= sizeof(CRYPT_URL_ARRAY
);
162 for (i
= 0, cUrl
= 0; i
< info
->cDistPoint
; i
++)
163 if (info
->rgDistPoint
[i
].DistPointName
.dwDistPointNameChoice
164 == CRL_DIST_POINT_FULL_NAME
)
167 CERT_ALT_NAME_INFO
*name
=
168 &info
->rgDistPoint
[i
].DistPointName
.u
.FullName
;
170 for (j
= 0; j
< name
->cAltEntry
; j
++)
171 if (name
->rgAltEntry
[j
].dwAltNameChoice
==
174 if (name
->rgAltEntry
[j
].u
.pwszURL
)
177 bytesNeeded
+= sizeof(LPWSTR
) +
178 (lstrlenW(name
->rgAltEntry
[j
].u
.pwszURL
) + 1)
185 SetLastError(E_INVALIDARG
);
189 *pcbUrlArray
= bytesNeeded
;
190 else if (*pcbUrlArray
< bytesNeeded
)
192 SetLastError(ERROR_MORE_DATA
);
193 *pcbUrlArray
= bytesNeeded
;
200 *pcbUrlArray
= bytesNeeded
;
202 pUrlArray
->rgwszUrl
=
203 (LPWSTR
*)((BYTE
*)pUrlArray
+ sizeof(CRYPT_URL_ARRAY
));
204 nextUrl
= (LPWSTR
)((BYTE
*)pUrlArray
+ sizeof(CRYPT_URL_ARRAY
)
205 + cUrl
* sizeof(LPWSTR
));
206 for (i
= 0; i
< info
->cDistPoint
; i
++)
207 if (info
->rgDistPoint
[i
].DistPointName
.dwDistPointNameChoice
208 == CRL_DIST_POINT_FULL_NAME
)
211 CERT_ALT_NAME_INFO
*name
=
212 &info
->rgDistPoint
[i
].DistPointName
.u
.FullName
;
214 for (j
= 0; j
< name
->cAltEntry
; j
++)
215 if (name
->rgAltEntry
[j
].dwAltNameChoice
==
218 if (name
->rgAltEntry
[j
].u
.pwszURL
)
221 name
->rgAltEntry
[j
].u
.pwszURL
);
222 pUrlArray
->rgwszUrl
[pUrlArray
->cUrl
++] =
225 (lstrlenW(name
->rgAltEntry
[j
].u
.pwszURL
) + 1);
234 FIXME("url info: stub\n");
236 *pcbUrlInfo
= sizeof(CRYPT_URL_INFO
);
237 else if (*pcbUrlInfo
< sizeof(CRYPT_URL_INFO
))
239 *pcbUrlInfo
= sizeof(CRYPT_URL_INFO
);
240 SetLastError(ERROR_MORE_DATA
);
245 *pcbUrlInfo
= sizeof(CRYPT_URL_INFO
);
246 memset(pUrlInfo
, 0, sizeof(CRYPT_URL_INFO
));
254 SetLastError(CRYPT_E_NOT_FOUND
);
258 /***********************************************************************
259 * CryptGetObjectUrl (CRYPTNET.@)
261 BOOL WINAPI
CryptGetObjectUrl(LPCSTR pszUrlOid
, LPVOID pvPara
, DWORD dwFlags
,
262 PCRYPT_URL_ARRAY pUrlArray
, DWORD
*pcbUrlArray
, PCRYPT_URL_INFO pUrlInfo
,
263 DWORD
*pcbUrlInfo
, LPVOID pvReserved
)
265 UrlDllGetObjectUrlFunc func
= NULL
;
266 HCRYPTOIDFUNCADDR hFunc
= NULL
;
269 TRACE("(%s, %p, %08x, %p, %p, %p, %p, %p)\n", debugstr_a(pszUrlOid
),
270 pvPara
, dwFlags
, pUrlArray
, pcbUrlArray
, pUrlInfo
, pcbUrlInfo
, pvReserved
);
272 if (!HIWORD(pszUrlOid
))
274 switch (LOWORD(pszUrlOid
))
276 case LOWORD(URL_OID_CERTIFICATE_ISSUER
):
277 func
= CRYPT_GetUrlFromCertificateIssuer
;
279 case LOWORD(URL_OID_CERTIFICATE_CRL_DIST_POINT
):
280 func
= CRYPT_GetUrlFromCertificateCRLDistPoint
;
283 FIXME("unimplemented for %s\n", url_oid_to_str(pszUrlOid
));
284 SetLastError(ERROR_FILE_NOT_FOUND
);
289 static HCRYPTOIDFUNCSET set
= NULL
;
292 set
= CryptInitOIDFunctionSet(URL_OID_GET_OBJECT_URL_FUNC
, 0);
293 CryptGetOIDFunctionAddress(set
, X509_ASN_ENCODING
, pszUrlOid
, 0,
294 (void **)&func
, &hFunc
);
297 ret
= func(pszUrlOid
, pvPara
, dwFlags
, pUrlArray
, pcbUrlArray
,
298 pUrlInfo
, pcbUrlInfo
, pvReserved
);
300 CryptFreeOIDFunctionAddress(hFunc
, 0);
304 /***********************************************************************
305 * CryptRetrieveObjectByUrlA (CRYPTNET.@)
307 BOOL WINAPI
CryptRetrieveObjectByUrlA(LPCSTR pszURL
, LPCSTR pszObjectOid
,
308 DWORD dwRetrievalFlags
, DWORD dwTimeout
, LPVOID
*ppvObject
,
309 HCRYPTASYNC hAsyncRetrieve
, PCRYPT_CREDENTIALS pCredentials
, LPVOID pvVerify
,
310 PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
)
315 TRACE("(%s, %s, %08x, %d, %p, %p, %p, %p, %p)\n", debugstr_a(pszURL
),
316 debugstr_a(pszObjectOid
), dwRetrievalFlags
, dwTimeout
, ppvObject
,
317 hAsyncRetrieve
, pCredentials
, pvVerify
, pAuxInfo
);
321 SetLastError(ERROR_INVALID_PARAMETER
);
324 len
= MultiByteToWideChar(CP_ACP
, 0, pszURL
, -1, NULL
, 0);
327 LPWSTR url
= CryptMemAlloc(len
* sizeof(WCHAR
));
331 MultiByteToWideChar(CP_ACP
, 0, pszURL
, -1, url
, len
);
332 ret
= CryptRetrieveObjectByUrlW(url
, pszObjectOid
,
333 dwRetrievalFlags
, dwTimeout
, ppvObject
, hAsyncRetrieve
,
334 pCredentials
, pvVerify
, pAuxInfo
);
338 SetLastError(ERROR_OUTOFMEMORY
);
343 static void WINAPI
CRYPT_FreeBlob(LPCSTR pszObjectOid
,
344 PCRYPT_BLOB_ARRAY pObject
, void *pvFreeContext
)
348 for (i
= 0; i
< pObject
->cBlob
; i
++)
349 CryptMemFree(pObject
->rgBlob
[i
].pbData
);
350 CryptMemFree(pObject
->rgBlob
);
353 static BOOL
CRYPT_GetObjectFromFile(HANDLE hFile
, PCRYPT_BLOB_ARRAY pObject
)
358 if ((ret
= GetFileSizeEx(hFile
, &size
)))
362 WARN("file too big\n");
363 SetLastError(ERROR_INVALID_DATA
);
368 CRYPT_DATA_BLOB blob
;
370 blob
.pbData
= CryptMemAlloc(size
.u
.LowPart
);
373 blob
.cbData
= size
.u
.LowPart
;
374 ret
= ReadFile(hFile
, blob
.pbData
, size
.u
.LowPart
, &blob
.cbData
,
378 pObject
->rgBlob
= CryptMemAlloc(sizeof(CRYPT_DATA_BLOB
));
382 memcpy(pObject
->rgBlob
, &blob
, sizeof(CRYPT_DATA_BLOB
));
386 SetLastError(ERROR_OUTOFMEMORY
);
391 CryptMemFree(blob
.pbData
);
395 SetLastError(ERROR_OUTOFMEMORY
);
403 static BOOL
CRYPT_GetObjectFromCache(LPCWSTR pszURL
, PCRYPT_BLOB_ARRAY pObject
,
404 PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
)
407 INTERNET_CACHE_ENTRY_INFOW
*pCacheInfo
= NULL
;
410 TRACE("(%s, %p, %p)\n", debugstr_w(pszURL
), pObject
, pAuxInfo
);
412 ret
= GetUrlCacheEntryInfoW(pszURL
, NULL
, &size
);
413 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
415 pCacheInfo
= CryptMemAlloc(size
);
419 SetLastError(ERROR_OUTOFMEMORY
);
421 if (ret
&& (ret
= GetUrlCacheEntryInfoW(pszURL
, pCacheInfo
, &size
)))
425 GetSystemTimeAsFileTime(&ft
);
426 if (CompareFileTime(&pCacheInfo
->ExpireTime
, &ft
) >= 0)
428 HANDLE hFile
= CreateFileW(pCacheInfo
->lpszLocalFileName
,
429 GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
431 if (hFile
!= INVALID_HANDLE_VALUE
)
433 if ((ret
= CRYPT_GetObjectFromFile(hFile
, pObject
)))
435 if (pAuxInfo
&& pAuxInfo
->cbSize
>=
436 offsetof(CRYPT_RETRIEVE_AUX_INFO
,
437 pLastSyncTime
) + sizeof(PFILETIME
) &&
438 pAuxInfo
->pLastSyncTime
)
439 memcpy(pAuxInfo
->pLastSyncTime
,
440 &pCacheInfo
->LastSyncTime
,
447 DeleteUrlCacheEntryW(pszURL
);
453 DeleteUrlCacheEntryW(pszURL
);
457 CryptMemFree(pCacheInfo
);
458 TRACE("returning %d\n", ret
);
462 /* Parses the URL, and sets components's lpszHostName and lpszUrlPath members
463 * to NULL-terminated copies of those portions of the URL (to be freed with
466 static BOOL
CRYPT_CrackUrl(LPCWSTR pszURL
, URL_COMPONENTSW
*components
)
470 TRACE("(%s, %p)\n", debugstr_w(pszURL
), components
);
472 memset(components
, 0, sizeof(*components
));
473 components
->dwStructSize
= sizeof(*components
);
474 components
->lpszHostName
= CryptMemAlloc(MAX_PATH
* sizeof(WCHAR
));
475 components
->dwHostNameLength
= MAX_PATH
;
476 components
->lpszUrlPath
= CryptMemAlloc(MAX_PATH
* 2 * sizeof(WCHAR
));
477 components
->dwUrlPathLength
= 2 * MAX_PATH
;
478 ret
= InternetCrackUrlW(pszURL
, 0, ICU_DECODE
, components
);
481 if ((components
->dwUrlPathLength
== 2 * MAX_PATH
- 1) ||
482 (components
->dwHostNameLength
== MAX_PATH
- 1))
483 FIXME("Buffers are too small\n");
484 switch (components
->nScheme
)
486 case INTERNET_SCHEME_FTP
:
487 if (!components
->nPort
)
488 components
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
490 case INTERNET_SCHEME_HTTP
:
491 if (!components
->nPort
)
492 components
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
498 TRACE("returning %d\n", ret
);
509 static struct InetContext
*CRYPT_MakeInetContext(DWORD dwTimeout
)
511 struct InetContext
*context
= CryptMemAlloc(sizeof(struct InetContext
));
515 context
->event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
518 CryptMemFree(context
);
523 context
->timeout
= dwTimeout
;
524 context
->error
= ERROR_SUCCESS
;
530 static BOOL
CRYPT_DownloadObject(DWORD dwRetrievalFlags
, HINTERNET hHttp
,
531 struct InetContext
*context
, PCRYPT_BLOB_ARRAY pObject
,
532 PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
)
534 CRYPT_DATA_BLOB object
= { 0, NULL
};
535 DWORD bytesAvailable
;
539 if ((ret
= InternetQueryDataAvailable(hHttp
, &bytesAvailable
, 0, 0)))
544 object
.pbData
= CryptMemRealloc(object
.pbData
,
545 object
.cbData
+ bytesAvailable
);
547 object
.pbData
= CryptMemAlloc(bytesAvailable
);
550 INTERNET_BUFFERSA buffer
= { sizeof(buffer
), 0 };
552 buffer
.dwBufferLength
= bytesAvailable
;
553 buffer
.lpvBuffer
= object
.pbData
+ object
.cbData
;
554 if (!(ret
= InternetReadFileExA(hHttp
, &buffer
, IRF_NO_WAIT
,
555 (DWORD_PTR
)context
)))
557 if (GetLastError() == ERROR_IO_PENDING
)
559 if (WaitForSingleObject(context
->event
,
560 context
->timeout
) == WAIT_TIMEOUT
)
561 SetLastError(ERROR_TIMEOUT
);
562 else if (context
->error
)
563 SetLastError(context
->error
);
569 object
.cbData
+= bytesAvailable
;
573 SetLastError(ERROR_OUTOFMEMORY
);
578 else if (GetLastError() == ERROR_IO_PENDING
)
580 if (WaitForSingleObject(context
->event
, context
->timeout
) ==
582 SetLastError(ERROR_TIMEOUT
);
586 } while (ret
&& bytesAvailable
);
589 pObject
->rgBlob
= CryptMemAlloc(sizeof(CRYPT_DATA_BLOB
));
590 if (!pObject
->rgBlob
)
592 CryptMemFree(object
.pbData
);
593 SetLastError(ERROR_OUTOFMEMORY
);
598 pObject
->rgBlob
[0].cbData
= object
.cbData
;
599 pObject
->rgBlob
[0].pbData
= object
.pbData
;
603 TRACE("returning %d\n", ret
);
607 /* Finds the object specified by pszURL in the cache. If it's not found,
608 * creates a new cache entry for the object and writes the object to it.
609 * Sets the expiration time of the cache entry to expires.
611 static void CRYPT_CacheURL(LPCWSTR pszURL
, PCRYPT_BLOB_ARRAY pObject
,
612 DWORD dwRetrievalFlags
, FILETIME expires
)
614 WCHAR cacheFileName
[MAX_PATH
];
616 BOOL ret
, create
= FALSE
;
618 GetUrlCacheEntryInfoW(pszURL
, NULL
, &size
);
619 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
621 INTERNET_CACHE_ENTRY_INFOW
*info
= CryptMemAlloc(size
);
627 ret
= GetUrlCacheEntryInfoW(pszURL
, info
, &size
);
629 lstrcpyW(cacheFileName
, info
->lpszLocalFileName
);
630 /* Check if the existing cache entry is up to date. If it isn't,
631 * overwite it with the new value.
633 GetSystemTimeAsFileTime(&ft
);
634 if (CompareFileTime(&info
->ExpireTime
, &ft
) < 0)
643 ret
= CreateUrlCacheEntryW(pszURL
, pObject
->rgBlob
[0].cbData
, NULL
,
654 HANDLE hCacheFile
= CreateFileW(cacheFileName
, GENERIC_WRITE
, 0,
655 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
657 if (hCacheFile
!= INVALID_HANDLE_VALUE
)
661 WriteFile(hCacheFile
, pObject
->rgBlob
[0].pbData
,
662 pObject
->rgBlob
[0].cbData
, &bytesWritten
, NULL
);
663 CloseHandle(hCacheFile
);
670 if (!(dwRetrievalFlags
& CRYPT_STICKY_CACHE_RETRIEVAL
))
671 entryType
= NORMAL_CACHE_ENTRY
;
673 entryType
= STICKY_CACHE_ENTRY
;
674 CommitUrlCacheEntryW(pszURL
, cacheFileName
, expires
, ft
, entryType
,
675 NULL
, 0, NULL
, NULL
);
680 static void CALLBACK
CRYPT_InetStatusCallback(HINTERNET hInt
,
681 DWORD_PTR dwContext
, DWORD status
, void *statusInfo
, DWORD statusInfoLen
)
683 struct InetContext
*context
= (struct InetContext
*)dwContext
;
684 LPINTERNET_ASYNC_RESULT result
;
688 case INTERNET_STATUS_REQUEST_COMPLETE
:
690 context
->error
= result
->dwError
;
691 SetEvent(context
->event
);
695 static BOOL
CRYPT_Connect(URL_COMPONENTSW
*components
,
696 struct InetContext
*context
, PCRYPT_CREDENTIALS pCredentials
,
697 HINTERNET
*phInt
, HINTERNET
*phHost
)
701 TRACE("(%s:%d, %p, %p, %p, %p)\n", debugstr_w(components
->lpszHostName
),
702 components
->nPort
, context
, pCredentials
, phInt
, phInt
);
705 *phInt
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
,
706 context
? INTERNET_FLAG_ASYNC
: 0);
712 InternetSetStatusCallbackW(*phInt
, CRYPT_InetStatusCallback
);
713 switch (components
->nScheme
)
715 case INTERNET_SCHEME_FTP
:
716 service
= INTERNET_SERVICE_FTP
;
718 case INTERNET_SCHEME_HTTP
:
719 service
= INTERNET_SERVICE_HTTP
;
724 /* FIXME: use pCredentials for username/password */
725 *phHost
= InternetConnectW(*phInt
, components
->lpszHostName
,
726 components
->nPort
, NULL
, NULL
, service
, 0, (DWORD_PTR
)context
);
729 InternetCloseHandle(*phInt
);
738 TRACE("returning %d\n", ret
);
742 static BOOL WINAPI
FTP_RetrieveEncodedObjectW(LPCWSTR pszURL
,
743 LPCSTR pszObjectOid
, DWORD dwRetrievalFlags
, DWORD dwTimeout
,
744 PCRYPT_BLOB_ARRAY pObject
, PFN_FREE_ENCODED_OBJECT_FUNC
*ppfnFreeObject
,
745 void **ppvFreeContext
, HCRYPTASYNC hAsyncRetrieve
,
746 PCRYPT_CREDENTIALS pCredentials
, PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
)
748 FIXME("(%s, %s, %08x, %d, %p, %p, %p, %p, %p, %p)\n", debugstr_w(pszURL
),
749 debugstr_a(pszObjectOid
), dwRetrievalFlags
, dwTimeout
, pObject
,
750 ppfnFreeObject
, ppvFreeContext
, hAsyncRetrieve
, pCredentials
, pAuxInfo
);
753 pObject
->rgBlob
= NULL
;
754 *ppfnFreeObject
= CRYPT_FreeBlob
;
755 *ppvFreeContext
= NULL
;
759 static const WCHAR x509cacert
[] = { 'a','p','p','l','i','c','a','t','i','o','n',
760 '/','x','-','x','5','0','9','-','c','a','-','c','e','r','t',0 };
761 static const WCHAR x509emailcert
[] = { 'a','p','p','l','i','c','a','t','i','o',
762 'n','/','x','-','x','5','0','9','-','e','m','a','i','l','-','c','e','r','t',
764 static const WCHAR x509servercert
[] = { 'a','p','p','l','i','c','a','t','i','o',
765 'n','/','x','-','x','5','0','9','-','s','e','r','v','e','r','-','c','e','r',
767 static const WCHAR x509usercert
[] = { 'a','p','p','l','i','c','a','t','i','o',
768 'n','/','x','-','x','5','0','9','-','u','s','e','r','-','c','e','r','t',0 };
769 static const WCHAR pkcs7cert
[] = { 'a','p','p','l','i','c','a','t','i','o','n',
770 '/','x','-','p','k','c','s','7','-','c','e','r','t','i','f','c','a','t','e',
772 static const WCHAR pkixCRL
[] = { 'a','p','p','l','i','c','a','t','i','o','n',
773 '/','p','k','i','x','-','c','r','l',0 };
774 static const WCHAR pkcs7CRL
[] = { 'a','p','p','l','i','c','a','t','i','o','n',
775 '/','x','-','p','k','c','s','7','-','c','r','l',0 };
776 static const WCHAR pkcs7sig
[] = { 'a','p','p','l','i','c','a','t','i','o','n',
777 '/','x','-','p','k','c','s','7','-','s','i','g','n','a','t','u','r','e',0 };
778 static const WCHAR pkcs7mime
[] = { 'a','p','p','l','i','c','a','t','i','o','n',
779 '/','x','-','p','k','c','s','7','-','m','i','m','e',0 };
781 static BOOL WINAPI
HTTP_RetrieveEncodedObjectW(LPCWSTR pszURL
,
782 LPCSTR pszObjectOid
, DWORD dwRetrievalFlags
, DWORD dwTimeout
,
783 PCRYPT_BLOB_ARRAY pObject
, PFN_FREE_ENCODED_OBJECT_FUNC
*ppfnFreeObject
,
784 void **ppvFreeContext
, HCRYPTASYNC hAsyncRetrieve
,
785 PCRYPT_CREDENTIALS pCredentials
, PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
)
789 TRACE("(%s, %s, %08x, %d, %p, %p, %p, %p, %p, %p)\n", debugstr_w(pszURL
),
790 debugstr_a(pszObjectOid
), dwRetrievalFlags
, dwTimeout
, pObject
,
791 ppfnFreeObject
, ppvFreeContext
, hAsyncRetrieve
, pCredentials
, pAuxInfo
);
794 pObject
->rgBlob
= NULL
;
795 *ppfnFreeObject
= CRYPT_FreeBlob
;
796 *ppvFreeContext
= NULL
;
798 if (!(dwRetrievalFlags
& CRYPT_WIRE_ONLY_RETRIEVAL
))
799 ret
= CRYPT_GetObjectFromCache(pszURL
, pObject
, pAuxInfo
);
800 if (!ret
&& (!(dwRetrievalFlags
& CRYPT_CACHE_ONLY_RETRIEVAL
) ||
801 (dwRetrievalFlags
& CRYPT_WIRE_ONLY_RETRIEVAL
)))
803 URL_COMPONENTSW components
;
805 if ((ret
= CRYPT_CrackUrl(pszURL
, &components
)))
807 HINTERNET hInt
, hHost
;
808 struct InetContext
*context
= NULL
;
811 context
= CRYPT_MakeInetContext(dwTimeout
);
812 ret
= CRYPT_Connect(&components
, context
, pCredentials
, &hInt
,
816 static LPCWSTR types
[] = { x509cacert
, x509emailcert
,
817 x509servercert
, x509usercert
, pkcs7cert
, pkixCRL
, pkcs7CRL
,
818 pkcs7sig
, pkcs7mime
, NULL
};
819 HINTERNET hHttp
= HttpOpenRequestW(hHost
, NULL
,
820 components
.lpszUrlPath
, NULL
, NULL
, types
,
821 INTERNET_FLAG_NO_COOKIES
| INTERNET_FLAG_NO_UI
,
828 InternetSetOptionW(hHttp
,
829 INTERNET_OPTION_RECEIVE_TIMEOUT
, &dwTimeout
,
831 InternetSetOptionW(hHttp
, INTERNET_OPTION_SEND_TIMEOUT
,
832 &dwTimeout
, sizeof(dwTimeout
));
834 ret
= HttpSendRequestExW(hHttp
, NULL
, NULL
, 0,
836 if (!ret
&& GetLastError() == ERROR_IO_PENDING
)
838 if (WaitForSingleObject(context
->event
,
839 context
->timeout
) == WAIT_TIMEOUT
)
840 SetLastError(ERROR_TIMEOUT
);
844 /* We don't set ret to TRUE in this block to avoid masking
845 * an error from HttpSendRequestExW.
847 if (!HttpEndRequestW(hHttp
, NULL
, 0, (DWORD_PTR
)context
) &&
848 GetLastError() == ERROR_IO_PENDING
)
850 if (WaitForSingleObject(context
->event
,
851 context
->timeout
) == WAIT_TIMEOUT
)
853 SetLastError(ERROR_TIMEOUT
);
858 ret
= CRYPT_DownloadObject(dwRetrievalFlags
, hHttp
,
859 context
, pObject
, pAuxInfo
);
860 if (ret
&& !(dwRetrievalFlags
& CRYPT_DONT_CACHE_RESULT
))
863 DWORD len
= sizeof(st
);
865 if (HttpQueryInfoW(hHttp
,
866 HTTP_QUERY_EXPIRES
| HTTP_QUERY_FLAG_SYSTEMTIME
, &st
,
871 SystemTimeToFileTime(&st
, &ft
);
872 CRYPT_CacheURL(pszURL
, pObject
, dwRetrievalFlags
,
876 InternetCloseHandle(hHttp
);
878 InternetCloseHandle(hHost
);
879 InternetCloseHandle(hInt
);
883 CloseHandle(context
->event
);
884 CryptMemFree(context
);
886 CryptMemFree(components
.lpszUrlPath
);
887 CryptMemFree(components
.lpszHostName
);
890 TRACE("returning %d\n", ret
);
894 static BOOL WINAPI
File_RetrieveEncodedObjectW(LPCWSTR pszURL
,
895 LPCSTR pszObjectOid
, DWORD dwRetrievalFlags
, DWORD dwTimeout
,
896 PCRYPT_BLOB_ARRAY pObject
, PFN_FREE_ENCODED_OBJECT_FUNC
*ppfnFreeObject
,
897 void **ppvFreeContext
, HCRYPTASYNC hAsyncRetrieve
,
898 PCRYPT_CREDENTIALS pCredentials
, PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
)
900 URL_COMPONENTSW components
= { sizeof(components
), 0 };
903 TRACE("(%s, %s, %08x, %d, %p, %p, %p, %p, %p, %p)\n", debugstr_w(pszURL
),
904 debugstr_a(pszObjectOid
), dwRetrievalFlags
, dwTimeout
, pObject
,
905 ppfnFreeObject
, ppvFreeContext
, hAsyncRetrieve
, pCredentials
, pAuxInfo
);
908 pObject
->rgBlob
= NULL
;
909 *ppfnFreeObject
= CRYPT_FreeBlob
;
910 *ppvFreeContext
= NULL
;
912 components
.lpszUrlPath
= CryptMemAlloc(MAX_PATH
* 2 * sizeof(WCHAR
));
913 components
.dwUrlPathLength
= 2 * MAX_PATH
;
914 ret
= InternetCrackUrlW(pszURL
, 0, ICU_DECODE
, &components
);
919 if (components
.dwUrlPathLength
== 2 * MAX_PATH
- 1)
920 FIXME("Buffers are too small\n");
922 /* 3 == lstrlenW(L"c:") + 1 */
923 path
= CryptMemAlloc((components
.dwUrlPathLength
+ 3) * sizeof(WCHAR
));
928 /* Try to create the file directly - Wine handles / in pathnames */
929 lstrcpynW(path
, components
.lpszUrlPath
,
930 components
.dwUrlPathLength
+ 1);
931 hFile
= CreateFileW(path
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
932 FILE_ATTRIBUTE_NORMAL
, NULL
);
933 if (hFile
== INVALID_HANDLE_VALUE
)
935 /* Try again on the current drive */
936 GetCurrentDirectoryW(components
.dwUrlPathLength
, path
);
939 lstrcpynW(path
+ 2, components
.lpszUrlPath
,
940 components
.dwUrlPathLength
+ 1);
941 hFile
= CreateFileW(path
, GENERIC_READ
, 0, NULL
,
942 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
944 if (hFile
== INVALID_HANDLE_VALUE
)
946 /* Try again on the Windows drive */
947 GetWindowsDirectoryW(path
, components
.dwUrlPathLength
);
950 lstrcpynW(path
+ 2, components
.lpszUrlPath
,
951 components
.dwUrlPathLength
+ 1);
952 hFile
= CreateFileW(path
, GENERIC_READ
, 0, NULL
,
953 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
957 if (hFile
!= INVALID_HANDLE_VALUE
)
959 if ((ret
= CRYPT_GetObjectFromFile(hFile
, pObject
)))
961 if (pAuxInfo
&& pAuxInfo
->cbSize
>=
962 offsetof(CRYPT_RETRIEVE_AUX_INFO
,
963 pLastSyncTime
) + sizeof(PFILETIME
) &&
964 pAuxInfo
->pLastSyncTime
)
965 GetFileTime(hFile
, NULL
, NULL
,
966 pAuxInfo
->pLastSyncTime
);
975 CryptMemFree(components
.lpszUrlPath
);
979 typedef BOOL (WINAPI
*SchemeDllRetrieveEncodedObjectW
)(LPCWSTR pwszUrl
,
980 LPCSTR pszObjectOid
, DWORD dwRetrievalFlags
, DWORD dwTimeout
,
981 PCRYPT_BLOB_ARRAY pObject
, PFN_FREE_ENCODED_OBJECT_FUNC
*ppfnFreeObject
,
982 void **ppvFreeContext
, HCRYPTASYNC hAsyncRetrieve
,
983 PCRYPT_CREDENTIALS pCredentials
, PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
);
985 static BOOL
CRYPT_GetRetrieveFunction(LPCWSTR pszURL
,
986 SchemeDllRetrieveEncodedObjectW
*pFunc
, HCRYPTOIDFUNCADDR
*phFunc
)
988 URL_COMPONENTSW components
= { sizeof(components
), 0 };
991 TRACE("(%s, %p, %p)\n", debugstr_w(pszURL
), pFunc
, phFunc
);
995 components
.dwSchemeLength
= 1;
996 ret
= InternetCrackUrlW(pszURL
, 0, 0, &components
);
999 /* Microsoft always uses CryptInitOIDFunctionSet/
1000 * CryptGetOIDFunctionAddress, but there doesn't seem to be a pressing
1001 * reason to do so for builtin schemes.
1003 switch (components
.nScheme
)
1005 case INTERNET_SCHEME_FTP
:
1006 *pFunc
= FTP_RetrieveEncodedObjectW
;
1008 case INTERNET_SCHEME_HTTP
:
1009 *pFunc
= HTTP_RetrieveEncodedObjectW
;
1011 case INTERNET_SCHEME_FILE
:
1012 *pFunc
= File_RetrieveEncodedObjectW
;
1016 int len
= WideCharToMultiByte(CP_ACP
, 0, components
.lpszScheme
,
1017 components
.dwSchemeLength
, NULL
, 0, NULL
, NULL
);
1021 LPSTR scheme
= CryptMemAlloc(len
);
1025 static HCRYPTOIDFUNCSET set
= NULL
;
1028 set
= CryptInitOIDFunctionSet(
1029 SCHEME_OID_RETRIEVE_ENCODED_OBJECTW_FUNC
, 0);
1030 WideCharToMultiByte(CP_ACP
, 0, components
.lpszScheme
,
1031 components
.dwSchemeLength
, scheme
, len
, NULL
, NULL
);
1032 ret
= CryptGetOIDFunctionAddress(set
, X509_ASN_ENCODING
,
1033 scheme
, 0, (void **)pFunc
, phFunc
);
1034 CryptMemFree(scheme
);
1038 SetLastError(ERROR_OUTOFMEMORY
);
1047 TRACE("returning %d\n", ret
);
1051 static BOOL WINAPI
CRYPT_CreateBlob(LPCSTR pszObjectOid
,
1052 DWORD dwRetrievalFlags
, PCRYPT_BLOB_ARRAY pObject
, void **ppvContext
)
1055 CRYPT_BLOB_ARRAY
*context
;
1058 size
= sizeof(CRYPT_BLOB_ARRAY
) + pObject
->cBlob
* sizeof(CRYPT_DATA_BLOB
);
1059 for (i
= 0; i
< pObject
->cBlob
; i
++)
1060 size
+= pObject
->rgBlob
[i
].cbData
;
1061 context
= CryptMemAlloc(size
);
1068 (CRYPT_DATA_BLOB
*)((LPBYTE
)context
+ sizeof(CRYPT_BLOB_ARRAY
));
1070 (LPBYTE
)context
->rgBlob
+ pObject
->cBlob
* sizeof(CRYPT_DATA_BLOB
);
1071 for (i
= 0; i
< pObject
->cBlob
; i
++)
1073 memcpy(nextData
, pObject
->rgBlob
[i
].pbData
,
1074 pObject
->rgBlob
[i
].cbData
);
1075 context
->rgBlob
[i
].pbData
= nextData
;
1076 context
->rgBlob
[i
].cbData
= pObject
->rgBlob
[i
].cbData
;
1077 nextData
+= pObject
->rgBlob
[i
].cbData
;
1080 *ppvContext
= context
;
1086 typedef BOOL (WINAPI
*AddContextToStore
)(HCERTSTORE hCertStore
,
1087 const void *pContext
, DWORD dwAddDisposition
, const void **ppStoreContext
);
1089 static BOOL
CRYPT_CreateContext(PCRYPT_BLOB_ARRAY pObject
,
1090 DWORD dwExpectedContentTypeFlags
, AddContextToStore addFunc
, void **ppvContext
)
1094 if (!pObject
->cBlob
)
1096 SetLastError(ERROR_INVALID_DATA
);
1100 else if (pObject
->cBlob
== 1)
1102 if (!CryptQueryObject(CERT_QUERY_OBJECT_BLOB
, &pObject
->rgBlob
[0],
1103 dwExpectedContentTypeFlags
, CERT_QUERY_FORMAT_FLAG_BINARY
, 0, NULL
,
1104 NULL
, NULL
, NULL
, NULL
, (const void **)ppvContext
))
1106 SetLastError(CRYPT_E_NO_MATCH
);
1112 HCERTSTORE store
= CertOpenStore(CERT_STORE_PROV_MEMORY
, 0, 0,
1113 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
1118 const void *context
;
1120 for (i
= 0; i
< pObject
->cBlob
; i
++)
1122 if (CryptQueryObject(CERT_QUERY_OBJECT_BLOB
,
1123 &pObject
->rgBlob
[i
], dwExpectedContentTypeFlags
,
1124 CERT_QUERY_FORMAT_FLAG_BINARY
, 0, NULL
, NULL
, NULL
, NULL
,
1127 if (!addFunc(store
, context
, CERT_STORE_ADD_ALWAYS
, NULL
))
1132 SetLastError(CRYPT_E_NO_MATCH
);
1139 *ppvContext
= store
;
1144 static BOOL WINAPI
CRYPT_CreateCert(LPCSTR pszObjectOid
,
1145 DWORD dwRetrievalFlags
, PCRYPT_BLOB_ARRAY pObject
, void **ppvContext
)
1147 return CRYPT_CreateContext(pObject
, CERT_QUERY_CONTENT_FLAG_CERT
,
1148 (AddContextToStore
)CertAddCertificateContextToStore
, ppvContext
);
1151 static BOOL WINAPI
CRYPT_CreateCRL(LPCSTR pszObjectOid
,
1152 DWORD dwRetrievalFlags
, PCRYPT_BLOB_ARRAY pObject
, void **ppvContext
)
1154 return CRYPT_CreateContext(pObject
, CERT_QUERY_CONTENT_FLAG_CRL
,
1155 (AddContextToStore
)CertAddCRLContextToStore
, ppvContext
);
1158 static BOOL WINAPI
CRYPT_CreateCTL(LPCSTR pszObjectOid
,
1159 DWORD dwRetrievalFlags
, PCRYPT_BLOB_ARRAY pObject
, void **ppvContext
)
1161 return CRYPT_CreateContext(pObject
, CERT_QUERY_CONTENT_FLAG_CTL
,
1162 (AddContextToStore
)CertAddCTLContextToStore
, ppvContext
);
1165 static BOOL WINAPI
CRYPT_CreatePKCS7(LPCSTR pszObjectOid
,
1166 DWORD dwRetrievalFlags
, PCRYPT_BLOB_ARRAY pObject
, void **ppvContext
)
1170 if (!pObject
->cBlob
)
1172 SetLastError(ERROR_INVALID_DATA
);
1176 else if (pObject
->cBlob
== 1)
1177 ret
= CryptQueryObject(CERT_QUERY_OBJECT_BLOB
, &pObject
->rgBlob
[0],
1178 CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
|
1179 CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED
, CERT_QUERY_FORMAT_FLAG_BINARY
,
1180 0, NULL
, NULL
, NULL
, ppvContext
, NULL
, NULL
);
1183 FIXME("multiple messages unimplemented\n");
1189 static BOOL WINAPI
CRYPT_CreateAny(LPCSTR pszObjectOid
,
1190 DWORD dwRetrievalFlags
, PCRYPT_BLOB_ARRAY pObject
, void **ppvContext
)
1194 if (!pObject
->cBlob
)
1196 SetLastError(ERROR_INVALID_DATA
);
1202 HCERTSTORE store
= CertOpenStore(CERT_STORE_PROV_COLLECTION
, 0, 0,
1203 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
1207 HCERTSTORE memStore
= CertOpenStore(CERT_STORE_PROV_MEMORY
, 0, 0,
1208 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
1212 CertAddStoreToCollection(store
, memStore
,
1213 CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG
, 0);
1214 CertCloseStore(memStore
, 0);
1218 CertCloseStore(store
, 0);
1227 for (i
= 0; i
< pObject
->cBlob
; i
++)
1229 DWORD contentType
, expectedContentTypes
=
1230 CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
|
1231 CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED
|
1232 CERT_QUERY_CONTENT_FLAG_CERT
|
1233 CERT_QUERY_CONTENT_FLAG_CRL
|
1234 CERT_QUERY_CONTENT_FLAG_CTL
;
1235 HCERTSTORE contextStore
;
1236 const void *context
;
1238 if (CryptQueryObject(CERT_QUERY_OBJECT_BLOB
,
1239 &pObject
->rgBlob
[i
], expectedContentTypes
,
1240 CERT_QUERY_FORMAT_FLAG_BINARY
, 0, NULL
, &contentType
, NULL
,
1241 &contextStore
, NULL
, &context
))
1243 switch (contentType
)
1245 case CERT_QUERY_CONTENT_CERT
:
1246 if (!CertAddCertificateContextToStore(store
,
1247 context
, CERT_STORE_ADD_ALWAYS
, NULL
))
1250 case CERT_QUERY_CONTENT_CRL
:
1251 if (!CertAddCRLContextToStore(store
,
1252 context
, CERT_STORE_ADD_ALWAYS
, NULL
))
1255 case CERT_QUERY_CONTENT_CTL
:
1256 if (!CertAddCTLContextToStore(store
,
1257 context
, CERT_STORE_ADD_ALWAYS
, NULL
))
1261 CertAddStoreToCollection(store
, contextStore
, 0, 0);
1270 *ppvContext
= store
;
1275 typedef BOOL (WINAPI
*ContextDllCreateObjectContext
)(LPCSTR pszObjectOid
,
1276 DWORD dwRetrievalFlags
, PCRYPT_BLOB_ARRAY pObject
, void **ppvContext
);
1278 static BOOL
CRYPT_GetCreateFunction(LPCSTR pszObjectOid
,
1279 ContextDllCreateObjectContext
*pFunc
, HCRYPTOIDFUNCADDR
*phFunc
)
1283 TRACE("(%s, %p, %p)\n", debugstr_a(pszObjectOid
), pFunc
, phFunc
);
1287 if (!HIWORD(pszObjectOid
))
1289 switch (LOWORD(pszObjectOid
))
1292 *pFunc
= CRYPT_CreateBlob
;
1294 case LOWORD(CONTEXT_OID_CERTIFICATE
):
1295 *pFunc
= CRYPT_CreateCert
;
1297 case LOWORD(CONTEXT_OID_CRL
):
1298 *pFunc
= CRYPT_CreateCRL
;
1300 case LOWORD(CONTEXT_OID_CTL
):
1301 *pFunc
= CRYPT_CreateCTL
;
1303 case LOWORD(CONTEXT_OID_PKCS7
):
1304 *pFunc
= CRYPT_CreatePKCS7
;
1306 case LOWORD(CONTEXT_OID_CAPI2_ANY
):
1307 *pFunc
= CRYPT_CreateAny
;
1313 static HCRYPTOIDFUNCSET set
= NULL
;
1316 set
= CryptInitOIDFunctionSet(
1317 CONTEXT_OID_CREATE_OBJECT_CONTEXT_FUNC
, 0);
1318 ret
= CryptGetOIDFunctionAddress(set
, X509_ASN_ENCODING
, pszObjectOid
,
1319 0, (void **)pFunc
, phFunc
);
1321 TRACE("returning %d\n", ret
);
1325 typedef BOOL (*get_object_expiration_func
)(void *pvContext
,
1326 FILETIME
*expiration
);
1328 static BOOL
CRYPT_GetExpirationFromCert(void *pvObject
, FILETIME
*expiration
)
1330 PCCERT_CONTEXT cert
= pvObject
;
1332 *expiration
= cert
->pCertInfo
->NotAfter
;
1336 static BOOL
CRYPT_GetExpirationFromCRL(void *pvObject
, FILETIME
*expiration
)
1338 PCCRL_CONTEXT cert
= pvObject
;
1340 *expiration
= cert
->pCrlInfo
->NextUpdate
;
1344 static BOOL
CRYPT_GetExpirationFromCTL(void *pvObject
, FILETIME
*expiration
)
1346 PCCTL_CONTEXT cert
= pvObject
;
1348 *expiration
= cert
->pCtlInfo
->NextUpdate
;
1352 static BOOL
CRYPT_GetExpirationFunction(LPCSTR pszObjectOid
,
1353 get_object_expiration_func
*getExpiration
)
1357 if (!HIWORD(pszObjectOid
))
1359 switch (LOWORD(pszObjectOid
))
1361 case LOWORD(CONTEXT_OID_CERTIFICATE
):
1362 *getExpiration
= CRYPT_GetExpirationFromCert
;
1365 case LOWORD(CONTEXT_OID_CRL
):
1366 *getExpiration
= CRYPT_GetExpirationFromCRL
;
1369 case LOWORD(CONTEXT_OID_CTL
):
1370 *getExpiration
= CRYPT_GetExpirationFromCTL
;
1382 /***********************************************************************
1383 * CryptRetrieveObjectByUrlW (CRYPTNET.@)
1385 BOOL WINAPI
CryptRetrieveObjectByUrlW(LPCWSTR pszURL
, LPCSTR pszObjectOid
,
1386 DWORD dwRetrievalFlags
, DWORD dwTimeout
, LPVOID
*ppvObject
,
1387 HCRYPTASYNC hAsyncRetrieve
, PCRYPT_CREDENTIALS pCredentials
, LPVOID pvVerify
,
1388 PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
)
1391 SchemeDllRetrieveEncodedObjectW retrieve
;
1392 ContextDllCreateObjectContext create
;
1393 HCRYPTOIDFUNCADDR hRetrieve
= 0, hCreate
= 0;
1395 TRACE("(%s, %s, %08x, %d, %p, %p, %p, %p, %p)\n", debugstr_w(pszURL
),
1396 debugstr_a(pszObjectOid
), dwRetrievalFlags
, dwTimeout
, ppvObject
,
1397 hAsyncRetrieve
, pCredentials
, pvVerify
, pAuxInfo
);
1401 SetLastError(ERROR_INVALID_PARAMETER
);
1404 ret
= CRYPT_GetRetrieveFunction(pszURL
, &retrieve
, &hRetrieve
);
1406 ret
= CRYPT_GetCreateFunction(pszObjectOid
, &create
, &hCreate
);
1409 CRYPT_BLOB_ARRAY object
= { 0, NULL
};
1410 PFN_FREE_ENCODED_OBJECT_FUNC freeObject
;
1413 ret
= retrieve(pszURL
, pszObjectOid
, dwRetrievalFlags
, dwTimeout
,
1414 &object
, &freeObject
, &freeContext
, hAsyncRetrieve
, pCredentials
,
1418 get_object_expiration_func getExpiration
;
1420 ret
= create(pszObjectOid
, dwRetrievalFlags
, &object
, ppvObject
);
1421 if (ret
&& !(dwRetrievalFlags
& CRYPT_DONT_CACHE_RESULT
) &&
1422 CRYPT_GetExpirationFunction(pszObjectOid
, &getExpiration
))
1426 if (getExpiration(*ppvObject
, &expires
))
1427 CRYPT_CacheURL(pszURL
, &object
, dwRetrievalFlags
, expires
);
1429 freeObject(pszObjectOid
, &object
, freeContext
);
1433 CryptFreeOIDFunctionAddress(hCreate
, 0);
1435 CryptFreeOIDFunctionAddress(hRetrieve
, 0);
1436 TRACE("returning %d\n", ret
);
1440 typedef struct _OLD_CERT_REVOCATION_STATUS
{
1445 } OLD_CERT_REVOCATION_STATUS
, *POLD_CERT_REVOCATION_STATUS
;
1447 /***********************************************************************
1448 * CertDllVerifyRevocation (CRYPTNET.@)
1450 BOOL WINAPI
CertDllVerifyRevocation(DWORD dwEncodingType
, DWORD dwRevType
,
1451 DWORD cContext
, PVOID rgpvContext
[], DWORD dwFlags
,
1452 PCERT_REVOCATION_PARA pRevPara
, PCERT_REVOCATION_STATUS pRevStatus
)
1457 TRACE("(%08x, %d, %d, %p, %08x, %p, %p)\n", dwEncodingType
, dwRevType
,
1458 cContext
, rgpvContext
, dwFlags
, pRevPara
, pRevStatus
);
1460 if (pRevStatus
->cbSize
!= sizeof(OLD_CERT_REVOCATION_STATUS
) &&
1461 pRevStatus
->cbSize
!= sizeof(CERT_REVOCATION_STATUS
))
1463 SetLastError(E_INVALIDARG
);
1466 memset(&pRevStatus
->dwIndex
, 0, pRevStatus
->cbSize
- sizeof(DWORD
));
1467 if (dwRevType
!= CERT_CONTEXT_REVOCATION_TYPE
)
1469 error
= CRYPT_E_NO_REVOCATION_CHECK
;
1475 for (i
= 0; ret
&& i
< cContext
; i
++)
1479 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
1480 rgpvContext
[i
], 0, NULL
, &cbUrlArray
, NULL
, NULL
, NULL
);
1481 if (!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
)
1483 error
= CRYPT_E_NO_REVOCATION_CHECK
;
1484 pRevStatus
->dwIndex
= i
;
1488 CRYPT_URL_ARRAY
*urlArray
= CryptMemAlloc(cbUrlArray
);
1492 DWORD j
, retrievalFlags
= 0, startTime
, endTime
, timeout
;
1494 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
1495 rgpvContext
[i
], 0, urlArray
, &cbUrlArray
, NULL
, NULL
,
1497 if (dwFlags
& CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION
)
1498 retrievalFlags
|= CRYPT_CACHE_ONLY_RETRIEVAL
;
1499 if (dwFlags
& CERT_VERIFY_REV_ACCUMULATIVE_TIMEOUT_FLAG
&&
1500 pRevPara
->cbSize
>= offsetof(CERT_REVOCATION_PARA
,
1501 dwUrlRetrievalTimeout
) + sizeof(DWORD
))
1503 startTime
= GetTickCount();
1504 endTime
= startTime
+ pRevPara
->dwUrlRetrievalTimeout
;
1505 timeout
= pRevPara
->dwUrlRetrievalTimeout
;
1508 endTime
= timeout
= 0;
1509 for (j
= 0; ret
&& j
< urlArray
->cUrl
; j
++)
1513 ret
= CryptRetrieveObjectByUrlW(urlArray
->rgwszUrl
[j
],
1514 CONTEXT_OID_CRL
, retrievalFlags
, timeout
,
1515 (void **)&crl
, NULL
, NULL
, NULL
, NULL
);
1518 PCRL_ENTRY entry
= NULL
;
1520 CertFindCertificateInCRL(
1521 rgpvContext
[i
], crl
, 0, NULL
,
1525 error
= CRYPT_E_REVOKED
;
1526 pRevStatus
->dwIndex
= i
;
1531 DWORD time
= GetTickCount();
1533 if ((int)(endTime
- time
) <= 0)
1535 error
= ERROR_TIMEOUT
;
1536 pRevStatus
->dwIndex
= i
;
1540 timeout
= endTime
- time
;
1542 CertFreeCRLContext(crl
);
1545 error
= CRYPT_E_REVOCATION_OFFLINE
;
1547 CryptMemFree(urlArray
);
1551 error
= ERROR_OUTOFMEMORY
;
1552 pRevStatus
->dwIndex
= i
;
1557 pRevStatus
->dwIndex
= i
;
1563 SetLastError(error
);
1564 pRevStatus
->dwError
= error
;
1566 TRACE("returning %d (%08x)\n", ret
, error
);