1 | /* asn_public.h
|
---|
2 | *
|
---|
3 | * Copyright (C) 2006-2020 wolfSSL Inc.
|
---|
4 | *
|
---|
5 | * This file is part of wolfSSL.
|
---|
6 | *
|
---|
7 | * wolfSSL is free software; you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation; either version 2 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * wolfSSL is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with this program; if not, write to the Free Software
|
---|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*!
|
---|
23 | \file wolfssl/wolfcrypt/asn_public.h
|
---|
24 | */
|
---|
25 |
|
---|
26 | /*
|
---|
27 | DESCRIPTION
|
---|
28 | This library defines the interface APIs for X509 certificates.
|
---|
29 |
|
---|
30 | */
|
---|
31 | #ifndef WOLF_CRYPT_ASN_PUBLIC_H
|
---|
32 | #define WOLF_CRYPT_ASN_PUBLIC_H
|
---|
33 |
|
---|
34 | #include <wolfssl/wolfcrypt/types.h>
|
---|
35 |
|
---|
36 | #ifdef __cplusplus
|
---|
37 | extern "C" {
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | /* guard on redeclaration */
|
---|
41 | #ifndef WC_ECCKEY_TYPE_DEFINED
|
---|
42 | typedef struct ecc_key ecc_key;
|
---|
43 | #define WC_ECCKEY_TYPE_DEFINED
|
---|
44 | #endif
|
---|
45 | #ifndef WC_ED25519KEY_TYPE_DEFINED
|
---|
46 | typedef struct ed25519_key ed25519_key;
|
---|
47 | #define WC_ED25519KEY_TYPE_DEFINED
|
---|
48 | #endif
|
---|
49 | #ifndef WC_ED448KEY_TYPE_DEFINED
|
---|
50 | typedef struct ed448_key ed448_key;
|
---|
51 | #define WC_ED448KEY_TYPE_DEFINED
|
---|
52 | #endif
|
---|
53 | #ifndef WC_RSAKEY_TYPE_DEFINED
|
---|
54 | typedef struct RsaKey RsaKey;
|
---|
55 | #define WC_RSAKEY_TYPE_DEFINED
|
---|
56 | #endif
|
---|
57 | #ifndef WC_RNG_TYPE_DEFINED
|
---|
58 | typedef struct WC_RNG WC_RNG;
|
---|
59 | #define WC_RNG_TYPE_DEFINED
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | enum Ecc_Sum {
|
---|
63 | ECC_SECP112R1_OID = 182,
|
---|
64 | ECC_SECP112R2_OID = 183,
|
---|
65 | ECC_SECP128R1_OID = 204,
|
---|
66 | ECC_SECP128R2_OID = 205,
|
---|
67 | ECC_SECP160R1_OID = 184,
|
---|
68 | ECC_SECP160R2_OID = 206,
|
---|
69 | ECC_SECP160K1_OID = 185,
|
---|
70 | ECC_BRAINPOOLP160R1_OID = 98,
|
---|
71 | ECC_SECP192R1_OID = 520,
|
---|
72 | ECC_PRIME192V2_OID = 521,
|
---|
73 | ECC_PRIME192V3_OID = 522,
|
---|
74 | ECC_SECP192K1_OID = 207,
|
---|
75 | ECC_BRAINPOOLP192R1_OID = 100,
|
---|
76 | ECC_SECP224R1_OID = 209,
|
---|
77 | ECC_SECP224K1_OID = 208,
|
---|
78 | ECC_BRAINPOOLP224R1_OID = 102,
|
---|
79 | ECC_PRIME239V1_OID = 523,
|
---|
80 | ECC_PRIME239V2_OID = 524,
|
---|
81 | ECC_PRIME239V3_OID = 525,
|
---|
82 | ECC_SECP256R1_OID = 526,
|
---|
83 | ECC_SECP256K1_OID = 186,
|
---|
84 | ECC_BRAINPOOLP256R1_OID = 104,
|
---|
85 | ECC_X25519_OID = 365,
|
---|
86 | ECC_ED25519_OID = 256,
|
---|
87 | ECC_BRAINPOOLP320R1_OID = 106,
|
---|
88 | ECC_X448_OID = 362,
|
---|
89 | ECC_ED448_OID = 257,
|
---|
90 | ECC_SECP384R1_OID = 210,
|
---|
91 | ECC_BRAINPOOLP384R1_OID = 108,
|
---|
92 | ECC_BRAINPOOLP512R1_OID = 110,
|
---|
93 | ECC_SECP521R1_OID = 211,
|
---|
94 | };
|
---|
95 |
|
---|
96 |
|
---|
97 | /* Certificate file Type */
|
---|
98 | enum CertType {
|
---|
99 | CERT_TYPE = 0,
|
---|
100 | PRIVATEKEY_TYPE,
|
---|
101 | DH_PARAM_TYPE,
|
---|
102 | DSA_PARAM_TYPE,
|
---|
103 | CRL_TYPE,
|
---|
104 | CA_TYPE,
|
---|
105 | ECC_PRIVATEKEY_TYPE,
|
---|
106 | DSA_PRIVATEKEY_TYPE,
|
---|
107 | CERTREQ_TYPE,
|
---|
108 | DSA_TYPE,
|
---|
109 | ECC_TYPE,
|
---|
110 | RSA_TYPE,
|
---|
111 | PUBLICKEY_TYPE,
|
---|
112 | RSA_PUBLICKEY_TYPE,
|
---|
113 | ECC_PUBLICKEY_TYPE,
|
---|
114 | TRUSTED_PEER_TYPE,
|
---|
115 | EDDSA_PRIVATEKEY_TYPE,
|
---|
116 | ED25519_TYPE,
|
---|
117 | ED448_TYPE,
|
---|
118 | PKCS12_TYPE,
|
---|
119 | PKCS8_PRIVATEKEY_TYPE,
|
---|
120 | PKCS8_ENC_PRIVATEKEY_TYPE,
|
---|
121 | DETECT_CERT_TYPE,
|
---|
122 | DH_PRIVATEKEY_TYPE,
|
---|
123 | };
|
---|
124 |
|
---|
125 |
|
---|
126 | /* Signature type, by OID sum */
|
---|
127 | enum Ctc_SigType {
|
---|
128 | CTC_SHAwDSA = 517,
|
---|
129 | CTC_SHA256wDSA = 416,
|
---|
130 | CTC_MD2wRSA = 646,
|
---|
131 | CTC_MD5wRSA = 648,
|
---|
132 | CTC_SHAwRSA = 649,
|
---|
133 | CTC_SHAwECDSA = 520,
|
---|
134 | CTC_SHA224wRSA = 658,
|
---|
135 | CTC_SHA224wECDSA = 523,
|
---|
136 | CTC_SHA256wRSA = 655,
|
---|
137 | CTC_SHA256wECDSA = 524,
|
---|
138 | CTC_SHA384wRSA = 656,
|
---|
139 | CTC_SHA384wECDSA = 525,
|
---|
140 | CTC_SHA512wRSA = 657,
|
---|
141 | CTC_SHA512wECDSA = 526,
|
---|
142 | CTC_ED25519 = 256,
|
---|
143 | CTC_ED448 = 257
|
---|
144 | };
|
---|
145 |
|
---|
146 | enum Ctc_Encoding {
|
---|
147 | CTC_UTF8 = 0x0c, /* utf8 */
|
---|
148 | CTC_PRINTABLE = 0x13 /* printable */
|
---|
149 | };
|
---|
150 |
|
---|
151 | #ifndef WC_CTC_NAME_SIZE
|
---|
152 | #define WC_CTC_NAME_SIZE 64
|
---|
153 | #endif
|
---|
154 | #ifndef WC_CTC_MAX_ALT_SIZE
|
---|
155 | #define WC_CTC_MAX_ALT_SIZE 16384
|
---|
156 | #endif
|
---|
157 |
|
---|
158 | enum Ctc_Misc {
|
---|
159 | CTC_COUNTRY_SIZE = 2,
|
---|
160 | CTC_NAME_SIZE = WC_CTC_NAME_SIZE,
|
---|
161 | CTC_DATE_SIZE = 32,
|
---|
162 | CTC_MAX_ALT_SIZE = WC_CTC_MAX_ALT_SIZE, /* may be huge, default: 16384 */
|
---|
163 | CTC_SERIAL_SIZE = 20,
|
---|
164 | CTC_GEN_SERIAL_SZ = 16,
|
---|
165 | #ifdef WOLFSSL_CERT_EXT
|
---|
166 | /* AKID could contains: hash + (Option) AuthCertIssuer,AuthCertSerialNum
|
---|
167 | * We support only hash */
|
---|
168 | CTC_MAX_SKID_SIZE = 32, /* SHA256_DIGEST_SIZE */
|
---|
169 | CTC_MAX_AKID_SIZE = 32, /* SHA256_DIGEST_SIZE */
|
---|
170 | CTC_MAX_CERTPOL_SZ = 64,
|
---|
171 | CTC_MAX_CERTPOL_NB = 2 /* Max number of Certificate Policy */
|
---|
172 | #endif /* WOLFSSL_CERT_EXT */
|
---|
173 | };
|
---|
174 |
|
---|
175 | /* DER buffer */
|
---|
176 | typedef struct DerBuffer {
|
---|
177 | byte* buffer;
|
---|
178 | void* heap;
|
---|
179 | word32 length;
|
---|
180 | int type; /* enum CertType */
|
---|
181 | int dynType; /* DYNAMIC_TYPE_* */
|
---|
182 | } DerBuffer;
|
---|
183 |
|
---|
184 | typedef struct WOLFSSL_ASN1_TIME {
|
---|
185 | unsigned char data[CTC_DATE_SIZE]; /* date bytes */
|
---|
186 | int length;
|
---|
187 | int type;
|
---|
188 | } WOLFSSL_ASN1_TIME;
|
---|
189 |
|
---|
190 | enum {
|
---|
191 | IV_SZ = 32, /* max iv sz */
|
---|
192 | NAME_SZ = 80, /* max one line */
|
---|
193 |
|
---|
194 | PEM_PASS_READ = 0,
|
---|
195 | PEM_PASS_WRITE = 1,
|
---|
196 | };
|
---|
197 |
|
---|
198 |
|
---|
199 | typedef int (pem_password_cb)(char* passwd, int sz, int rw, void* userdata);
|
---|
200 |
|
---|
201 | typedef struct EncryptedInfo {
|
---|
202 | pem_password_cb* passwd_cb;
|
---|
203 | void* passwd_userdata;
|
---|
204 |
|
---|
205 | long consumed; /* tracks PEM bytes consumed */
|
---|
206 |
|
---|
207 | int cipherType;
|
---|
208 | word32 keySz;
|
---|
209 | word32 ivSz; /* salt or encrypted IV size */
|
---|
210 |
|
---|
211 | char name[NAME_SZ]; /* cipher name, such as "DES-CBC" */
|
---|
212 | byte iv[IV_SZ]; /* salt or encrypted IV */
|
---|
213 |
|
---|
214 | word16 set:1; /* if encryption set */
|
---|
215 | } EncryptedInfo;
|
---|
216 |
|
---|
217 |
|
---|
218 | #define WOLFSSL_ASN1_INTEGER_MAX 20
|
---|
219 | typedef struct WOLFSSL_ASN1_INTEGER {
|
---|
220 | /* size can be increased set at 20 for tag, length then to hold at least 16
|
---|
221 | * byte type */
|
---|
222 | unsigned char intData[WOLFSSL_ASN1_INTEGER_MAX];
|
---|
223 | /* ASN_INTEGER | LENGTH | hex of number */
|
---|
224 | unsigned char negative; /* negative number flag */
|
---|
225 |
|
---|
226 | unsigned char* data;
|
---|
227 | unsigned int dataMax; /* max size of data buffer */
|
---|
228 | unsigned int isDynamic:1; /* flag for if data pointer dynamic (1 is yes 0 is no) */
|
---|
229 |
|
---|
230 | int length;
|
---|
231 | int type;
|
---|
232 | } WOLFSSL_ASN1_INTEGER;
|
---|
233 |
|
---|
234 |
|
---|
235 | #if defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_CERT_EXT)
|
---|
236 | #ifdef WOLFSSL_EKU_OID
|
---|
237 | #ifndef CTC_MAX_EKU_NB
|
---|
238 | #define CTC_MAX_EKU_NB 1
|
---|
239 | #endif
|
---|
240 | #ifndef CTC_MAX_EKU_OID_SZ
|
---|
241 | #define CTC_MAX_EKU_OID_SZ 30
|
---|
242 | #endif
|
---|
243 | #else
|
---|
244 | #undef CTC_MAX_EKU_OID_SZ
|
---|
245 | #define CTC_MAX_EKU_OID_SZ 0
|
---|
246 | #endif
|
---|
247 | #endif /* WOLFSSL_CERT_GEN || WOLFSSL_CERT_EXT */
|
---|
248 |
|
---|
249 | #ifdef WOLFSSL_CERT_GEN
|
---|
250 |
|
---|
251 | #ifdef WOLFSSL_MULTI_ATTRIB
|
---|
252 | #ifndef CTC_MAX_ATTRIB
|
---|
253 | #define CTC_MAX_ATTRIB 4
|
---|
254 | #endif
|
---|
255 |
|
---|
256 | /* ASN Encoded Name field */
|
---|
257 | typedef struct NameAttrib {
|
---|
258 | int sz; /* actual string value length */
|
---|
259 | int id; /* id of name */
|
---|
260 | int type; /* enc of name */
|
---|
261 | char value[CTC_NAME_SIZE]; /* name */
|
---|
262 | } NameAttrib;
|
---|
263 | #endif /* WOLFSSL_MULTI_ATTRIB */
|
---|
264 |
|
---|
265 |
|
---|
266 | typedef struct CertName {
|
---|
267 | char country[CTC_NAME_SIZE];
|
---|
268 | char countryEnc;
|
---|
269 | char state[CTC_NAME_SIZE];
|
---|
270 | char stateEnc;
|
---|
271 | char locality[CTC_NAME_SIZE];
|
---|
272 | char localityEnc;
|
---|
273 | char sur[CTC_NAME_SIZE];
|
---|
274 | char surEnc;
|
---|
275 | char org[CTC_NAME_SIZE];
|
---|
276 | char orgEnc;
|
---|
277 | char unit[CTC_NAME_SIZE];
|
---|
278 | char unitEnc;
|
---|
279 | char commonName[CTC_NAME_SIZE];
|
---|
280 | char commonNameEnc;
|
---|
281 | char serialDev[CTC_NAME_SIZE];
|
---|
282 | char serialDevEnc;
|
---|
283 | #ifdef WOLFSSL_CERT_EXT
|
---|
284 | char busCat[CTC_NAME_SIZE];
|
---|
285 | char busCatEnc;
|
---|
286 | char joiC[CTC_NAME_SIZE];
|
---|
287 | char joiCEnc;
|
---|
288 | char joiSt[CTC_NAME_SIZE];
|
---|
289 | char joiStEnc;
|
---|
290 | #endif
|
---|
291 | char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */
|
---|
292 | #ifdef WOLFSSL_MULTI_ATTRIB
|
---|
293 | NameAttrib name[CTC_MAX_ATTRIB];
|
---|
294 | #endif
|
---|
295 | } CertName;
|
---|
296 |
|
---|
297 |
|
---|
298 | /* for user to fill for certificate generation */
|
---|
299 | typedef struct Cert {
|
---|
300 | int version; /* x509 version */
|
---|
301 | byte serial[CTC_SERIAL_SIZE]; /* serial number */
|
---|
302 | int serialSz; /* serial size */
|
---|
303 | int sigType; /* signature algo type */
|
---|
304 | CertName issuer; /* issuer info */
|
---|
305 | int daysValid; /* validity days */
|
---|
306 | int selfSigned; /* self signed flag */
|
---|
307 | CertName subject; /* subject info */
|
---|
308 | int isCA; /* is this going to be a CA */
|
---|
309 | /* internal use only */
|
---|
310 | int bodySz; /* pre sign total size */
|
---|
311 | int keyType; /* public key type of subject */
|
---|
312 | #ifdef WOLFSSL_ALT_NAMES
|
---|
313 | byte altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */
|
---|
314 | int altNamesSz; /* altNames size in bytes */
|
---|
315 | byte beforeDate[CTC_DATE_SIZE]; /* before date copy */
|
---|
316 | int beforeDateSz; /* size of copy */
|
---|
317 | byte afterDate[CTC_DATE_SIZE]; /* after date copy */
|
---|
318 | int afterDateSz; /* size of copy */
|
---|
319 | #endif
|
---|
320 | #ifdef WOLFSSL_CERT_EXT
|
---|
321 | byte skid[CTC_MAX_SKID_SIZE]; /* Subject Key Identifier */
|
---|
322 | int skidSz; /* SKID size in bytes */
|
---|
323 | byte akid[CTC_MAX_AKID_SIZE]; /* Authority Key Identifier */
|
---|
324 | int akidSz; /* AKID size in bytes */
|
---|
325 | word16 keyUsage; /* Key Usage */
|
---|
326 | byte extKeyUsage; /* Extended Key Usage */
|
---|
327 | #ifdef WOLFSSL_EKU_OID
|
---|
328 | /* Extended Key Usage OIDs */
|
---|
329 | byte extKeyUsageOID[CTC_MAX_EKU_NB][CTC_MAX_EKU_OID_SZ];
|
---|
330 | byte extKeyUsageOIDSz[CTC_MAX_EKU_NB];
|
---|
331 | #endif
|
---|
332 | char certPolicies[CTC_MAX_CERTPOL_NB][CTC_MAX_CERTPOL_SZ];
|
---|
333 | word16 certPoliciesNb; /* Number of Cert Policy */
|
---|
334 | #endif
|
---|
335 | #if defined(WOLFSSL_CERT_EXT) || defined(OPENSSL_EXTRA) || \
|
---|
336 | defined(WOLFSSL_CERT_REQ)
|
---|
337 | byte issRaw[sizeof(CertName)]; /* raw issuer info */
|
---|
338 | byte sbjRaw[sizeof(CertName)]; /* raw subject info */
|
---|
339 | #endif
|
---|
340 | #ifdef WOLFSSL_CERT_REQ
|
---|
341 | char challengePw[CTC_NAME_SIZE];
|
---|
342 | int challengePwPrintableString; /* encode as PrintableString */
|
---|
343 | #endif
|
---|
344 | void* decodedCert; /* internal DecodedCert allocated from heap */
|
---|
345 | byte* der; /* Pointer to buffer of current DecodedCert cache */
|
---|
346 | void* heap; /* heap hint */
|
---|
347 | } Cert;
|
---|
348 |
|
---|
349 |
|
---|
350 | /* Initialize and Set Certificate defaults:
|
---|
351 | version = 3 (0x2)
|
---|
352 | serial = 0 (Will be randomly generated)
|
---|
353 | sigType = SHA_WITH_RSA
|
---|
354 | issuer = blank
|
---|
355 | daysValid = 500
|
---|
356 | selfSigned = 1 (true) use subject as issuer
|
---|
357 | subject = blank
|
---|
358 | isCA = 0 (false)
|
---|
359 | keyType = RSA_KEY (default)
|
---|
360 | */
|
---|
361 | WOLFSSL_API int wc_InitCert(Cert*);
|
---|
362 | WOLFSSL_API int wc_MakeCert_ex(Cert* cert, byte* derBuffer, word32 derSz,
|
---|
363 | int keyType, void* key, WC_RNG* rng);
|
---|
364 | WOLFSSL_API int wc_MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
|
---|
365 | ecc_key*, WC_RNG*);
|
---|
366 | #ifdef WOLFSSL_CERT_REQ
|
---|
367 | WOLFSSL_API int wc_MakeCertReq_ex(Cert*, byte* derBuffer, word32 derSz,
|
---|
368 | int, void*);
|
---|
369 | WOLFSSL_API int wc_MakeCertReq(Cert*, byte* derBuffer, word32 derSz,
|
---|
370 | RsaKey*, ecc_key*);
|
---|
371 | #endif
|
---|
372 | WOLFSSL_API int wc_SignCert_ex(int requestSz, int sType, byte* buffer,
|
---|
373 | word32 buffSz, int keyType, void* key,
|
---|
374 | WC_RNG* rng);
|
---|
375 | WOLFSSL_API int wc_SignCert(int requestSz, int sigType, byte* derBuffer,
|
---|
376 | word32 derSz, RsaKey*, ecc_key*, WC_RNG*);
|
---|
377 | WOLFSSL_API int wc_MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
|
---|
378 | WC_RNG*);
|
---|
379 | WOLFSSL_API int wc_SetIssuer(Cert*, const char*);
|
---|
380 | WOLFSSL_API int wc_SetSubject(Cert*, const char*);
|
---|
381 | #ifdef WOLFSSL_ALT_NAMES
|
---|
382 | WOLFSSL_API int wc_SetAltNames(Cert*, const char*);
|
---|
383 | #endif
|
---|
384 |
|
---|
385 | #ifdef WOLFSSL_CERT_GEN_CACHE
|
---|
386 | WOLFSSL_API void wc_SetCert_Free(Cert* cert);
|
---|
387 | #endif
|
---|
388 |
|
---|
389 | WOLFSSL_API int wc_SetIssuerBuffer(Cert*, const byte*, int);
|
---|
390 | WOLFSSL_API int wc_SetSubjectBuffer(Cert*, const byte*, int);
|
---|
391 | WOLFSSL_API int wc_SetAltNamesBuffer(Cert*, const byte*, int);
|
---|
392 | WOLFSSL_API int wc_SetDatesBuffer(Cert*, const byte*, int);
|
---|
393 |
|
---|
394 | #ifndef NO_ASN_TIME
|
---|
395 | WOLFSSL_API int wc_GetCertDates(Cert* cert, struct tm* before,
|
---|
396 | struct tm* after);
|
---|
397 | #endif
|
---|
398 |
|
---|
399 | #ifdef WOLFSSL_CERT_EXT
|
---|
400 | WOLFSSL_API int wc_SetAuthKeyIdFromPublicKey_ex(Cert *cert, int keyType,
|
---|
401 | void* key);
|
---|
402 | WOLFSSL_API int wc_SetAuthKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey,
|
---|
403 | ecc_key *eckey);
|
---|
404 | WOLFSSL_API int wc_SetAuthKeyIdFromCert(Cert *cert, const byte *der, int derSz);
|
---|
405 | WOLFSSL_API int wc_SetAuthKeyId(Cert *cert, const char* file);
|
---|
406 | WOLFSSL_API int wc_SetSubjectKeyIdFromPublicKey_ex(Cert *cert, int keyType,
|
---|
407 | void* key);
|
---|
408 | WOLFSSL_API int wc_SetSubjectKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey,
|
---|
409 | ecc_key *eckey);
|
---|
410 | WOLFSSL_API int wc_SetSubjectKeyId(Cert *cert, const char* file);
|
---|
411 | WOLFSSL_API int wc_GetSubjectRaw(byte **subjectRaw, Cert *cert);
|
---|
412 | WOLFSSL_API int wc_SetSubjectRaw(Cert* cert, const byte* der, int derSz);
|
---|
413 | WOLFSSL_API int wc_SetIssuerRaw(Cert* cert, const byte* der, int derSz);
|
---|
414 |
|
---|
415 | #ifdef HAVE_NTRU
|
---|
416 | WOLFSSL_API int wc_SetSubjectKeyIdFromNtruPublicKey(Cert *cert, byte *ntruKey,
|
---|
417 | word16 ntruKeySz);
|
---|
418 | #endif
|
---|
419 |
|
---|
420 | /* Set the KeyUsage.
|
---|
421 | * Value is a string separated tokens with ','. Accepted tokens are :
|
---|
422 | * digitalSignature,nonRepudiation,contentCommitment,keyCertSign,cRLSign,
|
---|
423 | * dataEncipherment,keyAgreement,keyEncipherment,encipherOnly and decipherOnly.
|
---|
424 | *
|
---|
425 | * nonRepudiation and contentCommitment are for the same usage.
|
---|
426 | */
|
---|
427 | WOLFSSL_API int wc_SetKeyUsage(Cert *cert, const char *value);
|
---|
428 |
|
---|
429 | /* Set ExtendedKeyUsage
|
---|
430 | * Value is a string separated tokens with ','. Accepted tokens are :
|
---|
431 | * any,serverAuth,clientAuth,codeSigning,emailProtection,timeStamping,OCSPSigning
|
---|
432 | */
|
---|
433 | WOLFSSL_API int wc_SetExtKeyUsage(Cert *cert, const char *value);
|
---|
434 |
|
---|
435 |
|
---|
436 | #ifdef WOLFSSL_EKU_OID
|
---|
437 | /* Set ExtendedKeyUsage with unique OID
|
---|
438 | * oid is expected to be in byte representation
|
---|
439 | */
|
---|
440 | WOLFSSL_API int wc_SetExtKeyUsageOID(Cert *cert, const char *oid, word32 sz,
|
---|
441 | byte idx, void* heap);
|
---|
442 | #endif /* WOLFSSL_EKU_OID */
|
---|
443 | #endif /* WOLFSSL_CERT_EXT */
|
---|
444 |
|
---|
445 | #ifdef HAVE_NTRU
|
---|
446 | WOLFSSL_API int wc_MakeNtruCert(Cert*, byte* derBuffer, word32 derSz,
|
---|
447 | const byte* ntruKey, word16 keySz,
|
---|
448 | WC_RNG*);
|
---|
449 | #endif
|
---|
450 |
|
---|
451 | #endif /* WOLFSSL_CERT_GEN */
|
---|
452 |
|
---|
453 | WOLFSSL_API int wc_GetDateInfo(const byte* certDate, int certDateSz,
|
---|
454 | const byte** date, byte* format, int* length);
|
---|
455 | #ifndef NO_ASN_TIME
|
---|
456 | WOLFSSL_API int wc_GetDateAsCalendarTime(const byte* date, int length,
|
---|
457 | byte format, struct tm* time);
|
---|
458 | #endif
|
---|
459 |
|
---|
460 | #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
|
---|
461 |
|
---|
462 | WOLFSSL_API int wc_PemGetHeaderFooter(int type, const char** header,
|
---|
463 | const char** footer);
|
---|
464 |
|
---|
465 | #endif
|
---|
466 |
|
---|
467 | WOLFSSL_API int wc_AllocDer(DerBuffer** pDer, word32 length, int type, void* heap);
|
---|
468 | WOLFSSL_API void wc_FreeDer(DerBuffer** pDer);
|
---|
469 |
|
---|
470 | #ifdef WOLFSSL_PEM_TO_DER
|
---|
471 | WOLFSSL_API int wc_PemToDer(const unsigned char* buff, long longSz, int type,
|
---|
472 | DerBuffer** pDer, void* heap, EncryptedInfo* info, int* eccKey);
|
---|
473 |
|
---|
474 | WOLFSSL_API int wc_KeyPemToDer(const unsigned char*, int,
|
---|
475 | unsigned char*, int, const char*);
|
---|
476 | WOLFSSL_API int wc_CertPemToDer(const unsigned char*, int,
|
---|
477 | unsigned char*, int, int);
|
---|
478 | #endif /* WOLFSSL_PEM_TO_DER */
|
---|
479 |
|
---|
480 | #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER)
|
---|
481 | #ifndef NO_FILESYSTEM
|
---|
482 | WOLFSSL_API int wc_PemPubKeyToDer(const char* fileName,
|
---|
483 | unsigned char* derBuf, int derSz);
|
---|
484 | #endif
|
---|
485 |
|
---|
486 | WOLFSSL_API int wc_PubKeyPemToDer(const unsigned char*, int,
|
---|
487 | unsigned char*, int);
|
---|
488 | #endif /* WOLFSSL_CERT_EXT || WOLFSSL_PUB_PEM_TO_DER */
|
---|
489 |
|
---|
490 | #ifdef WOLFSSL_CERT_GEN
|
---|
491 | #ifndef NO_FILESYSTEM
|
---|
492 | WOLFSSL_API int wc_PemCertToDer(const char* fileName,
|
---|
493 | unsigned char* derBuf, int derSz);
|
---|
494 | #endif
|
---|
495 | #endif /* WOLFSSL_CERT_GEN */
|
---|
496 |
|
---|
497 | #ifdef WOLFSSL_DER_TO_PEM
|
---|
498 | WOLFSSL_API int wc_DerToPem(const byte* der, word32 derSz, byte* output,
|
---|
499 | word32 outputSz, int type);
|
---|
500 | WOLFSSL_API int wc_DerToPemEx(const byte* der, word32 derSz, byte* output,
|
---|
501 | word32 outputSz, byte *cipherIno, int type);
|
---|
502 | #endif
|
---|
503 |
|
---|
504 | #ifndef NO_RSA
|
---|
505 | #if !defined(HAVE_USER_RSA)
|
---|
506 | WOLFSSL_API int wc_RsaPublicKeyDecode_ex(const byte* input, word32* inOutIdx,
|
---|
507 | word32 inSz, const byte** n, word32* nSz, const byte** e, word32* eSz);
|
---|
508 | #endif
|
---|
509 | WOLFSSL_API int wc_RsaPublicKeyDerSize(RsaKey* key, int with_header);
|
---|
510 | #endif
|
---|
511 |
|
---|
512 | #ifdef HAVE_ECC
|
---|
513 | /* private key helpers */
|
---|
514 | WOLFSSL_API int wc_EccPrivateKeyDecode(const byte*, word32*,
|
---|
515 | ecc_key*, word32);
|
---|
516 | WOLFSSL_API int wc_EccKeyToDer(ecc_key*, byte* output, word32 inLen);
|
---|
517 | WOLFSSL_API int wc_EccPrivateKeyToDer(ecc_key* key, byte* output,
|
---|
518 | word32 inLen);
|
---|
519 | WOLFSSL_API int wc_EccPrivateKeyToPKCS8(ecc_key* key, byte* output,
|
---|
520 | word32* outLen);
|
---|
521 | WOLFSSL_API int wc_EccKeyToPKCS8(ecc_key* key, byte* output,
|
---|
522 | word32* outLen);
|
---|
523 |
|
---|
524 | /* public key helper */
|
---|
525 | WOLFSSL_API int wc_EccPublicKeyDecode(const byte*, word32*,
|
---|
526 | ecc_key*, word32);
|
---|
527 | WOLFSSL_API int wc_EccPublicKeyToDer(ecc_key*, byte* output,
|
---|
528 | word32 inLen, int with_AlgCurve);
|
---|
529 | WOLFSSL_API int wc_EccPublicKeyDerSize(ecc_key*, int with_AlgCurve);
|
---|
530 | #endif
|
---|
531 |
|
---|
532 | #ifdef HAVE_ED25519
|
---|
533 | /* private key helpers */
|
---|
534 | WOLFSSL_API int wc_Ed25519PrivateKeyDecode(const byte*, word32*,
|
---|
535 | ed25519_key*, word32);
|
---|
536 | WOLFSSL_API int wc_Ed25519KeyToDer(ed25519_key* key, byte* output,
|
---|
537 | word32 inLen);
|
---|
538 | WOLFSSL_API int wc_Ed25519PrivateKeyToDer(ed25519_key* key, byte* output,
|
---|
539 | word32 inLen);
|
---|
540 |
|
---|
541 | /* public key helper */
|
---|
542 | WOLFSSL_API int wc_Ed25519PublicKeyDecode(const byte*, word32*,
|
---|
543 | ed25519_key*, word32);
|
---|
544 | #if (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
|
---|
545 | WOLFSSL_API int wc_Ed25519PublicKeyToDer(ed25519_key*, byte* output,
|
---|
546 | word32 inLen, int with_AlgCurve);
|
---|
547 | #endif
|
---|
548 | #endif
|
---|
549 |
|
---|
550 | #ifdef HAVE_ED448
|
---|
551 | /* private key helpers */
|
---|
552 | WOLFSSL_API int wc_Ed448PrivateKeyDecode(const byte*, word32*,
|
---|
553 | ed448_key*, word32);
|
---|
554 | WOLFSSL_API int wc_Ed448KeyToDer(ed448_key* key, byte* output,
|
---|
555 | word32 inLen);
|
---|
556 | WOLFSSL_API int wc_Ed448PrivateKeyToDer(ed448_key* key, byte* output,
|
---|
557 | word32 inLen);
|
---|
558 |
|
---|
559 | /* public key helper */
|
---|
560 | WOLFSSL_API int wc_Ed448PublicKeyDecode(const byte*, word32*,
|
---|
561 | ed448_key*, word32);
|
---|
562 | #if (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
|
---|
563 | WOLFSSL_API int wc_Ed448PublicKeyToDer(ed448_key*, byte* output,
|
---|
564 | word32 inLen, int with_AlgCurve);
|
---|
565 | #endif
|
---|
566 | #endif
|
---|
567 |
|
---|
568 | /* DER encode signature */
|
---|
569 | WOLFSSL_API word32 wc_EncodeSignature(byte* out, const byte* digest,
|
---|
570 | word32 digSz, int hashOID);
|
---|
571 | WOLFSSL_API int wc_GetCTC_HashOID(int type);
|
---|
572 |
|
---|
573 | WOLFSSL_API int wc_GetPkcs8TraditionalOffset(byte* input,
|
---|
574 | word32* inOutIdx, word32 sz);
|
---|
575 | WOLFSSL_API int wc_CreatePKCS8Key(byte* out, word32* outSz,
|
---|
576 | byte* key, word32 keySz, int algoID, const byte* curveOID, word32 oidSz);
|
---|
577 |
|
---|
578 | #ifndef NO_ASN_TIME
|
---|
579 | /* Time */
|
---|
580 | /* Returns seconds (Epoch/UTC)
|
---|
581 | * timePtr: is "time_t", which is typically "long"
|
---|
582 | * Example:
|
---|
583 | long lTime;
|
---|
584 | rc = wc_GetTime(&lTime, (word32)sizeof(lTime));
|
---|
585 | */
|
---|
586 | WOLFSSL_API int wc_GetTime(void* timePtr, word32 timeSize);
|
---|
587 | #endif
|
---|
588 |
|
---|
589 | #ifdef WOLFSSL_ENCRYPTED_KEYS
|
---|
590 | WOLFSSL_API int wc_EncryptedInfoGet(EncryptedInfo* info,
|
---|
591 | const char* cipherInfo);
|
---|
592 | #endif
|
---|
593 |
|
---|
594 |
|
---|
595 | #ifdef WOLFSSL_CERT_PIV
|
---|
596 |
|
---|
597 | typedef struct _wc_CertPIV {
|
---|
598 | const byte* cert;
|
---|
599 | word32 certSz;
|
---|
600 | const byte* certErrDet;
|
---|
601 | word32 certErrDetSz;
|
---|
602 | const byte* nonce; /* Identiv Only */
|
---|
603 | word32 nonceSz; /* Identiv Only */
|
---|
604 | const byte* signedNonce; /* Identiv Only */
|
---|
605 | word32 signedNonceSz; /* Identiv Only */
|
---|
606 |
|
---|
607 | /* flags */
|
---|
608 | word16 compression:2;
|
---|
609 | word16 isX509:1;
|
---|
610 | word16 isIdentiv:1;
|
---|
611 | } wc_CertPIV;
|
---|
612 |
|
---|
613 | WOLFSSL_API int wc_ParseCertPIV(wc_CertPIV* cert, const byte* buf, word32 totalSz);
|
---|
614 | #endif /* WOLFSSL_CERT_PIV */
|
---|
615 |
|
---|
616 |
|
---|
617 | #ifdef __cplusplus
|
---|
618 | } /* extern "C" */
|
---|
619 | #endif
|
---|
620 |
|
---|
621 | #endif /* WOLF_CRYPT_ASN_PUBLIC_H */
|
---|