-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For now it can only parse an end entity DER certificate. Can be extended further later. Is not meant to be public, does not provide a stable interface. Useful mostly for debugging of WebPKI itself. ``` % cargo run -p webpki-bin -- print-cert ./tests/netflix/ca.der ... target/debug/webpki: failed to parse a cert ./tests/netflix/ca.der: BadDER zsh: exit 1 cargo run -p webpki-bin -- print-cert ./tests/netflix/ca.der % cargo run -p webpki-bin -- print-cert ./tests/netflix/ee.der ... cert ./tests/netflix/ee.der parsed successfully ``` I agree to license my contributions to each file under the terms given at the top of each file I changed.
- Loading branch information
1 parent
082a744
commit 3ed5630
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2021 Brian Smith. | ||
# | ||
# Permission to use, copy, modify, and/or distribute this software for any | ||
# purpose with or without fee is hereby granted, provided that the above | ||
# copyright notice and this permission notice appear in all copies. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES | ||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR | ||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
[package] | ||
authors = ["Brian Smith <[email protected]>"] | ||
description = "Test binaries for webpki crate." | ||
edition = "2018" | ||
license-file = "../LICENSE" | ||
name = "webpki-bin" | ||
repository = "https://github.com/briansmith/webpki" | ||
version = "0.0.0" | ||
publish = false | ||
|
||
[dependencies] | ||
webpki = { version = "*", path = "..", features = ["std"] } | ||
clap = "3.0.0-beta.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use clap::Clap; | ||
use std::convert::TryFrom; | ||
use std::env; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
use std::process; | ||
|
||
#[derive(Clap)] | ||
#[clap(about = "Parse and print a certificate")] | ||
struct PrintCert { | ||
filename: PathBuf, | ||
} | ||
|
||
#[derive(Clap)] | ||
enum Command { | ||
PrintCert(PrintCert), | ||
} | ||
|
||
#[derive(Clap)] | ||
#[clap(about = "Utility to debug webpki. Does not have a stable API.")] | ||
struct Opts { | ||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
fn print_error_and_exit(s: String) -> ! { | ||
let arg0 = env::args().next(); | ||
let arg0 = arg0.as_ref().map(|s| s.as_str()).unwrap_or("webpki"); | ||
eprintln!("{}: {}", arg0, s); | ||
process::exit(1) | ||
} | ||
|
||
fn print_cert(args: PrintCert) { | ||
let der = match fs::read(&args.filename) { | ||
Ok(der) => der, | ||
Err(e) => print_error_and_exit(format!( | ||
"cannot read file {}: {}", | ||
args.filename.display(), | ||
e | ||
)), | ||
}; | ||
|
||
match webpki::EndEntityCert::try_from(der.as_slice()) { | ||
Ok(cert) => cert, | ||
Err(e) => print_error_and_exit(format!( | ||
"failed to parse a cert {}: {}", | ||
&args.filename.display(), | ||
e | ||
)), | ||
}; | ||
|
||
eprintln!("cert {} parsed successfully", &args.filename.display()); | ||
// TODO: actually print something about the certificate | ||
} | ||
|
||
fn main() { | ||
let opts: Opts = Opts::parse(); | ||
match opts.command { | ||
Command::PrintCert(args) => print_cert(args), | ||
} | ||
} |