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
7 changes: 7 additions & 0 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ I do.

## How to Install

> [!Note]
> This tool is not yet available on `crates.io`. You can install it from source
> below. To change the default keychain service, you can define `BPB_SERVICE_NAME`
> in your environment at build time.

```sh
git clone https://github.com/pkgxdev/bpb
cd bpb
Expand Down Expand Up @@ -104,9 +109,4 @@ it does not replace any other functionality. For example, if you want to
verify the signatures on other peoples' git commits, it will shell out to gpg.


## TODO

- [ ] Move keychain identifiers out to build variables in `main.rs`


[teaBASE]: https://github.com/teaxyz/teaBASE
1 change: 1 addition & 0 deletions bpb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ serde_derive = "1.0.215"
serde = "1.0.215"
hex = "0.3.2"
failure = "0.1.1"
lazy_static = "1.5.0"

[dependencies.pbp]
path = "../pbp"
Expand Down
11 changes: 11 additions & 0 deletions bpb/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use std::io::{Read, Write};

use failure::Error;
use lazy_static::lazy_static;

lazy_static! {
static ref SERVICE_NAME: String = option_env!("BPB_SERVICE_NAME")
.unwrap_or("xyz.tea.BASE.bpb")
.to_string();
}

#[derive(Serialize, Deserialize)]
pub struct Config {
Expand Down Expand Up @@ -41,6 +48,10 @@ impl Config {
pub fn user_id(&self) -> &str {
&self.public.userid
}

pub fn service(&self) -> &str {
&SERVICE_NAME
}
}

#[derive(Serialize, Deserialize)]
Expand Down
11 changes: 6 additions & 5 deletions bpb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ fn generate_keypair(userid: String) -> Result<(), Error> {
if let Ok(_config) = Config::load() {
eprintln!(
"A keypair already exists. If you (really) want to reinitialize your state\n\
run `security delete-generic-password -s xyz.tea.BASE.bpb` first."
run `security delete-generic-password -s {}` first.",
_config.service()
);
return Ok(());
}
Expand All @@ -79,7 +80,7 @@ fn generate_keypair(userid: String) -> Result<(), Error> {
let config = Config::create(public_key, userid, timestamp)?;
config.write()?;

let service = "xyz.tea.BASE.bpb";
let service = config.service();
let account = config.user_id();
let hex = hex::encode(keypair.to_bytes());
add_keychain_item(service, account, &hex)?;
Expand All @@ -92,7 +93,7 @@ fn generate_keypair(userid: String) -> Result<(), Error> {

fn print_public_key() -> Result<(), Error> {
let config = Config::load()?;
let service = "xyz.tea.BASE.bpb";
let service = config.service();
let account = config.user_id();
let secret_str = get_keychain_item(service, account)?;
let secret = to_32_bytes(&secret_str)?;
Expand All @@ -110,7 +111,7 @@ fn verify_commit() -> Result<(), Error> {
stdin.read_to_string(&mut commit)?;

let config = Config::load()?;
let service = "xyz.tea.BASE.bpb";
let service = config.service();
let account = config.user_id();
let secret_str = get_keychain_item(service, account)?;
let secret = to_32_bytes(&secret_str)?;
Expand All @@ -137,7 +138,7 @@ fn delegate() -> ! {
fn upgrade() -> Result<(), Error> {
let mut file = std::fs::File::open(legacy_keys_file())?;
let (config, secret) = LegacyConfig::convert(&mut file)?;
let service = "xyz.tea.BASE.bpb";
let service = config.service();
let account = config.user_id();
let hex = hex::encode(secret);
add_keychain_item(service, account, &hex)?;
Expand Down
Loading