Skip to content

Commit

Permalink
trim keys before attempting import
Browse files Browse the repository at this point in the history
When pasting from e.g. signal-desktop, private keys can have a trailing
newline that isn't readily visible. As a result the import mysteriously
fails with a "Private key is not recognized" message.

This is fixed by trimming whitespace from the ends of keys before
attempting to add them.
  • Loading branch information
jamesob authored and mikedilger committed Sep 23, 2023
1 parent 7cb8684 commit 267e5e8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/overlord/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ impl Overlord {
}));
}
ToOverlordMessage::FollowNprofile(nprofile) => {
match Profile::try_from_bech32_string(&nprofile, true) {
match Profile::try_from_bech32_string(&nprofile.trim(), true) {
Ok(np) => self.follow_nprofile(np).await?,
Err(e) => GLOBALS.status_queue.write().write(format!("{}", e)),
}
Expand All @@ -603,8 +603,8 @@ impl Overlord {
password.zeroize();
GLOBALS.signer.save().await?;
} else {
let maybe_pk1 = PrivateKey::try_from_bech32_string(&import_priv);
let maybe_pk2 = PrivateKey::try_from_hex_string(&import_priv);
let maybe_pk1 = PrivateKey::try_from_bech32_string(&import_priv.trim());
let maybe_pk2 = PrivateKey::try_from_hex_string(&import_priv.trim());
import_priv.zeroize();
if maybe_pk1.is_err() && maybe_pk2.is_err() {
password.zeroize();
Expand All @@ -621,8 +621,8 @@ impl Overlord {
}
}
ToOverlordMessage::ImportPub(pubstr) => {
let maybe_pk1 = PublicKey::try_from_bech32_string(&pubstr, true);
let maybe_pk2 = PublicKey::try_from_hex_string(&pubstr, true);
let maybe_pk1 = PublicKey::try_from_bech32_string(&pubstr.trim(), true);
let maybe_pk2 = PublicKey::try_from_hex_string(&pubstr.trim(), true);
if maybe_pk1.is_err() && maybe_pk2.is_err() {
GLOBALS
.status_queue
Expand Down Expand Up @@ -901,7 +901,7 @@ impl Overlord {
pubkeystr: String,
relay: RelayUrl,
) -> Result<(), Error> {
let pubkey = match PublicKey::try_from_bech32_string(&pubkeystr, true) {
let pubkey = match PublicKey::try_from_bech32_string(&pubkeystr.trim(), true) {
Ok(pk) => pk,
Err(_) => PublicKey::try_from_hex_string(&pubkeystr, true)?,
};
Expand Down

0 comments on commit 267e5e8

Please sign in to comment.