aboutsummaryrefslogtreecommitdiff
path: root/pw_tls_client_mbedtls/public
diff options
context:
space:
mode:
authorYecheng Zhao <zyecheng@google.com>2021-06-23 21:14:02 -0700
committerCQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>2021-07-20 01:55:46 +0000
commit60465a7872427ed4fab9d0683ea1e52cededde7d (patch)
tree85e3c97227fec1856bd0c3e7a0e26aa3c7924d30 /pw_tls_client_mbedtls/public
parenteba7dd6adf850cdf2e2e4edd6fef3653045ba041 (diff)
downloadpigweed-60465a7872427ed4fab9d0683ea1e52cededde7d.tar.gz
pw_tls_client_mbedtls: Add initialization logic
Define necessary data structures for MbedTLS based TLS client and implement initialization logic. Bug: 398 Change-Id: I07c7659d889fec2c9ae9a5f863147ffe30287057 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/51403 Commit-Queue: Yecheng Zhao <zyecheng@google.com> Reviewed-by: David Palchak <palchak@google.com> Reviewed-by: Ali Zhang <alizhang@google.com>
Diffstat (limited to 'pw_tls_client_mbedtls/public')
-rw-r--r--pw_tls_client_mbedtls/public/pw_tls_client_mbedtls/backend_types.h44
1 files changed, 43 insertions, 1 deletions
diff --git a/pw_tls_client_mbedtls/public/pw_tls_client_mbedtls/backend_types.h b/pw_tls_client_mbedtls/public/pw_tls_client_mbedtls/backend_types.h
index a080dff69..e3a2fd44b 100644
--- a/pw_tls_client_mbedtls/public/pw_tls_client_mbedtls/backend_types.h
+++ b/pw_tls_client_mbedtls/public/pw_tls_client_mbedtls/backend_types.h
@@ -14,9 +14,51 @@
#pragma once
+#include "mbedtls/certs.h"
+#include "mbedtls/ctr_drbg.h"
+#include "mbedtls/entropy.h"
+#include "mbedtls/error.h"
+#include "mbedtls/ssl.h"
+#include "pw_status/status.h"
+#include "pw_tls_client/options.h"
+
namespace pw::tls_client::backend {
class SessionImplementation {
- // TODO(pwbug/398): To implement
+ public:
+ SessionImplementation(SessionOptions options);
+ ~SessionImplementation();
+ Status Setup();
+ void SetTlsStatus(TLSStatus status) { tls_status_ = status; }
+ TLSStatus GetTlsStatus() { return tls_status_; }
+
+ // The method is for test only. When given a non-Ok status, it will override
+ // the status returned by entropy source pw::tls_client::GetRandomBytes();
+ static void SetEntropySourceStatus(Status status);
+
+ private:
+ // mbedtls entropy
+ mbedtls_entropy_context entropy_ctx_;
+ mbedtls_ctr_drbg_context drbg_ctx_;
+
+ // SSL data structure
+ mbedtls_ssl_context ssl_ctx_;
+
+ // Configuration data structure
+ mbedtls_ssl_config ssl_config_;
+
+ // A copy of the option when creating the client.
+ SessionOptions session_options_;
+
+ TLSStatus tls_status_ = TLSStatus::kOk;
+
+ static int MbedTlsWrite(void* ctx, const uint8_t* buf, size_t len);
+ static int MbedTlsRead(void* ctx, unsigned char* buf, size_t len);
+ static int MbedTlsEntropySource(void* ctx,
+ unsigned char* out,
+ size_t len,
+ size_t* output_length);
+
+ static Status entropy_source_status_;
};
} // namespace pw::tls_client::backend