Fix login on main bitwarden instance

This commit is contained in:
Bernd Schoolmann 2023-09-11 14:14:27 +02:00
parent 31cf9746d5
commit ca320de77c
No known key found for this signature in database
4 changed files with 20 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package bitwarden
import ( import (
"bytes" "bytes"
"context" "context"
"fmt"
"net/url" "net/url"
"os" "os"
"os/signal" "os/signal"
@ -71,13 +72,13 @@ func connectToWebsocket(ctx context.Context, vault *vault.Vault, cfg *config.Con
interrupt := make(chan os.Signal, 1) interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt) signal.Notify(interrupt, os.Interrupt)
url, err := url.Parse(cfg.ConfigFile.ApiUrl) url, err := url.Parse(cfg.ConfigFile.NotificationsUrl)
if err != nil { if err != nil {
return err return err
} }
token, err := cfg.GetToken() token, err := cfg.GetToken()
var websocketURL = "wss://" + url.Host + "/notifications/hub?access_token=" + token.AccessToken var websocketURL = "wss://" + url.Host + url.Path + "/hub?access_token=" + token.AccessToken
c, _, err := websocket.DefaultDialer.Dial(websocketURL, nil) c, _, err := websocket.DefaultDialer.Dial(websocketURL, nil)
if err != nil { if err != nil {
return err return err
@ -87,11 +88,14 @@ func connectToWebsocket(ctx context.Context, vault *vault.Vault, cfg *config.Con
websocketLog.Info("Connected to websocket server...") websocketLog.Info("Connected to websocket server...")
done := make(chan struct{}) done := make(chan struct{})
//handshake required for official bitwarden implementation
c.WriteMessage(1, []byte(`{"protocol":"messagepack","version":1}`))
go func() { go func() {
defer close(done) defer close(done)
for { for {
_, message, err := c.ReadMessage() mt, message, err := c.ReadMessage()
fmt.Println(mt)
if err != nil { if err != nil {
websocketLog.Error("Error reading websocket message %s", err) websocketLog.Error("Error reading websocket message %s", err)
return return

View File

@ -37,6 +37,7 @@ type RuntimeConfig struct {
WebsocketDisabled bool WebsocketDisabled bool
ApiURI string ApiURI string
IdentityURI string IdentityURI string
NotificationsURI string
SingleProcess bool SingleProcess bool
DeviceUUID string DeviceUUID string
User string User string
@ -47,6 +48,7 @@ type RuntimeConfig struct {
type ConfigFile struct { type ConfigFile struct {
IdentityUrl string IdentityUrl string
ApiUrl string ApiUrl string
NotificationsUrl string
DeviceUUID string DeviceUUID string
ConfigKeyHash string ConfigKeyHash string
EncryptedToken string EncryptedToken string
@ -75,8 +77,9 @@ func DefaultConfig() Config {
return Config{ return Config{
memguard.NewBuffer(32), memguard.NewBuffer(32),
ConfigFile{ ConfigFile{
IdentityUrl: "https://identity.bitwarden.com/", IdentityUrl: "https://vault.bitwarden.com/identity",
ApiUrl: "https://identity.bitwarden.com/", ApiUrl: "https://vault.bitwarden.com/api",
NotificationsUrl: "https://notifications.bitwarden.com",
DeviceUUID: deviceUUID.String(), DeviceUUID: deviceUUID.String(),
ConfigKeyHash: "", ConfigKeyHash: "",
EncryptedToken: "", EncryptedToken: "",

View File

@ -106,7 +106,8 @@ func StartUnixAgent(path string, runtimeConfig config.RuntimeConfig) error {
var vault = vault.NewVault(&keyring) var vault = vault.NewVault(&keyring)
cfg, err := config.ReadConfig(runtimeConfig) cfg, err := config.ReadConfig(runtimeConfig)
if err != nil { if err != nil {
var cfg = config.DefaultConfig() cfg = config.DefaultConfig()
cfg.ConfigFile.RuntimeConfig = runtimeConfig
cfg.WriteConfig() cfg.WriteConfig()
} }
cfg.ConfigFile.RuntimeConfig = runtimeConfig cfg.ConfigFile.RuntimeConfig = runtimeConfig
@ -116,6 +117,9 @@ func StartUnixAgent(path string, runtimeConfig config.RuntimeConfig) error {
if cfg.ConfigFile.RuntimeConfig.IdentityURI != "" { if cfg.ConfigFile.RuntimeConfig.IdentityURI != "" {
cfg.ConfigFile.IdentityUrl = cfg.ConfigFile.RuntimeConfig.IdentityURI cfg.ConfigFile.IdentityUrl = cfg.ConfigFile.RuntimeConfig.IdentityURI
} }
if cfg.ConfigFile.RuntimeConfig.NotificationsURI != "" {
cfg.ConfigFile.NotificationsUrl = cfg.ConfigFile.RuntimeConfig.NotificationsURI
}
if cfg.ConfigFile.RuntimeConfig.DeviceUUID != "" { if cfg.ConfigFile.RuntimeConfig.DeviceUUID != "" {
cfg.ConfigFile.DeviceUUID = cfg.ConfigFile.RuntimeConfig.DeviceUUID cfg.ConfigFile.DeviceUUID = cfg.ConfigFile.RuntimeConfig.DeviceUUID
} }

View File

@ -89,6 +89,9 @@ func StartVirtualAgent(runtimeConfig config.RuntimeConfig) (chan []byte, chan []
if cfg.ConfigFile.RuntimeConfig.IdentityURI != "" { if cfg.ConfigFile.RuntimeConfig.IdentityURI != "" {
cfg.ConfigFile.IdentityUrl = cfg.ConfigFile.RuntimeConfig.IdentityURI cfg.ConfigFile.IdentityUrl = cfg.ConfigFile.RuntimeConfig.IdentityURI
} }
if cfg.ConfigFile.RuntimeConfig.NotificationsURI != "" {
cfg.ConfigFile.NotificationsUrl = cfg.ConfigFile.RuntimeConfig.NotificationsURI
}
if cfg.ConfigFile.RuntimeConfig.DeviceUUID != "" { if cfg.ConfigFile.RuntimeConfig.DeviceUUID != "" {
cfg.ConfigFile.DeviceUUID = cfg.ConfigFile.RuntimeConfig.DeviceUUID cfg.ConfigFile.DeviceUUID = cfg.ConfigFile.RuntimeConfig.DeviceUUID
} }