https://github.com/oatpp/oatpp-mbedtls
Client/Server Secure ConnectionProvider for oatpp applications. Based on MbedTLS.
https://github.com/oatpp/oatpp-mbedtls
cpp mbedtls oatpp tls
Last synced: 11 months ago
JSON representation
Client/Server Secure ConnectionProvider for oatpp applications. Based on MbedTLS.
- Host: GitHub
- URL: https://github.com/oatpp/oatpp-mbedtls
- Owner: oatpp
- License: apache-2.0
- Created: 2019-05-24T01:45:39.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-25T05:58:15.000Z (almost 2 years ago)
- Last Synced: 2025-04-21T03:27:01.218Z (12 months ago)
- Topics: cpp, mbedtls, oatpp, tls
- Language: C++
- Homepage: https://oatpp.io/
- Size: 158 KB
- Stars: 7
- Watchers: 8
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# oatpp-mbedtls [](https://dev.azure.com/lganzzzo/lganzzzo/_build/latest?definitionId=18&branchName=master)
**oatpp-mbedtls** - extension for [Oat++ Web Framework](https://github.com/oatpp/oatpp).
It provides secure server and client connection providers for oatpp applications. Based on [MbedTLS](https://tls.mbed.org/).
Supports both "Simple" and "Async" oatpp APIs.
See more:
- [Oat++ Website](https://oatpp.io/)
- [Oat++ Github Repository](https://github.com/oatpp/oatpp)
- [MbedTLS](https://tls.mbed.org/)
## How To Build
### Requires
- MbedTLS installed.
#### Install MbedTLS from source
```bash
git clone -b 'mbedtls-2.16.1' --single-branch --depth 1 --recurse-submodules https://github.com/ARMmbed/mbedtls
cd mbedtls
mkdir build && cd build
cmake ..
make install
```
#### Install MbedTLS to a custom location
```bash
git clone -b 'mbedtls-2.16.1' --single-branch --depth 1 --recurse-submodules https://github.com/ARMmbed/mbedtls
cd mbedtls
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/my/custom/location ..
make install
```
### Build And Install oatpp-mbedtls
If mbedtls was installed to a standard location:
```bash
mkdir build && cd build
cmake ..
make install
```
If mbedtls was installed to a custom location:
```bash
mkdir build && cd build
cmake -DMBEDTLS_ROOT_DIR=/my/custom/location ..
make install
```
## APIs
### Server
#### ConnectionProvider
Create `ConnectionProvider`
```cpp
const char* serverCertificateFile = "path/to/server/certificate";
const char* serverPrivateKeyFile = "path/to/server/private/key";
/* Create Config */
auto config = oatpp::mbedtls::Config::createDefaultServerConfigShared(serverCertificateFile, serverPrivateKeyFile);
/* Create Secure Connection Provider */
auto connectionProvider = oatpp::mbedtls::server::ConnectionProvider::createShared(config, {"localhost" /* host */, 443 /* port */});
/* Get Secure Connection Stream */
auto connection = connectionProvider->getConnection();
```
#### Custom Transport Stream
Create `ConnectionProvider` with custom transport stream.
```cpp
const char* serverCertificateFile = "path/to/server/certificate";
const char* serverPrivateKeyFile = "path/to/server/private/key";
/* Create Config */
auto config = oatpp::mbedtls::Config::createDefaultServerConfigShared(serverCertificateFile, serverPrivateKeyFile);
/* Create Transport Stream Provider */
/* Replace With Your Custom Transport Stream Provider */
auto transportStreamProvider = oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost" /* host */, 443 /* port */});
/* Create Secure Connection Provider */
auto connectionProvider = oatpp::mbedtls::server::ConnectionProvider::createShared(config, transportStreamProvider);
/* Get Secure Connection Stream over Custom Transport Stream */
auto connection = connectionProvider->getConnection();
```
**Note:** To use `oatpp-mbedtls` for server connections with custom transport stream you should implement:
- [oatpp::network::ServerConnectionProvider](https://oatpp.io/api/latest/oatpp/network/ConnectionProvider/#serverconnectionprovider).
- [oatpp::data::stream::IOStream](https://oatpp.io/api/latest/oatpp/core/data/stream/Stream/#iostream) - to be returned by `ConnectionProvider`.
### Client
#### ConnectionProvider
Create `ConnectionProvider`
```cpp
/* Create Config */
auto config = oatpp::mbedtls::Config::createDefaultClientConfigShared();
/* Create Secure Connection Provider */
auto connectionProvider = oatpp::mbedtls::client::ConnectionProvider::createShared(config, {"httpbin.org", 443 /* port */});
/* Get Secure Connection Stream */
auto connection = connectionProvider->getConnection();
```
#### Custom Transport Stream
Create `ConnectionProvider` with custom transport stream.
```cpp
/* Create Config */
auto config = oatpp::mbedtls::Config::createDefaultClientConfigShared();
/* Create Transport Stream Provider */
/* Replace With Your Custom Transport Stream Provider */
auto transportStreamProvider = oatpp::network::client::SimpleTCPConnectionProvider::createShared({"httpbin.org", 443 /* port */});
/* Create Secure Connection Provider */
auto connectionProvider = oatpp::mbedtls::client::ConnectionProvider::createShared(config, transportStreamProvider);
/* Get Secure Connection Stream over Custom Transport Stream */
auto connection = connectionProvider->getConnection();
```
**Note:** To use `oatpp-mbedtls` for client connections with custom transport stream you should implement:
- [oatpp::network::ClientConnectionProvider](https://oatpp.io/api/latest/oatpp/network/ConnectionProvider/#clientconnectionprovider).
- [oatpp::data::stream::IOStream](https://oatpp.io/api/latest/oatpp/core/data/stream/Stream/#iostream) - to be returned by `ConnectionProvider`.
## See more
- [oatpp-libressl](https://github.com/oatpp/oatpp-libressl)