Skip to content

Commit

Permalink
create types ListOfCertificatesByAddress and CertificatesByAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Apr 28, 2023
1 parent 802c3e9 commit 75b5ade
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
8 changes: 4 additions & 4 deletions bin/src/ctl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,11 @@ pub fn print_certificates(

for (_worker_id, response_content) in response_contents.iter() {
match response_content {
ResponseContent::Certificates(h) => {
for (addr, h2) in h.iter() {
println!("\t{addr}:");
ResponseContent::Certificates(list) => {
for certs in list.certificates.iter() {
println!("\t{}:", certs.address);

for summary in h2.iter() {
for summary in certs.certificate_summaries.iter() {
println!(
"\t\t{}:\t{}",
summary.domain,
Expand Down
9 changes: 9 additions & 0 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ message CertificateSummary {
required string fingerprint = 2;
}

message ListOfCertificatesByAddress {
repeated CertificatesByAddress certificates = 1;
}

message CertificatesByAddress {
required string address = 1;
repeated CertificateSummary certificate_summaries = 2;
}

// A certificate matching a request by fingerprint,
// and the list of domain names associated
message CertificateWithNames {
Expand Down
18 changes: 6 additions & 12 deletions command/src/response.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
use std::{
cmp::Ordering,
collections::{BTreeMap, HashMap},
default::Default,
fmt,
net::SocketAddr,
};
use std::{cmp::Ordering, collections::BTreeMap, default::Default, fmt, net::SocketAddr};

use crate::{
proto::command::{
AddBackend, AggregatedMetrics, AvailableMetrics, CertificateSummary, ClusterHashes,
ClusterInformations, Event, FilteredTimeSerie, ListenersList, LoadBalancingParams,
PathRule, PathRuleKind, RequestHttpFrontend, RequestTcpFrontend, ResponseStatus,
RulePosition, RunState, WorkerInfos, WorkerMetrics, CertificateWithNames,
AddBackend, AggregatedMetrics, AvailableMetrics, CertificateWithNames, ClusterHashes,
ClusterInformations, Event, FilteredTimeSerie, ListOfCertificatesByAddress, ListenersList,
LoadBalancingParams, PathRule, PathRuleKind, RequestHttpFrontend, RequestTcpFrontend,
ResponseStatus, RulePosition, RunState, WorkerInfos, WorkerMetrics,
},
request::PROTOCOL_VERSION,
state::ClusterId,
Expand Down Expand Up @@ -72,7 +66,7 @@ pub enum ResponseContent {
ClustersHashes(ClusterHashes),

/// a list of certificates for each socket address
Certificates(HashMap<SocketAddr, Vec<CertificateSummary>>),
Certificates(ListOfCertificatesByAddress),

/// returns the certificate matching a request by fingerprint,
/// and the list of domain names associated
Expand Down
31 changes: 21 additions & 10 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ use sozu_command::{
config::DEFAULT_CIPHER_SUITES,
logging,
proto::command::{
request::RequestType, AddCertificate, CertificateSummary, Cluster, HttpsListenerConfig,
RemoveCertificate, RemoveListener, ReplaceCertificate, RequestHttpFrontend, TlsVersion,
request::RequestType, AddCertificate, CertificateSummary, CertificatesByAddress, Cluster,
HttpsListenerConfig, ListOfCertificatesByAddress, RemoveCertificate, RemoveListener,
ReplaceCertificate, RequestHttpFrontend, TlsVersion,
},
ready::Ready,
request::WorkerRequest,
Expand Down Expand Up @@ -954,16 +955,21 @@ impl HttpsProxy {
})
.collect();

(owned.address, certificate_summaries)
CertificatesByAddress {
address: owned.address.to_string(),
certificate_summaries,
}
})
.collect::<HashMap<_, _>>();
.collect();

info!(
"got Certificates::All query, answering with {:?}",
certificates
);

Ok(Some(ResponseContent::Certificates(certificates)))
Ok(Some(ResponseContent::Certificates(
ListOfCertificatesByAddress { certificates },
)))
}

pub fn query_certificate_for_domain(
Expand All @@ -976,26 +982,31 @@ impl HttpsProxy {
.map(|listener| {
let owned = listener.borrow();
let resolver = unwrap_msg!(owned.resolver.0.lock());
let mut certificate_summary = vec![];
let mut certificate_summaries = vec![];

resolver
.domain_lookup(domain.as_bytes(), true)
.map(|(k, fingerprint)| {
certificate_summary.push(CertificateSummary {
certificate_summaries.push(CertificateSummary {
domain: String::from_utf8(k.to_vec()).unwrap(),
fingerprint: fingerprint.to_string(),
});
});
(owned.address, certificate_summary)
CertificatesByAddress {
address: owned.address.to_string(),
certificate_summaries,
}
})
.collect::<HashMap<_, _>>();
.collect();

info!(
"got Certificates::Domain({}) query, answering with {:?}",
domain, certificates
);

Ok(Some(ResponseContent::Certificates(certificates)))
Ok(Some(ResponseContent::Certificates(
ListOfCertificatesByAddress { certificates },
)))
}

pub fn activate_listener(
Expand Down

0 comments on commit 75b5ade

Please sign in to comment.