tmp
This commit is contained in:
parent
583e181140
commit
d47be239ff
|
@ -15,6 +15,7 @@ base64 = "0.13.0"
|
|||
hyper = { version = "0.14.18", features = ["client", "http1", "http2"] }
|
||||
hyper-rustls = { version = "0.23.0", default-features = false, features = ["http1", "http2", "native-tokio", "tls12"] }
|
||||
ring = { version = "0.16.20", features = ["std"] }
|
||||
rustls = "0.20.7"
|
||||
serde = { version = "1.0.104", features = ["derive"] }
|
||||
serde_json = "1.0.78"
|
||||
thiserror = "1.0.30"
|
||||
|
@ -23,6 +24,7 @@ thiserror = "1.0.30"
|
|||
anyhow = "1.0.66"
|
||||
clap = { version = "4.0.29", features = ["derive"] }
|
||||
rcgen = "0.10.0"
|
||||
rustls-pemfile = "1.0.1"
|
||||
tokio = { version = "1.22.0", features = ["rt", "macros", "rt-multi-thread"] }
|
||||
tracing = "0.1.37"
|
||||
tracing-subscriber = "0.3.16"
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
use std::{io, time::Duration};
|
||||
|
||||
use clap::Parser;
|
||||
use rustls::Certificate;
|
||||
use tokio::time::sleep;
|
||||
use tracing::{error, info};
|
||||
|
||||
use instant_acme::{
|
||||
Account, AuthorizationStatus, ChallengeType, Identifier, LetsEncrypt, NewAccount, NewOrder,
|
||||
OrderStatus,
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
// let opts = Options::parse();
|
||||
|
||||
// Create a new account. This will generate a fresh ECDSA key for you.
|
||||
// Alternatively, restore an account from serialized credentials by
|
||||
// using `Account::from_credentials()`.
|
||||
|
||||
// let account = Account::create(
|
||||
// &NewAccount {
|
||||
// contact: &[],
|
||||
// terms_of_service_agreed: true,
|
||||
// only_return_existing: false,
|
||||
// },
|
||||
// LetsEncrypt::Staging.url(),
|
||||
// )
|
||||
// .await?;
|
||||
|
||||
let creds = serde_json::from_str(ACCOUNT).unwrap();
|
||||
let account = Account::from_credentials(creds).unwrap();
|
||||
|
||||
let certs = rustls_pemfile::certs(&mut CERT).unwrap();
|
||||
let cert = certs[0].clone();
|
||||
account.revoke(&Certificate(cert)).await.unwrap();
|
||||
|
||||
// info!(
|
||||
// "account credentials:\n\n{}",
|
||||
// serde_json::to_string_pretty(&ACCOUNT.credentials()).unwrap()
|
||||
// );
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// SMTP server
|
||||
#[derive(Parser)]
|
||||
struct Options {
|
||||
// #[clap(long)]
|
||||
// name: String,
|
||||
}
|
||||
|
||||
const CERT: &[u8] = b"-----BEGIN CERTIFICATE-----
|
||||
MIID8TCCA3igAwIBAgITAPrsbmSSkWU08+AFKwWnHLCgCjAKBggqhkjOPQQDAzBV
|
||||
MQswCQYDVQQGEwJVUzEgMB4GA1UEChMXKFNUQUdJTkcpIExldCdzIEVuY3J5cHQx
|
||||
JDAiBgNVBAMTGyhTVEFHSU5HKSBFcnNhdHogRWRhbWFtZSBFMTAeFw0yMjExMzAx
|
||||
NzM2NTlaFw0yMzAyMjgxNzM2NThaMCExHzAdBgNVBAMTFnNhZ2U4OS5tZXNzd2l0
|
||||
aGRucy5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAS9Vx9GxJCvGffEZqgW
|
||||
mEtBx6s8kUTGQp+K7afTae1sz/GrOnRnNYwGkQaRRaRkNiU6SoPSpaIEF7SppfLE
|
||||
VQ+Ro4ICWTCCAlUwDgYDVR0PAQH/BAQDAgeAMB0GA1UdJQQWMBQGCCsGAQUFBwMB
|
||||
BggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBTFI9bBN5i1NTThtA//
|
||||
R7C3wt5ooDAfBgNVHSMEGDAWgBTr+SXCgChm4m0IkjLzwuGtw/81RTBdBggrBgEF
|
||||
BQcBAQRRME8wJQYIKwYBBQUHMAGGGWh0dHA6Ly9zdGctZTEuby5sZW5jci5vcmcw
|
||||
JgYIKwYBBQUHMAKGGmh0dHA6Ly9zdGctZTEua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+f8lTtmFO
|
||||
/I6qSSl8T5XyNE385zNXaRd8rMJqNC9fIHDjPeJMIaou0TZYT0uNb9OZ7ZhT7smQ
|
||||
SaHcGxtK0SVmJvGNagc6RldrHFbemLbwVpeI4NopRHynQqzkVtsfAlK8VD92SYbp
|
||||
olFsJZWuHVkHgccuI1Hx0+RUp1VGj1PPV+0JmGZeG2ybLloU2rjjMbRmkNjTxub2
|
||||
U1vzCGpBSaBfYQLjLHDwQk1AqRENlZxDqCkXFro8eqT6TFHdtw27KIT+ov1Qyofi
|
||||
q3Uj1w7tPpcFMSDfiWNRE0XGYCjELDo19oPqQthIMQ5X+/3YpCqZceR4vMR6n9ol
|
||||
Lp/0KmjAzqU+LqD2fmFLttKvZUxW8aECTGIcDHGCPJDklwDW3l7DUQ08Wj5Fh/KE
|
||||
f5c9fF3u87WUAJu4Vh9C+ewXZtzL0LD46lYgpn7fv5w9sLS4zQ3CIC3udjJ5Gc/v
|
||||
8VhPQaU1Enn7NW+4IHnfSeP6G5rzLEtl0PreC4k=
|
||||
-----END CERTIFICATE-----";
|
||||
|
||||
const ACCOUNT: &str = "
|
||||
{
|
||||
\"id\": \"https://acme-staging-v02.api.letsencrypt.org/acme/acct/78060154\",
|
||||
\"key_pkcs8\": \"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgvjyueuqwXkRd0jjqRsYO6cIwvIctiPt1gqlLgMppwiehRANCAATUfP9I90-kJqSfW0ocUSG8Rmt6Du4U6goTdfx7as2ThDAsCYnFJlqOqe2RKJfeHfjMD_0Ks0N_PAFey8agM41h\",
|
||||
\"urls\": {
|
||||
\"newNonce\": \"https://acme-staging-v02.api.letsencrypt.org/acme/new-nonce\",
|
||||
\"newAccount\": \"https://acme-staging-v02.api.letsencrypt.org/acme/new-acct\",
|
||||
\"newOrder\": \"https://acme-staging-v02.api.letsencrypt.org/acme/new-order\",
|
||||
\"revokeCert\": \"https://acme-staging-v02.api.letsencrypt.org/acme/revoke-cert\"
|
||||
}
|
||||
}
|
||||
";
|
41
src/lib.rs
41
src/lib.rs
|
@ -14,6 +14,7 @@ use hyper::{Body, Method, Request, Response};
|
|||
use ring::digest::{digest, SHA256};
|
||||
use ring::rand::SystemRandom;
|
||||
use ring::signature::{EcdsaKeyPair, ECDSA_P256_SHA256_FIXED_SIGNING};
|
||||
use rustls::Certificate;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
|
||||
|
@ -23,7 +24,8 @@ pub use types::{
|
|||
Identifier, LetsEncrypt, NewAccount, NewOrder, OrderState, OrderStatus, Problem,
|
||||
};
|
||||
use types::{
|
||||
DirectoryUrls, Empty, FinalizeRequest, Header, JoseJson, Jwk, KeyOrKeyId, SigningAlgorithm,
|
||||
DirectoryUrls, Empty, FinalizeRequest, Header, JoseJson, Jwk, KeyOrKeyId, RevocationRequest,
|
||||
SigningAlgorithm,
|
||||
};
|
||||
|
||||
/// An ACME order as described in RFC 8555 (section 7.1.3)
|
||||
|
@ -219,6 +221,21 @@ impl Account {
|
|||
pub fn credentials(&self) -> AccountCredentials<'_> {
|
||||
self.inner.credentials()
|
||||
}
|
||||
|
||||
/// Revoke a certificate
|
||||
pub async fn revoke(&self, certificate: &Certificate) -> Result<(), Error> {
|
||||
let rsp = self
|
||||
.inner
|
||||
.post(
|
||||
Some(&RevocationRequest::new(certificate)),
|
||||
None,
|
||||
&self.inner.client.urls.revoke_cert,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let _ = Problem::from_response(rsp).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct AccountInner {
|
||||
|
@ -285,6 +302,28 @@ impl Signer for AccountInner {
|
|||
}
|
||||
}
|
||||
|
||||
// struct Revocation {
|
||||
// account: Arc<AccountInner>,
|
||||
// certificate: Certificate,
|
||||
// }
|
||||
|
||||
// impl Revocation {
|
||||
// async fn revoke(&self) -> Result<(), Error> {
|
||||
// let rsp = self
|
||||
// .account
|
||||
// .post(
|
||||
// Some(&RevocationRequest {
|
||||
// certificate: &self.certificate,
|
||||
// }),
|
||||
// None,
|
||||
// &self.account.client.urls.revoke_cert,
|
||||
// )
|
||||
// .await?;
|
||||
// Problem::check(rsp).await?;
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Client {
|
||||
client: hyper::Client<hyper_rustls::HttpsConnector<HttpConnector>>,
|
||||
|
|
15
src/types.rs
15
src/types.rs
|
@ -5,6 +5,7 @@ use base64::URL_SAFE_NO_PAD;
|
|||
use hyper::{Body, Response};
|
||||
use ring::digest::{digest, Digest, SHA256};
|
||||
use ring::signature::{EcdsaKeyPair, KeyPair};
|
||||
use rustls::Certificate;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
@ -252,6 +253,7 @@ pub(crate) struct DirectoryUrls {
|
|||
pub(crate) new_nonce: String,
|
||||
pub(crate) new_account: String,
|
||||
pub(crate) new_order: String,
|
||||
pub(crate) revoke_cert: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -353,3 +355,16 @@ pub(crate) enum SigningAlgorithm {
|
|||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub(crate) struct Empty {}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub(crate) struct RevocationRequest {
|
||||
certificate: String,
|
||||
}
|
||||
|
||||
impl RevocationRequest {
|
||||
pub(crate) fn new(certificate: &Certificate) -> Self {
|
||||
Self {
|
||||
certificate: base64::encode_config(&certificate, base64::URL_SAFE_NO_PAD),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue