2008-08-29 16:29:00 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Juan Lang
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wincrypt.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "crypt32_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
|
|
|
|
2013-10-14 14:47:30 +02:00
|
|
|
static void CTL_free(context_t *context)
|
|
|
|
{
|
|
|
|
ctl_t *ctl = (ctl_t*)context;
|
|
|
|
|
|
|
|
CryptMsgClose(ctl->ctx.hCryptMsg);
|
|
|
|
CryptMemFree(ctl->ctx.pbCtlEncoded);
|
|
|
|
CryptMemFree(ctl->ctx.pbCtlContext);
|
|
|
|
LocalFree(ctl->ctx.pCtlInfo);
|
|
|
|
}
|
|
|
|
|
2013-10-17 11:06:44 +02:00
|
|
|
static context_t *CTL_clone(context_t *context, WINECRYPT_CERTSTORE *store, BOOL use_link)
|
2013-10-15 16:53:54 +02:00
|
|
|
{
|
|
|
|
ctl_t *ctl;
|
|
|
|
|
2013-10-17 11:06:44 +02:00
|
|
|
if(!use_link) {
|
|
|
|
FIXME("Only links supported\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-18 10:50:43 +02:00
|
|
|
ctl = (ctl_t*)Context_CreateLinkContext(sizeof(CTL_CONTEXT), context, store);
|
2013-10-15 16:53:54 +02:00
|
|
|
if(!ctl)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ctl->ctx.hCertStore = store;
|
|
|
|
return &ctl->base;
|
|
|
|
}
|
|
|
|
|
2013-10-14 14:47:30 +02:00
|
|
|
static const context_vtbl_t ctl_vtbl = {
|
2013-10-15 16:53:54 +02:00
|
|
|
CTL_free,
|
|
|
|
CTL_clone
|
2013-10-14 14:47:30 +02:00
|
|
|
};
|
|
|
|
|
2008-08-29 16:59:37 +02:00
|
|
|
BOOL WINAPI CertAddCTLContextToStore(HCERTSTORE hCertStore,
|
|
|
|
PCCTL_CONTEXT pCtlContext, DWORD dwAddDisposition,
|
|
|
|
PCCTL_CONTEXT* ppStoreContext)
|
|
|
|
{
|
2013-09-04 12:38:51 +02:00
|
|
|
WINECRYPT_CERTSTORE *store = hCertStore;
|
2008-08-29 16:59:37 +02:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
PCCTL_CONTEXT toAdd = NULL, existing = NULL;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %08x, %p)\n", hCertStore, pCtlContext, dwAddDisposition,
|
|
|
|
ppStoreContext);
|
|
|
|
|
|
|
|
if (dwAddDisposition != CERT_STORE_ADD_ALWAYS)
|
|
|
|
{
|
|
|
|
existing = CertFindCTLInStore(hCertStore, 0, 0, CTL_FIND_EXISTING,
|
|
|
|
pCtlContext, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dwAddDisposition)
|
|
|
|
{
|
|
|
|
case CERT_STORE_ADD_ALWAYS:
|
|
|
|
toAdd = CertDuplicateCTLContext(pCtlContext);
|
|
|
|
break;
|
|
|
|
case CERT_STORE_ADD_NEW:
|
|
|
|
if (existing)
|
|
|
|
{
|
|
|
|
TRACE("found matching CTL, not adding\n");
|
|
|
|
SetLastError(CRYPT_E_EXISTS);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
toAdd = CertDuplicateCTLContext(pCtlContext);
|
|
|
|
break;
|
|
|
|
case CERT_STORE_ADD_NEWER:
|
|
|
|
if (existing)
|
|
|
|
{
|
|
|
|
LONG newer = CompareFileTime(&existing->pCtlInfo->ThisUpdate,
|
|
|
|
&pCtlContext->pCtlInfo->ThisUpdate);
|
|
|
|
|
|
|
|
if (newer < 0)
|
|
|
|
toAdd = CertDuplicateCTLContext(pCtlContext);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("existing CTL is newer, not adding\n");
|
|
|
|
SetLastError(CRYPT_E_EXISTS);
|
|
|
|
ret = FALSE;
|
2008-12-22 19:55:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
toAdd = CertDuplicateCTLContext(pCtlContext);
|
|
|
|
break;
|
|
|
|
case CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES:
|
|
|
|
if (existing)
|
|
|
|
{
|
|
|
|
LONG newer = CompareFileTime(&existing->pCtlInfo->ThisUpdate,
|
|
|
|
&pCtlContext->pCtlInfo->ThisUpdate);
|
|
|
|
|
|
|
|
if (newer < 0)
|
|
|
|
{
|
|
|
|
toAdd = CertDuplicateCTLContext(pCtlContext);
|
2013-10-08 16:24:44 +02:00
|
|
|
Context_CopyProperties(existing, pCtlContext);
|
2008-12-22 19:55:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("existing CTL is newer, not adding\n");
|
|
|
|
SetLastError(CRYPT_E_EXISTS);
|
|
|
|
ret = FALSE;
|
2008-08-29 16:59:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
toAdd = CertDuplicateCTLContext(pCtlContext);
|
|
|
|
break;
|
|
|
|
case CERT_STORE_ADD_REPLACE_EXISTING:
|
|
|
|
toAdd = CertDuplicateCTLContext(pCtlContext);
|
|
|
|
break;
|
|
|
|
case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES:
|
|
|
|
toAdd = CertDuplicateCTLContext(pCtlContext);
|
|
|
|
if (existing)
|
2013-10-08 16:24:44 +02:00
|
|
|
Context_CopyProperties(toAdd, existing);
|
2008-08-29 16:59:37 +02:00
|
|
|
break;
|
|
|
|
case CERT_STORE_ADD_USE_EXISTING:
|
|
|
|
if (existing)
|
2009-12-10 18:06:39 +01:00
|
|
|
{
|
2013-10-08 16:24:44 +02:00
|
|
|
Context_CopyProperties(existing, pCtlContext);
|
2009-12-10 18:06:39 +01:00
|
|
|
if (ppStoreContext)
|
|
|
|
*ppStoreContext = CertDuplicateCTLContext(existing);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
toAdd = CertDuplicateCTLContext(pCtlContext);
|
2008-08-29 16:59:37 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unimplemented add disposition %d\n", dwAddDisposition);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toAdd)
|
|
|
|
{
|
2013-10-17 11:08:15 +02:00
|
|
|
if (store) {
|
|
|
|
context_t *ret_ctx;
|
|
|
|
|
|
|
|
ret = store->vtbl->ctls.addContext(store, context_from_ptr(toAdd),
|
|
|
|
existing ? context_from_ptr(existing) : NULL, ppStoreContext ? &ret_ctx : NULL, TRUE);
|
|
|
|
if(ret && ppStoreContext)
|
|
|
|
*ppStoreContext = context_ptr(ret_ctx);
|
|
|
|
}else if (ppStoreContext) {
|
2008-08-29 16:59:37 +02:00
|
|
|
*ppStoreContext = CertDuplicateCTLContext(toAdd);
|
2013-10-17 11:08:15 +02:00
|
|
|
}
|
2008-08-29 16:59:37 +02:00
|
|
|
CertFreeCTLContext(toAdd);
|
|
|
|
}
|
|
|
|
CertFreeCTLContext(existing);
|
|
|
|
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-29 16:31:16 +02:00
|
|
|
BOOL WINAPI CertAddEncodedCTLToStore(HCERTSTORE hCertStore,
|
|
|
|
DWORD dwMsgAndCertEncodingType, const BYTE *pbCtlEncoded, DWORD cbCtlEncoded,
|
|
|
|
DWORD dwAddDisposition, PCCTL_CONTEXT *ppCtlContext)
|
|
|
|
{
|
|
|
|
PCCTL_CONTEXT ctl = CertCreateCTLContext(dwMsgAndCertEncodingType,
|
|
|
|
pbCtlEncoded, cbCtlEncoded);
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(%p, %08x, %p, %d, %08x, %p)\n", hCertStore,
|
|
|
|
dwMsgAndCertEncodingType, pbCtlEncoded, cbCtlEncoded, dwAddDisposition,
|
|
|
|
ppCtlContext);
|
|
|
|
|
|
|
|
if (ctl)
|
|
|
|
{
|
|
|
|
ret = CertAddCTLContextToStore(hCertStore, ctl, dwAddDisposition,
|
|
|
|
ppCtlContext);
|
|
|
|
CertFreeCTLContext(ctl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-17 11:07:55 +02:00
|
|
|
PCCTL_CONTEXT WINAPI CertEnumCTLsInStore(HCERTSTORE hCertStore, PCCTL_CONTEXT pPrev)
|
2008-08-29 16:34:07 +02:00
|
|
|
{
|
2013-10-17 11:07:55 +02:00
|
|
|
ctl_t *prev = pPrev ? ctl_from_ptr(pPrev) : NULL, *ret;
|
2009-01-26 11:01:47 +01:00
|
|
|
WINECRYPT_CERTSTORE *hcs = hCertStore;
|
2008-08-29 16:34:07 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", hCertStore, pPrev);
|
|
|
|
if (!hCertStore)
|
|
|
|
ret = NULL;
|
|
|
|
else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
|
|
|
|
ret = NULL;
|
|
|
|
else
|
2013-10-17 11:07:55 +02:00
|
|
|
ret = (ctl_t*)hcs->vtbl->ctls.enumContext(hcs, prev ? &prev->base : NULL);
|
|
|
|
return ret ? &ret->ctx : NULL;
|
2008-08-29 16:34:07 +02:00
|
|
|
}
|
|
|
|
|
2008-08-29 16:57:19 +02:00
|
|
|
typedef BOOL (*CtlCompareFunc)(PCCTL_CONTEXT pCtlContext, DWORD dwType,
|
|
|
|
DWORD dwFlags, const void *pvPara);
|
|
|
|
|
|
|
|
static BOOL compare_ctl_any(PCCTL_CONTEXT pCtlContext, DWORD dwType,
|
|
|
|
DWORD dwFlags, const void *pvPara)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL compare_ctl_by_md5_hash(PCCTL_CONTEXT pCtlContext, DWORD dwType,
|
|
|
|
DWORD dwFlags, const void *pvPara)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
BYTE hash[16];
|
|
|
|
DWORD size = sizeof(hash);
|
|
|
|
|
|
|
|
ret = CertGetCTLContextProperty(pCtlContext, CERT_MD5_HASH_PROP_ID, hash,
|
|
|
|
&size);
|
|
|
|
if (ret)
|
|
|
|
{
|
2009-01-26 11:01:47 +01:00
|
|
|
const CRYPT_HASH_BLOB *pHash = pvPara;
|
2008-08-29 16:57:19 +02:00
|
|
|
|
|
|
|
if (size == pHash->cbData)
|
|
|
|
ret = !memcmp(pHash->pbData, hash, size);
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL compare_ctl_by_sha1_hash(PCCTL_CONTEXT pCtlContext, DWORD dwType,
|
|
|
|
DWORD dwFlags, const void *pvPara)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
BYTE hash[20];
|
|
|
|
DWORD size = sizeof(hash);
|
|
|
|
|
|
|
|
ret = CertGetCTLContextProperty(pCtlContext, CERT_SHA1_HASH_PROP_ID, hash,
|
|
|
|
&size);
|
|
|
|
if (ret)
|
|
|
|
{
|
2009-01-26 11:01:47 +01:00
|
|
|
const CRYPT_HASH_BLOB *pHash = pvPara;
|
2008-08-29 16:57:19 +02:00
|
|
|
|
|
|
|
if (size == pHash->cbData)
|
|
|
|
ret = !memcmp(pHash->pbData, hash, size);
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL compare_ctl_existing(PCCTL_CONTEXT pCtlContext, DWORD dwType,
|
|
|
|
DWORD dwFlags, const void *pvPara)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (pvPara)
|
|
|
|
{
|
2009-01-26 11:01:47 +01:00
|
|
|
PCCTL_CONTEXT ctl = pvPara;
|
2008-08-29 16:57:19 +02:00
|
|
|
|
|
|
|
if (pCtlContext->cbCtlContext == ctl->cbCtlContext)
|
|
|
|
{
|
|
|
|
if (ctl->cbCtlContext)
|
|
|
|
ret = !memcmp(pCtlContext->pbCtlContext, ctl->pbCtlContext,
|
|
|
|
ctl->cbCtlContext);
|
|
|
|
else
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCCTL_CONTEXT WINAPI CertFindCTLInStore(HCERTSTORE hCertStore,
|
|
|
|
DWORD dwCertEncodingType, DWORD dwFindFlags, DWORD dwFindType,
|
|
|
|
const void *pvFindPara, PCCTL_CONTEXT pPrevCtlContext)
|
|
|
|
{
|
|
|
|
PCCTL_CONTEXT ret;
|
|
|
|
CtlCompareFunc compare;
|
|
|
|
|
|
|
|
TRACE("(%p, %d, %d, %d, %p, %p)\n", hCertStore, dwCertEncodingType,
|
|
|
|
dwFindFlags, dwFindType, pvFindPara, pPrevCtlContext);
|
|
|
|
|
|
|
|
switch (dwFindType)
|
|
|
|
{
|
|
|
|
case CTL_FIND_ANY:
|
|
|
|
compare = compare_ctl_any;
|
|
|
|
break;
|
|
|
|
case CTL_FIND_SHA1_HASH:
|
|
|
|
compare = compare_ctl_by_sha1_hash;
|
|
|
|
break;
|
|
|
|
case CTL_FIND_MD5_HASH:
|
|
|
|
compare = compare_ctl_by_md5_hash;
|
|
|
|
break;
|
|
|
|
case CTL_FIND_EXISTING:
|
|
|
|
compare = compare_ctl_existing;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("find type %08x unimplemented\n", dwFindType);
|
|
|
|
compare = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compare)
|
|
|
|
{
|
|
|
|
BOOL matches = FALSE;
|
|
|
|
|
|
|
|
ret = pPrevCtlContext;
|
|
|
|
do {
|
|
|
|
ret = CertEnumCTLsInStore(hCertStore, ret);
|
|
|
|
if (ret)
|
|
|
|
matches = compare(ret, dwFindType, dwFindFlags, pvFindPara);
|
|
|
|
} while (ret != NULL && !matches);
|
|
|
|
if (!ret)
|
|
|
|
SetLastError(CRYPT_E_NOT_FOUND);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(CRYPT_E_NOT_FOUND);
|
|
|
|
ret = NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-29 16:34:33 +02:00
|
|
|
BOOL WINAPI CertDeleteCTLFromStore(PCCTL_CONTEXT pCtlContext)
|
|
|
|
{
|
2013-10-26 10:33:23 +02:00
|
|
|
WINECRYPT_CERTSTORE *hcs;
|
2013-10-21 15:59:11 +02:00
|
|
|
ctl_t *ctl = ctl_from_ptr(pCtlContext);
|
2008-08-29 16:34:33 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", pCtlContext);
|
|
|
|
|
|
|
|
if (!pCtlContext)
|
2013-10-21 15:59:11 +02:00
|
|
|
return TRUE;
|
2008-08-29 16:34:33 +02:00
|
|
|
|
2013-10-26 10:33:23 +02:00
|
|
|
hcs = pCtlContext->hCertStore;
|
|
|
|
|
2013-10-21 15:59:11 +02:00
|
|
|
if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ret = hcs->vtbl->ctls.delete(hcs, &ctl->base);
|
|
|
|
if (ret)
|
|
|
|
ret = CertFreeCTLContext(pCtlContext);
|
2008-08-29 16:34:33 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-29 16:29:00 +02:00
|
|
|
PCCTL_CONTEXT WINAPI CertCreateCTLContext(DWORD dwMsgAndCertEncodingType,
|
|
|
|
const BYTE *pbCtlEncoded, DWORD cbCtlEncoded)
|
|
|
|
{
|
2013-10-21 15:58:56 +02:00
|
|
|
ctl_t *ctl = NULL;
|
2008-08-29 16:29:00 +02:00
|
|
|
HCRYPTMSG msg;
|
|
|
|
BOOL ret;
|
|
|
|
BYTE *content = NULL;
|
|
|
|
DWORD contentSize = 0, size;
|
|
|
|
PCTL_INFO ctlInfo = NULL;
|
|
|
|
|
|
|
|
TRACE("(%08x, %p, %d)\n", dwMsgAndCertEncodingType, pbCtlEncoded,
|
|
|
|
cbCtlEncoded);
|
|
|
|
|
|
|
|
if (GET_CERT_ENCODING_TYPE(dwMsgAndCertEncodingType) != X509_ASN_ENCODING)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!pbCtlEncoded || !cbCtlEncoded)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, 0, 0,
|
|
|
|
0, NULL, NULL);
|
|
|
|
if (!msg)
|
|
|
|
return NULL;
|
|
|
|
ret = CryptMsgUpdate(msg, pbCtlEncoded, cbCtlEncoded, TRUE);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
/* Check that it's really a CTL */
|
|
|
|
ret = CryptMsgGetParam(msg, CMSG_INNER_CONTENT_TYPE_PARAM, 0, NULL, &size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
char *innerContent = CryptMemAlloc(size);
|
|
|
|
|
|
|
|
if (innerContent)
|
|
|
|
{
|
|
|
|
ret = CryptMsgGetParam(msg, CMSG_INNER_CONTENT_TYPE_PARAM, 0,
|
|
|
|
innerContent, &size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (strcmp(innerContent, szOID_CTL))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CryptMemFree(innerContent);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
goto end;
|
|
|
|
ret = CryptMsgGetParam(msg, CMSG_CONTENT_PARAM, 0, NULL, &contentSize);
|
|
|
|
if (!ret)
|
|
|
|
goto end;
|
|
|
|
content = CryptMemAlloc(contentSize);
|
|
|
|
if (content)
|
|
|
|
{
|
|
|
|
ret = CryptMsgGetParam(msg, CMSG_CONTENT_PARAM, 0, content,
|
|
|
|
&contentSize);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
ret = CryptDecodeObjectEx(dwMsgAndCertEncodingType, PKCS_CTL,
|
|
|
|
content, contentSize, CRYPT_DECODE_ALLOC_FLAG, NULL,
|
2009-01-26 11:01:47 +01:00
|
|
|
&ctlInfo, &size);
|
2008-08-29 16:29:00 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
2013-10-21 15:58:56 +02:00
|
|
|
ctl = (ctl_t*)Context_CreateDataContext(sizeof(CTL_CONTEXT), &ctl_vtbl, &empty_store);
|
2008-08-29 16:29:00 +02:00
|
|
|
if (ctl)
|
|
|
|
{
|
|
|
|
BYTE *data = CryptMemAlloc(cbCtlEncoded);
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
memcpy(data, pbCtlEncoded, cbCtlEncoded);
|
2013-10-21 15:58:56 +02:00
|
|
|
ctl->ctx.dwMsgAndCertEncodingType =
|
2008-08-29 16:29:00 +02:00
|
|
|
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
|
2013-10-21 15:58:56 +02:00
|
|
|
ctl->ctx.pbCtlEncoded = data;
|
|
|
|
ctl->ctx.cbCtlEncoded = cbCtlEncoded;
|
|
|
|
ctl->ctx.pCtlInfo = ctlInfo;
|
|
|
|
ctl->ctx.hCertStore = &empty_store;
|
|
|
|
ctl->ctx.hCryptMsg = msg;
|
|
|
|
ctl->ctx.pbCtlContext = content;
|
|
|
|
ctl->ctx.cbCtlContext = contentSize;
|
2008-08-29 16:29:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (!ret)
|
|
|
|
{
|
2013-10-21 15:58:56 +02:00
|
|
|
if(ctl)
|
|
|
|
Context_Release(&ctl->base);
|
2008-08-29 16:29:00 +02:00
|
|
|
ctl = NULL;
|
|
|
|
LocalFree(ctlInfo);
|
|
|
|
CryptMemFree(content);
|
|
|
|
CryptMsgClose(msg);
|
2013-10-21 15:58:56 +02:00
|
|
|
return NULL;
|
2008-08-29 16:29:00 +02:00
|
|
|
}
|
2013-10-21 15:58:56 +02:00
|
|
|
return &ctl->ctx;
|
2008-08-29 16:29:00 +02:00
|
|
|
}
|
|
|
|
|
2008-08-29 16:30:45 +02:00
|
|
|
PCCTL_CONTEXT WINAPI CertDuplicateCTLContext(PCCTL_CONTEXT pCtlContext)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", pCtlContext);
|
2009-10-20 18:54:56 +02:00
|
|
|
if (pCtlContext)
|
2013-10-14 14:47:07 +02:00
|
|
|
Context_AddRef(&ctl_from_ptr(pCtlContext)->base);
|
2008-08-29 16:30:45 +02:00
|
|
|
return pCtlContext;
|
|
|
|
}
|
|
|
|
|
2008-08-29 16:29:00 +02:00
|
|
|
BOOL WINAPI CertFreeCTLContext(PCCTL_CONTEXT pCTLContext)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", pCTLContext);
|
|
|
|
|
|
|
|
if (pCTLContext)
|
2013-10-18 10:50:23 +02:00
|
|
|
Context_Release(&ctl_from_ptr(pCTLContext)->base);
|
|
|
|
return TRUE;
|
2008-08-29 16:29:00 +02:00
|
|
|
}
|
2008-08-29 16:30:19 +02:00
|
|
|
|
|
|
|
DWORD WINAPI CertEnumCTLContextProperties(PCCTL_CONTEXT pCTLContext,
|
|
|
|
DWORD dwPropId)
|
|
|
|
{
|
2013-10-17 11:07:24 +02:00
|
|
|
ctl_t *ctl = ctl_from_ptr(pCTLContext);
|
2008-08-29 16:30:19 +02:00
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
TRACE("(%p, %d)\n", pCTLContext, dwPropId);
|
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
if (ctl->base.properties)
|
|
|
|
ret = ContextPropertyList_EnumPropIDs(ctl->base.properties, dwPropId);
|
2008-08-29 16:30:19 +02:00
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
static BOOL CTLContext_SetProperty(ctl_t *ctl, DWORD dwPropId,
|
2008-08-29 16:30:19 +02:00
|
|
|
DWORD dwFlags, const void *pvData);
|
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
static BOOL CTLContext_GetHashProp(ctl_t *ctl, DWORD dwPropId,
|
2008-08-29 16:30:19 +02:00
|
|
|
ALG_ID algID, const BYTE *toHash, DWORD toHashLen, void *pvData,
|
|
|
|
DWORD *pcbData)
|
|
|
|
{
|
|
|
|
BOOL ret = CryptHashCertificate(0, algID, 0, toHash, toHashLen, pvData,
|
|
|
|
pcbData);
|
2008-12-23 04:32:41 +01:00
|
|
|
if (ret && pvData)
|
2008-08-29 16:30:19 +02:00
|
|
|
{
|
|
|
|
CRYPT_DATA_BLOB blob = { *pcbData, pvData };
|
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
ret = CTLContext_SetProperty(ctl, dwPropId, 0, &blob);
|
2008-08-29 16:30:19 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
static BOOL CTLContext_GetProperty(ctl_t *ctl, DWORD dwPropId,
|
2008-08-29 16:30:19 +02:00
|
|
|
void *pvData, DWORD *pcbData)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
CRYPT_DATA_BLOB blob;
|
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
TRACE("(%p, %d, %p, %p)\n", ctl, dwPropId, pvData, pcbData);
|
2008-08-29 16:30:19 +02:00
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
if (ctl->base.properties)
|
|
|
|
ret = ContextPropertyList_FindProperty(ctl->base.properties, dwPropId, &blob);
|
2008-08-29 16:30:19 +02:00
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (!pvData)
|
|
|
|
*pcbData = blob.cbData;
|
|
|
|
else if (*pcbData < blob.cbData)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
*pcbData = blob.cbData;
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(pvData, blob.pbData, blob.cbData);
|
|
|
|
*pcbData = blob.cbData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Implicit properties */
|
|
|
|
switch (dwPropId)
|
|
|
|
{
|
|
|
|
case CERT_SHA1_HASH_PROP_ID:
|
2013-10-17 11:07:24 +02:00
|
|
|
ret = CTLContext_GetHashProp(ctl, dwPropId, CALG_SHA1,
|
|
|
|
ctl->ctx.pbCtlEncoded, ctl->ctx.cbCtlEncoded, pvData, pcbData);
|
2008-08-29 16:30:19 +02:00
|
|
|
break;
|
|
|
|
case CERT_MD5_HASH_PROP_ID:
|
2013-10-17 11:07:24 +02:00
|
|
|
ret = CTLContext_GetHashProp(ctl, dwPropId, CALG_MD5,
|
|
|
|
ctl->ctx.pbCtlEncoded, ctl->ctx.cbCtlEncoded, pvData, pcbData);
|
2008-08-29 16:30:19 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetLastError(CRYPT_E_NOT_FOUND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI CertGetCTLContextProperty(PCCTL_CONTEXT pCTLContext,
|
|
|
|
DWORD dwPropId, void *pvData, DWORD *pcbData)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(%p, %d, %p, %p)\n", pCTLContext, dwPropId, pvData, pcbData);
|
|
|
|
|
|
|
|
switch (dwPropId)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case CERT_CERT_PROP_ID:
|
|
|
|
case CERT_CRL_PROP_ID:
|
|
|
|
case CERT_CTL_PROP_ID:
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
case CERT_ACCESS_STATE_PROP_ID:
|
|
|
|
if (!pvData)
|
|
|
|
{
|
|
|
|
*pcbData = sizeof(DWORD);
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else if (*pcbData < sizeof(DWORD))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
*pcbData = sizeof(DWORD);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-21 15:59:11 +02:00
|
|
|
ret = CertGetStoreProperty(pCTLContext->hCertStore, dwPropId, pvData, pcbData);
|
2008-08-29 16:30:19 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2013-10-17 11:07:24 +02:00
|
|
|
ret = CTLContext_GetProperty(ctl_from_ptr(pCTLContext), dwPropId, pvData,
|
2008-08-29 16:30:19 +02:00
|
|
|
pcbData);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
static BOOL CTLContext_SetProperty(ctl_t *ctl, DWORD dwPropId,
|
2008-08-29 16:30:19 +02:00
|
|
|
DWORD dwFlags, const void *pvData)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
TRACE("(%p, %d, %08x, %p)\n", ctl, dwPropId, dwFlags, pvData);
|
2008-08-29 16:30:19 +02:00
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
if (!ctl->base.properties)
|
2008-08-29 16:30:19 +02:00
|
|
|
ret = FALSE;
|
|
|
|
else if (!pvData)
|
|
|
|
{
|
2013-10-17 11:07:24 +02:00
|
|
|
ContextPropertyList_RemoveProperty(ctl->base.properties, dwPropId);
|
2008-08-29 16:30:19 +02:00
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (dwPropId)
|
|
|
|
{
|
|
|
|
case CERT_AUTO_ENROLL_PROP_ID:
|
|
|
|
case CERT_CTL_USAGE_PROP_ID: /* same as CERT_ENHKEY_USAGE_PROP_ID */
|
|
|
|
case CERT_DESCRIPTION_PROP_ID:
|
|
|
|
case CERT_FRIENDLY_NAME_PROP_ID:
|
|
|
|
case CERT_HASH_PROP_ID:
|
|
|
|
case CERT_KEY_IDENTIFIER_PROP_ID:
|
|
|
|
case CERT_MD5_HASH_PROP_ID:
|
|
|
|
case CERT_NEXT_UPDATE_LOCATION_PROP_ID:
|
|
|
|
case CERT_PUBKEY_ALG_PARA_PROP_ID:
|
|
|
|
case CERT_PVK_FILE_PROP_ID:
|
|
|
|
case CERT_SIGNATURE_HASH_PROP_ID:
|
|
|
|
case CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID:
|
|
|
|
case CERT_SUBJECT_NAME_MD5_HASH_PROP_ID:
|
|
|
|
case CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID:
|
|
|
|
case CERT_ENROLLMENT_PROP_ID:
|
|
|
|
case CERT_CROSS_CERT_DIST_POINTS_PROP_ID:
|
|
|
|
case CERT_RENEWAL_PROP_ID:
|
|
|
|
{
|
|
|
|
PCRYPT_DATA_BLOB blob = (PCRYPT_DATA_BLOB)pvData;
|
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
ret = ContextPropertyList_SetProperty(ctl->base.properties, dwPropId,
|
2008-08-29 16:30:19 +02:00
|
|
|
blob->pbData, blob->cbData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CERT_DATE_STAMP_PROP_ID:
|
2013-10-17 11:07:24 +02:00
|
|
|
ret = ContextPropertyList_SetProperty(ctl->base.properties, dwPropId,
|
2009-01-26 11:01:47 +01:00
|
|
|
pvData, sizeof(FILETIME));
|
2008-08-29 16:30:19 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("%d: stub\n", dwPropId);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI CertSetCTLContextProperty(PCCTL_CONTEXT pCTLContext,
|
|
|
|
DWORD dwPropId, DWORD dwFlags, const void *pvData)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(%p, %d, %08x, %p)\n", pCTLContext, dwPropId, dwFlags, pvData);
|
|
|
|
|
|
|
|
/* Handle special cases for "read-only"/invalid prop IDs. Windows just
|
|
|
|
* crashes on most of these, I'll be safer.
|
|
|
|
*/
|
|
|
|
switch (dwPropId)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case CERT_ACCESS_STATE_PROP_ID:
|
|
|
|
case CERT_CERT_PROP_ID:
|
|
|
|
case CERT_CRL_PROP_ID:
|
|
|
|
case CERT_CTL_PROP_ID:
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-10-17 11:07:24 +02:00
|
|
|
ret = CTLContext_SetProperty(ctl_from_ptr(pCTLContext), dwPropId, dwFlags, pvData);
|
2008-08-29 16:30:19 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|