Skip to content

Commit 5a13773

Browse files
authored
Merge pull request #9 from Jzow/master
#8 Add SSL in boot
2 parents 96fdad6 + f9c981a commit 5a13773

File tree

10 files changed

+135
-1
lines changed

10 files changed

+135
-1
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
22
members = [
3+
"summer-boot",
34
"summer-boot-tests",
45
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod server;
2+
pub mod error;

summer-boot-project/summer-boot/Cargo.toml summer-boot/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ description = "summer boot core"
77
authors = [
88
"James Zow <[email protected]>"
99
]
10-
license = "Apache-2.0"
10+
license = "Apache-2.0"
11+
12+
[dependencies]
13+
serde = { version = "1", features = ["derive"] }
14+
serde_json = "1"

summer-boot/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod web;
2+
File renamed without changes.

summer-boot/src/web/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod server;
2+
pub mod error;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub struct ConfigurableWebServer {
2+
3+
pub port: Option<i32>,
4+
5+
pub server_header: Option<String>,
6+
7+
8+
}

summer-boot/src/web/server/http.rs

Whitespace-only changes.

summer-boot/src/web/server/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod ssl;

summer-boot/src/web/server/ssl.rs

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Debug, Serialize, Deserialize)]
4+
enum ClientAuth {
5+
/**
6+
* Client authentication is not wanted
7+
*/
8+
NONE,
9+
/**
10+
* Client authentication is wanted but not mandatory.
11+
*/
12+
WANT,
13+
/**
14+
* Client authentication is needed and mandatory.
15+
*/
16+
NEED
17+
}
18+
19+
#[derive(Debug, Serialize, Deserialize)]
20+
pub struct Ssl {
21+
22+
enabled: Option<bool>,
23+
24+
ciphers: Vec<String>,
25+
26+
client_auth: ClientAuth,
27+
28+
enabled_protocols: Vec<String>,
29+
30+
key_alias: Option<String>,
31+
32+
key_passowrd: Option<String>,
33+
34+
key_store: Option<String>,
35+
36+
key_store_password: Option<String>,
37+
38+
key_store_type: Option<String>,
39+
40+
trust_store: Option<String>,
41+
42+
trust_store_password: Option<String>,
43+
44+
trust_store_type: Option<String>,
45+
46+
trust_store_provider: Option<String>,
47+
48+
certificate: Option<String>,
49+
50+
certificate_private_key: Option<String>,
51+
52+
trust_certificate: Option<String>,
53+
54+
trust_certificate_private_key: Option<String>,
55+
56+
protocol: Option<String>,
57+
}
58+
59+
impl Ssl {
60+
61+
pub(crate) fn new(ssl_config: Ssl) -> Self {
62+
Ssl {
63+
enabled: Some(true),
64+
protocol: Some(String::from("TLS")),
65+
ciphers: ssl_config.ciphers,
66+
client_auth: ssl_config.client_auth,
67+
enabled_protocols: ssl_config.enabled_protocols,
68+
key_alias: ssl_config.key_alias,
69+
key_passowrd: ssl_config.key_passowrd,
70+
key_store: ssl_config.key_store,
71+
key_store_password: ssl_config.key_store_password,
72+
key_store_type: ssl_config.key_store_type,
73+
trust_store: ssl_config.trust_store,
74+
trust_store_password: ssl_config.trust_store_password,
75+
trust_store_type: ssl_config.trust_store_type,
76+
trust_store_provider: ssl_config.trust_store_provider,
77+
certificate: ssl_config.certificate,
78+
certificate_private_key: ssl_config.certificate_private_key,
79+
trust_certificate: ssl_config.trust_certificate,
80+
trust_certificate_private_key: ssl_config.trust_certificate_private_key,
81+
}
82+
}
83+
}
84+
85+
#[cfg(test)]
86+
mod tests {
87+
use super::*;
88+
89+
#[test]
90+
fn test_ssl_config() {
91+
let ssl_config = Ssl {
92+
enabled: Some(false),
93+
protocol: Some(String::from("TLS")),
94+
ciphers: Vec::new(),
95+
client_auth: ClientAuth::NONE,
96+
enabled_protocols: Vec::new(),
97+
key_alias: None,
98+
key_passowrd: None,
99+
key_store: None,
100+
key_store_password: None,
101+
key_store_type: None,
102+
trust_store: None,
103+
trust_store_password: None,
104+
trust_store_type: None,
105+
trust_store_provider: None,
106+
certificate: None,
107+
certificate_private_key: None,
108+
trust_certificate: None,
109+
trust_certificate_private_key: None,
110+
};
111+
112+
println!("ssl config : {:?}", Ssl::new(ssl_config));
113+
}
114+
}

0 commit comments

Comments
 (0)