1
+ #include <stdio.h>
2
+ #include <string.h>
3
+ #include <unistd.h>
4
+ #include <errno.h>
5
+
6
+
7
+ #include <rats-tls/api.h>
8
+ #include <rats-tls/log.h>
9
+ #include "rats-tls/api.h"
10
+ #include "sgx_urts.h"
11
+ #include "sgx_stub_t.h"
12
+
13
+ #define FUZZ_IP "127.0.0.1"
14
+ #define FUZZ_PORT 1234
15
+
16
+ int ecall_client_startup (rats_tls_log_level_t log_level ,char * fuzz_conf_bytes ,char * attester_type ,char * verifier_type , char * tls_type , char * crypto_type , unsigned long flags ){
17
+
18
+ rats_tls_conf_t conf ;
19
+ memcpy (& conf ,fuzz_conf_bytes ,sizeof (& conf ));
20
+
21
+ // little confused, why use snprintf
22
+ snprintf (conf .attester_type , sizeof (conf .attester_type ), "%s" , attester_type );
23
+ snprintf (conf .verifier_type , sizeof (conf .verifier_type ), "%s" , verifier_type );
24
+ snprintf (conf .tls_type , sizeof (conf .tls_type ), "%s" , tls_type );
25
+ snprintf (conf .crypto_type , sizeof (conf .crypto_type ), "%s" , crypto_type );
26
+ conf .flags = flags ;
27
+ conf .cert_algo = RATS_TLS_CERT_ALGO_DEFAULT ;
28
+
29
+ /*passing a struct into enclave seems a little complicated,
30
+ use the default instead */
31
+ claim_t custom_claims [2 ] = {
32
+ { .name = "key_0" , .value = (uint8_t * )"value_0" , .value_size = sizeof ("value_0" ) },
33
+ { .name = "key_1" , .value = (uint8_t * )"value_1" , .value_size = sizeof ("value_1" ) },
34
+ };
35
+ conf .custom_claims = (claim_t * )custom_claims ;
36
+ conf .custom_claims_length = 2 ;
37
+
38
+ /* Create a socket that uses an internet IPv4 address,
39
+ * Sets the socket to be stream based (TCP),
40
+ * 0 means choose the default protocol.
41
+ */
42
+
43
+ int64_t sockfd ;
44
+ int sgx_status = ocall_socket (& sockfd , RTLS_AF_INET , RTLS_SOCK_STREAM , 0 );
45
+ if (sgx_status != SGX_SUCCESS || sockfd < 0 ) {
46
+ RTLS_ERR ("Failed to call socket() %#x %d\n" , sgx_status , sockfd );
47
+ return -1 ;
48
+ }
49
+
50
+ struct rtls_sockaddr_in s_addr ;
51
+ memset (& s_addr , 0 , sizeof (s_addr ));
52
+ s_addr .sin_family = RTLS_AF_INET ;
53
+ s_addr .sin_addr .s_addr = FUZZ_IP ;
54
+ s_addr .sin_port = FUZZ_PORT ;
55
+
56
+ /* Connect to the server */
57
+ int ocall_ret = 0 ;
58
+ sgx_status = ocall_connect (& ocall_ret , sockfd , & s_addr , sizeof (s_addr ));
59
+ if (sgx_status != SGX_SUCCESS || ocall_ret == -1 ) {
60
+ RTLS_ERR ("failed to call connect() %#x %d\n" , sgx_status , ocall_ret );
61
+ return -1 ;
62
+ }
63
+
64
+ /* rats-tls init */
65
+ librats_tls_init ();
66
+ rats_tls_handle handle ;
67
+ rats_tls_err_t ret = rats_tls_init (& conf , & handle );
68
+ if (ret != RATS_TLS_ERR_NONE ) {
69
+ RTLS_ERR ("Failed to initialize rats tls %#x\n" , ret );
70
+ return -1 ;
71
+ }
72
+
73
+ ret = rats_tls_negotiate (handle , (int )sockfd );
74
+ if (ret != RATS_TLS_ERR_NONE ) {
75
+ RTLS_ERR ("Failed to negotiate %#x\n" , ret );
76
+ return -1 ;
77
+ }
78
+
79
+ const char * msg = "Hello and welcome to RATS-TLS!\n" ;
80
+
81
+
82
+ return 0 ;
83
+ }
84
+
85
+
86
+ int ecall_server_startup (rats_tls_log_level_t log_level ,char * fuzz_conf_bytes ,char * attester_type ,char * verifier_type , char * tls_type , char * crypto_type , unsigned long flags ){
87
+ RTLS_ERR ("entering into the server " );
88
+ return 0 ;
89
+
90
+ }
0 commit comments