@@ -4,22 +4,20 @@ use std::collections::{BTreeMap, HashMap, HashSet};
44use std:: io:: { BufRead , Cursor } ;
55
66use anyhow:: { Context as _, Result , bail} ;
7- use chrono:: SubsecRound ;
87use deltachat_contact_tools:: EmailAddress ;
98use pgp:: armor:: BlockType ;
109use pgp:: composed:: {
11- ArmorOptions , DecryptionOptions , Deserializable , DetachedSignature , KeyType as PgpKeyType ,
12- Message , MessageBuilder , SecretKeyParamsBuilder , SignedPublicKey , SignedPublicSubKey ,
13- SignedSecretKey , SubkeyParamsBuilder , SubpacketConfig , TheRing ,
10+ ArmorOptions , DecryptionOptions , Deserializable , DetachedSignature , EncryptionCaps ,
11+ KeyType as PgpKeyType , Message , MessageBuilder , SecretKeyParamsBuilder , SignedPublicKey ,
12+ SignedPublicSubKey , SignedSecretKey , SubkeyParamsBuilder , SubpacketConfig , TheRing ,
1413} ;
1514use pgp:: crypto:: aead:: { AeadAlgorithm , ChunkSize } ;
1615use pgp:: crypto:: ecc_curve:: ECCCurve ;
1716use pgp:: crypto:: hash:: HashAlgorithm ;
1817use pgp:: crypto:: sym:: SymmetricKeyAlgorithm ;
1918use pgp:: packet:: { SignatureConfig , SignatureType , Subpacket , SubpacketData } ;
2019use pgp:: types:: {
21- CompressionAlgorithm , KeyDetails , KeyVersion , Password , PublicKeyTrait , SecretKeyTrait as _,
22- StringToKey ,
20+ CompressionAlgorithm , KeyDetails , KeyVersion , Password , SigningKey as _, StringToKey ,
2321} ;
2422use rand_old:: { Rng as _, thread_rng} ;
2523use tokio:: runtime:: Handle ;
@@ -83,9 +81,7 @@ impl KeyPair {
8381 ///
8482 /// Public key is split off the secret key.
8583 pub fn new ( secret : SignedSecretKey ) -> Result < Self > {
86- use crate :: key:: DcSecretKey ;
87-
88- let public = secret. split_public_key ( ) ?;
84+ let public = secret. to_public_key ( ) ;
8985 Ok ( Self { public, secret } )
9086 }
9187}
@@ -123,7 +119,7 @@ pub(crate) fn create_keypair(addr: EmailAddress) -> Result<KeyPair> {
123119 . subkey (
124120 SubkeyParamsBuilder :: default ( )
125121 . key_type ( encryption_key_type)
126- . can_encrypt ( true )
122+ . can_encrypt ( EncryptionCaps :: All )
127123 . passphrase ( None )
128124 . build ( )
129125 . context ( "failed to build subkey parameters" ) ?,
@@ -134,18 +130,16 @@ pub(crate) fn create_keypair(addr: EmailAddress) -> Result<KeyPair> {
134130 let mut rng = thread_rng ( ) ;
135131 let secret_key = key_params
136132 . generate ( & mut rng)
137- . context ( "failed to generate the key" ) ?
138- . sign ( & mut rng, & Password :: empty ( ) )
139- . context ( "failed to sign secret key" ) ?;
133+ . context ( "Failed to generate the key" ) ?;
140134 secret_key
141- . verify ( )
142- . context ( "invalid secret key generated" ) ?;
135+ . verify_bindings ( )
136+ . context ( "Invalid secret key generated" ) ?;
143137
144138 let key_pair = KeyPair :: new ( secret_key) ?;
145139 key_pair
146140 . public
147- . verify ( )
148- . context ( "invalid public key generated" ) ?;
141+ . verify_bindings ( )
142+ . context ( "Invalid public key generated" ) ?;
149143 Ok ( key_pair)
150144}
151145
@@ -157,7 +151,7 @@ pub(crate) fn create_keypair(addr: EmailAddress) -> Result<KeyPair> {
157151fn select_pk_for_encryption ( key : & SignedPublicKey ) -> Option < & SignedPublicSubKey > {
158152 key. public_subkeys
159153 . iter ( )
160- . find ( |subkey| subkey. is_encryption_key ( ) )
154+ . find ( |subkey| subkey. algorithm ( ) . can_encrypt ( ) )
161155}
162156
163157/// Version of SEIPD packet to use.
@@ -194,7 +188,7 @@ pub async fn pk_encrypt(
194188 let subpkts = {
195189 let mut hashed = Vec :: with_capacity ( 1 + public_keys_for_encryption. len ( ) + 1 ) ;
196190 hashed. push ( Subpacket :: critical ( SubpacketData :: SignatureCreationTime (
197- chrono :: Utc :: now ( ) . trunc_subsecs ( 0 ) ,
191+ pgp :: types :: Timestamp :: now ( ) ,
198192 ) ) ?) ;
199193 // Test "elena" uses old Delta Chat.
200194 let skip = private_key_for_signing. dc_fingerprint ( ) . hex ( )
@@ -215,8 +209,8 @@ pub async fn pk_encrypt(
215209 ) ) ?) ;
216210 let mut unhashed = vec ! [ ] ;
217211 if private_key_for_signing. version ( ) <= KeyVersion :: V4 {
218- unhashed. push ( Subpacket :: regular ( SubpacketData :: Issuer (
219- private_key_for_signing. key_id ( ) ,
212+ unhashed. push ( Subpacket :: regular ( SubpacketData :: IssuerKeyId (
213+ private_key_for_signing. legacy_key_id ( ) ,
220214 ) ) ?) ;
221215 }
222216 SubpacketConfig :: UserDefined { hashed, unhashed }
@@ -302,15 +296,15 @@ pub fn pk_calc_signature(
302296 private_key_for_signing. fingerprint( ) ,
303297 ) ) ?,
304298 Subpacket :: critical( SubpacketData :: SignatureCreationTime (
305- chrono :: Utc :: now( ) . trunc_subsecs ( 0 ) ,
299+ pgp :: types :: Timestamp :: now( ) ,
306300 ) ) ?,
307301 ] ;
308302 config. unhashed_subpackets = vec ! [ ] ;
309303 if private_key_for_signing. version ( ) <= KeyVersion :: V4 {
310304 config
311305 . unhashed_subpackets
312- . push ( Subpacket :: regular ( SubpacketData :: Issuer (
313- private_key_for_signing. key_id ( ) ,
306+ . push ( Subpacket :: regular ( SubpacketData :: IssuerKeyId (
307+ private_key_for_signing. legacy_key_id ( ) ,
314308 ) ) ?) ;
315309 }
316310
0 commit comments