-
Notifications
You must be signed in to change notification settings - Fork 3k
mbedtls: allow storing certificates in filesystem #13863
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
facchinm
wants to merge
3
commits into
ARMmbed:master
from
arduino:mbedtls_certificates_in_filesystem
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_cert_in_filesystem.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2020, Arduino SA, All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "mbed.h" | ||
#include "TLSSocket.h" | ||
#include "greentea-client/test_env.h" | ||
#include "unity/unity.h" | ||
#include "utest.h" | ||
#include "tls_tests.h" | ||
#include "HeapBlockDevice.h" | ||
#include "LittleFileSystem.h" | ||
|
||
using namespace utest::v1; | ||
|
||
void TLSSOCKET_CERT_IN_FILESYSTEM() | ||
{ | ||
SKIP_IF_TCP_UNSUPPORTED(); | ||
|
||
HeapBlockDevice bd(1024 * 10); | ||
LittleFileSystem fs("fs"); | ||
TEST_ASSERT_EQUAL(0, fs.format(&bd)); | ||
TEST_ASSERT_EQUAL(0, fs.mount(&bd)); | ||
|
||
FILE *fp = fopen("/fs/certs.pem", "wb"); | ||
int ret = fwrite(tls_global::cert, strlen(tls_global::cert), 1, fp); | ||
fclose(fp); | ||
|
||
TLSSocket sock; | ||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); | ||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert_path("/fs")); | ||
|
||
SocketAddress a; | ||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &a)); | ||
a.set_port(ECHO_SERVER_PORT_TLS); | ||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(a)); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -399,6 +399,12 @@ TEST_F(TestTLSSocketWrapper, set_root_ca_cert_invalid) | |
EXPECT_EQ(wrapper->set_root_ca_cert(cert, strlen(cert)), NSAPI_ERROR_PARAMETER); | ||
} | ||
|
||
TEST_F(TestTLSSocketWrapper, set_root_ca_cert_path) | ||
{ | ||
EXPECT_EQ(transport->open(&stack), NSAPI_ERROR_OK); | ||
EXPECT_EQ(wrapper->set_root_ca_cert_path("/"), NSAPI_ERROR_OK); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this test testing? How can we test the side effects are what we want? Is there a mock block device we can use? or a higher level mock? @pan- Do you know what mocks Mbed OS has available for the filesystem? |
||
} | ||
|
||
TEST_F(TestTLSSocketWrapper, set_client_cert_key) | ||
{ | ||
EXPECT_EQ(wrapper->get_own_cert(), static_cast<mbedtls_x509_crt *>(NULL)); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to carry our own modification to mbedtls files, as it prevents us from upgrading mbedtls easily. We have precedent for modifying some files though, usually config files. See the mbedtls importer makefile: https://github.com/ARMmbed/mbed-os/blob/master/connectivity/mbedtls/tools/importer/Makefile
If the importer makefile isn't updated to apply this patch, we run the risk of losing these changes on an upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally understandable... Do you envision any way to import the patch? Or should it be filed to https://github.com/ARMmbed/mbedtls directly?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apply this to the upstream, mbedtls repository
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xc0170 PR submitted here Mbed-TLS/mbedtls#4453