@@ -66,7 +66,7 @@ make_conn(const char *hostname, const char *port)
66
66
int getaddrinfo_result =
67
67
getaddrinfo (hostname , port , & hints , & getaddrinfo_output );
68
68
if (getaddrinfo_result != 0 ) {
69
- fprintf (stderr , "getaddrinfo: %s\n" , gai_strerror (getaddrinfo_result ));
69
+ fprintf (stderr , "client: getaddrinfo: %s\n" , gai_strerror (getaddrinfo_result ));
70
70
goto cleanup ;
71
71
}
72
72
@@ -125,18 +125,18 @@ do_read(struct conndata *conn, struct rustls_connection *rconn)
125
125
126
126
if (err == EAGAIN || err == EWOULDBLOCK ) {
127
127
fprintf (stderr ,
128
- "reading from socket: EAGAIN or EWOULDBLOCK: %s\n" ,
128
+ "client: reading from socket: EAGAIN or EWOULDBLOCK: %s\n" ,
129
129
strerror (errno ));
130
130
return CRUSTLS_DEMO_AGAIN ;
131
131
}
132
132
else if (err != 0 ) {
133
- fprintf (stderr , "reading from socket: errno %d\n" , err );
133
+ fprintf (stderr , "client: reading from socket: errno %d\n" , err );
134
134
return CRUSTLS_DEMO_ERROR ;
135
135
}
136
136
137
137
result = rustls_connection_process_new_packets (rconn );
138
138
if (result != RUSTLS_RESULT_OK ) {
139
- print_error ("in process_new_packets" , result );
139
+ print_error ("server" , " in process_new_packets" , result );
140
140
return CRUSTLS_DEMO_ERROR ;
141
141
}
142
142
@@ -150,13 +150,13 @@ do_read(struct conndata *conn, struct rustls_connection *rconn)
150
150
signed_n = read (conn -> fd , buf , sizeof (buf ));
151
151
if (signed_n > 0 ) {
152
152
fprintf (stderr ,
153
- "read returned %ld bytes after receiving close_notify\n" ,
153
+ "client: error: read returned %ld bytes after receiving close_notify\n" ,
154
154
n );
155
155
return CRUSTLS_DEMO_ERROR ;
156
156
}
157
157
else if (signed_n < 0 && errno != EWOULDBLOCK ) {
158
158
fprintf (stderr ,
159
- "read returned incorrect error after receiving close_notify: %s\n" ,
159
+ "client: error: read returned incorrect error after receiving close_notify: %s\n" ,
160
160
strerror (errno ));
161
161
return CRUSTLS_DEMO_ERROR ;
162
162
}
@@ -208,12 +208,12 @@ send_request_and_read_response(struct conndata *conn,
208
208
* us- to the rustls connection. */
209
209
result = rustls_connection_write (rconn , (uint8_t * )buf , strlen (buf ), & n );
210
210
if (result != RUSTLS_RESULT_OK ) {
211
- fprintf (stderr , "error writing plaintext bytes to rustls_connection\n" );
211
+ fprintf (stderr , "client: error writing plaintext bytes to rustls_connection\n" );
212
212
goto cleanup ;
213
213
}
214
214
if (n != strlen (buf )) {
215
215
fprintf (stderr ,
216
- "short write writing plaintext bytes to rustls_connection\n" );
216
+ "client: short write writing plaintext bytes to rustls_connection\n" );
217
217
goto cleanup ;
218
218
}
219
219
@@ -230,7 +230,7 @@ send_request_and_read_response(struct conndata *conn,
230
230
}
231
231
232
232
if (!rustls_connection_wants_read (rconn ) && !rustls_connection_wants_write (rconn )) {
233
- fprintf (stderr , "rustls wants neither read nor write. draining plaintext and exiting.\n" );
233
+ fprintf (stderr , "client: rustls wants neither read nor write. draining plaintext and exiting.\n" );
234
234
goto drain_plaintext ;
235
235
}
236
236
@@ -241,11 +241,6 @@ send_request_and_read_response(struct conndata *conn,
241
241
}
242
242
243
243
if (FD_ISSET (sockfd , & read_fds )) {
244
- fprintf (
245
- stderr ,
246
- "rustls_connection wants us to read_tls. First we need to pull some "
247
- "bytes from the socket\n" );
248
-
249
244
/* Read all bytes until we get EAGAIN. Then loop again to wind up in
250
245
select awaiting the next bit of data. */
251
246
for (;;) {
@@ -263,26 +258,26 @@ send_request_and_read_response(struct conndata *conn,
263
258
body = body_beginning (& conn -> data );
264
259
if (body != NULL ) {
265
260
headers_len = body - conn -> data .data ;
266
- fprintf (stderr , "body began at %ld\n" , headers_len );
261
+ fprintf (stderr , "client: body began at %ld\n" , headers_len );
267
262
content_length_str = get_first_header_value (conn -> data .data ,
268
263
headers_len ,
269
264
CONTENT_LENGTH ,
270
265
strlen (CONTENT_LENGTH ),
271
266
& n );
272
267
if (content_length_str == NULL ) {
273
- fprintf (stderr , "content length header not found\n" );
268
+ fprintf (stderr , "client: content length header not found\n" );
274
269
goto cleanup ;
275
270
}
276
271
content_length =
277
272
strtoul (content_length_str , (char * * )& content_length_end , 10 );
278
273
if (content_length_end == content_length_str ) {
279
274
fprintf (stderr ,
280
- "invalid Content-Length '%.*s'\n" ,
275
+ "client: invalid Content-Length '%.*s'\n" ,
281
276
(int )n ,
282
277
content_length_str );
283
278
goto cleanup ;
284
279
}
285
- fprintf (stderr , "content length %ld\n" , content_length );
280
+ fprintf (stderr , "client: content length %ld\n" , content_length );
286
281
}
287
282
}
288
283
if (headers_len != 0 &&
@@ -292,36 +287,35 @@ send_request_and_read_response(struct conndata *conn,
292
287
}
293
288
}
294
289
if (FD_ISSET (sockfd , & write_fds )) {
295
- fprintf (stderr , "rustls_connection wants us to write_tls.\n" );
296
290
for (;;) {
297
291
/* This invokes rustls_connection_write_tls. We pass a callback to
298
292
* that function. Rustls will pass a buffer to that callback with
299
293
* encrypted bytes, that we will write to `conn`. */
300
294
err = write_tls (rconn , conn , & n );
301
295
if (err != 0 ) {
302
296
fprintf (
303
- stderr , "Error in rustls_connection_write_tls: errno %d\n" , err );
297
+ stderr , "client: error in rustls_connection_write_tls: errno %d\n" , err );
304
298
goto cleanup ;
305
299
}
306
300
if (result == CRUSTLS_DEMO_AGAIN ) {
307
301
break ;
308
302
}
309
303
else if (n == 0 ) {
310
- fprintf (stderr , "write 0 from rustls_connection_write_tls\n" );
304
+ fprintf (stderr , "client: write returned 0 from rustls_connection_write_tls\n" );
311
305
break ;
312
306
}
313
307
}
314
308
}
315
309
}
316
310
317
- fprintf (stderr , "send_request_and_read_response: loop fell through" );
311
+ fprintf (stderr , "client: send_request_and_read_response: loop fell through" );
318
312
319
313
drain_plaintext :
320
314
result = copy_plaintext_to_buffer (conn );
321
315
if (result != CRUSTLS_DEMO_OK && result != CRUSTLS_DEMO_EOF ) {
322
316
goto cleanup ;
323
317
}
324
- fprintf (stderr , "writing %ld bytes to stdout\n" , conn -> data .len );
318
+ fprintf (stderr , "client: writing %ld bytes to stdout\n" , conn -> data .len );
325
319
if (write (STDOUT_FILENO , conn -> data .data , conn -> data .len ) < 0 ) {
326
320
fprintf (stderr , "error writing to stderr\n" );
327
321
goto cleanup ;
@@ -351,7 +345,7 @@ do_request(const struct rustls_client_config *client_config,
351
345
rustls_result result =
352
346
rustls_client_connection_new (client_config , hostname , & rconn );
353
347
if (result != RUSTLS_RESULT_OK ) {
354
- print_error ("client_connection_new" , result );
348
+ print_error ("server" , " client_connection_new" , result );
355
349
goto cleanup ;
356
350
}
357
351
@@ -399,20 +393,20 @@ verify(void *userdata, const rustls_verify_server_cert_params *params)
399
393
struct conndata * conn = (struct conndata * )userdata ;
400
394
401
395
fprintf (stderr ,
402
- "custom certificate verifier called for %.*s\n" ,
396
+ "client: custom certificate verifier called for %.*s\n" ,
403
397
(int )params -> dns_name .len ,
404
398
params -> dns_name .data );
405
- fprintf (stderr , "end entity len: %ld\n" , params -> end_entity_cert_der .len );
406
- fprintf (stderr , "intermediates:\n" );
399
+ fprintf (stderr , "client: end entity len: %ld\n" , params -> end_entity_cert_der .len );
400
+ fprintf (stderr , "client: intermediates:\n" );
407
401
for (i = 0 ; i < intermediates_len ; i ++ ) {
408
402
bytes = rustls_slice_slice_bytes_get (intermediates , i );
409
403
if (bytes .data != NULL ) {
410
- fprintf (stderr , " intermediate, len = %ld\n" , bytes .len );
404
+ fprintf (stderr , "client: intermediate, len = %ld\n" , bytes .len );
411
405
}
412
406
}
413
- fprintf (stderr , "ocsp response len: %ld\n" , params -> ocsp_response .len );
407
+ fprintf (stderr , "client: ocsp response len: %ld\n" , params -> ocsp_response .len );
414
408
if (0 != strcmp (conn -> verify_arg , "verify_arg" )) {
415
- fprintf (stderr , "invalid argument to verify: %p\n" , userdata );
409
+ fprintf (stderr , "client: invalid argument to verify: %p\n" , userdata );
416
410
return RUSTLS_RESULT_GENERAL ;
417
411
}
418
412
return RUSTLS_RESULT_OK ;
@@ -454,14 +448,14 @@ main(int argc, const char **argv)
454
448
result = rustls_client_config_builder_load_roots_from_file (
455
449
config_builder , getenv ("CA_FILE" ));
456
450
if (result != RUSTLS_RESULT_OK ) {
457
- print_error ("loading trusted certificates" , result );
451
+ print_error ("server" , " loading trusted certificates" , result );
458
452
goto cleanup ;
459
453
}
460
454
} else if (getenv ("NO_CHECK_CERTIFICATE" )) {
461
455
rustls_client_config_builder_dangerous_set_certificate_verifier (
462
456
config_builder , verify );
463
457
} else {
464
- fprintf (stderr , "must set either CA_FILE or NO_CHECK_CERTIFICATE env var\n" );
458
+ fprintf (stderr , "client: must set either CA_FILE or NO_CHECK_CERTIFICATE env var\n" );
465
459
goto cleanup ;
466
460
}
467
461
0 commit comments