Skip to content
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

at_c: non-encrypted notifications cause a segfault #246

Open
JeremyTubongbanua opened this issue May 10, 2024 · 4 comments
Open

at_c: non-encrypted notifications cause a segfault #246

JeremyTubongbanua opened this issue May 10, 2024 · 4 comments
Assignees

Comments

@JeremyTubongbanua
Copy link
Member

When set shouldencrypt=false when sending a notification, it will send isEncrypted:false and send the value in plain text (unencrypted). This willc ause a segfault.

This ticket is dependent on atsign-foundation/at_server#1944

@JeremyTubongbanua JeremyTubongbanua self-assigned this May 13, 2024
@JeremyTubongbanua
Copy link
Member Author

JeremyTubongbanua commented May 13, 2024

Not a high priority since only encrypted notifications are ever used in the C Daemon

@JeremyTubongbanua
Copy link
Member Author

Setting this to blocked because some work I believe is needed to be done on the atServer side of things - atsign-foundation/at_server#2050

@JeremyTubongbanua
Copy link
Member Author

No longer blocked, as this is implemented in the protocol now.

Setting it to triage now

@JeremyTubongbanua
Copy link
Member Author

Current investigation shows that non-encrypted notifications cause a segfault still.

Monitor code:

#include <atlogger/atlogger.h>
#include <atclient/atclient.h>
#include <atclient/monitor.h>

#define ATSIGN "@12alpaca"
#define KEYS_PATH "/home/jeremy/.atsign/keys/@12alpaca_key.atKeys"

#define TAG "main"

int main() {
  int ret = 1;

  atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_DEBUG);

  atclient main_client;
  atclient_init(&main_client);

  atclient monitor_client;
  atclient_init(&monitor_client);

  atclient_atkeys atkeys;
  atclient_atkeys_init(&atkeys);

  if((ret = atclient_atkeys_populate_from_path(&atkeys, KEYS_PATH)) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to populate atkeys from path\n");
    goto exit;
  }

  if((ret = atclient_pkam_authenticate(&main_client, ATSIGN, &atkeys, NULL, NULL)) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate connection\n");
    goto exit;
  }

  if((ret = atclient_monitor_pkam_authenticate(&monitor_client, ATSIGN, &atkeys, NULL)) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate monitor connection\n");
    goto exit;
  }

  if((ret = atclient_monitor_start(&monitor_client, ".*")) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to start monitor\n");
    goto exit;
  }

  while(1) {
    atclient_monitor_message message;
    atclient_monitor_message_init(&message);

    ret = atclient_monitor_read(&monitor_client, &main_client, &message, NULL);

    if(message.type == ATCLIENT_MONITOR_MESSAGE_TYPE_NOTIFICATION) {
      atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "Received notification:");
      atlogger_log(NULL, ATLOGGER_LOGGING_LEVEL_INFO, "%s", message.notification->decrypted_value);
      atlogger_log(NULL, ATLOGGER_LOGGING_LEVEL_INFO, "\n");
    }

    atclient_monitor_message_free(&message);
  }
  

  ret = 0;

exit: { return ret; }
}

Monitor code output:

[INFO] 2025-02-18 04:16:27.012189 | atclient | Missing atServer host or port. Using root.atsign.org:64 atDirectory to find atServer address
[INFO] 2025-02-18 04:16:27.781273 | connection | Connected
[DEBG] 2025-02-18 04:16:27.902201 | connection |        SENT: "from:12alpaca"
[DEBG] 2025-02-18 04:16:27.928354 | connection |        RECV: "data:_d127a83f-6965-432d-946b-c1a4b5bbc796@12alpaca:69f00170-d0d1-4c10-acbc-474000cc0ef3"
[DEBG] 2025-02-18 04:16:27.938160 | connection |        SENT: "pkam:EeBil8oW0gGbOURdrsdwH1QpzdySLYSQQ1I+dSkQVi+e4gU0ISgUiBwq8IbQFW8wOmYTczUGnzUdV1XxqjszqazgVZBOy43D0RTrwwqQ1uLR9gZ5M2PXT/ecB7mMrQ4gt/KAzRWyV3Vtv7g4eGTTTkMJbLHG6LRu4tYOnmhCSsxaZ4wGVaC5cFRVFJTVsEfrfgYS+pX4lyxSAAdkSjl+5qsp1hhED0dFcYisUTs/daZ0A6EVd0YZyFdLogrLxIYXJVa7VaLydCj8W/QunOSoBqS43eYHQWmyrN6Jw7fUKaUX5F1EpXbgZA5LMQgAs7QuSe9uJnxweOYI2LKa70+SWw=="
[DEBG] 2025-02-18 04:16:27.965335 | connection |        RECV: "data:success"
[INFO] 2025-02-18 04:16:27.965356 | atclient | Missing atServer host or port. Using root.atsign.org:64 atDirectory to find atServer address
[INFO] 2025-02-18 04:16:28.332004 | connection | Connected
[DEBG] 2025-02-18 04:16:28.447717 | connection |        SENT: "from:12alpaca"
[DEBG] 2025-02-18 04:16:28.473230 | connection |        RECV: "data:_e3a279c5-2dca-4aa5-8532-17107e058589@12alpaca:96a03524-ce10-4999-90c7-774d41a55c02"
[DEBG] 2025-02-18 04:16:28.483597 | connection |        SENT: "pkam:F3kfgvqBErOGN/jXiVp0DlsdjFpY2cW/EtJ6ltE0IeBQ90AykUbGyx/c+iyVajHO9QTYRcOKJ4v8lNuIAGcXHuQnF5Gx+2Dvwtxcf8O2OSvtu8wIEv7WJcqHpsFDsP1ZPGJl3bJ+SqnkvvfC8H0nMRY6tFDVN4bjjZCMMZOYH2DDmBNoYNiRq0Wno9Mpm8r6kSbDDF0esh9FHy15aFMqi6oBRdTuucqH4kOF/C3y9ejeHrRddtk3Z0LMpWQ5e4hyn1LVjH98flNR/3oIJx+uzCRBJNCAguF1/VXaI7sN/g4m51ZQXZXZ+csFLEnl69BzhiGfLEGcDNdjIUQg+02JnA=="
[DEBG] 2025-02-18 04:16:28.509546 | connection |        RECV: "data:success"
[DEBG] 2025-02-18 04:16:28.509591 | connection |        SENT: "monitor .*"
[ERROR] 2025-02-18 04:16:28.509595 | connection | recv is null. exiting
[DEBG] 2025-02-18 04:16:28.509598 | atclient_monitor |  SENT: "monitor .*"
[DEBG] 2025-02-18 04:16:31.512413 | atclient_socket_mbedtls | Socket read error: -26624
[DEBG] 2025-02-18 04:16:31.943873 | atclient_monitor |  RECV: "notification: {"id":"f8cd6801-6158-4952-8ea8-bc1d6aaf8177","from":"@12snowboating","to":"@12alpaca","key":"@12alpaca:non_encrypted_notification.test@12snowboating","value":"Hello, World!","operation":"update","epochMillis":1739852191933,"messageType":"MessageType.key","isEncrypted":true,"metadata":{"encKeyName":null,"encAlgo":null,"ivNonce":null,"skeEncKeyName":null,"skeEncAlgo":null,"sharedKeyEnc":null,"pubKeyHash":null}}"
Segmentation fault

Notification code:

#include <atlogger/atlogger.h>
#include <atclient/notify.h>
#include <atclient/atclient.h>

#define TAG "main"

#define ATSIGN "@12snowboating"
#define KEYS_PATH "/home/jeremy/.atsign/keys/@12snowboating_key.atKeys"

int main() {
  int ret = 1;

  atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_DEBUG);

  atclient main_client;
  atclient_init(&main_client);

  atclient_atkeys atkeys;
  atclient_atkeys_init(&atkeys);

  atclient_atkey atkey;
  atclient_atkey_init(&atkey);

  atclient_notify_params params;
  atclient_notify_params_init(&params);

  if((ret = atclient_atkeys_populate_from_path(&atkeys, KEYS_PATH)) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to populate atkeys from path\n");
    goto exit;
  }

  if((ret = atclient_pkam_authenticate(&main_client, ATSIGN, &atkeys, NULL, NULL)) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate connection\n");
    goto exit;
  }


  if((ret = atclient_atkey_create_shared_key(&atkey, "non_encrypted_notification", "@12snowboating", "@12alpaca", "test")) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create shared key\n");
    goto exit;
  }

  if((ret = atclient_notify_params_set_atkey(&params, &atkey)) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set atkey\n");
    goto exit;
  }

  if((ret = atclient_notify_params_set_value(&params, "Hello, World!")) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set value\n");
    goto exit;
  }

  if((ret = atclient_notify_params_set_should_encrypt(&params, false)) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set should_encrypt\n");
    goto exit;
  }

  // print params
  atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "Params:\n");
  atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "  atkey: %p\n", params.atkey);
  atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "  value: %s\n", params.value);
  atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "  should_encrypt: %d\n", params.should_encrypt);


  if((ret = atclient_notify(&main_client, &params, NULL)) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to send notification\n");
    goto exit;
  }

  ret = 0;

exit: { return ret; }
}

Notification code output:

[INFO] 2025-02-18 04:16:31.262158 | atclient | Missing atServer host or port. Using root.atsign.org:64 atDirectory to find atServer address
[INFO] 2025-02-18 04:16:31.669670 | connection | Connected
[DEBG] 2025-02-18 04:16:31.823723 | connection |        SENT: "from:12snowboating"
[DEBG] 2025-02-18 04:16:31.863246 | connection |        RECV: "data:_3eef9370-035b-439c-805a-d1394fc79a19@12snowboating:f1e546f5-34f5-44fc-8743-578b880dff47"
[DEBG] 2025-02-18 04:16:31.874154 | connection |        SENT: "pkam:TeCtcnHlBndSeVmQW3MV4q4rVdlgGTtUsZ17scJrhV92UvMpgsOoFO1pQiZBkGSBLzDDZLmQ6yKxn3sBP8v2vJrOpmZqXAg4cNsM3CCeiUXNGCWdyiXmOPDH5HOognAX2MGC+Evr5MxRYXm7mnNN++G/9usQy2b1uGXn2k09iQQqthwdTywLTVVl1cRX3dhERsvvWTRD2DoAeV6r/9OCiO05eR4Rdvf/iBxHm82PCDpOizmgqrUezRh6wMXjG//sM8f5d7E1AQtgXVToNQfz2fqVdctf0/hJ7bTwLGHxHY2Ro8COIKBfYnTO6cNgHRVwuMP6cNj2lrsT/VYF3lvw6A=="
[DEBG] 2025-02-18 04:16:31.915127 | connection |        RECV: "data:success"
[INFO] 2025-02-18 04:16:31.915167 | main | Params:
[INFO] 2025-02-18 04:16:31.915170 | main |   atkey: 0x5ad154df6e10
[INFO] 2025-02-18 04:16:31.915172 | main |   value: Hello, World!
[INFO] 2025-02-18 04:16:31.915174 | main |   should_encrypt: 0
[DEBG] 2025-02-18 04:16:31.915241 | connection |        SENT: "notify:@12alpaca:non_encrypted_notification.test@12snowboating:Hello, World!"
[DEBG] 2025-02-18 04:16:31.953815 | connection |        RECV: "data:f8cd6801-6158-4952-8ea8-bc1d6aaf8177"
jeremy@atsign:~/GitHub/at_c/examples/desktop/non_encrypted_notification$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant