forked from wolfSSL/wolfssl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssl.h
More file actions
15366 lines (12514 loc) · 478 KB
/
ssl.h
File metadata and controls
15366 lines (12514 loc) · 478 KB
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
/*!
\brief This function initializes the DTLS v1.2 client method.
\return pointer This function returns a pointer to a new
WOLFSSL_METHOD structure.
\param none No parameters.
_Example_
\code
wolfSSL_Init();
WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method());
…
WOLFSSL* ssl = wolfSSL_new(ctx);
…
\endcode
\sa wolfSSL_Init
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfDTLSv1_2_client_method_ex(void* heap);
/*!
\ingroup Setup
\brief This function returns a WOLFSSL_METHOD similar to
wolfSSLv23_client_method except that it is not determined
which side yet (server/client).
\return WOLFSSL_METHOD* On successful creations returns a WOLFSSL_METHOD
pointer
\return NULL Null if memory allocation error or failure to create method
\param none No parameters.
_Example_
\code
WOLFSSL* ctx;
ctx = wolfSSL_CTX_new(wolfSSLv23_method());
// check ret value
\endcode
\sa wolfSSL_new
\sa wolfSSL_free
*/
WOLFSSL_METHOD *wolfSSLv23_method(void);
/*!
\ingroup Setup
\brief The wolfSSLv3_server_method() function is used to indicate
that the application is a server and will only support the SSL 3.0
protocol. This function allocates memory for and initializes a new
wolfSSL_METHOD structure to be used when creating the SSL/TLS context
with wolfSSL_CTX_new().
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the
failure value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
#include <wolfssl/ssl.h>
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfSSLv3_server_method();
if (method == NULL) {
unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfTLSv1_server_method
\sa wolfTLSv1_1_server_method
\sa wolfTLSv1_2_server_method
\sa wolfTLSv1_3_server_method
\sa wolfDTLSv1_server_method
\sa wolfSSLv23_server_method
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfSSLv3_server_method(void);
/*!
\ingroup Setup
\brief The wolfSSLv3_client_method() function is used to indicate
that the application is a client and will only support the SSL 3.0
protocol. This function allocates memory for and initializes a
new wolfSSL_METHOD structure to be used when creating the SSL/TLS
context with wolfSSL_CTX_new().
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the
failure value of the underlying malloc() implementation will be
returned (typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
#include <wolfssl/ssl.h>
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfSSLv3_client_method();
if (method == NULL) {
unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfTLSv1_client_method
\sa wolfTLSv1_1_client_method
\sa wolfTLSv1_2_client_method
\sa wolfTLSv1_3_client_method
\sa wolfDTLSv1_client_method
\sa wolfSSLv23_client_method
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfSSLv3_client_method(void);
/*!
\ingroup Setup
\brief The wolfTLSv1_server_method() function is used to indicate that the
application is a server and will only support the TLS 1.0 protocol. This
function allocates memory for and initializes a new wolfSSL_METHOD
structure to be used when creating the SSL/TLS context with
wolfSSL_CTX_new().
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
#include <wolfssl/ssl.h>
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfTLSv1_server_method();
if (method == NULL) {
unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfSSLv3_server_method
\sa wolfTLSv1_1_server_method
\sa wolfTLSv1_2_server_method
\sa wolfTLSv1_3_server_method
\sa wolfDTLSv1_server_method
\sa wolfSSLv23_server_method
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfTLSv1_server_method(void);
/*!
\ingroup Setup
\brief The wolfTLSv1_client_method() function is used to indicate
that the application is a client and will only support the TLS 1.0
protocol. This function allocates memory for and initializes a new
wolfSSL_METHOD structure to be used when creating the SSL/TLS context
with wolfSSL_CTX_new().
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC,
the failure value of the underlying malloc() implementation
will be returned (typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
#include <wolfssl/ssl.h>
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfTLSv1_client_method();
if (method == NULL) {
unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfSSLv3_client_method
\sa wolfTLSv1_1_client_method
\sa wolfTLSv1_2_client_method
\sa wolfTLSv1_3_client_method
\sa wolfDTLSv1_client_method
\sa wolfSSLv23_client_method
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfTLSv1_client_method(void);
/*!
\ingroup Setup
\brief The wolfTLSv1_1_server_method() function is used to indicate
that the application is a server and will only support the TLS 1.1
protocol. This function allocates memory for and initializes a new
wolfSSL_METHOD structure to be used when creating the SSL/TLS
context with wolfSSL_CTX_new().
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
#include <wolfssl/ssl.h>
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfTLSv1_1_server_method();
if (method == NULL) {
// unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfSSLv3_server_method
\sa wolfTLSv1_server_method
\sa wolfTLSv1_2_server_method
\sa wolfTLSv1_3_server_method
\sa wolfDTLSv1_server_method
\sa wolfSSLv23_server_method
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfTLSv1_1_server_method(void);
/*!
\ingroup Setup
\brief The wolfTLSv1_1_client_method() function is used to indicate
that the application is a client and will only support the TLS 1.0
protocol. This function allocates memory for and initializes a
new wolfSSL_METHOD structure to be used when creating the SSL/TLS
context with wolfSSL_CTX_new().
\return * If successful, the call will return a pointer to the
newly created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
#include <wolfssl/ssl.h>
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfTLSv1_1_client_method();
if (method == NULL) {
// unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfSSLv3_client_method
\sa wolfTLSv1_client_method
\sa wolfTLSv1_2_client_method
\sa wolfTLSv1_3_client_method
\sa wolfDTLSv1_client_method
\sa wolfSSLv23_client_method
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfTLSv1_1_client_method(void);
/*!
\ingroup Setup
\brief The wolfTLSv1_2_server_method() function is used to indicate
that the application is a server and will only support the TLS 1.2
protocol. This function allocates memory for and initializes a new
wolfSSL_METHOD structure to be used when creating the SSL/TLS context
with wolfSSL_CTX_new().
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
#include <wolfssl/ssl.h>
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfTLSv1_2_server_method();
if (method == NULL) {
// unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfSSLv3_server_method
\sa wolfTLSv1_server_method
\sa wolfTLSv1_1_server_method
\sa wolfTLSv1_3_server_method
\sa wolfDTLSv1_server_method
\sa wolfSSLv23_server_method
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfTLSv1_2_server_method(void);
/*!
\ingroup Setup
\brief The wolfTLSv1_2_client_method() function is used to indicate
that the application is a client and will only support the TLS 1.2
protocol. This function allocates memory for and initializes a new
wolfSSL_METHOD structure to be used when creating the SSL/TLS context
with wolfSSL_CTX_new().
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
#include <wolfssl/ssl.h>
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfTLSv1_2_client_method();
if (method == NULL) {
// unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfSSLv3_client_method
\sa wolfTLSv1_client_method
\sa wolfTLSv1_1_client_method
\sa wolfTLSv1_3_client_method
\sa wolfDTLSv1_client_method
\sa wolfSSLv23_client_method
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfTLSv1_2_client_method(void);
/*!
\ingroup Setup
\brief The wolfDTLSv1_client_method() function is used to indicate that
the application is a client and will only support the DTLS 1.0 protocol.
This function allocates memory for and initializes a new
wolfSSL_METHOD structure to be used when creating the SSL/TLS context
with wolfSSL_CTX_new(). This function is only available when wolfSSL has
been compiled with DTLS support (--enable-dtls,
or by defining wolfSSL_DTLS).
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfDTLSv1_client_method();
if (method == NULL) {
// unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfSSLv3_client_method
\sa wolfTLSv1_client_method
\sa wolfTLSv1_1_client_method
\sa wolfTLSv1_2_client_method
\sa wolfTLSv1_3_client_method
\sa wolfSSLv23_client_method
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfDTLSv1_client_method(void);
/*!
\ingroup Setup
\brief The wolfDTLSv1_server_method() function is used to indicate
that the application is a server and will only support the DTLS 1.0
protocol. This function allocates memory for and initializes a
new wolfSSL_METHOD structure to be used when creating the SSL/TLS
context with wolfSSL_CTX_new(). This function is only available
when wolfSSL has been compiled with DTLS support (--enable-dtls,
or by defining wolfSSL_DTLS).
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfDTLSv1_server_method();
if (method == NULL) {
// unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfSSLv3_server_method
\sa wolfTLSv1_server_method
\sa wolfTLSv1_1_server_method
\sa wolfTLSv1_2_server_method
\sa wolfTLSv1_3_server_method
\sa wolfSSLv23_server_method
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfDTLSv1_server_method(void);
/*!
\ingroup Setup
\brief The wolfDTLSv1_3_server_method() function is used to indicate that
the application is a server and will only support the DTLS 1.3
protocol. This function allocates memory for and initializes a new
wolfSSL_METHOD structure to be used when creating the SSL/TLS context with
wolfSSL_CTX_new(). This function is only available when wolfSSL has been
compiled with DTLSv1.3 support (--enable-dtls13, or by defining
wolfSSL_DTLS13).
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfDTLSv1_3_server_method();
if (method == NULL) {
// unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfDTLSv1_3_client_method
*/
WOLFSSL_METHOD *wolfDTLSv1_3_server_method(void);
/*!
\ingroup Setup
\brief The wolfDTLSv1_3_client_method() function is used to indicate that
the application is a client and will only support the DTLS 1.3
protocol. This function allocates memory for and initializes a new
wolfSSL_METHOD structure to be used when creating the SSL/TLS context with
wolfSSL_CTX_new(). This function is only available when wolfSSL has been
compiled with DTLSv1.3 support (--enable-dtls13, or by defining
wolfSSL_DTLS13).
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfDTLSv1_3_client_method();
if (method == NULL) {
// unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfDTLSv1_3_server_method
*/
WOLFSSL_METHOD* wolfDTLSv1_3_client_method(void);
/*!
\ingroup Setup
\brief The wolfDTLS_server_method() function is used to indicate that the
application is a server and will support the highest version of DTLS
available and all the version up to the minimum version allowed. The
default minimum version allowed is based on the define
WOLFSSL_MIN_DTLS_DOWNGRADE and can be changed at runtime using
wolfSSL_SetMinVersion(). This function allocates memory for and initializes
a new wolfSSL_METHOD structure to be used when creating the SSL/TLS context
with wolfSSL_CTX_new(). This function is only available when wolfSSL has
been compiled with DTLS support (--enable-dtls, or by defining
wolfSSL_DTLS).
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfDTLS_server_method();
if (method == NULL) {
// unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfDTLS_client_method
\sa wolfSSL_SetMinVersion
*/
WOLFSSL_METHOD *wolfDTLS_server_method(void);
/*!
\ingroup Setup
\brief The wolfDTLS_client_method() function is used to indicate that the
application is a client and will support the highest version of DTLS
available and all the version up to the minimum version allowed. The
default minimum version allowed is based on the define
WOLFSSL_MIN_DTLS_DOWNGRADE and can be changed at runtime using
wolfSSL_SetMinVersion(). This function allocates memory for and initializes
a new wolfSSL_METHOD structure to be used when creating the SSL/TLS context
with wolfSSL_CTX_new(). This function is only available when wolfSSL has
been compiled with DTLS support (--enable-dtls, or by defining
wolfSSL_DTLS).
\return * If successful, the call will return a pointer to the newly
created WOLFSSL_METHOD structure.
\return FAIL If memory allocation fails when calling XMALLOC, the failure
value of the underlying malloc() implementation will be returned
(typically NULL with errno will be set to ENOMEM).
\param none No parameters.
_Example_
\code
WOLFSSL_METHOD* method;
WOLFSSL_CTX* ctx;
method = wolfDTLS_client_method();
if (method == NULL) {
// unable to get method
}
ctx = wolfSSL_CTX_new(method);
...
\endcode
\sa wolfDTLS_server_method
\sa wolfSSL_SetMinVersion
*/
WOLFSSL_METHOD *wolfDTLS_client_method(void);
/*!
\brief This function creates and initializes a WOLFSSL_METHOD for the
server side.
\return This function returns a WOLFSSL_METHOD pointer.
\param none No parameters.
_Example_
\code
WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
WOLFSSL* ssl = WOLFSSL_new(ctx);
…
\endcode
\sa wolfSSL_CTX_new
*/
WOLFSSL_METHOD *wolfDTLSv1_2_server_method(void);
/*!
\ingroup Setup
\brief Since there is some differences between the first release and
newer versions of chacha-poly AEAD construction we have added an option
to communicate with servers/clients using the older version. By default
wolfSSL uses the new version.
\return 0 upon success
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param value whether or not to use the older version of setting up the
information for poly1305. Passing a flag value of 1 indicates yes use the
old poly AEAD, to switch back to using the new version pass a flag value
of 0.
_Example_
\code
int ret = 0;
WOLFSSL* ssl;
...
ret = wolfSSL_use_old_poly(ssl, 1);
if (ret != 0) {
// failed to set poly1305 AEAD version
}
\endcode
\sa none
*/
int wolfSSL_use_old_poly(WOLFSSL* ssl, int value);
/*!
\brief The wolfSSL_dtls_import() function is used to parse in a serialized
session state. This allows for picking up the connection after the
handshake has been completed.
\return Success If successful, the amount of the buffer read will be
returned.
\return Failure All unsuccessful return values will be less than 0.
\return VERSION_ERROR If a version mismatch is found ie DTLS v1 and ctx
was set up for DTLS v1.2 then VERSION_ERROR is returned.
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param buf serialized session to import.
\param sz size of serialized session buffer.
_Example_
\code
WOLFSSL* ssl;
int ret;
unsigned char buf[MAX];
bufSz = MAX;
...
//get information sent from wc_dtls_export function and place it in buf
fread(buf, 1, bufSz, input);
ret = wolfSSL_dtls_import(ssl, buf, bufSz);
if (ret < 0) {
// handle error case
}
// no wolfSSL_accept needed since handshake was already done
...
ret = wolfSSL_write(ssl) and wolfSSL_read(ssl);
...
\endcode
\sa wolfSSL_new
\sa wolfSSL_CTX_new
\sa wolfSSL_CTX_dtls_set_export
*/
int wolfSSL_dtls_import(WOLFSSL* ssl, unsigned char* buf,
unsigned int sz);
/*!
\brief Used to import a serialized TLS session. This function is for
importing the state of the connection.
WARNING: buf contains sensitive information about the state and is best to
be encrypted before storing if stored.
Additional debug info can be displayed with the macro
WOLFSSL_SESSION_EXPORT_DEBUG defined.
\return the number of bytes read from buffer 'buf'
\param ssl WOLFSSL structure to import the session into
\param buf serialized session
\param sz size of buffer 'buf'
\sa wolfSSL_dtls_import
\sa wolfSSL_tls_export
*/
int wolfSSL_tls_import(WOLFSSL* ssl, const unsigned char* buf,
unsigned int sz);
/*!
\brief The wolfSSL_CTX_dtls_set_export() function is used to set
the callback function for exporting a session. It is allowed to
pass in NULL as the parameter func to clear the export function
previously stored. Used on the server side and is called immediately
after handshake is completed.
\return SSL_SUCCESS upon success.
\return BAD_FUNC_ARG If null or not expected arguments are passed in
\param ctx a pointer to a WOLFSSL_CTX structure, created
with wolfSSL_CTX_new().
\param func wc_dtls_export function to use when exporting a session.
_Example_
\code
int send_session(WOLFSSL* ssl, byte* buf, word32 sz, void* userCtx);
// body of send session (wc_dtls_export) that passes
// buf (serialized session) to destination
WOLFSSL_CTX* ctx;
int ret;
...
ret = wolfSSL_CTX_dtls_set_export(ctx, send_session);
if (ret != SSL_SUCCESS) {
// handle error case
}
...
ret = wolfSSL_accept(ssl);
...
\endcode
\sa wolfSSL_new
\sa wolfSSL_CTX_new
\sa wolfSSL_dtls_set_export
\sa Static buffer use
*/
int wolfSSL_CTX_dtls_set_export(WOLFSSL_CTX* ctx,
wc_dtls_export func);
/*!
\brief The wolfSSL_dtls_set_export() function is used to set the callback
function for exporting a session. It is allowed to pass in NULL as the
parameter func to clear the export function previously stored. Used on
the server side and is called immediately after handshake is completed.
\return SSL_SUCCESS upon success.
\return BAD_FUNC_ARG If null or not expected arguments are passed in
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param func wc_dtls_export function to use when exporting a session.
_Example_
\code
int send_session(WOLFSSL* ssl, byte* buf, word32 sz, void* userCtx);
// body of send session (wc_dtls_export) that passes
// buf (serialized session) to destination
WOLFSSL* ssl;
int ret;
...
ret = wolfSSL_dtls_set_export(ssl, send_session);
if (ret != SSL_SUCCESS) {
// handle error case
}
...
ret = wolfSSL_accept(ssl);
...
\endcode
\sa wolfSSL_new
\sa wolfSSL_CTX_new
\sa wolfSSL_CTX_dtls_set_export
*/
int wolfSSL_dtls_set_export(WOLFSSL* ssl, wc_dtls_export func);
/*!
\brief The wolfSSL_dtls_export() function is used to serialize a
WOLFSSL session into the provided buffer. Allows for less memory
overhead than using a function callback for sending a session and
choice over when the session is serialized. If buffer is NULL when
passed to function then sz will be set to the size of buffer needed
for serializing the WOLFSSL session.
\return Success If successful, the amount of the buffer used will
be returned.
\return Failure All unsuccessful return values will be less than 0.
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param buf buffer to hold serialized session.
\param sz size of buffer.
_Example_
\code
WOLFSSL* ssl;
int ret;
unsigned char buf[MAX];
bufSz = MAX;
...
ret = wolfSSL_dtls_export(ssl, buf, bufSz);
if (ret < 0) {
// handle error case
}
...
\endcode
\sa wolfSSL_new
\sa wolfSSL_CTX_new
\sa wolfSSL_CTX_dtls_set_export
\sa wolfSSL_dtls_import
*/
int wolfSSL_dtls_export(WOLFSSL* ssl, unsigned char* buf,
unsigned int* sz);
/*!
\brief Used to export a serialized TLS session. This function is for
exporting a serialized state of the connection.
In most cases wolfSSL_get1_session should be used instead of
wolfSSL_tls_export.
Additional debug info can be displayed with the macro
WOLFSSL_SESSION_EXPORT_DEBUG defined.
WARNING: buf contains sensitive information about the state and is best to
be encrypted before storing if stored.
\return the number of bytes written into buffer 'buf'
\param ssl WOLFSSL structure to export the session from
\param buf output of serialized session
\param sz size in bytes set in 'buf'
\sa wolfSSL_dtls_import
\sa wolfSSL_tls_import
*/
int wolfSSL_tls_export(WOLFSSL* ssl, unsigned char* buf,
unsigned int* sz);
/*!
\brief This function is used to set aside static memory for a CTX. Memory
set aside is then used for the CTX’s lifetime and for any SSL objects
created from the CTX. By passing in a NULL ctx pointer and a
wolfSSL_method_func function the creation of the CTX itself will also
use static memory. wolfSSL_method_func has the function signature of
WOLFSSL_METHOD* (*wolfSSL_method_func)(void* heap);. Passing in 0 for max
makes it behave as if not set and no max concurrent use restrictions is
in place. The flag value passed in determines how the memory is used and
behavior while operating. Available flags are the following: 0 - default
general memory, WOLFMEM_IO_POOL - used for input/output buffer when
sending receiving messages and overrides general memory, so all memory
in buffer passed in is used for IO, WOLFMEM_IO_FIXED - same as
WOLFMEM_IO_POOL but each SSL now keeps two buffers to themselves for
their lifetime, WOLFMEM_TRACK_STATS - each SSL keeps track of memory
stats while running.
\return SSL_SUCCESS upon success.
\return SSL_FAILURE upon failure.
\param ctx address of pointer to a WOLFSSL_CTX structure.
\param method function to create protocol. (should be NULL if ctx is not
also NULL)
\param buf memory to use for all operations.
\param sz size of memory buffer being passed in.
\param flag type of memory.
\param max max concurrent operations.
_Example_
\code
WOLFSSL_CTX* ctx;
WOLFSSL* ssl;
int ret;
unsigned char memory[MAX];
int memorySz = MAX;
unsigned char IO[MAX];
int IOSz = MAX;
int flag = WOLFMEM_IO_FIXED | WOLFMEM_TRACK_STATS;
...
// create ctx also using static memory, start with general memory to use
ctx = NULL:
ret = wolfSSL_CTX_load_static_memory(&ctx, wolfSSLv23_server_method_ex,
memory, memorySz, 0, MAX_CONCURRENT_HANDSHAKES);
if (ret != SSL_SUCCESS) {
// handle error case
}
// load in memory for use with IO
ret = wolfSSL_CTX_load_static_memory(&ctx, NULL, IO, IOSz, flag,
MAX_CONCURRENT_IO);
if (ret != SSL_SUCCESS) {
// handle error case
}
...
\endcode
\sa wolfSSL_CTX_new
\sa wolfSSL_CTX_is_static_memory
\sa wolfSSL_is_static_memory
*/
int wolfSSL_CTX_load_static_memory(WOLFSSL_CTX** ctx,
wolfSSL_method_func method,
unsigned char* buf, unsigned int sz,
int flag, int max);
/*!
\brief This function does not change any of the connections behavior
and is used only for gathering information about the static memory usage.
\return 1 is returned if using static memory for the CTX is true.
\return 0 is returned if not using static memory.
\param ctx a pointer to a WOLFSSL_CTX structure, created using
wolfSSL_CTX_new().
\param mem_stats structure to hold information about static memory usage.
_Example_
\code
WOLFSSL_CTX* ctx;
int ret;
WOLFSSL_MEM_STATS mem_stats;
...
//get information about static memory with CTX
ret = wolfSSL_CTX_is_static_memory(ctx, &mem_stats);
if (ret == 1) {
// handle case of is using static memory
// print out or inspect elements of mem_stats
}
if (ret == 0) {
//handle case of ctx not using static memory
}
…
\endcode
\sa wolfSSL_CTX_new
\sa wolfSSL_CTX_load_static_memory
\sa wolfSSL_is_static_memory
*/
int wolfSSL_CTX_is_static_memory(WOLFSSL_CTX* ctx,
WOLFSSL_MEM_STATS* mem_stats);
/*!
\brief wolfSSL_is_static_memory is used to gather information about
a SSL’s static memory usage. The return value indicates if static
memory is being used and WOLFSSL_MEM_CONN_STATS will be filled out
if and only if the flag WOLFMEM_TRACK_STATS was passed to the parent
CTX when loading in static memory.
\return 1 is returned if using static memory for the CTX is true.
\return 0 is returned if not using static memory.
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param mem_stats structure to contain static memory usage.
_Example_
\code
WOLFSSL* ssl;
int ret;
WOLFSSL_MEM_CONN_STATS mem_stats;
...