feat: parse pgp file works
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
test_key.asc
|
||||
.idea/
|
||||
# ---> Rust
|
||||
# Generated by Cargo
|
||||
|
||||
140
Cargo.lock
generated
140
Cargo.lock
generated
@@ -1,5 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.15.2"
|
||||
@@ -196,6 +198,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
@@ -635,6 +643,15 @@ version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lalrpop"
|
||||
version = "0.19.6"
|
||||
@@ -922,6 +939,17 @@ version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
|
||||
|
||||
[[package]]
|
||||
name = "pem"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"once_cell",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.5.1"
|
||||
@@ -974,6 +1002,12 @@ dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.9"
|
||||
@@ -1106,6 +1140,21 @@ version = "0.6.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.16.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"spin",
|
||||
"untrusted",
|
||||
"web-sys",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "runloop"
|
||||
version = "0.1.0"
|
||||
@@ -1238,12 +1287,28 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
|
||||
|
||||
[[package]]
|
||||
name = "simpledateformat"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a84014cdabee95bd9b17e3e55e80cd28f99df562a97f5e3ac92883f59bf04ff"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"quick-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbce6d4507c7e4a3962091436e56e95290cb71fa302d0d270e32130b75fbff27"
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
@@ -1437,6 +1502,12 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "untrusted"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
@@ -1467,21 +1538,90 @@ version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f"
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webauthn-cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"authenticator",
|
||||
"base64 0.13.0",
|
||||
"chrono",
|
||||
"clap",
|
||||
"hex",
|
||||
"openpgp-card",
|
||||
"openssl",
|
||||
"pem",
|
||||
"rand 0.8.4",
|
||||
"ring",
|
||||
"rust_util",
|
||||
"sequoia-openpgp",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"simpledateformat",
|
||||
"u2f",
|
||||
]
|
||||
|
||||
|
||||
@@ -19,3 +19,8 @@ hex = "0.4"
|
||||
u2f = "0.2"
|
||||
openpgp-card = "0.0.1"
|
||||
sequoia-openpgp = "1.3.0"
|
||||
chrono = "0.4.19"
|
||||
simpledateformat = "0.1.2"
|
||||
ring = "0.16.20"
|
||||
openssl = "0.10.35"
|
||||
pem = "0.8.3"
|
||||
|
||||
229
src/pgp.rs
229
src/pgp.rs
@@ -2,6 +2,13 @@ use clap::{ArgMatches, SubCommand, App, Arg};
|
||||
use crate::cmd::{Command, CommandError};
|
||||
use sequoia_openpgp::parse::Parse;
|
||||
use sequoia_openpgp::parse::{PacketParser, PacketParserResult};
|
||||
use sequoia_openpgp::Packet;
|
||||
use sequoia_openpgp::packet::Key;
|
||||
use chrono::{DateTime, Local};
|
||||
use openssl::rsa::Rsa;
|
||||
use sequoia_openpgp::crypto::mpi::PublicKey;
|
||||
use openssl::bn::BigNum;
|
||||
use pem::Pem;
|
||||
|
||||
pub struct CommandImpl;
|
||||
|
||||
@@ -10,107 +17,159 @@ impl Command for CommandImpl {
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||
SubCommand::with_name(self.name()).about("OpenPGP Card List subcommand")
|
||||
// .arg(Arg::with_name("app-id").long("app-id").default_value("https://example.com").help("App id"))
|
||||
// .arg(Arg::with_name("timeout").long("timeout").default_value("10").help("Timeout in seconds"))
|
||||
.arg(Arg::with_name("in").long("in").takes_value(true).help("File input"))
|
||||
.arg(Arg::with_name("detail").long("detail").help("Detail output"))
|
||||
.arg(Arg::with_name("json").long("json").help("JSON output"))
|
||||
}
|
||||
|
||||
fn run(&self, _arg_matches: &ArgMatches, _sub_arg_matches: &ArgMatches) -> CommandError {
|
||||
let p = PacketParser::from_bytes(b"-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
Comment: GPGTools - https://gpgtools.org
|
||||
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
|
||||
let in_file = sub_arg_matches.value_of("in");
|
||||
let show_detail = sub_arg_matches.is_present("detail");
|
||||
|
||||
mQINBFbFsmEBEACvuRVhMfEWNkP2RP7D3sEaId+qXKi6UnXRxGppbBff+Zkp+h4Y
|
||||
mQEOCUWct+C0eFeK8+pFKfvewJfozQcLNKr0z92uSaz8fxx5wzTxKhl1lMzRNWv9
|
||||
zzDRkDsimh16v0r/0t0akiChzepryF1jacdPAZgnndpC/fad45yDen+/Op3OCbBu
|
||||
TgkuNwgyE65NSPjEzw4yeTFGnLL34aGLbZehlcPG7yZ4jY9zyMz7OlFhvTB3Tp13
|
||||
bfWbTcIrzQsDBK8ift0YUCv7FMXlcqilcdi+5P71KyGzNs/j6lKpsQdmEk5fX+iz
|
||||
5Sjwop/KyJ8kEp8oJW9VaGjxAJaheCI244ndxihOF9bBSkhLVLnV6X9889KTcrb3
|
||||
mOVkA433ISzN3MocZUY6u0nt71dLEoheqEa6zZcDXh4y+FB1o6B39uxxchh7hjOq
|
||||
9qq9VGINQ/xvMD7jDRy0HTD0dEUYrmVqNOf9BC+Qo/0lBebpNvYYH7CO5TfA9eEp
|
||||
FaxwTNsdXAyrZaJpgfm9ZWEcjqVupdxaS9mLaBldA/KsArNRq7VnaUE3bGLZy/n7
|
||||
0km2Hmkd5u4s5Zu5/VZXidHV91I10bsYaaMb3nXD/VtOoiXM3hWXqR2it7i7jlTi
|
||||
Q7hd/serxvyTzKzXTsQ2mA7uUH0ougwwUpK+Mb4Q8QXeDzLAppLyZlBf6wARAQAB
|
||||
tDZIYXR0ZXIgSmlhbmcgKEhhdHRlcidzIDQwOTYgUEdQL0MpIDxqaHQ1OTQ1QGdt
|
||||
YWlsLmNvbT6JAjcEEwEKACEFAlbFsmECGwMFCw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6w3788+p52yK8RhUp+jj3e6HQmzYABg5qsU/Aq7Q
|
||||
kTMqsV+W12P+SetefiSdzJWvhOsyR1IivLJCQdgNQFRf6QRm0yuOJCX9I/Q9LNGQ
|
||||
qwL/86jT1pM5dOx97h7VWf7wA2cpPARCIXnFftz08fG9FFJIM8zQuCWeVQqnVQ8X
|
||||
be3ar+HbgDMsAm5MvBu+7Ni/1vSkevxw+EbCavSMnz5k1HmABZceHvSP/K+CSCB4
|
||||
XA6Z+GbXx/8HTqUiho6aqifsoLBkDhwxNYHGtZVIigI3N9JIu9JILgCdEtkO7LVG
|
||||
EjqUEteCn41f3y3YpzQLjOmYF7LNLUIYaD3KoL6fnrOXPdbq0dYsoWHWQ4ndlNbn
|
||||
mZRgfN/IatnSXcA+keRUd1bXgB4jVhv0P38jH9DsrYeb3xOmd6RSCdKFBLV4PkGZ
|
||||
+6FdbJQ5ZmvmhYinyAP5yqIqig/9W6v/BnQlbocEEdDLfY1UMUl7kSB8Wz9t74BH
|
||||
1rkCwHJxVp+tOfY+pCG0aVHFW6WIHFR0dFpc4D2Wksed1m4cqjmbqfPANu4G01wX
|
||||
tYVrOQO08M4xbeeClpW9DqxR7toB860Hoq8aonXikmaJXxrv3V6/rLofCHInH22a
|
||||
VvhSegJ3QeP4bkBgxW1X6t1QgQGRJnundzv4U+tKbltS5hPmvcU=
|
||||
=HzsD
|
||||
-----END PGP PUBLIC KEY BLOCK-----");
|
||||
// TODO ...
|
||||
let mut ppr = p.unwrap();
|
||||
let in_file = match in_file {
|
||||
Some(i) => i,
|
||||
None => return simple_error!("Input file must assined"),
|
||||
};
|
||||
|
||||
let in_file_bytes = opt_result!(std::fs::read(in_file), "Read file: {}, failed: {}", in_file);
|
||||
let p = PacketParser::from_bytes(&in_file_bytes);
|
||||
let mut ppr = opt_result!(p, "Parse file: {}, failed: {}", in_file);
|
||||
while let PacketParserResult::Some(pp) = ppr {
|
||||
success!(">> >> {:?}", &pp.packet);
|
||||
// Start parsing the next packet, recursing.
|
||||
match &pp.packet {
|
||||
Packet::Signature(signature) => {
|
||||
debugging!("Found signature: {:?}", signature);
|
||||
information!("Found signature: {:?} - {:?} [{:?}]", signature.get_issuers(), signature.hash_algo(), signature.features());
|
||||
}
|
||||
Packet::OnePassSig(one_pass_sig) => {
|
||||
information!("Found one pass sig: {:?}", one_pass_sig);
|
||||
}
|
||||
Packet::PublicKey(public_key) => {
|
||||
debugging!("Found public key: {:?}", public_key);
|
||||
match public_key {
|
||||
Key::V4(key4) => {
|
||||
let mut public_key4 = String::with_capacity(512);
|
||||
public_key4.push_str(&format!("\n\tKey ID: {:?}", key4.keyid()));
|
||||
public_key4.push_str(&format!("\n\tFinger print {:?}", key4.fingerprint()));
|
||||
public_key4.push_str(&format!("\n\tHash algo security: {:?}", key4.hash_algo_security()));
|
||||
// public_key4.push_str(&format!("\n\tKey handle {:?}", key4.key_handle()));
|
||||
let creation_time: DateTime<Local> = DateTime::from(key4.creation_time());
|
||||
let creation_time_str = simpledateformat::fmt("yyyy-MM-dd HH:mm:ss").unwrap().format(&creation_time);
|
||||
public_key4.push_str(&format!("\n\tCreation time {}", creation_time_str));
|
||||
public_key4.push_str(&format!("\n\tPublic algo: {:?}", key4.pk_algo()));
|
||||
if show_detail {
|
||||
if let Some(pubkey_pem) = public_key_pem(key4.mpis()) {
|
||||
public_key4.push_str(&format!("\n\tPublic key PEM: {}", pubkey_pem));
|
||||
}
|
||||
}
|
||||
information!("Found public key: {}", public_key4);
|
||||
}
|
||||
unknown => warning!("Unknown key: {:?}", unknown),
|
||||
}
|
||||
}
|
||||
Packet::PublicSubkey(public_sub_key) => {
|
||||
debugging!("Found public sub key: {:?}", public_sub_key);
|
||||
match public_sub_key {
|
||||
Key::V4(key4) => {
|
||||
let mut public_key4 = String::with_capacity(512);
|
||||
public_key4.push_str(&format!("\n\tKey ID: {:?}", key4.keyid()));
|
||||
public_key4.push_str(&format!("\n\tFinger print {:?}", key4.fingerprint()));
|
||||
public_key4.push_str(&format!("\n\tHash algo security: {:?}", key4.hash_algo_security()));
|
||||
let creation_time: DateTime<Local> = DateTime::from(key4.creation_time());
|
||||
let creation_time_str = simpledateformat::fmt("yyyy-MM-dd HH:mm:ss").unwrap().format(&creation_time);
|
||||
public_key4.push_str(&format!("\n\tCreation time {}", creation_time_str));
|
||||
public_key4.push_str(&format!("\n\tPublic algo: {:?}", key4.pk_algo()));
|
||||
if show_detail {
|
||||
if let Some(pubkey_pem) = public_key_pem(key4.mpis()) {
|
||||
public_key4.push_str(&format!("\n\tPublic key PEM: {}", pubkey_pem));
|
||||
}
|
||||
}
|
||||
information!("Found public key: {}", public_key4);
|
||||
}
|
||||
unknown => warning!("Unknown key: {:?}", unknown),
|
||||
}
|
||||
}
|
||||
Packet::SecretKey(secret_key) => {
|
||||
information!("Found secret key: {:?}", secret_key);
|
||||
}
|
||||
Packet::SecretSubkey(secret_sub_key) => {
|
||||
information!("Found secret sub key: {:?}", secret_sub_key);
|
||||
}
|
||||
Packet::Marker(marker) => {
|
||||
information!("Found marker: {:?}", marker);
|
||||
}
|
||||
Packet::Trust(trust) => {
|
||||
information!("Found trust: {:?}", trust);
|
||||
}
|
||||
Packet::UserID(user_id) => {
|
||||
information!("Found user ID: {}", String::from_utf8_lossy(user_id.value()));
|
||||
}
|
||||
Packet::UserAttribute(user_attribute) => {
|
||||
information!("Found user attribute: {:?}", user_attribute);
|
||||
}
|
||||
Packet::Literal(literal) => {
|
||||
information!("Found literal: {:?}", literal);
|
||||
}
|
||||
Packet::CompressedData(compressed_data) => {
|
||||
information!("Found compressed data: {:?}", compressed_data);
|
||||
}
|
||||
Packet::PKESK(pkesk) => {
|
||||
information!("Found PKESK: {:?}", pkesk);
|
||||
}
|
||||
Packet::SKESK(skesk) => {
|
||||
information!("Found SKESK: {:?}", skesk);
|
||||
}
|
||||
Packet::SEIP(seip) => {
|
||||
information!("Found SEIP: {:?}", seip);
|
||||
}
|
||||
Packet::MDC(mdc) => {
|
||||
information!("Found MDC: {:?}", mdc);
|
||||
}
|
||||
Packet::AED(aed) => {
|
||||
information!("Found AED: {:?}", aed);
|
||||
}
|
||||
Packet::Unknown(unknown) => {
|
||||
warning!("Found unknown: {:?}", unknown);
|
||||
}
|
||||
unknown => {
|
||||
warning!("Found UNKNOWN: {:?}", unknown);
|
||||
}
|
||||
}
|
||||
|
||||
ppr = pp.recurse()?.1;
|
||||
}
|
||||
|
||||
if let PacketParserResult::EOF(eof) = ppr {
|
||||
// information!("{:?}", eof);
|
||||
debugging!("{:?}", eof);
|
||||
if eof.is_message().is_ok() {
|
||||
information!("IS MESSAGE");
|
||||
information!("FILE IS MESSAGE");
|
||||
} else if eof.is_cert().is_ok() {
|
||||
information!("IS CERT");
|
||||
information!("FILE IS CERT");
|
||||
} else if eof.is_keyring().is_ok() {
|
||||
information!("IS KEYRING");
|
||||
information!("FILE IS KEYRING");
|
||||
} else {
|
||||
information!("IS OTHER");
|
||||
information!("FILE IS OTHER");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn public_key_pem(public_key: &PublicKey) -> Option<String> {
|
||||
match public_key {
|
||||
PublicKey::RSA { e, n } => {
|
||||
let rr = Rsa::from_public_components(
|
||||
BigNum::from_slice(n.value()).unwrap(),
|
||||
BigNum::from_slice(e.value()).unwrap(),
|
||||
);
|
||||
let pubkey_pem_obj = Pem {
|
||||
tag: String::from("RSA PUBLIC KEY"),
|
||||
contents: rr.unwrap().public_key_to_der().unwrap(),
|
||||
};
|
||||
Some(pem::encode(&pubkey_pem_obj))
|
||||
}
|
||||
_ => {
|
||||
warning!("Not rsa public key: {:?}", public_key);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user