Update Cargo.lock from latest master, update age library to 0.7 (#625)

* Update cargo lock and introduce changes for update to age library

* update bech32 prefix
This commit is contained in:
Yeastplume 2021-11-13 12:19:32 +00:00 committed by GitHub
parent 8547f4a162
commit 1f35feed00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1251 additions and 867 deletions

2074
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -30,7 +30,7 @@ base64 = "0.9"
regex = "1.3" regex = "1.3"
sha2 = "0.8" sha2 = "0.8"
bs58 = "0.3" bs58 = "0.3"
age = "0.4" age = "0.7"
curve25519-dalek = "2.1" curve25519-dalek = "2.1"
secrecy = "0.6" secrecy = "0.6"
bech32 = "0.7" bech32 = "0.7"

View file

@ -435,14 +435,30 @@ impl From<util::OnionV3AddressError> for Error {
} }
} }
impl From<age::Error> for Error { impl From<age::EncryptError> for Error {
fn from(error: age::Error) -> Error { fn from(error: age::EncryptError) -> Error {
Error { Error {
inner: Context::new(ErrorKind::Age(format!("{}", error))), inner: Context::new(ErrorKind::Age(format!("{}", error))),
} }
} }
} }
impl From<age::DecryptError> for Error {
fn from(error: age::DecryptError) -> Error {
Error {
inner: Context::new(ErrorKind::Age(format!("{}", error))),
}
}
}
impl From<&str> for Error {
fn from(error: &str) -> Error {
Error {
inner: Context::new(ErrorKind::Age(format!("Bech32 Key Encoding - {}", error))),
}
}
}
impl From<bech32::Error> for Error { impl From<bech32::Error> for Error {
fn from(error: bech32::Error) -> Error { fn from(error: bech32::Error) -> Error {
Error { Error {

View file

@ -67,6 +67,14 @@ impl SlatepackAddress {
// add length byte // add length byte
Ok(encoded.as_bytes().len() + 1) Ok(encoded.as_bytes().len() + 1)
} }
/// utility to construct a public key that can be read by age 0.5+,
/// for some reason the author decided the library can no longer accept
/// x25519 keys to construct its types even though it uses them under the hood
pub fn to_age_pubkey_str(&self) -> Result<String, Error> {
let x_key = xDalekPublicKey::try_from(self)?;
Ok(bech32::encode("age", x_key.as_bytes().to_base32())?.to_string())
}
} }
impl Display for SlatepackAddress { impl Display for SlatepackAddress {

View file

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use bech32::{self, ToBase32};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
/// Slatepack Types + Serialization implementation /// Slatepack Types + Serialization implementation
use ed25519_dalek::SecretKey as edSecretKey; use ed25519_dalek::SecretKey as edSecretKey;
@ -25,7 +26,6 @@ use grin_wallet_util::byte_ser;
use super::SlatepackAddress; use super::SlatepackAddress;
use std::convert::TryInto;
use std::fmt; use std::fmt;
use std::io::{Cursor, Read, Write}; use std::io::{Cursor, Read, Write};
@ -158,8 +158,8 @@ impl Slatepack {
let rec_keys: Result<Vec<_>, _> = recipients let rec_keys: Result<Vec<_>, _> = recipients
.into_iter() .into_iter()
.map(|addr| { .map(|addr| {
let key = age::keys::RecipientKey::X25519((&addr).try_into()?); let recp_key: age::x25519::Recipient = addr.to_age_pubkey_str()?.parse()?;
Ok(key) Ok(Box::new(recp_key) as Box<dyn age::Recipient>)
}) })
.collect(); .collect();
@ -170,7 +170,7 @@ impl Slatepack {
let encryptor = age::Encryptor::with_recipients(keys); let encryptor = age::Encryptor::with_recipients(keys);
let mut encrypted = vec![]; let mut encrypted = vec![];
let mut writer = encryptor.wrap_output(&mut encrypted, age::Format::Binary)?; let mut writer = encryptor.wrap_output(&mut encrypted)?;
writer.write_all(&to_encrypt)?; writer.write_all(&to_encrypt)?;
writer.finish()?; writer.finish()?;
self.payload = encrypted.to_vec(); self.payload = encrypted.to_vec();
@ -195,14 +195,16 @@ impl Slatepack {
b.copy_from_slice(&result[0..32]); b.copy_from_slice(&result[0..32]);
let x_dec_secret = StaticSecret::from(b); let x_dec_secret = StaticSecret::from(b);
let key = age::keys::SecretKey::X25519(x_dec_secret); let x_dec_secret_bech32 =
bech32::encode("age-secret-key-", (&x_dec_secret).to_bytes().to_base32())?;
let key: age::x25519::Identity = x_dec_secret_bech32.parse()?;
let decryptor = match age::Decryptor::new(&self.payload[..])? { let decryptor = match age::Decryptor::new(&self.payload[..])? {
age::Decryptor::Recipients(d) => d, age::Decryptor::Recipients(d) => d,
_ => unreachable!(), _ => unreachable!(),
}; };
let mut decrypted = vec![]; let mut decrypted = vec![];
let mut reader = decryptor.decrypt(&[key.into()])?; let mut reader = decryptor.decrypt(std::iter::once(&key as &dyn age::Identity))?;
reader.read_to_end(&mut decrypted)?; reader.read_to_end(&mut decrypted)?;
// Parse encrypted metadata from payload, first 4 bytes of decrypted payload // Parse encrypted metadata from payload, first 4 bytes of decrypted payload
// will be encrypted metadata length // will be encrypted metadata length