Merge pull request #141 from SuperSandro2000/browser-err
Improve overhaul error handling, Fix more lints found by golangci-lint's default config
This commit is contained in:
commit
6ac5754075
@ -20,6 +20,9 @@ func handleCreateSend(msg messages.IPCMessage, cfg *config.Config, vault *vault.
|
|||||||
|
|
||||||
ctx := context.WithValue(context.TODO(), bitwarden.AuthToken{}, token.AccessToken)
|
ctx := context.WithValue(context.TODO(), bitwarden.AuthToken{}, token.AccessToken)
|
||||||
url, err := bitwarden.CreateSend(ctx, cfg, vault, parsedMsg.Name, parsedMsg.Text)
|
url, err := bitwarden.CreateSend(ctx, cfg, vault, parsedMsg.Name, parsedMsg.Text)
|
||||||
|
if err != nil {
|
||||||
|
actionsLog.Warn(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
response, err = messages.IPCMessageFromPayload(messages.CreateSendResponse{
|
response, err = messages.IPCMessageFromPayload(messages.CreateSendResponse{
|
||||||
URL: url,
|
URL: url,
|
||||||
|
@ -17,7 +17,7 @@ func handleAddSSH(msg messages.IPCMessage, cfg *config.Config, vault *vault.Vaul
|
|||||||
req := messages.ParsePayload(msg).(messages.CreateSSHKeyRequest)
|
req := messages.ParsePayload(msg).(messages.CreateSSHKeyRequest)
|
||||||
|
|
||||||
cipher, publicKey := ssh.NewSSHKeyCipher(req.Name, vault.Keyring)
|
cipher, publicKey := ssh.NewSSHKeyCipher(req.Name, vault.Keyring)
|
||||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
_, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||||
Success: true,
|
Success: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -25,6 +25,9 @@ func handleAddSSH(msg messages.IPCMessage, cfg *config.Config, vault *vault.Vaul
|
|||||||
}
|
}
|
||||||
|
|
||||||
token, err := cfg.GetToken()
|
token, err := cfg.GetToken()
|
||||||
|
if err != nil {
|
||||||
|
actionsLog.Warn(err.Error())
|
||||||
|
}
|
||||||
ctx := context.WithValue(context.TODO(), bitwarden.AuthToken{}, token.AccessToken)
|
ctx := context.WithValue(context.TODO(), bitwarden.AuthToken{}, token.AccessToken)
|
||||||
ciph, err := bitwarden.PostCipher(ctx, cipher, cfg)
|
ciph, err := bitwarden.PostCipher(ctx, cipher, cfg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -162,10 +162,10 @@ func LoginWithMasterpassword(ctx context.Context, email string, cfg *config.Conf
|
|||||||
return LoginResponseToken{}, crypto.MasterKey{}, "", err
|
return LoginResponseToken{}, crypto.MasterKey{}, "", err
|
||||||
}
|
}
|
||||||
} else if err != nil && strings.Contains(err.Error(), "Captcha required.") {
|
} else if err != nil && strings.Contains(err.Error(), "Captcha required.") {
|
||||||
notify.Notify("Goldwarden", fmt.Sprintf("Captcha required"), "", 0, func() {})
|
notify.Notify("Goldwarden", "Captcha required", "", 0, func() {})
|
||||||
return LoginResponseToken{}, crypto.MasterKey{}, "", fmt.Errorf("captcha required, please login via the web interface")
|
return LoginResponseToken{}, crypto.MasterKey{}, "", fmt.Errorf("captcha required, please login via the web interface")
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
notify.Notify("Goldwarden", fmt.Sprintf("Could not login via password: %v", err), "", 0, func() {})
|
notify.Notify("Goldwarden", fmt.Sprintf("Could not login via password: %s", err.Error()), "", 0, func() {})
|
||||||
return LoginResponseToken{}, crypto.MasterKey{}, "", fmt.Errorf("could not login via password: %v", err)
|
return LoginResponseToken{}, crypto.MasterKey{}, "", fmt.Errorf("could not login via password: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@ -105,7 +104,7 @@ func makeAuthenticatedHTTPRequest(ctx context.Context, req *http.Request, recv i
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
body, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -69,11 +69,17 @@ func CreateAuthResponse(ctx context.Context, authRequest AuthRequestData, keyrin
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
publicKey, err := base64.StdEncoding.DecodeString(authRequest.PublicKey)
|
publicKey, err := base64.StdEncoding.DecodeString(authRequest.PublicKey)
|
||||||
|
if err != nil {
|
||||||
|
return AuthRequestResponseData{}, err
|
||||||
|
}
|
||||||
requesterKey, err := crypto.MemoryAssymmetricEncryptionKeyFromBytes(publicKey)
|
requesterKey, err := crypto.MemoryAssymmetricEncryptionKeyFromBytes(publicKey)
|
||||||
|
if err != nil {
|
||||||
|
return AuthRequestResponseData{}, err
|
||||||
|
}
|
||||||
|
|
||||||
encryptedUserSymmetricKey, err := crypto.EncryptWithAsymmetric(userSymmetricKey, requesterKey)
|
encryptedUserSymmetricKey, err := crypto.EncryptWithAsymmetric(userSymmetricKey, requesterKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return AuthRequestResponseData{}, err
|
||||||
}
|
}
|
||||||
//encryptedMasterPasswordHash, err := crypto.EncryptWithAsymmetric(masterPasswordHash, requesterKey)
|
//encryptedMasterPasswordHash, err := crypto.EncryptWithAsymmetric(masterPasswordHash, requesterKey)
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
|
@ -76,6 +76,10 @@ func connectToWebsocket(ctx context.Context, vault *vault.Vault, cfg *config.Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
token, err := cfg.GetToken()
|
token, err := cfg.GetToken()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var websocketURL = "wss://" + url.Host + url.Path + "/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 {
|
||||||
|
@ -99,7 +99,7 @@ func (pe *Pinentry) Get(arg keybase1.SecretEntryArg) (res *keybase1.SecretEntryR
|
|||||||
|
|
||||||
func (pi *pinentryInstance) Close() {
|
func (pi *pinentryInstance) Close() {
|
||||||
pi.stdin.Close()
|
pi.stdin.Close()
|
||||||
pi.cmd.Wait()
|
_ = pi.cmd.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
type pinentryInstance struct {
|
type pinentryInstance struct {
|
||||||
@ -123,7 +123,6 @@ func (pi *pinentryInstance) Set(cmd, val string, errp *error) {
|
|||||||
if string(line) != "OK" {
|
if string(line) != "OK" {
|
||||||
*errp = fmt.Errorf("Response to " + cmd + " was " + string(line))
|
*errp = fmt.Errorf("Response to " + cmd + " was " + string(line))
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pi *pinentryInstance) Init() (err error) {
|
func (pi *pinentryInstance) Init() (err error) {
|
||||||
|
@ -42,50 +42,47 @@ func TypeString(textToType string) {
|
|||||||
var sessionHandle dbus.ObjectPath
|
var sessionHandle dbus.ObjectPath
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
message := <-signals
|
||||||
case message := <-signals:
|
switch state {
|
||||||
if state == 0 {
|
case 0:
|
||||||
log.Info("Selecting Devices")
|
log.Info("Selecting Devices")
|
||||||
result := message.Body[1].(map[string]dbus.Variant)
|
result := message.Body[1].(map[string]dbus.Variant)
|
||||||
resultSessionHandle := result["session_handle"]
|
resultSessionHandle := result["session_handle"]
|
||||||
sessionHandle = dbus.ObjectPath(resultSessionHandle.String()[1 : len(resultSessionHandle.String())-1])
|
sessionHandle = dbus.ObjectPath(resultSessionHandle.String()[1 : len(resultSessionHandle.String())-1])
|
||||||
res := obj.Call("org.freedesktop.portal.RemoteDesktop.SelectDevices", 0, sessionHandle, map[string]dbus.Variant{
|
res := obj.Call("org.freedesktop.portal.RemoteDesktop.SelectDevices", 0, sessionHandle, map[string]dbus.Variant{
|
||||||
"types": dbus.MakeVariant(uint32(1)),
|
"types": dbus.MakeVariant(uint32(1)),
|
||||||
})
|
})
|
||||||
if res.Err != nil {
|
if res.Err != nil {
|
||||||
log.Error("Error selecting devices: %s", res.Err.Error())
|
log.Error("Error selecting devices: %s", res.Err.Error())
|
||||||
}
|
|
||||||
state = 1
|
|
||||||
} else if state == 1 {
|
|
||||||
log.Info("Starting Session")
|
|
||||||
res := obj.Call("org.freedesktop.portal.RemoteDesktop.Start", 0, sessionHandle, "", map[string]dbus.Variant{})
|
|
||||||
if res.Err != nil {
|
|
||||||
log.Error("Error starting session: %s", res.Err.Error())
|
|
||||||
}
|
|
||||||
state = 2
|
|
||||||
} else if state == 2 {
|
|
||||||
log.Info("Performing Typing")
|
|
||||||
state = 3
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
for _, char := range textToType {
|
|
||||||
if char == '\t' {
|
|
||||||
obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeycode", 0, sessionHandle, map[string]dbus.Variant{}, 15, uint32(1))
|
|
||||||
time.Sleep(autoTypeDelay)
|
|
||||||
obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeycode", 0, sessionHandle, map[string]dbus.Variant{}, 15, uint32(0))
|
|
||||||
time.Sleep(autoTypeDelay)
|
|
||||||
} else {
|
|
||||||
obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeysym", 0, sessionHandle, map[string]dbus.Variant{}, int32(char), uint32(1))
|
|
||||||
time.Sleep(autoTypeDelay)
|
|
||||||
obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeysym", 0, sessionHandle, map[string]dbus.Variant{}, int32(char), uint32(0))
|
|
||||||
time.Sleep(autoTypeDelay)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bus.Close()
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
log.Info("State 3")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
state = 1
|
||||||
|
case 1:
|
||||||
|
log.Info("Starting Session")
|
||||||
|
res := obj.Call("org.freedesktop.portal.RemoteDesktop.Start", 0, sessionHandle, "", map[string]dbus.Variant{})
|
||||||
|
if res.Err != nil {
|
||||||
|
log.Error("Error starting session: %s", res.Err.Error())
|
||||||
|
}
|
||||||
|
state = 2
|
||||||
|
case 2:
|
||||||
|
log.Info("Performing Typing")
|
||||||
|
time.Sleep(1000 * time.Millisecond)
|
||||||
|
for _, char := range textToType {
|
||||||
|
if char == '\t' {
|
||||||
|
obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeycode", 0, sessionHandle, map[string]dbus.Variant{}, 15, uint32(1))
|
||||||
|
time.Sleep(autoTypeDelay)
|
||||||
|
obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeycode", 0, sessionHandle, map[string]dbus.Variant{}, 15, uint32(0))
|
||||||
|
time.Sleep(autoTypeDelay)
|
||||||
|
} else {
|
||||||
|
obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeysym", 0, sessionHandle, map[string]dbus.Variant{}, int32(char), uint32(1))
|
||||||
|
time.Sleep(autoTypeDelay)
|
||||||
|
obj.Call("org.freedesktop.portal.RemoteDesktop.NotifyKeyboardKeysym", 0, sessionHandle, map[string]dbus.Variant{}, int32(char), uint32(0))
|
||||||
|
time.Sleep(autoTypeDelay)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bus.Close()
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@ -25,44 +26,50 @@ func setupCommunication() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataToBytes(msg SendMessage) []byte {
|
func dataToBytes(msg SendMessage) ([]byte, error) {
|
||||||
byteMsg, err := json.Marshal(msg)
|
byteMsg, err := json.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panicf("Unable to marshal OutgoingMessage struct to slice of bytes: " + err.Error())
|
return nil, fmt.Errorf("unable to marshal OutgoingMessage struct to slice of bytes: %w", err)
|
||||||
}
|
}
|
||||||
return byteMsg
|
return byteMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeMessageLength(msg []byte) {
|
func writeMessageLength(msg []byte) error {
|
||||||
err := binary.Write(os.Stdout, nativeEndian, uint32(len(msg)))
|
err := binary.Write(os.Stdout, nativeEndian, uint32(len(msg)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panicf("Unable to write message length to Stdout: " + err.Error())
|
return fmt.Errorf("unable to write message length to stdout: %w", err)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readMessageLength(msg []byte) int {
|
func readMessageLength(msg []byte) (int, error) {
|
||||||
var length uint32
|
var length int
|
||||||
buf := bytes.NewBuffer(msg)
|
buf := bytes.NewBuffer(msg)
|
||||||
err := binary.Read(buf, nativeEndian, &length)
|
err := binary.Read(buf, nativeEndian, &length)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panicf("Unable to read bytes representing message length:" + err.Error())
|
return 0, fmt.Errorf("Unable to read bytes representing message length: %w", err)
|
||||||
}
|
}
|
||||||
return int(length)
|
return length, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func send(msg SendMessage) {
|
func send(msg SendMessage) error {
|
||||||
byteMsg := dataToBytes(msg)
|
byteMsg, err := dataToBytes(msg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
logging.Debugf("[SENSITIVE] Sending message: " + string(byteMsg))
|
logging.Debugf("[SENSITIVE] Sending message: " + string(byteMsg))
|
||||||
writeMessageLength(byteMsg)
|
err = writeMessageLength(byteMsg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var msgBuf bytes.Buffer
|
var msgBuf bytes.Buffer
|
||||||
_, err := msgBuf.Write(byteMsg)
|
_, err = msgBuf.Write(byteMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panicf(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = msgBuf.WriteTo(os.Stdout)
|
_, err = msgBuf.WriteTo(os.Stdout)
|
||||||
if err != nil {
|
return err
|
||||||
logging.Panicf(err.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func pkcs7Pad(b []byte, blocksize int) ([]byte, error) {
|
|||||||
if blocksize <= 0 {
|
if blocksize <= 0 {
|
||||||
return nil, ErrInvalidBlockSize
|
return nil, ErrInvalidBlockSize
|
||||||
}
|
}
|
||||||
if b == nil || len(b) == 0 {
|
if len(b) == 0 {
|
||||||
return nil, ErrInvalidPKCS7Data
|
return nil, ErrInvalidPKCS7Data
|
||||||
}
|
}
|
||||||
n := blocksize - (len(b) % blocksize)
|
n := blocksize - (len(b) % blocksize)
|
||||||
@ -37,7 +37,7 @@ func pkcs7Unpad(b []byte, blocksize int) ([]byte, error) {
|
|||||||
if blocksize <= 0 {
|
if blocksize <= 0 {
|
||||||
return nil, ErrInvalidBlockSize
|
return nil, ErrInvalidBlockSize
|
||||||
}
|
}
|
||||||
if b == nil || len(b) == 0 {
|
if len(b) == 0 {
|
||||||
return nil, ErrInvalidPKCS7Data
|
return nil, ErrInvalidPKCS7Data
|
||||||
}
|
}
|
||||||
if len(b)%blocksize != 0 {
|
if len(b)%blocksize != 0 {
|
||||||
@ -56,10 +56,10 @@ func pkcs7Unpad(b []byte, blocksize int) ([]byte, error) {
|
|||||||
return b[:len(b)-n], nil
|
return b[:len(b)-n], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decryptStringSymmetric(key []byte, ivb64 string, data string) string {
|
func decryptStringSymmetric(key []byte, ivb64 string, data string) (string, error) {
|
||||||
block, err := aes.NewCipher(key)
|
block, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return "", err
|
||||||
}
|
}
|
||||||
iv, _ := base64.StdEncoding.DecodeString(ivb64)
|
iv, _ := base64.StdEncoding.DecodeString(ivb64)
|
||||||
ciphertext, _ := base64.StdEncoding.DecodeString(data)
|
ciphertext, _ := base64.StdEncoding.DecodeString(data)
|
||||||
@ -67,19 +67,19 @@ func decryptStringSymmetric(key []byte, ivb64 string, data string) string {
|
|||||||
bm.CryptBlocks(ciphertext, ciphertext)
|
bm.CryptBlocks(ciphertext, ciphertext)
|
||||||
ciphertext, _ = pkcs7Unpad(ciphertext, aes.BlockSize)
|
ciphertext, _ = pkcs7Unpad(ciphertext, aes.BlockSize)
|
||||||
|
|
||||||
return string(ciphertext)
|
return string(ciphertext), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func encryptStringSymmetric(key []byte, data []byte) EncryptedString {
|
func encryptStringSymmetric(key []byte, data []byte) (EncryptedString, error) {
|
||||||
block, err := aes.NewCipher(key)
|
block, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return EncryptedString{}, err
|
||||||
}
|
}
|
||||||
data, _ = pkcs7Pad(data, block.BlockSize())
|
data, _ = pkcs7Pad(data, block.BlockSize())
|
||||||
ciphertext := make([]byte, aes.BlockSize+len(data))
|
ciphertext := make([]byte, aes.BlockSize+len(data))
|
||||||
iv := ciphertext[:aes.BlockSize]
|
iv := ciphertext[:aes.BlockSize]
|
||||||
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
||||||
panic(err)
|
return EncryptedString{}, err
|
||||||
}
|
}
|
||||||
bm := cipher.NewCBCEncrypter(block, iv)
|
bm := cipher.NewCBCEncrypter(block, iv)
|
||||||
bm.CryptBlocks(ciphertext[aes.BlockSize:], data)
|
bm.CryptBlocks(ciphertext[aes.BlockSize:], data)
|
||||||
@ -88,15 +88,15 @@ func encryptStringSymmetric(key []byte, data []byte) EncryptedString {
|
|||||||
IV: base64.StdEncoding.EncodeToString(ciphertext[:aes.BlockSize]),
|
IV: base64.StdEncoding.EncodeToString(ciphertext[:aes.BlockSize]),
|
||||||
Data: base64.StdEncoding.EncodeToString(ciphertext[aes.BlockSize:]),
|
Data: base64.StdEncoding.EncodeToString(ciphertext[aes.BlockSize:]),
|
||||||
EncType: 0,
|
EncType: 0,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTransportKey() []byte {
|
func generateTransportKey() ([]byte, error) {
|
||||||
key := make([]byte, 32)
|
key := make([]byte, 32)
|
||||||
if _, err := io.ReadFull(rand.Reader, key); err != nil {
|
if _, err := io.ReadFull(rand.Reader, key); err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
return key
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func rsaEncrypt(keyB64 string, message []byte) (string, error) {
|
func rsaEncrypt(keyB64 string, message []byte) (string, error) {
|
||||||
|
@ -36,13 +36,17 @@ const appID = "com.quexten.bw-bio-handler"
|
|||||||
|
|
||||||
var transportKey []byte
|
var transportKey []byte
|
||||||
|
|
||||||
func Main(rtCfg *config.RuntimeConfig) {
|
func Main(rtCfg *config.RuntimeConfig) error {
|
||||||
logging.Debugf("Starting browserbiometrics")
|
logging.Debugf("Starting browserbiometrics")
|
||||||
transportKey = generateTransportKey()
|
var err error
|
||||||
|
transportKey, err = generateTransportKey()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
logging.Debugf("Generated transport key")
|
logging.Debugf("Generated transport key")
|
||||||
|
|
||||||
setupCommunication()
|
setupCommunication()
|
||||||
readLoop(rtCfg)
|
return readLoop(rtCfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DetectAndInstallBrowsers() error {
|
func DetectAndInstallBrowsers() error {
|
||||||
|
@ -3,6 +3,7 @@ package browserbiometrics
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ import (
|
|||||||
|
|
||||||
var runtimeConfig *config.RuntimeConfig
|
var runtimeConfig *config.RuntimeConfig
|
||||||
|
|
||||||
func readLoop(rtCfg *config.RuntimeConfig) {
|
func readLoop(rtCfg *config.RuntimeConfig) error {
|
||||||
runtimeConfig = rtCfg
|
runtimeConfig = rtCfg
|
||||||
v := bufio.NewReader(os.Stdin)
|
v := bufio.NewReader(os.Stdin)
|
||||||
s := bufio.NewReaderSize(v, bufferSize)
|
s := bufio.NewReaderSize(v, bufferSize)
|
||||||
@ -23,64 +24,86 @@ func readLoop(rtCfg *config.RuntimeConfig) {
|
|||||||
lengthNum := int(0)
|
lengthNum := int(0)
|
||||||
|
|
||||||
logging.Debugf("Sending connected message")
|
logging.Debugf("Sending connected message")
|
||||||
send(SendMessage{
|
err := send(SendMessage{
|
||||||
Command: "connected",
|
Command: "connected",
|
||||||
AppID: appID,
|
AppID: appID,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
logging.Debugf("Starting read loop")
|
logging.Debugf("Starting read loop")
|
||||||
for b, err := s.Read(lengthBytes); b > 0 && err == nil; b, err = s.Read(lengthBytes) {
|
for b, err := s.Read(lengthBytes); b > 0 && err == nil; b, err = s.Read(lengthBytes) {
|
||||||
lengthNum = readMessageLength(lengthBytes)
|
lengthNum, err = readMessageLength(lengthBytes)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
content := make([]byte, lengthNum)
|
content := make([]byte, lengthNum)
|
||||||
_, err := s.Read(content)
|
_, err := s.Read(content)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
logging.Panicf(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
parseMessage(content)
|
err = parseMessage(content)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseMessage(msg []byte) {
|
func parseMessage(msg []byte) error {
|
||||||
logging.Debugf("Received message: " + string(msg))
|
logging.Debugf("Received message: " + string(msg))
|
||||||
|
|
||||||
var genericMessage GenericRecvMessage
|
var genericMessage GenericRecvMessage
|
||||||
err := json.Unmarshal(msg, &genericMessage)
|
err := json.Unmarshal(msg, &genericMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panicf("Unable to unmarshal json to struct: " + err.Error())
|
return fmt.Errorf("unable to unmarshal json to struct: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := (genericMessage.Message.(map[string]interface{})["command"]); ok {
|
if _, ok := (genericMessage.Message.(map[string]interface{})["command"]); ok {
|
||||||
logging.Debugf("Message is unencrypted")
|
logging.Debugf("Message is unencrypted")
|
||||||
|
|
||||||
var unmsg UnencryptedRecvMessage
|
var unmsg UnencryptedRecvMessage
|
||||||
err := json.Unmarshal(msg, &unmsg)
|
err := json.Unmarshal(msg, &unmsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panicf("Unable to unmarshal json to struct: " + err.Error())
|
return fmt.Errorf("unable to unmarshal json to struct: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleUnencryptedMessage(unmsg)
|
err = handleUnencryptedMessage(unmsg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logging.Debugf("Message is encrypted")
|
logging.Debugf("Message is encrypted")
|
||||||
|
|
||||||
var encmsg EncryptedRecvMessage
|
var encmsg EncryptedRecvMessage
|
||||||
err := json.Unmarshal(msg, &encmsg)
|
err := json.Unmarshal(msg, &encmsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panicf("Unable to unmarshal json to struct: " + err.Error())
|
return fmt.Errorf("unable to unmarshal json to struct: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
decryptedMessage := decryptStringSymmetric(transportKey, encmsg.Message.IV, encmsg.Message.Data)
|
decryptedMessage, err := decryptStringSymmetric(transportKey, encmsg.Message.IV, encmsg.Message.Data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
var payloadMsg PayloadMessage
|
var payloadMsg PayloadMessage
|
||||||
err = json.Unmarshal([]byte(decryptedMessage), &payloadMsg)
|
err = json.Unmarshal([]byte(decryptedMessage), &payloadMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panicf("Unable to unmarshal json to struct: " + err.Error())
|
return fmt.Errorf("unable to unmarshal json to struct: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePayloadMessage(payloadMsg, genericMessage.AppID)
|
err = handlePayloadMessage(payloadMsg, genericMessage.AppID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleUnencryptedMessage(msg UnencryptedRecvMessage) {
|
func handleUnencryptedMessage(msg UnencryptedRecvMessage) error {
|
||||||
logging.Debugf("Received unencrypted message: %+v", msg.Message)
|
logging.Debugf("Received unencrypted message: %+v", msg.Message)
|
||||||
logging.Debugf(" with command: %s", msg.Message.Command)
|
logging.Debugf(" with command: %s", msg.Message.Command)
|
||||||
|
|
||||||
@ -88,17 +111,22 @@ func handleUnencryptedMessage(msg UnencryptedRecvMessage) {
|
|||||||
case "setupEncryption":
|
case "setupEncryption":
|
||||||
sharedSecret, err := rsaEncrypt(msg.Message.PublicKey, transportKey)
|
sharedSecret, err := rsaEncrypt(msg.Message.PublicKey, transportKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panicf(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
send(SendMessage{
|
err = send(SendMessage{
|
||||||
Command: "setupEncryption",
|
Command: "setupEncryption",
|
||||||
AppID: msg.AppID,
|
AppID: msg.AppID,
|
||||||
SharedSecret: sharedSecret,
|
SharedSecret: sharedSecret,
|
||||||
})
|
})
|
||||||
break
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func handlePayloadMessage(msg PayloadMessage, appID string) {
|
|
||||||
|
func handlePayloadMessage(msg PayloadMessage, appID string) error {
|
||||||
logging.Debugf("Received unencrypted message: %+v", msg)
|
logging.Debugf("Received unencrypted message: %+v", msg)
|
||||||
|
|
||||||
switch msg.Command {
|
switch msg.Command {
|
||||||
@ -108,7 +136,7 @@ func handlePayloadMessage(msg PayloadMessage, appID string) {
|
|||||||
|
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtimeConfig.GoldwardenSocketPath == "" {
|
if runtimeConfig.GoldwardenSocketPath == "" {
|
||||||
@ -127,16 +155,12 @@ func handlePayloadMessage(msg PayloadMessage, appID string) {
|
|||||||
|
|
||||||
result, err := client.NewUnixSocketClient(runtimeConfig).SendToAgent(messages.GetBiometricsKeyRequest{})
|
result, err := client.NewUnixSocketClient(runtimeConfig).SendToAgent(messages.GetBiometricsKeyRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Errorf("Unable to send message to agent: %s", err.Error())
|
return fmt.Errorf("Unable to send message to agent: %w", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
switch result.(type) {
|
|
||||||
case messages.GetBiometricsKeyResponse:
|
|
||||||
if err != nil {
|
|
||||||
logging.Panicf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
var key = result.(messages.GetBiometricsKeyResponse).Key
|
switch result := result.(type) {
|
||||||
|
case messages.GetBiometricsKeyResponse:
|
||||||
|
var key = result.Key
|
||||||
var payloadMsg ReceiveMessage = ReceiveMessage{
|
var payloadMsg ReceiveMessage = ReceiveMessage{
|
||||||
Command: "biometricUnlock",
|
Command: "biometricUnlock",
|
||||||
Response: "unlocked",
|
Response: "unlocked",
|
||||||
@ -145,18 +169,23 @@ func handlePayloadMessage(msg PayloadMessage, appID string) {
|
|||||||
}
|
}
|
||||||
payloadStr, err := json.Marshal(payloadMsg)
|
payloadStr, err := json.Marshal(payloadMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Panicf(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
logging.Debugf("Payload: %s", payloadStr)
|
logging.Debugf("Payload: %s", payloadStr)
|
||||||
|
|
||||||
encStr := encryptStringSymmetric(transportKey, payloadStr)
|
encStr, err := encryptStringSymmetric(transportKey, payloadStr)
|
||||||
send(SendMessage{
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = send(SendMessage{
|
||||||
AppID: appID,
|
AppID: appID,
|
||||||
Message: encStr,
|
Message: encStr,
|
||||||
})
|
})
|
||||||
break
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,6 @@ var loginCmd = &cobra.Command{
|
|||||||
func init() {
|
func init() {
|
||||||
vaultCmd.AddCommand(loginCmd)
|
vaultCmd.AddCommand(loginCmd)
|
||||||
loginCmd.PersistentFlags().String("email", "", "")
|
loginCmd.PersistentFlags().String("email", "", "")
|
||||||
loginCmd.MarkFlagRequired("email")
|
_ = loginCmd.MarkFlagRequired("email")
|
||||||
loginCmd.PersistentFlags().Bool("passwordless", false, "")
|
loginCmd.PersistentFlags().Bool("passwordless", false, "")
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/icza/gox/stringsx"
|
"github.com/icza/gox/stringsx"
|
||||||
@ -17,7 +18,7 @@ var baseLoginCmd = &cobra.Command{
|
|||||||
Short: "Commands for managing logins.",
|
Short: "Commands for managing logins.",
|
||||||
Long: `Commands for managing logins.`,
|
Long: `Commands for managing logins.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmd.Help()
|
_ = cmd.Help()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +27,11 @@ var getLoginCmd = &cobra.Command{
|
|||||||
Short: "Gets a login in your vault",
|
Short: "Gets a login in your vault",
|
||||||
Long: `Gets a login in your vault.`,
|
Long: `Gets a login in your vault.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
loginIfRequired()
|
err := loginIfRequired()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
uuid, _ := cmd.Flags().GetString("uuid")
|
uuid, _ := cmd.Flags().GetString("uuid")
|
||||||
name, _ := cmd.Flags().GetString("name")
|
name, _ := cmd.Flags().GetString("name")
|
||||||
@ -51,7 +56,7 @@ var getLoginCmd = &cobra.Command{
|
|||||||
} else {
|
} else {
|
||||||
fmt.Println(response.Result.Password)
|
fmt.Println(response.Result.Password)
|
||||||
}
|
}
|
||||||
break
|
return
|
||||||
case messages.ActionResponse:
|
case messages.ActionResponse:
|
||||||
fmt.Println("Error: " + resp.(messages.ActionResponse).Message)
|
fmt.Println("Error: " + resp.(messages.ActionResponse).Message)
|
||||||
return
|
return
|
||||||
@ -64,7 +69,11 @@ var listLoginsCmd = &cobra.Command{
|
|||||||
Short: "Lists all logins in your vault",
|
Short: "Lists all logins in your vault",
|
||||||
Long: `Lists all logins in your vault.`,
|
Long: `Lists all logins in your vault.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
loginIfRequired()
|
err := loginIfRequired()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
logins, err := ListLogins(commandClient)
|
logins, err := ListLogins(commandClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -54,7 +54,7 @@ var runCmd = &cobra.Command{
|
|||||||
command.Stdout = os.Stdout
|
command.Stdout = os.Stdout
|
||||||
command.Stderr = os.Stderr
|
command.Stderr = os.Stderr
|
||||||
command.Stdin = os.Stdin
|
command.Stdin = os.Stdin
|
||||||
command.Run()
|
_ = command.Run()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
cmd/send.go
12
cmd/send.go
@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/quexten/goldwarden/ipc/messages"
|
"github.com/quexten/goldwarden/ipc/messages"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -12,7 +13,7 @@ var sendCmd = &cobra.Command{
|
|||||||
Short: "Commands for managing sends",
|
Short: "Commands for managing sends",
|
||||||
Long: `Commands for managing sends.`,
|
Long: `Commands for managing sends.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmd.Help()
|
_ = cmd.Help()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +22,12 @@ var sendCreateCmd = &cobra.Command{
|
|||||||
Short: "Uploads a Bitwarden send.",
|
Short: "Uploads a Bitwarden send.",
|
||||||
Long: `Uploads a Bitwarden send.`,
|
Long: `Uploads a Bitwarden send.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
loginIfRequired()
|
err := loginIfRequired()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
name, _ := cmd.Flags().GetString("name")
|
name, _ := cmd.Flags().GetString("name")
|
||||||
text, _ := cmd.Flags().GetString("text")
|
text, _ := cmd.Flags().GetString("text")
|
||||||
|
|
||||||
@ -37,7 +43,7 @@ var sendCreateCmd = &cobra.Command{
|
|||||||
switch result.(type) {
|
switch result.(type) {
|
||||||
case messages.CreateSendResponse:
|
case messages.CreateSendResponse:
|
||||||
fmt.Println("Send created: " + result.(messages.CreateSendResponse).URL)
|
fmt.Println("Send created: " + result.(messages.CreateSendResponse).URL)
|
||||||
break
|
return
|
||||||
case messages.ActionResponse:
|
case messages.ActionResponse:
|
||||||
fmt.Println("Error: " + result.(messages.ActionResponse).Message)
|
fmt.Println("Error: " + result.(messages.ActionResponse).Message)
|
||||||
return
|
return
|
||||||
|
@ -23,7 +23,7 @@ var sessionCmd = &cobra.Command{
|
|||||||
text = strings.TrimSuffix(text, "\n")
|
text = strings.TrimSuffix(text, "\n")
|
||||||
args := strings.Split(text, " ")
|
args := strings.Split(text, " ")
|
||||||
rootCmd.SetArgs(args)
|
rootCmd.SetArgs(args)
|
||||||
rootCmd.Execute()
|
_ = rootCmd.Execute()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -64,6 +64,9 @@ var pinentry = &cobra.Command{
|
|||||||
case messages.PinentryApprovalRequest:
|
case messages.PinentryApprovalRequest:
|
||||||
err = conn.WriteMessage(messages.PinentryApprovalResponse{Approved: text == "true"})
|
err = conn.WriteMessage(messages.PinentryApprovalResponse{Approved: text == "true"})
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,10 @@ func setupSystemd() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
file.WriteString(strings.ReplaceAll(systemdService, "@BINARY_PATH@", path))
|
_, err = file.WriteString(strings.ReplaceAll(systemdService, "@BINARY_PATH@", path))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
file.Close()
|
file.Close()
|
||||||
|
|
||||||
userDirectory := os.Getenv("HOME")
|
userDirectory := os.Getenv("HOME")
|
||||||
@ -172,7 +175,7 @@ var setupCmd = &cobra.Command{
|
|||||||
Short: "Sets up Goldwarden integrations",
|
Short: "Sets up Goldwarden integrations",
|
||||||
Long: "Sets up Goldwarden integrations",
|
Long: "Sets up Goldwarden integrations",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmd.Help()
|
_ = cmd.Help()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
cmd/ssh.go
26
cmd/ssh.go
@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
"github.com/quexten/goldwarden/ipc/messages"
|
"github.com/quexten/goldwarden/ipc/messages"
|
||||||
@ -13,7 +14,7 @@ var sshCmd = &cobra.Command{
|
|||||||
Short: "Commands for managing SSH keys",
|
Short: "Commands for managing SSH keys",
|
||||||
Long: `Commands for managing SSH keys.`,
|
Long: `Commands for managing SSH keys.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmd.Help()
|
_ = cmd.Help()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +25,11 @@ var sshAddCmd = &cobra.Command{
|
|||||||
Long: `Runs a command with environment variables from your vault.
|
Long: `Runs a command with environment variables from your vault.
|
||||||
The variables are stored as a secure note. Consult the documentation for more information.`,
|
The variables are stored as a secure note. Consult the documentation for more information.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
loginIfRequired()
|
err := loginIfRequired()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
name, _ := cmd.Flags().GetString("name")
|
name, _ := cmd.Flags().GetString("name")
|
||||||
copyToClipboard, _ := cmd.Flags().GetBool("clipboard")
|
copyToClipboard, _ := cmd.Flags().GetBool("clipboard")
|
||||||
@ -43,9 +48,12 @@ var sshAddCmd = &cobra.Command{
|
|||||||
fmt.Println(response.Digest)
|
fmt.Println(response.Digest)
|
||||||
|
|
||||||
if copyToClipboard {
|
if copyToClipboard {
|
||||||
clipboard.WriteAll(string(response.Digest))
|
err := clipboard.WriteAll(string(response.Digest))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break
|
return
|
||||||
case messages.ActionResponse:
|
case messages.ActionResponse:
|
||||||
fmt.Println("Error: " + result.(messages.ActionResponse).Message)
|
fmt.Println("Error: " + result.(messages.ActionResponse).Message)
|
||||||
return
|
return
|
||||||
@ -58,7 +66,11 @@ var listSSHCmd = &cobra.Command{
|
|||||||
Short: "Lists all SSH keys in your vault",
|
Short: "Lists all SSH keys in your vault",
|
||||||
Long: `Lists all SSH keys in your vault.`,
|
Long: `Lists all SSH keys in your vault.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
loginIfRequired()
|
err := loginIfRequired()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
result, err := commandClient.SendToAgent(messages.GetSSHKeysRequest{})
|
result, err := commandClient.SendToAgent(messages.GetSSHKeysRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -72,7 +84,7 @@ var listSSHCmd = &cobra.Command{
|
|||||||
for _, key := range response.Keys {
|
for _, key := range response.Keys {
|
||||||
fmt.Println(key)
|
fmt.Println(key)
|
||||||
}
|
}
|
||||||
break
|
return
|
||||||
case messages.ActionResponse:
|
case messages.ActionResponse:
|
||||||
fmt.Println("Error: " + result.(messages.ActionResponse).Message)
|
fmt.Println("Error: " + result.(messages.ActionResponse).Message)
|
||||||
return
|
return
|
||||||
@ -84,7 +96,7 @@ func init() {
|
|||||||
rootCmd.AddCommand(sshCmd)
|
rootCmd.AddCommand(sshCmd)
|
||||||
sshCmd.AddCommand(sshAddCmd)
|
sshCmd.AddCommand(sshAddCmd)
|
||||||
sshAddCmd.PersistentFlags().String("name", "", "")
|
sshAddCmd.PersistentFlags().String("name", "", "")
|
||||||
sshAddCmd.MarkFlagRequired("name")
|
_ = sshAddCmd.MarkFlagRequired("name")
|
||||||
sshAddCmd.PersistentFlags().Bool("clipboard", false, "Copy the public key to the clipboard")
|
sshAddCmd.PersistentFlags().Bool("clipboard", false, "Copy the public key to the clipboard")
|
||||||
sshCmd.AddCommand(listSSHCmd)
|
sshCmd.AddCommand(listSSHCmd)
|
||||||
}
|
}
|
||||||
|
6
main.go
6
main.go
@ -45,8 +45,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(os.Args) > 1 && (strings.Contains(os.Args[1], "com.8bit.bitwarden.json") || strings.Contains(os.Args[1], "chrome-extension://")) {
|
if len(os.Args) > 1 && (strings.Contains(os.Args[1], "com.8bit.bitwarden.json") || strings.Contains(os.Args[1], "chrome-extension://")) {
|
||||||
browserbiometrics.Main(&runtimeConfig)
|
err = browserbiometrics.Main(&runtimeConfig)
|
||||||
return
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Execute(runtimeConfig)
|
cmd.Execute(runtimeConfig)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user