-
Notifications
You must be signed in to change notification settings - Fork 970
Expand file tree
/
Copy pathasn_public.h
More file actions
4175 lines (3426 loc) · 130 KB
/
asn_public.h
File metadata and controls
4175 lines (3426 loc) · 130 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
/*!
\ingroup ASN
\brief This function initializes a default cert, with the default options:
version = 3 (0x2), serial = 0, sigType = SHA_WITH_RSA, issuer = blank,
daysValid = 500, selfSigned = 1 (true) use subject as issuer,
subject = blank
\return none No returns.
\param cert pointer to an uninitialized cert structure to initialize
_Example_
\code
Cert myCert;
wc_InitCert(&myCert);
\endcode
\sa wc_MakeCert
\sa wc_MakeCertReq
*/
int wc_InitCert(Cert* cert);
/*!
\ingroup ASN
\brief This function allocates a new Cert structure for use during
cert operations without the application having to allocate the structure
itself. The Cert structure is also initialized by this function thus
removing the need to call wc_InitCert(). When the application is finished
using the allocated Cert structure wc_CertFree() must be called.
\return pointer If successful the call will return a pointer to the
newly allocated and initialized Cert.
\return NULL On a memory allocation failure.
\param A pointer to the heap used for dynamic allocation. Can be NULL.
_Example_
\code
Cert* myCert;
myCert = wc_CertNew(NULL);
if (myCert == NULL) {
// Cert creation failure
}
\endcode
\sa wc_InitCert
\sa wc_MakeCert
\sa wc_CertFree
*/
Cert* wc_CertNew(void* heap);
/*!
\ingroup ASN
\brief Initializes certificate with heap hint and device ID.
\return 0 on success
\return BAD_FUNC_ARG if cert is NULL
\param cert Cert structure to initialize
\param heap Heap hint for memory allocation
\param devId Device ID for hardware acceleration
_Example_
\code
Cert myCert;
int ret = wc_InitCert_ex(&myCert, NULL, INVALID_DEVID);
if (ret != 0) {
// error initializing cert
}
\endcode
\sa wc_InitCert
\sa wc_MakeCert_ex
*/
int wc_InitCert_ex(Cert* cert, void* heap, int devId);
/*!
\ingroup ASN
\brief This function frees the memory allocated for a cert structure
by a previous call to wc_CertNew().
\return None.
\param A pointer to the cert structure to free.
_Example_
\code
Cert* myCert;
myCert = wc_CertNew(NULL);
// Perform cert operations.
wc_CertFree(myCert);
\endcode
\sa wc_InitCert
\sa wc_MakeCert
\sa wc_CertNew
*/
void wc_CertFree(Cert* cert);
/*!
\ingroup ASN
\brief Used to make CA signed certs. Called after the subject information
has been entered. This function makes an x509 Certificate v3 RSA or ECC
from a cert input. It then writes this cert to derBuffer. It takes in
either an rsaKey or an eccKey to generate the certificate. The certificate
must be initialized with wc_InitCert before this method is called.
\return Success On successfully making an x509 certificate from the
specified input cert, returns the size of the cert generated.
\return MEMORY_E Returned if there is an error allocating memory
with XMALLOC
\return BUFFER_E Returned if the provided derBuffer is too small to
store the generated certificate
\return Others Additional error messages may be returned if the cert
generation is not successful.
\param cert pointer to an initialized cert structure
\param derBuffer pointer to the buffer in which to hold the generated cert
\param derSz size of the buffer in which to store the cert
\param rsaKey pointer to an RsaKey structure containing the rsa key used
to generate the certificate
\param eccKey pointer to an EccKey structure containing the ecc key used
to generate the certificate
\param rng pointer to the random number generator used to make the cert
_Example_
\code
Cert myCert;
wc_InitCert(&myCert);
WC_RNG rng;
//initialize rng;
RsaKey key;
//initialize key;
byte * derCert = malloc(FOURK_BUF);
word32 certSz;
certSz = wc_MakeCert(&myCert, derCert, FOURK_BUF, &key, NULL, &rng);
\endcode
\sa wc_InitCert
\sa wc_MakeCertReq
*/
int wc_MakeCert(Cert* cert, byte* derBuffer, word32 derSz, RsaKey* rsaKey,
ecc_key* eccKey, WC_RNG* rng);
/*!
\ingroup ASN
\brief Makes certificate with generic key type support.
\return Size of certificate on success
\return MEMORY_E if memory allocation fails
\return BUFFER_E if buffer too small
\return Other error codes on failure
\param cert Initialized cert structure
\param derBuffer Buffer for generated certificate
\param derSz Size of derBuffer
\param keyType Key type (RSA_TYPE, ECC_TYPE, ED25519_TYPE, etc.)
\param key Pointer to key structure
\param rng Random number generator
_Example_
\code
Cert myCert;
wc_InitCert(&myCert);
byte derCert[4096];
RsaKey key;
WC_RNG rng;
int certSz = wc_MakeCert_ex(&myCert, derCert, sizeof(derCert),
RSA_TYPE, &key, &rng);
\endcode
\sa wc_MakeCert
\sa wc_SignCert_ex
*/
int wc_MakeCert_ex(Cert* cert, byte* derBuffer, word32 derSz,
int keyType, void* key, WC_RNG* rng);
/*!
\ingroup ASN
\brief Makes certificate request with generic key type support.
\return Size of certificate request on success
\return MEMORY_E if memory allocation fails
\return BUFFER_E if buffer too small
\return Other error codes on failure
\param cert Initialized cert structure
\param derBuffer Buffer for generated certificate request
\param derSz Size of derBuffer
\param keyType Key type (RSA_TYPE, ECC_TYPE, ED25519_TYPE, etc.)
\param key Pointer to key structure
_Example_
\code
Cert myCert;
wc_InitCert(&myCert);
byte derCert[4096];
EccKey key;
int certSz = wc_MakeCertReq_ex(&myCert, derCert, sizeof(derCert),
ECC_TYPE, &key);
\endcode
\sa wc_MakeCertReq
\sa wc_SignCert_ex
*/
int wc_MakeCertReq_ex(Cert* cert, byte* derBuffer, word32 derSz,
int keyType, void* key);
/*!
\ingroup ASN
\brief Signs certificate with generic key type support.
\return New size of certificate with signature on success
\return MEMORY_E if memory allocation fails
\return BUFFER_E if buffer too small
\return Other error codes on failure
\param requestSz Size of certificate body to sign
\param sType Signature type
\param buf Buffer containing certificate to sign
\param buffSz Total size of buffer
\param keyType Key type (RSA_TYPE, ECC_TYPE, ED25519_TYPE, etc.)
\param key Pointer to key structure
\param rng Random number generator
_Example_
\code
Cert myCert;
byte derCert[4096];
RsaKey key;
WC_RNG rng;
// Initialize cert and set fields (issuer, subject, dates, etc.)
wc_InitCert(&myCert);
// ... set myCert fields ...
// Generate certificate body (TBS - To Be Signed)
int bodySz = wc_MakeCert_ex(&myCert, derCert, sizeof(derCert),
RSA_TYPE, &key, &rng);
if (bodySz > 0) {
// bodySz is the size of the unsigned certificate body
// Sign the certificate body and append signature
int certSz = wc_SignCert_ex(bodySz, CTC_SHA256wRSA,
derCert, sizeof(derCert), RSA_TYPE,
&key, &rng);
// derCert now contains complete signed certificate of size certSz
}
\endcode
\sa wc_SignCert
\sa wc_MakeCert_ex
*/
int wc_SignCert_ex(int requestSz, int sType, byte* buf, word32 buffSz,
int keyType, void* key, WC_RNG* rng);
/*!
\ingroup ASN
\brief Makes signature with bit string encoding. This function is used
for dual algorithm certificate signing, where an alternative signature
is created using a secondary key algorithm (e.g., a post-quantum algorithm
alongside a traditional algorithm).
\note This API is only available when WOLFSSL_DUAL_ALG_CERTS is defined,
which enables support for dual algorithm certificates used in Post-Quantum
cryptography to provide hybrid signing with both traditional and PQ
algorithms.
\return Size of signature on success
\return Negative on error
\param sig Output buffer for signature
\param sigSz Size of signature buffer
\param sType Signature type
\param buf Data to sign (typically the TBS - To Be Signed -
certificate data)
\param bufSz Size of data
\param keyType Key type (RSA_TYPE, ECC_TYPE, ED25519_TYPE, etc.)
\param key Pointer to key structure
\param rng Random number generator
_Example_
\code
byte sig[512], data[256];
RsaKey key;
WC_RNG rng;
int sigSz = wc_MakeSigWithBitStr(sig, sizeof(sig), CTC_SHA256wRSA,
data, sizeof(data), RSA_TYPE,
&key, &rng);
\endcode
\sa wc_SignCert_ex
\sa wc_GeneratePreTBS
*/
int wc_MakeSigWithBitStr(byte *sig, int sigSz, int sType, byte* buf,
word32 bufSz, int keyType, void* key,
WC_RNG* rng);
/*!
\ingroup ASN
\brief Gets certificate validity dates.
\return 0 on success
\return BAD_FUNC_ARG if parameters invalid
\param cert Certificate structure
\param before Output for notBefore date
\param after Output for notAfter date
_Example_
\code
Cert myCert;
struct tm beforeDate, afterDate;
int ret = wc_GetCertDates(&myCert, &beforeDate, &afterDate);
\endcode
\sa wc_InitCert
*/
int wc_GetCertDates(Cert* cert, struct tm* before, struct tm* after);
/*!
\ingroup ASN
\brief Extracts date information from certificate date field. This
function parses an ASN.1 encoded date (including tag and length) and
returns a pointer to the raw date value bytes, the ASN.1 time type,
and the length of the date value.
\return 0 on success
\return BAD_FUNC_ARG if parameters invalid
\return ASN_PARSE_E if date parsing fails
\param certDate Certificate date buffer containing ASN.1 encoded date
(tag + length + value)
\param certDateSz Size of certificate date buffer
\param date Output pointer set to the raw date value bytes (without
tag/length)
\param format Output byte indicating ASN.1 time type: ASN_UTC_TIME
(0x17) or ASN_GENERALIZED_TIME (0x18)
\param length Output length of the raw date value in bytes
_Example_
\code
const byte* certDate;
const byte* date;
byte format;
int length;
int ret = wc_GetDateInfo(certDate, certDateSz, &date,
&format, &length);
if (ret == 0) {
// date points to raw time bytes, format indicates UTC or
// Generalized time, length is the number of date value bytes
}
\endcode
\sa wc_GetCertDates
\sa wc_GetDateAsCalendarTime
*/
int wc_GetDateInfo(const byte* certDate, int certDateSz,
const byte** date, byte* format, int* length);
/*!
\ingroup ASN
\brief Converts certificate date to calendar time structure.
\return 0 on success
\return BAD_FUNC_ARG if parameters invalid
\return ASN_TIME_E if time conversion fails
\param date Date buffer
\param length Length of date buffer
\param format Date format (ASN_UTC_TIME or ASN_GENERALIZED_TIME)
\param timearg Pointer to tm structure to fill
_Example_
\code
const byte* date;
int length;
byte format;
struct tm timeInfo;
int ret = wc_GetDateAsCalendarTime(date, length, format,
&timeInfo);
\endcode
\sa wc_GetDateInfo
\sa wc_GetCertDates
*/
int wc_GetDateAsCalendarTime(const byte* date, int length,
byte format, struct tm* timearg);
/*!
\ingroup ASN
\brief This function makes a certificate signing request using the input
certificate and writes the output to derBuffer. It takes in either an
rsaKey or an eccKey to generate the certificate request. wc_SignCert()
will need to be called after this function to sign the certificate request.
Please see the wolfCrypt test application (./wolfcrypt/test/test.c) for an
example usage of this function.
\return Success On successfully making an X.509 certificate request from
the specified input cert, returns the size of the certificate
request generated.
\return MEMORY_E Returned if there is an error allocating memory
with XMALLOC
\return BUFFER_E Returned if the provided derBuffer is too small to store
the generated certificate
\return Other Additional error messages may be returned if the certificate
request generation is not successful.
\param cert pointer to an initialized cert structure
\param derBuffer pointer to the buffer in which to hold the generated
certificate request
\param derSz size of the buffer in which to store the certificate request
\param rsaKey pointer to an RsaKey structure containing the rsa key used
to generate the certificate request
\param eccKey pointer to an EccKey structure containing the ecc key used
to generate the certificate request
_Example_
\code
Cert myCert;
// initialize myCert
EccKey key;
//initialize key;
byte* derCert = (byte*)malloc(FOURK_BUF);
word32 certSz;
certSz = wc_MakeCertReq(&myCert, derCert, FOURK_BUF, NULL, &key);
\endcode
\sa wc_InitCert
\sa wc_MakeCert
*/
int wc_MakeCertReq(Cert* cert, byte* derBuffer, word32 derSz,
RsaKey* rsaKey, ecc_key* eccKey);
/*!
\ingroup ASN
\brief This function signs buffer and adds the signature to the end of
buffer. It takes in a signature type. Must be called after wc_MakeCert()
or wc_MakeCertReq() if creating a CA signed cert.
\return Success On successfully signing the certificate, returns the new
size of the cert (including signature).
\return MEMORY_E Returned if there is an error allocating
memory with XMALLOC
\return BUFFER_E Returned if the provided buffer is too small to store
the generated certificate
\return Other Additional error messages may be returned if the cert
generation is not successful.
\param requestSz the size of the certificate body we’re requesting
to have signed
\param sType Type of signature to create. Valid options are: CTC_MD5wRSA,
CTC_SHAwRSA, CTC_SHAwECDSA, CTC_SHA256wECDSA, and CTC_SHA256wRSA
\param buffer pointer to the buffer containing the certificate to be
signed. On success: will hold the newly signed certificate
\param buffSz the (total) size of the buffer in which to store the newly
signed certificate
\param rsaKey pointer to an RsaKey structure containing the rsa key
to used to sign the certificate
\param eccKey pointer to an EccKey structure containing the ecc key
to used to sign the certificate
\param rng pointer to the random number generator used to sign
the certificate
_Example_
\code
Cert myCert;
byte* derCert = (byte*)malloc(FOURK_BUF);
// initialize myCert, derCert
RsaKey key;
// initialize key;
WC_RNG rng;
// initialize rng
word32 certSz;
certSz = wc_SignCert(myCert.bodySz, myCert.sigType,derCert,FOURK_BUF,
&key, NULL,
&rng);
\endcode
\sa wc_InitCert
\sa wc_MakeCert
*/
int wc_SignCert(int requestSz, int sigType, byte* derBuffer,
word32 derSz, RsaKey* rsaKey, ecc_key* eccKey, WC_RNG* rng);
/*!
\ingroup ASN
\brief This function is a combination of the previous two functions,
wc_MakeCert and wc_SignCert for self signing (the previous functions may
be used for CA requests). It makes a certificate, and then signs it,
generating a self-signed certificate.
\return Success On successfully signing the certificate, returns the
new size of the cert.
\return MEMORY_E Returned if there is an error allocating memory
with XMALLOC
\return BUFFER_E Returned if the provided buffer is too small to store
the generated certificate
\return Other Additional error messages may be returned if the cert
generation is not successful.
\param cert pointer to the cert to make and sign
\param buffer pointer to the buffer in which to hold the signed certificate
\param buffSz size of the buffer in which to store the signed certificate
\param key pointer to an RsaKey structure containing the rsa key to
used to sign the certificate
\param rng pointer to the random number generator used to generate
and sign the certificate
_Example_
\code
Cert myCert;
byte* derCert = (byte*)malloc(FOURK_BUF);
// initialize myCert, derCert
RsaKey key;
// initialize key;
WC_RNG rng;
// initialize rng
word32 certSz;
certSz = wc_MakeSelfCert(&myCert, derCert, FOURK_BUF, &key, NULL, &rng);
\endcode
\sa wc_InitCert
\sa wc_MakeCert
\sa wc_SignCert
*/
int wc_MakeSelfCert(Cert* cert, byte* derBuffer, word32 derSz, RsaKey* key,
WC_RNG* rng);
/*!
\ingroup ASN
\brief This function sets the issuer for a certificate to the issuer
in the provided pem issuerFile. It also changes the certificate’s
self-signed attribute to false. The issuer specified in issuerFile is
verified prior to setting the cert issuer. This method is used to set
fields prior to signing.
\return 0 Returned on successfully setting the issuer for the certificate
\return MEMORY_E Returned if there is an error allocating memory
with XMALLOC
\return ASN_PARSE_E Returned if there is an error parsing the
cert header file
\return ASN_OBJECT_ID_E Returned if there is an error parsing the
encryption type from the cert
\return ASN_EXPECT_0_E Returned if there is a formatting error in
the encryption specification of the cert file
\return ASN_BEFORE_DATE_E Returned if the date is before the certificate
start date
\return ASN_AFTER_DATE_E Returned if the date is after the certificate
expiration date
\return ASN_BITSTR_E Returned if there is an error parsing a bit string
from the certificate
\return ECC_CURVE_OID_E Returned if there is an error parsing the ECC key
from the certificate
\return ASN_UNKNOWN_OID_E Returned if the certificate is using an unknown
key object id
\return ASN_VERSION_E Returned if the ALLOW_V1_EXTENSIONS option is not
defined and the certificate is a V1 or V2 certificate
\return BAD_FUNC_ARG Returned if there is an error processing the
certificate extension
\return ASN_CRIT_EXT_E Returned if an unfamiliar critical extension is
encountered in processing the certificate
\return ASN_SIG_OID_E Returned if the signature encryption type is not
the same as the encryption type of the certificate in the provided file
\return ASN_SIG_CONFIRM_E Returned if confirming the certification
signature fails
\return ASN_NAME_INVALID_E Returned if the certificate’s name is not
permitted by the CA name constraints
\return ASN_NO_SIGNER_E Returned if there is no CA signer to verify
the certificate’s authenticity
\param cert pointer to the cert for which to set the issuer
\param issuerFile path of the file containing the pem formatted certificate
_Example_
\code
Cert myCert;
// initialize myCert
if(wc_SetIssuer(&myCert, ”./path/to/ca-cert.pem”) != 0) {
// error setting issuer
}
\endcode
\sa wc_InitCert
\sa wc_SetSubject
\sa wc_SetIssuerBuffer
*/
int wc_SetIssuer(Cert* cert, const char* issuerFile);
/*!
\ingroup ASN
\brief This function sets the subject for a certificate to the subject
in the provided pem subjectFile. This method is used to set fields prior
to signing.
\return 0 Returned on successfully setting the issuer for the certificate
\return MEMORY_E Returned if there is an error allocating memory with XMALLOC
\return ASN_PARSE_E Returned if there is an error parsing the cert
header file
\return ASN_OBJECT_ID_E Returned if there is an error parsing the
encryption type from the cert
\return ASN_EXPECT_0_E Returned if there is a formatting error in the
encryption specification of the cert file
\return ASN_BEFORE_DATE_E Returned if the date is before the certificate
start date
\return ASN_AFTER_DATE_E Returned if the date is after the certificate
expiration date
\return ASN_BITSTR_E Returned if there is an error parsing a bit string
from the certificate
\return ECC_CURVE_OID_E Returned if there is an error parsing the ECC key
from the certificate
\return ASN_UNKNOWN_OID_E Returned if the certificate is using an unknown
key object id
\return ASN_VERSION_E Returned if the ALLOW_V1_EXTENSIONS option is not
defined and the certificate is a V1 or V2 certificate
\return BAD_FUNC_ARG Returned if there is an error processing the
certificate extension
\return ASN_CRIT_EXT_E Returned if an unfamiliar critical extension is
encountered in processing the certificate
\return ASN_SIG_OID_E Returned if the signature encryption type is not
the same as the encryption type of the certificate in the provided file
\return ASN_SIG_CONFIRM_E Returned if confirming the certification
signature fails
\return ASN_NAME_INVALID_E Returned if the certificate’s name is not
permitted by the CA name constraints
\return ASN_NO_SIGNER_E Returned if there is no CA signer to verify the
certificate’s authenticity
\param cert pointer to the cert for which to set the issuer
\param subjectFile path of the file containing the pem formatted certificate
_Example_
\code
Cert myCert;
// initialize myCert
if(wc_SetSubject(&myCert, ”./path/to/ca-cert.pem”) != 0) {
// error setting subject
}
\endcode
\sa wc_InitCert
\sa wc_SetIssuer
*/
int wc_SetSubject(Cert* cert, const char* subjectFile);
/*!
\ingroup ASN
\brief This function sets the raw subject for a certificate from the
subject in the provided der buffer. This method is used to set the raw
subject field prior to signing.
\return 0 Returned on successfully setting the subject for the certificate
\return MEMORY_E Returned if there is an error allocating memory
with XMALLOC
\return ASN_PARSE_E Returned if there is an error parsing the cert
header file
\return ASN_OBJECT_ID_E Returned if there is an error parsing the
encryption type from the cert
\return ASN_EXPECT_0_E Returned if there is a formatting error in the
encryption specification of the cert file
\return ASN_BEFORE_DATE_E Returned if the date is before the certificate
start date
\return ASN_AFTER_DATE_E Returned if the date is after the certificate
expiration date
\return ASN_BITSTR_E Returned if there is an error parsing a bit string
from the certificate
\return ECC_CURVE_OID_E Returned if there is an error parsing the ECC key
from the certificate
\return ASN_UNKNOWN_OID_E Returned if the certificate is using an unknown
key object id
\return ASN_VERSION_E Returned if the ALLOW_V1_EXTENSIONS option is not
defined and the certificate is a V1 or V2 certificate
\return BAD_FUNC_ARG Returned if there is an error processing the
certificate extension
\return ASN_CRIT_EXT_E Returned if an unfamiliar critical extension is
encountered in processing the certificate
\return ASN_SIG_OID_E Returned if the signature encryption type is not
the same as the encryption type of the certificate in the provided file
\return ASN_SIG_CONFIRM_E Returned if confirming the certification
signature fails
\return ASN_NAME_INVALID_E Returned if the certificate’s name is not
permitted by the CA name constraints
\return ASN_NO_SIGNER_E Returned if there is no CA signer to verify the
certificate’s authenticity
\param cert pointer to the cert for which to set the raw subject
\param der pointer to the buffer containing the der formatted certificate
from which to grab the subject
\param derSz size of the buffer containing the der formatted certificate
from which to grab the subject
_Example_
\code
Cert myCert;
// initialize myCert
byte* der;
der = (byte*)malloc(FOURK_BUF);
// initialize der
if(wc_SetSubjectRaw(&myCert, der, FOURK_BUF) != 0) {
// error setting subject
}
\endcode
\sa wc_InitCert
\sa wc_SetSubject
*/
int wc_SetSubjectRaw(Cert* cert, const byte* der, int derSz);
/*!
\ingroup ASN
\brief This function gets the raw subject from the certificate structure.
\return 0 Returned on successfully getting the subject from the certificate
\return BAD_FUNC_ARG Returned if there is an error processing the
certificate extension
\param subjectRaw pointer-pointer to the raw subject upon successful return
\param cert pointer to the cert from which to get the raw subject
_Example_
\code
Cert myCert;
byte *subjRaw;
// initialize myCert
if(wc_GetSubjectRaw(&subjRaw, &myCert) != 0) {
// error setting subject
}
\endcode
\sa wc_InitCert
\sa wc_SetSubjectRaw
*/
int wc_GetSubjectRaw(byte **subjectRaw, Cert *cert);
/*!
\ingroup ASN
\brief This function sets the alternate names for a certificate to the
alternate names in the provided pem file. This is useful in the case that
one wishes to secure multiple domains with the same certificate. This
method is used to set fields prior to signing.
\return 0 Returned on successfully setting the alt names for the certificate
\return MEMORY_E Returned if there is an error allocating memory
with XMALLOC
\return ASN_PARSE_E Returned if there is an error parsing the cert
header file
\return ASN_OBJECT_ID_E Returned if there is an error parsing the
encryption type from the cert
\return ASN_EXPECT_0_E Returned if there is a formatting error in the
encryption specification of the cert file
\return ASN_BEFORE_DATE_E Returned if the date is before the certificate
start date
\return ASN_AFTER_DATE_E Returned if the date is after the certificate
expiration date
\return ASN_BITSTR_E Returned if there is an error parsing a bit string
from the certificate
\return ECC_CURVE_OID_E Returned if there is an error parsing the ECC key
from the certificate
\return ASN_UNKNOWN_OID_E Returned if the certificate is using an unknown
key object id
\return ASN_VERSION_E Returned if the ALLOW_V1_EXTENSIONS option is not
defined and the certificate is a V1 or V2 certificate
\return BAD_FUNC_ARG Returned if there is an error processing the
certificate extension
\return ASN_CRIT_EXT_E Returned if an unfamiliar critical extension is
encountered in processing the certificate
\return ASN_SIG_OID_E Returned if the signature encryption type is not
the same as the encryption type of the certificate in the provided file
\return ASN_SIG_CONFIRM_E Returned if confirming the certification
signature fails
\return ASN_NAME_INVALID_E Returned if the certificate’s name is not
permitted by the CA name constraints
\return ASN_NO_SIGNER_E Returned if there is no CA signer to verify the
certificate’s authenticity
\param cert pointer to the cert for which to set the alt names
\param file path of the file containing the pem formatted certificate
_Example_
\code
Cert myCert;
// initialize myCert
if(wc_SetSubject(&myCert, ”./path/to/ca-cert.pem”) != 0) {
// error setting alt names
}
\endcode
\sa wc_InitCert
\sa wc_SetIssuer
*/
int wc_SetAltNames(Cert* cert, const char* file);
/*!
\ingroup ASN
\brief This function sets the issuer for a certificate from the issuer in
the provided der buffer. It also changes the certificate’s self-signed
attribute to false. This method is used to set fields prior to signing.
\return 0 Returned on successfully setting the issuer for the certificate
\return MEMORY_E Returned if there is an error allocating memory
with XMALLOC
\return ASN_PARSE_E Returned if there is an error parsing the cert
header file
\return ASN_OBJECT_ID_E Returned if there is an error parsing the
encryption type from the cert
\return ASN_EXPECT_0_E Returned if there is a formatting error in the
encryption specification of the cert file
\return ASN_BEFORE_DATE_E Returned if the date is before the certificate
start date
\return ASN_AFTER_DATE_E Returned if the date is after the certificate
expiration date
\return ASN_BITSTR_E Returned if there is an error parsing a bit string
from the certificate
\return ECC_CURVE_OID_E Returned if there is an error parsing the ECC
key from the certificate
\return ASN_UNKNOWN_OID_E Returned if the certificate is using an unknown
key object id
\return ASN_VERSION_E Returned if the ALLOW_V1_EXTENSIONS option is not
defined and the certificate is a V1 or V2 certificate
\return BAD_FUNC_ARG Returned if there is an error processing the
certificate extension
\return ASN_CRIT_EXT_E Returned if an unfamiliar critical extension is
encountered in processing the certificate
\return ASN_SIG_OID_E Returned if the signature encryption type is not
the same as the encryption type of the certificate in the provided file
\return ASN_SIG_CONFIRM_E Returned if confirming the certification
signature fails
\return ASN_NAME_INVALID_E Returned if the certificate’s name is not
permitted by the CA name constraints
\return ASN_NO_SIGNER_E Returned if there is no CA signer to verify
the certificate’s authenticity
\param cert pointer to the cert for which to set the issuer
\param der pointer to the buffer containing the der formatted certificate
from which to grab the issuer
\param derSz size of the buffer containing the der formatted certificate
from which to grab the issuer
_Example_
\code
Cert myCert;
// initialize myCert
byte* der;
der = (byte*)malloc(FOURK_BUF);
// initialize der
if(wc_SetIssuerBuffer(&myCert, der, FOURK_BUF) != 0) {
// error setting issuer
}
\endcode
\sa wc_InitCert
\sa wc_SetIssuer
*/
int wc_SetIssuerBuffer(Cert* cert, const byte* der, int derSz);
/*!
\ingroup ASN
\brief This function sets the raw issuer for a certificate from the
issuer in the provided der buffer. This method is used to set the raw
issuer field prior to signing.
\return 0 Returned on successfully setting the issuer for the certificate
\return MEMORY_E Returned if there is an error allocating memory
with XMALLOC
\return ASN_PARSE_E Returned if there is an error parsing the cert
header file
\return ASN_OBJECT_ID_E Returned if there is an error parsing the
encryption type from the cert
\return ASN_EXPECT_0_E Returned if there is a formatting error in the
encryption specification of the cert file
\return ASN_BEFORE_DATE_E Returned if the date is before the certificate
start date
\return ASN_AFTER_DATE_E Returned if the date is after the certificate
expiration date
\return ASN_BITSTR_E Returned if there is an error parsing a bit string
from the certificate
\return ECC_CURVE_OID_E Returned if there is an error parsing the ECC key
from the certificate
\return ASN_UNKNOWN_OID_E Returned if the certificate is using an unknown
key object id
\return ASN_VERSION_E Returned if the ALLOW_V1_EXTENSIONS option is not
defined and the certificate is a V1 or V2 certificate
\return BAD_FUNC_ARG Returned if there is an error processing the
certificate extension
\return ASN_CRIT_EXT_E Returned if an unfamiliar critical extension is
encountered in processing the certificate
\return ASN_SIG_OID_E Returned if the signature encryption type is not
the same as the encryption type of the certificate in the provided file
\return ASN_SIG_CONFIRM_E Returned if confirming the certification
signature fails
\return ASN_NAME_INVALID_E Returned if the certificate’s name is not
permitted by the CA name constraints
\return ASN_NO_SIGNER_E Returned if there is no CA signer to verify the
certificate’s authenticity
\param cert pointer to the cert for which to set the raw issuer
\param der pointer to the buffer containing the der formatted certificate
from which to grab the subject
\param derSz size of the buffer containing the der formatted certificate
from which to grab the subject
_Example_
\code
Cert myCert;
// initialize myCert
byte* der;
der = (byte*)malloc(FOURK_BUF);
// initialize der
if(wc_SetIssuerRaw(&myCert, der, FOURK_BUF) != 0) {
// error setting subject
}
\endcode
\sa wc_InitCert
\sa wc_SetIssuer
*/
int wc_SetIssuerRaw(Cert* cert, const byte* der, int derSz);
/*!
\ingroup ASN
\brief This function sets the subject for a certificate from the subject in
the provided der buffer. This method is used to set fields prior to signing.
\return 0 Returned on successfully setting the subject for the certificate
\return MEMORY_E Returned if there is an error allocating memory
with XMALLOC
\return ASN_PARSE_E Returned if there is an error parsing the cert
header file
\return ASN_OBJECT_ID_E Returned if there is an error parsing the
encryption type from the cert
\return ASN_EXPECT_0_E Returned if there is a formatting error in the
encryption specification of the cert file
\return ASN_BEFORE_DATE_E Returned if the date is before the certificate
start date
\return ASN_AFTER_DATE_E Returned if the date is after the certificate
expiration date
\return ASN_BITSTR_E Returned if there is an error parsing a bit string
from the certificate
\return ECC_CURVE_OID_E Returned if there is an error parsing the ECC key
from the certificate
\return ASN_UNKNOWN_OID_E Returned if the certificate is using an unknown
key object id
\return ASN_VERSION_E Returned if the ALLOW_V1_EXTENSIONS option is not
defined and the certificate is a V1 or V2 certificate
\return BAD_FUNC_ARG Returned if there is an error processing the
certificate extension
\return ASN_CRIT_EXT_E Returned if an unfamiliar critical extension is
encountered in processing the certificate
\return ASN_SIG_OID_E Returned if the signature encryption type is not
the same as the encryption type of the certificate in the provided file
\return ASN_SIG_CONFIRM_E Returned if confirming the certification
signature fails
\return ASN_NAME_INVALID_E Returned if the certificate’s name is not
permitted by the CA name constraints
\return ASN_NO_SIGNER_E Returned if there is no CA signer to verify the
certificate’s authenticity
\param cert pointer to the cert for which to set the subject
\param der pointer to the buffer containing the der formatted certificate
from which to grab the subject
\param derSz size of the buffer containing the der formatted certificate
from which to grab the subject
_Example_
\code
Cert myCert;
// initialize myCert
byte* der;
der = (byte*)malloc(FOURK_BUF);
// initialize der
if(wc_SetSubjectBuffer(&myCert, der, FOURK_BUF) != 0) {
// error setting subject
}
\endcode
\sa wc_InitCert
\sa wc_SetSubject