Commit c39977f2 authored by Christian Kandeler's avatar Christian Kandeler

SSH: Fix composition of ECDH key exchange signature.

We need to pad the encoded integers to the full width, so the
signature will have the correct length.

Change-Id: Ic844a5996ed3d8a121847d09aae1a7782ee2c24c
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent 6b2917a2
......@@ -130,5 +130,13 @@ QByteArray SshCapabilities::findBestMatch(const QList<QByteArray> &myCapabilitie
return commonCapabilities(myCapabilities, serverCapabilities).first();
}
int SshCapabilities::ecdsaIntegerWidthInBytes(const QByteArray &ecdsaAlgo)
{
if (ecdsaAlgo == PubKeyEcdsa256)
return 32;
throw SshClientException(SshInternalError, SSH_TR("Unexpected ecdsa algorithm \"%1\"")
.arg(QString::fromLatin1(ecdsaAlgo)));
}
} // namespace Internal
} // namespace QSsh
......@@ -76,6 +76,8 @@ public:
const QList<QByteArray> &serverCapabilities);
static QByteArray findBestMatch(const QList<QByteArray> &myCapabilities,
const QList<QByteArray> &serverCapabilities);
static int ecdsaIntegerWidthInBytes(const QByteArray &ecdsaAlgo);
};
} // namespace Internal
......
......@@ -194,6 +194,11 @@ static void getHostKeySpecificReplyData(SshKeyExchangeReply &replyData,
}
}
static QByteArray &padToWidth(QByteArray &data, int targetWidth)
{
return data.prepend(QByteArray(targetWidth - data.count(), 0));
}
SshKeyExchangeReply SshIncomingPacket::extractKeyExchangeReply(const QByteArray &kexAlgo,
const QByteArray &hostKeyAlgo) const
{
......@@ -226,8 +231,11 @@ SshKeyExchangeReply SshIncomingPacket::extractKeyExchangeReply(const QByteArray
quint32 blobOffset = 0;
const Botan::BigInt r = SshPacketParser::asBigInt(replyData.signatureBlob, &blobOffset);
const Botan::BigInt s = SshPacketParser::asBigInt(replyData.signatureBlob, &blobOffset);
replyData.signatureBlob = convertByteArray(Botan::BigInt::encode(r));
replyData.signatureBlob += convertByteArray(Botan::BigInt::encode(s));
const int width = SshCapabilities::ecdsaIntegerWidthInBytes(hostKeyAlgo);
QByteArray encodedR = convertByteArray(Botan::BigInt::encode(r));
replyData.signatureBlob = padToWidth(encodedR, width);
QByteArray encodedS = convertByteArray(Botan::BigInt::encode(s));
replyData.signatureBlob += padToWidth(encodedS, width);
}
replyData.k_s.prepend(m_data.mid(TypeOffset + 1, 4));
return replyData;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment