Update to support the latest KeePassXC

This commit is contained in:
varjolintu
2021-01-16 14:39:56 +02:00
parent 211ae91e36
commit 338735e6f4
4 changed files with 90 additions and 90 deletions
Generated
+25 -25
View File
@@ -1,91 +1,91 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "bitflags"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
[[package]]
name = "byteorder"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
[[package]]
name = "cc"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275"
[[package]]
name = "cfg-if"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
[[package]]
name = "keepassxc-proxy"
version = "0.1.0"
dependencies = [
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"named_pipe 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder",
"named_pipe",
"nix",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi",
"winapi-build",
]
[[package]]
name = "libc"
version = "0.2.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
[[package]]
name = "named_pipe"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "516fe2b5b1131f912a3d4e0cbfec369ca9a65f89d477c15d86ef0fc376faaa55"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys",
"winapi",
]
[[package]]
name = "nix"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d37e713a259ff641624b6cb20e3b12b2952313ba36b6823c0f16e6cfd9e5de17"
dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags",
"cc",
"cfg-if",
"libc",
"void",
]
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
"checksum cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275"
"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
"checksum named_pipe 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "516fe2b5b1131f912a3d4e0cbfec369ca9a65f89d477c15d86ef0fc376faaa55"
"checksum nix 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d37e713a259ff641624b6cb20e3b12b2952313ba36b6823c0f16e6cfd9e5de17"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
+3 -3
View File
@@ -4,11 +4,11 @@ Application that works as a proxy between Native Messaging browser extension and
This is still under development. Installing the proxy needs manual changes to JSON scripts installed for Native Messaging.
See [this page](https://developer.chrome.com/extensions/nativeMessaging) for further information.
keepassxc-proxy listens stdin from keepassxc-browser extension and transfers the data to Unix domain socket `XDG_RUNTIME_DIR` or `/tmp/kpxc_server` which KeePassXC listens.
With Windows this is a named pipe under `keepassxc\<username>\kpxc_server`.
keepassxc-proxy listens stdin from keepassxc-browser extension and transfers the data to Unix domain socket `XDG_RUNTIME_DIR` or `/tmp/org.keepassxc.KeePassXC.BrowserServer` which KeePassXC listens.
With Windows this is a named pipe under `org.keepassxc.KeePassXC.BrowserServer\<username>`.
```
Copyright (C) 2017-2018 Sami Vänttinen <sami.vanttinen@protonmail.com>
Copyright (C) 2017-2021 Sami Vänttinen <sami.vanttinen@protonmail.com>
Copyright (C) 2017-2018 Andy Brandt <andy@brandt.tech>
This program is free software: you can redistribute it and/or modify
+34 -34
View File
@@ -14,58 +14,58 @@ use proxy_socket::ProxySocket;
const BUFFER_SIZE: u32 = 1024 ^ 2; // 1024 ^ 2 is the maximum
fn valid_length(length: u32) -> bool {
return length > 0 && length <= BUFFER_SIZE;
return length > 0 && length <= BUFFER_SIZE;
}
fn read_header() -> u32 {
let stdin = io::stdin();
let mut buf = vec![0; 4];
let mut handle = stdin.lock();
let stdin = io::stdin();
let mut buf = vec![0; 4];
let mut handle = stdin.lock();
handle.read_exact(&mut buf).unwrap();
NativeEndian::read_u32(&buf)
handle.read_exact(&mut buf).unwrap();
NativeEndian::read_u32(&buf)
}
fn read_body<T: Read + Write>(length: u32, socket: &mut ProxySocket<T>) {
let mut buffer = vec![0; length as usize];
let stdin = io::stdin();
let mut handle = stdin.lock();
let mut buffer = vec![0; length as usize];
let stdin = io::stdin();
let mut handle = stdin.lock();
if let Ok(_) = handle.read_exact(&mut buffer) {
if valid_length(length) {
socket.write(&buffer).unwrap();
socket.flush().unwrap();
read_response(socket);
}
}
if let Ok(_) = handle.read_exact(&mut buffer) {
if valid_length(length) {
socket.write(&buffer).unwrap();
socket.flush().unwrap();
read_response(socket);
}
}
}
fn read_response<T: Read>(socket: &mut ProxySocket<T>) {
let mut buf = vec![0; BUFFER_SIZE as usize];
if let Ok(len) = socket.read(&mut buf) {
write_response(&buf[0..len]);
}
let mut buf = vec![0; BUFFER_SIZE as usize];
if let Ok(len) = socket.read(&mut buf) {
write_response(&buf[0..len]);
}
}
fn write_response(buf: &[u8]) {
let stdout = io::stdout();
let mut out = stdout.lock();
let stdout = io::stdout();
let mut out = stdout.lock();
out.write_u32::<NativeEndian>(buf.len() as u32).unwrap();
out.write(buf).unwrap();
out.flush().unwrap();
out.write_u32::<NativeEndian>(buf.len() as u32).unwrap();
out.write(buf).unwrap();
out.flush().unwrap();
}
fn main() {
let mut socket = proxy_socket::connect(BUFFER_SIZE).unwrap();
let mut socket = proxy_socket::connect(BUFFER_SIZE).unwrap();
// Start thread for user input reading
let ui = thread::spawn(move || {
loop {
let length = read_header();
read_body(length, &mut socket);
}
});
// Start thread for user input reading
let ui = thread::spawn(move || {
loop {
let length = read_header();
read_body(length, &mut socket);
}
});
let _ui_res = ui.join().unwrap();
let _ui_res = ui.join().unwrap();
}
+28 -28
View File
@@ -12,48 +12,48 @@ use nix::sys::socket::sockopt::RcvBuf;
use named_pipe::PipeClient;
pub struct ProxySocket<T> {
inner: T,
inner: T,
}
impl<R: Read> Read for ProxySocket<R> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.read(buf)
}
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.read(buf)
}
}
impl<W: Write> Write for ProxySocket<W> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.write(buf)
}
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.write(buf)
}
fn flush(&mut self) -> io::Result<()> {
self.inner.flush()
}
fn flush(&mut self) -> io::Result<()> {
self.inner.flush()
}
}
#[cfg(windows)]
pub fn connect(buffer_size: u32) -> io::Result<ProxySocket<PipeClient>> {
let username = env::var("USERNAME").unwrap();
let pipe_name = format!("\\\\.\\pipe\\keepassxc\\{}\\kpxc_server", username);
let client = PipeClient::connect(pipe_name)?;
Ok(ProxySocket { inner: client })
let username = env::var("USERNAME").unwrap();
let pipe_name = format!("\\\\.\\pipe\\keepassxc\\{}\\org.keepassxc.KeePassXC.BrowserServer", username);
let client = PipeClient::connect(pipe_name)?;
Ok(ProxySocket { inner: client })
}
#[cfg(not(windows))]
pub fn connect(buffer_size: u32) -> io::Result<ProxySocket<UnixStream>> {
use std::time::Duration;
use std::time::Duration;
let socket_name = "kpxc_server";
let socket: String;
if let Ok(dir) = if cfg!(target_os = "macos") {env::var("TMPDIR") } else { env::var("XDG_RUNTIME_DIR") } {
socket = format!("{}/{}", dir, socket_name);
} else {
socket = format!("/tmp/{}", socket_name);
}
let s = UnixStream::connect(socket)?;
socket::setsockopt(s.as_raw_fd(), SndBuf, &(buffer_size as usize)).expect("setsockopt for SndBuf failed");
socket::setsockopt(s.as_raw_fd(), RcvBuf, &(buffer_size as usize)).expect("setsockopt for RcvBuf failed");
let timeout: Option<Duration> = Some(Duration::from_secs(1));
s.set_read_timeout(timeout)?;
Ok(ProxySocket { inner: s })
let socket_name = "org.keepassxc.KeePassXC.BrowserServer";
let socket: String;
if let Ok(dir) = if cfg!(target_os = "macos") {env::var("TMPDIR") } else { env::var("XDG_RUNTIME_DIR") } {
socket = format!("{}/{}", dir, socket_name);
} else {
socket = format!("/tmp/{}", socket_name);
}
let s = UnixStream::connect(socket)?;
socket::setsockopt(s.as_raw_fd(), SndBuf, &(buffer_size as usize)).expect("setsockopt for SndBuf failed");
socket::setsockopt(s.as_raw_fd(), RcvBuf, &(buffer_size as usize)).expect("setsockopt for RcvBuf failed");
let timeout: Option<Duration> = Some(Duration::from_secs(1));
s.set_read_timeout(timeout)?;
Ok(ProxySocket { inner: s })
}