Repository navigation
wincng: add ECDSA support for host and user authentication - #1315
Conversation
|
@willco007 and @vszakats, would you mind taking another look? Thanks! |
|
@jpassing Would you mind investigating the failures here? Thanks. |
Yes, sorry for the delay. Added the missing declarations. I don't have a linux/mingw64 setup locally. so I have to rely on the CI build to check whether it's ok now. |
|
Would it be possible to trigger the CI again? I hope my last commits fixed the remaining build issues. |
|
Thanks! Unfortunatelty some tests failed because of issues unrelated to this PR: Could you trigger it once again, please? |
|
More intermittent Let's wait a few hours and try again? |
|
@jpassing The intermittent issue was the xz backdoor most probably. It should be okay now. |
3f9b340 to
bb2e9c0
Compare
7e20de5 to
ceabf6a
Compare
|
There is a what looks like a crash happening while running tests in job The job fails consistently: |
|
Yes... I was able to reproduce the crash on 8.1 and it looks like an access violation, possibly caused by a double-free. I'll have a closer look at why this is happening. |
|
The last commit fixed the crash and tests on Windows Server 2012 are now failing with It's quite possible that CNG on Windows Server 2012 doesn't support all required feature yet, but I'll have to verify that. |
The problematic line of code is the call to
The documentation for
But the documentation doesn't distinguish between RSA and ECC, and it's possible that ECC support was added later. Interestingly, the .NET runtime guards calls with a Windows Server 2012 R2 and Windows 8.1 are both out of support, so I figure it might be okay if WinCNG/ECDSA doesn't work on these platforms? If so, is there any established pattern that I could use to ensure we skip respective tests when executed on these Windows versions? |
|
|
||
| *signature = NULL; | ||
| *signature_length = (size_t) | ||
| _wincng_ecdsa_algorithms[curve].point_length * 2; |
There was a problem hiding this comment.
Would it be useful to check for a possible overflow?
There was a problem hiding this comment.
_wincng_ecdsa_algorithms[curve].point_length is a constant, so I'd say that an overflow check is uneccessary.
It's fine to not support it on these versions (do we have any other choice?). But, we don't have a pattern to skip tests based on runtime availability of algos yet. Also, we don't have plumbing for Windows version detection — this can lead into a rabbit whole, also with manifests, so I'd be happy to avoid it. Do I understand correctly that This reminds of these earlier commit dealing with a similar scenario (with version detection briefly introduced, then solved differently): Do I understand correctly that:
/cc @mback2k |
Yes, exactly. So it's not that ECDSA isn't supported at all on older Windows versions, it's just that this particular function/flag combination doesn't seem to be implemented.
I think it's the same issue: IIUC, with RSA, the solution was to attempt to use The issue with ECDSA is that we don't have an alternate method to fall back to... or at least I'm not aware of one. I agree that checking Windows versions tends to be complex and/or unreliable, so I'd rather avoid that -- at least within the library. Testing in advance if What might work is the following:
Wdyt? |
|
For tests the Thinking of downstream code trying to use libssh2 though, I'm not sure this would be workable without breaking those when run in an unfit (pre-10) Windows env. Those apps either need to keep ECDSA disabled from the get go or fallback to something else automatically. This brings back to a reliable / fast / manifest-less (end-user apps may not have manifests, nor do our tests), feature or Windows 10 detection on init. Could Or perhaps There is Another option is to enable this only when building for Win10 or higher based on |
That's a good point. I'm sure we could do a Windows version check somehow, but I worry that it would be a high-impact change: All places that currently use
Guarding the feature by a If That would also block |
That'd be harsh indeed. It means it's not enough to do this once in
Good idea, we can go with it. The mingw-w64 equivalent for the MSVC linker option above seems to be: I propose using the names |
) The WinCNG backend currently only supports DSA and RSA. This PR adds ECDSA support for host and user authentication. * Disable WinCNG ECDSA support by default to maintain backward compatibility for projects that target versions below Windows 10. * Add cmake option `ENABLE_ECDSA_WINCNG` to guard ECDSA support. * Update AppVeyor job matrix to only enable ECDSA on Server 2016+
- add `./configure` option `--enable-ecdsa-wincng` - add WinCNG autotools jobs to GHA. - enable WinCNG ECDSA in some GHA jobs (both CMake and autotools). Follow-up to 3e72343 libssh2#1315 Closes libssh2#1368
To make sure the null-terminator is present after the magic string. Refs: https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key https://anongit.mindrot.org/openssh.git/tree/PROTOCOL.key Reported by Copilot Bug: #2014 (comment) Bug: #2014 (comment) Follow-up to 3e72343 #1315 Follow-up to 0309229 #248 Closes #2022
"When `wcng_uncompressed_point_from_publickey` fails, `result` is set to an error code but execution falls through into the `malloc` / struct initialization block instead of jumping to `cleanup`. This causes `*out_private_key` to be allocated and populated even in the error path. At `cleanup`, the key handle is destroyed via `BCryptDestroyKey` and `*out_private_key` is freed, but the pointer is not set to NULL, leaving the caller with a dangling pointer. A `goto cleanup` should follow the `ssh2_err` call." Reported by GitHub Code Quality Follow-up to 3e72343 #1315 Closes #2190
"In `ssh2_ecdh_gen_k`, `agreed_secret_handle` is only destroyed when `result != LIBSSH2_ERROR_NONE`. On the success path, the handle is never passed to `BCryptDestroySecret`, causing a resource leak. The handle should be destroyed unconditionally in the cleanup block, regardless of success or failure." Ref: 2f7f107 #2038 Follow-up to 3e72343 #1315 Closes #2299
To match rest of code. Follow-up to 3e72343 libssh2#1315
Reported by GitHub Code Quality Follow-up to 3e72343 libssh2#1315
Ref: #2300 (comment) Ref: #2301 (comment) Follow-up to 3e72343 #1315 Closes #2306
- reuse `pem.c/ssh2_openssh_pem_parse()` in `ssh2_ecdsa_new_private()`, replacing the generic PEM parser used prior to this patch. - reuse `pem.c/ssh2_openssh_pem_parse_memory()` in `ssh2_ecdsa_new_private_frommemory()`. - optimize out local `wcng_load_pem()`. - move ECDSA key macros to from `crypto.h` to `pem.c`. To avoid code duplication, and also to hopefully enable support for passphrased OpenSSH-format ECDSA private keys with WinCNG. Build tested only. Fixes #1517 Follow-up to 3e72343 #1315 Closes #2279
`wcng_privatekey_from_point()` sizes the ECC private-key blob with `sizeof(BCRYPT_ECCPRIVATE_BLOB)`, but that name is the wide blob-type string `L"ECCPRIVATEBLOB"`, not a struct, so the `sizeof` measures the string (30 bytes on Windows) rather than the 8-byte `BCRYPT_ECCKEY_BLOB` header. The three `memcpy` offsets right below it, and the public-key sibling `wcng_publickey_from_point()`, already use `sizeof(BCRYPT_ECCKEY_BLOB)`, so the buffer ends up oversized and its uninitialized tail is handed to `BCryptImportKeyPair()` with an inflated `cbInput`. This is on the path that loads an OpenSSH-format ECDSA private key through `libssh2_userauth_publickey_frommemory()`/`fromfile()` on the CNG backend. Using `sizeof(BCRYPT_ECCKEY_BLOB)` lines the allocation up with the header the copies actually write from and with the length passed to `BCryptImportKeyPair()`. Keeping it in step with the public-key path means the private blob is described to CNG with exactly the bytes it holds. Follow-up to 3e72343 #1315 Closes #2631
The WinCNG backend currently only supports DSA and RSA. This PR adds
ECDSA support for host and user authentication.
I'd appreciate if someone could take a look.