1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-12-24 19:37:49 +03:00

Fixes when server/client uses encryption method with integrated MAC and the other doesn't (#1582)

Notes:
Connection fails when server/client uses one encryption method with integrated MAC and one without.

Credit:
Christian Ghisler
This commit is contained in:
chrisgch
2025-05-21 22:38:11 +02:00
committed by GitHub
parent 9136cc763b
commit d8ae40bad0

View File

@@ -134,7 +134,7 @@ decrypt(LIBSSH2_SESSION * session, unsigned char *source,
/* if we get called with a len that isn't an even number of blocksizes
we risk losing those extra bytes. AAD is an exception, since those first
few bytes aren't encrypted so it throws off the rest of the count. */
if(!CRYPT_FLAG_L(session, PKTLEN_AAD))
if(!CRYPT_FLAG_R(session, PKTLEN_AAD))
assert((len % blocksize) == 0);
while(len > 0) {
@@ -149,7 +149,7 @@ decrypt(LIBSSH2_SESSION * session, unsigned char *source,
/* If the last block would be less than a whole blocksize, combine it
with the previous block to make it larger. This ensures that the
whole MAC is included in a single decrypt call. */
if(CRYPT_FLAG_L(session, PKTLEN_AAD) && IS_LAST(firstlast)
if(CRYPT_FLAG_R(session, PKTLEN_AAD) && IS_LAST(firstlast)
&& (len < blocksize*2)) {
decryptlen = len;
lowerfirstlast = LAST_BLOCK;
@@ -1051,7 +1051,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0;
if(encrypted && session->local.crypt &&
CRYPT_FLAG_R(session, REQUIRES_FULL_PACKET)) {
CRYPT_FLAG_L(session, REQUIRES_FULL_PACKET)) {
auth_len = session->local.crypt->auth_len;
}
else {
@@ -1124,7 +1124,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
/* subtract 4 bytes of the packet_length field when padding AES-GCM
or with ETM */
crypt_offset = (etm || auth_len ||
(encrypted && CRYPT_FLAG_R(session, PKTLEN_AAD)))
(encrypted && CRYPT_FLAG_L(session, PKTLEN_AAD)))
? 4 : 0;
etm_crypt_offset = etm ? 4 : 0;