Skip to content

Commit

Permalink
Merge pull request #587 from breez/ok300-bump-ecies
Browse files Browse the repository at this point in the history
Bump ecies dependency
  • Loading branch information
ok300 authored Nov 6, 2023
2 parents 35af4b1 + 2dd76dc commit a12e372
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 170 deletions.
103 changes: 25 additions & 78 deletions libs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/sdk-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gl-client = { git = "https://github.com/Blockstream/greenlight.git", features =
zbase32 = "0.1.2"
base64 = "0.13.0"
chrono = "0.4"
ecies = { version = "0.2", default-features = false, features = ["pure"] }
ecies = { version = "0.2.6", default-features = false, features = ["pure"] }
env_logger = "0.10"
futures = "0.3.28"
ripemd = "0.1"
Expand Down
8 changes: 4 additions & 4 deletions libs/sdk-core/src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};

use anyhow::{anyhow, Result};
use ecies::utils::{aes_decrypt, aes_encrypt};
use ecies::symmetric::{sym_decrypt, sym_encrypt};
use miniz_oxide::{deflate::compress_to_vec, inflate::decompress_to_vec_with_limit};
use std::{
fs::{self, File},
Expand Down Expand Up @@ -390,11 +390,11 @@ impl BackupWorker {
match state {
Some(state) => {
let mut decrypted =
aes_decrypt(self.encryption_key.as_slice(), state.data.as_slice());
sym_decrypt(self.encryption_key.as_slice(), state.data.as_slice());
if decrypted.is_none() {
warn!("Failed to decrypt backup with new key, trying legacy key");
decrypted =
aes_decrypt(self.legacy_encryption_key.as_slice(), state.data.as_slice());
sym_decrypt(self.legacy_encryption_key.as_slice(), state.data.as_slice());
}
let decrypted_data = decrypted.ok_or(anyhow!("Failed to decrypt backup"))?;
match decompress_to_vec_with_limit(&decrypted_data, 4000000) {
Expand All @@ -419,7 +419,7 @@ impl BackupWorker {
compressed_data.len()
);
let encrypted_data =
aes_encrypt(self.encryption_key.as_slice(), compressed_data.as_slice())
sym_encrypt(self.encryption_key.as_slice(), compressed_data.as_slice())
.ok_or(anyhow!("Failed to encrypt backup"))?;
let version = self.inner.push(version, encrypted_data.clone()).await?;
Ok((version, encrypted_data))
Expand Down
6 changes: 3 additions & 3 deletions libs/sdk-core/src/crypt.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use anyhow::Result;
use anyhow::{anyhow, Result};

pub fn encrypt(key: Vec<u8>, msg: Vec<u8>) -> Result<Vec<u8>> {
match ecies::encrypt(key.as_slice(), msg.as_slice()) {
Ok(res) => Ok(res),
Err(err) => Err(err.into()),
Err(err) => Err(anyhow!(err.to_string())),
}
}

#[allow(dead_code)]
pub fn decrypt(key: Vec<u8>, msg: Vec<u8>) -> Result<Vec<u8>> {
match ecies::decrypt(key.as_slice(), msg.as_slice()) {
Ok(res) => Ok(res),
Err(err) => Err(err.into()),
Err(err) => Err(anyhow!(err.to_string())),
}
}
8 changes: 4 additions & 4 deletions libs/sdk-core/src/greenlight/node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use bitcoin::secp256k1::PublicKey;
use bitcoin::secp256k1::Secp256k1;
use bitcoin::util::bip32::{ChildNumber, ExtendedPrivKey};
use bitcoin::{Address, OutPoint, Script, Sequence, Transaction, TxIn, TxOut, Txid, Witness};
use ecies::utils::{aes_decrypt, aes_encrypt};
use ecies::symmetric::{sym_decrypt, sym_encrypt};
use gl_client::node::ClnClient;
use gl_client::pb::cln::listinvoices_invoices::ListinvoicesInvoicesStatus;
use gl_client::pb::cln::listpays_pays::ListpaysPaysStatus;
Expand Down Expand Up @@ -99,11 +99,11 @@ impl Greenlight {
let parsed_credentials: Result<GreenlightCredentials> = match credentials {
// In case we found existing credentials, try to decrypt them and connect to the node
Some(creds) => {
let mut decrypted_credentials = aes_decrypt(encryption_key_slice, creds.as_slice());
let mut decrypted_credentials = sym_decrypt(encryption_key_slice, creds.as_slice());
if decrypted_credentials.is_none() {
info!("Failed to decrypt credentials, trying legacy key");
decrypted_credentials =
aes_decrypt(legacy_encryption_key_slice, creds.as_slice());
sym_decrypt(legacy_encryption_key_slice, creds.as_slice());
}
match decrypted_credentials {
Some(creds) => {
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Greenlight {
let res = match parsed_credentials {
Ok(creds) => {
let json_creds = serde_json::to_string(&creds)?.as_bytes().to_vec();
let encryptd_creds = aes_encrypt(encryption_key_slice, json_creds.as_slice());
let encryptd_creds = sym_encrypt(encryption_key_slice, json_creds.as_slice());
match encryptd_creds {
Some(c) => {
persister.set_gl_credentials(c)?;
Expand Down
Loading

0 comments on commit a12e372

Please sign in to comment.