Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Signing 3 - Key loading/handling in Conductor #1010

Merged
merged 23 commits into from
Feb 19, 2019
Merged

Signing 3 - Key loading/handling in Conductor #1010

merged 23 commits into from
Feb 19, 2019

Conversation

lucksus
Copy link
Collaborator

@lucksus lucksus commented Feb 14, 2019

on top of #968

  • I have added a summary of my changes to the changelog

Context

screenshot 2019-02-14 at 19 34 04
All the pre-work enabling the Conductor to create real signatures from real keys read out of real files.

Steps

  • Conductor gets a new call back KeyLoader that is implemented with a default that reads files from the filesystem and prompts for a passphrase
  • nodejs Conductor provides its own key loader callback to inject deterministic keys for tests that are created from the agent name's SHA256
  • Conductor checks that public keys given in the config match the key load from file

@lucksus lucksus added the review label Feb 14, 2019
@lucksus
Copy link
Collaborator Author

lucksus commented Feb 14, 2019

@neonphog, @zo-el, I had to declare SodiumBuf Send for this to work: 19cde59
Is it safe to send these across threads? We sure need that and I don't see why not, but rustc can't say much about a c_void..

@neonphog
Copy link
Contributor

@lucksus - so long as sodium_init() is called before any functions are invoked, all libsodium functions are thread safe. The memory allocated in SodiumBuf is not mutexed or anything, so not safe to access from multiple threads, but, as you say, sending should be perfectly safe.

I misread this question at first, and thought we needed a clone for SecBuf... here's that code in case it's useful someday, lol. Keys are generally very small so cloning is cheap: https://github.com/holochain/holochain-rust/compare/clone-secbuf

let passphrase = rpassword::read_password_from_tty(Some("Passphrase: "))?;

let bundle: KeyBundle = serde_json::from_str(&contents)?;
let mut passphrase = SecBuf::with_insecure_from_string(passphrase);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passphrases should use secure memory

Ideally, we'd use a low-level keyboard binding to prevent a class of malware keyloggers and input the data directly into a secure buffer.

For the short-term, we should be sure to zero the memory in "passphrase" returned by the rpassword utility.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had tried that already in hc keygen but SodiumBuf doesn't allow arbitrary sizes for secure buffers. Only multiples of 8. Also, since the passphrase is coming in as a String, it wouldn't make it much safer, right?

But yeah, so you are saying, we should roll our own read_password_from_tty eventually?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: ) right, that totally makes sense. I'll create an issue to do the alignment in the background and deal with appropriately sized slice references in the SecBuf so we don't have to worry about the sizing during implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@neonphog neonphog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some security comments. Looking awesome, I'm excited to see this coming together!

@lucksus
Copy link
Collaborator Author

lucksus commented Feb 15, 2019

@neonphog, I've implemented your change requests, except for using a secure SecBuf as that enforces sizes % 8. I've tried padding with zeros but I guess that makes it be a different passphrase. Can't unlock keys with that. Any hint how to use SecBuf with arbitrary length passphrases?

Copy link
Member

@zippy zippy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one tiny change in an error message

let agent_config = self
.config
.agent_by_id(agent_id)
.ok_or(format!("Agent '{}' not found", agent_id))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.ok_or(format!("Agent '{}' not found", agent_id))?;
.ok_or(format!("Agent '{}' not found in config", agent_id))?;

@lucksus lucksus changed the base branch from signing-1 to develop February 19, 2019 18:47
@lucksus lucksus merged commit 90a2aba into develop Feb 19, 2019
@lucksus lucksus removed the review label Feb 19, 2019
@zippy zippy deleted the signing-3 branch July 5, 2019 13:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants