CoAP 保護
這個模組包含控管 CoAP Secure (CoAP over DTLS) 通訊的功能。
摘要
啟用 CoAP Secure API 功能 (OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
) 時,即可使用本單元中的函式。
類型 |
|
---|---|
otHandleCoapSecureClientConnect)(bool aConnected, void *aContext)
|
typedefvoid(*
當 DTLS 連線狀態變更時,會呼叫此函式指標。 |
函式 |
|
---|---|
otCoapSecureAddBlockWiseResource(otInstance *aInstance, otCoapBlockwiseResource *aResource)
|
void
這項函式會將封鎖區塊資源新增至 CoAP Secure 伺服器。
|
otCoapSecureAddResource(otInstance *aInstance, otCoapResource *aResource)
|
void
這項函式會將資源新增至 CoAP Secure 伺服器。
|
otCoapSecureConnect(otInstance *aInstance, const otSockAddr *aSockAddr, otHandleCoapSecureClientConnect aHandler, void *aContext)
|
這個方法會透過對等點初始化 DTLS 工作階段。
|
otCoapSecureDisconnect(otInstance *aInstance)
|
void
這個方法會停止 DTLS 連線。
|
otCoapSecureGetPeerCertificateBase64(otInstance *aInstance, unsigned char *aPeerCert, size_t *aCertLength, size_t aCertBufferSize)
|
這個方法會傳回對等的 x509 憑證 Base64 編碼。
|
otCoapSecureIsConnected(otInstance *aInstance)
|
bool
這個方法會指出是否已連結 DTLS 工作階段。
|
otCoapSecureIsConnectionActive(otInstance *aInstance)
|
bool
這個方法會指出 DTLS 工作階段是否在運作。
|
otCoapSecureRemoveBlockWiseResource(otInstance *aInstance, otCoapBlockwiseResource *aResource)
|
void
這項函式會從 CoAP Secure 伺服器移除區塊層級的資源。
|
otCoapSecureRemoveResource(otInstance *aInstance, otCoapResource *aResource)
|
void
這個函式會從 CoAP Secure 伺服器移除資源,
|
otCoapSecureSendRequest(otInstance *aInstance, otMessage *aMessage, otCoapResponseHandler aHandler, void *aContext)
|
這種方法會透過安全的 DTLS 連線傳送 CoAP 要求。
|
otCoapSecureSendRequestBlockWise(otInstance *aInstance, otMessage *aMessage, otCoapResponseHandler aHandler, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook, otCoapBlockwiseReceiveHook aReceiveHook)
|
這個方法會透過安全的 DTLS 連線,以區塊化的方式傳送 CoAP 要求。
|
otCoapSecureSendResponse(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo)
|
這項函式會從 CoAP Secure 伺服器傳送 CoAP 回應。
|
otCoapSecureSendResponseBlockWise(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook)
|
這項函式會從 CoAP Secure 伺服器以封鎖的方式傳送 CoAP 回應。
|
otCoapSecureSetCaCertificateChain(otInstance *aInstance, const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength)
|
void
這個方法會設定信任的頂層 CA。
|
otCoapSecureSetCertificate(otInstance *aInstance, const uint8_t *aX509Cert, uint32_t aX509Length, const uint8_t *aPrivateKey, uint32_t aPrivateKeyLength)
|
void
這個方法會使用 DTLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 為本機裝置設定 X509 憑證,並為其加上對應的私密金鑰。
|
otCoapSecureSetClientConnectedCallback(otInstance *aInstance, otHandleCoapSecureClientConnect aHandler, void *aContext)
|
void
這個方法會設定連線回呼,在用戶端連線到 CoAP Secure 伺服器時指出。
|
otCoapSecureSetDefaultHandler(otInstance *aInstance, otCoapRequestHandler aHandler, void *aContext)
|
void
這個函式會處理未處理的 CoAP Secure 要求的預設處理常式。
|
otCoapSecureSetPsk(otInstance *aInstance, const uint8_t *aPsk, uint16_t aPskLength, const uint8_t *aPskIdentity, uint16_t aPskIdLength)
|
void
這個方法會設定預先共用金鑰 (PSK) 和加密套件 DTLS_PSK_WITH_AES_128_CCM_8。
|
otCoapSecureSetSslAuthMode(otInstance *aInstance, bool aVerifyPeerCertificate)
|
void
這個方法可以設定 Coap 安全連線的驗證模式。
|
otCoapSecureStart(otInstance *aInstance, uint16_t aPort)
|
這項功能會啟動 CoAP Secure 服務。
|
otCoapSecureStop(otInstance *aInstance)
|
void
這項函式會停止 CoAP Secure 伺服器。
|
類型
otHandlingCoapSecureClientConnect
void(* otHandleCoapSecureClientConnect)(bool aConnected, void *aContext)
當 DTLS 連線狀態變更時,會呼叫此函式指標。
說明 | |||||
---|---|---|---|---|---|
參數 |
|
函式
otCoapSecureAddBlockWiseResource
void otCoapSecureAddBlockWiseResource( otInstance *aInstance, otCoapBlockwiseResource *aResource )
這項函式會將封鎖區塊資源新增至 CoAP Secure 伺服器。
說明 | |||||
---|---|---|---|---|---|
參數 |
|
otCoapSecureAddResource
void otCoapSecureAddResource( otInstance *aInstance, otCoapResource *aResource )
這項函式會將資源新增至 CoAP Secure 伺服器。
說明 | |||||
---|---|---|---|---|---|
參數 |
|
otCoapSecureConnect
otError otCoapSecureConnect( otInstance *aInstance, const otSockAddr *aSockAddr, otHandleCoapSecureClientConnect aHandler, void *aContext )
這個方法會透過對等點初始化 DTLS 工作階段。
說明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
參數 |
|
||||||||
傳回值 |
|
otCoapSecureConnect
void otCoapSecureDisconnect( otInstance *aInstance )
這個方法會停止 DTLS 連線。
說明 | |||
---|---|---|---|
參數 |
|
otCoapSecureGetPeerCertificateBase64
otError otCoapSecureGetPeerCertificateBase64( otInstance *aInstance, unsigned char *aPeerCert, size_t *aCertLength, size_t aCertBufferSize )
這個方法會傳回對等的 x509 憑證 Base64 編碼。
說明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
參數 |
|
||||||||
傳回值 |
|
otCoapSecureIsConnected
bool otCoapSecureIsConnected( otInstance *aInstance )
這個方法會指出是否已連結 DTLS 工作階段。
說明 | |||||
---|---|---|---|---|---|
參數 |
|
||||
傳回值 |
|
otCoapSecureIsConnectionActive
bool otCoapSecureIsConnectionActive( otInstance *aInstance )
這個方法會指出 DTLS 工作階段是否在運作。
說明 | |||||
---|---|---|---|---|---|
參數 |
|
||||
傳回值 |
|
otCoapSecureRemoveBlockWiseResource
void otCoapSecureRemoveBlockWiseResource( otInstance *aInstance, otCoapBlockwiseResource *aResource )
這項函式會從 CoAP Secure 伺服器移除區塊層級的資源。
說明 | |||||
---|---|---|---|---|---|
參數 |
|
otCoapSecureRemoveResource
void otCoapSecureRemoveResource( otInstance *aInstance, otCoapResource *aResource )
這個函式會從 CoAP Secure 伺服器移除資源,
說明 | |||||
---|---|---|---|---|---|
參數 |
|
otCoapSecureSendRequest
otError otCoapSecureSendRequest( otInstance *aInstance, otMessage *aMessage, otCoapResponseHandler aHandler, void *aContext )
這種方法會透過安全的 DTLS 連線傳送 CoAP 要求。
如果要求是預期的回應,則應提供對應的函式和結構定義資訊。如果預期沒有回應,這些引數應為 NULL 指標。如果標頭中沒有郵件 ID (等於 0),這個函式就會將專屬訊息 ID 指派給郵件。
說明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
參數 |
|
||||||||
傳回值 |
|
otCoapSecureSendRequestBlockWise
otError otCoapSecureSendRequestBlockWise( otInstance *aInstance, otMessage *aMessage, otCoapResponseHandler aHandler, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook, otCoapBlockwiseReceiveHook aReceiveHook )
這個方法會透過安全的 DTLS 連線,以區塊化的方式傳送 CoAP 要求。
啟用 OPENCONVERSATION_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE 設定時可以使用這項功能。
如果要求是預期的回應,則應提供對應的函式和結構定義資訊。如果預期沒有回應,這些引數應為 NULL 指標。如果標頭中沒有郵件 ID (等於 0),這個函式就會將專屬訊息 ID 指派給郵件。
說明 | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
參數 |
|
||||||||||||
傳回值 |
|
otCoapSecureSendResponse
otError otCoapSecureSendResponse( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo )
這項函式會從 CoAP Secure 伺服器傳送 CoAP 回應。
說明 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
||||||
傳回值 |
|
otCoapSecureSendResponseBlockWise
otError otCoapSecureSendResponseBlockWise( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook )
這項函式會從 CoAP Secure 伺服器以封鎖的方式傳送 CoAP 回應。
啟用 OPENCONVERSATION_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE 設定時可以使用這項功能。
說明 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
參數 |
|
||||||||||
傳回值 |
|
otCoapSecureSetCaCertificateChain
void otCoapSecureSetCaCertificateChain( otInstance *aInstance, const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength )
這個方法會設定信任的頂層 CA。
需要驗證對等點的憑證。
DTLS 模式「ECDHE ECDSA 搭配 AES 128 CCM 8」,適用於應用程式 CoAPS。
說明 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
otCoapSecureSetCertificate
void otCoapSecureSetCertificate( otInstance *aInstance, const uint8_t *aX509Cert, uint32_t aX509Length, const uint8_t *aPrivateKey, uint32_t aPrivateKeyLength )
這個方法會使用 DTLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 為本機裝置設定 X509 憑證,並為其加上對應的私密金鑰。
說明 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
參數 |
|
otCoapSecureSetClientConnectedCallback
void otCoapSecureSetClientConnectedCallback( otInstance *aInstance, otHandleCoapSecureClientConnect aHandler, void *aContext )
這個方法會設定連線回呼,在用戶端連線到 CoAP Secure 伺服器時指出。
說明 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
otCoapSecureSetDefaultHandler
void otCoapSecureSetDefaultHandler( otInstance *aInstance, otCoapRequestHandler aHandler, void *aContext )
這個函式會處理未處理的 CoAP Secure 要求的預設處理常式。
說明 | |||||||
---|---|---|---|---|---|---|---|
參數 |
|
otCoapSecureSetPsk
void otCoapSecureSetPsk( otInstance *aInstance, const uint8_t *aPsk, uint16_t aPskLength, const uint8_t *aPskIdentity, uint16_t aPskIdLength )
這個方法會設定預先共用金鑰 (PSK) 和加密套件 DTLS_PSK_WITH_AES_128_CCM_8。
說明 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
參數 |
|
otCoapSecureSetSslAuthMode
void otCoapSecureSetSslAuthMode( otInstance *aInstance, bool aVerifyPeerCertificate )
這個方法可以設定 Coap 安全連線的驗證模式。
停用或啟用對等憑證的驗證。必須在開始之前呼叫。
說明 | |||||
---|---|---|---|---|---|
參數 |
|
otCoapSecureStart
otError otCoapSecureStart( otInstance *aInstance, uint16_t aPort )
這項功能會啟動 CoAP Secure 服務。
說明 | |||||
---|---|---|---|---|---|
參數 |
|
||||
傳回值 |
|
otCoapSecureStop
void otCoapSecureStop( otInstance *aInstance )
這項函式會停止 CoAP Secure 伺服器。
說明 | |||
---|---|---|---|
參數 |
|
巨集
OT_DEFAULT_COAP_SECURE_PORT
OT_DEFAULT_COAP_SECURE_PORT 5684
RFC 7252 中指定的預設 CoAP 安全通訊埠。