23#define NONAMELESSUNION
25#define WIN32_NO_STATUS
28#include "wine/winternl.h"
29#define CRYPT_OID_INFO_HAS_EXTRA_FIELDS
36#include "wine/unicode.h"
162 cert->ctx.hCertStore = store;
178 switch (add_disposition)
204 FIXME(
"Unimplemented add disposition %d\n", add_disposition);
209 switch (add_disposition)
216 TRACE(
"found matching certificate, not adding\n");
225 FIXME(
"CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES: semi-stub for links\n");
227 inherit_props =
TRUE;
231 FIXME(
"CERT_STORE_ADD_USE_EXISTING: semi-stub for links\n");
243 TRACE(
"existing certificate is newer, not adding\n");
253 TRACE(
"existing certificate is newer, not adding\n");
257 inherit_props =
TRUE;
270 (ret_context || inherit_props) ? &new_context :
NULL, use_link);
354 cert->ctx.pCertInfo = certInfo;
388 if (
cert->base.properties)
439 if (
cert->base.properties)
462 cert->ctx.pCertInfo->Subject.pbData,
463 cert->ctx.pCertInfo->Subject.cbData,
468 cert->ctx.pCertInfo->SubjectPublicKeyInfo.PublicKey.pbData,
469 cert->ctx.pCertInfo->SubjectPublicKeyInfo.PublicKey.cbData,
474 cert->ctx.pCertInfo->SerialNumber.pbData,
475 cert->ctx.pCertInfo->SerialNumber.cbData,
493 cert->ctx.pCertInfo->rgExtension);
525 DWORD i, containerLen, provNameLen;
530 data += containerLen;
536 if (
info->cProvParam)
541 for (
i = 0;
i <
info->cProvParam;
i++)
614 if (
from->pwszContainerName)
622 if (
from->pwszProvName)
642 from->rgProvParam[
i].cbData);
643 nextData +=
from->rgProvParam[
i].cbData;
654 if (
info->pwszContainerName)
658 if (
info->pwszProvName)
662 size += containerSize + provNameSize;
663 for (
i = 0;
i <
info->cProvParam;
i++)
685 if (!
cert->base.properties)
748 (
const BYTE *)keyContext, keyContext->
cbSize);
778 keyContext.
cbSize =
sizeof(keyContext);
860 info->pwszProvName,
info->dwProvType, 0);
865 for (
i = 0;
i <
info->cProvParam;
i++)
868 info->rgProvParam[
i].dwParam,
info->rgProvParam[
i].pbData,
869 info->rgProvParam[
i].dwFlags);
871 *pdwKeySpec =
info->dwKeySpec;
883 DWORD *pdwKeySpec,
BOOL *pfCallerFreeProv)
891 phCryptProv, pdwKeySpec, pfCallerFreeProv);
913 size =
sizeof(keyContext);
921 if (pfCallerFreeProv)
922 *pfCallerFreeProv = !
cache;
936 keyContext.
cbSize =
sizeof(keyContext);
940 if (pfCallerFreeProv)
941 *pfCallerFreeProv =
FALSE;
946 if (pfCallerFreeProv)
947 *pfCallerFreeProv =
TRUE;
1006 copy = *keyProvInfo;
1007 copy.pwszContainerName = containerW;
1044 while (
ret && !found)
1049 (
BYTE *)containerA, &
size, enumFlags);
1054 enumFlags &= ~CRYPT_FIRST;
1071 memset(&keyProvInfo, 0,
sizeof(keyProvInfo));
1072 while (
ret && !found)
1080 if (
size <= cbProvName)
1110 keyProvInfo.
dwFlags &= ~CRYPT_USER_KEYSET;
1227 TRACE(
"(%p, %p)\n", pInt1, pInt2);
1290 *pk2 = (
LPVOID)(pblob2 + 1);
1320 FIXME(
"unimplemented for DH public keys\n");
1466 switch (
id->dwIdChoice)
1473 &
id->u.IssuerSerialNumber.SerialNumber);
1580 subject->pCertInfo->cExtension, subject->pCertInfo->rgExtension)))
1592 if (
info->CertIssuer.cbData &&
info->CertSerialNumber.cbData)
1595 memcpy(&
id.
u.IssuerSerialNumber.Issuer, &
info->CertIssuer,
1597 memcpy(&
id.
u.IssuerSerialNumber.SerialNumber,
1600 else if (
info->KeyId.cbData)
1614 subject->pCertInfo->cExtension, subject->pCertInfo->rgExtension)))
1626 if (
info->AuthorityCertIssuer.cAltEntry &&
1627 info->AuthorityCertSerialNumber.cbData)
1632 for (
i = 0; !directoryName &&
1633 i <
info->AuthorityCertIssuer.cAltEntry;
i++)
1634 if (
info->AuthorityCertIssuer.rgAltEntry[
i].dwAltNameChoice
1637 &
info->AuthorityCertIssuer.rgAltEntry[
i];
1641 memcpy(&
id.
u.IssuerSerialNumber.Issuer,
1643 memcpy(&
id.
u.IssuerSerialNumber.SerialNumber,
1644 &
info->AuthorityCertSerialNumber,
1649 FIXME(
"no supported name type in authority key id2\n");
1653 else if (
info->KeyId.cbData)
1669 dwFlags, &subject->pCertInfo->Issuer);
1815 FIXME(
"find type %08x unimplemented\n", dwType);
1851 if (*pdwFlags & ~supportedFlags)
1875 *pdwFlags &= ~CERT_STORE_TIME_VALIDITY_FLAG;
1882 *pdwFlags &= ~CERT_STORE_SIGNATURE_FLAG;
1893 TRACE(
"(%p, %p, %p, %08x)\n", hCertStore, pSubjectContext,
1894 pPrevIssuerContext, *pdwFlags);
1896 if (!pSubjectContext)
1904 pSubjectContext, pPrevIssuerContext);
1941 cContext, rgpvContext,
dwFlags, pRevPara, pRevStatus);
1986 rgpvContext,
dwFlags, pRevPara, pRevStatus);
2022 for (
i = 0; !
ret &&
i < cAttr;
i++)
2023 if (rgAttr[
i].pszObjId && !
strcmp(pszObjId, rgAttr[
i].pszObjId))
2044 for (
i = 0; !
ret &&
i < cExtensions;
i++)
2045 if (rgExtensions[
i].pszObjId && !
strcmp(pszObjId,
2046 rgExtensions[
i].pszObjId))
2047 ret = &rgExtensions[
i];
2066 if (
pName->rgRDN[
i].rgRDNAttr[
j].pszObjId && !
strcmp(pszObjId,
2067 pName->rgRDN[
i].rgRDNAttr[
j].pszObjId))
2080 for (
j = 0;
j <
name->rgRDN[
i].cRDNAttr;
j++)
2084 name->rgRDN[
i].rgRDNAttr[
j].dwValueType ==
2093 if (
attr->Value.cbData !=
2094 name->rgRDN[
i].rgRDNAttr[
j].Value.cbData)
2102 TRACE(
"%s : %s => %d\n",
2113 if (
attr->Value.cbData !=
2114 name->rgRDN[
i].rgRDNAttr[
j].Value.cbData)
2118 attr->Value.cbData);
2121 TRACE(
"%s : %s => %d\n",
2167 pTimeToVerify = &fileTime;
2181 TRACE(
"(%p, %p)\n", pSubjectInfo, pIssuerInfo);
2189 DWORD *pcbComputedHash)
2194 TRACE(
"(%08lx, %d, %08x, %p, %d, %p, %p)\n", hCryptProv, Algid,
dwFlags,
2195 pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash);
2209 pcbComputedHash, 0);
2218 BYTE *pbComputedHash,
DWORD *pcbComputedHash)
2223 TRACE(
"(%08lx, %d, %08x, %d, %p, %p, %p)\n", hCryptProv, Algid,
dwFlags,
2251 pcbComputedHash, 0);
2262 BYTE *pbComputedHash,
DWORD *pcbComputedHash)
2269 pbEncoded, cbEncoded, pbComputedHash, *pcbComputedHash);
2281 info->SignatureAlgorithm.pszObjId, 0);
2293 info->ToBeSigned.cbData, 0);
2296 pcbComputedHash, 0);
2308 const void *pvHashAuxInfo,
BYTE *pbSignature,
DWORD *pcbSignature)
2314 TRACE(
"(%08lx, %d, %d, %p, %d, %p, %p, %p, %p)\n", hCryptProv,
2316 pSignatureAlgorithm, pvHashAuxInfo, pbSignature, pcbSignature);
2333 cbEncodedToBeSigned, 0);
2353 cbEncodedToBeSigned, 0);
2370 DWORD encodedSize, hashSize;
2372 TRACE(
"(%08lx, %d, %d, %s, %p, %p, %p, %p, %p)\n", hCryptProv, dwKeySpec,
2377 NULL, &encodedSize);
2385 pvStructInfo, encoded, &encodedSize);
2390 pvHashAuxInfo,
NULL, &hashSize);
2399 pSignatureAlgorithm, pvHashAuxInfo,
hash, &hashSize);
2404 info.ToBeSigned.cbData = encodedSize;
2405 info.ToBeSigned.pbData = encoded;
2406 info.SignatureAlgorithm = *pSignatureAlgorithm;
2407 info.Signature.cbData = hashSize;
2409 info.Signature.cUnusedBits = 0;
2445 hashID =
info->u.Algid;
2446 if (
info->ExtraInfo.cbData >=
sizeof(
ALG_ID))
2447 pubKeyID = *(
ALG_ID *)
info->ExtraInfo.pbData;
2454 pubKeyInfo, pubKeyID, 0,
NULL, &
key);
2518 const WCHAR *sign_algo;
2551 FIXME(
"Unsupported ecc curve type: %s\n", *ecc_curve);
2668 BYTE *hash_value =
NULL, *sig_value;
2669 DWORD hash_len, sig_len;
2685 FIXME(
"Failed to verify signature: %08x\n",
status);
2724 TRACE(
"(%08lx, %d, %d, %p, %d, %p, %08x, %p)\n", hCryptProv,
2728 switch (dwSubjectType)
2767 &signedCert, &
size);
2770 switch (dwIssuerType)
2784 FIXME(
"CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN: stub\n");
2795 FIXME(
"unimplemented for NULL signer\n");
2831 if (cbKeyUsage <
usage.cbData)
2836 if (cbKeyUsage >
usage.cbData)
2838 cbKeyUsage -
usage.cbData);
2915 *pcbUsage = bytesNeeded;
2916 else if (*pcbUsage < bytesNeeded)
2919 *pcbUsage = bytesNeeded;
2924 *pcbUsage = bytesNeeded;
2935 for (
i = 0;
i <
usage->cUsageIdentifier;
i++)
2939 nextOID +=
strlen(nextOID) + 1;
2979 LPCSTR pszUsageIdentifier)
3001 for (
i = 0; !exists &&
i <
usage->cUsageIdentifier;
i++)
3004 pszUsageIdentifier))
3019 + (
usage->cUsageIdentifier + 1) *
sizeof(
LPSTR));
3020 for (
i = 0;
i <
usage->cUsageIdentifier;
i++)
3024 nextOID +=
strlen(nextOID) + 1;
3027 strcpy(nextOID, pszUsageIdentifier);
3048 usage->rgpszUsageIdentifier =
3052 strcpy(
usage->rgpszUsageIdentifier[0], pszUsageIdentifier);
3053 usage->cUsageIdentifier = 1;
3064 LPCSTR pszUsageIdentifier)
3093 pszUsageIdentifier))
3095 if (found && i < pUsage->cUsageIdentifier - 1)
3126#define BITS_PER_DWORD (sizeof(DWORD) * 8)
3132 if (indexIndex + 1 >
field->cIndexes)
3134 if (
field->cIndexes)
3136 (indexIndex + 1) *
sizeof(
DWORD));
3141 field->indexes[indexIndex] = 0;
3142 field->cIndexes = indexIndex + 1;
3167 TRACE(
"(%d, %p, %d, %p, %d)\n", cCerts, rghCerts, *
cNumOIDs,
3170 for (
i = 0;
i < cCerts;
i++)
3181 allUsagesValid =
FALSE;
3246 -
j - 1) *
sizeof(
LPSTR));
3402 blob->pbData,
blob->cbData, sigAlgo,
NULL, sig, &sigSize);
3407 DWORD encodedSignedCertSize = 0;
3417 &encodedSignedCert, &encodedSignedCertSize);
3421 encodedSignedCert, encodedSignedCertSize);
3452 assert(pSubjectIssuerBlob);
3459 info->SerialNumber.cbData = pSerialNumber->
cbData;
3460 info->SerialNumber.pbData = pSerialNumber->
pbData;
3461 if (pSignatureAlgorithm)
3462 info->SignatureAlgorithm = *pSignatureAlgorithm;
3465 info->SignatureAlgorithm.pszObjId = oid;
3466 info->SignatureAlgorithm.Parameters.cbData = 0;
3467 info->SignatureAlgorithm.Parameters.pbData =
NULL;
3469 info->Issuer.cbData = pSubjectIssuerBlob->
cbData;
3470 info->Issuer.pbData = pSubjectIssuerBlob->
pbData;
3487 info->Subject.cbData = pSubjectIssuerBlob->
cbData;
3488 info->Subject.pbData = pSubjectIssuerBlob->
pbData;
3497 info->cExtension = 0;
3518 rpcrt,
"RpcStringFreeA");
3520 if (uuidCreate && uuidToString && rpcStringFree)
3527 unsigned char *uuidStr;
3543 rpcStringFree(&uuidStr);
3561 DWORD pubKeySize = 0, dwKeySpec;
3563 TRACE(
"(%08lx, %p, %08x, %p, %p, %p, %p, %p)\n",
hProv,
3564 pSubjectIssuerBlob,
dwFlags, pKeyProvInfo, pSignatureAlgorithm, pStartTime,
3565 pExtensions, pExtensions);
3567 if(!pSubjectIssuerBlob)
3579 releaseContext =
TRUE;
3620 releaseContext =
TRUE;
3642 pSignatureAlgorithm, pStartTime, pEndTime,
pubKey, pExtensions);
3650 &
info.SignatureAlgorithm);
3673 dwSubjectType, pvSubject, pSubjectUsage,
dwFlags, pVerifyUsagePara,
3674 pVerifyUsageStatus);
3693 FIXME(
"pCreatePara not handled\n");
3697 switch (dwContextType)
3706 WARN(
"unknown context type: 0x%x\n", dwContextType);
int strcmp(const char *String1, const char *String2)
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
ACPI_SIZE strlen(const char *String)
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
char * strcpy(char *DstString, const char *SrcString)
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
#define BCRYPT_ECDSA_PUBLIC_P256_MAGIC
NTSTATUS WINAPI BCryptDestroyKey(BCRYPT_KEY_HANDLE)
#define BCRYPT_ECDSA_P384_ALGORITHM
#define BCRYPT_ECCPUBLIC_BLOB
#define BCRYPT_ECDSA_PUBLIC_P384_MAGIC
NTSTATUS WINAPI BCryptVerifySignature(BCRYPT_KEY_HANDLE, void *, UCHAR *, ULONG, UCHAR *, ULONG, ULONG)
struct _BCRYPT_ECCKEY_BLOB BCRYPT_ECCKEY_BLOB
#define BCRYPT_ECDSA_P256_ALGORITHM
#define BCRYPT_HASH_LENGTH
NTSTATUS WINAPI BCryptImportKeyPair(BCRYPT_ALG_HANDLE, BCRYPT_KEY_HANDLE, LPCWSTR, BCRYPT_KEY_HANDLE *, UCHAR *, ULONG, ULONG)
NTSTATUS WINAPI BCryptHashData(BCRYPT_HASH_HANDLE handle, UCHAR *input, ULONG size, ULONG flags)
NTSTATUS WINAPI BCryptGetProperty(BCRYPT_HANDLE handle, LPCWSTR prop, UCHAR *buffer, ULONG count, ULONG *res, ULONG flags)
NTSTATUS WINAPI BCryptDestroyHash(BCRYPT_HASH_HANDLE handle)
NTSTATUS WINAPI BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE *handle, LPCWSTR id, LPCWSTR implementation, DWORD flags)
NTSTATUS WINAPI BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE handle, DWORD flags)
NTSTATUS WINAPI BCryptCreateHash(BCRYPT_ALG_HANDLE algorithm, BCRYPT_HASH_HANDLE *handle, UCHAR *object, ULONG objectlen, UCHAR *secret, ULONG secretlen, ULONG flags)
NTSTATUS WINAPI BCryptFinishHash(BCRYPT_HASH_HANDLE handle, UCHAR *output, ULONG size, ULONG flags)
BOOL WINAPI CryptDecodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
BOOL WINAPI CryptDecodeObject(DWORD dwCertEncodingType, LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo)
static void * context_ptr(context_t *context)
DWORD ContextPropertyList_EnumPropIDs(CONTEXT_PROPERTY_LIST *list, DWORD id) DECLSPEC_HIDDEN
BOOL ContextPropertyList_FindProperty(CONTEXT_PROPERTY_LIST *list, DWORD id, PCRYPT_DATA_BLOB blob) DECLSPEC_HIDDEN
#define CERT_CERT_PROP_ID
#define WINE_CRYPTCERTSTORE_MAGIC
HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(ALG_ID)
static context_t * context_from_ptr(const void *ptr)
BOOL ContextPropertyList_SetProperty(CONTEXT_PROPERTY_LIST *list, DWORD id, const BYTE *pbData, size_t cbData) DECLSPEC_HIDDEN