Skip to content

Commit

Permalink
Merge pull request #100 from quexten/feature/authenticated-connection
Browse files Browse the repository at this point in the history
Authenticated Session & External Pinentry
  • Loading branch information
quexten authored Feb 9, 2024
2 parents 4a3e8ca + 2e42a79 commit 52156f8
Show file tree
Hide file tree
Showing 55 changed files with 1,137 additions and 483 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ goldwarden
__pycache__
.flatpak-builder
flatpak-pip-generator
repo
repo
__debug*
20 changes: 10 additions & 10 deletions agent/actions/logins.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ func handleGetLoginCipher(request messages.IPCMessage, cfg *config.Config, vault
}

func handleListLoginsRequest(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
if approved, err := pinentry.GetApproval("Access Vault", fmt.Sprintf("%s on %s>%s>%s is trying access ALL CREDENTIALS", ctx.UserName, ctx.GrandParentProcessName, ctx.ParentProcessName, ctx.ProcessName)); err != nil || !approved {
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
Success: false,
Message: "not approved",
})
if err != nil {
return messages.IPCMessage{}, err
}
return response, nil
}
// if approved, err := pinentry.GetApproval("Access Vault", fmt.Sprintf("%s on %s>%s>%s is trying access ALL CREDENTIALS", ctx.UserName, ctx.GrandParentProcessName, ctx.ParentProcessName, ctx.ProcessName)); err != nil || !approved {
// response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
// Success: false,
// Message: "not approved",
// })
// if err != nil {
// return messages.IPCMessage{}, err
// }
// return response, nil
// }

logins := vault.GetLogins()
decryptedLoginCiphers := make([]messages.DecryptedLoginCipher, 0)
Expand Down
3 changes: 1 addition & 2 deletions agent/bitwarden/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
"time"
)
Expand Down Expand Up @@ -114,7 +113,7 @@ func makeAuthenticatedHTTPRequest(ctx context.Context, req *http.Request, recv i
return &errStatusCode{res.StatusCode, body}
}
if err := json.Unmarshal(body, recv); err != nil {
fmt.Fprintln(os.Stderr, string(body))
fmt.Println(string(body))
return err
}
return nil
Expand Down
1 change: 1 addition & 0 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type RuntimeConfig struct {
UseMemguard bool
SSHAgentSocketPath string
GoldwardenSocketPath string
DaemonAuthToken string
}

type ConfigFile struct {
Expand Down
2 changes: 2 additions & 0 deletions agent/sockets/callingcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type CallingContext struct {
ParentProcessPid int
GrandParentProcessPid int
Error bool
Authenticated bool
}

func GetCallingContext(connection net.Conn) CallingContext {
Expand All @@ -30,6 +31,7 @@ func GetCallingContext(connection net.Conn) CallingContext {
ParentProcessPid: 0,
GrandParentProcessPid: 0,
Error: true,
Authenticated: false,
}
if err != nil {
return errorContext
Expand Down
4 changes: 2 additions & 2 deletions agent/systemauth/pinentry/go-pinentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/twpayne/go-pinentry"
)

func GetPassword(title string, description string) (string, error) {
func getPassword(title string, description string) (string, error) {
client, err := pinentry.NewClient(
pinentry.WithBinaryNameFromGnuPGAgentConf(),
pinentry.WithGPGTTY(),
Expand Down Expand Up @@ -38,7 +38,7 @@ func GetPassword(title string, description string) (string, error) {
}
}

func GetApproval(title string, description string) (bool, error) {
func getApproval(title string, description string) (bool, error) {
if systemAuthDisabled {
return true, nil
}
Expand Down
4 changes: 2 additions & 2 deletions agent/systemauth/pinentry/keybase-pinentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
pinentry "github.com/quexten/goldwarden/agent/systemauth/pinentry/keybase-pinentry"
)

func GetPassword(title string, description string) (string, error) {
func getPassword(title string, description string) (string, error) {
pinentryInstance := pinentry.New("", logger.New(""), "")
result, err := pinentryInstance.Get(keybase1.SecretEntryArg{
Prompt: title,
Expand All @@ -28,7 +28,7 @@ func GetPassword(title string, description string) (string, error) {
return result.Text, nil
}

func GetApproval(title string, description string) (bool, error) {
func getApproval(title string, description string) (bool, error) {
pinentryInstance := pinentry.New("", logger.New(""), "")
result, err := pinentryInstance.Get(keybase1.SecretEntryArg{
Prompt: title,
Expand Down
45 changes: 45 additions & 0 deletions agent/systemauth/pinentry/pinentry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pinentry

import (
"errors"
"os"

"github.com/quexten/goldwarden/logging"
Expand All @@ -9,8 +10,52 @@ import (
var log = logging.GetLogger("Goldwarden", "Pinentry")
var systemAuthDisabled = false

type Pinentry struct {
GetPassword func(title string, description string) (string, error)
GetApproval func(title string, description string) (bool, error)
}

var externalPinentry Pinentry = Pinentry{}

func init() {
if os.Getenv("GOLDWARDEN_SYSTEM_AUTH_DISABLED") == "true" {
systemAuthDisabled = true
}
}

func SetExternalPinentry(pinentry Pinentry) error {
if externalPinentry.GetPassword != nil {
return errors.New("External pinentry already set")
}

externalPinentry = pinentry
return nil
}

func GetPassword(title string, description string) (string, error) {
password, err := getPassword(title, description)
if err == nil {
return password, nil
}

if externalPinentry.GetPassword != nil {
return externalPinentry.GetPassword(title, description)
}

// return "", errors.New("Not implemented")
return password, nil
}

func GetApproval(title string, description string) (bool, error) {
approval, err := getApproval(title, description)
if err == nil {
return approval, nil
}

if externalPinentry.GetApproval != nil {
return externalPinentry.GetApproval(title, description)
}

// return true, errors.New("Not implemented")
return approval, nil
}
4 changes: 2 additions & 2 deletions agent/systemauth/pinentry/unimplemented.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ package pinentry

import "errors"

func GetPassword(title string, description string) (string, error) {
func getPassword(title string, description string) (string, error) {
log.Info("Asking for password is not implemented on this platform")
return "", errors.New("Not implemented")
}

func GetApproval(title string, description string) (bool, error) {
func getApproval(title string, description string) (bool, error) {
log.Info("Asking for approval is not implemented on this platform")
return true, errors.New("Not implemented")
}
4 changes: 4 additions & 0 deletions agent/systemauth/systemauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (s *SessionStore) verifySession(ctx sockets.CallingContext, sessionType Ses

// with session
func GetPermission(sessionType SessionType, ctx sockets.CallingContext, config *config.Config) (bool, error) {
if ctx.Authenticated {
return true, nil
}

log.Info("Checking permission for " + ctx.ProcessName + " with session type " + string(sessionType))
var actionDescription = ""
biometricsApprovalType := biometrics.AccessVault
Expand Down
Loading

0 comments on commit 52156f8

Please sign in to comment.