Skip to content

Commit bc3e6ec

Browse files
committed
Add --ca option to tedge cert renew
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
1 parent a2b4369 commit bc3e6ec

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

crates/core/tedge/src/cli/certificate/cli.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,17 @@ pub enum TEdgeCertCli {
6767
#[clap(long = "csr-path", global = true, value_hint = ValueHint::FilePath)]
6868
csr_path: Option<Utf8PathBuf>,
6969

70-
/// Force the renewal of self-signed certificates as self-signed
70+
/// Certificate Authority (CA) used to renew the certificate
7171
///
72-
/// This can be used to bypass the default behavior
73-
/// which is to forward the renewal request to the cloud CA
74-
/// even if the current certificate has not been signed by this CA.
72+
/// Cumulocity CA is currently the only supported one and this is the default,
73+
/// even if the current certificate has not been signed by Cumulocity.
7574
/// In most cases, the default behavior is what you want:
7675
/// substitute a proper CA-signed certificate for a self-signed certificate.
7776
///
7877
/// However, if this is not the case, or if the cloud endpoint doesn't provide a CA:
79-
/// use `--self-signed` to get a renewed self-signed certificate.
80-
#[clap(long = "self-signed", default_value_t = false)]
81-
self_signed_only: bool,
78+
/// use `--ca self-signed` to get a renewed self-signed certificate.
79+
#[clap(long = "ca", default_value_t = CA::C8y)]
80+
ca: CA,
8281

8382
#[clap(subcommand)]
8483
cloud: Option<CloudArg>,
@@ -132,6 +131,15 @@ pub enum TEdgeCertCli {
132131
Download(DownloadCertCli),
133132
}
134133

134+
#[derive(clap::ValueEnum, Clone, Debug, Eq, PartialEq, strum_macros::Display)]
135+
pub enum CA {
136+
#[strum(serialize = "self-signed")]
137+
SelfSigned,
138+
139+
#[strum(serialize = "c8y")]
140+
C8y,
141+
}
142+
135143
impl BuildCommand for TEdgeCertCli {
136144
fn build_command(
137145
self,
@@ -287,7 +295,7 @@ impl BuildCommand for TEdgeCertCli {
287295
TEdgeCertCli::Renew {
288296
csr_path,
289297
cloud,
290-
self_signed_only,
298+
ca,
291299
} => {
292300
let cloud: Option<Cloud> = cloud.map(<_>::try_into).transpose()?;
293301
let cert_path = config.device_cert_path(cloud.as_ref())?.to_owned();
@@ -310,15 +318,15 @@ impl BuildCommand for TEdgeCertCli {
310318
}
311319
};
312320

313-
if is_self_signed && self_signed_only {
321+
if is_self_signed && ca == CA::SelfSigned {
314322
let cmd = RenewCertCmd {
315323
cert_path,
316324
new_cert_path,
317325
key_path,
318326
csr_template,
319327
};
320328
cmd.into_boxed()
321-
} else if self_signed_only {
329+
} else if ca == CA::SelfSigned {
322330
return Err(
323331
anyhow!("Cannot renew certificate with `--self-signed`: {cert_path} is not self-signed").into()
324332
);

tests/RobotFramework/tests/tedge/tedge_upload_cert.robot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Renew the certificate
3838
[Setup] Setup With Self-Signed Certificate
3939
Execute Command sudo tedge disconnect c8y
4040
${output}= Execute Command
41-
... sudo tedge cert renew --self-signed
41+
... sudo tedge cert renew --ca self-signed
4242
... stderr=${True}
4343
... stdout=${False}
4444
... ignore_exit_code=${True}
@@ -57,7 +57,7 @@ Cert upload prompts for username (from stdin)
5757
[Setup] Setup With Self-Signed Certificate
5858
Execute Command sudo tedge disconnect c8y
5959
${output}= Execute Command
60-
... sudo tedge cert renew --self-signed
60+
... sudo tedge cert renew --ca self-signed
6161
... stderr=${True}
6262
... stdout=${False}
6363
... ignore_exit_code=${True}
@@ -75,7 +75,7 @@ Cert upload supports reading username/password from go-c8y-cli env variables
7575
[Setup] Setup With Self-Signed Certificate
7676
Execute Command sudo tedge disconnect c8y
7777
${output}= Execute Command
78-
... sudo tedge cert renew --self-signed
78+
... sudo tedge cert renew --ca self-signed
7979
... stderr=${True}
8080
... stdout=${False}
8181
... ignore_exit_code=${True}
@@ -93,7 +93,7 @@ Renew certificate fails
9393
[Setup] Setup Without Certificate
9494
Execute Command sudo tedge cert remove
9595
${output}= Execute Command
96-
... sudo tedge cert renew --self-signed
96+
... sudo tedge cert renew --ca self-signed
9797
... stderr=${True}
9898
... stdout=${False}
9999
... ignore_exit_code=${True}

tests/RobotFramework/tests/tedge/tedge_upload_cert_custom_root_cert_path.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tedge cert upload c8y respects root cert path
1515
[Setup] Setup With Self-Signed Certificate
1616
Execute Command sudo tedge disconnect c8y
1717
${output}= Execute Command
18-
... sudo tedge cert renew --self-signed
18+
... sudo tedge cert renew --ca self-signed
1919
... stderr=${True}
2020
... stdout=${False}
2121
... ignore_exit_code=${True}

0 commit comments

Comments
 (0)