Skip to content

Commit

Permalink
Merge pull request #9 from Jzow/master
Browse files Browse the repository at this point in the history
#8 Add SSL in boot
  • Loading branch information
Jzow authored May 31, 2022
2 parents 96fdad6 + f9c981a commit 5a13773
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
members = [
"summer-boot",
"summer-boot-tests",
]
2 changes: 2 additions & 0 deletions summer-boot-starters/summer-boot-starter-web/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod server;
pub mod error;
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ description = "summer boot core"
authors = [
"James Zow <[email protected]>"
]
license = "Apache-2.0"
license = "Apache-2.0"

[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"
2 changes: 2 additions & 0 deletions summer-boot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod web;

File renamed without changes.
2 changes: 2 additions & 0 deletions summer-boot/src/web/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod server;
pub mod error;
8 changes: 8 additions & 0 deletions summer-boot/src/web/server/configurable_webserver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub struct ConfigurableWebServer {

pub port: Option<i32>,

pub server_header: Option<String>,


}
Empty file.
1 change: 1 addition & 0 deletions summer-boot/src/web/server/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod ssl;
114 changes: 114 additions & 0 deletions summer-boot/src/web/server/ssl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
enum ClientAuth {
/**
* Client authentication is not wanted
*/
NONE,
/**
* Client authentication is wanted but not mandatory.
*/
WANT,
/**
* Client authentication is needed and mandatory.
*/
NEED
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Ssl {

enabled: Option<bool>,

ciphers: Vec<String>,

client_auth: ClientAuth,

enabled_protocols: Vec<String>,

key_alias: Option<String>,

key_passowrd: Option<String>,

key_store: Option<String>,

key_store_password: Option<String>,

key_store_type: Option<String>,

trust_store: Option<String>,

trust_store_password: Option<String>,

trust_store_type: Option<String>,

trust_store_provider: Option<String>,

certificate: Option<String>,

certificate_private_key: Option<String>,

trust_certificate: Option<String>,

trust_certificate_private_key: Option<String>,

protocol: Option<String>,
}

impl Ssl {

pub(crate) fn new(ssl_config: Ssl) -> Self {
Ssl {
enabled: Some(true),
protocol: Some(String::from("TLS")),
ciphers: ssl_config.ciphers,
client_auth: ssl_config.client_auth,
enabled_protocols: ssl_config.enabled_protocols,
key_alias: ssl_config.key_alias,
key_passowrd: ssl_config.key_passowrd,
key_store: ssl_config.key_store,
key_store_password: ssl_config.key_store_password,
key_store_type: ssl_config.key_store_type,
trust_store: ssl_config.trust_store,
trust_store_password: ssl_config.trust_store_password,
trust_store_type: ssl_config.trust_store_type,
trust_store_provider: ssl_config.trust_store_provider,
certificate: ssl_config.certificate,
certificate_private_key: ssl_config.certificate_private_key,
trust_certificate: ssl_config.trust_certificate,
trust_certificate_private_key: ssl_config.trust_certificate_private_key,
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_ssl_config() {
let ssl_config = Ssl {
enabled: Some(false),
protocol: Some(String::from("TLS")),
ciphers: Vec::new(),
client_auth: ClientAuth::NONE,
enabled_protocols: Vec::new(),
key_alias: None,
key_passowrd: None,
key_store: None,
key_store_password: None,
key_store_type: None,
trust_store: None,
trust_store_password: None,
trust_store_type: None,
trust_store_provider: None,
certificate: None,
certificate_private_key: None,
trust_certificate: None,
trust_certificate_private_key: None,
};

println!("ssl config : {:?}", Ssl::new(ssl_config));
}
}

0 comments on commit 5a13773

Please sign in to comment.