@@ -43,7 +43,7 @@ rats_tls_log_level_t log_level = RATS_TLS_LOG_LEVEL_INFO;
4343
4444const char * command_get_secret = "getSecret" ;
4545
46- char * get_secret_from_kbs_through_rats_tls (rats_tls_log_level_t log_level ,
46+ char * get_secret_from_sbs_through_rats_tls (rats_tls_log_level_t log_level ,
4747 char * attester_type ,
4848 char * verifier_type ,
4949 char * tls_type ,
@@ -81,8 +81,12 @@ char* get_secret_from_kbs_through_rats_tls(rats_tls_log_level_t log_level,
8181 if (validation_error ) {
8282 return NULL ;
8383 }
84+ LOG_DEBUG ("attester_type: %s" , attester_type );
85+ LOG_DEBUG ("verifier_type: %s" , verifier_type );
86+ LOG_DEBUG ("tls_type: %s" , tls_type );
87+ LOG_DEBUG ("crypto_type: %s" , crypto_type );
88+
8489 rats_tls_conf_t conf ;
85-
8690 memset (& conf , 0 , sizeof (conf ));
8791
8892 char * app_id ;
@@ -96,7 +100,7 @@ char* get_secret_from_kbs_through_rats_tls(rats_tls_log_level_t log_level,
96100 conf .custom_claims = (claim_t * )custom_claims ;
97101 conf .custom_claims_length = 1 ;
98102 } else {
99- LOG_ERROR ("could not read the app_id from env" );
103+ LOG_ERROR ("Could not read the app_id from env" );
100104 return NULL ;
101105 }
102106 }
@@ -111,16 +115,18 @@ char* get_secret_from_kbs_through_rats_tls(rats_tls_log_level_t log_level,
111115 strncpy (conf .crypto_type , crypto_type , CRYPTO_TYPE_NAME_SIZE - 1 );
112116 conf .crypto_type [CRYPTO_TYPE_NAME_SIZE - 1 ] = '\0' ;
113117 conf .cert_algo = RATS_TLS_CERT_ALGO_DEFAULT ;
114- if (mutual )
118+ if (mutual ){
115119 conf .flags |= RATS_TLS_CONF_FLAGS_MUTUAL ;
120+ LOG_DEBUG ("Mutual attestation is enabled" );
121+ }
116122
117123 /* Create a socket that uses an internet IPv4 address,
118124 * Sets the socket to be stream based (TCP),
119125 * 0 means choose the default protocol.
120126 */
121127 int sockfd = socket (AF_INET , SOCK_STREAM , 0 );
122128 if (sockfd < 0 ) {
123- LOG_ERROR ("failed to call socket()" );
129+ LOG_ERROR ("Failed to call socket()" );
124130 return NULL ;
125131 }
126132 struct sockaddr_in s_addr ;
@@ -130,14 +136,14 @@ char* get_secret_from_kbs_through_rats_tls(rats_tls_log_level_t log_level,
130136
131137 /* Get the server IPv4 address from the command line call */
132138 if (inet_pton (AF_INET , ip , & s_addr .sin_addr ) != 1 ) {
133- LOG_ERROR ("invalid server address" );
139+ LOG_ERROR ("Invalid server address" );
134140 close (sockfd );
135141 return NULL ;
136142 }
137143
138144 /* Connect to the server */
139145 if (connect (sockfd , (struct sockaddr * )& s_addr , sizeof (s_addr )) == -1 ) {
140- LOG_ERROR ("failed to call connect()" );
146+ LOG_ERROR ("Failed to call connect()" );
141147 close (sockfd );
142148 return NULL ;
143149 }
@@ -205,8 +211,9 @@ char* get_secret_from_kbs_through_rats_tls(rats_tls_log_level_t log_level,
205211 buf [bytes_received ] = '\0' ;
206212
207213 ret = rats_tls_cleanup (handle );
208- if (ret != RATS_TLS_ERR_NONE )
214+ if (ret != RATS_TLS_ERR_NONE ){
209215 LOG_ERROR ("Failed to cleanup %#x" , ret );
216+ }
210217
211218 close (sockfd );
212219 return buf ;
@@ -221,24 +228,24 @@ char* get_secret_from_kbs_through_rats_tls(rats_tls_log_level_t log_level,
221228int main (int argc , char * * argv ) {
222229 setvbuf (stdout , NULL , _IONBF , 0 );
223230 char * secret = "" ;
224- LOG_INFO ("try to get key from kbs " );
225- char * kbs_endpoint = getenv ("kbsEndpoint " );
226- if (NULL == kbs_endpoint ) {
227- LOG_ERROR ("kbs mode must config kbsEndpoint " );
231+ LOG_INFO ("Try to get key from SBS " );
232+ char * sbs_endpoint = getenv ("sbsEndpoint " );
233+ if (NULL == sbs_endpoint ) {
234+ LOG_ERROR ("SBS mode must config sbsEndpoint environment variable " );
228235 return -1 ;
229236 }
230237
231- LOG_DEBUG ("config of kbsEndpoint is %s" , kbs_endpoint );
238+ LOG_DEBUG ("Config of SBS endpoint is %s" , sbs_endpoint );
232239
233240 char * secret_save_path = NULL ;
234241 char * srv_ip = NULL ;
235242 char * str_port = NULL ;
236243 int port ;
237244
238- srv_ip = strtok (kbs_endpoint , ":" );
245+ srv_ip = strtok (sbs_endpoint , ":" );
239246 str_port = strtok (NULL , ":" );
240247 if (NULL == str_port ) {
241- LOG_ERROR ("kbsEndpoint format error, eg: 127.0.0.1:5443" );
248+ LOG_ERROR ("sbsEndpoint format error, eg: 127.0.0.1:5443" );
242249 return -1 ;
243250 }
244251 port = atoi (str_port );
@@ -335,16 +342,15 @@ int main(int argc, char** argv) {
335342 return -1 ;
336343 }
337344
338- secret = get_secret_from_kbs_through_rats_tls (log_level , attester_type , verifier_type ,
345+ secret = get_secret_from_sbs_through_rats_tls (log_level , attester_type , verifier_type ,
339346 tls_type , crypto_type , mutual , srv_ip ,
340347 port , appid_flag );
341348 if (secret == NULL ) {
342- LOG_ERROR ("get secret from kbs failed" );
349+ LOG_ERROR ("Get secret from SBS failed" );
343350 return -1 ;
344351 }
345352
346- LOG_INFO ("get secret successful" );
347- LOG_DEBUG ("secret is %s" , secret );
353+ LOG_INFO ("Get secret successful" );
348354
349355 fputs (secret , file );
350356 fclose (file );
0 commit comments