Skip to content

Commit bcab517

Browse files
committed
Print out root certificate details too
1 parent b22ab4a commit bcab517

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

signature/examples/balrog-cli.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
15
use clap::Parser;
26
use ureq;
7+
use ring::digest;
38
use std::{io, process};
49
use std::io::Write;
510
use x509_parser::time::ASN1Time;
611

712
use signature::{Balrog, BalrogError, parse_pem_chain};
813

9-
const PROD_ROOT_HASH: &str = "97e8ba9cf12fb3de53cc42a4e6577ed64df493c247b414fea036818d3823560e";
10-
1114
/// Program arguments
1215
#[derive(Parser, Debug)]
1316
#[command(version, about, long_about = None)]
1417
struct Args {
1518
/// Balrog update URL
1619
url: String,
17-
18-
/// Root certificate hash
19-
#[arg(short, long, default_value_t = PROD_ROOT_HASH.to_string())]
20-
root: String,
2120
}
2221

2322
struct BalrogData {
@@ -67,7 +66,7 @@ fn fetch(args: &Args) -> Result<BalrogData, ureq::Error> {
6766
})
6867
}
6968

70-
fn run(args: &Args, data: &BalrogData) -> Result<(), BalrogError> {
69+
fn run(data: &BalrogData) -> Result<(), BalrogError> {
7170
let chain = parse_pem_chain(data.chain.as_slice())?;
7271
let balrog = Balrog::new(&chain)?;
7372

@@ -84,8 +83,22 @@ fn run(args: &Args, data: &BalrogData) -> Result<(), BalrogError> {
8483
}
8584
}
8685
}
86+
if balrog.chain.len() >= 2 {
87+
let root = balrog.chain.last().unwrap();
88+
for cn in root.subject().iter_common_name() {
89+
let name = cn.as_str()?;
90+
eprintln!("Root hostname: {}", name);
91+
}
92+
93+
if let Some(ext) = root.subject_alternative_name()? {
94+
for san in ext.value.general_names.iter() {
95+
eprintln!("Root alternative name: {}", san);
96+
}
97+
}
8798

88-
//let roothash = hex::decode(args.root.as_str()).unwrap();
99+
let digest = digest::digest(&digest::SHA256, root.as_raw());
100+
eprintln!("Root hash: {}", hex::encode(digest));
101+
}
89102

90103
balrog.verify(
91104
data.payload.as_slice(),
@@ -114,7 +127,7 @@ fn main() {
114127
};
115128

116129
// Run the cryptographic validation
117-
let result = run(&args, &data);
130+
let result = run(&data);
118131

119132
// Write the payload data to stdout.
120133
let _ = io::stdout().write_all(data.payload.as_slice());

0 commit comments

Comments
 (0)