3
3
use std:: collections:: HashMap ;
4
4
use std:: io;
5
5
6
+ use age_core:: format:: { FileKey , Stanza } ;
7
+ use age_core:: secrecy:: ExposeSecret ;
6
8
use age_core:: {
7
9
format:: FILE_KEY_BYTES ,
8
10
primitives:: { aead_decrypt, hkdf} ,
9
11
} ;
10
- use age_core:: {
11
- format:: { FileKey , Stanza } ,
12
- secrecy:: Zeroize as _,
13
- } ;
12
+ use age_plugin:: PluginHandler ;
14
13
use age_plugin:: {
15
14
identity:: { self , IdentityPluginV1 } ,
16
- recipient:: { self , RecipientPluginV1 } ,
17
15
run_state_machine, Callbacks ,
18
16
} ;
19
17
use bech32:: { Bech32 , Hrp } ;
@@ -29,6 +27,7 @@ use openpgp_card::{
29
27
} ;
30
28
use subtle:: ConstantTimeEq ;
31
29
use x25519_dalek:: PublicKey ;
30
+ use zeroize:: Zeroize as _;
32
31
33
32
// Use lower-case HRP to avoid https://github.com/rust-bitcoin/rust-bech32/issues/40
34
33
const IDENTITY_PREFIX : Hrp = Hrp :: parse_unchecked ( "age-plugin-openpgp-card-" ) ;
@@ -40,35 +39,6 @@ const X25519_RECIPIENT_KEY_LABEL: &[u8] = b"age-encryption.org/v1/X25519";
40
39
41
40
pub const EPK_LEN_BYTES : usize = 32 ;
42
41
pub const ENCRYPTED_FILE_KEY_BYTES : usize = FILE_KEY_BYTES + 16 ;
43
- struct RecipientPlugin ;
44
-
45
- impl RecipientPluginV1 for RecipientPlugin {
46
- fn add_recipient (
47
- & mut self ,
48
- _index : usize ,
49
- _plugin_name : & str ,
50
- _bytes : & [ u8 ] ,
51
- ) -> Result < ( ) , recipient:: Error > {
52
- todo ! ( )
53
- }
54
-
55
- fn add_identity (
56
- & mut self ,
57
- _index : usize ,
58
- _plugin_name : & str ,
59
- _bytes : & [ u8 ] ,
60
- ) -> Result < ( ) , recipient:: Error > {
61
- todo ! ( )
62
- }
63
-
64
- fn wrap_file_keys (
65
- & mut self ,
66
- _file_keys : Vec < FileKey > ,
67
- _callbacks : impl Callbacks < recipient:: Error > ,
68
- ) -> io:: Result < Result < Vec < Vec < Stanza > > , Vec < recipient:: Error > > > {
69
- todo ! ( )
70
- }
71
- }
72
42
73
43
struct CardStub {
74
44
ident : String ,
@@ -165,7 +135,11 @@ impl IdentityPlugin {
165
135
return Err ( DecryptError :: NonEccCard . into ( ) ) ;
166
136
} ;
167
137
tx. verify_user_pin (
168
- callbacks. request_secret ( & format ! ( "Unlock card {}" , card_stub. ident) ) ??,
138
+ callbacks
139
+ . request_secret ( & format ! ( "Unlock card {}" , card_stub. ident) ) ??
140
+ . expose_secret ( )
141
+ . to_string ( )
142
+ . into ( ) ,
169
143
) ?;
170
144
171
145
if let Ok ( Some ( uif) ) = tx. user_interaction_flag ( Decryption ) {
@@ -202,7 +176,7 @@ impl IdentityPlugin {
202
176
// It's ours!
203
177
let file_key: [ u8 ; FILE_KEY_BYTES ] = pt[ ..] . try_into ( ) . unwrap ( ) ;
204
178
pt. zeroize ( ) ;
205
- FileKey :: from ( file_key)
179
+ FileKey :: new ( Box :: new ( file_key) )
206
180
} )
207
181
{
208
182
return Ok ( Some ( result) ) ;
@@ -212,6 +186,12 @@ impl IdentityPlugin {
212
186
}
213
187
}
214
188
189
+ impl PluginHandler for IdentityPlugin {
190
+ type RecipientV1 = std:: convert:: Infallible ;
191
+
192
+ type IdentityV1 = Self ;
193
+ }
194
+
215
195
impl IdentityPluginV1 for IdentityPlugin {
216
196
fn add_identity (
217
197
& mut self ,
@@ -275,8 +255,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
275
255
if let Some ( state_machine) = opts. age_plugin {
276
256
return Ok ( run_state_machine (
277
257
& state_machine,
278
- Some ( || RecipientPlugin ) ,
279
- Some ( || IdentityPlugin { cards : vec ! [ ] } ) ,
258
+ IdentityPlugin { cards : vec ! [ ] } ,
280
259
) ?) ;
281
260
}
282
261
0 commit comments