ncrypt: Always map bcrypt return values.
Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
bd55fe145e
commit
0f5f8f980f
|
@ -37,6 +37,7 @@ static SECURITY_STATUS map_ntstatus(NTSTATUS status)
|
||||||
switch (status)
|
switch (status)
|
||||||
{
|
{
|
||||||
case STATUS_INVALID_HANDLE: return NTE_INVALID_HANDLE;
|
case STATUS_INVALID_HANDLE: return NTE_INVALID_HANDLE;
|
||||||
|
case NTE_BAD_DATA: return NTE_BAD_DATA;
|
||||||
default:
|
default:
|
||||||
FIXME("unhandled status %#lx\n", status);
|
FIXME("unhandled status %#lx\n", status);
|
||||||
return NTE_INTERNAL_ERROR;
|
return NTE_INTERNAL_ERROR;
|
||||||
|
@ -123,7 +124,7 @@ static SECURITY_STATUS set_object_property(struct object *object, const WCHAR *n
|
||||||
static struct object *create_key_object(enum algid algid, NCRYPT_PROV_HANDLE provider)
|
static struct object *create_key_object(enum algid algid, NCRYPT_PROV_HANDLE provider)
|
||||||
{
|
{
|
||||||
struct object *object;
|
struct object *object;
|
||||||
NTSTATUS ret;
|
NTSTATUS status;
|
||||||
|
|
||||||
if (!(object = allocate_object(KEY)))
|
if (!(object = allocate_object(KEY)))
|
||||||
{
|
{
|
||||||
|
@ -135,10 +136,10 @@ static struct object *create_key_object(enum algid algid, NCRYPT_PROV_HANDLE pro
|
||||||
{
|
{
|
||||||
case RSA:
|
case RSA:
|
||||||
{
|
{
|
||||||
ret = BCryptOpenAlgorithmProvider(&object->key.bcrypt_alg, BCRYPT_RSA_ALGORITHM, NULL, 0);
|
status = BCryptOpenAlgorithmProvider(&object->key.bcrypt_alg, BCRYPT_RSA_ALGORITHM, NULL, 0);
|
||||||
if (ret != ERROR_SUCCESS)
|
if (status != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
ERR("Error opening algorithm provider\n");
|
ERR("Error opening algorithm provider %#lx\n", status);
|
||||||
free(object);
|
free(object);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -174,7 +175,7 @@ SECURITY_STATUS WINAPI NCryptCreatePersistedKey(NCRYPT_PROV_HANDLE provider, NCR
|
||||||
|
|
||||||
if (!lstrcmpiW(algid, BCRYPT_RSA_ALGORITHM))
|
if (!lstrcmpiW(algid, BCRYPT_RSA_ALGORITHM))
|
||||||
{
|
{
|
||||||
NTSTATUS ret;
|
NTSTATUS status;
|
||||||
DWORD default_bitlen = 1024;
|
DWORD default_bitlen = 1024;
|
||||||
|
|
||||||
if (!(object = create_key_object(RSA, provider)))
|
if (!(object = create_key_object(RSA, provider)))
|
||||||
|
@ -183,13 +184,13 @@ SECURITY_STATUS WINAPI NCryptCreatePersistedKey(NCRYPT_PROV_HANDLE provider, NCR
|
||||||
return NTE_NO_MEMORY;
|
return NTE_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = BCryptGenerateKeyPair(object->key.bcrypt_alg, &object->key.bcrypt_key, default_bitlen, 0);
|
status = BCryptGenerateKeyPair(object->key.bcrypt_alg, &object->key.bcrypt_key, default_bitlen, 0);
|
||||||
if (ret != ERROR_SUCCESS)
|
if (status != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
ERR("Error generating key pair\n");
|
ERR("Error generating key pair %#lx\n", status);
|
||||||
BCryptCloseAlgorithmProvider(object->key.bcrypt_alg, 0);
|
BCryptCloseAlgorithmProvider(object->key.bcrypt_alg, 0);
|
||||||
free(object);
|
free(object);
|
||||||
return NTE_INTERNAL_ERROR;
|
return map_ntstatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_object_property(object, NCRYPT_LENGTH_PROPERTY, (BYTE *)&default_bitlen, sizeof(default_bitlen));
|
set_object_property(object, NCRYPT_LENGTH_PROPERTY, (BYTE *)&default_bitlen, sizeof(default_bitlen));
|
||||||
|
@ -278,15 +279,16 @@ SECURITY_STATUS WINAPI NCryptFreeBuffer(PVOID buf)
|
||||||
|
|
||||||
static SECURITY_STATUS free_key_object(struct key *key)
|
static SECURITY_STATUS free_key_object(struct key *key)
|
||||||
{
|
{
|
||||||
NTSTATUS ret = BCryptDestroyKey(key->bcrypt_key);
|
NTSTATUS status, status2;
|
||||||
if (BCryptCloseAlgorithmProvider(key->bcrypt_alg, 0)) return NTE_INVALID_HANDLE;
|
status = BCryptDestroyKey(key->bcrypt_key);
|
||||||
return ret ? NTE_INVALID_HANDLE : ERROR_SUCCESS;
|
if ((status2 = BCryptCloseAlgorithmProvider(key->bcrypt_alg, 0))) return map_ntstatus(status2);
|
||||||
|
return status ? map_ntstatus(status) : ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SECURITY_STATUS WINAPI NCryptFreeObject(NCRYPT_HANDLE handle)
|
SECURITY_STATUS WINAPI NCryptFreeObject(NCRYPT_HANDLE handle)
|
||||||
{
|
{
|
||||||
struct object *object = (struct object *)handle;
|
struct object *object = (struct object *)handle;
|
||||||
SECURITY_STATUS ret = ERROR_SUCCESS;
|
SECURITY_STATUS ret = STATUS_SUCCESS;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
TRACE("(%#Ix)\n", handle);
|
TRACE("(%#Ix)\n", handle);
|
||||||
|
@ -378,7 +380,7 @@ SECURITY_STATUS WINAPI NCryptImportKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_H
|
||||||
case BCRYPT_RSAPRIVATE_MAGIC:
|
case BCRYPT_RSAPRIVATE_MAGIC:
|
||||||
case BCRYPT_RSAPUBLIC_MAGIC:
|
case BCRYPT_RSAPUBLIC_MAGIC:
|
||||||
{
|
{
|
||||||
NTSTATUS ret;
|
NTSTATUS status;
|
||||||
BCRYPT_RSAKEY_BLOB *rsablob = (BCRYPT_RSAKEY_BLOB *)data;
|
BCRYPT_RSAKEY_BLOB *rsablob = (BCRYPT_RSAKEY_BLOB *)data;
|
||||||
|
|
||||||
if (!(object = create_key_object(RSA, provider)))
|
if (!(object = create_key_object(RSA, provider)))
|
||||||
|
@ -387,13 +389,13 @@ SECURITY_STATUS WINAPI NCryptImportKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_H
|
||||||
return NTE_NO_MEMORY;
|
return NTE_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = BCryptImportKeyPair(object->key.bcrypt_alg, NULL, type, &object->key.bcrypt_key, data, datasize, 0);
|
status = BCryptImportKeyPair(object->key.bcrypt_alg, NULL, type, &object->key.bcrypt_key, data, datasize, 0);
|
||||||
if (ret != ERROR_SUCCESS)
|
if (status != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
WARN("Error importing key pair with bcrypt %#lx\n", ret);
|
WARN("Error importing key pair %#lx\n", status);
|
||||||
BCryptCloseAlgorithmProvider(object->key.bcrypt_alg, 0);
|
BCryptCloseAlgorithmProvider(object->key.bcrypt_alg, 0);
|
||||||
free(object);
|
free(object);
|
||||||
return NTE_BAD_DATA;
|
return map_ntstatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_object_property(object, NCRYPT_LENGTH_PROPERTY, (BYTE *)&rsablob->BitLength, sizeof(rsablob->BitLength));
|
set_object_property(object, NCRYPT_LENGTH_PROPERTY, (BYTE *)&rsablob->BitLength, sizeof(rsablob->BitLength));
|
||||||
|
|
Loading…
Reference in New Issue