Giter VIP home page Giter VIP logo

380-chat's Introduction

380-chat

Shein Htike

In this code, the chat app first uses triple Diffie-Hellman to initally exchange keys over the websocket. Both parties require only the other party's public key.

After a key exchange, both parties should now have a symmetric key. After this, all messages are encrypted and decrypted using EVP_aes_256_gcm().

For EVP_aes_256_gcm, a 64 bit counter is used as the IV or nonce in order to prevent replay attacks and ensure that the same message looks different when sent multiple times.

Additionally, the GCM mode provides it's own GMAC or Galois Message Authentication Code. This means that no HMAC is required for message authentication purposes.

In summary, this protocol:

  • Has forward secrecy - A unique derived key is used for every connection.
  • Has mutual authentication - Triple diffie-hellman key exchange ensures that only the person with the correct secret key can get the same KDF output.
  • Is resilient against replay attacks - A nonce counter prevents replaying while using minimal memory compared to a random nonce.
  • Has message authentication - EVP_aes_256_gcm provides its own message authentication in the algorithm

Security flaws:

  • I did not implement any handling for messages that are too long.
  • It is possible that the program has a memory leak somewhere
  • Situations such as invalid session keys simply cause the program to halt without wiping RAM.
  • A more secure RNG should be used for both long term and ephemeral key generation.

If I had more time, those flaws could have been addressed.

MacOS Compatibility

I had to make a number of tweaks to get the code to run on macOS:

  1. I ran brew install gtk+3 openssl gmp to install all dependencies using homebrew
  2. In my makefile, I included openssl and gmp in my pkg-config flags
LDADD    := -lpthread -lcrypto $(shell pkg-config --libs gtk+-3.0 openssl gmp
INCLUDE  := $(shell pkg-config --cflags gtk+-3.0 openssl gmp)
  1. I found a file endian.h on github which acted as a subsitute for <endian.h> and defined some missing symbols.
  2. For some reason HOST_LIMIT_MAX is not defined anywhere on macOS so I had to do it manually inside chat.c
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 255
#endif
  1. The following code refused to run on macOS. %ms does not seem to be supported. I even tried compiling with gcc-14 instead of the default clang compiler but I ran into the same issue.
	if (fscanf(f,"name:%ms\n",&name) != 1) {
		rv = -2;
		goto end;
	}

To fix this, I re-implemented something equivalent using getline() but it is probably less secure.

    char *line = NULL;
    size_t len = 0;
    ssize_t read = getline(&line, &len, f);
    if (read == -1) {
        free(line);
		rv = -2;
		goto end;
    }
    if (read <= 5 || memcmp(line,"name:",5) != 0) {
        rv = -2;
        free(line);
        goto end;
    }
    int i;
    bool newLineFound = false;
    for(i = 0; i < read; i++){
        if(line[i] == '\n'){
            line[i] = 0;
            newLineFound = true;
            break;
        }
    }
    if(!newLineFound){
        rv = -2;
        free(line);
        goto end;
    }
    size_t namelen = strlen(line+5);
    name = malloc(namelen+1);
    memcpy(name,line+5,namelen+1);
    free(line);

380-chat's People

Contributors

sheinh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.