1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use confy;
use lazy_static::lazy_static;
use rustls::{Certificate, PrivateKey};
use rustls_pemfile;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::default;
use std::{fs, io};
lazy_static! {
pub static ref CONFIG: EppClientConfig = match confy::load("epp-client") {
Ok(cfg) => cfg,
Err(e) => panic!("Config read error: {}", e),
};
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EppClientTlsFiles {
cert_chain: String,
key: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EppClientConnection {
host: String,
port: u16,
username: String,
password: String,
ext_uris: Option<Vec<String>>,
tls_files: Option<EppClientTlsFiles>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EppClientConfig {
pub registry: HashMap<String, EppClientConnection>,
}
impl default::Default for EppClientConfig {
fn default() -> Self {
let mut registries: HashMap<String, EppClientConnection> = HashMap::new();
let registrar = EppClientConnection {
host: "epphost".to_string(),
port: 700,
username: "username".to_string(),
password: "password".to_string(),
ext_uris: Some(vec![]),
tls_files: Some(EppClientTlsFiles {
cert_chain: "/path/to/certificate/chain/pemfile".to_string(),
key: "/path/to/private/key/pemfile".to_string(),
}),
};
registries.insert("verisign".to_string(), registrar);
Self {
registry: registries,
}
}
}
impl EppClientConnection {
pub fn connection_details(&self) -> (String, u16) {
(self.host.to_string(), self.port)
}
pub fn credentials(&self) -> (String, String) {
(self.username.to_string(), self.password.to_string())
}
pub fn ext_uris(&self) -> Option<&Vec<String>> {
self.ext_uris.as_ref()
}
pub fn tls_files(&self) -> Option<(Vec<Certificate>, PrivateKey)> {
let certificates = self.client_certificate();
let key = self.key();
if certificates == None || key == None {
None
} else {
Some((certificates.unwrap(), key.unwrap()))
}
}
fn client_certificate(&self) -> Option<Vec<Certificate>> {
match &self.tls_files {
Some(tls) => Some(
rustls_pemfile::certs(&mut io::BufReader::new(
fs::File::open(tls.cert_chain.to_string()).unwrap(),
))
.unwrap()
.iter()
.map(|v| Certificate(v.clone()))
.collect(),
),
None => None,
}
}
fn key(&self) -> Option<PrivateKey> {
match &self.tls_files {
Some(tls) => Some(rustls::PrivateKey(
rustls_pemfile::rsa_private_keys(&mut io::BufReader::new(
fs::File::open(tls.key.to_string()).unwrap(),
))
.unwrap()[0]
.clone(),
)),
None => None,
}
}
}
impl EppClientConfig {
pub fn registry(&self, registry: &str) -> Option<&EppClientConnection> {
self.registry.get(registry)
}
}