Skip to content

Commit 3b361eb

Browse files
committed
feat: v1.3.0, support init-piv
1 parent 381b2e5 commit 3b361eb

14 files changed

Lines changed: 369 additions & 107 deletions

Cargo.lock

Lines changed: 26 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tiny-encrypt"
3-
version = "1.2.0"
3+
version = "1.3.0"
44
edition = "2021"
55
license = "MIT"
66
description = "A simple and tiny file encrypt tool"
@@ -10,7 +10,8 @@ repository = "https://git.hatter.ink/hatter/tiny-encrypt-rs"
1010

1111
[features]
1212
default = ["decrypt", "macos", "secure-enclave"]
13-
decrypt = ["openpgp-card", "openpgp-card-pcsc", "yubikey"]
13+
decrypt = ["smartcard"]
14+
smartcard = ["openpgp-card", "openpgp-card-pcsc", "yubikey"]
1415
macos = ["security-framework"]
1516
secure-enclave = ["macos", "swift-rs"]
1617

@@ -44,6 +45,7 @@ x509-parser = "0.15"
4445
yubikey = { version = "0.8", features = ["untested"], optional = true }
4546
zeroize = "1.7"
4647
swift-rs = { path = "swift-rs", optional = true }
48+
spki = "0.7.3"
4749

4850
[build-dependencies]
4951
swift-rs = { path = "swift-rs", features = ["build"], optional = true }

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ Encrypt config `~/.tinyencrypt/config-rs.json`:
7070

7171
Supported PKI encryption types:
7272

73-
| Type | Algorithm | Description |
74-
|------------|-----------------|------------------------|
75-
| pgp | PKCS1-v1.5 | OpenPGP Encryption Key |
76-
| pgp-x25519 | ECDH(X25519) | OpenPGP Encryption Key |
77-
| ecdh | ECDH(secp256r1) | PIV Slot |
78-
| ecdh-p384 | ECDH(secp384r1) | PIV Slot |
73+
| Type | Algorithm | Description |
74+
|---------------|-----------------|-----------------------------------------|
75+
| pgp-rsa | PKCS1-v1.5 | OpenPGP Encryption Key (Previous `pgp`) |
76+
| pgp-x25519 | ECDH(X25519) | OpenPGP Encryption Key |
77+
| static-x25519 | ECDH(X25519) | Key Stored in KeyChain |
78+
| piv-p256 | ECDH(secp256r1) | PIV Slot (Previous `ecdh`) |
79+
| piv-p384 | ECDH(secp384r1) | PIV Slot (Previous `ecdh-p384`) |
80+
| key-p256 | ECDH(secp256r1) | Key Stored in Secure Enclave |
7981

8082
Smart Card(Yubikey) protected ECDH Encryption description:
8183

src/cmd_decrypt.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ use crate::wrap_key::WrapKey;
4141
pub struct CmdDecrypt {
4242
/// Files need to be decrypted
4343
pub paths: Vec<PathBuf>,
44-
/// PIN
44+
/// PGP or PIV PIN
4545
#[arg(long, short = 'p')]
4646
pub pin: Option<String>,
4747
/// KeyID
4848
#[arg(long, short = 'k')]
4949
pub key_id: Option<String>,
50-
/// Slot
50+
/// PIV slot
5151
#[arg(long, short = 's')]
5252
pub slot: Option<String>,
5353
/// Remove source file
@@ -68,7 +68,7 @@ pub struct CmdDecrypt {
6868
/// Edit file
6969
#[arg(long, short = 'E')]
7070
pub edit_file: bool,
71-
// Readonly
71+
/// Readonly mode
7272
#[arg(long)]
7373
pub readonly: bool,
7474
/// Digest algorithm (sha1, sha256[default], sha384, sha512 ...)
@@ -432,11 +432,11 @@ pub fn try_decrypt_key(config: &Option<TinyEncryptConfig>,
432432
pin: &Option<String>,
433433
slot: &Option<String>) -> XResult<Vec<u8>> {
434434
match envelop.r#type {
435-
TinyEncryptEnvelopType::Pgp => try_decrypt_key_pgp(envelop, pin),
435+
TinyEncryptEnvelopType::PgpRsa => try_decrypt_key_pgp(envelop, pin),
436436
TinyEncryptEnvelopType::PgpX25519 => try_decrypt_key_ecdh_pgp_x25519(envelop, pin),
437437
#[cfg(feature = "macos")]
438438
TinyEncryptEnvelopType::StaticX25519 => try_decrypt_key_ecdh_static_x25519(config, envelop),
439-
TinyEncryptEnvelopType::Ecdh | TinyEncryptEnvelopType::EcdhP384 => try_decrypt_key_ecdh(config, envelop, pin, slot),
439+
TinyEncryptEnvelopType::PivP256 | TinyEncryptEnvelopType::PivP384 => try_decrypt_key_ecdh(config, envelop, pin, slot),
440440
#[cfg(feature = "secure-enclave")]
441441
TinyEncryptEnvelopType::KeyP256 => try_decrypt_se_key_ecdh(config, envelop),
442442
unknown_type => simple_error!("Unknown or unsupported type: {}", unknown_type.get_name()),

src/cmd_encrypt.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub struct CmdEncrypt {
5252
/// Remove source file
5353
#[arg(long, short = 'R')]
5454
pub remove_file: bool,
55-
/// Create file
56-
#[arg(long)]
55+
/// Create file (create a empty encrypted file)
56+
#[arg(long, short = 'a')]
5757
pub create: bool,
5858
/// Disable compress meta
5959
#[arg(long)]
@@ -265,16 +265,16 @@ fn encrypt_envelops(cryptor: Cryptor, key: &[u8], envelops: &[&TinyEncryptConfig
265265
let mut encrypted_envelops = vec![];
266266
for envelop in envelops {
267267
match envelop.r#type {
268-
TinyEncryptEnvelopType::Pgp => {
268+
TinyEncryptEnvelopType::PgpRsa => {
269269
encrypted_envelops.push(encrypt_envelop_pgp(key, envelop)?);
270270
}
271271
TinyEncryptEnvelopType::PgpX25519 | TinyEncryptEnvelopType::StaticX25519 => {
272272
encrypted_envelops.push(encrypt_envelop_ecdh_x25519(cryptor, key, envelop)?);
273273
}
274-
TinyEncryptEnvelopType::Ecdh | TinyEncryptEnvelopType::KeyP256 => {
274+
TinyEncryptEnvelopType::PivP256 | TinyEncryptEnvelopType::KeyP256 => {
275275
encrypted_envelops.push(encrypt_envelop_ecdh(cryptor, key, envelop)?);
276276
}
277-
TinyEncryptEnvelopType::EcdhP384 => {
277+
TinyEncryptEnvelopType::PivP384 => {
278278
encrypted_envelops.push(encrypt_envelop_ecdh_p384(cryptor, key, envelop)?);
279279
}
280280
_ => return simple_error!("Not supported type: {:?}", envelop.r#type),
@@ -285,7 +285,7 @@ fn encrypt_envelops(cryptor: Cryptor, key: &[u8], envelops: &[&TinyEncryptConfig
285285

286286
fn encrypt_envelop_ecdh(cryptor: Cryptor, key: &[u8], envelop: &TinyEncryptConfigEnvelop) -> XResult<TinyEncryptEnvelop> {
287287
let public_key_point_hex = &envelop.public_part;
288-
let (shared_secret, ephemeral_spki) = util_p256::compute_shared_secret(public_key_point_hex)?;
288+
let (shared_secret, ephemeral_spki) = util_p256::compute_p256_shared_secret(public_key_point_hex)?;
289289
let enc_type = match cryptor {
290290
Cryptor::Aes256Gcm => ENC_AES256_GCM_P256,
291291
Cryptor::ChaCha20Poly1305 => ENC_CHACHA20_POLY1305_P256,

src/cmd_execenv.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ use crate::util_enc_file;
1818

1919
#[derive(Debug, Args)]
2020
pub struct CmdExecEnv {
21-
/// PIN
21+
/// PGP or PIV PIN
2222
#[arg(long, short = 'p')]
2323
pub pin: Option<String>,
2424
/// KeyID
2525
#[arg(long, short = 'k')]
2626
pub key_id: Option<String>,
27-
/// Slot
27+
/// PIV slot
2828
#[arg(long, short = 's')]
2929
pub slot: Option<String>,
30-
// Tiny encrypt file name
30+
/// Tiny encrypt file name
3131
pub file_name: String,
32-
// Arguments
33-
pub arguments: Vec<String>,
32+
/// Command and arguments
33+
pub command_arguments: Vec<String>,
3434
}
3535

3636
impl Drop for CmdExecEnv {
@@ -43,7 +43,7 @@ pub fn exec_env(cmd_exec_env: CmdExecEnv) -> XResult<()> {
4343
util_msg::set_logger_std_out(false);
4444
debugging!("Cmd exec env: {:?}", cmd_exec_env);
4545
let config = TinyEncryptConfig::load(TINY_ENC_CONFIG_FILE).ok();
46-
if cmd_exec_env.arguments.is_empty() {
46+
if cmd_exec_env.command_arguments.is_empty() {
4747
return simple_error!("No commands assigned.");
4848
}
4949

@@ -75,7 +75,7 @@ pub fn exec_env(cmd_exec_env: CmdExecEnv) -> XResult<()> {
7575
let decrypted_content = decrypt_limited_content_to_vec(&mut file_in, &meta, cryptor, &key_nonce)?;
7676
let exit_code = if let Some(output) = decrypted_content {
7777
debugging!("Outputs: {}", output);
78-
let arguments = &cmd_exec_env.arguments;
78+
let arguments = &cmd_exec_env.command_arguments;
7979
let envs = parse_output_to_env(&output);
8080

8181
let mut command = Command::new(&arguments[0]);

0 commit comments

Comments
 (0)