Flight Simulator XAL authentication hits this condition because of buggy bcrypt private key export (see next patch).
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/bcrypt/bcrypt_main.c | 4 ++-- dlls/bcrypt/tests/bcrypt.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c index b6bb73a715f..cd3b746e295 100644 --- a/dlls/bcrypt/bcrypt_main.c +++ b/dlls/bcrypt/bcrypt_main.c @@ -1171,7 +1171,7 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP return STATUS_NOT_SUPPORTED; }
- if (ecc_blob->dwMagic != magic) return STATUS_NOT_SUPPORTED; + if (ecc_blob->dwMagic != magic) return STATUS_INVALID_PARAMETER; if (ecc_blob->cbKey != key_size || input_len < sizeof(*ecc_blob) + ecc_blob->cbKey * 2) return STATUS_INVALID_PARAMETER;
@@ -1211,7 +1211,7 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP return STATUS_NOT_SUPPORTED; }
- if (ecc_blob->dwMagic != magic) return STATUS_NOT_SUPPORTED; + if (ecc_blob->dwMagic != magic) return STATUS_INVALID_PARAMETER; if (ecc_blob->cbKey != key_size || input_len < sizeof(*ecc_blob) + ecc_blob->cbKey * 3) return STATUS_INVALID_PARAMETER;
diff --git a/dlls/bcrypt/tests/bcrypt.c b/dlls/bcrypt/tests/bcrypt.c index e37a33e38a0..3e5d5cf17f8 100644 --- a/dlls/bcrypt/tests/bcrypt.c +++ b/dlls/bcrypt/tests/bcrypt.c @@ -1730,6 +1730,12 @@ static void test_ECDSA(void) status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &key, buffer, size, 0); ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
+ ecckey->dwMagic = BCRYPT_ECDH_PUBLIC_P256_MAGIC; + ecckey->cbKey = 32; + status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &key, buffer, size, 0); + ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %08x\n", status); + + ecckey->dwMagic = BCRYPT_ECDSA_PUBLIC_P256_MAGIC; ecckey->cbKey = 32; status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &key, buffer, size, 0); ok(!status, "BCryptImportKeyPair failed: %08x\n", status); @@ -1749,6 +1755,12 @@ static void test_ECDSA(void) status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &key, buffer, size, 0); ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
+ ecckey->dwMagic = BCRYPT_ECDH_PRIVATE_P256_MAGIC; + ecckey->cbKey = 32; + status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &key, buffer, size, 0); + ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %08x\n", status); + + ecckey->dwMagic = BCRYPT_ECDSA_PRIVATE_P256_MAGIC; ecckey->cbKey = 32; status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &key, buffer, size, 0); ok(!status, "BCryptImportKeyPair failed: %08x\n", status);
This fixes Flight Simulator XAL authentication error message.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/bcrypt/gnutls.c | 24 +++++++++++++++++------- dlls/bcrypt/tests/bcrypt.c | 8 ++++++++ 2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/dlls/bcrypt/gnutls.c b/dlls/bcrypt/gnutls.c index a80bce47f95..f9c021969f7 100644 --- a/dlls/bcrypt/gnutls.c +++ b/dlls/bcrypt/gnutls.c @@ -894,20 +894,30 @@ NTSTATUS key_export_ecc( struct key *key, UCHAR *buf, ULONG len, ULONG *ret_len UCHAR *src, *dst; int ret;
+ switch (key->alg_id) + { + case ALG_ID_ECDH_P256: + magic = BCRYPT_ECDH_PRIVATE_P256_MAGIC; + size = 32; + break; + case ALG_ID_ECDSA_P256: + magic = BCRYPT_ECDSA_PRIVATE_P256_MAGIC; + size = 32; + break; + + default: + FIXME( "algorithm %u does not yet support exporting ecc blob\n", key->alg_id ); + return STATUS_NOT_IMPLEMENTED; + } + if ((ret = pgnutls_privkey_export_ecc_raw( key->u.a.handle, &curve, &x, &y, &d ))) { pgnutls_perror( ret ); return STATUS_INTERNAL_ERROR; }
- switch (curve) + if (curve != GNUTLS_ECC_CURVE_SECP256R1) { - case GNUTLS_ECC_CURVE_SECP256R1: - magic = BCRYPT_ECDH_PRIVATE_P256_MAGIC; - size = 32; - break; - - default: FIXME( "curve %u not supported\n", curve ); free( x.data ); free( y.data ); free( d.data ); return STATUS_NOT_IMPLEMENTED; diff --git a/dlls/bcrypt/tests/bcrypt.c b/dlls/bcrypt/tests/bcrypt.c index 3e5d5cf17f8..7fdc0ac7fb2 100644 --- a/dlls/bcrypt/tests/bcrypt.c +++ b/dlls/bcrypt/tests/bcrypt.c @@ -1765,6 +1765,14 @@ static void test_ECDSA(void) status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &key, buffer, size, 0); ok(!status, "BCryptImportKeyPair failed: %08x\n", status);
+ memset( buffer, 0, sizeof(buffer) ); + status = pBCryptExportKey(key, NULL, BCRYPT_ECCPRIVATE_BLOB, buffer, size, &size, 0); + ok(status == STATUS_SUCCESS, "got %08x\n", status); + ecckey = (BCRYPT_ECCKEY_BLOB *)buffer; + ok(ecckey->dwMagic == BCRYPT_ECDSA_PRIVATE_P256_MAGIC, "got %08x\n", ecckey->dwMagic); + ok(ecckey->cbKey == 32, "got %u\n", ecckey->cbKey); + ok(size == sizeof(*ecckey) + ecckey->cbKey * 3, "got %u\n", size); + pBCryptDestroyKey(key); pBCryptCloseAlgorithmProvider(alg, 0); }