SharkSSL™ Embedded SSL/TLS Stack
SharkSSL.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * SharkSSL Embedded SSL/TLS Stack
10 ****************************************************************************
11 * PROGRAM MODULE
12 *
13 * $Id: SharkSSL.h 5551 2024-08-16 14:41:30Z wini $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2010 - 2024
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://www.realtimelogic.com
33 * http://www.sharkssl.com
34 ****************************************************************************
35 *
36 */
37#ifndef _SharkSsl_h
38#define _SharkSsl_h
39
40#include "TargConfig.h" /* platform dependencies */
41
42#ifndef SHARKDBG_PRINTF
43#define SHARKDBG_PRINTF(x)
44#endif
45
46#ifndef SHARKSSL_API
47#define SHARKSSL_API
48#else /* Barracuda */
49#define SHARKSSL_BA 1
50#include <ThreadLib.h>
51#include <BaServerLib.h>
52#endif
53
54#include "SharkSSL_cfg.h" /* SharkSSL configuration */
55#ifdef __cplusplus
56#include <stddef.h> /* size_t for new, delete */
57#endif
58
59#include "SharkSslCrypto.h" /* Crypto API */
60
61#ifndef sharkCertSerialNumber2NetworkEndian
66typedef U64 SharkCertSerialNumber;
67#ifdef B_BIG_ENDIAN
68#define sharkCertSerialNumber2NetworkEndian(n)
69#else
70#define sharkCertSerialNumber2NetworkEndian(n) \
71 do { \
72 U64 nn=0; \
73 register U8* t=(U8*)&nn; \
74 register U8* f=(U8*)&n; \
75 t[7]=f[0]; \
76 t[6]=f[1]; \
77 t[5]=f[2]; \
78 t[4]=f[3]; \
79 t[3]=f[4]; \
80 t[2]=f[5]; \
81 t[1]=f[6]; \
82 t[0]=f[7]; \
83 n=nn; \
84 } while(0)
85#endif
86#endif
87
88/* Forward decl. */
89struct SharkSslCertDN;
92
114#define SHARKSSL_ALERT_LEVEL_WARNING 1
115
117#define SHARKSSL_ALERT_LEVEL_FATAL 2
118
131#define SHARKSSL_ALERT_CLOSE_NOTIFY 0
133#define SHARKSSL_ALERT_UNEXPECTED_MESSAGE 10
135#define SHARKSSL_ALERT_BAD_RECORD_MAC 20
137#define SHARKSSL_ALERT_DECRYPTION_FAILED 21
139#define SHARKSSL_ALERT_RECORD_OVERFLOW 22
141#define SHARKSSL_ALERT_DECOMPRESSION_FAILURE 30
143#define SHARKSSL_ALERT_HANDSHAKE_FAILURE 40
145#define SHARKSSL_ALERT_BAD_CERTIFICATE 42
147#define SHARKSSL_ALERT_UNSUPPORTED_CERTIFICATE 43
149#define SHARKSSL_ALERT_CERTIFICATE_REVOKED 44
151#define SHARKSSL_ALERT_CERTIFICATE_EXPIRED 45
153#define SHARKSSL_ALERT_CERTIFICATE_UNKNOWN 46
155#define SHARKSSL_ALERT_ILLEGAL_PARAMETER 47
157#define SHARKSSL_ALERT_UNKNOWN_CA 48
159#define SHARKSSL_ALERT_ACCESS_DENIED 49
161#define SHARKSSL_ALERT_DECODE_ERROR 50
163#define SHARKSSL_ALERT_DECRYPT_ERROR 51
165#define SHARKSSL_ALERT_EXPORT_RESTRICTION 60
167#define SHARKSSL_ALERT_PROTOCOL_VERSION 70
169#define SHARKSSL_ALERT_INSUFFICIENT_SECURITY 71
171#define SHARKSSL_ALERT_INTERNAL_ERROR 80
173#define SHARKSSL_ALERT_USER_CANCELED 90
175#define SHARKSSL_ALERT_NO_RENEGOTIATION 100
177#define SHARKSSL_ALERT_UNRECOGNIZED_NAME 112
179#define SHARKSSL_ALERT_NO_APPLICATION_PROTOCOL 120 /* RFC 7301 */
180 /* end group SharkSslAlertMsg */ /* end group SharkSslAlert */
183
184
193#if SHARKSSL_TLS_1_3
195#define TLS_AES_128_GCM_SHA256 0x1301
197#define TLS_AES_256_GCM_SHA384 0x1302
199#define TLS_CHACHA20_POLY1305_SHA256 0x1303
200#endif
201#if SHARKSSL_TLS_1_2
203#define TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 0x009E
205#define TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 0x009F
207#define TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0xC02B
209#define TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0xC02C
211#define TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0xC02F
213#define TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0xC030
215#define TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 0xCCA8
217#define TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 0xCCA9
219#define TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 0xCCAA
220#endif
221 /* end group SharkSslCiphers */
223
224
232#define SHARKSSL_PROTOCOL_UNKNOWN 0x00
234#define SHARKSSL_PROTOCOL_TLS_1_2 0x33
236#define SHARKSSL_PROTOCOL_TLS_1_3 0x34
237
238/* internal use, with SHARKSSL_PROTOCOL_TLS_1_x as parameter */
239#define SHARKSSL_PROTOCOL_MAJOR(p) (p >> 4)
240#define SHARKSSL_PROTOCOL_MINOR(p) (p & 0xF)
241 /* end group SharkSslProtocol */
243
244
245#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
246#ifndef BA_API /* standalone SharkSSL */
247#define BA_API SHARKSSL_API
248#ifdef _SHARKSSL_C_
249#define SingleListCode 1
250#endif
251#endif
252#include "SingleList.h"
253#endif
254
255
256#if SHARKSSL_ENABLE_SESSION_CACHE || SHARKSSL_NOPACK
257
266 /* end group SharkSslSessionApi */
268
269#ifndef _DOXYGEN
270typedef struct SharkSslSessionCache
271{
272 SharkSslSession *cache;
273 ThreadMutexBase cacheMutex;
274 U16 cacheSize;
275} SharkSslSessionCache;
276#endif
277#endif
278
279
291typedef enum
292{
297 /* end group SharkSslInfoAndCodes */
299
300
301#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
309typedef U8* SharkSslKey;
310
311
317typedef const U8 *SharkSslCert;
318
319#ifdef __cplusplus
320extern "C" {
321#endif
322
328SHARKSSL_API U16 SharkSslCert_len(SharkSslCert cert);
329
332#ifdef __DOXYGEN__
334#endif
335
336#if SHARKSSL_ENABLE_CSR_CREATION
399SHARKSSL_API int
401 SharkSslKey privKey,
402 U8 hashID,
403 struct SharkSslCertDN* certDN,
404 const char *SAN,
405 struct SharkSslBitExtReq* keyUsage,
406 struct SharkSslBitExtReq* nsCertType);
407#endif
408
409#if SHARKSSL_ENABLE_CSR_SIGNING
470SHARKSSL_API int
472 const U8 *csrData,
473 int csrDataLen,
474 const SharkSslCert caCert,
475 const SharkSslKey privKey,
476 const char *validFrom,
477 const char *validTo,
478 SharkCertSerialNumber serialNumber,
479 U8 hashID);
480#endif
481
482#if SHARKSSL_ENABLE_ASN1_KEY_CREATION
489SHARKSSL_API int
491#endif
492
493
494#ifdef __cplusplus
495}
496#endif
497
498
499#if SHARKSSL_ENABLE_CA_LIST
505typedef const U8 *SharkSslCAList;
506#endif
507 /* end group SharkSslInfoAndCodes */
509#endif
510
511#ifndef _DOXYGEN
512struct SharkSsl;
513#endif
514
515
516/* Non documented API used by SharkSslSCMgr when used indirectly by
517 Lua code in the Barracuda Application Server. The code manages
518 automatic destruction of SharkSslSCMgr.
519 */
520#ifndef _DOXYGEN
521struct SharkSslIntf;
522typedef void (*SharkSslIntf_Terminate)(struct SharkSslIntf* o,
523 struct SharkSsl* ssl);
524typedef struct SharkSslIntf
525{
526 SharkSslIntf_Terminate terminate;
527} SharkSslIntf;
528#define SharkSslIntf_constructor(o,terminateFunc) (o)->terminate=terminateFunc
529#endif
530
531
554
555
559typedef struct
561{
562#ifdef __cplusplus
563 void *operator new(size_t s) { return ::baMalloc(s); }
564 void operator delete(void* d) { if(d) ::baFree(d); }
565 void *operator new(size_t, void *place) { return place; }
566 void operator delete(void*, void *) { }
567
568 SharkSsl() {};
569
571 U16 cacheSize = 0,
572 U16 inBufStartSize = 4096,
573 U16 outBufSize = 4096
574 );
575
576 ~SharkSsl();
577 SharkSslCon *createCon(void);
578 U8 setCAList(SharkSslCAList caList);
579 U8 addCertificate(SharkSslCert cert);
580 void terminateCon(SharkSslCon *sslCon);
581#endif
582 #if (SHARKSSL_SSL_SERVER_CODE && SHARKSSL_SSL_CLIENT_CODE) || SHARKSSL_NOPACK
583 SharkSsl_Role role;
584 #endif
585 U16 outBufSize;
586 U16 inBufStartSize;
587 U16 nCon;
588 #if (SHARKSSL_ENABLE_RSA || (SHARKSSL_ENABLE_ECDSA)) || SHARKSSL_NOPACK
589 SingleList certList;
590 #if SHARKSSL_ENABLE_CA_LIST || SHARKSSL_NOPACK
591 SharkSslCAList caList;
592 #endif
593 #endif
594 #if SHARKSSL_ENABLE_SESSION_CACHE || SHARKSSL_NOPACK
595 SharkSslSessionCache sessionCache;
596 /* Reserved for use with one SharkSslSCMgr object */
597 SharkSslIntf* intf;
598 #endif
600 /* end group SharkSslInfoAndCodes */
602
609typedef enum
610{
614
618
629
642
655
669
678
690
696
700
702 /* end group SharkSslCoreApi */
704
705#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
706
718#if SHARKSSL_ENABLE_CERT_KEYUSAGE
719#define SHARKSSL_CERT_KEYUSAGE_DIGITALSIGNATURE 0x00000001
720#define SHARKSSL_CERT_KEYUSAGE_NONREPUDIATION 0x00000002
721#define SHARKSSL_CERT_KEYUSAGE_KEYENCIPHERMENT 0x00000004
722#define SHARKSSL_CERT_KEYUSAGE_DATAENCIPHERMENT 0x00000008
723#define SHARKSSL_CERT_KEYUSAGE_KEYAGREEMENT 0x00000010
724#define SHARKSSL_CERT_KEYUSAGE_KEYCERTSIGN 0x00000020
725#define SHARKSSL_CERT_KEYUSAGE_CRLSIGN 0x00000040
726#define SHARKSSL_CERT_KEYUSAGE_ENCIPHERONLY 0x00000080
727#define SHARKSSL_CERT_KEYUSAGE_DECIPHERONLY 0x00000100
728#define SHARKSSL_CERT_KEYUSAGE_PRESENT 0x00000200
729#define SHARKSSL_CERT_KEYUSAGE_CRITICAL 0x00000400
730
731#define SHARKSSL_CERT_KEYPURPOSE_SERVERAUTH 0x00010000
732#define SHARKSSL_CERT_KEYPURPOSE_CLIENTAUTH 0x00020000
733#define SHARKSSL_CERT_KEYPURPOSE_CODESIGNING 0x00040000
734#define SHARKSSL_CERT_KEYPURPOSE_EMAILPROTECTION 0x00080000
735#define SHARKSSL_CERT_KEYPURPOSE_TIMESTAMPING 0x00100000
736#define SHARKSSL_CERT_KEYPURPOSE_OCSPSIGNING 0x00200000
737
738#define SharkSslCertInfo_KeyFlagSet(o,f) ((o)->keyUsagePurposes & f)
739
743#define SharkSslCertInfo_isKeyUsagePresent(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_PRESENT)
744#define SharkSslCertInfo_isKeyUsageCritical(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_CRITICAL)
745#define SharkSslCertInfo_KU_digitalSignature(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_DIGITALSIGNATURE)
746#define SharkSslCertInfo_KU_nonRepudiation(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_NONREPUDIATION)
747#define SharkSslCertInfo_KU_keyEncipherment(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_KEYENCIPHERMENT)
748#define SharkSslCertInfo_KU_dataEncipherment(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_DATAENCIPHERMENT)
749#define SharkSslCertInfo_KU_keyAgreement(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_KEYAGREEMENT)
750#define SharkSslCertInfo_KU_keyCertSign(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_KEYCERTSIGN)
751#define SharkSslCertInfo_KU_cRLSign(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_CRLSIGN)
752#define SharkSslCertInfo_KU_encipherOnly(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_ENCIPHERONLY)
753#define SharkSslCertInfo_KU_decipherOnly(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_DECIPHERONLY)
754
755#define SharkSslCertInfo_kp_serverAuth(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_SERVERAUTH)
756#define SharkSslCertInfo_kp_clientAuth(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_CLIENTAUTH)
757#define SharkSslCertInfo_kp_codeSigning(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_CODESIGNING)
758#define SharkSslCertInfo_kp_emailProtection(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_EMAILPROTECTION)
759#define SharkSslCertInfo_kp_timeStamping(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_TIMESTAMPING)
760#define SharkSslCertInfo_kp_OCSPSigning(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_OCSPSIGNING)
761#endif
762
763
775typedef struct SharkSslCertDN
776{
777 const U8 *countryName;
778 const U8 *province;
779 const U8 *locality;
780 const U8 *organization;
781 const U8 *unit;
785 const U8 *commonName;
786 const U8 *emailAddress;
787
788 U8 countryNameLen;
796
799#define SharkSslCertDN_constructor(o) memset(o,0,sizeof(SharkSslCertDN))
802#define SharkSslCertDN_setCountryName(o, countryNameMA) \
803 (o)->countryName=(const U8*)countryNameMA,(o)->countryNameLen=(U8)strlen(countryNameMA)
806#define SharkSslCertDN_setProvince(o, provinceMA) \
807 (o)->province=(const U8*)provinceMA,(o)->provinceLen=(U8)strlen(provinceMA)
810#define SharkSslCertDN_setLocality(o, localityMA) \
811 (o)->locality=(const U8*)localityMA,(o)->localityLen=(U8)strlen(localityMA)
814#define SharkSslCertDN_setOrganization(o, organizationMA) \
815 (o)->organization=(const U8*)organizationMA,(o)->organizationLen=(U8)strlen(organizationMA)
818#define SharkSslCertDN_setUnit(o, unitMA) \
819 (o)->unit=(const U8*)unitMA,(o)->unitLen=(U8)strlen(unitMA)
822#define SharkSslCertDN_setCommonName(o, commonNameMA) \
823 (o)->commonName=(const U8*)commonNameMA,(o)->commonNameLen=(U8)strlen(commonNameMA)
826#define SharkSslCertDN_setEmailAddress(o, emailAddressMA) \
827 (o)->emailAddress=(const U8*)emailAddressMA,(o)->emailAddressLen=(U8)strlen(emailAddressMA)
828
829
833typedef struct SharkSslCertInfo
834{
836 U16 snLen;
837
842
847
850 U8 *sn;
851
855 U8 *timeFrom; /* declaration of U8 timeFromLen below */
856
861 U8 *timeTo; /* declaration of U8 timeToLen below */
862
868
874
887 U16 subjectAltNamesLen;
888
891
894
895 #if SHARKSSL_ENABLE_CERT_KEYUSAGE
918 U32 keyUsagePurposes;
919 #endif
920
926 /* end group SharkSslCertInfo */
928#endif
929
935#ifdef __cplusplus
936extern "C" {
937#endif
938
966SHARKSSL_API void SharkSsl_constructor(
967 SharkSsl *o,
968 SharkSsl_Role role,
969 U16 cacheSize,
970 U16 inBufStartSize,
971 U16 outBufSize
972 );
973
981SHARKSSL_API void SharkSsl_destructor(SharkSsl *o);
982
983
1004
1005
1021
1022
1023#if SHARKSSL_ENABLE_SESSION_CACHE
1024
1029SHARKSSL_API U16 SharkSsl_getCacheSize(SharkSsl *o);
1030
1031#define SharkSsl_setIntf(o, sharkSslIntf) (o)->intf=sharkSslIntf
1032#define SharkSsl_getIntf(o) (o)->intf
1033
1034#endif
1035
1036
1043#define SharkSslCon_terminate(o) SharkSsl_terminateCon(0, o)
1044
1067
1068
1094
1095
1105
1106
1124
1125
1136
1148
1149
1164
1195U16 SharkSslCon_copyDecData(SharkSslCon *o, U8 *buf, U16 maxLen);
1196
1197
1207SHARKSSL_API U16 SharkSslCon_getDecData(SharkSslCon *o, U8 **bufPtr);
1208
1209
1222
1223
1237
1238
1254
1255
1266
1267
1280
1281
1289
1290
1294
1295
1306
1307
1318
1319
1329#define SharkSslCon_getAlertData(o) SharkSslCon_getEncData(o)
1330
1331
1341#define SharkSslCon_getAlertDataLen(o) SharkSslCon_getEncDataLen(o)
1342 /* end group SharkSslCoreApi */
1344
1345
1346#if SHARKSSL_ENABLE_INFO_API
1347
1351
1354#if (SHARKSSL_TLS_1_3 && SHARKSSL_TLS_1_2)
1356#elif SHARKSSL_TLS_1_3
1357#define SharkSslCon_getProtocol(o) (SHARKSSL_PROTOCOL_TLS_1_3)
1358#elif SHARKSSL_TLS_1_2
1359#define SharkSslCon_getProtocol(o) (SHARKSSL_PROTOCOL_TLS_1_2)
1360#else
1361#error please enable at least one of SHARKSSL_TLS_1_3, SHARKSSL_TLS_1_2
1362#endif
1363
1364#endif
1365
1366
1367#if SHARKSSL_ENABLE_SNI
1368
1369#if SHARKSSL_SSL_CLIENT_CODE
1372SHARKSSL_API U8 SharkSslCon_setSNI(SharkSslCon *o, const char *name, U16 length);
1373#endif
1374
1375#endif
1376
1377
1378#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
1379#if (SHARKSSL_SSL_CLIENT_CODE && SHARKSSL_ENABLE_CLIENT_AUTH)
1384#endif
1385
1390
1402
1403#if SHARKSSL_ENABLE_CA_LIST
1404
1425SHARKSSL_API U8 SharkSsl_setCAList(SharkSsl *o, SharkSslCAList caList);
1426
1441
1442U8 SharkSslCon_isCAListEmpty(SharkSslCon *o);
1443#else
1444
1445#define SharkSslCon_trustedCA(o) 0
1446#endif /* SHARKSSL_ENABLE_CA_LIST */
1447
1448#if (SHARKSSL_SSL_SERVER_CODE && SHARKSSL_ENABLE_RSA)
1452/* to be used as 'flag' param */
1453#define SHARKSSL_SET_FAVOR_RSA 1
1454#define SHARKSSL_CLEAR_FAVOR_RSA 0
1455
1474#endif /* SHARKSSL_SSL_SERVER_CODE */
1475#endif /* SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA */
1476
1477#if SHARKSSL_SSL_CLIENT_CODE
1478U8 SharkSslCon_selectProtocol(SharkSslCon *o, U8 protocol);
1479#endif
1480
1485#if SHARKSSL_ENABLE_SESSION_CACHE
1486
1487#if SHARKSSL_ENABLE_INFO_API
1491#endif
1492
1496
1497#if SHARKSSL_SSL_SERVER_CODE
1501#endif
1502
1503#if SHARKSSL_SSL_CLIENT_CODE
1504
1513
1514
1522
1528#endif
1529#endif
1530 /* end group SharkSslSessionApi */
1532
1533#if (SHARKSSL_SSL_SERVER_CODE && SHARKSSL_ENABLE_CLIENT_AUTH && \
1534 (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA))
1567 SharkSslCon *o, const void *caList);
1568#endif
1569
1570#if (SHARKSSL_TLS_1_3 && SHARKSSL_SSL_CLIENT_CODE && SHARKSSL_ENABLE_CA_EXTENSION && \
1571 (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA))
1599 SharkSslCon *o, const void *caList);
1600#endif
1601
1602#if SHARKSSL_ENABLE_ALPN_EXTENSION
1603#if SHARKSSL_SSL_CLIENT_CODE
1620 SharkSslCon* o, const char* protList);
1621
1635SHARKSSL_API const char *SharkSslCon_getALPNProtocol(SharkSslCon* o);
1636#endif
1637#if SHARKSSL_SSL_SERVER_CODE
1638typedef int(*ALPNFunction)(SharkSslCon*, const char*, void *);
1639SHARKSSL_API U8 SharkSslCon_setALPNFunction(
1640 SharkSslCon *o, ALPNFunction func, void *pvoid);
1641#endif
1642#endif /* SHARKSSL_ENABLE_ALPN_EXTENSION */
1643
1644#if ((SHARKSSL_SSL_SERVER_CODE || SHARKSSL_SSL_CLIENT_CODE) && \
1645 SHARKSSL_ENABLE_SELECT_CIPHERSUITE)
1675SHARKSSL_API U8 SharkSslCon_selectCiphersuite(SharkSslCon *o, U16 cipherSuite);
1676
1680#endif
1681
1682#if (SHARKSSL_SSL_SERVER_CODE && SHARKSSL_ENABLE_SECURE_RENEGOTIATION)
1703#endif
1704 /* end group SharkSslApi */
1706
1707
1708#if SHARKSSL_ENABLE_PEM_API
1716typedef enum
1717{
1720
1723
1726
1729
1732
1735
1738
1741
1744
1747
1750
1753
1756
1759
1762
1765
1768
1771
1775
1776
1806 const char *certPEM, const char *keyPEM,
1807 const char *passphrase, SharkSslCert *sharkSslCert);
1808
1809#if SHARKSSL_ENABLE_ENCRYPTED_PKCS8_SUPPORT
1827SHARKSSL_API int sharkssl_PEM_PBKDF2(
1828 U8 *dk, const char *passphrase,
1829 const char *salt, U32 saltLen,
1830 U32 iterations, U16 dkLen, U8 hashID);
1831#endif
1832 /* end group RayCryptoApi */
1834#endif
1835
1836#if SHARKSSL_ENABLE_RSA
1837
1844#define SHARKSSL_RSA_NO_PADDING 0
1845
1846
1850#define SHARKSSL_RSA_PKCS1_PADDING 1
1851
1852
1857typedef enum
1858{
1861
1864
1867
1870
1873
1876
1879
1882
1886#endif
1887 /* end group SharkSslInfoAndCodes */
1889
1890#if SHARKSSL_ENABLE_RSA_API
1891
1902typedef U8* SharkSslRSAKey;
1903
1904#if SHARKSSL_ENABLE_PEM_API
1929 const char *PEMKey, const char *passphrase);
1930
1954SHARKSSL_API SharkSslKey
1956
1957SHARKSSL_API SharkSslKey
1958sharkssl_PEM_extractPublicKey_ext(const char *certPEM, U8 *keyType);
1959#endif /* SHARKSSL_ENABLE_PEM_API */
1960
1961#if (SHARKSSL_ENABLE_PEM_API || (SHARKSSL_ENABLE_RSA && SHARKSSL_ENABLE_RSAKEY_CREATE))
1966#define _SHARKSSLRSAKEY_FREE 1
1967#endif
1968
1969#if SHARKSSL_ENABLE_RSA
1970#if SHARKSSL_ENABLE_RSAKEY_CREATE
1992SHARKSSL_API int SharkSslRSAKey_create(SharkSslRSAKey *privKey, U16 keyLength);
1993
2008#endif
2009
2015
2039 U16 len, U8 *in, U8 *out, SharkSslRSAKey key, U8 padding);
2040
2041
2060 U16 len, U8 *in, U8 *out, SharkSslRSAKey privkey, U8 padding);
2061
2062
2063#if SHARKSSL_ENABLE_RSA_OAEP
2088SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_private_decrypt_OAEP(
2089 U16 len, U8 *in, U8 *out, SharkSslRSAKey privkey, U8 hashID, const char *label, U16 labelLen);
2090
2091
2117SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_public_encrypt_OAEP(
2118 U16 len, const U8 *in, U8 *out, SharkSslRSAKey pubkey, U8 hashID, const char *label, U16 labelLen);
2119#endif
2120
2121
2143 U16 len, U8 *in, U8 *out, SharkSslRSAKey privkey, U8 padding);
2144
2145
2167 U16 len, U8 *in, U8 *out, SharkSslRSAKey key, U8 padding);
2168
2169#endif
2170 /* end group RSA */
2172#endif
2173
2174
2187#if SHARKSSL_USE_ECC
2188
2189/*
2190 * NamedCurve, use as curveID parameter
2191 * SECPxxxR1 - RFC 4492 section 5.1.1
2192 * BRAINPOOLPxxxR1 - RFC 7027 section 2
2193 * CURVE25519,448 - RFC 8446 section 4.2.7
2194 */
2195#define SHARKSSL_EC_CURVE_ID_SECP256R1 23
2196#define SHARKSSL_EC_CURVE_ID_SECP384R1 24
2197#define SHARKSSL_EC_CURVE_ID_SECP521R1 25
2198#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP256R1 26
2199#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP384R1 27
2200#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP512R1 28
2201#define SHARKSSL_EC_CURVE_ID_CURVE25519 29
2202#define SHARKSSL_EC_CURVE_ID_CURVE448 30
2203
2204
2211typedef U8* SharkSslECCKey;
2212
2213#if SHARKSSL_ENABLE_PEM_API
2240 const char *PEMKey, const char *passphrase);
2241
2242
2243#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
2251SHARKSSL_API U16 SharkSslKey_vectSize(const SharkSslKey key);
2252#define SharkSslCert_vectSize(c) SharkSslKey_vectSize((const SharkSslCert)c)
2253#if SHARKSSL_ENABLE_RSA
2254#define SharkSslRSAKey_vectSize(k) SharkSslKey_vectSize(k)
2255#endif
2256#if SHARKSSL_ENABLE_ECDSA
2257#define SharkSslECCKey_vectSize(k) SharkSslKey_vectSize(k)
2258#endif
2259#endif
2260#endif
2261
2262#if SHARKSSL_ENABLE_ECCKEY_CREATE
2263
2264typedef int (*sharkssl_rngfunc)(void* handle, U8 *ptr, U16 len);
2265
2266
2285#define SharkSslECCKey_create(privKey, curveID) SharkSslECCKey_createEx((privKey), (curveID), 0, 0)
2286
2287
2337SHARKSSL_API int SharkSslECCKey_createEx(SharkSslECCKey* privKey, U16 curveID, void* rngHandle, sharkssl_rngfunc rngFunc);
2338#endif
2339
2340
2341#if (SHARKSSL_ENABLE_PEM_API || SHARKSSL_ENABLE_ECCKEY_CREATE)
2348#define _SHARKSSLECCKEY_FREE 1
2349#endif
2350
2351
2352/*
2353 *-----------------------------------------------------------------------------
2354 * To free up the memory allocated by SharkSslECCKey_create and
2355 * SharkSslRSAKey_create, the following macro is provided
2356 * For instance, this function could be called after saving the key to a file
2357 *-----------------------------------------------------------------------------
2358 * key: input parameter, points to a buffer allocated by either
2359 * SharkSslECCKey_create or SharkSslRSAKey_create
2360 */
2361#if defined(_SHARKSSLRSAKEY_FREE)
2362#define SharkSslKey_free SharkSslRSAKey_free
2363#elif defined (_SHARKSSLECCKEY_FREE)
2364#define SharkSslKey_free SharkSslECCKey_free
2365#else
2366#define SharkSslKey_free
2367#endif
2368#undef _SHARKSSLRSAKEY_FREE
2369#undef _SHARKSSLECCKEY_FREE
2370
2371
2377#if SHARKSSL_ENABLE_ECDSA
2381/* ECDSA API and also internal sharkssl_ECDSA_signASN1 */
2382typedef enum
2383{
2386
2389
2392
2395
2398
2401
2404
2407
2410
2414 /* end group SharkSslInfoAndCodes */
2416
2422#if SHARKSSL_ENABLE_ECDSA_API
2423#if (!SHARKSSL_ECDSA_ONLY_VERIFY)
2432SHARKSSL_API U16 sharkssl_ECDSA_siglen(SharkSslECCKey privkey);
2433
2457 SharkSslECCKey privkey, U8 *sig, U16 *siglen, U8 *hash, U8 hashlen);
2458#endif
2459
2478 SharkSslECCKey pubkey, U8 *sig, U16 siglen, U8 *hash, U8 hashlen);
2479
2480#endif /* SHARKSSL_ENABLE_ECDSA_API */
2481#endif /* SHARKSSL_ENABLE_ECDSA */
2482 /* end group ECC */
2484#endif
2485
2486
2487#if (SHARKSSL_ENABLE_CA_LIST && SHARKSSL_ENABLE_CERTSTORE_API)
2488
2494#ifndef BA_API /* standalone SharkSSL */
2495#define BA_API SHARKSSL_API
2496typedef U8 BaBool;
2497#endif
2498#include "DoubleList.h"
2499
2519typedef struct SharkSslCertStore
2520{
2521 DoubleList certList;
2522 SharkSslCAList caList;
2523 U16 elements; /* number of elements in list */
2525
2535
2539
2541#define SharkSslCertStore_release(o) SharkSslCertStore_destructor(o)
2542
2555SHARKSSL_API U16 SharkSslCertStore_add(
2556 SharkSslCertStore *o, const char *cert, U32 certlen);
2557
2569 SharkSslCertStore *o, SharkSslCAList *outList);
2570 /* end group SharkSslCertApi */
2572#endif /* SHARKSSL_ENABLE_CA_LIST && SHARKSSL_ENABLE_CERTSTORE_API */
2573
2574#if ((SHARKSSL_ENABLE_PEM_API) || (SHARKSSL_ENABLE_CERTSTORE_API))
2575SHARKSSL_API U32 sharkssl_B64Decode(
2576 U8 *outStr, U32 outStrSize, const char *b64beg, const char *b64end);
2577#endif
2578
2579
2580
2581#ifdef __cplusplus
2582}
2583
2584inline SharkSsl::SharkSsl(
2585 SharkSsl_Role role, U16 cacheSize, U16 inBufStartSize, U16 outBufSize) {
2586 SharkSsl_constructor(this, role, cacheSize, inBufStartSize, outBufSize);
2587}
2588inline SharkSsl::~SharkSsl() {
2589 SharkSsl_destructor(this);
2590}
2591inline SharkSslCon *SharkSsl::createCon(void) {
2592 return SharkSsl_createCon(this);
2593}
2594inline void SharkSsl::terminateCon(SharkSslCon *sslCon) {
2595 SharkSsl_terminateCon(this, sslCon);
2596}
2597
2598#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
2599inline U8 SharkSsl::addCertificate(SharkSslCert cert) {
2600 return SharkSsl_addCertificate(this, cert);
2601}
2602#if SHARKSSL_ENABLE_CA_LIST
2603inline U8 SharkSsl::setCAList(SharkSslCAList caList) {
2604 return SharkSsl_setCAList(this, caList);
2605}
2606#endif /* SHARKSSL_ENABLE_CA_LIST */
2607#endif /* SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA */
2608
2609#endif /* __cplusplus */
2610
2611
2612#endif
SHARKSSL_API SharkSslECCKey sharkssl_PEM_to_ECCKey(const char *PEMKey, const char *passphrase)
Convert an ECC private or public key in PEM format to the SharkSslECCKey format.
SHARKSSL_API sharkssl_ECDSA_RetVal sharkssl_ECDSA_verify_hash(SharkSslECCKey pubkey, U8 *sig, U16 siglen, U8 *hash, U8 hashlen)
Verify a message using the ECC public key and a hash algorithm.
SHARKSSL_API U16 sharkssl_ECDSA_siglen(SharkSslECCKey privkey)
Returns the maximum length (in bytes) of a DER-encoded ECDSA signature generated with the private key...
U8 * SharkSslECCKey
SharkSslECCKey is an alias for the SharkSslCert type and is a private/public key converted by sharkss...
Definition: SharkSSL.h:2211
SHARKSSL_API sharkssl_ECDSA_RetVal sharkssl_ECDSA_sign_hash(SharkSslECCKey privkey, U8 *sig, U16 *siglen, U8 *hash, U8 hashlen)
Generate the signature using the ECC private key and a hash.
SHARKSSL_API SharkSslRSAKey sharkssl_PEM_to_RSAKey(const char *PEMKey, const char *passphrase)
Convert an RSA private or public key in PEM format to the SharkSslRSAKey format.
SHARKSSL_API SharkSslKey sharkssl_PEM_extractPublicKey(const char *certPEM)
Extract the public key form a certificate in PEM format.
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_public_decrypt(U16 len, U8 *in, U8 *out, SharkSslRSAKey key, U8 padding)
Bring back a message digest using the public key or private key.
SHARKSSL_API void SharkSslRSAKey_free(SharkSslRSAKey key)
Release a SharkSslRSAKey allocated by functions sharkssl_PEM_to_RSAKey and sharkssl_PEM_extractPublic...
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_private_decrypt(U16 len, U8 *in, U8 *out, SharkSslRSAKey privkey, U8 padding)
Decrypt ciphertext using the private key.
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_public_encrypt(U16 len, U8 *in, U8 *out, SharkSslRSAKey key, U8 padding)
Encrypt data using the public key or private key.
U8 * SharkSslRSAKey
SharkSslRSAKey is an alias for the SharkSslCert type and is a private/public key converted by sharkss...
Definition: SharkSSL.h:1902
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_private_encrypt(U16 len, U8 *in, U8 *out, SharkSslRSAKey privkey, U8 padding)
Sign a message digest using the private key.
sharkssl_PEM_RetVal
Return values from function sharkssl_PEM.
Definition: SharkSSL.h:1717
SHARKSSL_API sharkssl_PEM_RetVal sharkssl_PEM(const char *certPEM, const char *keyPEM, const char *passphrase, SharkSslCert *sharkSslCert)
Create a SharkSslCert certificate by using a certificate and key in PEM format.
SHARKSSL_API int sharkssl_PEM_PBKDF2(U8 *dk, const char *passphrase, const char *salt, U32 saltLen, U32 iterations, U16 dkLen, U8 hashID)
sharkssl_PEM_PBKDF2 (output, passphrase, salt, salt_len, iterations, dkLen, hashID) Derives a key fro...
@ SHARKSSL_PEM_CERT_UNSUPPORTED_TYPE
CERT_UNSUPPORTED_TYPE.
Definition: SharkSSL.h:1761
@ SHARKSSL_PEM_KEY_UNSUPPORTED_ENCRYPTION_TYPE
KEY_UNSUPPORTED_ENCRYPTION_TYPE.
Definition: SharkSSL.h:1752
@ SHARKSSL_PEM_OK
OK.
Definition: SharkSSL.h:1719
@ SHARKSSL_PEM_OK_PUBLIC
OK_PUBLIC.
Definition: SharkSSL.h:1722
@ SHARKSSL_PEM_KEY_PRIVATE_KEY_REQUIRED
A PRIVATE KEY IS REQUIRED.
Definition: SharkSSL.h:1770
@ SHARKSSL_PEM_KEY_UNSUPPORTED_EXPONENT_LENGTH
KEY_UNSUPPORTED_EXPONENT_LENGTH.
Definition: SharkSSL.h:1749
@ SHARKSSL_PEM_KEY_UNSUPPORTED_FORMAT
KEY_UNSUPPORTED_FORMAT.
Definition: SharkSSL.h:1743
@ SHARKSSL_PEM_KEY_UNRECOGNIZED_FORMAT
KEY_UNRECOGNIZED_FORMAT.
Definition: SharkSSL.h:1740
@ SHARKSSL_PEM_KEY_UNSUPPORTED_VERSION
KEY_UNSUPPORTED_VERSION.
Definition: SharkSSL.h:1764
@ SHARKSSL_PEM_KEY_PASSPHRASE_REQUIRED
KEY_PASSPHRASE_REQUIRED.
Definition: SharkSSL.h:1737
@ SHARKSSL_PEM_KEY_WRONG_LENGTH
KEY_WRONG_LENGTH.
Definition: SharkSSL.h:1734
@ SHARKSSL_PEM_KEY_PARSE_ERROR
KEY_PARSE_ERROR.
Definition: SharkSSL.h:1728
@ SHARKSSL_PEM_CERT_UNRECOGNIZED_FORMAT
CERT_UNRECOGNIZED_FORMAT.
Definition: SharkSSL.h:1758
@ SHARKSSL_PEM_KEY_REQUIRED
KEY_REQUIRED.
Definition: SharkSSL.h:1767
@ SHARKSSL_PEM_ALLOCATION_ERROR
ALLOCATION_ERROR.
Definition: SharkSSL.h:1725
@ SHARKSSL_PEM_KEY_WRONG_IV
KEY_WRONG_IV.
Definition: SharkSSL.h:1731
@ SHARKSSL_PEM_INTERNAL_ERROR
INTERNAL ERROR.
Definition: SharkSSL.h:1773
@ SHARKSSL_PEM_KEY_CERT_MISMATCH
KEY_CERT_MISMATCH.
Definition: SharkSSL.h:1755
@ SHARKSSL_PEM_KEY_UNSUPPORTED_MODULUS_LENGTH
KEY_UNSUPPORTED_MODULUS_LENGTH.
Definition: SharkSSL.h:1746
U8 SharkSslCon_favorRSA(SharkSslCon *o, U8 flag)
A SharkSSL server can have multiple certificates, such as RSA certificates with various strengths,...
SHARKSSL_API U16 SharkSsl_getCacheSize(SharkSsl *o)
Returns the SharkSsl session cache size.
SharkSslCon * SharkSsl_createCon(SharkSsl *o)
Create a SharkSslCon object.
SHARKSSL_API U8 SharkSslCon_setSNI(SharkSslCon *o, const char *name, U16 length)
set Server Name Indication for TLS client connections
SHARKSSL_API U8 SharkSslCon_trustedCA(SharkSslCon *o)
Returns TRUE if the certificate is valid and is signed with a root certificate trusted by SharkSSL.
SHARKSSL_API U8 SharkSslCon_requestClientCert(SharkSslCon *o, const void *caList)
This function is used by server solutions that require client SSL certificate authentication.
SHARKSSL_API void SharkSsl_destructor(SharkSsl *o)
Close the SharkSsl object.
SHARKSSL_API U8 SharkSslCon_setCertificateAuthorities(SharkSslCon *o, const void *caList)
This function is used by client solutions that require server SSL certificate authentication.
SHARKSSL_API U8 SharkSslCon_clearCiphersuiteSelection(SharkSslCon *o)
Clears the selection, thus enabling all ciphers.
SHARKSSL_API U8 SharkSslCon_getProtocol(SharkSslCon *o)
Returns the active session's protocol version.
SHARKSSL_API U8 SharkSslCon_setALPNProtocols(SharkSslCon *o, const char *protList)
This function is used by client solutions to specify a list of application layer protocols according ...
U8 SharkSslCon_certificateRequested(SharkSslCon *o)
Returns TRUE if the server requested a certificate from the client to verify that the client's identi...
SHARKSSL_API U8 SharkSsl_addCertificate(SharkSsl *o, SharkSslCert cert)
Add a certificate to the SharkSsl object.
SHARKSSL_API U8 SharkSslCon_selectCiphersuite(SharkSslCon *o, U16 cipherSuite)
This function enables you to limit the number of ciphers at runtime.
SHARKSSL_API U8 SharkSsl_setCAList(SharkSsl *o, SharkSslCAList caList)
Set a Certificate Authority (CA) list so the SharkSSL object can permform certificate validation on t...
void SharkSsl_terminateCon(const SharkSsl *o, SharkSslCon *con)
Terminate a SharkSslCon object created by function SharkSsl_createCon.
SHARKSSL_API SharkSslCertInfo * SharkSslCon_getCertInfo(SharkSslCon *o)
Returns the peer's certificate if the handshaking has completed.
SHARKSSL_API U8 SharkSslCon_renegotiate(SharkSslCon *o)
This function enables you to renegotiate an already established SSL/TLS connection.
SHARKSSL_API U16 SharkSslCon_getCiphersuite(SharkSslCon *o)
Returns the active session's chiper suite.
SHARKSSL_API const char * SharkSslCon_getALPNProtocol(SharkSslCon *o)
This function is used by client solutions to return the application layer protocol selected by the se...
SHARKSSL_API void SharkSsl_constructor(SharkSsl *o, SharkSsl_Role role, U16 cacheSize, U16 inBufStartSize, U16 outBufSize)
A SharkSsl object is the coordinator for managing SharkSslCon objects.
SHARKSSL_API int SharkSslECCKey_createEx(SharkSslECCKey *privKey, U16 curveID, void *rngHandle, sharkssl_rngfunc rngFunc)
Creates an ECC key using the SharkSSL library.
SHARKSSL_API int SharkSslRSAKey_create(SharkSslRSAKey *privKey, U16 keyLength)
RSA key creation.
SHARKSSL_API int SharkSslASN1Create_CSR(struct SharkSslASN1Create *o, SharkSslKey privKey, U8 hashID, struct SharkSslCertDN *certDN, const char *SAN, struct SharkSslBitExtReq *keyUsage, struct SharkSslBitExtReq *nsCertType)
CSR creation (all parameters are input parameters)
SHARKSSL_API void SharkSslCertStore_constructor(SharkSslCertStore *o)
Initialize a SharkSslCertStore object.
SHARKSSL_API int SharkSslCert_signCSR(SharkSslCert *signedCSR, const U8 *csrData, int csrDataLen, const SharkSslCert caCert, const SharkSslKey privKey, const char *validFrom, const char *validTo, SharkCertSerialNumber serialNumber, U8 hashID)
CSR signing (if not specified, parameters are input parameters)
SHARKSSL_API U16 SharkSslRSAKey_size(SharkSslRSAKey key)
Returns the private or public key's modulus size in bytes.
SHARKSSL_API void SharkSslECCKey_free(SharkSslECCKey key)
Release a SharkSslECCKey allocated by functions sharkssl_PEM_to_ECCKey or SharkSslECCKey_create.
SHARKSSL_API U16 SharkSslCertStore_add(SharkSslCertStore *o, const char *cert, U32 certlen)
add a certificate in PEM or p7b format to the CA store.
SHARKSSL_API U8 SharkSslCertStore_assemble(SharkSslCertStore *o, SharkSslCAList *outList)
Assemble all certificates added by calling SharkSslCertStore_add.
struct SharkSslCertStore SharkSslCertStore
SharkSslCertStore is a container object used when assembling a SharkSslCAList.
SHARKSSL_API void SharkSslCertStore_destructor(SharkSslCertStore *o)
Cleanup all memory used by the SharkSslCAList object.
SHARKSSL_API U16 SharkSslCert_len(SharkSslCert cert)
Get certificate length.
SHARKSSL_API U16 SharkSslKey_vectSize(const SharkSslKey key)
Returns the private or public key's "vector size" in bytes.
SHARKSSL_API U8 * SharkSslRSAKey_getPublic(SharkSslRSAKey privKey)
RSA public key extraction from a private key.
struct SharkSslCertInfo SharkSslCertInfo
The peer's certificate information returned by SharkSslCon_getCertInfo.
struct SharkSslCertDN SharkSslCertDN
Certificate KeyUsage and ExtendedKeyUsage flags and relative pseudofunctions.
U8 * SharkSslCon_getEncData(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Encrypted returned by function SharkSslCo...
U16 SharkSslCon_getHandshakeDataLen(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Handshake returned by function SharkSslCo...
U16 SharkSslCon_getEncDataLen(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Encrypted returned by function SharkSslCo...
U16 SharkSslCon_getBufLen(SharkSslCon *o)
Returns the length of the SharkSslCon input buffer.
SharkSslCon_RetVal
The SharkSslCon_decrypt and SharkSslCon_encrypt return values.
Definition: SharkSSL.h:610
SharkSslCon_RetVal SharkSslCon_decrypt(SharkSslCon *o, U16 readLen)
Decrypt the received data copied into the SharkSslCon receive buffer (the buffer returned by SharkSsl...
U16 SharkSslCon_getEncBufSize(SharkSslCon *o)
Returns the length of the buffer returned by SharkSslCon_getEncBufPtr.
U8 SharkSslCon_encryptMore(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Encrypted returned by function SharkSslCo...
U8 SharkSslCon_decryptMore(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Decrypted returned by function SharkSslCo...
U8 * SharkSslCon_getBuf(SharkSslCon *o)
Returns a pointer to the SharkSslCon input/receive buffer.
SHARKSSL_API U16 SharkSslCon_getDecData(SharkSslCon *o, U8 **bufPtr)
Get a pointer to the decoded data.
U8 SharkSslCon_getAlertLevel(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_AlertSend returned by function SharkSslCo...
U16 SharkSslCon_copyDecData(SharkSslCon *o, U8 *buf, U16 maxLen)
Copy decoded data to 'buf'.
U8 * SharkSslCon_getEncBufPtr(SharkSslCon *o)
This function is used in conjunction with SharkSslCon_encrypt when using the zero copy send API.
U16 SharkSslCon_setHandshakeDataSent(SharkSslCon *o, U16 length)
This function is used in conjunction with SharkSslCon_getHandshakeData.
U8 SharkSslCon_getAlertDescription(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_AlertSend returned by function SharkSslCo...
U8 SharkSslCon_isHandshakeComplete(SharkSslCon *o)
Returns the following values:
U8 * SharkSslCon_getHandshakeData(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Handshake returned by function SharkSslCo...
SharkSslCon_RetVal SharkSslCon_encrypt(SharkSslCon *o, U8 *buf, U16 maxLen)
Encrypt the data provided by parameter 'buf' or encrypt data in the SharkSslCon send buffer.
@ SharkSslCon_Encrypted
SharkSSL has successfully decrypted a chunk of data.
Definition: SharkSSL.h:689
@ SharkSslCon_Decrypted
Returned when a block of received data has been successfully decrypted.
Definition: SharkSSL.h:628
@ SharkSslCon_AlertSend
Returned when an SSL/TLS alert message must be sent to the peer side.
Definition: SharkSSL.h:668
@ SharkSslCon_AllocationError
The memory pool is too small.
Definition: SharkSSL.h:617
@ SharkSslCon_Error
Indicates general errors, including configuration errors.
Definition: SharkSSL.h:613
@ SharkSslCon_CertificateError
Unrecognized format of a provided certificate.
Definition: SharkSSL.h:699
@ SharkSslCon_AlertRecv
SharkSSL received an SSL/TLS alert message from the peer, which means that the peer either failed to ...
Definition: SharkSSL.h:677
@ SharkSslCon_HandshakeNotComplete
An error condition returned by function SharkSslCon_encrypt if the SSL handshake is not completed.
Definition: SharkSSL.h:695
@ SharkSslCon_Handshake
Returned when an SSL/TLS handshake message has been received or is to be sent.
Definition: SharkSSL.h:641
@ SharkSslCon_NeedMoreData
Returned when SharkSSL holds an incomplete SSL/TLS record or when the connection is initially establi...
Definition: SharkSSL.h:654
U32 baGetUnixTime(void)
Platform dependent function returning seconds since Jan 1 1970.
struct SharkSsl SharkSsl
A SharkSsl object is the coordinator for managing SharkSslCon objects (See SharkSsl_constructor for d...
const U8 * SharkSslCert
The SharkSSL Certificate is in a binary format optimized for speed and size.
Definition: SharkSSL.h:317
SHARKSSL_API int SharkSslASN1Create_key(struct SharkSslASN1Create *o, const SharkSslKey key)
Convert a SharkSslKey to ASN.1 representation.
const U8 * SharkSslCAList
The SharkSSL Certificate Authority (CA) List is in a binary format optimized for speed and size.
Definition: SharkSSL.h:505
struct SharkSslCon SharkSslCon
SharkSslCon is an opaque handle returned by function SharkSsl_createCon.
Definition: SharkSSL.h:553
SharkSsl_Role
Select one of client or server mode when creating a SharkSsl object.
Definition: SharkSSL.h:292
sharkssl_ECDSA_RetVal
Return values from functions sharkssl_ECDSA_sign_hash, sharkssl_ECDSA_verify_hash.
Definition: SharkSSL.h:2383
sharkssl_RSA_RetVal
Return values from functions sharkssl_RSA_public_encrypt, sharkssl_RSA_private_decrypt,...
Definition: SharkSSL.h:1858
U8 * SharkSslKey
The SharkSslKey type.
Definition: SharkSSL.h:309
@ SharkSsl_Unspecified
Definition: SharkSSL.h:293
@ SharkSsl_Client
Definition: SharkSSL.h:295
@ SharkSsl_Server
Definition: SharkSSL.h:294
@ SHARKSSL_ECDSA_ALLOCATION_ERROR
ALLOCATION_ERROR.
Definition: SharkSSL.h:2388
@ SHARKSSL_ECDSA_WRONG_KEY_FORMAT
WRONG_KEY_FORMAT.
Definition: SharkSSL.h:2397
@ SHARKSSL_ECDSA_WRONG_SIGNATURE
WRONG SIGNATURE.
Definition: SharkSSL.h:2412
@ SHARKSSL_ECDSA_WRONG_PARAMETERS
WRONG_PARAMETERS.
Definition: SharkSSL.h:2394
@ SHARKSSL_ECDSA_OK
OK.
Definition: SharkSSL.h:2385
@ SHARKSSL_ECDSA_VERIFICATION_FAIL
VERIFICATION_FAIL.
Definition: SharkSSL.h:2409
@ SHARKSSL_ECDSA_INTERNAL_ERROR
INTERNAL_ERROR.
Definition: SharkSSL.h:2391
@ SHARKSSL_ECDSA_KEY_NOT_PRIVATE
KEY_IS_NOT_PRIVATE.
Definition: SharkSSL.h:2400
@ SHARKSSL_ECDSA_KEY_NOT_PUBLIC
KEY_IS_NOT_PUBLIC.
Definition: SharkSSL.h:2403
@ SHARKSSL_ECDSA_SIGLEN_TOO_SMALL
SIGLEN_TOO_SMALL.
Definition: SharkSSL.h:2406
@ SHARKSSL_RSA_INPUT_DATA_LENGTH_TOO_BIG
INPUT_DATA_LENGTH_TOO_BIG.
Definition: SharkSSL.h:1878
@ SHARKSSL_RSA_OK
OK.
Definition: SharkSSL.h:1860
@ SHARKSSL_RSA_INTERNAL_ERROR
INTERNAL_ERROR.
Definition: SharkSSL.h:1866
@ SHARKSSL_RSA_WRONG_PARAMETERS
WRONG_PARAMETERS.
Definition: SharkSSL.h:1869
@ SHARKSSL_RSA_ALLOCATION_ERROR
ALLOCATION_ERROR.
Definition: SharkSSL.h:1863
@ SHARKSSL_RSA_WRONG_KEY_FORMAT
WRONG_KEY_FORMAT.
Definition: SharkSSL.h:1872
@ SHARKSSL_RSA_PKCS1_PADDING_ERROR
PKCS1_PADDING_ERROR.
Definition: SharkSSL.h:1884
@ SHARKSSL_RSA_INPUT_DATA_LENGTH_AND_KEY_LENGTH_MISMATCH
INPUT_DATA_LENGTH_AND_KEY_LENGTH_MISMATCH.
Definition: SharkSSL.h:1881
@ SHARKSSL_RSA_WRONG_KEY_LENGTH
WRONG_KEY_LENGTH.
Definition: SharkSSL.h:1875
SHARKSSL_API SharkSslSession * SharkSslCon_acquireSession(SharkSslCon *o)
Request a SharkSslSession object from the client's session pool.
SHARKSSL_API U8 SharkSslCon_releaseSession(SharkSslCon *o)
experimental
struct SharkSslSession SharkSslSession
SharkSslSession is an opaque handle returned by function SharkSslCon_acquireSession.
Definition: SharkSSL.h:265
SHARKSSL_API U8 SharkSslCon_resumeSession(SharkSslCon *o, SharkSslSession *s)
Resume an existing session.
SHARKSSL_API U8 SharkSslCon_isResumed(SharkSslCon *o)
Returns 1 if the current session is a resumed one.
SHARKSSL_API U32 SharkSslSession_getLatestAccessTime(SharkSslSession *o)
Returns the last time the session was accessed.
SHARKSSL_API U8 SharkSslSession_release(SharkSslSession *o, SharkSsl *s)
Release a session created by function SharkSslCon_acquireSession.
Opaque object used when creating ASN.1 encoded data.
Definition: SharkSslASN1.h:228
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/nss_tech_notes/nss_tech_note3 http://to...
Definition: SharkSslASN1.h:239
Certificate KeyUsage and ExtendedKeyUsage flags and relative pseudofunctions.
Definition: SharkSSL.h:776
U8 unitLen
length in bytes of the field "organization"
Definition: SharkSSL.h:792
U8 provinceLen
length in bytes of the field "country"
Definition: SharkSSL.h:789
const U8 * province
State or Province.
Definition: SharkSSL.h:778
U8 localityLen
length in bytes of the field "province"
Definition: SharkSSL.h:790
const U8 * unit
Organizational Unit (OU: department or organization unit)
Definition: SharkSSL.h:781
const U8 * organization
Organization Name (company or department)
Definition: SharkSSL.h:780
const U8 * commonName
Common Name is the Host + Domain Name (example: www.mycompany.com, where www is host and mycompany....
Definition: SharkSSL.h:785
const U8 * countryName
ISO3166 country code.
Definition: SharkSSL.h:777
U8 organizationLen
length in bytes of the field "locality"
Definition: SharkSSL.h:791
U8 commonNameLen
length in bytes of the field "unit"
Definition: SharkSSL.h:793
const U8 * locality
The city or town name.
Definition: SharkSSL.h:779
U8 emailAddressLen
length in bytes of the field "common name"
Definition: SharkSSL.h:794
The peer's certificate information returned by SharkSslCon_getCertInfo.
Definition: SharkSSL.h:834
U8 timeFromLen
Length of 'timeFrom'.
Definition: SharkSSL.h:890
U8 timeToLen
Length of 'timeTo'.
Definition: SharkSSL.h:893
U16 snLen
Length of 'sn' (serial number)
Definition: SharkSSL.h:836
U8 * timeTo
Certificate expiration date (in Time format: [YY]YYMMDDHHMMSSZ) UTCTime: 2-digit year; GeneralizedTim...
Definition: SharkSSL.h:861
U8 CAflag
The Certificate Authority flag (CA) is set to one if the certificate is a CA i.e.
Definition: SharkSSL.h:846
SharkSslCertDN issuer
The entity who has signed and issued the certificate (RFC 2459 4.1.2.4)
Definition: SharkSSL.h:867
SharkSslCertDN subject
The entity associated with the public key (RFC 2459 4.1.2.6).
Definition: SharkSSL.h:873
U8 * sn
Binary serial number.
Definition: SharkSSL.h:850
U8 * timeFrom
Certificate is valid from date (in Time format: [YY]YYMMDDHHMMSSZ) UTCTime: 2-digit year; Generalized...
Definition: SharkSSL.h:855
U8 * subjectAltNamesPtr
Subject Alternative Names subjectAltNamesPtr is a pointer to an ASN1 sequence, whose length is subjec...
Definition: SharkSSL.h:886
struct SharkSslCertInfo * parent
Pointer to parent node when the SharkSslCertInfo object is part of a certificate chain.
Definition: SharkSSL.h:924
U8 version
Certificate version is offset at 0 so add +1 for actual version number.
Definition: SharkSSL.h:841
SharkSslCertStore is a container object used when assembling a SharkSslCAList.
Definition: SharkSSL.h:2520
A SharkSsl object is the coordinator for managing SharkSslCon objects (See SharkSsl_constructor for d...
Definition: SharkSSL.h:561