Skip to content

Commit cdafffb

Browse files
committed
Fix key loading issue:
When we upgraded dalek-ed25519, we switched from a Keypair-centric API to a SigningKey-centric API, but inadvertently changed the format of the generated trust-key-v2 file to only include the private key. This is actually a better format, so we'll keep using it, and just truncate an incoming 64-byte file to 32 bytes to get the signing key, if that's the format it has.
1 parent 4b92df0 commit cdafffb

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/trust.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,15 @@ fn load_or_generate_signer() -> Result<SigningKey, Error> {
8888
};
8989
match r_o_bytes? {
9090
Some(bytes) => {
91-
let key = SigningKey::from_keypair_bytes(&bytes.try_into().unwrap())?;
92-
Ok(key)
91+
// We used to write the entire keypair to the file, but now we only write the private key.
92+
// So it's important to take only the first 32 bytes here.
93+
let key_bytes: [u8; 32] = bytes[..32].try_into()
94+
.map_err(|_| anyhow::anyhow!("Invalid key length"))?;
95+
Ok(SigningKey::from_bytes(&key_bytes))
9396
}
9497
None => {
9598
let mut csprng = OsRng {};
96-
let seed = SigningKey::generate(&mut csprng);
99+
let key = SigningKey::generate(&mut csprng);
97100

98101
fs::create_dir_all(Path::new(&path).to_path_buf().parent().unwrap())?;
99102
let mut file = match File::create(OsString::from(&path)) {
@@ -102,8 +105,9 @@ fn load_or_generate_signer() -> Result<SigningKey, Error> {
102105
Ok(f) => f,
103106
};
104107

105-
file.write_all(&seed.to_bytes())?;
106-
Ok(seed)
108+
// Write out just the 32-byte private key.
109+
file.write_all(&key.to_bytes())?;
110+
Ok(key)
107111
}
108112
}
109113
}

0 commit comments

Comments
 (0)