doy / rbw

unofficial bitwarden cli
https://git.tozt.net/rbw
Other
573 stars 82 forks source link

rbw login: failed to log in to bitwarden instance: failed to parse JSON: EOF while parsing a value at line 1 column 0 #148

Closed Philip-Wittamore closed 6 months ago

Philip-Wittamore commented 7 months ago

bw login works Firefox extension works

rbw login: failed to log in to bitwarden instance: failed to parse JSON: EOF while parsing a value at line 1 column 0

I've tried rotating encryption keys, adding backslash at the end of the paths, forcing ipv4, but no luck.

my laptop: arch linux rbw 1.8.3

philip@T430-1 ~ $ rbw config show { "email": "xxx@xxxx.xxx", "base_url": "https://api.bitwarden.eu", "identity_url": "https://identity.bitwarden.eu", "notifications_url": "https://notifications.bitwarden.eu", "lock_timeout": 3600, "sync_interval": 3600, "pinentry": "pinentry", "client_cert_path": null }

partial copy of strace:

connect(3, {sa_family=AF_UNIX, sun_path="/run/user/1000/rbw/socket"}, 28) = 0 ioctl(0, TCGETS, {c_iflag=ICRNL|IXON|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0 newfstatat(0, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}, AT_EMPTY_PATH) = 0 readlink("/proc/self/fd/0", "/dev/pts/0", 4095) = 10 newfstatat(AT_FDCWD, "/dev/pts/0", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}, 0) = 0 write(3, "{\"tty\":\"/dev/pts/0\",\"action\":{\"t"..., 48) = 48 write(3, "\n", 1) = 1 recvfrom(3, "{\"type\":\"Version\",\"version\":1008"..., 8192, 0, NULL, NULL) = 37 close(3) = 0 socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0) = 3 connect(3, {sa_family=AF_UNIX, sun_path="/run/user/1000/rbw/socket"}, 28) = 0 ioctl(0, TCGETS, {c_iflag=ICRNL|IXON|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0 newfstatat(0, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}, AT_EMPTY_PATH) = 0 readlink("/proc/self/fd/0", "/dev/pts/0", 4095) = 10 newfstatat(AT_FDCWD, "/dev/pts/0", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}, 0) = 0 write(3, "{\"tty\":\"/dev/pts/0\",\"action\":{\"t"..., 46) = 46 write(3, "\n", 1) = 1 recvfrom(3, "{\"type\":\"Error\",\"error\":\"failed "..., 8192, 0, NULL, NULL) = 134 close(3) = 0 write(2, "rbw login", 9rbw login) = 9 write(2, ": ", 2: ) = 2 write(2, "failed to log in to bitwarden in"..., 106failed to log in to bitwarden instance: failed to parse JSON: EOF while parsing a value at line 1 column 0) = 106 write(2, "\n", 1 ) = 1

matt-snider commented 6 months ago

Just noting this is probably related to (or a duplicate of) #145 or #32

Ironedde commented 6 months ago

I think I have found the culprit for this. Looking insidesrc/config you can find a section defining the default base_url and how to format a custom one:

    pub fn base_url(&self) -> String {
        self.base_url.clone().map_or_else(
            || "https://api.bitwarden.com".to_string(),
            |url| format!("{}/api", url.trim_end_matches('/')),
        )
    }

When Bitwarden introduced the EU servers they used the same style of URL as the US one: https://api.bitwarden.eu. But the code added on an /api at the end for all "custom" URL:s, which doesn't work the official instance. Understandable, of course, since the EU servers probably didn't exist when this code was original written

Adding something like this will solve the issue:

-            |url| format!("{}/api", url.trim_end_matches('/')),
+            |url| {
+                let clean_url = format!("{}", url.trim_end_matches('/'));
+                if clean_url == "https://api.bitwarden.eu" {
+                    return clean_url
+                } else {
+                    format!("{}/api", clean_url)
+                }
+            },

I can write a PR for this when I'm back from traveling on Monday. :+1:

Morten03Nordbye commented 6 months ago

Any status on this?

Ironedde commented 6 months ago

Any status on this?

Sorry, it took a while.

Feel free to try the solution provided in #152.

You can run the agent standalone with more debugging like this: RUST_LOG=trace ./target/release/rbw-agent --no-daemonize

Morten03Nordbye commented 6 months ago

I can conform it worked

Philip-Wittamore commented 6 months ago

Confirmed fixed in rbw-1.9.0-1 arch package. Thanks!

jurgenmehja commented 5 months ago

Having the same issue with the latest arch package, is there a way to debug it? Using the default config btw. Thanks!

TheNilesh commented 4 months ago

When I do rbw register it does not complain, but whenever I do rbw login|ls|get it returns the following error:

rbw login: failed to log in to bitwarden instance: failed to parse JSON: EOF while parsing a value at line 1 column 0
$ rbw --version
rbw 1.9.0