@@ -24,21 +24,21 @@ int testCerts(br_x509_trust_anchor *anch);
24
24
25
25
/**
26
26
* @brief The function that would be called whenever a PUBLISH is received.
27
- *
28
- * @note This function is not used in this example.
27
+ *
28
+ * @note This function is not used in this example.
29
29
*/
30
30
static void publish_callback (void * * unused , struct mqtt_response_publish * published );
31
31
32
32
/**
33
- * @brief Safely closes the socket in \p ctx before \c exit.
33
+ * @brief Safely closes the socket in \p ctx before \c exit.
34
34
*/
35
35
static void exit_example (int status , bearssl_context * ctx );
36
36
37
37
/* The next five functions decode a certificate into BearSSL format */
38
38
39
39
/**
40
40
* @brief Callback function to accumulate data in a buffer
41
- */
41
+ */
42
42
static void vblob_append (void * cc , const void * data , size_t len );
43
43
44
44
/**
@@ -54,14 +54,14 @@ static int certificate_to_trust_anchor(br_x509_certificate *xc, br_x509_trust_an
54
54
/**
55
55
* @brief Generates trust anchors for BearSSL from the contents of \p ca_file and stores them
56
56
* in the \p anchoOut array (based on code in BearSSL tools)
57
- */
57
+ */
58
58
static size_t get_trusted_anchors_from_file (const char * ca_file , br_x509_trust_anchor * * anchOut );
59
59
/**
60
60
* @brief Generates trust anchors for BearSSL from the string \p ca and stores them
61
61
* in the \p anchOut array (based on code in BearSSL tools)
62
- *
62
+ *
63
63
* @returns The number of trust anchors generated
64
- */
64
+ */
65
65
static size_t get_trusted_anchors (const unsigned char * ca , size_t ca_len , br_x509_trust_anchor * * anchOut );
66
66
67
67
// Global to return Ctrl-C event
@@ -76,9 +76,9 @@ void signalHandler(int signum) {
76
76
}
77
77
78
78
/**
79
- * A simple program to that publishes the current time until Ctrl-C is pressed.
79
+ * A simple program to that publishes the current time until Ctrl-C is pressed.
80
80
*/
81
- int main (int argc , const char * argv [])
81
+ int main (int argc , const char * argv [])
82
82
{
83
83
const char * addr ;
84
84
const char * port ;
@@ -126,20 +126,20 @@ int main(int argc, const char *argv[])
126
126
127
127
/* generate BearSSL trusted anchors - specifically kept out of open_nb_socket since it needs to malloc */
128
128
129
- /*
130
- Generate BearSSL trusted anchors
129
+ /*
130
+ Generate BearSSL trusted anchors
131
131
132
- This code converts the certificate into a format that is readable by the BearSSL library. Sadly there isn't
132
+ This code converts the certificate into a format that is readable by the BearSSL library. Sadly there isn't
133
133
a way to accomplish this without the use of malloc thus I specifically kept this code out of open_nb_socket.
134
134
The author of the bearSSL library offers two options:
135
135
136
- 1) Do the conversion of the certificate in your code. There are examples of how to do this. The benefit of
136
+ 1) Do the conversion of the certificate in your code. There are examples of how to do this. The benefit of
137
137
this is that you can run the same code against different servers by providing the appropriate trusted root
138
138
pem file. The function get_trusted_anchors does exactly this.
139
139
140
140
2) Use the tool provided with BearSSL to generate the C code that will initialize the trusted anchor structures.
141
- Essentially it simply generates initialized C structures that you can copy into your code. You will not need
142
- to use malloc but you will lose some flexibility. For information on the tool see
141
+ Essentially it simply generates initialized C structures that you can copy into your code. You will not need
142
+ to use malloc but you will lose some flexibility. For information on the tool see
143
143
this page: https://www.bearssl.org/api1.html
144
144
*/
145
145
ctx .ta_count = get_trusted_anchors_from_file (ca_file , & ctx .anchOut );
@@ -196,7 +196,7 @@ int main(int argc, const char *argv[])
196
196
exit_example (EXIT_FAILURE , & ctx );
197
197
}
198
198
close_socket (& ctx );
199
-
199
+
200
200
if (0 != open_nb_socket (& ctx , addr , port , bearssl_iobuf , sizeof (bearssl_iobuf )))
201
201
{
202
202
fprintf (stderr , "Unable to open socket: %d\n" , errno );
@@ -249,7 +249,7 @@ int main(int argc, const char *argv[])
249
249
return 4 ;
250
250
}
251
251
usleep (100000U );
252
- }
252
+ }
253
253
254
254
/* disconnect */
255
255
printf ("\n%s disconnecting from %s\n" , argv [0 ], addr );
@@ -266,7 +266,7 @@ int main(int argc, const char *argv[])
266
266
267
267
sleep (1 );
268
268
269
- /* exit */
269
+ /* exit */
270
270
exit_example (EXIT_SUCCESS , & ctx );
271
271
}
272
272
@@ -276,7 +276,7 @@ static void exit_example(int status, bearssl_context *ctx)
276
276
exit (status );
277
277
}
278
278
279
- static void publish_callback (void * * unused , struct mqtt_response_publish * published )
279
+ static void publish_callback (void * * unused , struct mqtt_response_publish * published )
280
280
{
281
281
static const char * prelim = "Received publish('" ;
282
282
/* note that published->topic_name is NOT null-terminated (here we'll change it to a c-string) */
@@ -302,7 +302,7 @@ static void vblob_append(void *cc, const void *data, size_t len)
302
302
static void free_ta_contents (br_x509_trust_anchor * ta )
303
303
{
304
304
free (ta -> dn .data );
305
- switch (ta -> pkey .key_type )
305
+ switch (ta -> pkey .key_type )
306
306
{
307
307
case BR_KEYTYPE_RSA :
308
308
free (ta -> pkey .key .rsa .n );
@@ -342,7 +342,7 @@ static int certificate_to_trust_anchor(br_x509_certificate *xc, br_x509_trust_an
342
342
ta -> dn .len = vdn .data_length ;
343
343
ta -> flags = 0 ;
344
344
345
- if (br_x509_decoder_isCA (& dc ))
345
+ if (br_x509_decoder_isCA (& dc ))
346
346
{
347
347
ta -> flags |= BR_X509_TA_CA ;
348
348
}
@@ -403,7 +403,7 @@ static size_t get_trusted_anchors_from_file(const char *ca_file, br_x509_trust_a
403
403
404
404
if (certs != NULL ) {
405
405
size_t read = fread (certs , 1 , fsize , f );
406
-
406
+
407
407
fclose (f );
408
408
409
409
if (read == fsize ) {
0 commit comments