Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master

env:
CARGO_TERM_COLOR: always

jobs:
linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.85.0
components: rustfmt, clippy
override: true
- name: rustfmt
run: cargo fmt -- --check
- name: clippy
run: cargo clippy --all-targets -- -D warnings

tests:
needs: linter
strategy:
matrix:
toolchain:
- 1.76
- nightly
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
override: true
profile: minimal
- name: tests
run: cargo test --verbose --color always -- --nocapture
build:
needs: tests
strategy:
matrix:
toolchain:
- 1.76
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
override: true
profile: minimal
- name: build
run: cargo build --release --features "cli miniscript_latest"
- name: build
run: cargo build --release --no-default-features --features "miniscript_12_0"
build_wasm:
needs: tests
strategy:
matrix:
toolchain:
- 1.82
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
override: true
profile: minimal
- name: tests
run: rustup target add wasm32-unknown-unknown && rustup target add wasm32-wasip1 && cargo build --target wasm32-unknown-unknown --no-default-features --features "miniscript_latest"
1 change: 1 addition & 0 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ clean:
rm -fRd encrypted_backup.profdata
rm -fRd coverage
rm -fRd *.profraw
rm -fRd Cargo.lock

test:
cargo test --features "rand" -- --nocapture
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ readme = "README.md"
description = "Bitcoin Encrypted Backup"
documentation = "https://docs.rs/bitcoin-encrypted-backup"
license-file = "LICENSE"
repository = "https://github.com/pythcoiner/encrypted_backup"
repository = "https://github.com/pythcoiner/bitcoin-encrypted-backup"

[dependencies]
aes-gcm = {version = "0.10.3", default-features = false, features = ["aes", "alloc"]}
Expand Down
25 changes: 8 additions & 17 deletions fuzz/fuzz_targets/encode.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![no_main]

extern crate encrypted_backup;
use encrypted_backup::{
extern crate bitcoin_encrypted_backup;
use bitcoin_encrypted_backup::{
Content, Encryption, Version,
ll::{
decode_v1, encode_derivation_paths, encode_encrypted_payload, encode_individual_secrets,
encode_v1, increment_offset, nonce, parse_derivation_paths, parse_individual_secrets,
encode_v1, increment_offset, nonce, parse_content_metadata, parse_derivation_paths,
parse_individual_secrets,
},
miniscript::bitcoin::bip32::DerivationPath,
};

use libfuzzer_sys::fuzz_target;
Expand All @@ -23,7 +23,7 @@ fn content(bytes: &[u8]) -> (usize, Content) {
if bytes.is_empty() {
return (1, Content::Unknown);
}
(1, Content::from(bytes[0]))
parse_content_metadata(bytes).unwrap_or((1, Content::Unknown))
}
fn encryption(bytes: &[u8]) -> (usize, Encryption) {
if bytes.is_empty() {
Expand Down Expand Up @@ -52,14 +52,14 @@ fuzz_target!(|bytes: &[u8]| {
} else {
return;
};
let (incr, content) = content(&bytes[offset..]);
let (incr, _content) = content(&bytes[offset..]);
offset = if let Ok(o) = increment_offset(bytes, offset, incr) {
o
} else {
return;
};
let (incr, encryption) = encryption(&bytes[offset..]);
offset = if let Ok(o) = increment_offset(bytes, offset, incr) {
let _offset = if let Ok(o) = increment_offset(bytes, offset, incr) {
o
} else {
return;
Expand All @@ -74,16 +74,7 @@ fuzz_target!(|bytes: &[u8]| {

let payload = encode_encrypted_payload(nonce(), "0".as_bytes()).unwrap();

let bytes = encode_v1(
version.into(),
deriv,
secrets,
content.into(),
encryption.into(),
payload,
);

// println!("encoded: {bytes:?}");
let bytes = encode_v1(version.into(), deriv, secrets, encryption.into(), payload);

let _ = decode_v1(&bytes).unwrap();
});
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/parse_deriv_paths.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_main]

use encrypted_backup::ll::parse_derivation_paths;
use bitcoin_encrypted_backup::ll::parse_derivation_paths;
use libfuzzer_sys::fuzz_target;

fuzz_target!(|bytes: &[u8]| {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/parse_encrypted_payload.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_main]

use encrypted_backup::ll::parse_encrypted_payload;
use bitcoin_encrypted_backup::ll::parse_encrypted_payload;
use libfuzzer_sys::fuzz_target;

fuzz_target!(|bytes: &[u8]| {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/parse_individual_secrets.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_main]

use encrypted_backup::ll::parse_individual_secrets;
use bitcoin_encrypted_backup::ll::parse_individual_secrets;
use libfuzzer_sys::fuzz_target;

fuzz_target!(|bytes: &[u8]| {
Expand Down
15 changes: 7 additions & 8 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ pub use mscript_12_3_5 as miniscript;
use clap::Parser;
use clap::Subcommand;

use bitcoin_encrypted_backup as encrypted_backup;

use encrypted_backup::Decrypted;
use encrypted_backup::EncryptedBackup;
use bitcoin_encrypted_backup::Decrypted;
use bitcoin_encrypted_backup::EncryptedBackup;
use miniscript::descriptor::DescriptorKeyParseError;
use miniscript::Descriptor;
use miniscript::DescriptorPublicKey;
Expand Down Expand Up @@ -38,8 +36,8 @@ pub enum CliError {
OpenError(std::io::Error),
WriteError(std::io::Error),
ReadError(std::io::Error),
FailedToEncrypt(encrypted_backup::Error),
FailedToDecrypt(encrypted_backup::Error),
FailedToEncrypt(bitcoin_encrypted_backup::Error),
FailedToDecrypt(bitcoin_encrypted_backup::Error),
Content,
NoKeys,
}
Expand Down Expand Up @@ -201,7 +199,7 @@ async fn main() -> Result<(), CliError> {
#[cfg(feature = "devices")]
let mut keys = {
let deriv_paths = backup.get_derivation_paths();
encrypted_backup::signing_devices::collect_xpubs(deriv_paths).await
bitcoin_encrypted_backup::signing_devices::collect_xpubs(deriv_paths).await
};

#[cfg(not(feature = "devices"))]
Expand All @@ -215,7 +213,8 @@ async fn main() -> Result<(), CliError> {
return Err(CliError::NoKeys);
}

let (pks, _) = encrypted_backup::descriptor::dpks_to_derivation_keys_paths(&keys);
let (pks, _) =
bitcoin_encrypted_backup::descriptor::dpks_to_derivation_keys_paths(&keys);

let decrypted = backup
.set_keys(pks)
Expand Down
2 changes: 1 addition & 1 deletion src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn dpks_to_derivation_keys_paths(
(keys, deriv)
}

#[cfg(test)]
#[cfg(all(test, feature = "rand"))]
pub mod tests {
use super::*;
use alloc::{str::FromStr, vec};
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl From<ll::Error> for Error {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "rand"))]
mod tests {
use miniscript::bitcoin;

Expand Down
7 changes: 5 additions & 2 deletions src/ll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ pub fn parse_content_metadata(bytes: &[u8]) -> Result<(usize, Content), Error> {
0 => Ok((1, Content::None)),
1 => Err(Error::ContentMetadata),
2 => {
if bytes.len() < 3 {
return Err(Error::ContentMetadata);
}
let bip_number = u16::from_be_bytes(bytes[1..3].try_into().expect("len ok"));
match bip_number {
380 => Ok((3, Content::Bip380)),
Expand All @@ -114,7 +117,7 @@ pub fn parse_content_metadata(bytes: &[u8]) -> Result<(usize, Content), Error> {
}
}
len => {
let end = (len + 1) as usize;
let end = (len as usize + 1).min(bytes.len());
let data = &bytes[1..end].to_vec();
Ok((end, Content::Proprietary(data.to_vec())))
}
Expand Down Expand Up @@ -611,7 +614,7 @@ pub fn parse_encrypted_payload(
Ok((nonce, cyphertext))
}

#[cfg(test)]
#[cfg(all(test, feature = "rand"))]
mod tests {
use alloc::string::{String, ToString};
use core::str::FromStr;
Expand Down
Loading