itsi-server 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Cargo.lock +950 -239
- data/README.md +2 -0
- data/exe/itsi +5 -5
- data/ext/itsi_acme/Cargo.toml +86 -0
- data/ext/itsi_acme/examples/high_level.rs +63 -0
- data/ext/itsi_acme/examples/high_level_warp.rs +52 -0
- data/ext/itsi_acme/examples/low_level.rs +87 -0
- data/ext/itsi_acme/examples/low_level_axum.rs +66 -0
- data/ext/itsi_acme/src/acceptor.rs +81 -0
- data/ext/itsi_acme/src/acme.rs +354 -0
- data/ext/itsi_acme/src/axum.rs +86 -0
- data/ext/itsi_acme/src/cache.rs +39 -0
- data/ext/itsi_acme/src/caches/boxed.rs +80 -0
- data/ext/itsi_acme/src/caches/composite.rs +69 -0
- data/ext/itsi_acme/src/caches/dir.rs +106 -0
- data/ext/itsi_acme/src/caches/mod.rs +11 -0
- data/ext/itsi_acme/src/caches/no.rs +78 -0
- data/ext/itsi_acme/src/caches/test.rs +136 -0
- data/ext/itsi_acme/src/config.rs +172 -0
- data/ext/itsi_acme/src/https_helper.rs +69 -0
- data/ext/itsi_acme/src/incoming.rs +142 -0
- data/ext/itsi_acme/src/jose.rs +161 -0
- data/ext/itsi_acme/src/lib.rs +142 -0
- data/ext/itsi_acme/src/resolver.rs +59 -0
- data/ext/itsi_acme/src/state.rs +424 -0
- data/ext/itsi_server/Cargo.toml +3 -3
- data/ext/itsi_server/src/ruby_types/itsi_http_request.rs +2 -2
- data/ext/itsi_server/src/ruby_types/itsi_server/itsi_server_config.rs +150 -19
- data/ext/itsi_server/src/ruby_types/itsi_server.rs +1 -0
- data/ext/itsi_server/src/server/binds/listener.rs +34 -29
- data/ext/itsi_server/src/server/binds/tls/locked_dir_cache.rs +2 -2
- data/ext/itsi_server/src/server/binds/tls.rs +1 -1
- data/ext/itsi_server/src/server/middleware_stack/middleware.rs +33 -28
- data/ext/itsi_server/src/server/middleware_stack/middlewares/auth_jwt.rs +56 -3
- data/ext/itsi_server/src/server/middleware_stack/middlewares/csp.rs +179 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/mod.rs +25 -2
- data/ext/itsi_server/src/server/middleware_stack/middlewares/ruby_app.rs +3 -3
- data/ext/itsi_server/src/server/middleware_stack/middlewares/static_assets.rs +2 -1
- data/ext/itsi_server/src/server/middleware_stack/mod.rs +32 -34
- data/ext/itsi_server/src/server/serve_strategy/cluster_mode.rs +10 -4
- data/ext/itsi_server/src/server/serve_strategy/single_mode.rs +30 -7
- data/ext/itsi_server/src/server/thread_worker.rs +2 -2
- data/ext/itsi_server/src/services/static_file_server.rs +30 -28
- data/ext/itsi_tracing/src/lib.rs +39 -8
- data/lib/itsi/server/config/config_helpers.rb +93 -0
- data/lib/itsi/server/config/dsl.rb +81 -33
- data/lib/itsi/server/config/known_paths/KitchensinkDirectories.txt +2346 -0
- data/lib/itsi/server/config/known_paths/Randomfiles.txt +24 -0
- data/lib/itsi/server/config/known_paths/UnixDotfiles.txt +52 -0
- data/lib/itsi/server/config/known_paths/backdoors/ASP_CommonBackdoors.txt +29 -0
- data/lib/itsi/server/config/known_paths/backdoors/bot_control_panels.txt +1668 -0
- data/lib/itsi/server/config/known_paths/backdoors/shells.txt +1167 -0
- data/lib/itsi/server/config/known_paths/cgi/CGI_HTTP_POST.txt +7 -0
- data/lib/itsi/server/config/known_paths/cgi/CGI_HTTP_POST_Windows.txt +6 -0
- data/lib/itsi/server/config/known_paths/cgi/CGI_Microsoft.txt +79 -0
- data/lib/itsi/server/config/known_paths/cgi/CGI_XPlatform.txt +3948 -0
- data/lib/itsi/server/config/known_paths/cms/README.md +5 -0
- data/lib/itsi/server/config/known_paths/cms/drupal_plugins.txt +6320 -0
- data/lib/itsi/server/config/known_paths/cms/drupal_themes.txt +828 -0
- data/lib/itsi/server/config/known_paths/cms/joomla_plugins.txt +224 -0
- data/lib/itsi/server/config/known_paths/cms/joomla_themes.txt +30 -0
- data/lib/itsi/server/config/known_paths/cms/php-nuke.txt +2142 -0
- data/lib/itsi/server/config/known_paths/cms/wordpress.txt +1566 -0
- data/lib/itsi/server/config/known_paths/cms/wp_common_theme_files.txt +46 -0
- data/lib/itsi/server/config/known_paths/cms/wp_plugins.txt +13366 -0
- data/lib/itsi/server/config/known_paths/cms/wp_plugins_full.txt +68662 -0
- data/lib/itsi/server/config/known_paths/cms/wp_plugins_top225.txt +225 -0
- data/lib/itsi/server/config/known_paths/cms/wp_themes.readme +12 -0
- data/lib/itsi/server/config/known_paths/cms/wp_themes.txt +7336 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/3CharExtBrute.txt +17576 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/CommonWebExtensions.txt +80 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/Extensions.Backup.txt +14 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/Extensions.Common.txt +865 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/Extensions.Compressed.txt +186 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/Extensions.Mostcommon.txt +30 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/Extensions.Skipfish.txt +93 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/WordlistSkipfish.txt +1918 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/copy_of.txt +8 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-large-directories-lowercase.txt +56180 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-large-directories.txt +62290 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-large-extensions-lowercase.txt +2367 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-large-extensions.txt +2450 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-large-files-lowercase.txt +35323 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-large-files.txt +37037 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-large-words-lowercase.txt +107982 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-large-words.txt +119600 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-medium-directories-lowercase.txt +26593 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-medium-directories.txt +30009 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-medium-extensions-lowercase.txt +1233 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-medium-extensions.txt +1289 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-medium-files-lowercase.txt +16243 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-medium-files.txt +17128 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-medium-words-lowercase.txt +56293 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-medium-words.txt +63087 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-small-directories-lowercase.txt +17776 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-small-directories.txt +20122 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-small-extensions-lowercase.txt +914 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-small-extensions.txt +963 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-small-files-lowercase.txt +10848 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-small-files.txt +11424 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-small-words-lowercase.txt +38267 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/raft-small-words.txt +43003 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/spanish.txt +445 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/test_demo.txt +36 -0
- data/lib/itsi/server/config/known_paths/filename-dirname-bruteforce/upload_variants.txt +44 -0
- data/lib/itsi/server/config/known_paths/login-file-locations/Logins.txt +71 -0
- data/lib/itsi/server/config/known_paths/login-file-locations/cfm.txt +294 -0
- data/lib/itsi/server/config/known_paths/login-file-locations/html.txt +295 -0
- data/lib/itsi/server/config/known_paths/login-file-locations/jsp.txt +294 -0
- data/lib/itsi/server/config/known_paths/login-file-locations/php.txt +294 -0
- data/lib/itsi/server/config/known_paths/login-file-locations/windows-asp.txt +294 -0
- data/lib/itsi/server/config/known_paths/login-file-locations/windows-aspx.txt +294 -0
- data/lib/itsi/server/config/known_paths/password-file-locations/Passwords.txt +47 -0
- data/lib/itsi/server/config/known_paths/php/PHP.txt +30 -0
- data/lib/itsi/server/config/known_paths/php/PHP_CommonBackdoors.txt +5 -0
- data/lib/itsi/server/config/known_paths/proxy-conf.txt +31 -0
- data/lib/itsi/server/config/known_paths/tftp.txt +79 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/ADFS.txt +86 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/AdobeXML.txt +16 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Apache.txt +101 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/ApacheTomcat.txt +47 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Apache_Axis.txt +16 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/ColdFusion.txt +111 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/FatwireCMS.txt +390 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Frontpage.txt +38 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/HP_System_Mgmt_Homepage.txt +239 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/HTTP_POST_Microsoft.txt +2 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Hyperion.txt +578 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/IIS.txt +187 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/JBoss.txt +5 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/JRun.txt +13 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/JavaServlets_Common.txt +3 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Joomla_exploitable.txt +1937 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/LotusNotes.txt +206 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Netware.txt +18 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Oracle9i.txt +60 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/OracleAppServer.txt +192 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/README.md +6 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Ruby_Rails.txt +121 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/SAP.txt +463 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Sharepoint.txt +1707 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/SiteMinder.txt +19 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/SunAppServerGlassfish.txt +51 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/SuniPlanet.txt +35 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Vignette.txt +73 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Weblogic.txt +160 -0
- data/lib/itsi/server/config/known_paths/webservers-appservers/Websphere.txt +366 -0
- data/lib/itsi/server/config/known_paths/wellknown-rfc5785.txt +30 -0
- data/lib/itsi/server/config/known_paths.rb +17 -0
- data/lib/itsi/server/config/middleware/_index.md +54 -0
- data/lib/itsi/server/config/middleware/log_requests.md +63 -0
- data/lib/itsi/server/config/middleware/log_requests.rb +33 -0
- data/lib/itsi/server/config/middleware.rb +9 -0
- data/lib/itsi/server/config/option.rb +9 -0
- data/lib/itsi/server/config/options/_index.md +36 -0
- data/lib/itsi/server/config/options/fiber_scheduler.md +35 -0
- data/lib/itsi/server/config/options/fiber_scheduler.rb +18 -0
- data/lib/itsi/server/config/options/threads.md +39 -0
- data/lib/itsi/server/config/options/threads.rb +17 -0
- data/lib/itsi/server/config/options/workers.md +43 -0
- data/lib/itsi/server/config/options/workers.rb +17 -0
- data/lib/itsi/server/config/typed_struct.rb +203 -0
- data/lib/itsi/server/config.rb +124 -30
- data/lib/itsi/server/signal_trap.rb +5 -1
- data/lib/itsi/server/typed_handlers/source_parser.rb +1 -1
- data/lib/itsi/server/version.rb +1 -1
- data/lib/itsi/server.rb +27 -6
- data/lib/ruby_lsp/itsi/addon.rb +64 -48
- metadata +141 -5
- data/CHANGELOG.md +0 -10
- data/CODE_OF_CONDUCT.md +0 -139
- data/LICENSE.txt +0 -21
- data/_index.md +0 -6
@@ -0,0 +1,354 @@
|
|
1
|
+
use std::sync::Arc;
|
2
|
+
|
3
|
+
use crate::https_helper::{https, HttpsRequestError, Method, Response};
|
4
|
+
use crate::jose::{key_authorization_sha256, sign, sign_eab, JoseError};
|
5
|
+
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
|
6
|
+
use base64::Engine;
|
7
|
+
use rcgen::{CustomExtension, Error as RcgenError, PKCS_ECDSA_P256_SHA256};
|
8
|
+
use ring::error::{KeyRejected, Unspecified};
|
9
|
+
use ring::rand::SystemRandom;
|
10
|
+
use ring::signature::{EcdsaKeyPair, EcdsaSigningAlgorithm, ECDSA_P256_SHA256_FIXED_SIGNING};
|
11
|
+
use rustls::{crypto::ring::sign::any_ecdsa_type, sign::CertifiedKey};
|
12
|
+
use rustls::{
|
13
|
+
pki_types::{PrivateKeyDer, PrivatePkcs8KeyDer},
|
14
|
+
ClientConfig,
|
15
|
+
};
|
16
|
+
use serde::{Deserialize, Serialize};
|
17
|
+
use serde_json::json;
|
18
|
+
use thiserror::Error;
|
19
|
+
|
20
|
+
pub const LETS_ENCRYPT_STAGING_DIRECTORY: &str =
|
21
|
+
"https://acme-staging-v02.api.letsencrypt.org/directory";
|
22
|
+
pub const LETS_ENCRYPT_PRODUCTION_DIRECTORY: &str =
|
23
|
+
"https://acme-v02.api.letsencrypt.org/directory";
|
24
|
+
pub const ACME_TLS_ALPN_NAME: &[u8] = b"acme-tls/1";
|
25
|
+
|
26
|
+
#[derive(Debug)]
|
27
|
+
pub struct Account {
|
28
|
+
pub key_pair: EcdsaKeyPair,
|
29
|
+
pub directory: Directory,
|
30
|
+
pub kid: String,
|
31
|
+
}
|
32
|
+
|
33
|
+
static ALG: &EcdsaSigningAlgorithm = &ECDSA_P256_SHA256_FIXED_SIGNING;
|
34
|
+
|
35
|
+
impl Account {
|
36
|
+
pub fn generate_key_pair() -> Vec<u8> {
|
37
|
+
let rng = SystemRandom::new();
|
38
|
+
let pkcs8 = EcdsaKeyPair::generate_pkcs8(ALG, &rng).unwrap();
|
39
|
+
pkcs8.as_ref().to_vec()
|
40
|
+
}
|
41
|
+
pub async fn create<'a, S, I>(
|
42
|
+
client_config: &Arc<ClientConfig>,
|
43
|
+
directory: Directory,
|
44
|
+
contact: I,
|
45
|
+
eab: &Option<ExternalAccountKey>,
|
46
|
+
) -> Result<Self, AcmeError>
|
47
|
+
where
|
48
|
+
S: AsRef<str> + 'a,
|
49
|
+
I: IntoIterator<Item = &'a S>,
|
50
|
+
{
|
51
|
+
let key_pair = Self::generate_key_pair();
|
52
|
+
Self::create_with_keypair(client_config, directory, contact, &key_pair, eab).await
|
53
|
+
}
|
54
|
+
pub async fn create_with_keypair<'a, S, I>(
|
55
|
+
client_config: &Arc<ClientConfig>,
|
56
|
+
directory: Directory,
|
57
|
+
contact: I,
|
58
|
+
key_pair: &[u8],
|
59
|
+
eab: &Option<ExternalAccountKey>,
|
60
|
+
) -> Result<Self, AcmeError>
|
61
|
+
where
|
62
|
+
S: AsRef<str> + 'a,
|
63
|
+
I: IntoIterator<Item = &'a S>,
|
64
|
+
{
|
65
|
+
let key_pair = EcdsaKeyPair::from_pkcs8(ALG, key_pair, &SystemRandom::new())?;
|
66
|
+
let contact: Vec<&'a str> = contact.into_iter().map(AsRef::<str>::as_ref).collect();
|
67
|
+
|
68
|
+
let payload = if let Some(eab) = &eab.as_ref() {
|
69
|
+
let eab_body = sign_eab(&key_pair, &eab.key, &eab.kid, &directory.new_account)?;
|
70
|
+
|
71
|
+
json!({
|
72
|
+
"termsOfServiceAgreed": true,
|
73
|
+
"contact": contact,
|
74
|
+
"externalAccountBinding": eab_body,
|
75
|
+
})
|
76
|
+
} else {
|
77
|
+
json!({
|
78
|
+
"termsOfServiceAgreed": true,
|
79
|
+
"contact": contact,
|
80
|
+
})
|
81
|
+
}
|
82
|
+
.to_string();
|
83
|
+
|
84
|
+
let body = sign(
|
85
|
+
&key_pair,
|
86
|
+
None,
|
87
|
+
directory.nonce(client_config).await?,
|
88
|
+
&directory.new_account,
|
89
|
+
&payload,
|
90
|
+
)?;
|
91
|
+
let response = https(
|
92
|
+
client_config,
|
93
|
+
&directory.new_account,
|
94
|
+
Method::Post,
|
95
|
+
Some(body),
|
96
|
+
)
|
97
|
+
.await?;
|
98
|
+
let kid = get_header(&response, "Location")?;
|
99
|
+
Ok(Account {
|
100
|
+
key_pair,
|
101
|
+
kid,
|
102
|
+
directory,
|
103
|
+
})
|
104
|
+
}
|
105
|
+
async fn request(
|
106
|
+
&self,
|
107
|
+
client_config: &Arc<ClientConfig>,
|
108
|
+
url: impl AsRef<str>,
|
109
|
+
payload: &str,
|
110
|
+
) -> Result<(Option<String>, String), AcmeError> {
|
111
|
+
let body = sign(
|
112
|
+
&self.key_pair,
|
113
|
+
Some(&self.kid),
|
114
|
+
self.directory.nonce(client_config).await?,
|
115
|
+
url.as_ref(),
|
116
|
+
payload,
|
117
|
+
)?;
|
118
|
+
let response = https(client_config, url.as_ref(), Method::Post, Some(body)).await?;
|
119
|
+
let location = get_header(&response, "Location").ok();
|
120
|
+
let body = response.text().await.map_err(HttpsRequestError::from)?;
|
121
|
+
log::debug!("response: {:?}", body);
|
122
|
+
Ok((location, body))
|
123
|
+
}
|
124
|
+
pub async fn new_order(
|
125
|
+
&self,
|
126
|
+
client_config: &Arc<ClientConfig>,
|
127
|
+
domains: Vec<String>,
|
128
|
+
) -> Result<(String, Order), AcmeError> {
|
129
|
+
let domains: Vec<Identifier> = domains.into_iter().map(Identifier::Dns).collect();
|
130
|
+
let payload = format!("{{\"identifiers\":{}}}", serde_json::to_string(&domains)?);
|
131
|
+
let response = self
|
132
|
+
.request(client_config, &self.directory.new_order, &payload)
|
133
|
+
.await?;
|
134
|
+
let url = response.0.ok_or(AcmeError::MissingHeader("Location"))?;
|
135
|
+
let order = serde_json::from_str(&response.1)?;
|
136
|
+
Ok((url, order))
|
137
|
+
}
|
138
|
+
pub async fn auth(
|
139
|
+
&self,
|
140
|
+
client_config: &Arc<ClientConfig>,
|
141
|
+
url: impl AsRef<str>,
|
142
|
+
) -> Result<Auth, AcmeError> {
|
143
|
+
let payload = "".to_string();
|
144
|
+
let response = self.request(client_config, url, &payload).await?;
|
145
|
+
Ok(serde_json::from_str(&response.1)?)
|
146
|
+
}
|
147
|
+
pub async fn challenge(
|
148
|
+
&self,
|
149
|
+
client_config: &Arc<ClientConfig>,
|
150
|
+
url: impl AsRef<str>,
|
151
|
+
) -> Result<(), AcmeError> {
|
152
|
+
self.request(client_config, &url, "{}").await?;
|
153
|
+
Ok(())
|
154
|
+
}
|
155
|
+
pub async fn order(
|
156
|
+
&self,
|
157
|
+
client_config: &Arc<ClientConfig>,
|
158
|
+
url: impl AsRef<str>,
|
159
|
+
) -> Result<Order, AcmeError> {
|
160
|
+
let response = self.request(client_config, &url, "").await?;
|
161
|
+
Ok(serde_json::from_str(&response.1)?)
|
162
|
+
}
|
163
|
+
pub async fn finalize(
|
164
|
+
&self,
|
165
|
+
client_config: &Arc<ClientConfig>,
|
166
|
+
url: impl AsRef<str>,
|
167
|
+
csr: Vec<u8>,
|
168
|
+
) -> Result<Order, AcmeError> {
|
169
|
+
let payload = format!("{{\"csr\":\"{}\"}}", URL_SAFE_NO_PAD.encode(csr),);
|
170
|
+
let response = self.request(client_config, &url, &payload).await?;
|
171
|
+
Ok(serde_json::from_str(&response.1)?)
|
172
|
+
}
|
173
|
+
pub async fn certificate(
|
174
|
+
&self,
|
175
|
+
client_config: &Arc<ClientConfig>,
|
176
|
+
url: impl AsRef<str>,
|
177
|
+
) -> Result<String, AcmeError> {
|
178
|
+
Ok(self.request(client_config, &url, "").await?.1)
|
179
|
+
}
|
180
|
+
pub fn tls_alpn_01<'a>(
|
181
|
+
&self,
|
182
|
+
challenges: &'a [Challenge],
|
183
|
+
domain: String,
|
184
|
+
) -> Result<(&'a Challenge, CertifiedKey), AcmeError> {
|
185
|
+
let challenge = challenges
|
186
|
+
.iter()
|
187
|
+
.find(|c| c.typ == ChallengeType::TlsAlpn01);
|
188
|
+
|
189
|
+
let challenge = match challenge {
|
190
|
+
Some(challenge) => challenge,
|
191
|
+
None => return Err(AcmeError::NoTlsAlpn01Challenge),
|
192
|
+
};
|
193
|
+
let mut params = rcgen::CertificateParams::new(vec![domain])?;
|
194
|
+
let key_auth = key_authorization_sha256(&self.key_pair, &challenge.token)?;
|
195
|
+
params.custom_extensions = vec![CustomExtension::new_acme_identifier(key_auth.as_ref())];
|
196
|
+
|
197
|
+
let key_pair = rcgen::KeyPair::generate_for(&PKCS_ECDSA_P256_SHA256)?;
|
198
|
+
let cert = params.self_signed(&key_pair)?;
|
199
|
+
|
200
|
+
let pk_bytes = key_pair.serialize_der();
|
201
|
+
let pk_der: PrivatePkcs8KeyDer = pk_bytes.into();
|
202
|
+
let pk_der: PrivateKeyDer = pk_der.into();
|
203
|
+
let pk = any_ecdsa_type(&pk_der).unwrap();
|
204
|
+
let certified_key = CertifiedKey::new(vec![cert.der().clone()], pk);
|
205
|
+
Ok((challenge, certified_key))
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
#[derive(Debug, Clone, Deserialize)]
|
210
|
+
#[serde(rename_all = "camelCase")]
|
211
|
+
pub struct Directory {
|
212
|
+
pub new_nonce: String,
|
213
|
+
pub new_account: String,
|
214
|
+
pub new_order: String,
|
215
|
+
}
|
216
|
+
|
217
|
+
impl Directory {
|
218
|
+
pub async fn discover(
|
219
|
+
client_config: &Arc<ClientConfig>,
|
220
|
+
url: impl AsRef<str>,
|
221
|
+
) -> Result<Self, AcmeError> {
|
222
|
+
let response = https(client_config, url, Method::Get, None).await?;
|
223
|
+
let body = response.bytes().await.map_err(HttpsRequestError::from)?;
|
224
|
+
|
225
|
+
Ok(serde_json::from_slice(&body)?)
|
226
|
+
}
|
227
|
+
pub async fn nonce(&self, client_config: &Arc<ClientConfig>) -> Result<String, AcmeError> {
|
228
|
+
let response = &https(client_config, &self.new_nonce.as_str(), Method::Head, None).await?;
|
229
|
+
get_header(response, "replay-nonce")
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
/// See RFC 8555 section 7.3.4 for more information.
|
234
|
+
pub struct ExternalAccountKey {
|
235
|
+
pub kid: String,
|
236
|
+
pub key: ring::hmac::Key,
|
237
|
+
}
|
238
|
+
|
239
|
+
impl ExternalAccountKey {
|
240
|
+
pub fn new(kid: String, key: &[u8]) -> Self {
|
241
|
+
Self {
|
242
|
+
kid,
|
243
|
+
key: ring::hmac::Key::new(ring::hmac::HMAC_SHA256, key),
|
244
|
+
}
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
#[derive(Debug, Deserialize, Eq, PartialEq)]
|
249
|
+
pub enum ChallengeType {
|
250
|
+
#[serde(rename = "http-01")]
|
251
|
+
Http01,
|
252
|
+
#[serde(rename = "dns-01")]
|
253
|
+
Dns01,
|
254
|
+
#[serde(rename = "tls-alpn-01")]
|
255
|
+
TlsAlpn01,
|
256
|
+
}
|
257
|
+
|
258
|
+
#[derive(Debug, Deserialize)]
|
259
|
+
#[serde(rename_all = "camelCase")]
|
260
|
+
pub struct Order {
|
261
|
+
#[serde(flatten)]
|
262
|
+
pub status: OrderStatus,
|
263
|
+
pub authorizations: Vec<String>,
|
264
|
+
pub finalize: String,
|
265
|
+
pub error: Option<Problem>,
|
266
|
+
}
|
267
|
+
|
268
|
+
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
|
269
|
+
#[serde(tag = "status", rename_all = "camelCase")]
|
270
|
+
pub enum OrderStatus {
|
271
|
+
Pending,
|
272
|
+
Ready,
|
273
|
+
Valid { certificate: String },
|
274
|
+
Invalid,
|
275
|
+
Processing,
|
276
|
+
}
|
277
|
+
|
278
|
+
#[derive(Debug, Deserialize)]
|
279
|
+
#[serde(rename_all = "camelCase")]
|
280
|
+
pub struct Auth {
|
281
|
+
pub status: AuthStatus,
|
282
|
+
pub identifier: Identifier,
|
283
|
+
pub challenges: Vec<Challenge>,
|
284
|
+
}
|
285
|
+
|
286
|
+
#[derive(Debug, Deserialize)]
|
287
|
+
#[serde(rename_all = "camelCase")]
|
288
|
+
pub enum AuthStatus {
|
289
|
+
Pending,
|
290
|
+
Valid,
|
291
|
+
Invalid,
|
292
|
+
Revoked,
|
293
|
+
Expired,
|
294
|
+
Deactivated,
|
295
|
+
}
|
296
|
+
|
297
|
+
#[derive(Clone, Debug, Serialize, Deserialize)]
|
298
|
+
#[serde(tag = "type", content = "value", rename_all = "camelCase")]
|
299
|
+
pub enum Identifier {
|
300
|
+
Dns(String),
|
301
|
+
}
|
302
|
+
|
303
|
+
#[derive(Debug, Deserialize)]
|
304
|
+
pub struct Challenge {
|
305
|
+
#[serde(rename = "type")]
|
306
|
+
pub typ: ChallengeType,
|
307
|
+
pub url: String,
|
308
|
+
pub token: String,
|
309
|
+
pub error: Option<Problem>,
|
310
|
+
}
|
311
|
+
|
312
|
+
#[derive(Clone, Debug, Serialize, Deserialize)]
|
313
|
+
#[serde(rename_all = "camelCase")]
|
314
|
+
pub struct Problem {
|
315
|
+
#[serde(rename = "type")]
|
316
|
+
pub typ: Option<String>,
|
317
|
+
pub detail: Option<String>,
|
318
|
+
}
|
319
|
+
|
320
|
+
#[derive(Error, Debug)]
|
321
|
+
pub enum AcmeError {
|
322
|
+
#[error("io error: {0}")]
|
323
|
+
Io(#[from] std::io::Error),
|
324
|
+
#[error("certificate generation error: {0}")]
|
325
|
+
Rcgen(#[from] RcgenError),
|
326
|
+
#[error("JOSE error: {0}")]
|
327
|
+
Jose(#[from] JoseError),
|
328
|
+
#[error("JSON error: {0}")]
|
329
|
+
Json(#[from] serde_json::Error),
|
330
|
+
#[error("http request error: {0}")]
|
331
|
+
HttpRequest(#[from] HttpsRequestError),
|
332
|
+
#[error("invalid key pair: {0}")]
|
333
|
+
KeyRejected(#[from] KeyRejected),
|
334
|
+
#[error("crypto error: {0}")]
|
335
|
+
Crypto(#[from] Unspecified),
|
336
|
+
#[error("acme service response is missing {0} header")]
|
337
|
+
MissingHeader(&'static str),
|
338
|
+
#[error("no tls-alpn-01 challenge found")]
|
339
|
+
NoTlsAlpn01Challenge,
|
340
|
+
}
|
341
|
+
|
342
|
+
fn get_header(response: &Response, header: &'static str) -> Result<String, AcmeError> {
|
343
|
+
let h = response
|
344
|
+
.headers()
|
345
|
+
.get_all(header)
|
346
|
+
.iter()
|
347
|
+
.next_back()
|
348
|
+
.and_then(|v| v.to_str().ok())
|
349
|
+
.map(|s| s.to_string());
|
350
|
+
match h {
|
351
|
+
None => Err(AcmeError::MissingHeader(header)),
|
352
|
+
Some(value) => Ok(value),
|
353
|
+
}
|
354
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
use crate::{AcmeAccept, AcmeAcceptor};
|
2
|
+
use rustls::ServerConfig;
|
3
|
+
use std::future::Future;
|
4
|
+
use std::io;
|
5
|
+
use std::io::ErrorKind;
|
6
|
+
use std::pin::Pin;
|
7
|
+
use std::sync::Arc;
|
8
|
+
use std::task::{Context, Poll};
|
9
|
+
use tokio::io::{AsyncRead, AsyncWrite};
|
10
|
+
use tokio_rustls::Accept;
|
11
|
+
|
12
|
+
#[derive(Clone)]
|
13
|
+
pub struct AxumAcceptor {
|
14
|
+
acme_acceptor: AcmeAcceptor,
|
15
|
+
config: Arc<ServerConfig>,
|
16
|
+
}
|
17
|
+
|
18
|
+
impl AxumAcceptor {
|
19
|
+
pub fn new(acme_acceptor: AcmeAcceptor, config: Arc<ServerConfig>) -> Self {
|
20
|
+
Self {
|
21
|
+
acme_acceptor,
|
22
|
+
config,
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
impl<I: AsyncRead + AsyncWrite + Unpin + Send + 'static, S: Send + 'static>
|
28
|
+
axum_server::accept::Accept<I, S> for AxumAcceptor
|
29
|
+
{
|
30
|
+
type Stream = tokio_rustls::server::TlsStream<I>;
|
31
|
+
type Service = S;
|
32
|
+
type Future = AxumAccept<I, S>;
|
33
|
+
|
34
|
+
fn accept(&self, stream: I, service: S) -> Self::Future {
|
35
|
+
let acme_accept = self.acme_acceptor.accept(stream);
|
36
|
+
Self::Future {
|
37
|
+
config: self.config.clone(),
|
38
|
+
acme_accept,
|
39
|
+
tls_accept: None,
|
40
|
+
service: Some(service),
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
pub struct AxumAccept<I: AsyncRead + AsyncWrite + Unpin + Send + 'static, S: Send + 'static> {
|
46
|
+
config: Arc<ServerConfig>,
|
47
|
+
acme_accept: AcmeAccept<I>,
|
48
|
+
tls_accept: Option<Accept<I>>,
|
49
|
+
service: Option<S>,
|
50
|
+
}
|
51
|
+
|
52
|
+
impl<I: AsyncRead + AsyncWrite + Unpin + Send + 'static, S: Send + 'static> Unpin
|
53
|
+
for AxumAccept<I, S>
|
54
|
+
{
|
55
|
+
}
|
56
|
+
|
57
|
+
impl<I: AsyncRead + AsyncWrite + Unpin + Send + 'static, S: Send + 'static> Future
|
58
|
+
for AxumAccept<I, S>
|
59
|
+
{
|
60
|
+
type Output = io::Result<(tokio_rustls::server::TlsStream<I>, S)>;
|
61
|
+
|
62
|
+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
63
|
+
loop {
|
64
|
+
if let Some(tls_accept) = &mut self.tls_accept {
|
65
|
+
return match Pin::new(&mut *tls_accept).poll(cx) {
|
66
|
+
Poll::Ready(Ok(tls)) => Poll::Ready(Ok((tls, self.service.take().unwrap()))),
|
67
|
+
Poll::Ready(Err(err)) => Poll::Ready(Err(err)),
|
68
|
+
Poll::Pending => Poll::Pending,
|
69
|
+
};
|
70
|
+
}
|
71
|
+
return match Pin::new(&mut self.acme_accept).poll(cx) {
|
72
|
+
Poll::Ready(Ok(Some(start_handshake))) => {
|
73
|
+
let config = self.config.clone();
|
74
|
+
self.tls_accept = Some(start_handshake.into_stream(config));
|
75
|
+
continue;
|
76
|
+
}
|
77
|
+
Poll::Ready(Ok(None)) => Poll::Ready(Err(io::Error::new(
|
78
|
+
ErrorKind::Other,
|
79
|
+
"TLS-ALPN-01 validation request",
|
80
|
+
))),
|
81
|
+
Poll::Ready(Err(err)) => Poll::Ready(Err(err)),
|
82
|
+
Poll::Pending => Poll::Pending,
|
83
|
+
};
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
use std::fmt::Debug;
|
2
|
+
|
3
|
+
use async_trait::async_trait;
|
4
|
+
|
5
|
+
pub trait Cache: CertCache + AccountCache {}
|
6
|
+
|
7
|
+
impl<T> Cache for T where T: CertCache + AccountCache {}
|
8
|
+
|
9
|
+
#[async_trait]
|
10
|
+
pub trait CertCache: Send + Sync {
|
11
|
+
type EC: Debug;
|
12
|
+
async fn load_cert(
|
13
|
+
&self,
|
14
|
+
domains: &[String],
|
15
|
+
directory_url: &str,
|
16
|
+
) -> Result<Option<Vec<u8>>, Self::EC>;
|
17
|
+
async fn store_cert(
|
18
|
+
&self,
|
19
|
+
domains: &[String],
|
20
|
+
directory_url: &str,
|
21
|
+
cert: &[u8],
|
22
|
+
) -> Result<(), Self::EC>;
|
23
|
+
}
|
24
|
+
|
25
|
+
#[async_trait]
|
26
|
+
pub trait AccountCache: Send + Sync {
|
27
|
+
type EA: Debug;
|
28
|
+
async fn load_account(
|
29
|
+
&self,
|
30
|
+
contact: &[String],
|
31
|
+
directory_url: &str,
|
32
|
+
) -> Result<Option<Vec<u8>>, Self::EA>;
|
33
|
+
async fn store_account(
|
34
|
+
&self,
|
35
|
+
contact: &[String],
|
36
|
+
directory_url: &str,
|
37
|
+
account: &[u8],
|
38
|
+
) -> Result<(), Self::EA>;
|
39
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
use crate::{AccountCache, CertCache};
|
2
|
+
use async_trait::async_trait;
|
3
|
+
use std::fmt::Debug;
|
4
|
+
|
5
|
+
pub struct BoxedErrCache<T: Send + Sync> {
|
6
|
+
inner: T,
|
7
|
+
}
|
8
|
+
|
9
|
+
impl<T: Send + Sync> BoxedErrCache<T> {
|
10
|
+
pub fn new(inner: T) -> Self {
|
11
|
+
Self { inner }
|
12
|
+
}
|
13
|
+
pub fn into_inner(self) -> T {
|
14
|
+
self.inner
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
fn box_err(e: impl Debug + 'static) -> Box<dyn Debug> {
|
19
|
+
Box::new(e)
|
20
|
+
}
|
21
|
+
|
22
|
+
#[async_trait]
|
23
|
+
impl<T: CertCache> CertCache for BoxedErrCache<T>
|
24
|
+
where
|
25
|
+
<T as CertCache>::EC: 'static,
|
26
|
+
{
|
27
|
+
type EC = Box<dyn Debug>;
|
28
|
+
async fn load_cert(
|
29
|
+
&self,
|
30
|
+
domains: &[String],
|
31
|
+
directory_url: &str,
|
32
|
+
) -> Result<Option<Vec<u8>>, Self::EC> {
|
33
|
+
self.inner
|
34
|
+
.load_cert(domains, directory_url)
|
35
|
+
.await
|
36
|
+
.map_err(box_err)
|
37
|
+
}
|
38
|
+
|
39
|
+
async fn store_cert(
|
40
|
+
&self,
|
41
|
+
domains: &[String],
|
42
|
+
directory_url: &str,
|
43
|
+
cert: &[u8],
|
44
|
+
) -> Result<(), Self::EC> {
|
45
|
+
self.inner
|
46
|
+
.store_cert(domains, directory_url, cert)
|
47
|
+
.await
|
48
|
+
.map_err(box_err)
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
#[async_trait]
|
53
|
+
impl<T: AccountCache> AccountCache for BoxedErrCache<T>
|
54
|
+
where
|
55
|
+
<T as AccountCache>::EA: 'static,
|
56
|
+
{
|
57
|
+
type EA = Box<dyn Debug>;
|
58
|
+
async fn load_account(
|
59
|
+
&self,
|
60
|
+
contact: &[String],
|
61
|
+
directory_url: &str,
|
62
|
+
) -> Result<Option<Vec<u8>>, Self::EA> {
|
63
|
+
self.inner
|
64
|
+
.load_account(contact, directory_url)
|
65
|
+
.await
|
66
|
+
.map_err(box_err)
|
67
|
+
}
|
68
|
+
|
69
|
+
async fn store_account(
|
70
|
+
&self,
|
71
|
+
contact: &[String],
|
72
|
+
directory_url: &str,
|
73
|
+
account: &[u8],
|
74
|
+
) -> Result<(), Self::EA> {
|
75
|
+
self.inner
|
76
|
+
.store_account(contact, directory_url, account)
|
77
|
+
.await
|
78
|
+
.map_err(box_err)
|
79
|
+
}
|
80
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
use crate::{AccountCache, CertCache};
|
2
|
+
use async_trait::async_trait;
|
3
|
+
|
4
|
+
pub struct CompositeCache<C: CertCache + Send + Sync, A: AccountCache + Send + Sync> {
|
5
|
+
pub cert_cache: C,
|
6
|
+
pub account_cache: A,
|
7
|
+
}
|
8
|
+
|
9
|
+
impl<C: CertCache + Send + Sync, A: AccountCache + Send + Sync> CompositeCache<C, A> {
|
10
|
+
pub fn new(cert_cache: C, account_cache: A) -> Self {
|
11
|
+
Self {
|
12
|
+
cert_cache,
|
13
|
+
account_cache,
|
14
|
+
}
|
15
|
+
}
|
16
|
+
pub fn into_inner(self) -> (C, A) {
|
17
|
+
(self.cert_cache, self.account_cache)
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
#[async_trait]
|
22
|
+
impl<C: CertCache + Send + Sync, A: AccountCache + Send + Sync> CertCache for CompositeCache<C, A> {
|
23
|
+
type EC = C::EC;
|
24
|
+
async fn load_cert(
|
25
|
+
&self,
|
26
|
+
domains: &[String],
|
27
|
+
directory_url: &str,
|
28
|
+
) -> Result<Option<Vec<u8>>, Self::EC> {
|
29
|
+
self.cert_cache.load_cert(domains, directory_url).await
|
30
|
+
}
|
31
|
+
|
32
|
+
async fn store_cert(
|
33
|
+
&self,
|
34
|
+
domains: &[String],
|
35
|
+
directory_url: &str,
|
36
|
+
cert: &[u8],
|
37
|
+
) -> Result<(), Self::EC> {
|
38
|
+
self.cert_cache
|
39
|
+
.store_cert(domains, directory_url, cert)
|
40
|
+
.await
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
#[async_trait]
|
45
|
+
impl<C: CertCache + Send + Sync, A: AccountCache + Send + Sync> AccountCache
|
46
|
+
for CompositeCache<C, A>
|
47
|
+
{
|
48
|
+
type EA = A::EA;
|
49
|
+
async fn load_account(
|
50
|
+
&self,
|
51
|
+
contact: &[String],
|
52
|
+
directory_url: &str,
|
53
|
+
) -> Result<Option<Vec<u8>>, Self::EA> {
|
54
|
+
self.account_cache
|
55
|
+
.load_account(contact, directory_url)
|
56
|
+
.await
|
57
|
+
}
|
58
|
+
|
59
|
+
async fn store_account(
|
60
|
+
&self,
|
61
|
+
contact: &[String],
|
62
|
+
directory_url: &str,
|
63
|
+
account: &[u8],
|
64
|
+
) -> Result<(), Self::EA> {
|
65
|
+
self.account_cache
|
66
|
+
.store_account(contact, directory_url, account)
|
67
|
+
.await
|
68
|
+
}
|
69
|
+
}
|