Skip to content

Commit

Permalink
Skip empty lines when parsing .git-credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Jan 9, 2022
1 parent 9b62792 commit 4cedc4a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ Most of nicators dependencies are statically linked, so it does not require any
4. Execute `nicator unlock` to enable storing and fetching credentials.
5. Execute `nicator lock` to disable storing and fetching credentials.

`nicator unlock -t SECONDS` allows specifying a timeout after which the credentials become inaccessible. It defaults to 1 hour. It might be handy to create a shell alias to change it consistently. The `-c` and `-s` flags can be used to change the path used for the credentials file and socket file respectively. These should not leak any data as long these files are only readable and writeable by the the file's owner, which nicator takes care of.
`nicator unlock -t SECONDS` allows specifying a timeout after which the credentials become inaccessible.
It defaults to 1 hour. It might be handy to create a shell alias to change it consistently. The `-c` and `-s` flags can be used to change the path used for the credentials file and socket file respectively.
These should not leak any data as long these files are only readable and writeable by the the file's owner, which nicator takes care of when creating these.

An existing `.git-credentials` file can be imported using `nicator import`.

## How nicator works
Unlocking will automatically launch a nicator server/daemon process listening on a unix socket with appropriate permissions (found in `/tmp`), which keeps the password in-memory.
Expand Down
15 changes: 10 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ fn perform_import(options: &ProgramOptions) -> Exit {
rpassword::prompt_password_stdout("Enter passphrase: ")
.expect("Failed to read passphrase from stdin."),
);
let git_credentials =
std::fs::read_to_string(&options.git_credentials).map(SecUtf8::from);
let git_credentials = std::fs::read_to_string(&options.git_credentials).map(SecUtf8::from);
if git_credentials.is_err() {
eprintln!("Failed to open .git-credentials");
return Exit::Failure;
Expand All @@ -323,11 +322,17 @@ fn perform_import(options: &ProgramOptions) -> Exit {
.unwrap()
.unsecure()
.lines()
.map(store::Credential::from_url)
.filter_map(|s| {
if s.is_empty() {
None
} else {
Some(store::Credential::from_url(s))
}
})
.collect();
if credentials.is_err() {
eprintln!("Failed to parse .git-credentials file.");
return Exit::Failure
return Exit::Failure;
}
let store = store::Store::decrypt_from(&options.store, passphrase.unsecure());
match store {
Expand All @@ -340,7 +345,7 @@ fn perform_import(options: &ProgramOptions) -> Exit {
Err(err) => {
eprintln!("Failed to store imported credentials. {}", err);
Exit::Failure
},
}
}
}
Err(err) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const SOCKET_PATH: &str = "./cli-nicator.sock";
const STORE_PATH: &str = "./.cli-credentials";
const GIT_PATH: &str = "./.git-credentials";
const PASSPHRASE: &[u8] = b"abc123\n";
const GIT_CRED: &[u8] = b"https://gituser:[email protected]/repo";
const GIT_CRED: &[u8] = b"\nhttps://gituser:[email protected]/repo";
const WRITE_CRED: &[u8] = b"host=test.com\nprotocol=http\nusername=user\npassword=pw\n";
const READ_CRED: &[u8] = b"host=test.com\nprotocol=http";

Expand Down

0 comments on commit 4cedc4a

Please sign in to comment.