Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird bug with hex conversions on macOS #4

Closed
alexwlchan opened this issue Jan 29, 2017 · 3 comments
Closed

Weird bug with hex conversions on macOS #4

alexwlchan opened this issue Jan 29, 2017 · 3 comments

Comments

@alexwlchan
Copy link

I have a weird bug where certain strings cause keyring-rs to throw an error on macOS. I haven’t worked out exactly what’s causing it, but it looks like my keychain entries are being interpreted as hex, and that’s throwing it off.

If I create a keychain entry ("testing", "password", "aa"), put the following in main.rs and then call cargo run:

// main.rs
extern crate keyring;

fn main() {
    println!("{:?}", keyring::Keyring::new("testing", "username").get_password());
}

I get the following error:

thread 'main' panicked at 'error converting hex to utf8: FromUtf8Error { bytes: [170], error: Utf8Error { valid_up_to: 0 } }', ../src/libcore/result.rs:788
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: Process didn't exit successfully: `target/debug/testing` (exit code: 101)

Other strings that produce the error: bb, c1, 99, 90, 80.

I get the correct result with 7f.

If I try hex strings below 7f (e.g. 6a, 00, 0a), the program exits correctly but the item it retrieves from the keychain is incorrect. e.g. if the keychain entry is 6a, it prints Ok("j").

Versions:

$ rustc --version
rustc 1.12.1 (d4f39402a 2016-10-19)

$ cat Cargo.toml
[package]
name = "testing"
version = "0.1.0"
authors = ["Alex Chan <alex@alexwlchan.net>"]

[dependencies]
keyring = "0.1.1"

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.12.2
BuildVersion:	16C67
@alexwlchan
Copy link
Author

I’m using the following diff in my fork, and that seems to have resolved my problems for now:

                 if output.status.success() {		                 if output.status.success() {
                     let output_string = String::from_utf8(output.stdout).unwrap().trim().to_owned();		                     let output_string = String::from_utf8(output.stdout).unwrap().trim().to_owned();
                     // padded with extra 'ffffff' before each octet?		
+                    Ok(output_string)
-                    //println!("{:?}", output_string);
-                    match output_string.from_hex() {		
-                        Ok(bytes) => {		
-                            // filter out extra 255?		
-                            let bytes: Vec<_> = bytes.into_iter().filter(|&b| b != 255).collect();		
-                            Ok(String::from_utf8(bytes).expect("error converting hex to utf8"))		
-                        },		
-                        _ => Ok(output_string),		
-                    }		
                 } else {
                     Err(KeyringError::MacOsKeychainError)
                 }		

@hwchen
Copy link
Owner

hwchen commented Jan 29, 2017

Hi,

Thanks for the report! I'm in the process of procuring a mac to help finish up development on this library.

I should be able to push a fix to crates.io by the end of the week, hope you can make do for now. I need to go back and verify the behavior of http://stackoverflow.com/questions/22370552/keychain-services-secure-notes and see if I just made a dumb mistake in the original implementation.

After that, I'm going to finish up my plans for this lib:

@hwchen hwchen mentioned this issue Feb 13, 2017
@hwchen
Copy link
Owner

hwchen commented Feb 13, 2017

Closed by #6. Now handles utf8 passwords (including "special chars) on osx correctly. Version is bumped to 0.2

@hwchen hwchen closed this as completed Feb 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants