commit 27050e2bbc709708ca5773fe253e2aeae25aa615
parent b2c7a7554f650fa29c25577853eab338f37fcd89
Author: lash <dev@holbrook.no>
Date: Fri, 23 Sep 2022 17:22:33 +0000
Partial implement of sequoia pgp for send cli, mutable trace test fail
Diffstat:
3 files changed, 67 insertions(+), 44 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -46,10 +46,14 @@ optional = true
version = "^2.5.0"
optional = true
+[dependencies.sequoia-openpgp]
+version = "^1.10.0"
+optional = true
+
[features]
pgpauth = ["pgp", "base64"]
dev = []
magic = ["tree_magic"]
meta = []
trace = []
-client = ["ureq"]
+client = ["ureq", "sequoia-openpgp"]
diff --git a/src/main_send.rs b/src/main_send.rs
@@ -1,4 +1,6 @@
-use log::{debug};
+use std::env::home_dir;
+
+use log::{info, debug};
use ureq::{Agent, AgentBuilder};
use env_logger;
use clap::{
@@ -7,6 +9,11 @@ use clap::{
};
use url::Url;
+use sequoia_openpgp::cert::prelude::CertParser;
+use sequoia_openpgp::parse::Parse;
+use sequoia_openpgp::parse::PacketParser;
+use sequoia_openpgp::policy::StandardPolicy;
+
use wala::record::{ResourceKey};
use wala::auth::{AuthResult};
@@ -67,6 +74,15 @@ fn main() {
let url_src = args.value_of("URL").unwrap();
let mut url = Url::parse(url_src).unwrap();
+ let mut have_auth = false;
+ let mut rk = ResourceKey {
+ v: Vec::new(),
+ };
+ let mut auth_data = AuthResult {
+ identity: Vec::new(),
+ error: false,
+ };
+
match args.value_of("key") {
Some(mut v) => {
debug!("have key {:?}", v);
@@ -80,23 +96,48 @@ fn main() {
v = nv.as_ref();
}
debug!("hex key input {:?}", &v);
- let auth_data = AuthResult {
- identity: v.as_bytes().to_vec(),
- error: false,
- };
-
- let rk = ResourceKey {
- v: d.clone(),
- };
+ auth_data.identity = hex::decode(&v).unwrap();
+ rk.v = d.clone();
let url_postfix = rk.pointer_for(&auth_data);
- //let url_postfix_str = String::from_utf8(url_postfix).unwrap();
let url_postfix_hex = hex::encode(url_postfix);
url = url.join(&url_postfix_hex).unwrap();
},
None => {},
}
+ let mut match_fp: Vec<u8> = Vec::new();
+ if rk.v.len() > 0 {
+ let p = StandardPolicy::new();
+ let fp_stem = home_dir().unwrap();
+ let fp = fp_stem.join(".gnupg/secring.gpg");
+ let pp = PacketParser::from_file(fp).unwrap();
+
+ // find a way to stop iter when key found
+ for v in CertParser::from(pp) {
+ match v {
+ Ok(r) => {
+ for k in r.keys()
+ .with_policy(&p, None)
+ .alive()
+ .revoked(false)
+ .for_signing()
+ .secret()
+ .map(|kk| kk.key()) {
+ debug!("check key {} {}", k.fingerprint(), hex::encode(&auth_data.identity));
+ if k.fingerprint().as_bytes() == auth_data.identity {
+ match_fp = auth_data.identity.clone();
+ }
+ }
+
+ },
+ Err(e) => {
+ panic!("keyparse fail: {:?}", e);
+ }
+ };
+ }
+ }
+ info!("signing with {}", hex::encode(&match_fp));
let ua = AgentBuilder::new().build();
let r = ua.put(url.as_str())
diff --git a/src/trace.rs b/src/trace.rs
@@ -96,14 +96,8 @@ mod tests {
let d = tempdir().unwrap();
let p = d.path();
let url = String::from("deadbeef");
- let r = RequestResult{
- typ: RequestResultType::Changed,
- v: Some(url),
- f: None,
- m: None,
- n: None,
- a: None,
- };
+ let mut r = RequestResult::new(RequestResultType::Changed);
+ r = r.with_content(url);
trace_request(&p, &r);
let fp = p.join(&r.v.unwrap());
let f = File::open(fp).unwrap();
@@ -116,14 +110,8 @@ mod tests {
let d = tempdir().unwrap();
let p = d.path();
let url = String::from("deadbeef");
- let r = RequestResult{
- typ: RequestResultType::Found,
- v: Some(url),
- f: None,
- m: None,
- n: None,
- a: None,
- };
+ let mut r = RequestResult::new(RequestResultType::Found);
+ r = r.with_content(url);
trace_request(&p, &r);
let fp = p.join(&r.v.unwrap());
let f = File::open(fp);
@@ -145,14 +133,9 @@ mod tests {
identity: vec!(),
error: false,
};
- let r = RequestResult{
- typ: RequestResultType::Changed,
- v: Some(url),
- f: None,
- m: None,
- n: None,
- a: Some(a),
- };
+ let mut r = RequestResult::new(RequestResultType::Changed);
+ r = r.with_content(url);
+ r = r.with_auth(a);
trace_request(&p, &r);
let fp = p.join(&r.v.unwrap());
let f = File::open(fp);
@@ -175,16 +158,11 @@ mod tests {
identity: id_b.to_vec(),
error: false,
};
- let r = RequestResult{
- typ: RequestResultType::Changed,
- v: Some(url),
- f: None,
- m: None,
- n: None,
- a: Some(a),
- };
+ let mut r = RequestResult::new(RequestResultType::Changed);
+ r = r.with_content(url);
+ r = r.with_auth(a);
trace_request(&p, &r);
- let fp = p.join(&r.v.unwrap());
+ let fp = p.join(r.v.unwrap());
let f = File::open(fp).unwrap();
let meta = f.metadata().unwrap();
let id_l = (id_b.len() * 2) as u64;