Some applications crash when the storage provider its null.
Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/main.c | 17 ++++++++++- dlls/ncrypt/ncrypt_internal.h | 56 +++++++++++++++++++++++++++++++++++ dlls/ncrypt/tests/ncrypt.c | 2 -- 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 dlls/ncrypt/ncrypt_internal.h
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c index f23b239d93f..3a916e5b722 100644 --- a/dlls/ncrypt/main.c +++ b/dlls/ncrypt/main.c @@ -19,10 +19,12 @@ */
#include <stdarg.h> +#include <stdlib.h>
#include "windef.h" #include "winbase.h" #include "ncrypt.h" +#include "ncrypt_internal.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(ncrypt); @@ -129,10 +131,23 @@ SECURITY_STATUS WINAPI NCryptOpenKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_HAN return NTE_NOT_SUPPORTED; }
+int allocate_storage_provider_object(struct ncrypt_object **providerobject) +{ + *providerobject = malloc(sizeof(struct ncrypt_object)); + if (providerobject == NULL) + { + ERR("Error allocating memory.\n"); + return NTE_NO_MEMORY; + } + memset(*providerobject, 0, sizeof(struct ncrypt_object)); + (*providerobject)->type = STORAGE_PROVIDER; + return ERROR_SUCCESS; +} + SECURITY_STATUS WINAPI NCryptOpenStorageProvider(NCRYPT_PROV_HANDLE *provider, const WCHAR *name, DWORD flags) { FIXME("(%p, %s, %u): stub\n", provider, wine_dbgstr_w(name), flags); - return NTE_NOT_SUPPORTED; + return allocate_storage_provider_object((struct ncrypt_object**)provider); }
SECURITY_STATUS WINAPI NCryptSetProperty(NCRYPT_HANDLE object, const WCHAR *property, diff --git a/dlls/ncrypt/ncrypt_internal.h b/dlls/ncrypt/ncrypt_internal.h new file mode 100644 index 00000000000..1201cdd857a --- /dev/null +++ b/dlls/ncrypt/ncrypt_internal.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 Santino Mazza + * + * 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 + */ + +#ifndef NCRYPT_INTERNAL_H +#define NCRYPT_INTERNAL_H + +#include <stdarg.h> + +#include "windef.h" +#include "winbase.h" +#include "winternl.h" + +struct ncrypt_storage_provider_object +{ + // FIXME Stub +}; + +enum ncrypt_object_type +{ + STORAGE_PROVIDER, +}; + +struct ncrypt_object_property +{ + WCHAR *key; + DWORD value_size; + VOID *value; +}; + +struct ncrypt_object +{ + enum ncrypt_object_type type; + DWORD number_of_properties; + struct ncrypt_object_property *properties; + union + { + struct ncrypt_storage_provider_object storage_provider; + } object; +}; + +#endif // NCRYPT_INTERNAL_H diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index 045dd60c793..df2179ca10a 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -92,12 +92,10 @@ static void test_key_import_rsa(void) NCRYPT_KEY_HANDLE key; SECURITY_STATUS ret;
- todo_wine { prov = 0; ret = NCryptOpenStorageProvider(&prov, NULL, 0); ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); ok(prov, "got null handle\n"); - }
todo_wine { key = 0;
Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/main.c | 115 +++++++++++++++++++++++++++++++--- dlls/ncrypt/ncrypt_internal.h | 37 +++++++++++ dlls/ncrypt/tests/ncrypt.c | 2 - 3 files changed, 142 insertions(+), 12 deletions(-)
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c index 3a916e5b722..54d80c83d67 100644 --- a/dlls/ncrypt/main.c +++ b/dlls/ncrypt/main.c @@ -24,6 +24,7 @@ #include "windef.h" #include "winbase.h" #include "ncrypt.h" +#include "bcrypt.h" #include "ncrypt_internal.h" #include "wine/debug.h"
@@ -34,7 +35,7 @@ SECURITY_STATUS WINAPI NCryptCreatePersistedKey(NCRYPT_PROV_HANDLE provider, NCR DWORD flags) { FIXME("(0x%lx, %p, %s, %s, 0x%08x, 0x%08x): stub\n", provider, key, wine_dbgstr_w(algid), - wine_dbgstr_w(name), keyspec, flags); + wine_dbgstr_w(name), keyspec, flags); return NTE_NOT_SUPPORTED; }
@@ -42,7 +43,7 @@ SECURITY_STATUS WINAPI NCryptDecrypt(NCRYPT_KEY_HANDLE key, BYTE *input, DWORD i BYTE *output, DWORD outsize, DWORD *result, DWORD flags) { FIXME("(0x%lx, %p, %u, %p, %p, %u, %p, 0x%08x): stub\n", key, input, insize, padding, - output, outsize, result, flags); + output, outsize, result, flags); return NTE_NOT_SUPPORTED; }
@@ -56,7 +57,7 @@ SECURITY_STATUS WINAPI NCryptEncrypt(NCRYPT_KEY_HANDLE key, BYTE *input, DWORD i BYTE *output, DWORD outsize, DWORD *result, DWORD flags) { FIXME("(0x%lx, %p, %u, %p, %p, %u, %p, 0x%08x): stub\n", key, input, insize, padding, - output, outsize, result, flags); + output, outsize, result, flags); return NTE_NOT_SUPPORTED; }
@@ -97,18 +98,112 @@ SECURITY_STATUS WINAPI NCryptGetProperty(NCRYPT_HANDLE object, const WCHAR *prop DWORD outsize, DWORD *result, DWORD flags) { FIXME("(0x%lx, %s, %p, %u, %p, 0x%08x): stub\n", object, wine_dbgstr_w(property), output, outsize, - result, flags); + result, flags); return NTE_NOT_SUPPORTED; }
+int allocate_key_object(struct ncrypt_object **keyobject) +{ + *keyobject = malloc(sizeof(struct ncrypt_object)); + if (keyobject == NULL) + { + ERR("Error allocating memory.\n"); + return NTE_NO_MEMORY; + } + memset(*keyobject, 0, sizeof(struct ncrypt_object)); + (*keyobject)->type = KEY; + return ERROR_SUCCESS; +} + SECURITY_STATUS WINAPI NCryptImportKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_HANDLE decrypt_key, const WCHAR *type, NCryptBufferDesc *params, NCRYPT_KEY_HANDLE *key, - PBYTE data, DWORD datasize, DWORD flags) + BYTE *data, DWORD datasize, DWORD flags) { - FIXME("(0x%lx, 0x%lx, %s, %p, %p, %p, %u, 0x%08x): stub\n", provider, decrypt_key, - wine_dbgstr_w(type), params, - key, data, datasize, flags); - return NTE_NOT_SUPPORTED; + BCRYPT_KEY_BLOB *keyheader = (BCRYPT_KEY_BLOB *)data; + + if (decrypt_key != 0) + { + FIXME("Key blob decryption not implemented\n"); + return NTE_NOT_SUPPORTED; + } + + if (params != NULL) + { + FIXME("Parameter information not implemented\n"); + return NTE_NOT_SUPPORTED; + } + + if (flags == NCRYPT_SILENT_FLAG) + { + FIXME("Silent flag not implemented\n"); + } + else if (flags != 0) + { + ERR("Invalid flags 0x%x\n", flags); + return NTE_BAD_FLAGS; + } + + switch (keyheader->Magic) + { + case BCRYPT_RSAPUBLIC_MAGIC: + { + int ret; + DWORD expected_size; + struct ncrypt_object *rsakeyobject; + struct ncrypt_key_object *rsakey; + BYTE *public_exp; + BYTE *modulus; + BCRYPT_RSAKEY_BLOB *rsaheader = (BCRYPT_RSAKEY_BLOB *)data; + + if (datasize < sizeof(BCRYPT_RSAKEY_BLOB)) + { + ERR("Invalid buffer size.\n"); + return NTE_BAD_DATA; + } + + expected_size = sizeof(BCRYPT_RSAKEY_BLOB) + rsaheader->cbPublicExp + rsaheader->cbModulus; + if (datasize != expected_size) + { + ERR("Invalid buffer size.\n"); + return NTE_BAD_DATA; + } + + ret = allocate_key_object(&rsakeyobject); + if (ret != ERROR_SUCCESS) + return ret; + + rsakey = &rsakeyobject->object.key; + rsakey->algtype = RSA; + rsakey->payload.rsa_key.public_exp_size = rsaheader->cbPublicExp; + rsakey->payload.rsa_key.modulus_size = rsaheader->cbModulus; + rsakey->payload.rsa_key.public_exp = malloc(rsaheader->cbPublicExp); + if (rsakey->payload.rsa_key.public_exp == NULL) + { + ERR("Error allocating memory.\n"); + return NTE_NO_MEMORY; + } + rsakey->payload.rsa_key.modulus = malloc(rsaheader->cbModulus); + if (rsakey->payload.rsa_key.modulus == NULL) + { + ERR("Error allocating memory.\n"); + return NTE_NO_MEMORY; + } + + public_exp = &data[sizeof(BCRYPT_RSAKEY_BLOB)]; /* The public exp its after the header. */ + modulus = &public_exp[rsaheader->cbPublicExp]; /* The modulus its after the public exp. */ + memcpy(rsakey->payload.rsa_key.public_exp, public_exp, rsaheader->cbPublicExp); + memcpy(rsakey->payload.rsa_key.modulus, modulus, rsaheader->cbModulus); + + *key = (NCRYPT_KEY_HANDLE)rsakeyobject; + } + break; + + default: + ERR("Invalid key magic %x\n", keyheader->Magic); + return NTE_INVALID_PARAMETER; + } + + return ERROR_SUCCESS; }
SECURITY_STATUS WINAPI NCryptIsAlgSupported(NCRYPT_PROV_HANDLE provider, const WCHAR *algid, @@ -154,6 +249,6 @@ SECURITY_STATUS WINAPI NCryptSetProperty(NCRYPT_HANDLE object, const WCHAR *prop PBYTE input, DWORD insize, DWORD flags) { FIXME("(%lx, %s, %p, %u, 0x%08x): stub\n", object, wine_dbgstr_w(property), input, insize, - flags); + flags); return NTE_NOT_SUPPORTED; } diff --git a/dlls/ncrypt/ncrypt_internal.h b/dlls/ncrypt/ncrypt_internal.h index 1201cdd857a..0948d84925e 100644 --- a/dlls/ncrypt/ncrypt_internal.h +++ b/dlls/ncrypt/ncrypt_internal.h @@ -25,6 +25,41 @@ #include "winbase.h" #include "winternl.h"
+enum asymmetric_key_type +{ + PUBLIC, + PRIVATE, +}; + +enum key_algorithm_type +{ + DH, + DSA, + ECC, + RSA, +}; + +struct ncrypt_rsa_key +{ + DWORD public_exp_size; + BYTE *public_exp; + DWORD modulus_size; + BYTE *modulus; + DWORD prime1_size; + BYTE *prime1; + DWORD prime2_size; + BYTE *prime2; +}; + +struct ncrypt_key_object +{ + enum key_algorithm_type algtype; + union + { + struct ncrypt_rsa_key rsa_key; + } payload; +}; + struct ncrypt_storage_provider_object { // FIXME Stub @@ -32,6 +67,7 @@ struct ncrypt_storage_provider_object
enum ncrypt_object_type { + KEY, STORAGE_PROVIDER, };
@@ -49,6 +85,7 @@ struct ncrypt_object struct ncrypt_object_property *properties; union { + struct ncrypt_key_object key; struct ncrypt_storage_provider_object storage_provider; } object; }; diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index df2179ca10a..bd30189e2c2 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -97,7 +97,6 @@ static void test_key_import_rsa(void) ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); ok(prov, "got null handle\n");
- todo_wine { key = 0; 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); @@ -135,7 +134,6 @@ static void test_key_import_rsa(void) ok(ret == NTE_BAD_DATA, "got %#lx\n", ret);
NCryptFreeObject(prov); - } }
START_TEST(ncrypt)
Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/tests/ncrypt.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index bd30189e2c2..c5ba5080241 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -136,7 +136,31 @@ static void test_key_import_rsa(void) NCryptFreeObject(prov); }
+static void test_ncrypt_free_object(void) +{ + NCRYPT_PROV_HANDLE prov; + SECURITY_STATUS ret = NCryptOpenStorageProvider(&prov, NULL, 0); + ok(ret == ERROR_SUCCESS, "got 0x%x\n", ret); + + todo_wine { + NCRYPT_KEY_HANDLE key; + ret = NCryptImportKey(prov, (NCRYPT_KEY_HANDLE)NULL, BCRYPT_RSAPUBLIC_BLOB, NULL, &key, rsa_key_blob, sizeof(rsa_key_blob), 0); + ret = NCryptFreeObject(key); + ok(ret == ERROR_SUCCESS, "got 0x%x\n", ret); + + key = 0; + ret = NCryptFreeObject(key); + ok(ret == NTE_INVALID_HANDLE, "got 0x%x\n", ret); + + key = malloc(50); + ret = NCryptFreeObject(key); + ok(ret == NTE_INVALID_HANDLE, "got 0x%x\n", ret); + free(key); + } +} + START_TEST(ncrypt) { test_key_import_rsa(); + test_ncrypt_free_object(); }
Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/main.c | 57 +++++++++++++++++++++++++++++++++-- dlls/ncrypt/ncrypt_internal.h | 1 + dlls/ncrypt/tests/ncrypt.c | 2 -- 3 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c index 54d80c83d67..491423a2643 100644 --- a/dlls/ncrypt/main.c +++ b/dlls/ncrypt/main.c @@ -88,10 +88,63 @@ SECURITY_STATUS WINAPI NCryptFreeBuffer(PVOID buf) return NTE_NOT_SUPPORTED; }
+int free_key_object(struct ncrypt_object *keyobject) +{ + struct ncrypt_key_object *key = &keyobject->object.key; + switch (key->algtype) + { + case RSA: + { + free(key->payload.rsa_key.modulus); + free(key->payload.rsa_key.public_exp); + if (key->payload.rsa_key.type == PRIVATE) + { + free(key->payload.rsa_key.prime1); + free(key->payload.rsa_key.prime2); + } + } + break; + + default: + { + ERR("invalid key object 0x%p\n", keyobject); + return NTE_INVALID_HANDLE; + } + break; + } + + return ERROR_SUCCESS; +} + SECURITY_STATUS WINAPI NCryptFreeObject(NCRYPT_HANDLE object) { - FIXME("(0x%lx): stub\n", object); - return NTE_NOT_SUPPORTED; + struct ncrypt_object *ncryptobj = (struct ncrypt_object *)object; + if (ncryptobj == NULL) + { + ERR("invalid handle 0x%p\n", ncryptobj); + return NTE_INVALID_HANDLE; + } + + switch (ncryptobj->type) + { + case KEY: + { + int ret = free_key_object(ncryptobj); + if (ret != ERROR_SUCCESS) + return ret; + } + break; + + default: + { + ERR("invalid handle 0x%p\n", ncryptobj); + return NTE_INVALID_HANDLE; + } + break; + } + + free(ncryptobj); + return ERROR_SUCCESS; }
SECURITY_STATUS WINAPI NCryptGetProperty(NCRYPT_HANDLE object, const WCHAR *property, PBYTE output, diff --git a/dlls/ncrypt/ncrypt_internal.h b/dlls/ncrypt/ncrypt_internal.h index 0948d84925e..81bd4bb442f 100644 --- a/dlls/ncrypt/ncrypt_internal.h +++ b/dlls/ncrypt/ncrypt_internal.h @@ -41,6 +41,7 @@ enum key_algorithm_type
struct ncrypt_rsa_key { + enum asymmetric_key_type type; DWORD public_exp_size; BYTE *public_exp; DWORD modulus_size; diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index c5ba5080241..05d430f246f 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -142,7 +142,6 @@ static void test_ncrypt_free_object(void) SECURITY_STATUS ret = NCryptOpenStorageProvider(&prov, NULL, 0); ok(ret == ERROR_SUCCESS, "got 0x%x\n", ret);
- todo_wine { NCRYPT_KEY_HANDLE key; ret = NCryptImportKey(prov, (NCRYPT_KEY_HANDLE)NULL, BCRYPT_RSAPUBLIC_BLOB, NULL, &key, rsa_key_blob, sizeof(rsa_key_blob), 0); ret = NCryptFreeObject(key); @@ -156,7 +155,6 @@ static void test_ncrypt_free_object(void) ret = NCryptFreeObject(key); ok(ret == NTE_INVALID_HANDLE, "got 0x%x\n", ret); free(key); - } }
START_TEST(ncrypt)
Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/main.c | 96 ++++++++++++++++++++++++++++++++++++-- dlls/ncrypt/tests/ncrypt.c | 24 ++++++++++ include/ncrypt.h | 2 + 3 files changed, 117 insertions(+), 5 deletions(-)
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c index 491423a2643..30055eedaec 100644 --- a/dlls/ncrypt/main.c +++ b/dlls/ncrypt/main.c @@ -143,16 +143,53 @@ SECURITY_STATUS WINAPI NCryptFreeObject(NCRYPT_HANDLE object) break; }
+ free(ncryptobj->properties); free(ncryptobj); return ERROR_SUCCESS; }
-SECURITY_STATUS WINAPI NCryptGetProperty(NCRYPT_HANDLE object, const WCHAR *property, PBYTE output, +int get_object_property(struct ncrypt_object *obj, const WCHAR *property_name, struct ncrypt_object_property *propertyout) +{ + if (obj->number_of_properties == 0) + return NTE_INVALID_PARAMETER; + + for (int i = 0; i < obj->number_of_properties; ++i) + { + struct ncrypt_object_property *property = &obj->properties[i]; + if (lstrcmpW(property->key, property_name) == 0) + { + memcpy(propertyout, property, sizeof(struct ncrypt_object_property)); + return ERROR_SUCCESS; + } + } + + return NTE_INVALID_PARAMETER; +} + +SECURITY_STATUS WINAPI NCryptGetProperty(NCRYPT_HANDLE object, const WCHAR *property, BYTE *output, DWORD outsize, DWORD *result, DWORD flags) { - FIXME("(0x%lx, %s, %p, %u, %p, 0x%08x): stub\n", object, wine_dbgstr_w(property), output, outsize, + struct ncrypt_object *ncryptobj = (struct ncrypt_object *)object; + struct ncrypt_object_property prop; + int ret = get_object_property(ncryptobj, property, &prop); + + FIXME("(0x%lx, %s, %p, %u, %p, 0x%08x): semi-stub\n", object, wine_dbgstr_w(property), output, outsize, result, flags); - return NTE_NOT_SUPPORTED; + + if (ret != ERROR_SUCCESS) + return ret; + + if (output == NULL) + { + *result = prop.value_size; + return ERROR_SUCCESS; + } + + if (outsize < prop.value_size) + return NTE_BUFFER_TOO_SMALL; + + memcpy(output, prop.value, prop.value_size); + return ERROR_SUCCESS; }
int allocate_key_object(struct ncrypt_object **keyobject) @@ -298,10 +335,59 @@ SECURITY_STATUS WINAPI NCryptOpenStorageProvider(NCRYPT_PROV_HANDLE *provider, c return allocate_storage_provider_object((struct ncrypt_object**)provider); }
+int set_object_property(struct ncrypt_object *obj, const WCHAR *property_name, BYTE *value, DWORD value_size) +{ + struct ncrypt_object_property property; + + if (obj->number_of_properties == 0) + { + obj->properties = malloc(sizeof(struct ncrypt_object_property)); + if (obj->properties == NULL) + { + ERR("Error allocating memory."); + return NTE_NO_MEMORY; + } + obj->number_of_properties++; + } + else + { + obj->number_of_properties++; + obj->properties = realloc(obj->properties, sizeof(struct ncrypt_object_property) * obj->number_of_properties); + if (obj->properties == NULL) + { + ERR("Error allocating memory."); + return NTE_NO_MEMORY; + } + } + + property.key = malloc((lstrlenW(property_name) + 1) * 2); + if (property.key == NULL) + { + ERR("Error allocating memory."); + return NTE_NO_MEMORY; + } + lstrcpyW(property.key, property_name); + property.value_size = value_size; + property.value = malloc(value_size); + if (property.value == NULL) + { + ERR("Error allocating memory."); + return NTE_NO_MEMORY; + } + memcpy(property.value, value, value_size); + + memcpy(&obj->properties[obj->number_of_properties - 1], &property, sizeof(struct ncrypt_object_property)); + + return ERROR_SUCCESS; +} + SECURITY_STATUS WINAPI NCryptSetProperty(NCRYPT_HANDLE object, const WCHAR *property, - PBYTE input, DWORD insize, DWORD flags) + BYTE *input, DWORD insize, DWORD flags) { + + struct ncrypt_object *ncryptobj = (struct ncrypt_object *)object; + FIXME("(%lx, %s, %p, %u, 0x%08x): stub\n", object, wine_dbgstr_w(property), input, insize, flags); - return NTE_NOT_SUPPORTED; + return set_object_property(ncryptobj, property, input, insize); } diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index 05d430f246f..9c79dc7855e 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -157,8 +157,32 @@ static void test_ncrypt_free_object(void) free(key); }
+static void test_get_property(void) +{ + NCRYPT_PROV_HANDLE prov; + SECURITY_STATUS ret = NCryptOpenStorageProvider(&prov, NULL, 0); + ok(ret == ERROR_SUCCESS, "got 0x%x\n", ret); + + todo_wine { + NCRYPT_KEY_HANDLE key; + ret = NCryptImportKey(prov, (NCRYPT_KEY_HANDLE)NULL, BCRYPT_RSAPUBLIC_BLOB, NULL, &key, rsa_key_blob, sizeof(rsa_key_blob), 0); + + DWORD size; + ret = NCryptGetProperty(key, L"Algorithm Group", NULL, 0, &size, 0); + ok(ret == ERROR_SUCCESS, "got 0x%x\n", ret); + ok(size == 8, "got 0x%x\n", size); + + WCHAR value[8]; + ret = NCryptGetProperty(key, L"Algorithm Group", value, 8, &size, 0); + ok(ret == ERROR_SUCCESS, "got 0x%x\n", ret); + ok(size == 8, "got 0x%x\n", size); + ok(lstrcmpW(value, L"RSA") == 0, "The string doesn't match with 'RSA'\n"); + } +} + START_TEST(ncrypt) { test_key_import_rsa(); test_ncrypt_free_object(); + test_get_property(); } diff --git a/include/ncrypt.h b/include/ncrypt.h index 84f1fedd0b9..fff0689ce05 100644 --- a/include/ncrypt.h +++ b/include/ncrypt.h @@ -80,6 +80,8 @@ SECURITY_STATUS WINAPI NCryptImportKey(NCRYPT_PROV_HANDLE, NCRYPT_KEY_HANDLE, co NCRYPT_KEY_HANDLE *, BYTE *, DWORD, DWORD); SECURITY_STATUS WINAPI NCryptOpenKey(NCRYPT_PROV_HANDLE, NCRYPT_KEY_HANDLE *, const WCHAR *, DWORD, DWORD); SECURITY_STATUS WINAPI NCryptOpenStorageProvider(NCRYPT_PROV_HANDLE *, const WCHAR *, DWORD); +SECURITY_STATUS WINAPI NCryptSetProperty(NCRYPT_HANDLE, const WCHAR *, BYTE *, DWORD, DWORD); +SECURITY_STATUS WINAPI NCryptGetProperty(NCRYPT_HANDLE, const WCHAR *, BYTE *, DWORD, DWORD *, DWORD);
#ifdef __cplusplus }