summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2023-07-06 12:31:37 +0200
committerJustus Winter <justus@sequoia-pgp.org>2023-07-06 19:33:07 +0200
commitc5670ce4958a33c4a7c3b861bdb1619f4b02e217 (patch)
treec7933a9173968dcf45470fe4873589f963625c09
parentf5343076ab1cee2087fb24f96b96cdb5a4092dc5 (diff)
ipc: Acknowledge unexpected inquiries.
- While signing and decrypting, handle unexpected inquiries. The agent will send PINENTRY_LAUNCHED inquiries if it has to unlock a key.
-rw-r--r--ipc/src/gnupg.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/ipc/src/gnupg.rs b/ipc/src/gnupg.rs
index 0bec65ed..3a070d04 100644
--- a/ipc/src/gnupg.rs
+++ b/ipc/src/gnupg.rs
@@ -369,12 +369,12 @@ impl Agent {
| assuan::Response::Comment { .. }
| assuan::Response::Status { .. } =>
(), // Ignore.
+ assuan::Response::Inquire { .. } =>
+ acknowledge_inquiry(self).await?,
assuan::Response::Error { ref message, .. } =>
return assuan::operation_failed(self, message).await,
assuan::Response::Data { ref partial } =>
data.extend_from_slice(partial),
- r =>
- return assuan::protocol_error(&r),
}
}
@@ -399,9 +399,12 @@ impl Agent {
self.send("PKDECRYPT")?;
while let Some(r) = self.next().await {
match r? {
- assuan::Response::Inquire { ref keyword, .. }
- if keyword == "CIPHERTEXT" =>
- (), // What we expect.
+ assuan::Response::Inquire { ref keyword, .. } =>
+ if keyword == "CIPHERTEXT" {
+ // What we expect.
+ } else {
+ acknowledge_inquiry(self).await?;
+ },
assuan::Response::Comment { .. }
| assuan::Response::Status { .. } =>
(), // Ignore.
@@ -422,6 +425,8 @@ impl Agent {
assuan::Response::Ok { .. }
| assuan::Response::Comment { .. } =>
(), // Ignore.
+ assuan::Response::Inquire { .. } =>
+ acknowledge_inquiry(self).await?,
assuan::Response::Status { ref keyword, ref message } =>
if keyword == "PADDING" {
padding = message != "0";
@@ -430,8 +435,6 @@ impl Agent {
return assuan::operation_failed(self, message).await,
assuan::Response::Data { ref partial } =>
data.extend_from_slice(partial),
- r =>
- return assuan::protocol_error(&r),
}
}
@@ -724,6 +727,16 @@ fn map_panic(_: Box<dyn std::any::Any + std::marker::Send>) -> anyhow::Error
anyhow::anyhow!("worker thread panicked")
}
+/// Helper function to respond to inquiries.
+///
+/// This function doesn't do something useful, but it ends the current
+/// inquiry.
+async fn acknowledge_inquiry(agent: &mut Agent) -> Result<()> {
+ agent.send("END")?;
+ agent.next().await; // Dummy read to send END.
+ Ok(())
+}
+
#[derive(thiserror::Error, Debug)]
/// Errors used in this module.
pub enum Error {