Needed for ManaSoul (SteamID: 2660840)
-- v2: ncrypt/tests: Add NCryptExportKey() tests. ncrypt: Add some missing RSA key properties. ncrypt/tests: Test default RSA key properties. include: Add some bcrypt definitions. include: Add some ncrypt definitions.
From: Zhiyi Zhang zzhang@codeweavers.com
--- include/ncrypt.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
diff --git a/include/ncrypt.h b/include/ncrypt.h index 9fc2cb5b171..7a1769c8bd9 100644 --- a/include/ncrypt.h +++ b/include/ncrypt.h @@ -58,6 +58,21 @@ typedef struct NCryptKeyName { DWORD dwFlags; } NCryptKeyName;
+typedef struct __NCRYPT_SUPPORTED_LENGTHS { + DWORD dwMinLength; + DWORD dwMaxLength; + DWORD dwIncrement; + DWORD dwDefaultLength; +} NCRYPT_SUPPORTED_LENGTHS; + +typedef struct __NCRYPT_UI_POLICY { + DWORD dwVersion; + DWORD dwFlags; + LPCWSTR pszCreationTitle; + LPCWSTR pszFriendlyName; + LPCWSTR pszDescription; +} NCRYPT_UI_POLICY; + typedef ULONG_PTR NCRYPT_HANDLE; typedef ULONG_PTR NCRYPT_PROV_HANDLE; typedef ULONG_PTR NCRYPT_KEY_HANDLE; @@ -76,6 +91,17 @@ typedef ULONG_PTR NCRYPT_SECRET_HANDLE; #define NCRYPT_PAD_OAEP_FLAG 0x00000004 #define NCRYPT_PAD_PSS_FLAG 0x00000008
+#define NCRYPT_ALLOW_DECRYPT_FLAG 0x00000001 +#define NCRYPT_ALLOW_SIGNING_FLAG 0x00000002 +#define NCRYPT_ALLOW_KEY_AGREEMENT_FLAG 0x00000004 +#define NCRYPT_ALLOW_KEY_IMPORT_FLAG 0x00000008 +#define NCRYPT_ALLOW_ALL_USAGES 0x00ffffff + +#define NCRYPT_ALLOW_EXPORT_FLAG 0x00000001 +#define NCRYPT_ALLOW_PLAINTEXT_EXPORT_FLAG 0x00000002 +#define NCRYPT_ALLOW_ARCHIVING_FLAG 0x00000004 +#define NCRYPT_ALLOW_PLAINTEXT_ARCHIVING_FLAG 0x00000008 + #define NCRYPT_NAME_PROPERTY L"Name" #define NCRYPT_UNIQUE_NAME_PROPERTY L"Unique Name" #define NCRYPT_ALGORITHM_PROPERTY L"Algorithm Name"
From: Zhiyi Zhang zzhang@codeweavers.com
--- include/bcrypt.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/include/bcrypt.h b/include/bcrypt.h index 462c43a7021..54a7c038021 100644 --- a/include/bcrypt.h +++ b/include/bcrypt.h @@ -58,6 +58,7 @@ typedef LONG NTSTATUS; #define BCRYPT_PADDING_SCHEMES L"PaddingSchemes" #define BCRYPT_PROVIDER_HANDLE L"ProviderHandle" #define BCRYPT_SIGNATURE_LENGTH L"SignatureLength" +#define BCRYPT_PUBLIC_KEY_LENGTH L"PublicKeyLength"
#define BCRYPT_OPAQUE_KEY_BLOB L"OpaqueKeyBlob" #define BCRYPT_KEY_DATA_BLOB L"KeyDataBlob" @@ -138,6 +139,7 @@ static const WCHAR BCRYPT_OBJECT_LENGTH[] = {'O','b','j','e','c','t','L','e','n' static const WCHAR BCRYPT_PADDING_SCHEMES[] = {'P','a','d','d','i','n','g','S','c','h','e','m','e','s',0}; static const WCHAR BCRYPT_PROVIDER_HANDLE[] = {'P','r','o','v','i','d','e','r','H','a','n','d','l','e',0}; static const WCHAR BCRYPT_SIGNATURE_LENGTH[] = {'S','i','g','n','a','t','u','r','e','L','e','n','g','t','h',0}; +static const WCHAR BCRYPT_PUBLIC_KEY_LENGTH[] = {'P','u','b','l','i','c','K','e','y','L','e','n','g','t','h',0};
static const WCHAR BCRYPT_OPAQUE_KEY_BLOB[] = {'O','p','a','q','u','e','K','e','y','B','l','o','b',0}; static const WCHAR BCRYPT_KEY_DATA_BLOB[] = {'K','e','y','D','a','t','a','B','l','o','b',0};
From: Zhiyi Zhang zzhang@codeweavers.com
--- dlls/ncrypt/tests/ncrypt.c | 260 +++++++++++++++++++++++++++++++------ 1 file changed, 221 insertions(+), 39 deletions(-)
diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index bd2f63bea87..572b325a04c 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -40,6 +40,85 @@ static UCHAR rsa_key_blob[] = { 0x44, 0x81, 0x09, 0x41, 0x80, 0x23, 0x7b, 0xf6, 0x3f, 0xaf, 0x91, 0xa1, 0x87, 0x75, 0x33, 0x15, 0xb8, 0xde, 0x32, 0x30, 0xb4, 0x5e, 0xfd};
+static UCHAR rsa_private_key_blob[] = { + 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x01, 0xaf, 0xc0, 0x68, 0x21, 0x76, 0xd7, 0x46, 0xf8, 0x23, + 0x78, 0x94, 0x22, 0xa3, 0x0f, 0x4e, 0xe8, 0xc6, 0x6a, 0x33, 0xdc, 0xbf, + 0x44, 0x6c, 0xb6, 0x95, 0x17, 0x78, 0x1e, 0x75, 0xca, 0xdc, 0x66, 0xe4, + 0x87, 0xbe, 0x91, 0xbf, 0xb3, 0xc0, 0xa5, 0x16, 0xa1, 0xb7, 0xfe, 0x4c, + 0x67, 0xaa, 0x03, 0x38, 0xe7, 0x13, 0x65, 0xfb, 0xb6, 0x4c, 0x52, 0x29, + 0xa4, 0xc4, 0x92, 0x34, 0xcd, 0x81, 0xa5, 0x0b, 0x7f, 0x5f, 0x56, 0xbf, + 0xa7, 0xf8, 0xec, 0x9a, 0xe7, 0xb3, 0x93, 0xba, 0x00, 0xe9, 0x48, 0x7a, + 0xf7, 0x04, 0x65, 0xa3, 0x14, 0x8d, 0x08, 0x78, 0xd8, 0x16, 0x5e, 0x82, + 0xeb, 0xd8, 0xea, 0x3c, 0xec, 0xcc, 0x64, 0x47, 0x97, 0x69, 0x43, 0x17, + 0x5d, 0x25, 0xd9, 0xb8, 0xdf, 0xfc, 0x80, 0x16, 0xbe, 0xbb, 0xa8, 0xe4, + 0xbf, 0x6a, 0x2f, 0xea, 0x9c, 0xe5, 0x58, 0x8a, 0xf4, 0x2b, 0xe5, 0xcf, + 0x67, 0x26, 0xe2, 0xeb, 0x92, 0x88, 0xde, 0x52, 0xee, 0x43, 0x44, 0x14, + 0x6d, 0xf7, 0x46, 0x9c, 0x87, 0xa8, 0x96, 0x85, 0xda, 0x19, 0xc3, 0x57, + 0x95, 0x09, 0x8d, 0xa2, 0x4e, 0xcd, 0x84, 0x67, 0x8e, 0x2c, 0x2d, 0x16, + 0xb0, 0xb4, 0xb4, 0x66, 0xcc, 0x7b, 0x7f, 0xaa, 0x2b, 0x14, 0x17, 0x4c, + 0x68, 0x4a, 0xa2, 0xd3, 0xfc, 0xe0, 0xb9, 0xcd, 0xa4, 0xbb, 0x44, 0x0b, + 0x84, 0xa7, 0x13, 0xd8, 0xee, 0xae, 0x8e, 0xdb, 0x0b, 0xd3, 0xc5, 0xc5, + 0x3b, 0xfd, 0x6c, 0xb0, 0x92, 0x14, 0xf0, 0x7b, 0xa7, 0x37, 0xd6, 0x21, + 0x73, 0x5d, 0x80, 0x9a, 0x49, 0x71, 0x2f, 0xc9, 0x05, 0xa5, 0x74, 0x81, + 0xc9, 0xd5, 0x2a, 0x6a, 0x7f, 0xe8, 0x8e, 0xa9, 0x7b, 0x79, 0x9e, 0x46, + 0x51, 0xe7, 0x08, 0xa1, 0x75, 0x51, 0x75, 0x7a, 0x4a, 0x43, 0x0e, 0x5b, + 0x5a, 0xb8, 0x1b, 0xa3, 0x85, 0x68, 0x27}; + +static UCHAR rsa_full_private_key_blob[] = { + 0x52, 0x53, 0x41, 0x33, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x01, 0xbb, 0x49, 0x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 0x2d, 0x84, 0x9a, + 0x02, 0x24, 0x4a, 0xf0, 0x5d, 0x9d, 0x6b, 0x09, 0xcb, 0x5e, 0x06, 0x4d, + 0xa3, 0x9e, 0x85, 0x38, 0x89, 0xf4, 0x44, 0xbd, 0x4a, 0xe3, 0x2e, 0x3c, + 0x74, 0x5c, 0xad, 0xc3, 0x17, 0x6b, 0x84, 0x24, 0x94, 0xcd, 0xa1, 0x21, + 0xec, 0x0a, 0x4c, 0x66, 0x38, 0x95, 0xc1, 0x64, 0x78, 0xf5, 0x12, 0x46, + 0x58, 0x7f, 0x8a, 0x3f, 0xce, 0xda, 0x9b, 0x7e, 0xa5, 0xe4, 0xbe, 0x9c, + 0x15, 0xd4, 0xb0, 0x84, 0xf0, 0xed, 0x94, 0x37, 0x71, 0x41, 0xbe, 0x9a, + 0x02, 0x02, 0xd9, 0xc2, 0xaf, 0x44, 0x32, 0x6d, 0xcd, 0xee, 0xce, 0xcb, + 0xb9, 0x03, 0xfb, 0xf6, 0xc1, 0xf9, 0x13, 0x59, 0x71, 0x96, 0xd4, 0x50, + 0x04, 0xff, 0x4d, 0xea, 0x8b, 0x28, 0x7c, 0x8e, 0xd9, 0xa6, 0x90, 0xa0, + 0xdf, 0x91, 0x40, 0x67, 0x19, 0x31, 0xd2, 0x76, 0xb3, 0x38, 0x38, 0x2e, + 0xec, 0xd8, 0x67, 0x93, 0x98, 0xb8, 0x07, 0x20, 0x53, 0xb1, 0xec, 0xf5, + 0x26, 0xa7, 0x65, 0x42, 0x0f, 0x15, 0x1f, 0x24, 0xc3, 0x13, 0x5f, 0x35, + 0x97, 0x8f, 0x23, 0x3e, 0x7c, 0xaf, 0xe8, 0x19, 0xeb, 0xee, 0xc6, 0xd2, + 0x1d, 0x5b, 0x75, 0x31, 0xae, 0xea, 0xc1, 0x5a, 0x49, 0xa4, 0xf4, 0x37, + 0x65, 0x16, 0xc9, 0xfb, 0x0a, 0x9d, 0x33, 0x5a, 0x44, 0xaa, 0x9b, 0x0b, + 0x62, 0x48, 0x5f, 0x4c, 0xb5, 0xba, 0x3f, 0xf7, 0xb5, 0xb4, 0xed, 0x84, + 0xbe, 0xc7, 0x6c, 0x1f, 0xa4, 0xd1, 0xb8, 0x23, 0xf6, 0xa6, 0x47, 0x06, + 0x09, 0x4a, 0x61}; + static UCHAR rsa_key_blob_with_invalid_bit_length[] = { 0x52, 0x53, 0x41, 0x31, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -86,6 +165,136 @@ static UCHAR invalid_rsa_key_blob[] = { 0x44, 0x81, 0x09, 0x41, 0x80, 0x23, 0x7b, 0xf6, 0x3f, 0xaf, 0x91, 0xa1, 0x87, 0x75, 0x33, 0x15, 0xb8, 0xde, 0x32, 0x30, 0xb4, 0x5e, 0xfd};
+struct expected_property +{ + const WCHAR *name; + BYTE expected_data[64]; + DWORD expected_size; + SECURITY_STATUS expected_status; + BOOL todo; + SECURITY_STATUS broken_status; + BYTE broken_data[64]; +}; + +static void check_property(int line, NCRYPT_KEY_HANDLE key, const struct expected_property *property) +{ + BYTE buffer[64] = {0}; + SECURITY_STATUS ret; + unsigned int i; + DWORD size; + + winetest_push_context("%s", wine_dbgstr_w(property->name)); + + if (property->expected_status != ERROR_SUCCESS) + { + size = 0; + ret = NCryptGetProperty(key, property->name, buffer, sizeof(buffer), &size, 0); + todo_wine_if(property->todo) + ok_(__FILE__, line)(ret == property->expected_status || broken(ret == property->broken_status), + "got unexpected return value %#lx\n", ret); + if (ret == ERROR_SUCCESS) + ok_(__FILE__, line)(size == property->expected_size, "got unexpected size %lu\n", size); + + goto done; + } + + size = 0; + ret = NCryptGetProperty(key, property->name, NULL, 0, &size, 0); + todo_wine_if(property->todo) + ok_(__FILE__, line)(ret == property->expected_status || broken(ret == property->broken_status), + "got unexpected return value %#lx\n", ret); + if (ret != ERROR_SUCCESS) + goto done; + ok_(__FILE__, line)(size == property->expected_size, "got unexpected size %lu\n", size); + + size = 0; + ret = NCryptGetProperty(key, property->name, buffer, sizeof(buffer), &size, 0); + ok_(__FILE__, line)(ret == property->expected_status, "got unexpected return value %#lx\n", ret); + ok_(__FILE__, line)(size == property->expected_size, "got unexpected size %lu\n", size); + if (ret == ERROR_SUCCESS && memcmp(property->expected_data, buffer, property->expected_size) + && broken(memcmp(property->broken_data, buffer, property->expected_size))) + { + for (i = 0; i < size; i ++) + { + ok_(__FILE__, line)(0, "%#04x \n", buffer[i]); + } + } + +done: + winetest_pop_context(); +} + +#define check_properties(a, b) _check_properties(__LINE__, a, b) +static void _check_properties(int line, NCRYPT_PROV_HANDLE prov, NCRYPT_KEY_HANDLE key) +{ + struct expected_property properties[] = + { + /* NCrypt properties */ + {NCRYPT_NAME_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_UNIQUE_NAME_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_ALGORITHM_PROPERTY, {'R', 0, 'S', 0, 'A', 0}, sizeof(L"RSA"), ERROR_SUCCESS, TRUE}, + {NCRYPT_LENGTH_PROPERTY, {0, 0x4} /* 1024 */, sizeof(DWORD)}, + {NCRYPT_LENGTHS_PROPERTY, {0, 0x2, 0, 0, 0, 0x40, 0, 0, 0x8, 0, 0, 0, 0, 0x4, 0, 0}, sizeof(DWORD) * 4 /* NCRYPT_SUPPORTED_LENGTHS */, ERROR_SUCCESS, TRUE, ERROR_SUCCESS, {0, 0x2, 0, 0, 0, 0x40, 0, 0, 0x40, 0, 0, 0, 0, 0x4, 0, 0}}, + {NCRYPT_BLOCK_LENGTH_PROPERTY, {0x80, 0, 0, 0}, sizeof(DWORD), ERROR_SUCCESS, TRUE}, + {NCRYPT_UI_POLICY_PROPERTY, {0}, sizeof(NCRYPT_UI_POLICY), NTE_NOT_FOUND, TRUE}, + {NCRYPT_EXPORT_POLICY_PROPERTY, {0}, sizeof(DWORD), ERROR_SUCCESS, TRUE}, + {NCRYPT_WINDOW_HANDLE_PROPERTY, {0}, 0, NTE_NOT_FOUND, TRUE}, + {NCRYPT_USE_CONTEXT_PROPERTY, {0}, 0, NTE_NOT_FOUND, TRUE}, + {NCRYPT_IMPL_TYPE_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_KEY_USAGE_PROPERTY, {0xff, 0xff, 0xff, 0} /* NCRYPT_ALLOW_ALL_USAGES */, sizeof(DWORD), ERROR_SUCCESS, TRUE}, + {NCRYPT_KEY_TYPE_PROPERTY, {0}, sizeof(DWORD), ERROR_SUCCESS, TRUE}, + {NCRYPT_VERSION_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_SECURITY_DESCR_SUPPORT_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_SECURITY_DESCR_PROPERTY, {0}, 0, NTE_BAD_FLAGS, TRUE}, + {NCRYPT_USE_COUNT_ENABLED_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_USE_COUNT_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_LAST_MODIFIED_PROPERTY, {0}, sizeof(FILETIME), NTE_NOT_FOUND, TRUE}, + {NCRYPT_WINDOW_HANDLE_PROPERTY, {0}, 0, NTE_NOT_FOUND, TRUE}, + {NCRYPT_MAX_NAME_LENGTH_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_ALGORITHM_GROUP_PROPERTY, {'R', 0, 'S', 0, 'A', 0}, sizeof(L"RSA")}, + {NCRYPT_PROVIDER_HANDLE_PROPERTY, {0}, sizeof(NCRYPT_PROV_HANDLE), ERROR_SUCCESS}, + {NCRYPT_PIN_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_READER_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_SMARTCARD_GUID_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_CERTIFICATE_PROPERTY, {0}, 0, NTE_NOT_FOUND, TRUE, NTE_NOT_SUPPORTED /* Win 7 */}, + {NCRYPT_PIN_PROMPT_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_USER_CERTSTORE_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_ROOT_CERTSTORE_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_SECURE_PIN_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_ASSOCIATED_ECDH_KEY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_SCARD_PIN_ID, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {NCRYPT_SCARD_PIN_INFO, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + /* BCrypt properties */ + {BCRYPT_ALGORITHM_NAME, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_AUTH_TAG_LENGTH, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_BLOCK_LENGTH, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_BLOCK_SIZE_LIST, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_CHAINING_MODE, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_EFFECTIVE_KEY_LENGTH, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_HASH_BLOCK_LENGTH, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_HASH_LENGTH, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_HASH_OID_LIST, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_KEY_LENGTH, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_KEY_LENGTHS, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_KEY_OBJECT_LENGTH, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_KEY_STRENGTH, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_OBJECT_LENGTH, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_PADDING_SCHEMES, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_PROVIDER_HANDLE, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, + {BCRYPT_SIGNATURE_LENGTH, {0x80, 0, 0, 0} /* 128 */, sizeof(DWORD), ERROR_SUCCESS, TRUE, NTE_NOT_SUPPORTED /* <= Win 8 */}, + {BCRYPT_PUBLIC_KEY_LENGTH, {0, 0x4} /* 1024 */, sizeof(DWORD), ERROR_SUCCESS, TRUE, NTE_NOT_SUPPORTED /* <= Win 8 */}, + }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(properties); i++) + { + if (!lstrcmpW(properties[i].name, NCRYPT_PROVIDER_HANDLE_PROPERTY)) + memcpy(properties[i].expected_data, &prov, sizeof(prov)); + + check_property(line, key, &properties[i]); + } +} + static void test_key_import_rsa(void) { NCRYPT_PROV_HANDLE prov; @@ -168,39 +377,28 @@ static void test_get_property(void) NCRYPT_PROV_HANDLE prov; NCRYPT_KEY_HANDLE key; SECURITY_STATUS ret; - WCHAR value[4]; DWORD keylength, size;
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); - - 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); + ret = NCryptGetProperty(0, NCRYPT_LENGTH_PROPERTY, (BYTE *)&keylength, size, &size, 0); + ok(ret == NTE_INVALID_HANDLE, "got %#lx\n", ret);
- size = 0; - value[0] = 0; - ret = NCryptGetProperty(key, NCRYPT_ALGORITHM_GROUP_PROPERTY, (BYTE *)value, sizeof(value), &size, 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); - ok(size == 8, "got %lu\n", size); - ok(!lstrcmpW(value, L"RSA"), "The string doesn't match with 'RSA'\n"); + check_properties(prov, key); + NCryptFreeObject(key);
- size = 0; - ret = NCryptGetProperty(key, NCRYPT_LENGTH_PROPERTY, NULL, 0, &size, 0); + ret = NCryptImportKey(prov, 0, BCRYPT_RSAPRIVATE_BLOB, NULL, &key, rsa_private_key_blob, sizeof(rsa_private_key_blob), 0); ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); - ok(size == sizeof(DWORD), "got %lu\n", size); + check_properties(prov, key); + NCryptFreeObject(key);
- keylength = 0; - ret = NCryptGetProperty(key, NCRYPT_LENGTH_PROPERTY, (BYTE *)&keylength, size, &size, 0); + ret = NCryptImportKey(prov, 0, BCRYPT_RSAFULLPRIVATE_BLOB, NULL, &key, rsa_full_private_key_blob, sizeof(rsa_full_private_key_blob), 0); ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); - ok(keylength == 1024, "got %lu\n", keylength); - - ret = NCryptGetProperty(0, NCRYPT_LENGTH_PROPERTY, (BYTE *)&keylength, size, &size, 0); - ok(ret == NTE_INVALID_HANDLE, "got %#lx\n", ret); + check_properties(prov, key); + NCryptFreeObject(key);
NCryptFreeObject(prov); } @@ -258,8 +456,6 @@ static void test_create_persisted_key(void) NCRYPT_PROV_HANDLE prov; NCRYPT_KEY_HANDLE key; SECURITY_STATUS ret; - DWORD size, keylength; - WCHAR alggroup[4];
ret = NCryptOpenStorageProvider(&prov, NULL, 0); ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); @@ -275,21 +471,7 @@ static void test_create_persisted_key(void) 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; - alggroup[0] = 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(keylength), &size, 0); - ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); - ok(size == 4, "got %lu\n", size); - ok(keylength == 1024, "got %lu\n", keylength); + check_properties(prov, key);
NCryptFinalizeKey(key, 0); NCryptFreeObject(key);
From: Zhiyi Zhang zzhang@codeweavers.com
--- dlls/ncrypt/main.c | 18 ++++++++++++++++++ dlls/ncrypt/tests/ncrypt.c | 16 ++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c index 8a720382bef..3511f8f2d3f 100644 --- a/dlls/ncrypt/main.c +++ b/dlls/ncrypt/main.c @@ -128,7 +128,9 @@ 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) { + NCRYPT_SUPPORTED_LENGTHS supported_lengths = {512, 16384, 8, 1024}; struct object *object; + DWORD dw_value;
switch (algid) { @@ -136,8 +138,16 @@ static struct object *create_key_object(enum algid algid, NCRYPT_PROV_HANDLE pro if (!(object = allocate_object(KEY))) return NULL;
object->key.algid = RSA; + set_object_property(object, NCRYPT_ALGORITHM_PROPERTY, (BYTE *)BCRYPT_RSA_ALGORITHM, + sizeof(BCRYPT_RSA_ALGORITHM)); set_object_property(object, NCRYPT_ALGORITHM_GROUP_PROPERTY, (BYTE *)BCRYPT_RSA_ALGORITHM, sizeof(BCRYPT_RSA_ALGORITHM)); + set_object_property(object, NCRYPT_LENGTHS_PROPERTY, (BYTE *)&supported_lengths, + sizeof(supported_lengths)); + dw_value = 128; + set_object_property(object, NCRYPT_BLOCK_LENGTH_PROPERTY, (BYTE *)&dw_value, sizeof(dw_value)); + dw_value = 128; + set_object_property(object, BCRYPT_SIGNATURE_LENGTH, (BYTE *)&dw_value, sizeof(dw_value)); break;
default: @@ -145,6 +155,12 @@ static struct object *create_key_object(enum algid algid, NCRYPT_PROV_HANDLE pro return NULL; }
+ dw_value = 0; + set_object_property(object, NCRYPT_EXPORT_POLICY_PROPERTY, (BYTE *)&dw_value, sizeof(dw_value)); + dw_value = NCRYPT_ALLOW_ALL_USAGES; + set_object_property(object, NCRYPT_KEY_USAGE_PROPERTY, (BYTE *)&dw_value, sizeof(dw_value)); + dw_value = 0; + set_object_property(object, NCRYPT_KEY_TYPE_PROPERTY, (BYTE *)&dw_value, sizeof(dw_value)); set_object_property(object, NCRYPT_PROVIDER_HANDLE_PROPERTY, (BYTE *)&provider, sizeof(provider)); return object; } @@ -181,6 +197,7 @@ SECURITY_STATUS WINAPI NCryptCreatePersistedKey(NCRYPT_PROV_HANDLE provider, NCR }
set_object_property(object, NCRYPT_LENGTH_PROPERTY, (BYTE *)&default_bitlen, sizeof(default_bitlen)); + set_object_property(object, BCRYPT_PUBLIC_KEY_LENGTH, (BYTE *)&default_bitlen, sizeof(default_bitlen)); } else { @@ -401,6 +418,7 @@ SECURITY_STATUS WINAPI NCryptImportKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_H }
set_object_property(object, NCRYPT_LENGTH_PROPERTY, (BYTE *)&rsablob->BitLength, sizeof(rsablob->BitLength)); + set_object_property(object, BCRYPT_PUBLIC_KEY_LENGTH, (BYTE *)&rsablob->BitLength, sizeof(rsablob->BitLength)); break; } default: diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index 572b325a04c..5f32f62bbf7 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -232,17 +232,17 @@ static void _check_properties(int line, NCRYPT_PROV_HANDLE prov, NCRYPT_KEY_HAND /* NCrypt properties */ {NCRYPT_NAME_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, {NCRYPT_UNIQUE_NAME_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, - {NCRYPT_ALGORITHM_PROPERTY, {'R', 0, 'S', 0, 'A', 0}, sizeof(L"RSA"), ERROR_SUCCESS, TRUE}, + {NCRYPT_ALGORITHM_PROPERTY, {'R', 0, 'S', 0, 'A', 0}, sizeof(L"RSA"), ERROR_SUCCESS}, {NCRYPT_LENGTH_PROPERTY, {0, 0x4} /* 1024 */, sizeof(DWORD)}, - {NCRYPT_LENGTHS_PROPERTY, {0, 0x2, 0, 0, 0, 0x40, 0, 0, 0x8, 0, 0, 0, 0, 0x4, 0, 0}, sizeof(DWORD) * 4 /* NCRYPT_SUPPORTED_LENGTHS */, ERROR_SUCCESS, TRUE, ERROR_SUCCESS, {0, 0x2, 0, 0, 0, 0x40, 0, 0, 0x40, 0, 0, 0, 0, 0x4, 0, 0}}, - {NCRYPT_BLOCK_LENGTH_PROPERTY, {0x80, 0, 0, 0}, sizeof(DWORD), ERROR_SUCCESS, TRUE}, + {NCRYPT_LENGTHS_PROPERTY, {0, 0x2, 0, 0, 0, 0x40, 0, 0, 0x8, 0, 0, 0, 0, 0x4, 0, 0}, sizeof(DWORD) * 4 /* NCRYPT_SUPPORTED_LENGTHS */, ERROR_SUCCESS, FALSE, ERROR_SUCCESS, {0, 0x2, 0, 0, 0, 0x40, 0, 0, 0x40, 0, 0, 0, 0, 0x4, 0, 0}}, + {NCRYPT_BLOCK_LENGTH_PROPERTY, {0x80, 0, 0, 0}, sizeof(DWORD), ERROR_SUCCESS}, {NCRYPT_UI_POLICY_PROPERTY, {0}, sizeof(NCRYPT_UI_POLICY), NTE_NOT_FOUND, TRUE}, - {NCRYPT_EXPORT_POLICY_PROPERTY, {0}, sizeof(DWORD), ERROR_SUCCESS, TRUE}, + {NCRYPT_EXPORT_POLICY_PROPERTY, {0}, sizeof(DWORD), ERROR_SUCCESS}, {NCRYPT_WINDOW_HANDLE_PROPERTY, {0}, 0, NTE_NOT_FOUND, TRUE}, {NCRYPT_USE_CONTEXT_PROPERTY, {0}, 0, NTE_NOT_FOUND, TRUE}, {NCRYPT_IMPL_TYPE_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, - {NCRYPT_KEY_USAGE_PROPERTY, {0xff, 0xff, 0xff, 0} /* NCRYPT_ALLOW_ALL_USAGES */, sizeof(DWORD), ERROR_SUCCESS, TRUE}, - {NCRYPT_KEY_TYPE_PROPERTY, {0}, sizeof(DWORD), ERROR_SUCCESS, TRUE}, + {NCRYPT_KEY_USAGE_PROPERTY, {0xff, 0xff, 0xff, 0} /* NCRYPT_ALLOW_ALL_USAGES */, sizeof(DWORD), ERROR_SUCCESS}, + {NCRYPT_KEY_TYPE_PROPERTY, {0}, sizeof(DWORD), ERROR_SUCCESS}, {NCRYPT_VERSION_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, {NCRYPT_SECURITY_DESCR_SUPPORT_PROPERTY, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, {NCRYPT_SECURITY_DESCR_PROPERTY, {0}, 0, NTE_BAD_FLAGS, TRUE}, @@ -281,8 +281,8 @@ static void _check_properties(int line, NCRYPT_PROV_HANDLE prov, NCRYPT_KEY_HAND {BCRYPT_OBJECT_LENGTH, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, {BCRYPT_PADDING_SCHEMES, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, {BCRYPT_PROVIDER_HANDLE, {0}, 0, NTE_NOT_SUPPORTED, TRUE}, - {BCRYPT_SIGNATURE_LENGTH, {0x80, 0, 0, 0} /* 128 */, sizeof(DWORD), ERROR_SUCCESS, TRUE, NTE_NOT_SUPPORTED /* <= Win 8 */}, - {BCRYPT_PUBLIC_KEY_LENGTH, {0, 0x4} /* 1024 */, sizeof(DWORD), ERROR_SUCCESS, TRUE, NTE_NOT_SUPPORTED /* <= Win 8 */}, + {BCRYPT_SIGNATURE_LENGTH, {0x80, 0, 0, 0} /* 128 */, sizeof(DWORD), ERROR_SUCCESS, FALSE, NTE_NOT_SUPPORTED /* <= Win 8 */}, + {BCRYPT_PUBLIC_KEY_LENGTH, {0, 0x4} /* 1024 */, sizeof(DWORD), ERROR_SUCCESS, FALSE, NTE_NOT_SUPPORTED /* <= Win 8 */}, }; unsigned int i;
From: Zhiyi Zhang zzhang@codeweavers.com
--- dlls/ncrypt/tests/ncrypt.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index 5f32f62bbf7..d2c53c8d1b3 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -798,6 +798,37 @@ static void test_NCryptEncrypt(void) NCryptFreeObject(prov); }
+static void test_NCryptExportKey(void) +{ + NCRYPT_PROV_HANDLE prov; + NCRYPT_KEY_HANDLE key; + SECURITY_STATUS ret; + DWORD size, policy; + BYTE buffer[1024]; + + ret = NCryptOpenStorageProvider(&prov, NULL, 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + ret = NCryptCreatePersistedKey(prov, &key, BCRYPT_RSA_ALGORITHM, NULL, 0, 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + policy = NCRYPT_ALLOW_EXPORT_FLAG | NCRYPT_ALLOW_PLAINTEXT_EXPORT_FLAG; + ret = NCryptSetProperty(key, NCRYPT_EXPORT_POLICY_PROPERTY, (BYTE *)&policy, sizeof(policy), 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + NCryptFinalizeKey(key, 0); + + size = 0; + ret = NCryptExportKey(key, 0, BCRYPT_RSAPRIVATE_BLOB, NULL, buffer, sizeof(buffer), &size, 0); + ok(ret == ERROR_SUCCESS, "got unexpected return value %lx\n", ret); + ok(size == 283, "got unexpected size %#lx\n", size); + + size = 0; + ret = NCryptExportKey(key, 0, BCRYPT_RSAFULLPRIVATE_BLOB, NULL, buffer, sizeof(buffer), &size, 0); + ok(ret == ERROR_SUCCESS, "got unexpected return value %lx\n", ret); + ok(size == 603, "got unexpected size %#lx\n", size); + + NCryptFreeObject(key); + NCryptFreeObject(prov); +} + START_TEST(ncrypt) { test_key_import_rsa(); @@ -809,4 +840,5 @@ START_TEST(ncrypt) test_verify_signature(); test_NCryptIsAlgSupported(); test_NCryptEncrypt(); + test_NCryptExportKey(); }
This merge request was approved by Hans Leidekker.