1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- //
- // Created by miti on 2019-12-24.
- //
- #include "DeploymentStageLogic.h"
- // Sets up a socket connected to the port passed as input - returns the socket FD on success and -1 on error.
- // Also prints the errno on error.
- int set_up_socket_connect(int port)
- {
- int sock = 0;
- if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- {
- printf("\n Error in socket call - errno is %d \n", errno);
- return -1;
- }
- struct sockaddr_in serv_addr;
- memset(&serv_addr, '0', sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_port = htons(port);
- // Convert IPv4 and IPv6 addresses from text to binary form
- if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
- {
- printf("\nError in inet_pton - errno is %d\n", errno);
- return -1;
- }
- if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
- {
- printf("\nError in connect - errno is %d \n", errno);
- return -1;
- }
- return sock;
- }
- uint32_t set_target_hash(uint8_t* given_hash)
- {
- uint32_t counter;
- for(counter=0; counter<32; counter++)
- target_hash[counter] = given_hash[counter];
- }
- int main_logic()
- {
- int decryptor_fd;
- uint8_t key[16];
- // Set up an IPC channel for local attestation and post-LA messages.
- decryptor_fd = set_up_socket_connect(port);
- if(decryptor_fd == -1)
- {
- perror("\nCould not set up the socket: had the following error: ");
- fflush(stderr);
- }
- // Conduct LA.
- ret_status = laInitiator.conduct_la(decryptor_fd);
- if(ret_status != 0)
- return ret_status;
- // Use the same channel for post-LA messages as the one used above for LA messages.
- postLAMessaging.set_fd(decryptor_fd);
- // Use the symmetric key from LA to send messages for the rest of the deployment stage.
- postLAMessaging.set_la_symmetric_key(laInitiator.get_la_symmetric_key(key));
- // Send the target's hash to the decryptor enclave.
- return send_secure_msg(target_hash, 32);
- }
- /*
- uint32_t generate_encrypted_rsa_keypair_hash(uint8_t* op_ciphertext, uint32_t* length)
- {
- uint8_t tag[16];
- int ciphertext_len;// int plaintext_len=32;
- uint8_t iv[12];
- memset(iv, 0, 12);
- return_status=aes_cipher(1, key, iv, hash, 32, op_ciphertext, &ciphertext_len, tag);
- if(return_status == 0)
- {
- for(counter=0;counter<12;counter++)
- op_ciphertext[counter+ ciphertext_len] = iv[counter];
- for(counter=0;counter<16;counter++)
- op_ciphertext[counter+ ciphertext_len + 12] = tag[counter];
- ciphertext_len+=28;
- *length=ciphertext_len;
- }
- }
- */
|