-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TestSSHAgent::testKeyGenRSA() fails occasionally: bignum is negative #10320
Comments
I'm not going to work on this (at least not now), so here are my thoughts:
|
Interesting, I don't think I've seen this failure in the CI before, it may be recent. Perhaps a new botan update or similar that caused it. |
tried to bisect but it's already in the introducing commit 3243243b |
That leads me to a library issue then. We have not had this problem in the past, certainly not as reproducing as you have |
That was the correct hint! Botan does not pad bigints on its own. If a (positive) bignum has the MSB set, it will render it just like that. However, ssh-agent does assume a negative number in that case: /~https://github.com/openssh/openssh-portable/blob/3deb501f86fc47e175ef6a3eaba9b9846a80d444/sshbuf-getput-basic.c#L610-L612. If I'm not mistaken, your ssh-agent adapter even pads the relevant bignum parameters by calling the helper keepassxc/src/sshagent/OpenSSHKeyGen.cpp Line 68 in dff2f18
In fact, as an experiment, I created 1,000 RSA key pairs and 22 of them had the MSB of |
Is |
Its not guaranteed, though typically |
So if we pad just one byte to ensure MSB is zero, then all is well? Sorry I'm not a bignum expert. I assume changing the call to write the |
For the record: I didn't look into the underlying communication protocol with the ssh-agent; and whether the extra padding byte would cause problems of some sort. But technically: yes, the padding bytes should fix this. |
Add the padding to I also tried to only add the padding when void bigIntToStream(const Botan::BigInt& i, BinaryStream& stream, int padding = 0)
{
if (i.is_positive()) {
QByteArray ba(i.bytes(), 0);
i.binary_encode(reinterpret_cast<uint8_t*>(ba.data()), ba.size());
stream.writeString(ba);
} else {
// Add one byte of padding to enforce positive BigNum
QByteArray ba(i.bytes() + 1, 0);
i.binary_encode(reinterpret_cast<uint8_t*>(ba.data() + 1), ba.size() - 1);
stream.writeString(ba);
}
} |
Regarding your conditional padding: Botan uses an internal flag to keep track of the bigint signedness. So Edit: sorry, there's a Try this, perhaps: void bigIntToStream(const Botan::BigInt& i, BinaryStream& stream, int padding = 0)
{
if (i.bits() > 0 && i.get_bit(i.bits() - 1)) {
QByteArray ba(i.bytes(), 0);
i.binary_encode(reinterpret_cast<uint8_t*>(ba.data()), ba.size());
stream.writeString(ba);
} else {
// Add one byte of padding to enforce positive BigNum
QByteArray ba(i.bytes() + 1, 0);
i.binary_encode(reinterpret_cast<uint8_t*>(ba.data() + 1), ba.size() - 1);
stream.writeString(ba);
}
} |
Overview
Every now and then
TestSSHAgent::testKeyGenRSA()
fails:Steps to Reproduce
Running the test until it fails breaks within seconds:
while ./build/tests/testsshagent testKeyGenRSA; do :; done
Expected Behavior
Should not fail.
Actual Behavior
In 10000 tries the test failed 232 times.
Context
CI failed when I was working on #10252 . However, I can also reproduce on current develop branch.
KeePassXC - Version 2.8.0-snapshot
Build-Typ: Snapshot
Revision: 4aed671
Operating System: Linux
Desktop Env: i3
Windowing System: X11
The text was updated successfully, but these errors were encountered: