Skip to content

Commit e78b509

Browse files
committed
chore: update rPGP from 0.18.0 to 0.19.0
1 parent 583979c commit e78b509

File tree

10 files changed

+48
-85
lines changed

10 files changed

+48
-85
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ num-derive = "0.4"
7878
num-traits = { workspace = true }
7979
parking_lot = "0.12.4"
8080
percent-encoding = "2.3"
81-
pgp = { version = "0.18.0", default-features = false }
81+
pgp = { version = "0.19.0", default-features = false }
8282
pin-project = "1"
8383
qrcodegen = "1.7.0"
8484
quick-xml = { version = "0.38", features = ["escape-html"] }

benches/decrypting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async fn create_context() -> Context {
5858
.await
5959
.unwrap();
6060
let secret = key_from_asc(include_str!("../test-data/key/bob-secret.asc")).unwrap();
61-
let public = secret.signed_public_key();
61+
let public = secret.to_public_key();
6262
let key_pair = KeyPair { public, secret };
6363
store_self_keypair(&context, &key_pair)
6464
.await

src/aheader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ impl FromStr for Aheader {
110110
SignedPublicKey::from_base64(&raw).context("autocrypt key cannot be decoded")
111111
})
112112
.and_then(|key| {
113-
key.verify()
113+
key.verify_bindings()
114114
.and(Ok(key))
115-
.context("autocrypt key cannot be verified")
115+
.context("Autocrypt key cannot be verified")
116116
})?;
117117

118118
let prefer_encrypt = attributes

src/imex.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::config::Config;
1919
use crate::context::Context;
2020
use crate::e2ee;
2121
use crate::events::EventType;
22-
use crate::key::{self, DcKey, DcSecretKey, SignedPublicKey, SignedSecretKey};
22+
use crate::key::{self, DcKey, SignedPublicKey, SignedSecretKey};
2323
use crate::log::{LogExt, warn};
2424
use crate::pgp;
2525
use crate::qr::DCBACKUP_VERSION;
@@ -142,7 +142,7 @@ pub async fn has_backup(_context: &Context, dir_name: &Path) -> Result<String> {
142142

143143
async fn set_self_key(context: &Context, armored: &str) -> Result<()> {
144144
let private_key = SignedSecretKey::from_asc(armored)?;
145-
let public_key = private_key.split_public_key()?;
145+
let public_key = private_key.to_public_key();
146146

147147
let keypair = pgp::KeyPair {
148148
public: public_key,
@@ -153,7 +153,7 @@ async fn set_self_key(context: &Context, armored: &str) -> Result<()> {
153153
info!(
154154
context,
155155
"stored self key: {:?}",
156-
keypair.secret.public_key().key_id()
156+
keypair.secret.public_key().legacy_key_id()
157157
);
158158
Ok(())
159159
}

src/key.rs

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use deltachat_contact_tools::EmailAddress;
1010
use pgp::composed::Deserializable;
1111
pub use pgp::composed::{SignedPublicKey, SignedSecretKey};
1212
use pgp::ser::Serialize;
13-
use pgp::types::{KeyDetails, KeyId, Password};
13+
use pgp::types::{KeyDetails, KeyId};
1414
use tokio::runtime::Handle;
1515

1616
use crate::context::Context;
@@ -264,7 +264,7 @@ impl DcKey for SignedPublicKey {
264264
}
265265

266266
fn key_id(&self) -> KeyId {
267-
KeyDetails::key_id(self)
267+
KeyDetails::legacy_key_id(self)
268268
}
269269
}
270270

@@ -291,30 +291,7 @@ impl DcKey for SignedSecretKey {
291291
}
292292

293293
fn key_id(&self) -> KeyId {
294-
KeyDetails::key_id(&**self)
295-
}
296-
}
297-
298-
/// Deltachat extension trait for secret keys.
299-
///
300-
/// Provides some convenience wrappers only applicable to [SignedSecretKey].
301-
pub(crate) trait DcSecretKey {
302-
/// Create a public key from a private one.
303-
fn split_public_key(&self) -> Result<SignedPublicKey>;
304-
}
305-
306-
impl DcSecretKey for SignedSecretKey {
307-
fn split_public_key(&self) -> Result<SignedPublicKey> {
308-
self.verify()?;
309-
let unsigned_pubkey = self.public_key();
310-
let mut rng = rand_old::thread_rng();
311-
let signed_pubkey = unsigned_pubkey.sign(
312-
&mut rng,
313-
&self.primary_key,
314-
self.primary_key.public_key(),
315-
&Password::empty(),
316-
)?;
317-
Ok(signed_pubkey)
294+
KeyDetails::legacy_key_id(&**self)
318295
}
319296
}
320297

@@ -426,7 +403,7 @@ pub(crate) async fn store_self_keypair(context: &Context, keypair: &KeyPair) ->
426403
/// Use import/export APIs instead.
427404
pub async fn preconfigure_keypair(context: &Context, secret_data: &str) -> Result<()> {
428405
let secret = SignedSecretKey::from_asc(secret_data)?;
429-
let public = secret.split_public_key()?;
406+
let public = secret.to_public_key();
430407
let keypair = KeyPair { public, secret };
431408
store_self_keypair(context, &keypair).await?;
432409
Ok(())
@@ -702,12 +679,6 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
702679
assert_eq!(res0.unwrap(), res1.unwrap());
703680
}
704681

705-
#[test]
706-
fn test_split_key() {
707-
let pubkey = KEYPAIR.secret.split_public_key().unwrap();
708-
assert_eq!(pubkey.primary_key, KEYPAIR.public.primary_key);
709-
}
710-
711682
/// Tests that setting a default key second time is not allowed.
712683
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
713684
async fn test_save_self_key_twice() {

src/mimeparser.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,7 @@ impl MimeMessage {
496496
// We don't decompress messages compressed multiple times.
497497
None
498498
}
499-
Some(pgp::composed::Message::SignedOnePass { reader, .. }) => reader.signature(),
500-
Some(pgp::composed::Message::Signed { reader, .. }) => Some(reader.signature()),
499+
Some(pgp::composed::Message::Signed { reader, .. }) => reader.signature(0),
501500
Some(pgp::composed::Message::Encrypted { .. }) => {
502501
// The message is already decrypted once.
503502
None
@@ -1636,7 +1635,7 @@ impl MimeMessage {
16361635
}
16371636
Ok(key) => key,
16381637
};
1639-
if let Err(err) = key.verify() {
1638+
if let Err(err) = key.verify_bindings() {
16401639
warn!(context, "Attached PGP key verification failed: {err:#}.");
16411640
return Ok(false);
16421641
}

src/pgp.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ use std::collections::{BTreeMap, HashMap, HashSet};
44
use std::io::{BufRead, Cursor};
55

66
use anyhow::{Context as _, Result, bail};
7-
use chrono::SubsecRound;
87
use deltachat_contact_tools::EmailAddress;
98
use pgp::armor::BlockType;
109
use 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
};
1514
use pgp::crypto::aead::{AeadAlgorithm, ChunkSize};
1615
use pgp::crypto::ecc_curve::ECCCurve;
1716
use pgp::crypto::hash::HashAlgorithm;
1817
use pgp::crypto::sym::SymmetricKeyAlgorithm;
1918
use pgp::packet::{SignatureConfig, SignatureType, Subpacket, SubpacketData};
2019
use pgp::types::{
21-
CompressionAlgorithm, KeyDetails, KeyVersion, Password, PublicKeyTrait, SecretKeyTrait as _,
22-
StringToKey,
20+
CompressionAlgorithm, KeyDetails, KeyVersion, Password, SigningKey as _, StringToKey,
2321
};
2422
use rand_old::{Rng as _, thread_rng};
2523
use 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> {
157151
fn 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

src/stats.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::collections::{BTreeMap, BTreeSet};
88
use anyhow::{Context as _, Result};
99
use deltachat_derive::FromSql;
1010
use num_traits::ToPrimitive;
11-
use pgp::types::PublicKeyTrait;
11+
use pgp::types::KeyDetails as _;
1212
use rand::distr::SampleString as _;
1313
use rusqlite::OptionalExtension;
1414
use serde::Serialize;
@@ -33,7 +33,7 @@ const MESSAGE_STATS_UPDATE_INTERVAL_SECONDS: i64 = 4 * 60; // 4 minutes (less th
3333
#[derive(Serialize)]
3434
struct Statistics {
3535
core_version: String,
36-
key_create_timestamps: Vec<i64>,
36+
key_create_timestamps: Vec<u32>,
3737
stats_id: String,
3838
is_chatmail: bool,
3939
contact_stats: Vec<ContactStat>,
@@ -345,10 +345,10 @@ async fn get_stats(context: &Context) -> Result<String> {
345345
.get_config_u32(Config::StatsLastOldContactId)
346346
.await?;
347347

348-
let key_create_timestamps: Vec<i64> = load_self_public_keyring(context)
348+
let key_create_timestamps: Vec<u32> = load_self_public_keyring(context)
349349
.await?
350350
.iter()
351-
.map(|k| k.created_at().timestamp())
351+
.map(|k| k.created_at().as_secs())
352352
.collect();
353353

354354
let sending_enabled_timestamps =

0 commit comments

Comments
 (0)