123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- //
- // 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;
- }
- void 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];
- uint32_t ret_status
- // Set up an IPC channel for local attestation and post-LA messages.
- decryptor_fd = set_up_socket_connect(port);
- if(decryptor_fd == -1)
- {
- printf("\nCould not set up the socket: had the following error: ");
- fflush(stdout);
- return 0x1;
- }
- // 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.
- laInitiator.get_la_symmetric_key(key);
- postLAMessaging.set_la_symmetric_key(key);
- // Send the target's hash to the decryptor enclave.
- return send_secure_msg(target_hash, 32);
- }
|