Skip to content

Commit 5131ce2

Browse files
fix: cert gen
1 parent 6ab2efd commit 5131ce2

File tree

10 files changed

+72
-70
lines changed

10 files changed

+72
-70
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ incremental = false
4949
strip = true
5050

5151
[workspace.package]
52-
version = "0.2.23-rc.3"
52+
version = "0.2.23-rc.4"
5353
edition = "2024"
5454
license = "MIT"
5555
publish = false

crates/wazuh-cert-oauth2-client/src/flow.rs

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,50 @@ use crate::services::save_to_file::save_cert_and_key;
1010
use crate::services::set_name::set_name;
1111
use crate::services::stop_agent::stop_agent;
1212
use crate::services::submit_csr::submit_csr;
13+
use crate::shared::cli::Opt;
1314

1415
#[derive(Debug, Clone)]
1516
pub struct FlowParams {
16-
pub issuer: String,
17-
pub audience_csv: String,
18-
pub client_id: String,
19-
pub client_secret: Option<String>,
20-
pub endpoint: String,
21-
pub is_service_account: bool,
22-
pub cert_path: String,
23-
pub ca_cert_path: String,
24-
pub key_path: String,
25-
pub agent_control: bool,
17+
issuer: String,
18+
audience_csv: String,
19+
client_id: String,
20+
client_secret: Option<String>,
21+
endpoint: String,
22+
is_service_account: bool,
23+
cert_path: String,
24+
ca_cert_path: String,
25+
key_path: String,
26+
agent_control: bool,
27+
}
28+
29+
impl From<Opt> for FlowParams {
30+
fn from(value: Opt) -> Self {
31+
match value {
32+
Opt::OAuth2 {
33+
issuer,
34+
audience,
35+
client_id,
36+
client_secret,
37+
endpoint,
38+
is_service_account,
39+
cert_path,
40+
ca_cert_path,
41+
key_path,
42+
agent_control,
43+
} => Self {
44+
issuer,
45+
audience_csv: audience,
46+
client_id,
47+
client_secret,
48+
endpoint,
49+
is_service_account,
50+
cert_path,
51+
key_path,
52+
agent_control,
53+
ca_cert_path,
54+
},
55+
}
56+
}
2657
}
2758

2859
pub async fn run_oauth2_flow(params: &FlowParams) -> AppResult<()> {

crates/wazuh-cert-oauth2-client/src/main.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,14 @@ async fn main() {
3131
/// Orchestrates the CSR flow: stop agent, obtain token, validate claims,
3232
/// generate CSR and key, submit CSR, save cert+key, set agent name, restart agent.
3333
async fn app() -> AppResult<()> {
34-
match Opt::try_parse()? {
35-
Opt::OAuth2 {
36-
issuer,
37-
audience,
38-
client_id,
39-
client_secret,
40-
endpoint,
41-
is_service_account,
42-
cert_path,
43-
ca_cert_path,
44-
key_path,
45-
agent_control,
46-
} => {
47-
let params = FlowParams {
48-
issuer,
49-
audience_csv: audience,
50-
client_id,
51-
client_secret,
52-
endpoint,
53-
is_service_account,
54-
cert_path,
55-
key_path,
56-
agent_control,
57-
ca_cert_path,
58-
};
59-
run_oauth2_flow(&params).await
34+
match Opt::try_parse() {
35+
Ok(opt) => {
36+
let params = FlowParams::from(opt);
37+
run_oauth2_flow(&params).await?;
38+
39+
Ok(())
6040
}
41+
_ => Ok(()),
6142
}
6243
}
6344

crates/wazuh-cert-oauth2-client/src/shared/cli.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ use clap::Parser;
44

55
#[derive(Parser, Debug)]
66
#[command(
7+
version,
78
name = "Wazuh Cert Auth CLI",
8-
about = "Installs and configures Wazuh Certificate Authority"
9+
about = "Wazuh Certificate Authority",
10+
long_about = "Installs and configures Wazuh Certificate Authority"
911
)]
1012
pub enum Opt {
1113
#[command(about = "Configure OAuth2 for Wazuh")]

crates/wazuh-cert-oauth2-healthcheck/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ license.workspace = true
77
authors.workspace = true
88

99
[dependencies]
10-
tokio.workspace = true
1110
reqwest.workspace = true
1211
env_logger.workspace = true
1312
log.workspace = true
1413
clap.workspace = true
14+
15+
[dependencies.tokio]
16+
workspace = true
17+
features = ["rt"]

crates/wazuh-cert-oauth2-server/src/shared/certs/extensions.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,41 +65,27 @@ pub(crate) fn append_client_eku(builder: &mut openssl::x509::X509Builder) -> App
6565
Ok(())
6666
}
6767

68-
pub(crate) fn append_san_cn(
68+
pub(crate) fn append_san_cn_and_identity_uri(
6969
builder: &mut openssl::x509::X509Builder,
7070
ca_cert: &X509Ref,
7171
subject_cn: &str,
72-
) -> AppResult<()> {
73-
let san = SubjectAlternativeName::new()
74-
.dns(subject_cn)
75-
.build(&builder.x509v3_context(Some(ca_cert), None))?;
76-
builder.append_extension(san)?;
77-
Ok(())
78-
}
79-
80-
/// Add a SAN URI that binds the Keycloak issuer (realm) and subject together.
81-
/// Uses the form: "{iss}#sub={sub}", which remains a valid absolute URI while
82-
/// clearly associating the realm (from iss) with the subject identifier.
83-
pub(crate) fn append_san_identity_uri(
84-
builder: &mut openssl::x509::X509Builder,
85-
ca_cert: &X509Ref,
8672
issuer: &str,
8773
subject_sub: &str,
8874
) -> AppResult<()> {
89-
// Best-effort: ensure issuer parses as a URL; if not, still include a URN form
9075
let value = match Url::parse(issuer) {
9176
Ok(url) => {
92-
// Reconstruct without params to avoid accidental leakage; keep path/host which include realm
9377
let mut base = String::new();
9478
base.push_str(url.as_str());
95-
// Append the subject in a fragment to keep it within the URI
9679
format!("{}#sub={}", base.trim_end_matches('#'), subject_sub)
9780
}
9881
Err(_) => format!("urn:keycloak:sub:{}", subject_sub),
9982
};
83+
10084
let san = SubjectAlternativeName::new()
85+
.dns(subject_cn)
10186
.uri(&value)
10287
.build(&builder.x509v3_context(Some(ca_cert), None))?;
88+
10389
builder.append_extension(san)?;
10490
Ok(())
10591
}

crates/wazuh-cert-oauth2-server/src/shared/certs/sign.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::models::ca_config::CaProvider;
99
use crate::shared::ledger::Ledger;
1010

1111
use super::{
12-
append_client_eku, append_core_extensions, append_crl_dp, append_key_usage, append_san_cn,
13-
append_san_identity_uri, enforce_key_policy, set_serial_number, set_subject_and_pubkey,
12+
append_client_eku, append_core_extensions, append_crl_dp, append_key_usage,
13+
append_san_cn_and_identity_uri, enforce_key_policy, set_serial_number, set_subject_and_pubkey,
1414
set_validity_1y, sign_builder,
1515
};
1616

@@ -95,8 +95,7 @@ fn sign_csr_with_ca(
9595
append_crl_dp(&mut builder, ca_cert, crl_dist_url)?;
9696
append_key_usage(&mut builder, is_rsa)?;
9797
append_client_eku(&mut builder)?;
98-
append_san_cn(&mut builder, ca_cert, subject_cn)?;
99-
append_san_identity_uri(&mut builder, ca_cert, issuer, subject_cn)?;
98+
append_san_cn_and_identity_uri(&mut builder, ca_cert, subject_cn, issuer, subject_cn)?;
10099
sign_builder(&mut builder, ca_key)?;
101100
Ok(builder.build())
102101
}

scripts/install.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $ErrorActionPreference = "Stop"
55
# Default log level and application details
66
$LOG_LEVEL = if ($env:LOG_LEVEL -ne $null) { $env:LOG_LEVEL } else { "INFO" }
77
$APP_NAME = if ($env:APP_NAME -ne $null) { $env:APP_NAME } else { "wazuh-cert-oauth2-client" }
8-
$DEFAULT_WOPS_VERSION = "0.2.23-rc.3"
8+
$DEFAULT_WOPS_VERSION = "0.2.23-rc.4"
99
$WOPS_VERSION = if ($env:WOPS_VERSION -ne $null) { $env:WOPS_VERSION } else { $DEFAULT_WOPS_VERSION }
1010
$OSSEC_CONF_PATH = if ($env:OSSEC_CONF_PATH -ne $null) { $env:OSSEC_CONF_PATH } else { "C:\Program Files (x86)\ossec-agent\ossec.conf" }
1111
$USER = "root"

scripts/install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ fi
1010
# Default log level and application details
1111
LOG_LEVEL=${LOG_LEVEL:-INFO}
1212
APP_NAME=${APP_NAME:-"wazuh-cert-oauth2-client"}
13-
WOPS_VERSION=${WOPS_VERSION:-"0.2.23-rc.3"}
13+
WOPS_VERSION=${WOPS_VERSION:-"0.2.23-rc.4"}
1414
USER="root"
1515
GROUP="wazuh"
1616

1717
# Determine the OS and architecture
1818
case "$(uname)" in
19-
"Linux") OS="unknown-linux-musl"; BIN_DIR="/var/ossec/bin"; OSSEC_CONF_PATH="/var/ossec/etc/ossec.conf" ;;
20-
"Darwin") OS="apple-darwin"; BIN_DIR="/Library/Ossec/bin"; OSSEC_CONF_PATH="/Library/Ossec/etc/ossec.conf" ;;
19+
"Linux") OS="unknown-linux-musl"; BIN_DIR=${BIN_DIR:-"/var/ossec/bin"}; OSSEC_CONF_PATH="/var/ossec/etc/ossec.conf" ;;
20+
"Darwin") OS="apple-darwin"; BIN_DIR=${BIN_DIR:-"/Library/Ossec/bin"}; OSSEC_CONF_PATH="/Library/Ossec/etc/ossec.conf" ;;
2121
*) error_exit "Unsupported operating system: $(uname)" ;;
2222
esac
2323

0 commit comments

Comments
 (0)