TrustCore SDK NanoSSL API reference  version 7.0
dtls.h
Go to the documentation of this file.
1 /*
2  * dtls.h
3  *
4  * DTLS Developer API
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
41 #ifndef __DTLS_H__
42 #define __DTLS_H__
43 
44 #if defined(__ENABLE_MOCANA_DTLS_SERVER__) || defined(__ENABLE_MOCANA_DTLS_CLIENT__)
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /*------------------------------------------------------------------*/
51 
52 #ifndef DTLS_MAX_MUTEX
53 #define DTLS_MAX_MUTEX (10)
54 #endif
55 
56 #ifndef TIMEOUT_DTLS_HELLO_VERIFY_COOKIE
57 #define TIMEOUT_DTLS_HELLO_VERIFY_COOKIE (10000) /* 10 seconds */
58 #endif
59 
60 struct certStore;
61 
62 /* common */
89 MOC_EXTERN struct sslSettings* DTLS_dtlsSettings(void);
90 
127 MOC_EXTERN sbyte4 DTLS_shutdown(void);
128 
165 MOC_EXTERN sbyte4 DTLS_releaseTables(void);
166 
199 MOC_EXTERN sbyte4 DTLS_getCookie(sbyte4 connectionInstance, void** pCookie);
200 
238 MOC_EXTERN sbyte4 DTLS_setCookie(sbyte4 connectionInstance, void* cookie);
239 
270 MOC_EXTERN sbyte4 DTLS_getPeerDescr(sbyte4 connectionInstance, const peerDescr **ppRetPeerDescr);
271 
309 MOC_EXTERN sbyte4 DTLS_isSessionDTLS(sbyte4 connectionInstance);
310 
346 MOC_EXTERN sbyte4 DTLS_getSessionFlags(sbyte4 connectionInstance, ubyte4 *pRetFlagsSSL);
347 
380 MOC_EXTERN sbyte4 DTLS_getSessionStatus(sbyte4 connectionInstance, ubyte4 *pRetStatusSSL);
381 
432 MOC_EXTERN sbyte4 DTLS_setSessionFlags(sbyte4 connectionInstance, ubyte4 flagsSSL);
469 MOC_EXTERN sbyte4 DTLS_ioctl(sbyte4 connectionInstance, ubyte4 setting, void *value);
470 
507 MOC_EXTERN sbyte4 DTLS_lookupAlert(sbyte4 connectionInstance, sbyte4 lookupError, sbyte4 *pRetAlertId, sbyte4 *pAlertClass);
508 
543 MOC_EXTERN sbyte4 DTLS_sendAlert(sbyte4 connectionInstance, sbyte4 alertId, sbyte4 alertClass);
544 
593 MOC_EXTERN sbyte4 DTLS_enableCiphers(sbyte4 connectionInstance, ubyte2 *pCipherSuiteList, ubyte4 listLength);
594 
595 #if (defined( __ENABLE_MOCANA_SSL_ECDH_SUPPORT__) || \
596  defined(__ENABLE_MOCANA_SSL_ECDHE_SUPPORT__)|| \
597  defined(__ENABLE_MOCANA_SSL_ECDH_ANON_SUPPORT__) )
598 
641 MOC_EXTERN sbyte4 DTLS_enableECCCurves(sbyte4 connectionInstance,
642  enum tlsExtNamedCurves* pECCCurvesList,
643  ubyte4 listLength);
644 #endif
645 
680 MOC_EXTERN sbyte4 DTLS_getCipherInfo( sbyte4 connectionInstance, ubyte2* pCipherId, ubyte4* pPeerEcCurves);
681 
722 MOC_EXTERN sbyte4 DTLS_initiateRehandshake(sbyte4 connectionInstance);
723 
755 MOC_EXTERN sbyte4 DTLS_checkHandshakeTimer(sbyte4 connectionInstance);
756 
757 #if (defined (__ENABLE_MOCANA_DTLS_SRTP__) && defined (__ENABLE_MOCANA_SRTP_PROFILES_SELECT__))
758 
797 MOC_EXTERN sbyte4 DTLS_enableSrtpProfiles(sbyte4 connectionInstance, ubyte2 *pSrtpProfileList, ubyte4 listLength);
798 #endif
799 
800 #if defined(__ENABLE_MOCANA_DTLS_CLIENT__)
801 
802 /* ywang NOTE: temporarily use hard code number to pass compile time */
803 
837 MOC_EXTERN sbyte4 DTLS_getClientSessionInfo(sbyte4 connectionInstance, ubyte* sessionIdLen, ubyte sessionId[32], ubyte masterSecret[48]);
838 
871 MOC_EXTERN sbyte4 DTLS_setServerNameIndication(sbyte4 connectionInstance,
872  const char* serverName);
873 
874 #if defined(__ENABLE_MOCANA_MULTIPLE_COMMON_NAMES__)
875 
910 MOC_EXTERN sbyte4 DTLS_setDNSNames( sbyte4 connectionInstance, const CNMatchInfo* cnMatchInfo);
911 #endif
912 #endif
913 
951 MOC_EXTERN sbyte4 DTLS_init(sbyte4 numServerConnections, sbyte4 numClientConnections);
952 
953 #if defined(__ENABLE_MOCANA_SSL_CUSTOM_RNG__)
954 
997 MOC_EXTERN sbyte4 DTLS_initEx(sbyte4 numServerConnections, sbyte4 numClientConnections,
998  RNGFun rngFun, void* arg);
999 #endif
1000 
1043 MOC_EXTERN sbyte4 DTLS_recvMessage(sbyte4 connectionInstance, ubyte *pBytesReceived, ubyte4 numBytesReceived,
1044  ubyte **ppRetBytesReceived, ubyte4 *pRetNumRxBytesRemaining);
1045 
1095 MOC_EXTERN sbyte4 DTLS_sendMessage(sbyte4 connectionInstance, sbyte *pBuffer, sbyte4 bufferSize, sbyte4 *pBytesSent);
1096 
1130 MOC_EXTERN sbyte4 DTLS_closeConnection(sbyte4 connectionInstance);
1131 
1164 MOC_EXTERN sbyte4 DTLS_getSendBuffer(sbyte4 connectionInstance, ubyte *data, ubyte4 *len);
1165 
1202 MOC_EXTERN sbyte4 DTLS_getRecvBuffer(sbyte4 connectionInstance, ubyte **data, ubyte4 *len, ubyte4 *pRetProtocol);
1203 
1204 #if defined(__ENABLE_MOCANA_TLS13__)
1205 
1206 #if defined(__ENABLE_MOCANA_SSL_MUTUAL_AUTH_SUPPORT__) && defined(__ENABLE_MOCANA_DTLS_SERVER__)
1207 
1235 MOC_EXTERN MSTATUS DTLS_sendPosthandshakeAuthCertificateRequest(sbyte4 connectionInstance);
1236 #endif
1237 
1267 MOC_EXTERN MSTATUS DTLS_sendKeyUpdateRequest(sbyte4 connectionInstance, ubyte updateRequest);
1268 
1269 #if (defined(__ENABLE_MOCANA_TLS13_PSK__) && defined(__ENABLE_MOCANA_TLS13_0RTT__))
1270 
1303 MOC_EXTERN sbyte4 DTLS_setRecvEarlyDataSize(sbyte4 connectionInstance,
1304  sbyte4 recvEarlyDataSize);
1305 
1336 MOC_EXTERN sbyte4 DTLS_setMaxEarlyDataSize(sbyte4 connectionInstance,
1337  sbyte4 earlyDataSize);
1338 
1370 MOC_EXTERN sbyte4 DTLS_setEarlyData(sbyte4 connectionInstance,
1371  ubyte* pEarlyData, ubyte4 earlyDataSize);
1372 
1405 MOC_EXTERN sbyte4
1406 DTLS_setReceiveApplicationDataCallback(sbyte4 (*funcPtrTLS13ApplicationDataCallback)(sbyte4 connectionInstance,
1407  ubyte *pData, ubyte4 dataLen,
1408  dataState state));
1409 #endif
1410 #endif /* __ENABLE_MOCANA_TLS13__ */
1411 
1412 /* client */
1413 #ifdef __ENABLE_MOCANA_DTLS_CLIENT__
1414 
1451 MOC_EXTERN sbyte4 DTLS_connect(peerDescr *pPeerDescr, ubyte sessionIdLen, ubyte * sessionId, ubyte * masterSecret,
1452  const sbyte* dnsName, struct certStore* pCertStore);
1453 
1482 MOC_EXTERN sbyte4 DTLS_start(sbyte4 connectionInstance);
1483 #endif
1484 
1485 #if defined(__ENABLE_MOCANA_DTLS_SERVER__)
1486 
1517 MOC_EXTERN sbyte4 DTLS_acceptConnection(peerDescr *pPeerDescr,
1518  struct certStore* pCertStore);
1519 
1552 MOC_EXTERN sbyte4 DTLS_getConnectionInstance(MOC_IP_ADDRESS srcAddr, ubyte2 srcPort, MOC_IP_ADDRESS peerAddr, ubyte2 peerPort);
1553 
1595 MOC_EXTERN sbyte4 DTLS_getNextConnectionInstance(ubyte4 *pCookie, sbyte4 *pConnectionInstance, const peerDescr **ppRetPeerDescr);
1596 
1639 MOC_EXTERN sbyte4 DTLS_verifyClientHelloCookie(MOC_IP_ADDRESS peerAddr, ubyte *pReceived, ubyte4 length, ubyte *pToSend, ubyte4 *pToSendLen);
1640 #endif
1641 #ifdef __cplusplus
1642 }
1643 #endif
1644 
1645 #endif /* defined(__ENABLE_MOCANA_DTLS_SERVER__) || defined(__ENABLE_MOCANA_DTLS_CLIENT__) */
1646 #endif /* __DTLS_H__ */
tlsExtNamedCurves
Definition: ssl.h:506
MOC_EXTERN sbyte4 DTLS_sendMessage(sbyte4 connectionInstance, sbyte *pBuffer, sbyte4 bufferSize, sbyte4 *pBytesSent)
Send data to a connected server/client.
MOC_EXTERN sbyte4 DTLS_ioctl(sbyte4 connectionInstance, ubyte4 setting, void *value)
Enable dynamic management of a connection's features.
MOC_EXTERN sbyte4 DTLS_setCookie(sbyte4 connectionInstance, void *cookie)
Store custom information for a connection instance.
MOC_EXTERN sbyte4 DTLS_init(sbyte4 numServerConnections, sbyte4 numClientConnections)
Initialize NanoDTLS client or server internal structures.
MOC_EXTERN sbyte4 DTLS_enableSrtpProfiles(sbyte4 connectionInstance, ubyte2 *pSrtpProfileList, ubyte4 listLength)
Enable specified SRTP profiles.
MOC_EXTERN MSTATUS DTLS_sendKeyUpdateRequest(sbyte4 connectionInstance, ubyte updateRequest)
Sends a key update request.
MOC_EXTERN sbyte4 DTLS_setDNSNames(sbyte4 connectionInstance, const CNMatchInfo *cnMatchInfo)
Specify a list of DNS names acceptable to the client.
MOC_EXTERN sbyte4 DTLS_enableECCCurves(sbyte4 connectionInstance, enum tlsExtNamedCurves *pECCCurvesList, ubyte4 listLength)
Enable ECC curves.
Configuration settings and callback function pointers for NanoSSL SSL/TLS clients and NanoDTLS DTLS c...
Definition: ssl.h:810
MOC_EXTERN sbyte4 DTLS_connect(peerDescr *pPeerDescr, ubyte sessionIdLen, ubyte *sessionId, ubyte *masterSecret, const sbyte *dnsName, struct certStore *pCertStore)
Create a NanoDTLS client connection descriptor.
MOC_EXTERN sbyte4 DTLS_getSessionStatus(sbyte4 connectionInstance, ubyte4 *pRetStatusSSL)
Get a connection's status.
MOC_EXTERN sbyte4 DTLS_sendAlert(sbyte4 connectionInstance, sbyte4 alertId, sbyte4 alertClass)
Send an SSL alert message to a DTLS peer.
MOC_EXTERN sbyte4 DTLS_recvMessage(sbyte4 connectionInstance, ubyte *pBytesReceived, ubyte4 numBytesReceived, ubyte **ppRetBytesReceived, ubyte4 *pRetNumRxBytesRemaining)
Get a pointer to the connection's most recently receiveed message.
MOC_EXTERN sbyte4 DTLS_initiateRehandshake(sbyte4 connectionInstance)
Renegotiate a NanoDTLS session.
MOC_EXTERN sbyte4 DTLS_getCookie(sbyte4 connectionInstance, void **pCookie)
Get custom information for a connection instance.
MOC_EXTERN sbyte4 DTLS_getCipherInfo(sbyte4 connectionInstance, ubyte2 *pCipherId, ubyte4 *pPeerEcCurves)
Get a connection's ciphers and ecCurves.
MOC_EXTERN sbyte4 DTLS_enableCiphers(sbyte4 connectionInstance, ubyte2 *pCipherSuiteList, ubyte4 listLength)
Enable specified ciphers.
MOC_EXTERN sbyte4 DTLS_setSessionFlags(sbyte4 connectionInstance, ubyte4 flagsSSL)
Store a connection's context (its flags).
MOC_EXTERN sbyte4 DTLS_setRecvEarlyDataSize(sbyte4 connectionInstance, sbyte4 recvEarlyDataSize)
Set the recv early data size.
MOC_EXTERN sbyte4 DTLS_shutdown(void)
Clean up memory and mutexes and shut down the NanoDTLS stack.
MOC_EXTERN MSTATUS DTLS_sendPosthandshakeAuthCertificateRequest(sbyte4 connectionInstance)
Sends a post-handshake authentication request to client.
MOC_EXTERN sbyte4 DTLS_getSessionFlags(sbyte4 connectionInstance, ubyte4 *pRetFlagsSSL)
Get a connection's context (its flags).
MOC_EXTERN sbyte4 DTLS_getClientSessionInfo(sbyte4 connectionInstance, ubyte *sessionIdLen, ubyte sessionId[32], ubyte masterSecret[48])
Get connection instance's identifying information.
MOC_EXTERN sbyte4 DTLS_verifyClientHelloCookie(MOC_IP_ADDRESS peerAddr, ubyte *pReceived, ubyte4 length, ubyte *pToSend, ubyte4 *pToSendLen)
Verify a client's legitimacy by using the provided cookie.
MOC_EXTERN sbyte4 DTLS_getSendBuffer(sbyte4 connectionInstance, ubyte *data, ubyte4 *len)
Get a copy of the connection's send data buffer.
MOC_EXTERN sbyte4 DTLS_isSessionDTLS(sbyte4 connectionInstance)
Determine whether a connection instance represents a DTLS server, a DTLS client, or an unrecognized c...
MOC_EXTERN sbyte4 DTLS_lookupAlert(sbyte4 connectionInstance, sbyte4 lookupError, sbyte4 *pRetAlertId, sbyte4 *pAlertClass)
Get the SSL alert code for a Digicert SoT Platform error.
MOC_EXTERN sbyte4 DTLS_getRecvBuffer(sbyte4 connectionInstance, ubyte **data, ubyte4 *len, ubyte4 *pRetProtocol)
Get a pointer to the connection's receive data buffer (the socket buffer itself). ...
MOC_EXTERN sbyte4 DTLS_closeConnection(sbyte4 connectionInstance)
Close a NanoDTLS session and release resources.
MOC_EXTERN sbyte4 DTLS_acceptConnection(peerDescr *pPeerDescr, struct certStore *pCertStore)
Register a secure NanoDTLS connection.
MOC_EXTERN sbyte4 DTLS_getPeerDescr(sbyte4 connectionInstance, const peerDescr **ppRetPeerDescr)
Get a NanoDTLS connection descriptor.
MOC_EXTERN sbyte4 DTLS_setServerNameIndication(sbyte4 connectionInstance, const char *serverName)
Specify the server name required by the client.
MOC_EXTERN sbyte4 DTLS_setReceiveApplicationDataCallback(sbyte4(*funcPtrTLS13ApplicationDataCallback)(sbyte4 connectionInstance, ubyte *pData, ubyte4 dataLen, dataState state))
Function to set the callback to pass data to the application received during the SSL handshake...
MOC_EXTERN sbyte4 DTLS_checkHandshakeTimer(sbyte4 connectionInstance)
Check a NanoDTLS client's or server's timer to provide time to the NanoDTLS stack.
MOC_EXTERN sbyte4 DTLS_initEx(sbyte4 numServerConnections, sbyte4 numClientConnections, RNGFun rngFun, void *arg)
Initialize NanoDTLS client or server internal structures with custom RNG.
MOC_EXTERN sbyte4 DTLS_getConnectionInstance(MOC_IP_ADDRESS srcAddr, ubyte2 srcPort, MOC_IP_ADDRESS peerAddr, ubyte2 peerPort)
Get a DTLS connection instance for the specified src-dst connection.
MOC_EXTERN sbyte4 DTLS_setEarlyData(sbyte4 connectionInstance, ubyte *pEarlyData, ubyte4 earlyDataSize)
Set the max early data.
Definition: ssl.h:729
MOC_EXTERN sbyte4 DTLS_releaseTables(void)
Release memory used by internal NanoDTLS memory tables.
MOC_EXTERN sbyte4 DTLS_start(sbyte4 connectionInstance)
Start establishing a secure client-server connection.
MOC_EXTERN sbyte4 DTLS_getNextConnectionInstance(ubyte4 *pCookie, sbyte4 *pConnectionInstance, const peerDescr **ppRetPeerDescr)
Get a server's next open client connection instance.
MOC_EXTERN sbyte4 DTLS_setMaxEarlyDataSize(sbyte4 connectionInstance, sbyte4 earlyDataSize)
Set the max early data size.
MOC_EXTERN struct sslSettings * DTLS_dtlsSettings(void)
Get a pointer to current context's configuration settings.