Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/main.c | 94 ++++++++++++++++++++++++++++++++++++-- dlls/ncrypt/tests/ncrypt.c | 24 ++++++++++ include/ncrypt.h | 2 + 3 files changed, 115 insertions(+), 5 deletions(-)
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c index fa4f52b3ee3..2b2875715d7 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, 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, + 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; + + struct ncrypt_object *ncryptobj = (struct ncrypt_object *)object; + struct ncrypt_object_property prop; + int ret = get_object_property(ncryptobj, property, &prop); + + 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,57 @@ SECURITY_STATUS WINAPI NCryptOpenStorageProvider(NCRYPT_PROV_HANDLE *provider, c return allocate_storage_provider_object(provider); }
+int set_object_property(struct ncrypt_object *obj, WCHAR *property_name, BYTE *value, DWORD value_size) +{ + 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; + } + } + + struct ncrypt_object_property property; + 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) { FIXME("(%lx, %s, %p, %u, 0x%08x): stub\n", object, wine_dbgstr_w(property), input, insize, flags); - return NTE_NOT_SUPPORTED; + + struct ncrypt_object *ncryptobj = (struct ncrypt_object *)object; + return set_object_property(ncryptobj, property, input, insize); } diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index eacb53f2dd3..ff4bc3be7cc 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -146,8 +146,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 d83105ccf0a..0af961c0b3c 100644 --- a/include/ncrypt.h +++ b/include/ncrypt.h @@ -80,6 +80,8 @@ SECURITY_STATUS WINAPI NCryptOpenKey(NCRYPT_PROV_HANDLE, NCRYPT_KEY_HANDLE *, co SECURITY_STATUS WINAPI NCryptImportKey(NCRYPT_PROV_HANDLE, NCRYPT_KEY_HANDLE, const WCHAR *, NCryptBufferDesc *, NCRYPT_KEY_HANDLE *, PBYTE, 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 }