Only re-prove identity when credentials change

finchie
Nov 27, 2022, 1:37 AM
44RUBHREQUNI4B36WSV7CUK5CVVIKG2AQOQJQZ7HU3BHY6W6AUEQC

Dependencies

  • [2] 6FRPUHWK Fix identity tests
  • [3] YJXRCXOS Disallow overwriting existing identities via `pijul id edit`
  • [4] 4OJWMSOW Fully replace crate::Identity
  • [5] QKBU6HCD Prevent illegal characters in identity name
  • [6] 4KJ45IJL Implement new identity management

Change contents

  • edit in pijul/src/identity/repair.rs at line 1
    [4.56][4.57:97]()
    use super::create::IdentityCreateError;
  • replacement in pijul/src/identity/repair.rs at line 66
    [4.4220][4.4220:4888]()
    // match create_identity(Some(old_identity.clone()), no_prompt).await {
    if let Err(e) = old_identity.clone().create(no_prompt, true).await {
    match e {
    IdentityCreateError::ProveFailed(name) => writeln!(stderr, "Failed to prove identity. You will still be able to create & sign patches, but until you run `pijul identity prove --name {name}` they will not be linked to your personal details. If you are on an enterprise network, perhaps try running with `--no-cert-check`")?,
    IdentityCreateError::Other(err) => return Err(err),
    }
    };
    [4.4220]
    [4.4888]
    old_identity.clone().create(no_prompt, true).await?;
  • replacement in pijul/src/identity/create.rs at line 13
    [4.28494][4.28494:28518]()
    use log::{debug, warn};
    [4.28494]
    [4.28518]
    use log::{debug, error, warn};
  • edit in pijul/src/identity/create.rs at line 15
    [4.28549][4.28549:28571]()
    use thiserror::Error;
  • edit in pijul/src/identity/create.rs at line 18
    [4.28632][4.28632:28953]()
    #[derive(Error, Debug)]
    pub enum IdentityCreateError {
    #[error("Could not prove identity {0}. Please check your credentials & network connection. If you are on an enterprise network, perhaps try running with `--no-cert-check`")]
    ProveFailed(String),
    #[error(transparent)]
    Other(#[from] anyhow::Error),
    }
  • replacement in pijul/src/identity/create.rs at line 26
    [4.8903][3.55:97]()
    replace_current: Option<&String>,
    [4.8903]
    [4.8934]
    to_replace: Option<&String>,
  • replacement in pijul/src/identity/create.rs at line 36
    [4.29468][3.98:160]()
    .with_initial_text(if replace_current.is_some() {
    [4.29468]
    [4.9110]
    .with_initial_text(if to_replace.is_some() {
  • replacement in pijul/src/identity/create.rs at line 48
    [4.29774][3.161:223]()
    if let Some(name) = replace_current {
    [4.29774]
    [3.223]
    if let Some(name) = to_replace {
  • replacement in pijul/src/identity/create.rs at line 109
    [4.10722][4.10722:10782]()
    new_identity.prompt_remote(link_remote).await?;
    [4.10722]
    [2.3674]
    new_identity.prompt_remote().await?;
    // There are 3 cases that require re-proving:
    // 1: new identity (replace_current == None)
    // 2: new secret key
    // 3. new username/origin
    if to_replace.is_none()
    || self.secret_key() != new_identity.secret_key()
    || (&self.config.author.origin, &self.config.author.username)
    != (
    &new_identity.config.author.origin,
    &new_identity.config.author.username,
    )
    {
    // Prove the identity to the server
    if link_remote
    && new_identity
    .prove(*NO_CERT_CHECK.get_or_init(|| false))
    .await
    .is_err()
    {
    error!("Could not prove identity `{}`. Please check your credentials & network connection. If you are on an enterprise network, perhaps try running with `--no-cert-check`. Your data is safe but will not be connected to {} without runnning `pijul identity prove {}`", new_identity.name, new_identity.config.author.origin, new_identity.name);
    }
    }
  • replacement in pijul/src/identity/create.rs at line 182
    [4.12406][4.12406:12500]()
    async fn prompt_remote(&mut self, link_remote: bool) -> Result<(), IdentityCreateError> {
    [4.12406]
    [4.12500]
    async fn prompt_remote(&mut self) -> Result<(), anyhow::Error> {
  • edit in pijul/src/identity/create.rs at line 213
    [2.4580][2.4580:4591](),[2.4591][4.13093:13377](),[4.13093][4.13093:13377]()
    }
    // Prove the identity to the server
    if link_remote
    && self
    .prove(*NO_CERT_CHECK.get_or_init(|| false))
    .await
    .is_err()
    {
    return Err(IdentityCreateError::ProveFailed(self.name.clone()));
  • replacement in pijul/src/identity/create.rs at line 303
    [4.37060][4.37060:37098](),[4.37098][2.4592:4661]()
    "Linking identity {}@{}",
    &self.config.author.username, &self.config.author.origin
    [4.37060]
    [4.37154]
    "Linking identity `{}` with {}@{}",
    &self.name, &self.config.author.username, &self.config.author.origin
  • replacement in pijul/src/identity/create.rs at line 346
    [4.38529][4.38529:38554](),[4.38554][4.13960:13975](),[4.13975][4.38568:38620](),[4.38568][4.38568:38620](),[4.38620][4.13976:14019]()
    pub async fn create(
    &self,
    no_prompt: bool,
    link_remote: bool,
    ) -> Result<(), IdentityCreateError> {
    [4.38529]
    [4.14019]
    pub async fn create(&self, no_prompt: bool, link_remote: bool) -> Result<(), anyhow::Error> {