mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-04 18:47:07 +00:00
ncrypt: Set a couple of key properties.
Signed-off-by: Santino Mazza <mazzasantino1206@gmail.com> Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
26d8f33479
commit
9b1c28e84b
|
@ -184,6 +184,53 @@ static struct object *allocate_object(enum object_type type)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static SECURITY_STATUS set_object_property(struct object *object, const WCHAR *name, BYTE *value, DWORD value_size)
|
||||
{
|
||||
struct object_property *property;
|
||||
|
||||
FIXME("check duplicates\n");
|
||||
if (!object->num_properties)
|
||||
{
|
||||
if (!(object->properties = malloc(sizeof(*property))))
|
||||
{
|
||||
ERR("Error allocating memory.");
|
||||
return NTE_NO_MEMORY;
|
||||
}
|
||||
property = &object->properties[object->num_properties++];
|
||||
}
|
||||
else
|
||||
{
|
||||
struct object_property *tmp;
|
||||
if (!(tmp = realloc(object->properties, sizeof(*property) * (object->num_properties + 1))))
|
||||
{
|
||||
ERR("Error allocating memory.");
|
||||
return NTE_NO_MEMORY;
|
||||
}
|
||||
object->properties = tmp;
|
||||
property = &object->properties[object->num_properties++];
|
||||
}
|
||||
|
||||
memset(property, 0, sizeof(*property));
|
||||
if (!(property->key = malloc((lstrlenW(name) + 1) * sizeof(WCHAR))))
|
||||
{
|
||||
ERR("Error allocating memory.");
|
||||
return NTE_NO_MEMORY;
|
||||
}
|
||||
|
||||
lstrcpyW(property->key, name);
|
||||
property->value_size = value_size;
|
||||
if (!(property->value = malloc(value_size)))
|
||||
{
|
||||
ERR("Error allocating memory.");
|
||||
free(property->key);
|
||||
property->key = NULL;
|
||||
return NTE_NO_MEMORY;
|
||||
}
|
||||
|
||||
memcpy(property->value, value, value_size);
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
SECURITY_STATUS WINAPI NCryptImportKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_HANDLE decrypt_key,
|
||||
const WCHAR *type, NCryptBufferDesc *params, NCRYPT_KEY_HANDLE *handle,
|
||||
BYTE *data, DWORD datasize, DWORD flags)
|
||||
|
@ -244,6 +291,7 @@ SECURITY_STATUS WINAPI NCryptImportKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_H
|
|||
|
||||
key = &object->key;
|
||||
key->alg = RSA;
|
||||
key->rsa.bit_length = rsaheader->BitLength;
|
||||
key->rsa.public_exp_size = rsaheader->cbPublicExp;
|
||||
key->rsa.modulus_size = rsaheader->cbModulus;
|
||||
if (!(key->rsa.public_exp = malloc(rsaheader->cbPublicExp)))
|
||||
|
@ -261,10 +309,13 @@ SECURITY_STATUS WINAPI NCryptImportKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_H
|
|||
}
|
||||
|
||||
public_exp = &data[sizeof(*rsaheader)]; /* The public exp is after the header. */
|
||||
modulus = &public_exp[rsaheader->cbPublicExp]; /* The modulus is after the public exp. */
|
||||
modulus = &public_exp[rsaheader->cbPublicExp]; /* The modulus is after the public exponent. */
|
||||
memcpy(key->rsa.public_exp, public_exp, rsaheader->cbPublicExp);
|
||||
memcpy(key->rsa.modulus, modulus, rsaheader->cbModulus);
|
||||
|
||||
set_object_property(object, NCRYPT_ALGORITHM_GROUP_PROPERTY, (BYTE *)L"RSA", sizeof(L"RSA"));
|
||||
set_object_property(object, NCRYPT_LENGTH_PROPERTY, (BYTE *)&key->rsa.bit_length, sizeof(key->rsa.bit_length));
|
||||
set_object_property(object, NCRYPT_PROVIDER_HANDLE_PROPERTY, (BYTE *)&provider, sizeof(provider));
|
||||
*handle = (NCRYPT_KEY_HANDLE)object;
|
||||
break;
|
||||
}
|
||||
|
@ -310,53 +361,6 @@ SECURITY_STATUS WINAPI NCryptOpenStorageProvider(NCRYPT_PROV_HANDLE *provider, c
|
|||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static SECURITY_STATUS set_object_property(struct object *object, const WCHAR *name, BYTE *value, DWORD value_size)
|
||||
{
|
||||
struct object_property *property;
|
||||
|
||||
FIXME("check duplicates\n");
|
||||
if (!object->num_properties)
|
||||
{
|
||||
if (!(object->properties = malloc(sizeof(*property))))
|
||||
{
|
||||
ERR("Error allocating memory.");
|
||||
return NTE_NO_MEMORY;
|
||||
}
|
||||
property = &object->properties[object->num_properties++];
|
||||
}
|
||||
else
|
||||
{
|
||||
struct object_property *tmp;
|
||||
if (!(tmp = realloc(object->properties, sizeof(*property) * (object->num_properties + 1))))
|
||||
{
|
||||
ERR("Error allocating memory.");
|
||||
return NTE_NO_MEMORY;
|
||||
}
|
||||
object->properties = tmp;
|
||||
property = &object->properties[object->num_properties++];
|
||||
}
|
||||
|
||||
memset(property, 0, sizeof(*property));
|
||||
if (!(property->key = malloc((lstrlenW(name) + 1) * sizeof(WCHAR))))
|
||||
{
|
||||
ERR("Error allocating memory.");
|
||||
return NTE_NO_MEMORY;
|
||||
}
|
||||
|
||||
lstrcpyW(property->key, name);
|
||||
property->value_size = value_size;
|
||||
if (!(property->value = malloc(value_size)))
|
||||
{
|
||||
ERR("Error allocating memory.");
|
||||
free(property->key);
|
||||
property->key = NULL;
|
||||
return NTE_NO_MEMORY;
|
||||
}
|
||||
|
||||
memcpy(property->value, value, value_size);
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
SECURITY_STATUS WINAPI NCryptSetProperty(NCRYPT_HANDLE handle, const WCHAR *name, BYTE *input, DWORD insize, DWORD flags)
|
||||
{
|
||||
struct object *object = (struct object *)handle;
|
||||
|
|
|
@ -26,6 +26,7 @@ enum key_algorithm
|
|||
|
||||
struct rsa_key
|
||||
{
|
||||
DWORD bit_length;
|
||||
DWORD public_exp_size;
|
||||
BYTE *public_exp;
|
||||
DWORD modulus_size;
|
||||
|
|
|
@ -169,7 +169,7 @@ static void test_get_property(void)
|
|||
NCRYPT_KEY_HANDLE key;
|
||||
SECURITY_STATUS ret;
|
||||
WCHAR value[4];
|
||||
DWORD size;
|
||||
DWORD keylength, size;
|
||||
|
||||
ret = NCryptOpenStorageProvider(&prov, NULL, 0);
|
||||
ok(ret == ERROR_SUCCESS, "got %#lx\n", ret);
|
||||
|
@ -177,17 +177,29 @@ static void test_get_property(void)
|
|||
ret = NCryptImportKey(prov, 0, BCRYPT_RSAPUBLIC_BLOB, NULL, &key, rsa_key_blob, sizeof(rsa_key_blob), 0);
|
||||
ok(ret == ERROR_SUCCESS, "got %#lx\n", ret);
|
||||
|
||||
todo_wine {
|
||||
ret = NCryptGetProperty(key, L"Algorithm Group", NULL, 0, &size, 0);
|
||||
size = 0;
|
||||
ret = NCryptGetProperty(key, NCRYPT_ALGORITHM_GROUP_PROPERTY, NULL, 0, &size, 0);
|
||||
ok(ret == ERROR_SUCCESS, "got %#lx\n", ret);
|
||||
ok(size == 8, "got %lu\n", size);
|
||||
|
||||
size = 0;
|
||||
ret = NCryptGetProperty(key, L"Algorithm Group", (BYTE *)value, sizeof(value), &size, 0);
|
||||
value[0] = 0;
|
||||
ret = NCryptGetProperty(key, NCRYPT_ALGORITHM_GROUP_PROPERTY, (BYTE *)value, sizeof(value), &size, 0);
|
||||
ok(ret == ERROR_SUCCESS, "got %#lx\n", ret);
|
||||
todo_wine {
|
||||
ok(size == 8, "got %lu\n", size);
|
||||
ok(!lstrcmpW(value, L"RSA"), "The string doesn't match with 'RSA'\n");
|
||||
}
|
||||
ok(!lstrcmpW(value, L"RSA"), "The string doesn't match with 'RSA'\n");
|
||||
|
||||
size = 0;
|
||||
ret = NCryptGetProperty(key, NCRYPT_LENGTH_PROPERTY, NULL, 0, &size, 0);
|
||||
ok(ret == ERROR_SUCCESS, "got %#lx\n", ret);
|
||||
ok(size == sizeof(DWORD), "got %lu\n", size);
|
||||
|
||||
keylength = 0;
|
||||
ret = NCryptGetProperty(key, NCRYPT_LENGTH_PROPERTY, (BYTE *)&keylength, size, &size, 0);
|
||||
ok(ret == ERROR_SUCCESS, "got %#lx\n", ret);
|
||||
ok(keylength == 1024, "got %lu\n", keylength);
|
||||
|
||||
NCryptFreeObject(prov);
|
||||
}
|
||||
|
|
|
@ -71,6 +71,40 @@ typedef ULONG_PTR NCRYPT_SECRET_HANDLE;
|
|||
|
||||
#define NCRYPT_SILENT_FLAG 0x00000040
|
||||
|
||||
#define NCRYPT_NAME_PROPERTY L"Name"
|
||||
#define NCRYPT_UNIQUE_NAME_PROPERTY L"Unique Name"
|
||||
#define NCRYPT_ALGORITHM_PROPERTY L"Algorithm Name"
|
||||
#define NCRYPT_LENGTH_PROPERTY L"Length"
|
||||
#define NCRYPT_LENGTHS_PROPERTY L"Lengths"
|
||||
#define NCRYPT_BLOCK_LENGTH_PROPERTY L"Block Length"
|
||||
#define NCRYPT_UI_POLICY_PROPERTY L"UI Policy"
|
||||
#define NCRYPT_EXPORT_POLICY_PROPERTY L"Export Policy"
|
||||
#define NCRYPT_WINDOW_HANDLE_PROPERTY L"HWND Handle"
|
||||
#define NCRYPT_USE_CONTEXT_PROPERTY L"Use Context"
|
||||
#define NCRYPT_IMPL_TYPE_PROPERTY L"Impl Type"
|
||||
#define NCRYPT_KEY_USAGE_PROPERTY L"Key Usage"
|
||||
#define NCRYPT_KEY_TYPE_PROPERTY L"Key Type"
|
||||
#define NCRYPT_VERSION_PROPERTY L"Version"
|
||||
#define NCRYPT_SECURITY_DESCR_SUPPORT_PROPERTY L"Security Descr Support"
|
||||
#define NCRYPT_SECURITY_DESCR_PROPERTY L"Security Descr"
|
||||
#define NCRYPT_USE_COUNT_ENABLED_PROPERTY L"Enabled Use Count"
|
||||
#define NCRYPT_USE_COUNT_PROPERTY L"Use Count"
|
||||
#define NCRYPT_LAST_MODIFIED_PROPERTY L"Modified"
|
||||
#define NCRYPT_MAX_NAME_LENGTH_PROPERTY L"Max Name Length"
|
||||
#define NCRYPT_ALGORITHM_GROUP_PROPERTY L"Algorithm Group"
|
||||
#define NCRYPT_PROVIDER_HANDLE_PROPERTY L"Provider Handle"
|
||||
#define NCRYPT_PIN_PROPERTY L"SmartCardPin"
|
||||
#define NCRYPT_READER_PROPERTY L"SmartCardReader"
|
||||
#define NCRYPT_SMARTCARD_GUID_PROPERTY L"SmartCardGuid"
|
||||
#define NCRYPT_CERTIFICATE_PROPERTY L"SmartCardKeyCertificate"
|
||||
#define NCRYPT_PIN_PROMPT_PROPERTY L"SmartCardPinPrompt"
|
||||
#define NCRYPT_USER_CERTSTORE_PROPERTY L"SmartCardUserCertStore"
|
||||
#define NCRYPT_ROOT_CERTSTORE_PROPERTY L"SmartcardRootCertStore"
|
||||
#define NCRYPT_SECURE_PIN_PROPERTY L"SmartCardSecurePin"
|
||||
#define NCRYPT_ASSOCIATED_ECDH_KEY L"SmartCardAssociatedECDHKey"
|
||||
#define NCRYPT_SCARD_PIN_ID L"SmartCardPinId"
|
||||
#define NCRYPT_SCARD_PIN_INFO L"SmartCardPinInfo"
|
||||
|
||||
SECURITY_STATUS WINAPI NCryptCreatePersistedKey(NCRYPT_PROV_HANDLE, NCRYPT_KEY_HANDLE *, const WCHAR *, const WCHAR *, DWORD, DWORD);
|
||||
SECURITY_STATUS WINAPI NCryptDecrypt(NCRYPT_KEY_HANDLE, BYTE *, DWORD, void *, BYTE *, DWORD, DWORD *, DWORD);
|
||||
SECURITY_STATUS WINAPI NCryptEncrypt(NCRYPT_KEY_HANDLE, BYTE *, DWORD, void *, BYTE *, DWORD, DWORD *, DWORD);
|
||||
|
|
Loading…
Reference in a new issue