feat: sig/enc ok now
This commit is contained in:
22
src/pgp.rs
22
src/pgp.rs
@@ -3,12 +3,13 @@ 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 sequoia_openpgp::packet::{Key, Signature};
|
||||
use chrono::{DateTime, Local};
|
||||
use openssl::rsa::Rsa;
|
||||
use sequoia_openpgp::crypto::mpi::PublicKey;
|
||||
use openssl::bn::BigNum;
|
||||
use pem::Pem;
|
||||
use sequoia_openpgp::packet::signature::subpacket::SubpacketTag;
|
||||
|
||||
pub struct CommandImpl;
|
||||
|
||||
@@ -38,12 +39,22 @@ impl Command for CommandImpl {
|
||||
match &pp.packet {
|
||||
Packet::Signature(signature) => {
|
||||
debugging!("Found signature: {:?}", signature);
|
||||
match signature {
|
||||
Signature::V4(sig) => {
|
||||
// information!("-----> {:?}", sig.hashed_area());
|
||||
if let Some(sub_package) = sig.hashed_area().subpacket(SubpacketTag::KeyFlags) {
|
||||
information!("Found sub key flags: {:?}", sub_package);
|
||||
}
|
||||
}
|
||||
unknown => warning!("Unknown signature: {:?}", unknown),
|
||||
}
|
||||
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) => {
|
||||
information!("{}", "-".repeat(88));
|
||||
debugging!("Found public key: {:?}", public_key);
|
||||
match public_key {
|
||||
Key::V4(key4) => {
|
||||
@@ -67,6 +78,7 @@ impl Command for CommandImpl {
|
||||
}
|
||||
}
|
||||
Packet::PublicSubkey(public_sub_key) => {
|
||||
information!("{}", "-".repeat(88));
|
||||
debugging!("Found public sub key: {:?}", public_sub_key);
|
||||
match public_sub_key {
|
||||
Key::V4(key4) => {
|
||||
@@ -161,8 +173,14 @@ fn public_key_pem(public_key: &PublicKey) -> Option<String> {
|
||||
BigNum::from_slice(n.value()).unwrap(),
|
||||
BigNum::from_slice(e.value()).unwrap(),
|
||||
);
|
||||
// let from = b"hello";
|
||||
// let mut to = vec![0_u8; 4096/8];
|
||||
// let mut_to = to.as_mut_slice();
|
||||
// let rt = rr.clone().unwrap().public_encrypt(from, mut_to, Padding::PKCS1);
|
||||
// println!("!!! {:?}", rt);
|
||||
// println!("??? {}", hex::encode(mut_to));
|
||||
let pubkey_pem_obj = Pem {
|
||||
tag: String::from("RSA PUBLIC KEY"),
|
||||
tag: String::from("PUBLIC KEY"),
|
||||
contents: rr.unwrap().public_key_to_der().unwrap(),
|
||||
};
|
||||
Some(pem::encode(&pubkey_pem_obj))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use clap::{ArgMatches, SubCommand, App, Arg};
|
||||
use crate::cmd::{Command, CommandError};
|
||||
use openpgp_card::OpenPGPCard;
|
||||
use openpgp_card::{OpenPGPCard, DecryptMe, Hash};
|
||||
|
||||
pub struct CommandImpl;
|
||||
|
||||
@@ -35,6 +35,42 @@ impl Command for CommandImpl {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(pass) = std::env::var("PASS") {
|
||||
if let Ok(list) = OpenPGPCard::list_cards() {
|
||||
// pw1_81 for signature
|
||||
// openssl dgst -sha256 -verify aa -signature sig LICENSE
|
||||
for card in list {
|
||||
match card.verify_pw1_81(&pass) {
|
||||
Result::Ok(user) => {
|
||||
let h = hex::decode("8f25018489d6fe0dec34a352314c38dc146247b7de65735790f4398a92afa84b").unwrap();
|
||||
let mut hh = [0_u8; 0x20];
|
||||
for i in 0..hh.len() {
|
||||
hh[i] = h[i];
|
||||
}
|
||||
let aa = user.signature_for_hash(Hash::SHA256(hh));
|
||||
println!("////// {}", hex::encode(&aa.unwrap()));
|
||||
}
|
||||
Result::Err(_) => { failure!("error!"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Ok(list) = OpenPGPCard::list_cards() {
|
||||
// pw1_82 for encryption
|
||||
// PKCSv1.5
|
||||
for card in list {
|
||||
match card.verify_pw1_82(&pass) {
|
||||
Result::Ok(user) => {
|
||||
let e = hex::decode("705d2af390174706c42de8361c4cb7a4684e06216305d6da70cab9248fa1abb9fac2b4c004187a53b9ed2b7f8ab75b20a54a12e6be672a742504b38d07b192f1f815285b6605b06a1a86d97f14ffcf41a9b3463ff3d8b2afe63e53aeb43048fef358639e5589fab8000d0805fe9145b5457cb5f7f91243b25181d1c7853b384a3bba45143a5ceeb2612463e51fbce52154e20726e6cf58f0317ebdf92613a10aec2b34224b0ffd1333c475cab473cf66aa895700e6681d20d12ddc897e0731226d4dc6bc9bd2e4aca02dba49175a35e45f9f3b56973a0381c777dac73a7eb8a04bfde45d3c19f44f740a193439da6829bf4beba90529c3017bddbd64aacbad92d3632260d5b6a7b5565fd852f17cff031fbdc2700d6acc2dedaaad307aaf7bb2de8f2b02faf84d94fa046e4ce487480918a54ca4672e1388deae8881436f454e65263a4984003495031126b4488ab27c6f4555f16bdd0fe2b9132443bbf49aa9c19864c4b1b917914e9c070a0327e52cf3b536e218a56ec97e12979e5981977e008eb9180d02da322c1a019fa535d77b67912039bc699b291d950714367d1c4a4a41edc86b1ab99d101da75a61c762fee28f8a004fb7656800623ac95d88c1978f18a1d286916cdab9c9f0f91d500cffdc8cb2853011a352bfa5f1fcd4a59720004153fb644afef083909c6a537ebc24255c1284ecf665a8cb7212672051e8b4").unwrap();
|
||||
println!(":::: {}", e.len());
|
||||
let x = user.decrypt(DecryptMe::RSA(&e));
|
||||
println!(">>>>>> {:?}", x);
|
||||
}
|
||||
Result::Err(_) => { failure!("error!"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user