-
Notifications
You must be signed in to change notification settings - Fork 106
/
mbedtlsstub.c
2247 lines (1899 loc) · 51.7 KB
/
mbedtlsstub.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
* modules/mbedtls_stub/api/mbedtlsstub.c
*
* Copyright 2021 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <errno.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <nuttx/wireless/lte/lte_ioctl.h>
#include <mbedtls/ssl.h>
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/x509_csr.h>
#include <mbedtls/entropy.h>
#include <mbedtls/pk_internal.h>
#include <mbedtls/md_internal.h>
#include <mbedtls/net_sockets.h>
#include "lte/lapi.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef ARRAY_SZ
# define ARRAY_SZ(array) (sizeof(array)/sizeof(array[0]))
#endif
#define CIPHER_STR_BUF 64
#define TLS_UNKNOWN "unknown"
/****************************************************************************
* Private Data
****************************************************************************/
static char cipher_str_buf[CIPHER_STR_BUF] = {0};
static mbedtls_x509_crt g_x509_crt = {0};
static struct mbedtls_pk_info_t g_pk_info = {0};
static mbedtls_rsa_context g_rsa_context = {0};
static mbedtls_cipher_info_t g_cipher_info = {0};
static mbedtls_md_info_t g_md_info = {0};
static sem_t g_vrfylock = SEM_INITIALIZER(1);
static int (*g_f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
static void *g_p_vrfy;
/****************************************************************************
* Private Functions
****************************************************************************/
static inline void ssllock(FAR sem_t *lock)
{
int ret;
do
{
ret = sem_wait(lock);
}
while (ret == -EINTR);
}
static inline void sslunlock(FAR sem_t *lock)
{
sem_post(lock);
}
static int32_t mbedtls_load_local_file(const char *path, unsigned char **buf, size_t *len)
{
FILE *fd;
size_t size;
fpos_t end_pos = 0;
/* Check file size */
if ((fd = fopen( path, "rb" )) == NULL)
{
return (MBEDTLS_ERR_PK_FILE_IO_ERROR);
}
fseek(fd, 0, SEEK_END);
if (0 != fgetpos(fd, &end_pos))
{
fclose(fd);
return(MBEDTLS_ERR_PK_FILE_IO_ERROR);
}
fseek(fd, 0, SEEK_SET);
if (end_pos <= 0)
{
fclose(fd);
return(MBEDTLS_ERR_PK_FILE_IO_ERROR);
}
size = end_pos;
/* Malloc buffer */
*len = (size_t) size;
if ((*len+1 == 0) || ((*buf = malloc(*len+1)) == NULL ))
{
fclose(fd);
return(MBEDTLS_ERR_PK_ALLOC_FAILED);
}
/* Read certificate file */
if (fread(*buf, 1, *len, fd) != *len)
{
fclose(fd);
free(*buf);
return(MBEDTLS_ERR_PK_FILE_IO_ERROR);
}
fclose(fd);
(*buf)[*len] = '\0';
if (strstr((const char *)*buf, "-----BEGIN ") != NULL)
{
++*len;
}
return(0);
}
static void verifycb_event(FAR void **cbarg)
{
int ret;
uint32_t flags = 0;
uint32_t id = *((FAR uint32_t *)cbarg[0]);
int32_t depth = *((FAR int32_t *)cbarg[1]);
int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
void *p_vrfy;
mbedtls_x509_crt crt =
{
};
FAR void *inarg[] =
{
&ret, &flags
};
crt.id = id;
ssllock(&g_vrfylock);
f_vrfy = g_f_vrfy;
p_vrfy = g_p_vrfy;
sslunlock(&g_vrfylock);
if (f_vrfy)
{
ret = f_vrfy(p_vrfy, &crt, depth, &flags);
lapi_req(LTE_CMDID_TLS_CONFIG_VERIFY_CALLBACK | LTE_CMDOPT_ASYNC_BIT,
(FAR void *)inarg, ARRAY_SZ(inarg),
NULL, 0, NULL);
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
void mbedtls_ssl_init(mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
FAR void *inarg[] = {&ssl->id};
FAR void *outarg[] = {&result, ssl};
ret = lapi_req(LTE_CMDID_TLS_SSL_INIT,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
void mbedtls_ssl_free(mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
FAR void *inarg[] = {ssl};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_FREE,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
int mbedtls_ssl_setup(mbedtls_ssl_context *ssl, const mbedtls_ssl_config *conf)
{
int ret;
int32_t result;
FAR void *inarg[] = {ssl, (void *)conf};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_SETUP,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
int mbedtls_ssl_set_hostname(mbedtls_ssl_context *ssl, const char *hostname)
{
int ret;
int32_t result;
FAR void *inarg[] = {ssl, (void *)hostname};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_HOSTNAME,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
void mbedtls_ssl_set_bio(mbedtls_ssl_context *ssl, void *p_bio, mbedtls_ssl_send_t *f_send, mbedtls_ssl_recv_t *f_recv, mbedtls_ssl_recv_timeout_t *f_recv_timeout)
{
int32_t result;
int fd;
FAR void *inarg[] = {ssl, p_bio, f_send, f_recv, f_recv_timeout, &fd};
FAR void *outarg[] = {&result};
struct lte_ioctl_data_s cmd;
if (!p_bio)
{
return;
}
cmd.cmdid = LTE_CMDID_TLS_SSL_BIO;
cmd.inparam = inarg;
cmd.inparamlen = ARRAY_SZ(inarg);
cmd.outparam = outarg;
cmd.outparamlen = ARRAY_SZ(outarg);
cmd.cb = NULL;
ioctl(((mbedtls_net_context *)p_bio)->fd, SIOCLTECMD, (unsigned long)&cmd);
return ;
}
int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
FAR void *inarg[] = {ssl};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_HANDSHAKE,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
int mbedtls_ssl_write(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len)
{
int ret;
int32_t result;
FAR void *inarg[] = {ssl, (void *)buf, &len};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_WRITE,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len)
{
int ret;
int32_t result;
FAR void *inarg[] = {ssl, &len};
FAR void *outarg[] = {&result, buf, &len};
ret = lapi_req(LTE_CMDID_TLS_SSL_READ,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
int mbedtls_ssl_close_notify(mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
FAR void *inarg[] = {ssl};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_CLOSE_NOTIFY,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
const char *mbedtls_ssl_get_version(const mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
const char* res_version = TLS_UNKNOWN;
FAR void *inarg[] = {(void *)ssl};
FAR void *outarg[] = {&result, (void *)&res_version};
ret = lapi_req(LTE_CMDID_TLS_SSL_VERSION,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
return res_version;
}
else
{
return NULL;
}
}
const char *mbedtls_ssl_get_ciphersuite(const mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
FAR void *inarg[] = {(void *)ssl};
FAR void *outarg[] = {&result, cipher_str_buf};
ret = lapi_req(LTE_CMDID_TLS_SSL_CIPHERSUITE,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
return cipher_str_buf;
}
else
{
return NULL;
}
}
int mbedtls_ssl_get_ciphersuite_id(const char *ciphersuite_name)
{
int ret;
int32_t result;
FAR void *inarg[] = {(void *)ciphersuite_name};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_CIPHERSUITE_ID,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
int mbedtls_ssl_get_record_expansion(const mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
FAR void *inarg[] = {(void *)ssl};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_RECORD_EXPANSION,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
uint32_t mbedtls_ssl_get_verify_result(const mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
FAR void *inarg[] = {(void *)ssl};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_VERIFY_RESULT,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
void mbedtls_ssl_set_timer_cb(mbedtls_ssl_context *ssl, void *p_timer, mbedtls_ssl_set_timer_t *f_set_timer, mbedtls_ssl_get_timer_t *f_get_timer)
{
int ret;
int32_t result;
FAR void *inarg[] = {ssl, p_timer, f_set_timer, f_get_timer};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_TIMER_CB,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert(const mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
FAR void *inarg[] = {(void *)ssl};
FAR void *outarg[] = {&result, &g_x509_crt};
ret = lapi_req(LTE_CMDID_TLS_SSL_PEER_CERT,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
return &g_x509_crt;
}
else
{
return NULL;
}
}
size_t mbedtls_ssl_get_bytes_avail(const mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
FAR void *inarg[] = {(void *)ssl};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SSL_BYTES_AVAIL,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
return result;
}
else
{
return 0;
}
}
void mbedtls_ssl_config_init(mbedtls_ssl_config *conf)
{
int ret;
int32_t result;
FAR void *inarg[] = {&conf->id};
FAR void *outarg[] = {&result, conf};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_INIT,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
void mbedtls_ssl_config_free(mbedtls_ssl_config *conf)
{
int ret;
int32_t result;
FAR void *inarg[] = {conf};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_FREE,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
int mbedtls_ssl_config_defaults(mbedtls_ssl_config *conf, int endpoint, int transport, int preset)
{
int ret;
int32_t result;
FAR void *inarg[] = {conf, &endpoint, &transport, &preset};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_DEFAULTS,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
void mbedtls_ssl_conf_authmode(mbedtls_ssl_config *conf, int authmode)
{
int ret;
int32_t result;
FAR void *inarg[] = {conf, &authmode};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_AUTHMODE,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
void mbedtls_ssl_conf_rng(mbedtls_ssl_config *conf, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
{
int ret;
int32_t result;
FAR void *inarg[] = {conf, f_rng, p_rng};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_RNG,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
void mbedtls_ssl_conf_ca_chain(mbedtls_ssl_config *conf, mbedtls_x509_crt *ca_chain, mbedtls_x509_crl *ca_crl)
{
int ret;
int32_t result;
FAR void *inarg[] = {conf, ca_chain, ca_crl};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_CA_CHAIN,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
int mbedtls_ssl_conf_own_cert(mbedtls_ssl_config *conf, mbedtls_x509_crt *own_cert, mbedtls_pk_context *pk_key)
{
int ret;
int32_t result;
FAR void *inarg[] = {conf, own_cert, pk_key};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_OWN_CERT,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
void mbedtls_ssl_conf_read_timeout(mbedtls_ssl_config *conf, uint32_t timeout)
{
int ret;
int32_t result;
FAR void *inarg[] = {conf, &timeout};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_READ_TIMEOUT,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
void mbedtls_ssl_conf_verify(mbedtls_ssl_config *conf, int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), void *p_vrfy)
{
int ret;
int32_t result;
FAR void *inarg[] = {conf, f_vrfy, p_vrfy};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_VERIFY,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
verifycb_event);
if (ret == 0)
{
ret = result;
/* Only one callback can be registered with mbedtls_ssl_conf_verify().
* Therefore, note that if mbedtls_ssl_conf_verify() is executed,
* it will be overwritten.
*/
ssllock(&g_vrfylock);
g_f_vrfy = f_vrfy;
g_p_vrfy = p_vrfy;
sslunlock(&g_vrfylock);
}
return ;
}
int mbedtls_ssl_conf_alpn_protocols(mbedtls_ssl_config *conf, const char **protos)
{
int ret;
int32_t result;
FAR void *inarg[] = {conf, protos};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_ALPN_PROTOCOLS,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
void mbedtls_ssl_conf_ciphersuites(mbedtls_ssl_config *conf, const int *ciphersuites)
{
int ret;
int32_t result;
FAR void *inarg[] = {conf, (void *)ciphersuites};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_CONFIG_CIPHERSUITES,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
void mbedtls_ssl_session_init(mbedtls_ssl_session *session)
{
int ret;
int32_t result;
FAR void *inarg[] = {&session->id};
FAR void *outarg[] = {&result, session};
ret = lapi_req(LTE_CMDID_TLS_SESSION_INIT,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
void mbedtls_ssl_session_free(mbedtls_ssl_session *session)
{
int ret;
int32_t result;
FAR void *inarg[] = {session};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SESSION_FREE,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
int mbedtls_ssl_get_session(const mbedtls_ssl_context *ssl, mbedtls_ssl_session *session)
{
int ret;
int32_t result;
FAR void *inarg[] = {(void *)ssl, session};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SESSION_GET,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
int mbedtls_ssl_set_session(mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session)
{
int ret;
int32_t result;
FAR void *inarg[] = {ssl, (void *)session};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SESSION_SET,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
int mbedtls_ssl_session_reset(mbedtls_ssl_context *ssl)
{
int ret;
int32_t result;
FAR void *inarg[] = {ssl};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_SESSION_RESET,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
void mbedtls_x509_crt_init(mbedtls_x509_crt *crt)
{
int ret;
int32_t result;
FAR void *inarg[] = {&crt->id};
FAR void *outarg[] = {&result, crt};
ret = lapi_req(LTE_CMDID_TLS_X509_CRT_INIT,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
void mbedtls_x509_crt_free(mbedtls_x509_crt *crt)
{
int ret;
int32_t result;
FAR void *inarg[] = {crt};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_X509_CRT_FREE,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ;
}
int mbedtls_x509_crt_parse_file(mbedtls_x509_crt *chain, const char *path)
{
int ret;
int32_t result;
FAR void *inarg[] = {chain, (void *)path};
FAR void *outarg[] = {&result};
FAR unsigned char *parse_buf = NULL;
size_t parse_len;
result = mbedtls_load_local_file(path, &parse_buf, &parse_len);
if (result == 0)
{
ret = mbedtls_x509_crt_parse(chain, parse_buf, parse_len);
free(parse_buf);
}
else
{
ret = lapi_req(LTE_CMDID_TLS_X509_CRT_PARSE_FILE,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
}
return ret;
}
int mbedtls_x509_crt_parse_der(mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen)
{
int ret;
int32_t result;
FAR void *inarg[] = {chain, (void *)buf, &buflen};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_X509_CRT_PARSE_DER,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
int mbedtls_x509_crt_parse(mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen)
{
int ret;
int32_t result;
FAR void *inarg[] = {chain, (void *)buf, &buflen};
FAR void *outarg[] = {&result};
ret = lapi_req(LTE_CMDID_TLS_X509_CRT_PARSE,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
int mbedtls_x509_crt_info(char *buf, size_t size, const char *prefix, const mbedtls_x509_crt *crt)
{
int ret;
int32_t result;
FAR void *inarg[] = {&size, (void *)prefix, (void *)crt};
FAR void *outarg[] = {&result, buf, &size};
ret = lapi_req(LTE_CMDID_TLS_X509_CRT_INFO,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
int mbedtls_x509_crt_verify_info(char *buf, size_t size, const char *prefix, uint32_t flags)
{
int ret;
int32_t result;
FAR void *inarg[] = {&size, (void *)prefix, &flags};
FAR void *outarg[] = {&result, buf, &size};
ret = lapi_req(LTE_CMDID_TLS_X509_CRT_VERIFY_INFO,
(FAR void *)inarg, ARRAY_SZ(inarg),
(FAR void *)outarg, ARRAY_SZ(outarg),
NULL);
if (ret == 0)
{
ret = result;
}
return ret;
}
void mbedtls_pk_init(mbedtls_pk_context *ctx)
{