Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for client certificate and private key#992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
pennam wants to merge3 commits intoarduino:main
base:main
Choose a base branch
Loading
frompennam:client-cert-key
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletionslibraries/SE05X/src/WiFiSSLSE050Client.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,8 +26,8 @@ arduino::MbedSSLSE050Client::MbedSSLSE050Client() {
void arduino::MbedSSLSE050Client::setEccSlot(int KeySlot, const byte cert[], int certLen) {

_keySlot = KeySlot;
_client_cert_len = certLen;
_client_cert = cert;
_certLen = certLen;
_cert = cert;
}

void WiFiSSLSE050Client::setEccSlot(int KeySlot, const byte cert[], int certLen) {
Expand Down
35 changes: 13 additions & 22 deletionslibraries/SE05X/src/WiFiSSLSE050Client.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,37 +37,28 @@ class MbedSSLSE050Client : public arduino::MbedSSLClient {
void setEccSlot(int KeySlot, const byte cert[], int certLen);

private:
const byte* _client_cert;
const char* _ca_cert;
int _client_cert_len;
const byte* _cert;
int _certLen;
int _keySlot;
sss_object_t _keyObject;

int setRootCAClientCertKey() {
if( NSAPI_ERROR_OK != ((TLSSocket*)sock)->set_root_ca_cert_path("/wlan/")) {
return 0;
int err = setRootCA();
if (err != NSAPI_ERROR_OK) {
return err;
}

if(_hostname && !_disableSNI) {
((TLSSocket*)sock)->set_hostname(_hostname);
if(SE05X.getObjectHandle(_keySlot, &_keyObject) != NSAPI_ERROR_OK) {
return NSAPI_ERROR_DEVICE_ERROR;
}

if( NSAPI_ERROR_OK != ((TLSSocket*)sock)->append_root_ca_cert(_ca_cert_custom)) {
return 0;
if(((TLSSocket*)sock)->set_client_cert_key((void*)_cert,
(size_t)_certLen,
&_keyObject,
SE05X.getDeviceCtx()) != NSAPI_ERROR_OK) {
return NSAPI_ERROR_DEVICE_ERROR;
}

if(!SE05X.getObjectHandle(_keySlot, &_keyObject)) {
return 0;
}

if( NSAPI_ERROR_OK != ((TLSSocket*)sock)->set_client_cert_key((void*)_client_cert,
(size_t)_client_cert_len,
&_keyObject,
SE05X.getDeviceCtx())) {
return 0;
}

return 1;
return NSAPI_ERROR_OK;
}
};

Expand Down
21 changes: 21 additions & 0 deletionslibraries/SocketWrapper/src/AClient.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,3 +143,24 @@ void arduino::ASslClient::appendCustomCACert(const char* ca_cert) {
}
static_cast<MbedSSLClient*>(client.get())->appendCustomCACert(ca_cert);
}

void arduino::ASslClient::setCACert(const char* rootCA) {
if (!client) {
newMbedClient();
}
static_cast<MbedSSLClient*>(client.get())->setCACert(rootCA);
}

void arduino::ASslClient::setCertificate(const char* clientCert) {
if (!client) {
newMbedClient();
}
static_cast<MbedSSLClient*>(client.get())->setCertificate(clientCert);
}

void arduino::ASslClient::setPrivateKey(const char* privateKey) {
if (!client) {
newMbedClient();
}
static_cast<MbedSSLClient*>(client.get())->setPrivateKey(privateKey);
}
3 changes: 3 additions & 0 deletionslibraries/SocketWrapper/src/AClient.h
View file
Open in desktop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I would add a comment specifying that these functions has to be called beforeconnect

Original file line numberDiff line numberDiff line change
Expand Up@@ -74,6 +74,9 @@ class ASslClient : public AClient {
void disableSNI(bool statusSNI);

void appendCustomCACert(const char* ca_cert);
void setCACert(const char* rootCA);
void setCertificate(const char* clientCert);
void setPrivateKey(const char* privateKey);

protected:
virtual void newMbedClient();
Expand Down
7 changes: 5 additions & 2 deletionslibraries/SocketWrapper/src/MbedSSLClient.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
#include "MbedSSLClient.h"

arduino::MbedSSLClient::MbedSSLClient()
:_ca_cert_custom(nullptr),
:_rootCA(nullptr),
_hostname(nullptr),
_disableSNI(false) {
_clientCert(nullptr),
_privateKey(nullptr),
_disableSNI(false),
_appendCA(true) {

onBeforeConnect(mbed::callback(this, &MbedSSLClient::setRootCA));
};
47 changes: 36 additions & 11 deletionslibraries/SocketWrapper/src/MbedSSLClient.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,19 +48,48 @@ class MbedSSLClient : public arduino::MbedClient {
_disableSNI = statusSNI;
}

void appendCustomCACert(const char* ca_cert) {
_ca_cert_custom = ca_cert;
void appendCustomCACert(const char* rootCA) {
_rootCA = rootCA;
_appendCA = true;
}
void setCACert(const char* rootCA) {
_rootCA = rootCA;
_appendCA = false;
}
void setCertificate(const char* clientCert) {
_clientCert = clientCert;
}
void setPrivateKey(const char* privateKey) {
_privateKey = privateKey;
}

protected:
const char*_ca_cert_custom;
private:
const char*_rootCA;
const char* _hostname;
const char* _clientCert;
const char* _privateKey;
bool _disableSNI;
bool _appendCA;

private:
protected:
int setRootCA() {
int err = 0;

if(_hostname && !_disableSNI) {
((TLSSocket*)sock)->set_hostname(_hostname);
}

if(_clientCert && _privateKey) {
err = ((TLSSocket*)sock)->set_client_cert_key(_clientCert, _privateKey);
if( err != NSAPI_ERROR_OK) {
return err;
}
}

if(!_appendCA && _rootCA) {
return ((TLSSocket*)sock)->set_root_ca_cert(_rootCA);
}

#if defined(MBEDTLS_FS_IO)
mbed::BlockDevice* root = mbed::BlockDevice::get_default_instance();
err = root->init();
Expand All@@ -82,12 +111,8 @@ class MbedSSLClient : public arduino::MbedClient {
}
#endif

if(_hostname && !_disableSNI) {
((TLSSocket*)sock)->set_hostname(_hostname);
}

if(_ca_cert_custom != NULL) {
err = ((TLSSocket*)sock)->append_root_ca_cert(_ca_cert_custom);
if(_rootCA != NULL) {
err = ((TLSSocket*)sock)->append_root_ca_cert(_rootCA);
}
return err;
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp