Coder Social home page Coder Social logo

oescal / sgx-based-mix-networks Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 0.0 11.34 MB

Hidden anonymization with SGX-based mixes

License: GNU General Public License v3.0

C++ 52.28% C 6.19% Makefile 21.47% Python 19.10% Shell 0.96%
sgx intel-sgx mix-network

sgx-based-mix-networks's Introduction

SGX based mix-networks

Hidden anonymization with Intel SGX based mixes

How to execute

  • The first requirement needed to run our solution is to have installed the SGX drivers and SDK:

    $ sudo apt install build-essential ocaml automake autoconf libtool wget python3 libssl-dev dkms
    $ wget https://download.01.org/intel-sgx/latest/linux-latest/distro/ubuntu20.04-server/sgx_linux_x64_driver_1.41.bin; sudo bash sgx_linux_x64_driver_1.41.bin
    
    $ sudo apt install libssl-dev libcurl4-openssl-dev libprotobuf-dev
    $ echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | sudo tee /etc/apt/    sources.list.d/intel-sgx.list
    $ wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add -
    $ sudo apt update
    $ sudo apt install libsgx-launch libsgx-urts
    $ sudo apt install libsgx-epid libsgx-urts
    
    $ wget https://download.01.org/intel-sgx/latest/linux-latest/distro/ubuntu20.04-server/sgx_linux_x64_sdk_2.13.103.1.bin; sudo bash sgx_linux_x64_sdk_2.13.103.1.bin             # answer no and choose /opt/intel
    # then, copy the contents of the file /opt/intel/sgxsdk/environment to your .bashrc
    
    $ wget https://download.01.org/intel-sgx/latest/linux-latest/as.ld.objdump.gold.r3.tar.gz
    $ tar xzvf as.ld.objdump.gold.r3.tar.gz external/toolset/ubuntu20.04
    $ sudo cp -v external/toolset/ubuntu20.04/* /usr/local/bin/
  • After that, you should change your terminal directory to the directory mix_solution/ of this repository.

  • Then, you have also to set the Python virtual environment and install the needed requirements:

    $ cd consumer_producer/
    $ virtualenv venv
    $ source venv/bin/activate
    
    $ pip install -r requirements.txt
  • Finally, open two terminals, one in the directory mix_solution/ and the other on the directory mix_solution/consumer_producer/, and run:

    # on the mix_solution/consumer_producer/, first enter the virtual environment (source venv/bin/activate)
    $ python3 server.py <minimum_number_of_mixes> <number_of_messages>                 # for example, "python3 server.py 100 10000" will create a consumer/producer that will wait for the public keys of 100 different mixes before starting to send the messages to the network, and will send a total of 10000 messages
    
    # on the mix_solution/
    $ make
    $ ./run_multiple.sh <number_of_mixes>                                                   # for example, "./run_multiple 100" will run create a network of 100 mixes
    • Note that you must run the Python server first and just after it is running is when you can run the script that will create the mix network.

    • You can check the mixes logs on the directory logs/.

  • You can also run each mix (node) for yourself without the need of the script run_multiple.sh. For that, you just have to run:

    $ make
    $ ./app <mix_port> <prev_mix_port> <next_mix_port> <consumer_producer_port>        # where <mix_port> is the port you want your mix to run on, the <prev_mix_port> is the port where is running the previous mix, the <next_mix_port> is the port where is running the next mix and the <consumer_producer_port> is where is running the Python consumer/producer

sgx-based-mix-networks's People

Contributors

oescal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sgx-based-mix-networks's Issues

Did not check malloc result

message may be NULL:

message = (unsigned char *)malloc(strlen(choosen_message));

We can infer that message holds sensitive information because it will be encrypted:

sgx_status_t ret_get_output_len = sgx_rsa_pub_encrypt_sha256(

So choosen_message is sensitive too beacuse its content will be copied into message

std::copy(choosen_message, choosen_message + strlen(choosen_message), message);

if message is NULL, choosen_message will be copied outside enclave, which results in privacy leakage.

information leak in Enclave code.

hi,sir
I think there is an information leak here, could you help me confirm it?

int dispatch(unsigned char *result, int *fan_out, size_t *buffer_size, int fan_all_out) {

    unsigned char *message;
    float probability_false = (WATER_MARK - (float)buffer.size()) / (float)WATER_MARK;

    // calculate the probability of fan out
    if (fan_all_out || generate_random_value() < PROBABILITY_FAN_OUT)
        *fan_out = 1;

    
    if (!*fan_out && probability_false > 0 && generate_random_value() < probability_false) {             // create a false message
        message = (unsigned char *) MESSAGE_FALSE;
        *buffer_size = buffer.size();
    } else {                                                                                                            // obtain a message from the buffer
        *buffer_size = buffer.size();

        if (buffer.size() < 1)
            return -1;

        int index = (int)(generate_random_value()*buffer.size());
        char *choosen_message = (char *) buffer.at(index).c_str();
        message = (unsigned char *)malloc(strlen(choosen_message));
        std::copy(choosen_message, choosen_message + strlen(choosen_message), message);
        message[strlen(choosen_message)] = '\0';

                                                                                              
        buffer.erase(buffer.begin() + index);


        // ======================= vulnerable code:========================
        // fan_out may be controlled by the attacker,
        //when *fan_out !=0, the unencrypted message can be leaked .


        if (*fan_out) { 
            std::copy(message, message + strlen((char *) message), result);
            return 1;
        }
    }

    size_t out_len = 0;

    sgx_status_t ret_get_output_len = sgx_rsa_pub_encrypt_sha256(
        previous_public_key, NULL, &out_len, message, strlen((char *) message));

    if (ret_get_output_len != SGX_SUCCESS) {
        printf("Determination of output length failed\n");
        return 0;
    }

    sgx_status_t ret_encrypt = sgx_rsa_pub_encrypt_sha256(
        previous_public_key, result, &out_len, message, strlen((char *) message));

    if (ret_encrypt != SGX_SUCCESS) {
        printf("Encryption failed\n");
        return 0;
    } else {
        printf("Encrypted message with success!\n");
    }

    return 1;
}

fan_out may be controlled by the attacker,
when *fan_out !=0, the unencrypted message can be leaked .

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.