Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/main.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c index 8e789573924..dbcb0087445 100644 --- a/dlls/ncrypt/main.c +++ b/dlls/ncrypt/main.c @@ -181,11 +181,10 @@ 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 *create_object_property(struct object *object, const WCHAR *name) { struct object_property *property;
- FIXME("check duplicates\n"); if (!object->num_properties) { if (!(object->properties = malloc(sizeof(*property)))) @@ -215,8 +214,18 @@ static SECURITY_STATUS set_object_property(struct object *object, const WCHAR *n }
lstrcpyW(property->key, name); + + return property; +} + +static SECURITY_STATUS set_object_property(struct object *object, const WCHAR *name, BYTE *value, DWORD value_size) +{ + struct object_property *property = get_object_property(object, name); + + if(!property) property = create_object_property(object, name); + property->value_size = value_size; - if (!(property->value = malloc(value_size))) + if (!(property->value = realloc(property->value, value_size))) { ERR("Error allocating memory."); free(property->key);
Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/main.c | 2 ++ dlls/ncrypt/tests/ncrypt.c | 3 +++ 2 files changed, 5 insertions(+)
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c index dbcb0087445..a4d88124237 100644 --- a/dlls/ncrypt/main.c +++ b/dlls/ncrypt/main.c @@ -162,6 +162,7 @@ SECURITY_STATUS WINAPI NCryptGetProperty(NCRYPT_HANDLE handle, const WCHAR *name const struct object_property *property;
TRACE("(%#Ix, %s, %p, %lu, %p, %#lx)\n", handle, wine_dbgstr_w(name), output, outsize, result, flags); + if (!handle) return NTE_INVALID_HANDLE; if (flags) FIXME("flags %#lx not supported\n", flags);
if (!(property = get_object_property(object, name))) return NTE_INVALID_PARAMETER; @@ -372,6 +373,7 @@ SECURITY_STATUS WINAPI NCryptSetProperty(NCRYPT_HANDLE handle, const WCHAR *name struct object *object = (struct object *)handle;
TRACE("(%#Ix, %s, %p, %lu, %#lx)\n", handle, wine_dbgstr_w(name), input, insize, flags); + if(!handle) return NTE_INVALID_HANDLE; if (flags) FIXME("flags %#lx not supported\n", flags);
return set_object_property(object, name, input, insize); diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index 891e5b60254..9ffd4bfec50 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -199,6 +199,9 @@ static void test_get_property(void) ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); ok(keylength == 1024, "got %lu\n", keylength);
+ ret = NCryptGetProperty(0, NCRYPT_LENGTH_PROPERTY, &keylength, size, &size, 0); + ok(ret == NTE_INVALID_HANDLE, "got %#lx\n", ret); + NCryptFreeObject(prov); }
Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/tests/ncrypt.c | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index 9ffd4bfec50..d7623a04a83 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -205,9 +205,57 @@ static void test_get_property(void) NCryptFreeObject(prov); }
+static void test_create_persisted_key() +{ + NCRYPT_PROV_HANDLE prov; + NCRYPT_KEY_HANDLE key; + SECURITY_STATUS ret; + DWORD size; + DWORD keylength; + WCHAR alggroup[4]; + memset(alggroup, 0, sizeof(alggroup)); + + ret = NCryptOpenStorageProvider(&prov, NULL, 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + + todo_wine + { + key = 0; + ret = NCryptCreatePersistedKey(NULL, &key, BCRYPT_RSA_ALGORITHM, NULL, 0, 0); + ok(ret == NTE_INVALID_HANDLE, "got %#lx\n", ret); + + ret = NCryptCreatePersistedKey(prov, &key, NULL, NULL, 0, 0); + ok(ret == 0x800706f4 || broken(ret == NTE_FAIL), "got %#lx\n", ret); /* FIXME Find name for this error */ + + ret = NCryptCreatePersistedKey(prov, &key, BCRYPT_RSA_ALGORITHM, NULL, 0, 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + ok(key, "got null handle\n"); + + 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, NCRYPT_ALGORITHM_GROUP_PROPERTY, (BYTE *)alggroup, sizeof(alggroup), &size, 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + ok(size == 8, "got %lu\n", size); + ok(!lstrcmpW(alggroup, L"RSA"), "The string doesn't match with 'RSA'\n"); + + ret = NCryptGetProperty(key, NCRYPT_LENGTH_PROPERTY, (BYTE *)&keylength, sizeof(DWORD), &size, 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + ok(size == 4, "got %lu\n", size); + ok(keylength == 1024, "got %lu\n", keylength); + + NCryptFinalizeKey(key, 0); + NCryptFreeObject(key); + NCryptFreeObject(prov); + } +} + START_TEST(ncrypt) { test_key_import_rsa(); test_ncrypt_free_object(); test_get_property(); + test_create_persisted_key(); }
Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/tests/ncrypt.c | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index d7623a04a83..5fc37bb425b 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -205,6 +205,51 @@ static void test_get_property(void) NCryptFreeObject(prov); }
+static void test_set_property() +{ + NCRYPT_PROV_HANDLE prov; + SECURITY_STATUS ret; + NCRYPT_KEY_HANDLE key; + DWORD keylength; + + ret = NCryptOpenStorageProvider(&prov, NULL, 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + + 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); + keylength = 2048; + ret = NCryptSetProperty(key, NCRYPT_LENGTH_PROPERTY, &keylength, sizeof(DWORD), 0); + ok(ret == ERROR_SUCCESS || broken(ret == NTE_INVALID_HANDLE), "got %#lx\n", ret); + + ret = NCryptSetProperty(0, NCRYPT_LENGTH_PROPERTY, &keylength, sizeof(DWORD), 0); + ok(ret == NTE_INVALID_HANDLE, "got %#lx\n", ret); + + todo_wine + { + ret = NCryptSetProperty(key, NCRYPT_NAME_PROPERTY, L"Key name", sizeof(WCHAR) * 9, 0); + ok(ret == NTE_NOT_SUPPORTED, "got %#lx\n", ret); + + NCryptFreeObject(key); + + key = 0; + ret = NCryptCreatePersistedKey(prov, &key, BCRYPT_RSA_ALGORITHM, NULL, 0, 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + ok(key, "got null handle\n"); + + keylength = 2048; + ret = NCryptSetProperty(key, NCRYPT_LENGTH_PROPERTY, &keylength, sizeof(DWORD), 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + + ret = NCryptSetProperty(key, NCRYPT_NAME_PROPERTY, L"Key name", sizeof(WCHAR) * 9, 0); + ok(ret == NTE_NOT_SUPPORTED, "got %#lx\n", ret); + + ret = NCryptSetProperty(key, L"My Custom Property", L"value", sizeof(WCHAR) * 7, 0); + ok(ret == NTE_NOT_SUPPORTED, "got %#lx\n", ret); + } + NCryptFreeObject(key); + NCryptFreeObject(prov); +} + static void test_create_persisted_key() { NCRYPT_PROV_HANDLE prov; @@ -257,5 +302,6 @@ START_TEST(ncrypt) test_key_import_rsa(); test_ncrypt_free_object(); test_get_property(); + test_set_property(); test_create_persisted_key(); }