-
Notifications
You must be signed in to change notification settings - Fork 83
PSK and DTLS support #202
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
Merged
Merged
PSK and DTLS support #202
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e5ac363
Add serde/alloc as no_std dependency
DrTobe 11b7799
Implement ssl_conf_psk to set PSK and PSK identity
DrTobe b4968c4
Add a PSK example client
DrTobe c2d237e
Add timer which is required for DTLS and an IoCallback impl for UDP
DrTobe 06b38b8
Fix build warnings and test errors
DrTobe 828546a
Require 'std' feature for new client examples
DrTobe 2c7ee98
Use already imported StdResult and import std::io::Error as IoError
DrTobe a1461fa
Merge branch 'master' into psk-and-dtls
DrTobe 790c2ed
Implement DTLS server side with all required preconditions and add ap…
DrTobe 16222fa
Fix documentation links
DrTobe 6909bf0
Add PSK-based operation to the client_server integration test
DrTobe 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* Copyright (c) Fortanix, Inc. | ||
* | ||
* Licensed under the GNU General Public License, version 2 <LICENSE-GPL or | ||
* https://www.gnu.org/licenses/gpl-2.0.html> or the Apache License, Version | ||
* 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your | ||
* option. This file may not be copied, modified, or distributed except | ||
* according to those terms. */ | ||
|
||
// needed to have common code for `mod support` in unit and integrations tests | ||
extern crate mbedtls; | ||
|
||
use std::io::{self, stdin, stdout, Write}; | ||
use std::net::UdpSocket; | ||
use std::sync::Arc; | ||
|
||
use mbedtls::rng::CtrDrbg; | ||
use mbedtls::ssl::config::{Endpoint, Preset, Transport}; | ||
use mbedtls::ssl::{Config, Context}; | ||
use mbedtls::x509::Certificate; | ||
use mbedtls::Result as TlsResult; | ||
|
||
#[path = "../tests/support/mod.rs"] | ||
mod support; | ||
use support::entropy::entropy_new; | ||
use support::keys; | ||
|
||
fn result_main(addr: &str) -> TlsResult<()> { | ||
let entropy = Arc::new(entropy_new()); | ||
let rng = Arc::new(CtrDrbg::new(entropy, None)?); | ||
let cert = Arc::new(Certificate::from_pem_multiple(keys::ROOT_CA_CERT.as_bytes())?); | ||
let mut config = Config::new(Endpoint::Client, Transport::Datagram, Preset::Default); | ||
config.set_rng(rng); | ||
config.set_ca_list(cert, None); | ||
let mut ctx = Context::new(Arc::new(config)); | ||
ctx.set_timer_callback(Box::new(mbedtls::ssl::context::Timer::new())); | ||
|
||
let sock = UdpSocket::bind("localhost:12345").unwrap(); | ||
let sock = mbedtls::ssl::context::ConnectedUdpSocket::connect(sock, addr).unwrap(); | ||
ctx.establish(sock, None).unwrap(); | ||
|
||
let mut line = String::new(); | ||
stdin().read_line(&mut line).unwrap(); | ||
ctx.write_all(line.as_bytes()).unwrap(); | ||
io::copy(&mut ctx, &mut stdout()).unwrap(); | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
let mut args = std::env::args(); | ||
args.next(); | ||
result_main( | ||
&args | ||
.next() | ||
.expect("supply destination in command-line argument"), | ||
) | ||
.unwrap(); | ||
} |
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,52 @@ | ||
/* Copyright (c) Fortanix, Inc. | ||
* | ||
* Licensed under the GNU General Public License, version 2 <LICENSE-GPL or | ||
* https://www.gnu.org/licenses/gpl-2.0.html> or the Apache License, Version | ||
* 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your | ||
* option. This file may not be copied, modified, or distributed except | ||
* according to those terms. */ | ||
|
||
// needed to have common code for `mod support` in unit and integrations tests | ||
extern crate mbedtls; | ||
|
||
use std::io::{self, stdin, stdout, Write}; | ||
use std::net::TcpStream; | ||
use std::sync::Arc; | ||
|
||
use mbedtls::rng::CtrDrbg; | ||
use mbedtls::ssl::config::{Endpoint, Preset, Transport}; | ||
use mbedtls::ssl::{Config, Context}; | ||
use mbedtls::Result as TlsResult; | ||
|
||
#[path = "../tests/support/mod.rs"] | ||
mod support; | ||
use support::entropy::entropy_new; | ||
|
||
fn result_main(addr: &str) -> TlsResult<()> { | ||
let entropy = Arc::new(entropy_new()); | ||
let rng = Arc::new(CtrDrbg::new(entropy, None)?); | ||
let mut config = Config::new(Endpoint::Client, Transport::Stream, Preset::Default); | ||
config.set_rng(rng); | ||
config.set_psk(&[0x12, 0x34, 0x56, 0x78], "client").unwrap(); | ||
let mut ctx = Context::new(Arc::new(config)); | ||
|
||
let conn = TcpStream::connect(addr).unwrap(); | ||
ctx.establish(conn, None)?; | ||
|
||
let mut line = String::new(); | ||
stdin().read_line(&mut line).unwrap(); | ||
ctx.write_all(line.as_bytes()).unwrap(); | ||
io::copy(&mut ctx, &mut stdout()).unwrap(); | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
let mut args = std::env::args(); | ||
args.next(); | ||
result_main( | ||
&args | ||
.next() | ||
.expect("supply destination in command-line argument"), | ||
) | ||
.unwrap(); | ||
} |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.