CoAP Secure
This module includes functions that control CoAP Secure (CoAP over DTLS) communication.
Summary
The functions in this module are available when CoAP Secure API feature (OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
) is enabled.
Enumerations |
|
---|---|
otCoapSecureConnectEvent{
|
enum CoAP secure connection event types. |
Typedefs |
|
---|---|
otCoapSecureAutoStopCallback)(void *aContext)
|
typedefvoid(*
Callback function pointer to notify when the CoAP secure agent is automatically stopped due to reaching the maximum number of connection attempts. |
otCoapSecureConnectEvent
|
typedef CoAP secure connection event types. |
otHandleCoapSecureClientConnect)(otCoapSecureConnectEvent aEvent, void *aContext)
|
typedefvoid(*
Pointer is called when the DTLS connection state changes. |
Functions |
|
---|---|
otCoapSecureAddBlockWiseResource(otInstance *aInstance, otCoapBlockwiseResource *aResource)
|
void
Adds a block-wise resource to the CoAP Secure server.
|
otCoapSecureAddResource(otInstance *aInstance, otCoapResource *aResource)
|
void
Adds a resource to the CoAP Secure server.
|
otCoapSecureConnect(otInstance *aInstance, const otSockAddr *aSockAddr, otHandleCoapSecureClientConnect aHandler, void *aContext)
|
Initializes DTLS session with a peer.
|
otCoapSecureDisconnect(otInstance *aInstance)
|
void
Stops the DTLS connection.
|
otCoapSecureGetPeerCertificateBase64(otInstance *aInstance, unsigned char *aPeerCert, size_t *aCertLength, size_t aCertBufferSize)
|
Returns the peer x509 certificate base64 encoded.
|
otCoapSecureIsClosed(otInstance *aInstance)
|
bool
Indicates whether or not the DTLS session is closed.
|
otCoapSecureIsConnected(otInstance *aInstance)
|
bool
Indicates whether or not the DTLS session is connected.
|
otCoapSecureIsConnectionActive(otInstance *aInstance)
|
bool
Indicates whether or not the DTLS session is active.
|
otCoapSecureRemoveBlockWiseResource(otInstance *aInstance, otCoapBlockwiseResource *aResource)
|
void
Removes a block-wise resource from the CoAP Secure server.
|
otCoapSecureRemoveResource(otInstance *aInstance, otCoapResource *aResource)
|
void
Removes a resource from the CoAP Secure server.
|
otCoapSecureSendRequest(otInstance *aInstance, otMessage *aMessage, otCoapResponseHandler aHandler, void *aContext)
|
Sends a CoAP request over secure DTLS connection.
|
otCoapSecureSendRequestBlockWise(otInstance *aInstance, otMessage *aMessage, otCoapResponseHandler aHandler, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook, otCoapBlockwiseReceiveHook aReceiveHook)
|
Sends a CoAP request block-wise over secure DTLS connection.
|
otCoapSecureSendResponse(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo)
|
Sends a CoAP response from the CoAP Secure server.
|
otCoapSecureSendResponseBlockWise(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook)
|
Sends a CoAP response block-wise from the CoAP Secure server.
|
otCoapSecureSetCaCertificateChain(otInstance *aInstance, const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength)
|
void
Sets the trusted top level CAs.
|
otCoapSecureSetCertificate(otInstance *aInstance, const uint8_t *aX509Cert, uint32_t aX509Length, const uint8_t *aPrivateKey, uint32_t aPrivateKeyLength)
|
void
Sets the local device's X509 certificate with corresponding private key for DTLS session with DTLS_ECDHE_ECDSA_WITH_AES_128_CCM_8.
|
otCoapSecureSetClientConnectEventCallback(otInstance *aInstance, otHandleCoapSecureClientConnect aHandler, void *aContext)
|
void
Sets the connect event callback to indicate when a Client connection to the CoAP Secure server has changed.
|
otCoapSecureSetDefaultHandler(otInstance *aInstance, otCoapRequestHandler aHandler, void *aContext)
|
void
Sets the default handler for unhandled CoAP Secure requests.
|
otCoapSecureSetPsk(otInstance *aInstance, const uint8_t *aPsk, uint16_t aPskLength, const uint8_t *aPskIdentity, uint16_t aPskIdLength)
|
void
Sets the Pre-Shared Key (PSK) and cipher suite DTLS_PSK_WITH_AES_128_CCM_8.
|
otCoapSecureSetSslAuthMode(otInstance *aInstance, bool aVerifyPeerCertificate)
|
void
Sets the authentication mode for the coap secure connection.
|
otCoapSecureStart(otInstance *aInstance, uint16_t aPort)
|
Starts the CoAP Secure service.
|
otCoapSecureStartWithMaxConnAttempts(otInstance *aInstance, uint16_t aPort, uint16_t aMaxAttempts, otCoapSecureAutoStopCallback aCallback, void *aContext)
|
Starts the CoAP secure service and sets the maximum number of allowed connection attempts before stopping the agent automatically.
|
otCoapSecureStop(otInstance *aInstance)
|
void
Stops the CoAP Secure server.
|
Macros |
|
---|---|
OT_DEFAULT_COAP_SECURE_PORT 5684
|
Default CoAP Secure port, as specified in RFC 7252.
|
Enumerations
otCoapSecureConnectEvent
otCoapSecureConnectEvent
CoAP secure connection event types.
Typedefs
otCoapSecureAutoStopCallback
void(* otCoapSecureAutoStopCallback)(void *aContext)
Callback function pointer to notify when the CoAP secure agent is automatically stopped due to reaching the maximum number of connection attempts.
Details | |||
---|---|---|---|
Parameters |
|
otCoapSecureConnectEvent
enum otCoapSecureConnectEvent otCoapSecureConnectEvent
CoAP secure connection event types.
otHandleCoapSecureClientConnect
void(* otHandleCoapSecureClientConnect)(otCoapSecureConnectEvent aEvent, void *aContext)
Pointer is called when the DTLS connection state changes.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
Functions
otCoapSecureAddBlockWiseResource
void otCoapSecureAddBlockWiseResource( otInstance *aInstance, otCoapBlockwiseResource *aResource )
Adds a block-wise resource to the CoAP Secure server.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
otCoapSecureAddResource
void otCoapSecureAddResource( otInstance *aInstance, otCoapResource *aResource )
Adds a resource to the CoAP Secure server.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
otCoapSecureConnect
otError otCoapSecureConnect( otInstance *aInstance, const otSockAddr *aSockAddr, otHandleCoapSecureClientConnect aHandler, void *aContext )
Initializes DTLS session with a peer.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otCoapSecureDisconnect
void otCoapSecureDisconnect( otInstance *aInstance )
Stops the DTLS connection.
Details | |||
---|---|---|---|
Parameters |
|
otCoapSecureGetPeerCertificateBase64
otError otCoapSecureGetPeerCertificateBase64( otInstance *aInstance, unsigned char *aPeerCert, size_t *aCertLength, size_t aCertBufferSize )
Returns the peer x509 certificate base64 encoded.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otCoapSecureIsClosed
bool otCoapSecureIsClosed( otInstance *aInstance )
Indicates whether or not the DTLS session is closed.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
otCoapSecureIsConnected
bool otCoapSecureIsConnected( otInstance *aInstance )
Indicates whether or not the DTLS session is connected.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
otCoapSecureIsConnectionActive
bool otCoapSecureIsConnectionActive( otInstance *aInstance )
Indicates whether or not the DTLS session is active.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
otCoapSecureRemoveBlockWiseResource
void otCoapSecureRemoveBlockWiseResource( otInstance *aInstance, otCoapBlockwiseResource *aResource )
Removes a block-wise resource from the CoAP Secure server.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
otCoapSecureRemoveResource
void otCoapSecureRemoveResource( otInstance *aInstance, otCoapResource *aResource )
Removes a resource from the CoAP Secure server.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
otCoapSecureSendRequest
otError otCoapSecureSendRequest( otInstance *aInstance, otMessage *aMessage, otCoapResponseHandler aHandler, void *aContext )
Sends a CoAP request over secure DTLS connection.
If a response for a request is expected, respective function and context information should be provided. If no response is expected, these arguments should be NULL pointers. If Message Id was not set in the header (equal to 0), this function will assign unique Message Id to the message.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
otCoapSecureSendRequestBlockWise
otError otCoapSecureSendRequestBlockWise( otInstance *aInstance, otMessage *aMessage, otCoapResponseHandler aHandler, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook, otCoapBlockwiseReceiveHook aReceiveHook )
Sends a CoAP request block-wise over secure DTLS connection.
Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.
If a response for a request is expected, respective function and context information should be provided. If no response is expected, these arguments should be NULL pointers. If Message Id was not set in the header (equal to 0), this function will assign unique Message Id to the message.
Details | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||||
Return Values |
|
otCoapSecureSendResponse
otError otCoapSecureSendResponse( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo )
Sends a CoAP response from the CoAP Secure server.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
otCoapSecureSendResponseBlockWise
otError otCoapSecureSendResponseBlockWise( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook )
Sends a CoAP response block-wise from the CoAP Secure server.
Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
otCoapSecureSetCaCertificateChain
void otCoapSecureSetCaCertificateChain( otInstance *aInstance, const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength )
Sets the trusted top level CAs.
It is needed for validating the certificate of the peer.
DTLS mode "ECDHE ECDSA with AES 128 CCM 8" for Application CoAPS.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
otCoapSecureSetCertificate
void otCoapSecureSetCertificate( otInstance *aInstance, const uint8_t *aX509Cert, uint32_t aX509Length, const uint8_t *aPrivateKey, uint32_t aPrivateKeyLength )
Sets the local device's X509 certificate with corresponding private key for DTLS session with DTLS_ECDHE_ECDSA_WITH_AES_128_CCM_8.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
otCoapSecureSetClientConnectEventCallback
void otCoapSecureSetClientConnectEventCallback( otInstance *aInstance, otHandleCoapSecureClientConnect aHandler, void *aContext )
Sets the connect event callback to indicate when a Client connection to the CoAP Secure server has changed.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
otCoapSecureSetDefaultHandler
void otCoapSecureSetDefaultHandler( otInstance *aInstance, otCoapRequestHandler aHandler, void *aContext )
Sets the default handler for unhandled CoAP Secure requests.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
otCoapSecureSetPsk
void otCoapSecureSetPsk( otInstance *aInstance, const uint8_t *aPsk, uint16_t aPskLength, const uint8_t *aPskIdentity, uint16_t aPskIdLength )
Sets the Pre-Shared Key (PSK) and cipher suite DTLS_PSK_WITH_AES_128_CCM_8.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
otCoapSecureSetSslAuthMode
void otCoapSecureSetSslAuthMode( otInstance *aInstance, bool aVerifyPeerCertificate )
Sets the authentication mode for the coap secure connection.
Disable or enable the verification of peer certificate. Must be called before start.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
otCoapSecureStart
otError otCoapSecureStart( otInstance *aInstance, uint16_t aPort )
Starts the CoAP Secure service.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
otCoapSecureStartWithMaxConnAttempts
otError otCoapSecureStartWithMaxConnAttempts( otInstance *aInstance, uint16_t aPort, uint16_t aMaxAttempts, otCoapSecureAutoStopCallback aCallback, void *aContext )
Starts the CoAP secure service and sets the maximum number of allowed connection attempts before stopping the agent automatically.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
otCoapSecureStop
void otCoapSecureStop( otInstance *aInstance )
Stops the CoAP Secure server.
Details | |||
---|---|---|---|
Parameters |
|
Macros
OT_DEFAULT_COAP_SECURE_PORT
OT_DEFAULT_COAP_SECURE_PORT 5684
Default CoAP Secure port, as specified in RFC 7252.
Resources
OpenThread API Reference topics originate from the source code, available on GitHub. For more information, or to contribute to our documentation, refer to Resources.