diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2023-08-07 18:03:42 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2023-08-07 18:03:42 +0200 |
commit | 182981a5dcb1285a8dc40f7661bbca96ffaa1df2 (patch) | |
tree | 927a0a004b551a3075d4f1cf05a120fd1876948e /src/messenger/messenger_api_message.c | |
parent | 689abc4fbfdf2d30f96bb992a6be0b0ee4d05548 (diff) | |
download | gnunet-182981a5dcb1285a8dc40f7661bbca96ffaa1df2.tar.gz gnunet-182981a5dcb1285a8dc40f7661bbca96ffaa1df2.zip |
MESSENGER: Update private message using new IDENTITY encyption
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/messenger/messenger_api_message.c')
-rw-r--r-- | src/messenger/messenger_api_message.c | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c index 0e27588ba..7b493f760 100644 --- a/src/messenger/messenger_api_message.c +++ b/src/messenger/messenger_api_message.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 GNUnet e.V. | 3 | Copyright (C) 2020--2023 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -858,29 +858,32 @@ encrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
858 | fold_short_message (message, &shortened); | 858 | fold_short_message (message, &shortened); |
859 | 859 | ||
860 | const uint16_t length = get_short_message_size (&shortened, GNUNET_YES); | 860 | const uint16_t length = get_short_message_size (&shortened, GNUNET_YES); |
861 | const uint16_t padded_length = calc_padded_length (length); | 861 | const uint16_t padded_length = calc_padded_length ( |
862 | length + GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES | ||
863 | ); | ||
862 | 864 | ||
863 | message->header.kind = GNUNET_MESSENGER_KIND_PRIVATE; | 865 | message->header.kind = GNUNET_MESSENGER_KIND_PRIVATE; |
864 | message->body.privacy.data = GNUNET_malloc (padded_length); | 866 | message->body.privacy.data = GNUNET_malloc (padded_length); |
865 | message->body.privacy.length = padded_length; | 867 | message->body.privacy.length = padded_length; |
868 | |||
869 | const uint16_t encoded_length = padded_length - GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES; | ||
866 | 870 | ||
867 | encode_short_message (&shortened, padded_length, message->body.privacy.data); | 871 | encode_short_message (&shortened, encoded_length, message->body.privacy.data); |
868 | 872 | ||
869 | if (padded_length == GNUNET_IDENTITY_encrypt_old (message->body.privacy.data, | 873 | if (GNUNET_OK != GNUNET_IDENTITY_encrypt (message->body.privacy.data, |
870 | padded_length, key, | 874 | encoded_length, |
871 | &(message->body.privacy.key), | 875 | key, |
872 | message->body.privacy.data)) | 876 | message->body.privacy.data, |
873 | { | 877 | padded_length)) |
874 | destroy_message_body (shortened.kind, &(shortened.body)); | ||
875 | return GNUNET_YES; | ||
876 | } | ||
877 | else | ||
878 | { | 878 | { |
879 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n"); | 879 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n"); |
880 | 880 | ||
881 | unfold_short_message (&shortened, message); | 881 | unfold_short_message (&shortened, message); |
882 | return GNUNET_NO; | 882 | return GNUNET_NO; |
883 | } | 883 | } |
884 | |||
885 | destroy_message_body (shortened.kind, &(shortened.body)); | ||
886 | return GNUNET_YES; | ||
884 | } | 887 | } |
885 | 888 | ||
886 | 889 | ||
@@ -890,22 +893,32 @@ decrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
890 | { | 893 | { |
891 | GNUNET_assert ((message) && (key)); | 894 | GNUNET_assert ((message) && (key)); |
892 | 895 | ||
893 | if (message->body.privacy.length != GNUNET_IDENTITY_decrypt_old ( | 896 | const uint16_t padded_length = message->body.privacy.length; |
894 | message->body.privacy.data, message->body.privacy.length, | 897 | |
895 | key, | 898 | if (padded_length < GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES) |
896 | &(message->body.privacy.key), | ||
897 | message->body. | ||
898 | privacy.data)) | ||
899 | { | 899 | { |
900 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Decrypting message failed!\n"); | 900 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Message length too short to decrypt!\n"); |
901 | 901 | ||
902 | return GNUNET_NO; | 902 | return GNUNET_NO; |
903 | } | 903 | } |
904 | 904 | ||
905 | const uint16_t encoded_length = padded_length - GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES; | ||
906 | |||
907 | if (GNUNET_OK != GNUNET_IDENTITY_decrypt (message->body.privacy.data, | ||
908 | padded_length, | ||
909 | key, | ||
910 | message->body.privacy.data, | ||
911 | encoded_length)) | ||
912 | { | ||
913 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Decrypting message failed!\n"); | ||
914 | |||
915 | return GNUNET_NO; | ||
916 | } | ||
917 | |||
905 | struct GNUNET_MESSENGER_ShortMessage shortened; | 918 | struct GNUNET_MESSENGER_ShortMessage shortened; |
906 | 919 | ||
907 | if (GNUNET_YES != decode_short_message (&shortened, | 920 | if (GNUNET_YES != decode_short_message (&shortened, |
908 | message->body.privacy.length, | 921 | encoded_length, |
909 | message->body.privacy.data)) | 922 | message->body.privacy.data)) |
910 | { | 923 | { |
911 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 924 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -915,7 +928,6 @@ decrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
915 | } | 928 | } |
916 | 929 | ||
917 | unfold_short_message (&shortened, message); | 930 | unfold_short_message (&shortened, message); |
918 | |||
919 | return GNUNET_YES; | 931 | return GNUNET_YES; |
920 | } | 932 | } |
921 | 933 | ||