chGoodchild / GLTollGate

6 stars 2 forks source link

Config file or arguments for network name, gateway etc... #36

Open chGoodchild opened 2 months ago

chGoodchild commented 2 months ago

Config file or arguments for network name, gateway, gateway password, login password, nsec, npub, owner credentials etc...

Owner LNURL

chGoodchild commented 2 months ago

These are the fields that need to be changed:

    option bssid 'F6:9F:C2:FA:75:A6'
    option key 'coworking'
    option encryption 'psk-mixed'

https://github.com/chGoodchild/GLTollGate/blob/6b3e3f9c66ec060b5d30e7b36c5ee520fe9dbcb8/etc/config/wireless#L37-L46

chGoodchild commented 2 months ago

https://github.com/chGoodchild/GLTollGate/issues/37

chGoodchild commented 2 months ago

The fleet manager can also provide access to a static IP address from a VPN provider via nostr.

chGoodchild commented 1 month ago

Commit: c64a37b3b83192bb201a4af4900091dffcb2bdc4

Multiple memory leaks when the note is large:

~/GLTollGate/nostr/c$ ./generate_encrypted_dm.sh "nostr_keys_router.json" "nostr_keys_operator.json" "test test test test test test test test test test test test test"
==115514== Memcheck, a memory error detector
==115514== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==115514== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==115514== Command: ./nostril --dm 34c83a1124c74c5236b7b2e8f45a0f6d00e7ce23eeb6a88607df8d9e7aae5670 --content test\ test\ test\ test\ test\ test\ test\ test\ test\ test\ test\ test\ test --sec b655fbb9270a50b10ed151ba080680502a6ead295421fc7b10a7787f389c0f14 --kind 14 --envelope --created-at 1724490403
==115514== 
shared_secret 36e24f1021af26503c0572689b7bbda55f59ac566477d6968c717499b9bacf75
==115514== Invalid write of size 1
==115514==    at 0x10A49F: cursor_push_byte (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x10B83F: aes_encrypt (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x10BF78: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x1099E3: main (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==  Address 0x4bcc551 is 0 bytes after a block of size 65 alloc'd
==115514==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==115514==    by 0x10BD43: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x1099E3: main (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== 
==115514== 
==115514== Invalid read of size 1
==115514==    at 0x4852A10: memmove (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==115514==    by 0x10E0D5: base64_encode_tail_using_maps (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x10E200: base64_encode_using_maps (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x10A857: base64_encode (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x10BFE9: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x1099E3: main (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==  Address 0x4bcc55e is 13 bytes after a block of size 65 alloc'd
==115514==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==115514==    by 0x10BD43: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x1099E3: main (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514== 
["EVENT",{"id": "84b1f1567a656a4c2b1ff5490fc64c75e7930da9423f76ea6bc32e041aad5f40","pubkey": "a9f62ced51f3c06c24aa9aad2e01836421a90df04a6a9a735070efa2f77bec6f","created_at": 1724490403,"kind": 14,"tags": [["p","34c83a1124c74c5236b7b2e8f45a0f6d00e7ce23eeb6a88607df8d9e7aae5670"]],"content": "1AnDRj5Yu3hDrImuZ4dMmu1uBSLr/8w5wVd3PfK3SUe7f5rTl7lZ0IUk9CI2QPShpzo89uKkqF17OeEktF1k1YoL8X//W+2UIukjlT0cD3Q=?iv=RAv0ZGm0uR7GseCi+/7Z2A==","sig": "e17a5f853ad8dbcbaf11c7ff3e893e51f6b9bc31560542ce240c4d950073dfbcafb2e8a159b540924db76db3703525eca6647d232224d2589f60c9a9971e8f97"}]
["EVENT",{"id": "84b1f1567a656a4c2b1ff5490fc64c75e7930da9423f76ea6bc32e041aad5f40","pubkey": "a9f62ced51f3c06c24aa9aad2e01836421a90df04a6a9a735070efa2f77bec6f","created_at": 1724490403,"kind": 14,"tags": [["p","34c83a1124c74c5236b7b2e8f45a0f6d00e7ce23eeb6a88607df8d9e7aae5670"]],"content": "1AnDRj5Yu3hDrImuZ4dMmu1uBSLr/8w5wVd3PfK3SUe7f5rTl7lZ0IUk9CI2QPShpzo89uKkqF17OeEktF1k1YoL8X//W+2UIukjlT0cD3Q=?iv=RAv0ZGm0uR7GseCi+/7Z2A==","sig": "e17a5f853ad8dbcbaf11c7ff3e893e51f6b9bc31560542ce240c4d950073dfbcafb2e8a159b540924db76db3703525eca6647d232224d2589f60c9a9971e8f97"}]
==115514== 
==115514== HEAP SUMMARY:
==115514==     in use at exit: 103,626 bytes in 3 blocks
==115514==   total heap usage: 4 allocs, 1 frees, 103,691 bytes allocated
==115514== 
==115514== LEAK SUMMARY:
==115514==    definitely lost: 103,626 bytes in 3 blocks
==115514==    indirectly lost: 0 bytes in 0 blocks
==115514==      possibly lost: 0 bytes in 0 blocks
==115514==    still reachable: 0 bytes in 0 blocks
==115514==         suppressed: 0 bytes in 0 blocks
==115514== Rerun with --leak-check=full to see details of leaked memory
==115514== 
==115514== For lists of detected and suppressed errors, rerun with: -s
==115514== ERROR SUMMARY: 2242 errors from 60 contexts (suppressed: 0 from 0)
  1. Invalid write in cursor_push_byte:
==115514== Invalid write of size 1
==115514==    at 0x10A49F: cursor_push_byte (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x10B83F: aes_encrypt (in /home/pachai/GLTollGate/nostr/c/nostril)
==115514==    by 0x10BF78: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)

This indicates a buffer overflow in the cursor_push_byte function, which is called during AES encryption.

  1. Invalid read in base64_encode:
    ==115514== Invalid read of size 1
    ==115514==    at 0x4852A10: memmove (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==115514==    by 0x10E0D5: base64_encode_tail_using_maps (in /home/pachai/GLTollGate/nostr/c/nostril)
    ==115514==    by 0x10E200: base64_encode_using_maps (in /home/pachai/GLTollGate/nostr/c/nostril)
    ==115514==    by 0x10A857: base64_encode (in /home/pachai/GLTollGate/nostr/c/nostril)
    ==115514==    by 0x10BFE9: make_encrypted_dm (in /home/pachai/GLTollGate/nostr/c/nostril)

This shows that the base64_encode function is reading beyond the allocated memory.

  1. Memory leaks:
    ==115514== LEAK SUMMARY:
    ==115514==    definitely lost: 103,626 bytes in 3 blocks

There are significant memory leaks in the program.

chGoodchild commented 1 month ago

In make_encrypted_dm:

        Address 0x4bcc551 is 0 bytes after a block of size 65 alloc'd
Increase the buffer size, ensuring it's large enough for the encrypted content plus any padding.

Here's a potential fix for the make_encrypted_dm function:


int make_encrypted_dm(secp256k1_context* ctx, struct key* key, struct nostr_event* ev, unsigned char nostr_pubkey[32], int kind)
{
    // ... (existing code)

    // Increase buffer size
    size_t content_len = strlen(ev->content);
    size_t padded_len = ((content_len + 15) / 16) * 16;  // Round up to nearest 16 bytes
    unsigned char* encbuf = (unsigned char*)malloc(padded_len + 16);  // Add extra space for potential padding
    if (!encbuf) {
        fprintf(stderr, "make_encrypted_dm: Failed to allocate memory for encryption\n");
        return 0;
    }

    // ... (perform encryption)

    // Ensure base64 buffer is large enough
    size_t base64_len = (padded_len + 2) / 3 * 4 + 1;  // Base64 encoding length + null terminator
    char* base64_output = (char*)malloc(base64_len);
    if (!base64_output) {
        fprintf(stderr, "make_encrypted_dm: Failed to allocate memory for base64 encoding\n");
        free(encbuf);
        return 0;
    }

    if (!base64_encode(encbuf, padded_len, base64_output, base64_len)) {
        fprintf(stderr, "make_encrypted_dm: base64 encode of encrypted data failed\n");
        free(encbuf);
        free(base64_output);
        return 0;
    }

    // ... (use base64_output)

    free(encbuf);
    free(base64_output);
    return 1;
}

Remember to apply similar fixes to other parts of the code where buffer overflows or memory leaks are occurring. Always ensure that allocated memory is properly freed when no longer needed.