]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
encrypted-payload: Change how the length for reassembled messages is calculated
authorTobias Brunner <tobias@strongswan.org>
Thu, 5 Jul 2018 15:21:47 +0000 (17:21 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 9 Jul 2018 15:25:02 +0000 (17:25 +0200)
If we have an AEAD transform we add the overhead as if the data would have
been transported in a single encrypted payload.

src/libcharon/encoding/payloads/encrypted_payload.c

index 2e9dd686d7cea7fd7dd34b4d60ccc76cabfa55f1..ba56ace55ec25b25126224d8e05f640174d5389a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011-2014 Tobias Brunner
+ * Copyright (C) 2011-2018 Tobias Brunner
  * Copyright (C) 2005-2010 Martin Willi
  * Copyright (C) 2010 revosec AG
  * Copyright (C) 2005 Jan Hutter
@@ -326,6 +326,21 @@ METHOD2(payload_t, encrypted_payload_t, get_length, size_t,
        return this->payload_length;
 }
 
+METHOD2(payload_t, encrypted_payload_t, get_length_plain, size_t,
+       private_encrypted_payload_t *this)
+{
+       /* contains only the decrypted payload data, no IV, padding or ICV */
+       this->payload_length = this->encrypted.len;
+
+       if (this->aead)
+       {
+               this->payload_length += compute_overhead(this->aead,
+                                                                                                this->payload_length);
+       }
+       this->payload_length += get_header_length(this);
+       return this->payload_length;
+}
+
 METHOD(encrypted_payload_t, add_payload, void,
        private_encrypted_payload_t *this, payload_t *payload)
 {
@@ -794,10 +809,11 @@ encrypted_payload_t *encrypted_payload_create_from_plain(payload_type_t next,
        private_encrypted_payload_t *this;
 
        this = (private_encrypted_payload_t*)encrypted_payload_create(PLV2_ENCRYPTED);
+       this->public.payload_interface.get_length = _get_length_plain;
+       this->public.get_length = _get_length_plain;
        this->public.decrypt = _decrypt_plain;
        this->next_payload = next;
        this->encrypted = plain;
-       compute_length(this);
 
        return &this->public;
 }