Refactor ipc
This commit is contained in:
parent
b547efaa45
commit
21b1f0b219
|
@ -9,35 +9,35 @@ import (
|
|||
"github.com/quexten/goldwarden/agent/sockets"
|
||||
"github.com/quexten/goldwarden/agent/systemauth"
|
||||
"github.com/quexten/goldwarden/agent/vault"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
var AgentActionsRegistry = newActionsRegistry()
|
||||
|
||||
type Action func(ipc.IPCMessage, *config.Config, *vault.Vault, *sockets.CallingContext) (ipc.IPCMessage, error)
|
||||
type Action func(messages.IPCMessage, *config.Config, *vault.Vault, *sockets.CallingContext) (messages.IPCMessage, error)
|
||||
type ActionsRegistry struct {
|
||||
actions map[ipc.IPCMessageType]Action
|
||||
actions map[messages.IPCMessageType]Action
|
||||
}
|
||||
|
||||
func newActionsRegistry() *ActionsRegistry {
|
||||
return &ActionsRegistry{
|
||||
actions: make(map[ipc.IPCMessageType]Action),
|
||||
actions: make(map[messages.IPCMessageType]Action),
|
||||
}
|
||||
}
|
||||
|
||||
func (registry *ActionsRegistry) Register(messageType ipc.IPCMessageType, action Action) {
|
||||
func (registry *ActionsRegistry) Register(messageType messages.IPCMessageType, action Action) {
|
||||
registry.actions[messageType] = action
|
||||
}
|
||||
|
||||
func (registry *ActionsRegistry) Get(messageType ipc.IPCMessageType) (Action, bool) {
|
||||
func (registry *ActionsRegistry) Get(messageType messages.IPCMessageType) (Action, bool) {
|
||||
action, ok := registry.actions[messageType]
|
||||
return action, ok
|
||||
}
|
||||
|
||||
func ensureIsLoggedIn(action Action) Action {
|
||||
return func(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (ipc.IPCMessage, error) {
|
||||
return func(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (messages.IPCMessage, error) {
|
||||
if hash, err := cfg.GetMasterPasswordHash(); err != nil || len(hash) == 0 {
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "Not logged in",
|
||||
})
|
||||
|
@ -68,13 +68,13 @@ func sync(ctx context.Context, vault *vault.Vault, cfg *config.Config) bool {
|
|||
}
|
||||
|
||||
func ensureIsNotLocked(action Action) Action {
|
||||
return func(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (ipc.IPCMessage, error) {
|
||||
return func(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (messages.IPCMessage, error) {
|
||||
if cfg.IsLocked() {
|
||||
err := cfg.TryUnlock(vault)
|
||||
ctx1 := context.Background()
|
||||
success := sync(ctx1, vault, cfg)
|
||||
if err != nil || !success {
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
|
@ -88,9 +88,9 @@ func ensureIsNotLocked(action Action) Action {
|
|||
}
|
||||
|
||||
func ensureBiometricsAuthorized(approvalType systemauth.SessionType, action Action) Action {
|
||||
return func(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (ipc.IPCMessage, error) {
|
||||
return func(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (messages.IPCMessage, error) {
|
||||
if permission, err := systemauth.GetPermission(approvalType, *ctx, cfg); err != nil || !permission {
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "Polkit authorization failed required",
|
||||
})
|
||||
|
|
|
@ -10,43 +10,44 @@ import (
|
|||
"github.com/quexten/goldwarden/agent/systemauth/biometrics"
|
||||
"github.com/quexten/goldwarden/agent/systemauth/pinentry"
|
||||
"github.com/quexten/goldwarden/agent/vault"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
func handleGetBiometricsKey(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
func handleGetBiometricsKey(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
if !(systemauth.VerifyPinSession(*ctx) || biometrics.CheckBiometrics(biometrics.BrowserBiometrics)) {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "not approved",
|
||||
})
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
if approved, err := pinentry.GetApproval("Approve Credential Access", fmt.Sprintf("%s on %s>%s>%s is trying to access your vault encryption key for browser biometric unlock.", ctx.UserName, ctx.GrandParentProcessName, ctx.ParentProcessName, ctx.ProcessName)); err != nil || !approved {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "not approved",
|
||||
})
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
masterKey, err := cfg.GetMasterKey()
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
masterKeyB64 := base64.StdEncoding.EncodeToString(masterKey)
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.GetBiometricsKeyResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.GetBiometricsKeyResponse{
|
||||
Key: masterKeyB64,
|
||||
})
|
||||
return response, err
|
||||
}
|
||||
|
||||
func init() {
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeGetBiometricsKeyRequest, ensureIsNotLocked(ensureIsLoggedIn(handleGetBiometricsKey)))
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.GetBiometricsKeyRequest{}), ensureIsNotLocked(ensureIsLoggedIn(handleGetBiometricsKey)))
|
||||
}
|
||||
|
|
|
@ -4,59 +4,59 @@ import (
|
|||
"github.com/quexten/goldwarden/agent/config"
|
||||
"github.com/quexten/goldwarden/agent/sockets"
|
||||
"github.com/quexten/goldwarden/agent/vault"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
func handleSetApiURL(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
apiURL := request.ParsedPayload().(ipc.SetApiURLRequest).Value
|
||||
func handleSetApiURL(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
apiURL := messages.ParsePayload(request).(messages.SetApiURLRequest).Value
|
||||
cfg.ConfigFile.ApiUrl = apiURL
|
||||
err = cfg.WriteConfig()
|
||||
if err != nil {
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
})
|
||||
}
|
||||
|
||||
func handleSetIdentity(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
identity := request.ParsedPayload().(ipc.SetIdentityURLRequest).Value
|
||||
func handleSetIdentity(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
identity := messages.ParsePayload(request).(messages.SetIdentityURLRequest).Value
|
||||
cfg.ConfigFile.IdentityUrl = identity
|
||||
err = cfg.WriteConfig()
|
||||
if err != nil {
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
})
|
||||
}
|
||||
|
||||
func handleSetNotifications(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
notifications := request.ParsedPayload().(ipc.SetNotificationsURLRequest).Value
|
||||
func handleSetNotifications(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
notifications := messages.ParsePayload(request).(messages.SetNotificationsURLRequest).Value
|
||||
cfg.ConfigFile.NotificationsUrl = notifications
|
||||
err = cfg.WriteConfig()
|
||||
if err != nil {
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
})
|
||||
}
|
||||
|
||||
func init() {
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetIdentityURLRequest, handleSetIdentity)
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetAPIUrlRequest, handleSetApiURL)
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetNotificationsURLRequest, handleSetNotifications)
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetIdentityURLRequest{}), handleSetIdentity)
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetApiURLRequest{}), handleSetApiURL)
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetNotificationsURLRequest{}), handleSetNotifications)
|
||||
}
|
||||
|
|
|
@ -8,36 +8,36 @@ import (
|
|||
"github.com/quexten/goldwarden/agent/systemauth"
|
||||
"github.com/quexten/goldwarden/agent/systemauth/pinentry"
|
||||
"github.com/quexten/goldwarden/agent/vault"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
func handleGetCliCredentials(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
req := request.ParsedPayload().(ipc.GetCLICredentialsRequest)
|
||||
func handleGetCliCredentials(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
req := messages.ParsePayload(request).(messages.GetCLICredentialsRequest)
|
||||
|
||||
if approved, err := pinentry.GetApproval("Approve Credential Access", fmt.Sprintf("%s on %s>%s>%s is trying to access credentials for %s", ctx.UserName, ctx.GrandParentProcessName, ctx.ParentProcessName, ctx.ProcessName, req.ApplicationName)); err != nil || !approved {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "not approved",
|
||||
})
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
env, found := vault.GetEnvCredentialForExecutable(req.ApplicationName)
|
||||
if !found {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "no credentials found for " + req.ApplicationName,
|
||||
})
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.GetCLICredentialsResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.GetCLICredentialsResponse{
|
||||
Env: env,
|
||||
})
|
||||
|
||||
|
@ -45,5 +45,5 @@ func handleGetCliCredentials(request ipc.IPCMessage, cfg *config.Config, vault *
|
|||
}
|
||||
|
||||
func init() {
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeGetCLICredentialsRequest, ensureEverything(systemauth.AccessVault, handleGetCliCredentials))
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.GetCLICredentialsRequest{}), ensureEverything(systemauth.AccessVault, handleGetCliCredentials))
|
||||
}
|
||||
|
|
|
@ -9,23 +9,23 @@ import (
|
|||
"github.com/quexten/goldwarden/agent/config"
|
||||
"github.com/quexten/goldwarden/agent/sockets"
|
||||
"github.com/quexten/goldwarden/agent/vault"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
func handleLogin(msg ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
func handleLogin(msg messages.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
if !cfg.HasPin() && !cfg.ConfigFile.RuntimeConfig.DisablePinRequirement {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "No pin set. Set a pin first!",
|
||||
})
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
req := msg.ParsedPayload().(ipc.DoLoginRequest)
|
||||
req := messages.ParsePayload(msg).(messages.DoLoginRequest)
|
||||
|
||||
ctx := context.Background()
|
||||
var token bitwarden.LoginResponseToken
|
||||
|
@ -38,13 +38,13 @@ func handleLogin(msg ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, cal
|
|||
token, masterKey, masterpasswordHash, err = bitwarden.LoginWithMasterpassword(ctx, req.Email, cfg, vault)
|
||||
}
|
||||
if err != nil {
|
||||
var payload = ipc.ActionResponse{
|
||||
var payload = messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: fmt.Sprintf("Could not login: %s", err.Error()),
|
||||
}
|
||||
response, err = ipc.IPCMessageFromPayload(payload)
|
||||
response, err = messages.IPCMessageFromPayload(payload)
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -59,13 +59,13 @@ func handleLogin(msg ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, cal
|
|||
|
||||
profile, err := bitwarden.Sync(context.WithValue(ctx, bitwarden.AuthToken{}, token.AccessToken), cfg)
|
||||
if err != nil {
|
||||
var payload = ipc.ActionResponse{
|
||||
var payload = messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: fmt.Sprintf("Could not sync vault: %s", err.Error()),
|
||||
}
|
||||
response, err = ipc.IPCMessageFromPayload(payload)
|
||||
response, err = messages.IPCMessageFromPayload(payload)
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -78,13 +78,13 @@ func handleLogin(msg ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, cal
|
|||
|
||||
err = crypto.InitKeyringFromMasterKey(vault.Keyring, profile.Profile.Key, profile.Profile.PrivateKey, orgKeys, masterKey)
|
||||
if err != nil {
|
||||
var payload = ipc.ActionResponse{
|
||||
var payload = messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: fmt.Sprintf("Could not sync vault: %s", err.Error()),
|
||||
}
|
||||
response, err = ipc.IPCMessageFromPayload(payload)
|
||||
response, err = messages.IPCMessageFromPayload(payload)
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -94,19 +94,19 @@ func handleLogin(msg ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, cal
|
|||
cfg.SetMasterKey([]byte(masterKey.GetBytes()))
|
||||
protectedUserSymetricKey, err := crypto.SymmetricEncryptionKeyFromBytes(vault.Keyring.AccountKey.Bytes())
|
||||
if err != nil {
|
||||
var payload = ipc.ActionResponse{
|
||||
var payload = messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: fmt.Sprintf("Could not sync vault: %s", err.Error()),
|
||||
}
|
||||
response, err = ipc.IPCMessageFromPayload(payload)
|
||||
response, err = messages.IPCMessageFromPayload(payload)
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
return
|
||||
}
|
||||
err = bitwarden.DoFullSync(context.WithValue(ctx, bitwarden.AuthToken{}, token.AccessToken), vault, cfg, &protectedUserSymetricKey, false)
|
||||
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -117,5 +117,5 @@ func handleLogin(msg ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, cal
|
|||
}
|
||||
|
||||
func init() {
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeDoLoginRequest, ensureIsNotLocked(handleLogin))
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.DoLoginRequest{}), ensureIsNotLocked(handleLogin))
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@ import (
|
|||
"github.com/quexten/goldwarden/agent/systemauth"
|
||||
"github.com/quexten/goldwarden/agent/systemauth/pinentry"
|
||||
"github.com/quexten/goldwarden/agent/vault"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
func handleGetLoginCipher(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
req := request.ParsedPayload().(ipc.GetLoginRequest)
|
||||
func handleGetLoginCipher(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
req := messages.ParsePayload(request).(messages.GetLoginRequest)
|
||||
login, err := vault.GetLoginByFilter(req.UUID, req.OrgId, req.Name, req.Username)
|
||||
if err != nil {
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "login not found",
|
||||
})
|
||||
|
@ -28,13 +28,13 @@ func handleGetLoginCipher(request ipc.IPCMessage, cfg *config.Config, vault *vau
|
|||
|
||||
cipherKey, err := login.GetKeyForCipher(*vault.Keyring)
|
||||
if err != nil {
|
||||
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "could not get cipher key",
|
||||
})
|
||||
}
|
||||
|
||||
decryptedLogin := ipc.DecryptedLoginCipher{
|
||||
decryptedLogin := messages.DecryptedLoginCipher{
|
||||
Name: "NO NAME FOUND",
|
||||
}
|
||||
decryptedLogin.UUID = login.ID.String()
|
||||
|
@ -84,36 +84,36 @@ func handleGetLoginCipher(request ipc.IPCMessage, cfg *config.Config, vault *vau
|
|||
}
|
||||
|
||||
if approved, err := pinentry.GetApproval("Approve Credential Access", fmt.Sprintf("%s on %s>%s>%s is trying to access credentials for user %s on entry %s", ctx.UserName, ctx.GrandParentProcessName, ctx.ParentProcessName, ctx.ProcessName, decryptedLogin.Username, decryptedLogin.Name)); err != nil || !approved {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "not approved",
|
||||
})
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
return ipc.IPCMessageFromPayload(ipc.GetLoginResponse{
|
||||
return messages.IPCMessageFromPayload(messages.GetLoginResponse{
|
||||
Found: true,
|
||||
Result: decryptedLogin,
|
||||
})
|
||||
}
|
||||
|
||||
func handleListLoginsRequest(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
func handleListLoginsRequest(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
if approved, err := pinentry.GetApproval("Approve List Credentials", fmt.Sprintf("%s on %s>%s>%s is trying to list credentials (name & username)", ctx.UserName, ctx.GrandParentProcessName, ctx.ParentProcessName, ctx.ProcessName)); err != nil || !approved {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "not approved",
|
||||
})
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
logins := vault.GetLogins()
|
||||
decryptedLoginCiphers := make([]ipc.DecryptedLoginCipher, 0)
|
||||
decryptedLoginCiphers := make([]messages.DecryptedLoginCipher, 0)
|
||||
for _, login := range logins {
|
||||
key, err := login.GetKeyForCipher(*vault.Keyring)
|
||||
if err != nil {
|
||||
|
@ -140,7 +140,7 @@ func handleListLoginsRequest(request ipc.IPCMessage, cfg *config.Config, vault *
|
|||
}
|
||||
}
|
||||
|
||||
decryptedLoginCiphers = append(decryptedLoginCiphers, ipc.DecryptedLoginCipher{
|
||||
decryptedLoginCiphers = append(decryptedLoginCiphers, messages.DecryptedLoginCipher{
|
||||
Name: string(decryptedName),
|
||||
Username: string(decryptedUsername),
|
||||
UUID: login.ID.String(),
|
||||
|
@ -150,13 +150,13 @@ func handleListLoginsRequest(request ipc.IPCMessage, cfg *config.Config, vault *
|
|||
debug.FreeOSMemory()
|
||||
}
|
||||
|
||||
return ipc.IPCMessageFromPayload(ipc.GetLoginsResponse{
|
||||
return messages.IPCMessageFromPayload(messages.GetLoginsResponse{
|
||||
Found: len(decryptedLoginCiphers) > 0,
|
||||
Result: decryptedLoginCiphers,
|
||||
})
|
||||
}
|
||||
|
||||
func init() {
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageGetLoginRequest, ensureEverything(systemauth.AccessVault, handleGetLoginCipher))
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageListLoginsRequest, ensureEverything(systemauth.AccessVault, handleListLoginsRequest))
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.GetLoginRequest{}), ensureEverything(systemauth.AccessVault, handleGetLoginCipher))
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.ListLoginsRequest{}), ensureEverything(systemauth.AccessVault, handleListLoginsRequest))
|
||||
}
|
||||
|
|
|
@ -10,17 +10,17 @@ import (
|
|||
"github.com/quexten/goldwarden/agent/ssh"
|
||||
"github.com/quexten/goldwarden/agent/systemauth"
|
||||
"github.com/quexten/goldwarden/agent/vault"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
"github.com/quexten/goldwarden/logging"
|
||||
)
|
||||
|
||||
var actionsLog = logging.GetLogger("Goldwarden", "Actions")
|
||||
|
||||
func handleAddSSH(msg ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
req := msg.ParsedPayload().(ipc.CreateSSHKeyRequest)
|
||||
func handleAddSSH(msg messages.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
req := messages.ParsePayload(msg).(messages.CreateSSHKeyRequest)
|
||||
|
||||
cipher, publicKey := ssh.NewSSHKeyCipher(req.Name, vault.Keyring)
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -36,27 +36,27 @@ func handleAddSSH(msg ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ca
|
|||
actionsLog.Warn("Error posting ssh key cipher: " + err.Error())
|
||||
}
|
||||
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.CreateSSHKeyResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.CreateSSHKeyResponse{
|
||||
Digest: strings.ReplaceAll(publicKey, "\n", "") + " " + req.Name,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func handleListSSH(msg ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
func handleListSSH(msg messages.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
keys := vault.GetSSHKeys()
|
||||
keyStrings := make([]string, 0)
|
||||
for _, key := range keys {
|
||||
keyStrings = append(keyStrings, strings.ReplaceAll(key.PublicKey+" "+key.Name, "\n", ""))
|
||||
}
|
||||
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.GetSSHKeysResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.GetSSHKeysResponse{
|
||||
Keys: keyStrings,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeCreateSSHKeyRequest, ensureEverything(systemauth.SSHKey, handleAddSSH))
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeGetSSHKeysRequest, ensureIsNotLocked(ensureIsLoggedIn(handleListSSH)))
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.CreateSSHKeyRequest{}), ensureEverything(systemauth.SSHKey, handleAddSSH))
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.GetSSHKeysRequest{}), ensureIsNotLocked(ensureIsLoggedIn(handleListSSH)))
|
||||
}
|
||||
|
|
|
@ -11,12 +11,13 @@ import (
|
|||
"github.com/quexten/goldwarden/agent/systemauth"
|
||||
"github.com/quexten/goldwarden/agent/systemauth/pinentry"
|
||||
"github.com/quexten/goldwarden/agent/vault"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
func handleUnlockVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
func handleUnlockVault(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
if !cfg.HasPin() {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "No pin set",
|
||||
})
|
||||
|
@ -28,7 +29,7 @@ func handleUnlockVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.
|
|||
}
|
||||
|
||||
if !cfg.IsLocked() {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
Message: "Unlocked",
|
||||
})
|
||||
|
@ -41,7 +42,7 @@ func handleUnlockVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.
|
|||
|
||||
err = cfg.TryUnlock(vault)
|
||||
if err != nil {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "wrong pin: " + err.Error(),
|
||||
})
|
||||
|
@ -75,7 +76,7 @@ func handleUnlockVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.
|
|||
}
|
||||
}
|
||||
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -85,9 +86,9 @@ func handleUnlockVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.
|
|||
return
|
||||
}
|
||||
|
||||
func handleLockVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
func handleLockVault(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
if !cfg.HasPin() {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "No pin set",
|
||||
})
|
||||
|
@ -99,7 +100,7 @@ func handleLockVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.Va
|
|||
}
|
||||
|
||||
if cfg.IsLocked() {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
Message: "Locked",
|
||||
})
|
||||
|
@ -114,7 +115,7 @@ func handleLockVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.Va
|
|||
vault.Clear()
|
||||
vault.Keyring.Lock()
|
||||
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -124,12 +125,12 @@ func handleLockVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.Va
|
|||
return
|
||||
}
|
||||
|
||||
func handleWipeVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
func handleWipeVault(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
cfg.Purge()
|
||||
cfg.WriteConfig()
|
||||
vault.Clear()
|
||||
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -139,29 +140,29 @@ func handleWipeVault(request ipc.IPCMessage, cfg *config.Config, vault *vault.Va
|
|||
return
|
||||
}
|
||||
|
||||
func handleUpdateVaultPin(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
func handleUpdateVaultPin(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
pin, err := pinentry.GetPassword("Pin Change", "Enter your desired pin")
|
||||
if err != nil {
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: err.Error(),
|
||||
})
|
||||
if err != nil {
|
||||
return ipc.IPCMessage{}, err
|
||||
return messages.IPCMessage{}, err
|
||||
} else {
|
||||
return response, nil
|
||||
}
|
||||
}
|
||||
cfg.UpdatePin(pin, true)
|
||||
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func handlePinStatus(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
||||
func handlePinStatus(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, callingContext *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
||||
var pinStatus string
|
||||
if cfg.HasPin() {
|
||||
pinStatus = "enabled"
|
||||
|
@ -169,7 +170,7 @@ func handlePinStatus(request ipc.IPCMessage, cfg *config.Config, vault *vault.Va
|
|||
pinStatus = "disabled"
|
||||
}
|
||||
|
||||
response, err = ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
||||
response, err = messages.IPCMessageFromPayload(messages.ActionResponse{
|
||||
Success: true,
|
||||
Message: pinStatus,
|
||||
})
|
||||
|
@ -178,9 +179,9 @@ func handlePinStatus(request ipc.IPCMessage, cfg *config.Config, vault *vault.Va
|
|||
}
|
||||
|
||||
func init() {
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeUnlockVaultRequest, handleUnlockVault)
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeLockVaultRequest, handleLockVault)
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeWipeVaultRequest, handleWipeVault)
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeUpdateVaultPINRequest, ensureBiometricsAuthorized(systemauth.AccessVault, handleUpdateVaultPin))
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeGetVaultPINStatusRequest, handlePinStatus)
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.UnlockVaultRequest{}), handleUnlockVault)
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.LockVaultRequest{}), handleLockVault)
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.WipeVaultRequest{}), handleWipeVault)
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.UpdateVaultPINRequest{}), ensureBiometricsAuthorized(systemauth.AccessVault, handleUpdateVaultPin))
|
||||
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.GetVaultPINRequest{}), handlePinStatus)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/quexten/goldwarden/agent/sockets"
|
||||
"github.com/quexten/goldwarden/agent/ssh"
|
||||
"github.com/quexten/goldwarden/agent/vault"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
"github.com/quexten/goldwarden/logging"
|
||||
)
|
||||
|
||||
|
@ -28,7 +28,7 @@ const (
|
|||
var log = logging.GetLogger("Goldwarden", "Agent")
|
||||
|
||||
func writeError(c net.Conn, errMsg error) error {
|
||||
payload := ipc.ActionResponse{
|
||||
payload := messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: errMsg.Error(),
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ func serveAgentSession(c net.Conn, ctx context.Context, vault *vault.Vault, cfg
|
|||
|
||||
data := buf[0:nr]
|
||||
|
||||
var msg ipc.IPCMessage
|
||||
var msg messages.IPCMessage
|
||||
err = json.Unmarshal(data, &msg)
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
|
@ -74,7 +74,7 @@ func serveAgentSession(c net.Conn, ctx context.Context, vault *vault.Vault, cfg
|
|||
continue
|
||||
}
|
||||
} else {
|
||||
payload := ipc.ActionResponse{
|
||||
payload := messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "Action not found",
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/quexten/goldwarden/agent/processsecurity"
|
||||
"github.com/quexten/goldwarden/agent/sockets"
|
||||
"github.com/quexten/goldwarden/agent/vault"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
func writeErrorToLog(err error) {
|
||||
|
@ -25,7 +25,7 @@ func serveVirtualAgent(recv chan []byte, send chan []byte, ctx context.Context,
|
|||
for {
|
||||
data := <-recv
|
||||
|
||||
var msg ipc.IPCMessage
|
||||
var msg messages.IPCMessage
|
||||
err := json.Unmarshal(data, &msg)
|
||||
if err != nil {
|
||||
writeErrorToLog(err)
|
||||
|
@ -55,7 +55,7 @@ func serveVirtualAgent(recv chan []byte, send chan []byte, ctx context.Context,
|
|||
continue
|
||||
}
|
||||
} else {
|
||||
payload := ipc.ActionResponse{
|
||||
payload := messages.ActionResponse{
|
||||
Success: false,
|
||||
Message: "Action not found",
|
||||
}
|
||||
|
|
|
@ -8,44 +8,44 @@ import (
|
|||
"github.com/atotto/clipboard"
|
||||
"github.com/quexten/goldwarden/autofill/autotype"
|
||||
"github.com/quexten/goldwarden/client"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
func GetLoginByUUID(uuid string, client client.Client) (ipc.DecryptedLoginCipher, error) {
|
||||
resp, err := client.SendToAgent(ipc.GetLoginRequest{
|
||||
func GetLoginByUUID(uuid string, client client.Client) (messages.DecryptedLoginCipher, error) {
|
||||
resp, err := client.SendToAgent(messages.GetLoginRequest{
|
||||
UUID: uuid,
|
||||
})
|
||||
if err != nil {
|
||||
return ipc.DecryptedLoginCipher{}, err
|
||||
return messages.DecryptedLoginCipher{}, err
|
||||
}
|
||||
|
||||
switch resp.(type) {
|
||||
case ipc.GetLoginResponse:
|
||||
castedResponse := (resp.(ipc.GetLoginResponse))
|
||||
case messages.GetLoginResponse:
|
||||
castedResponse := (resp.(messages.GetLoginResponse))
|
||||
return castedResponse.Result, nil
|
||||
case ipc.ActionResponse:
|
||||
castedResponse := (resp.(ipc.ActionResponse))
|
||||
return ipc.DecryptedLoginCipher{}, errors.New("Error: " + castedResponse.Message)
|
||||
case messages.ActionResponse:
|
||||
castedResponse := (resp.(messages.ActionResponse))
|
||||
return messages.DecryptedLoginCipher{}, errors.New("Error: " + castedResponse.Message)
|
||||
default:
|
||||
return ipc.DecryptedLoginCipher{}, errors.New("Wrong response type")
|
||||
return messages.DecryptedLoginCipher{}, errors.New("Wrong response type")
|
||||
}
|
||||
}
|
||||
|
||||
func ListLogins(client client.Client) ([]ipc.DecryptedLoginCipher, error) {
|
||||
resp, err := client.SendToAgent(ipc.ListLoginsRequest{})
|
||||
func ListLogins(client client.Client) ([]messages.DecryptedLoginCipher, error) {
|
||||
resp, err := client.SendToAgent(messages.ListLoginsRequest{})
|
||||
if err != nil {
|
||||
return []ipc.DecryptedLoginCipher{}, err
|
||||
return []messages.DecryptedLoginCipher{}, err
|
||||
}
|
||||
|
||||
switch resp.(type) {
|
||||
case ipc.GetLoginsResponse:
|
||||
castedResponse := (resp.(ipc.GetLoginsResponse))
|
||||
case messages.GetLoginsResponse:
|
||||
castedResponse := (resp.(messages.GetLoginsResponse))
|
||||
return castedResponse.Result, nil
|
||||
case ipc.ActionResponse:
|
||||
castedResponse := (resp.(ipc.ActionResponse))
|
||||
return []ipc.DecryptedLoginCipher{}, errors.New("Error: " + castedResponse.Message)
|
||||
case messages.ActionResponse:
|
||||
castedResponse := (resp.(messages.ActionResponse))
|
||||
return []messages.DecryptedLoginCipher{}, errors.New("Error: " + castedResponse.Message)
|
||||
default:
|
||||
return []ipc.DecryptedLoginCipher{}, errors.New("Wrong response type")
|
||||
return []messages.DecryptedLoginCipher{}, errors.New("Wrong response type")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
"github.com/quexten/goldwarden/browserbiometrics/logging"
|
||||
"github.com/quexten/goldwarden/client"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
func readLoop() {
|
||||
|
@ -99,18 +99,18 @@ func handlePayloadMessage(msg PayloadMessage, appID string) {
|
|||
case "biometricUnlock":
|
||||
logging.Debugf("Biometric unlock requested")
|
||||
// logging.Debugf("Biometrics authorized: %t", isAuthorized)
|
||||
result, err := client.NewUnixSocketClient().SendToAgent(ipc.GetBiometricsKeyRequest{})
|
||||
result, err := client.NewUnixSocketClient().SendToAgent(messages.GetBiometricsKeyRequest{})
|
||||
if err != nil {
|
||||
logging.Errorf("Unable to send message to agent: %s", err.Error())
|
||||
return
|
||||
}
|
||||
switch result.(type) {
|
||||
case ipc.GetBiometricsKeyResponse:
|
||||
case messages.GetBiometricsKeyResponse:
|
||||
if err != nil {
|
||||
logging.Panicf(err.Error())
|
||||
}
|
||||
|
||||
var key = result.(ipc.GetBiometricsKeyResponse).Key
|
||||
var key = result.(messages.GetBiometricsKeyResponse).Key
|
||||
var payloadMsg ReceiveMessage = ReceiveMessage{
|
||||
Command: "biometricUnlock",
|
||||
Response: "unlocked",
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
const READ_BUFFER = 1 * 1024 * 1024 // 1MB
|
||||
|
@ -25,7 +26,9 @@ func reader(r io.Reader) interface{} {
|
|||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
message, err := ipc.UnmarshalJSON(buf[0:n])
|
||||
|
||||
var message messages.IPCMessage
|
||||
err = json.Unmarshal(buf[0:n], &message)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -45,11 +48,11 @@ func (client UnixSocketClient) SendToAgent(request interface{}) (interface{}, er
|
|||
}
|
||||
defer c.Close()
|
||||
|
||||
message, err := ipc.IPCMessageFromPayload(request)
|
||||
message, err := messages.IPCMessageFromPayload(request)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
messageJson, err := message.MarshallToJson()
|
||||
messageJson, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -59,5 +62,5 @@ func (client UnixSocketClient) SendToAgent(request interface{}) (interface{}, er
|
|||
log.Fatal("write error:", err)
|
||||
}
|
||||
result := reader(c)
|
||||
return result.(ipc.IPCMessage).ParsedPayload(), nil
|
||||
return messages.ParsePayload(result.(messages.IPCMessage)), nil
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
func NewVirtualClient(recv chan []byte, send chan []byte) VirtualClient {
|
||||
|
@ -18,7 +20,8 @@ type VirtualClient struct {
|
|||
|
||||
func virtualReader(recv chan []byte) interface{} {
|
||||
for {
|
||||
message, err := ipc.UnmarshalJSON(<-recv)
|
||||
var message messages.IPCMessage
|
||||
err := json.Unmarshal(<-recv, &message)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -27,16 +30,16 @@ func virtualReader(recv chan []byte) interface{} {
|
|||
}
|
||||
|
||||
func (client VirtualClient) SendToAgent(request interface{}) (interface{}, error) {
|
||||
message, err := ipc.IPCMessageFromPayload(request)
|
||||
message, err := messages.IPCMessageFromPayload(request)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
messageJson, err := message.MarshallToJson()
|
||||
messageJson, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client.send <- messageJson
|
||||
result := virtualReader(client.recv)
|
||||
return result.(ipc.IPCMessage).ParsedPayload(), nil
|
||||
return messages.ParsePayload(result.(messages.IPCMessage)), nil
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -15,7 +15,7 @@ var setApiUrlCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
url := args[0]
|
||||
request := ipc.SetApiURLRequest{}
|
||||
request := messages.SetApiURLRequest{}
|
||||
request.Value = url
|
||||
|
||||
result, err := commandClient.SendToAgent(request)
|
||||
|
@ -25,11 +25,11 @@ var setApiUrlCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.ActionResponse:
|
||||
if result.(ipc.ActionResponse).Success {
|
||||
case messages.ActionResponse:
|
||||
if result.(messages.ActionResponse).Success {
|
||||
println("Done")
|
||||
} else {
|
||||
println("Setting api url failed: " + result.(ipc.ActionResponse).Message)
|
||||
println("Setting api url failed: " + result.(messages.ActionResponse).Message)
|
||||
}
|
||||
default:
|
||||
println("Wrong IPC response type")
|
||||
|
@ -48,7 +48,7 @@ var setIdentityURLCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
url := args[0]
|
||||
request := ipc.SetIdentityURLRequest{}
|
||||
request := messages.SetIdentityURLRequest{}
|
||||
request.Value = url
|
||||
|
||||
result, err := commandClient.SendToAgent(request)
|
||||
|
@ -58,11 +58,11 @@ var setIdentityURLCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.ActionResponse:
|
||||
if result.(ipc.ActionResponse).Success {
|
||||
case messages.ActionResponse:
|
||||
if result.(messages.ActionResponse).Success {
|
||||
println("Done")
|
||||
} else {
|
||||
println("Setting identity url failed: " + result.(ipc.ActionResponse).Message)
|
||||
println("Setting identity url failed: " + result.(messages.ActionResponse).Message)
|
||||
}
|
||||
default:
|
||||
println("Wrong IPC response type")
|
||||
|
@ -81,7 +81,7 @@ var setNotificationsURLCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
url := args[0]
|
||||
request := ipc.SetNotificationsURLRequest{}
|
||||
request := messages.SetNotificationsURLRequest{}
|
||||
request.Value = url
|
||||
|
||||
result, err := commandClient.SendToAgent(request)
|
||||
|
@ -91,11 +91,11 @@ var setNotificationsURLCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.ActionResponse:
|
||||
if result.(ipc.ActionResponse).Success {
|
||||
case messages.ActionResponse:
|
||||
if result.(messages.ActionResponse).Success {
|
||||
println("Done")
|
||||
} else {
|
||||
println("Setting notifications url failed: " + result.(ipc.ActionResponse).Message)
|
||||
println("Setting notifications url failed: " + result.(messages.ActionResponse).Message)
|
||||
}
|
||||
default:
|
||||
println("Wrong IPC response type")
|
||||
|
|
10
cmd/login.go
10
cmd/login.go
|
@ -4,7 +4,7 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -14,7 +14,7 @@ var loginCmd = &cobra.Command{
|
|||
Long: `Starts the login process for Bitwarden.
|
||||
You will be prompted to enter your password, and confirm your second factor if you have one.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
request := ipc.DoLoginRequest{}
|
||||
request := messages.DoLoginRequest{}
|
||||
email, _ := cmd.Flags().GetString("email")
|
||||
if email == "" {
|
||||
println("Error: No email specified")
|
||||
|
@ -32,11 +32,11 @@ var loginCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.ActionResponse:
|
||||
if result.(ipc.ActionResponse).Success {
|
||||
case messages.ActionResponse:
|
||||
if result.(messages.ActionResponse).Success {
|
||||
println("Logged in")
|
||||
} else {
|
||||
println("Login failed: " + result.(ipc.ActionResponse).Message)
|
||||
println("Login failed: " + result.(messages.ActionResponse).Message)
|
||||
}
|
||||
default:
|
||||
println("Wrong IPC response type for login")
|
||||
|
|
|
@ -3,7 +3,7 @@ package cmd
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -28,7 +28,7 @@ var getLoginCmd = &cobra.Command{
|
|||
username, _ := cmd.Flags().GetString("username")
|
||||
fullOutput, _ := cmd.Flags().GetBool("full")
|
||||
|
||||
resp, err := commandClient.SendToAgent(ipc.GetLoginRequest{
|
||||
resp, err := commandClient.SendToAgent(messages.GetLoginRequest{
|
||||
Name: name,
|
||||
Username: username,
|
||||
UUID: uuid,
|
||||
|
@ -39,16 +39,16 @@ var getLoginCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
switch resp.(type) {
|
||||
case ipc.GetLoginResponse:
|
||||
response := resp.(ipc.GetLoginResponse)
|
||||
case messages.GetLoginResponse:
|
||||
response := resp.(messages.GetLoginResponse)
|
||||
if fullOutput {
|
||||
fmt.Println(response.Result)
|
||||
} else {
|
||||
fmt.Println(response.Result.Password)
|
||||
}
|
||||
break
|
||||
case ipc.ActionResponse:
|
||||
println("Error: " + resp.(ipc.ActionResponse).Message)
|
||||
case messages.ActionResponse:
|
||||
println("Error: " + resp.(messages.ActionResponse).Message)
|
||||
return
|
||||
}
|
||||
},
|
||||
|
|
16
cmd/pin.go
16
cmd/pin.go
|
@ -1,7 +1,7 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -16,18 +16,18 @@ var setPinCmd = &cobra.Command{
|
|||
Short: "Set a new pin",
|
||||
Long: `Set a new pin. The pin is used to unlock the vault.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
result, err := commandClient.SendToAgent(ipc.UpdateVaultPINRequest{})
|
||||
result, err := commandClient.SendToAgent(messages.UpdateVaultPINRequest{})
|
||||
if err != nil {
|
||||
handleSendToAgentError(err)
|
||||
return
|
||||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.ActionResponse:
|
||||
if result.(ipc.ActionResponse).Success {
|
||||
case messages.ActionResponse:
|
||||
if result.(messages.ActionResponse).Success {
|
||||
println("Pin updated")
|
||||
} else {
|
||||
println("Pin updating failed: " + result.(ipc.ActionResponse).Message)
|
||||
println("Pin updating failed: " + result.(messages.ActionResponse).Message)
|
||||
}
|
||||
default:
|
||||
println("Wrong response type")
|
||||
|
@ -40,15 +40,15 @@ var pinStatusCmd = &cobra.Command{
|
|||
Short: "Check if a pin is set",
|
||||
Long: `Check if a pin is set. The pin is used to unlock the vault.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
result, err := commandClient.SendToAgent(ipc.GetVaultPINRequest{})
|
||||
result, err := commandClient.SendToAgent(messages.GetVaultPINRequest{})
|
||||
if err != nil {
|
||||
handleSendToAgentError(err)
|
||||
return
|
||||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.ActionResponse:
|
||||
println("Pin status: " + result.(ipc.ActionResponse).Message)
|
||||
case messages.ActionResponse:
|
||||
println("Pin status: " + result.(messages.ActionResponse).Message)
|
||||
default:
|
||||
println("Wrong response type")
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/quexten/goldwarden/agent"
|
||||
"github.com/quexten/goldwarden/agent/config"
|
||||
"github.com/quexten/goldwarden/client"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -46,12 +46,12 @@ func loginIfRequired() error {
|
|||
var err error
|
||||
|
||||
if runtimeConfig.AuthMethod == "password" {
|
||||
_, err = commandClient.SendToAgent(ipc.DoLoginRequest{
|
||||
_, err = commandClient.SendToAgent(messages.DoLoginRequest{
|
||||
Email: runtimeConfig.User,
|
||||
Password: runtimeConfig.Password,
|
||||
})
|
||||
} else if runtimeConfig.AuthMethod == "passwordless" {
|
||||
_, err = commandClient.SendToAgent(ipc.DoLoginRequest{
|
||||
_, err = commandClient.SendToAgent(messages.DoLoginRequest{
|
||||
Email: runtimeConfig.User,
|
||||
Passwordless: true,
|
||||
})
|
||||
|
|
12
cmd/run.go
12
cmd/run.go
|
@ -7,7 +7,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -28,7 +28,7 @@ var runCmd = &cobra.Command{
|
|||
|
||||
env := []string{}
|
||||
|
||||
result, err := commandClient.SendToAgent(ipc.GetCLICredentialsRequest{
|
||||
result, err := commandClient.SendToAgent(messages.GetCLICredentialsRequest{
|
||||
ApplicationName: executable,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -37,13 +37,13 @@ var runCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.GetCLICredentialsResponse:
|
||||
response := result.(ipc.GetCLICredentialsResponse)
|
||||
case messages.GetCLICredentialsResponse:
|
||||
response := result.(messages.GetCLICredentialsResponse)
|
||||
for key, value := range response.Env {
|
||||
env = append(env, key+"="+value)
|
||||
}
|
||||
case ipc.ActionResponse:
|
||||
println("Error: " + result.(ipc.ActionResponse).Message)
|
||||
case messages.ActionResponse:
|
||||
println("Error: " + result.(messages.ActionResponse).Message)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
25
cmd/ssh.go
25
cmd/ssh.go
|
@ -1,13 +1,10 @@
|
|||
/*
|
||||
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/atotto/clipboard"
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -32,7 +29,7 @@ var sshAddCmd = &cobra.Command{
|
|||
name, _ := cmd.Flags().GetString("name")
|
||||
copyToClipboard, _ := cmd.Flags().GetBool("clipboard")
|
||||
|
||||
result, err := commandClient.SendToAgent(ipc.CreateSSHKeyRequest{
|
||||
result, err := commandClient.SendToAgent(messages.CreateSSHKeyRequest{
|
||||
Name: name,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -41,16 +38,16 @@ var sshAddCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.CreateSSHKeyResponse:
|
||||
response := result.(ipc.CreateSSHKeyResponse)
|
||||
case messages.CreateSSHKeyResponse:
|
||||
response := result.(messages.CreateSSHKeyResponse)
|
||||
fmt.Println(response.Digest)
|
||||
|
||||
if copyToClipboard {
|
||||
clipboard.WriteAll(string(response.Digest))
|
||||
}
|
||||
break
|
||||
case ipc.ActionResponse:
|
||||
println("Error: " + result.(ipc.ActionResponse).Message)
|
||||
case messages.ActionResponse:
|
||||
println("Error: " + result.(messages.ActionResponse).Message)
|
||||
return
|
||||
}
|
||||
},
|
||||
|
@ -63,21 +60,21 @@ var listSSHCmd = &cobra.Command{
|
|||
Run: func(cmd *cobra.Command, args []string) {
|
||||
loginIfRequired()
|
||||
|
||||
result, err := commandClient.SendToAgent(ipc.GetSSHKeysRequest{})
|
||||
result, err := commandClient.SendToAgent(messages.GetSSHKeysRequest{})
|
||||
if err != nil {
|
||||
handleSendToAgentError(err)
|
||||
return
|
||||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.GetSSHKeysResponse:
|
||||
response := result.(ipc.GetSSHKeysResponse)
|
||||
case messages.GetSSHKeysResponse:
|
||||
response := result.(messages.GetSSHKeysResponse)
|
||||
for _, key := range response.Keys {
|
||||
fmt.Println(key)
|
||||
}
|
||||
break
|
||||
case ipc.ActionResponse:
|
||||
println("Error: " + result.(ipc.ActionResponse).Message)
|
||||
case messages.ActionResponse:
|
||||
println("Error: " + result.(messages.ActionResponse).Message)
|
||||
return
|
||||
}
|
||||
},
|
||||
|
|
26
cmd/vault.go
26
cmd/vault.go
|
@ -1,7 +1,7 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/quexten/goldwarden/ipc"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -16,7 +16,7 @@ var unlockCmd = &cobra.Command{
|
|||
Short: "Unlocks the vault",
|
||||
Long: `Unlocks the vault. You will be prompted for your pin. The pin is empty by default.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
request := ipc.UnlockVaultRequest{}
|
||||
request := messages.UnlockVaultRequest{}
|
||||
|
||||
result, err := commandClient.SendToAgent(request)
|
||||
if err != nil {
|
||||
|
@ -25,11 +25,11 @@ var unlockCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.ActionResponse:
|
||||
if result.(ipc.ActionResponse).Success {
|
||||
case messages.ActionResponse:
|
||||
if result.(messages.ActionResponse).Success {
|
||||
println("Unlocked")
|
||||
} else {
|
||||
println("Not unlocked: " + result.(ipc.ActionResponse).Message)
|
||||
println("Not unlocked: " + result.(messages.ActionResponse).Message)
|
||||
}
|
||||
default:
|
||||
println("Wrong response type")
|
||||
|
@ -42,7 +42,7 @@ var lockCmd = &cobra.Command{
|
|||
Short: "Locks the vault",
|
||||
Long: `Locks the vault.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
request := ipc.LockVaultRequest{}
|
||||
request := messages.LockVaultRequest{}
|
||||
|
||||
result, err := commandClient.SendToAgent(request)
|
||||
if err != nil {
|
||||
|
@ -51,11 +51,11 @@ var lockCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.ActionResponse:
|
||||
if result.(ipc.ActionResponse).Success {
|
||||
case messages.ActionResponse:
|
||||
if result.(messages.ActionResponse).Success {
|
||||
println("Locked")
|
||||
} else {
|
||||
println("Not locked: " + result.(ipc.ActionResponse).Message)
|
||||
println("Not locked: " + result.(messages.ActionResponse).Message)
|
||||
}
|
||||
default:
|
||||
println("Wrong response type")
|
||||
|
@ -68,7 +68,7 @@ var purgeCmd = &cobra.Command{
|
|||
Short: "Wipes the vault",
|
||||
Long: `Wipes the vault and encryption keys from ram and config. Does not delete any entries on the server side.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
request := ipc.WipeVaultRequest{}
|
||||
request := messages.WipeVaultRequest{}
|
||||
|
||||
result, err := commandClient.SendToAgent(request)
|
||||
if err != nil {
|
||||
|
@ -77,11 +77,11 @@ var purgeCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
switch result.(type) {
|
||||
case ipc.ActionResponse:
|
||||
if result.(ipc.ActionResponse).Success {
|
||||
case messages.ActionResponse:
|
||||
if result.(messages.ActionResponse).Success {
|
||||
println("Purged")
|
||||
} else {
|
||||
println("Not purged: " + result.(ipc.ActionResponse).Message)
|
||||
println("Not purged: " + result.(messages.ActionResponse).Message)
|
||||
}
|
||||
default:
|
||||
println("Wrong response type")
|
||||
|
|
508
ipc/ipc.go
508
ipc/ipc.go
|
@ -1,509 +1,15 @@
|
|||
package ipc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/quexten/goldwarden/ipc/messages"
|
||||
)
|
||||
|
||||
type IPCMessageType int64
|
||||
|
||||
const (
|
||||
IPCMessageTypeErrorMessage IPCMessageType = 0
|
||||
|
||||
IPCMessageTypeDoLoginRequest IPCMessageType = 1
|
||||
|
||||
IPCMessageTypeUpdateVaultPINRequest IPCMessageType = 4
|
||||
IPCMessageTypeUnlockVaultRequest IPCMessageType = 5
|
||||
IPCMessageTypeLockVaultRequest IPCMessageType = 6
|
||||
IPCMessageTypeWipeVaultRequest IPCMessageType = 7
|
||||
|
||||
IPCMessageTypeGetCLICredentialsRequest IPCMessageType = 11
|
||||
IPCMessageTypeGetCLICredentialsResponse IPCMessageType = 12
|
||||
|
||||
IPCMessageTypeCreateSSHKeyRequest IPCMessageType = 14
|
||||
IPCMessageTypeCreateSSHKeyResponse IPCMessageType = 15
|
||||
|
||||
IPCMessageTypeGetSSHKeysRequest IPCMessageType = 16
|
||||
IPCMessageTypeGetSSHKeysResponse IPCMessageType = 17
|
||||
|
||||
IPCMessageGetLoginRequest IPCMessageType = 18
|
||||
IPCMessageGetLoginResponse IPCMessageType = 19
|
||||
|
||||
IPCMessageAddLoginRequest IPCMessageType = 20
|
||||
IPCMessageAddLoginResponse IPCMessageType = 21
|
||||
|
||||
IPCMessageGetNoteRequest IPCMessageType = 26
|
||||
IPCMessageGetNoteResponse IPCMessageType = 27
|
||||
IPCMessageGetNotesResponse IPCMessageType = 32
|
||||
IPCMessageGetLoginsResponse IPCMessageType = 33
|
||||
|
||||
IPCMessageAddNoteRequest IPCMessageType = 28
|
||||
IPCMessageAddNoteResponse IPCMessageType = 29
|
||||
|
||||
IPCMessageListLoginsRequest IPCMessageType = 22
|
||||
|
||||
IPCMessageTypeActionResponse IPCMessageType = 13
|
||||
|
||||
IPCMessageTypeGetVaultPINStatusRequest IPCMessageType = 2
|
||||
|
||||
IPCMessageTypeSetAPIUrlRequest IPCMessageType = 30
|
||||
IPCMessageTypeSetIdentityURLRequest IPCMessageType = 31
|
||||
IPCMessageTypeSetNotificationsURLRequest IPCMessageType = 34
|
||||
|
||||
IPCMessageTypeGetBiometricsKeyRequest IPCMessageType = 8
|
||||
IPCMessageTypeGetBiometricsKeyResponse IPCMessageType = 9
|
||||
)
|
||||
|
||||
type IPCMessage struct {
|
||||
Type IPCMessageType `json:"type"`
|
||||
Payload []byte `json:"payload"`
|
||||
func ParsedPayload(m messages.IPCMessage) interface{} {
|
||||
payload := messages.ParsePayload(m)
|
||||
return payload
|
||||
}
|
||||
|
||||
func (m IPCMessage) MarshallToJson() ([]byte, error) {
|
||||
return json.Marshal(m)
|
||||
}
|
||||
|
||||
func UnmarshalJSON(data []byte) (IPCMessage, error) {
|
||||
var m IPCMessage
|
||||
err := json.Unmarshal(data, &m)
|
||||
return m, err
|
||||
}
|
||||
|
||||
func (m IPCMessage) ParsedPayload() interface{} {
|
||||
switch m.Type {
|
||||
case IPCMessageTypeDoLoginRequest:
|
||||
var req DoLoginRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageTypeActionResponse:
|
||||
var res ActionResponse
|
||||
err := json.Unmarshal(m.Payload, &res)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return res
|
||||
case IPCMessageTypeErrorMessage:
|
||||
return nil
|
||||
case IPCMessageTypeGetCLICredentialsRequest:
|
||||
var req GetCLICredentialsRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageTypeGetCLICredentialsResponse:
|
||||
var res GetCLICredentialsResponse
|
||||
err := json.Unmarshal(m.Payload, &res)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return res
|
||||
case IPCMessageTypeCreateSSHKeyRequest:
|
||||
var req CreateSSHKeyRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageTypeCreateSSHKeyResponse:
|
||||
var res CreateSSHKeyResponse
|
||||
err := json.Unmarshal(m.Payload, &res)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return res
|
||||
case IPCMessageTypeGetSSHKeysRequest:
|
||||
var req GetSSHKeysRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageTypeGetSSHKeysResponse:
|
||||
var res GetSSHKeysResponse
|
||||
err := json.Unmarshal(m.Payload, &res)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return res
|
||||
case IPCMessageGetLoginRequest:
|
||||
var req GetLoginRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageGetLoginResponse:
|
||||
var res GetLoginResponse
|
||||
err := json.Unmarshal(m.Payload, &res)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return res
|
||||
case IPCMessageAddLoginRequest:
|
||||
var req AddLoginRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageAddLoginResponse:
|
||||
var res AddLoginResponse
|
||||
err := json.Unmarshal(m.Payload, &res)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return res
|
||||
case IPCMessageTypeWipeVaultRequest:
|
||||
var req WipeVaultRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageTypeLockVaultRequest:
|
||||
var req LockVaultRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageTypeGetVaultPINStatusRequest:
|
||||
var req GetVaultPINRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageTypeSetAPIUrlRequest:
|
||||
var req SetApiURLRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageTypeSetIdentityURLRequest:
|
||||
var req SetIdentityURLRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageTypeSetNotificationsURLRequest:
|
||||
var req SetNotificationsURLRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageGetLoginsResponse:
|
||||
var res GetLoginsResponse
|
||||
err := json.Unmarshal(m.Payload, &res)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return res
|
||||
case IPCMessageTypeGetBiometricsKeyRequest:
|
||||
var res GetBiometricsKeyRequest
|
||||
err := json.Unmarshal(m.Payload, &res)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return res
|
||||
case IPCMessageTypeGetBiometricsKeyResponse:
|
||||
var res GetBiometricsKeyResponse
|
||||
err := json.Unmarshal(m.Payload, &res)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return res
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func IPCMessageFromPayload(payload interface{}) (IPCMessage, error) {
|
||||
jsonBytes, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return IPCMessage{}, err
|
||||
}
|
||||
|
||||
switch payload.(type) {
|
||||
case UnlockVaultRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeUnlockVaultRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case UpdateVaultPINRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeUpdateVaultPINRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case DoLoginRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeDoLoginRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case ActionResponse:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeActionResponse,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetCLICredentialsRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeGetCLICredentialsRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetCLICredentialsResponse:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeGetCLICredentialsResponse,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case CreateSSHKeyRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeCreateSSHKeyRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case CreateSSHKeyResponse:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeCreateSSHKeyResponse,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetSSHKeysRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeGetSSHKeysRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetSSHKeysResponse:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeGetSSHKeysResponse,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case WipeVaultRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeWipeVaultRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case LockVaultRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeLockVaultRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetVaultPINRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeGetVaultPINStatusRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case SetApiURLRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeSetAPIUrlRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case SetIdentityURLRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeSetIdentityURLRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case SetNotificationsURLRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeSetNotificationsURLRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetLoginRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageGetLoginRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetLoginResponse:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageGetLoginResponse,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case AddLoginRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageAddLoginRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case AddLoginResponse:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageAddLoginResponse,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetNotesRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageGetNoteRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetNotesResponse:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageGetNotesResponse,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetNoteResponse:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageGetNoteResponse,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetLoginsResponse:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageGetLoginsResponse,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case ListLoginsRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageListLoginsRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetBiometricsKeyRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeGetBiometricsKeyRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetBiometricsKeyResponse:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeGetBiometricsKeyResponse,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
default:
|
||||
payloadBytes, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return IPCMessage{}, err
|
||||
}
|
||||
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeErrorMessage,
|
||||
Payload: payloadBytes,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
type DoLoginRequest struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Passwordless bool `json:"passwordless"`
|
||||
}
|
||||
|
||||
type LockVaultRequest struct {
|
||||
}
|
||||
|
||||
type UnlockVaultRequest struct {
|
||||
}
|
||||
|
||||
type UpdateVaultPINRequest struct {
|
||||
}
|
||||
|
||||
type ActionResponse struct {
|
||||
Success bool
|
||||
Message string
|
||||
}
|
||||
|
||||
type GetCLICredentialsRequest struct {
|
||||
ApplicationName string
|
||||
}
|
||||
|
||||
type GetCLICredentialsResponse struct {
|
||||
Env map[string]string
|
||||
}
|
||||
|
||||
type CreateSSHKeyRequest struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type CreateSSHKeyResponse struct {
|
||||
Digest string
|
||||
}
|
||||
|
||||
type GetSSHKeysRequest struct {
|
||||
}
|
||||
|
||||
type GetSSHKeysResponse struct {
|
||||
Keys []string
|
||||
}
|
||||
|
||||
type GetLoginRequest struct {
|
||||
Name string
|
||||
Username string
|
||||
UUID string
|
||||
OrgId string
|
||||
|
||||
GetList bool
|
||||
}
|
||||
|
||||
type GetLoginResponse struct {
|
||||
Found bool
|
||||
Result DecryptedLoginCipher
|
||||
}
|
||||
|
||||
type GetLoginsResponse struct {
|
||||
Found bool
|
||||
Result []DecryptedLoginCipher
|
||||
}
|
||||
|
||||
type DecryptedLoginCipher struct {
|
||||
Name string
|
||||
Username string
|
||||
Password string
|
||||
UUID string
|
||||
OrgaizationID string
|
||||
Notes string
|
||||
TwoFactorCode string
|
||||
}
|
||||
|
||||
type GetNotesRequest struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type GetNoteResponse struct {
|
||||
Found bool
|
||||
Result DecryptedNoteCipher
|
||||
}
|
||||
|
||||
type GetNotesResponse struct {
|
||||
Found bool
|
||||
Result []DecryptedNoteCipher
|
||||
}
|
||||
|
||||
type DecryptedNoteCipher struct {
|
||||
Name string
|
||||
Contents string
|
||||
}
|
||||
|
||||
type AddLoginRequest struct {
|
||||
Name string
|
||||
UUID string
|
||||
}
|
||||
|
||||
type AddLoginResponse struct {
|
||||
Name string
|
||||
UUID string
|
||||
}
|
||||
|
||||
type WipeVaultRequest struct {
|
||||
}
|
||||
|
||||
type GetVaultPINRequest struct {
|
||||
}
|
||||
|
||||
type SetApiURLRequest struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
type SetIdentityURLRequest struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
type SetNotificationsURLRequest struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
type ListLoginsRequest struct {
|
||||
}
|
||||
|
||||
type GetBiometricsKeyRequest struct {
|
||||
}
|
||||
|
||||
type GetBiometricsKeyResponse struct {
|
||||
Key string
|
||||
func IPCMessageFromPayload(payload interface{}) (messages.IPCMessage, error) {
|
||||
message, err := messages.IPCMessageFromPayload(payload)
|
||||
return message, err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package messages
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type ActionResponse struct {
|
||||
Success bool
|
||||
Message string
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req ActionResponse
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, ActionResponse{})
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package messages
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type GetBiometricsKeyRequest struct {
|
||||
}
|
||||
|
||||
type GetBiometricsKeyResponse struct {
|
||||
Key string
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetBiometricsKeyRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetBiometricsKeyRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetBiometricsKeyResponse
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetBiometricsKeyResponse{})
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package messages
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type SetApiURLRequest struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
type SetIdentityURLRequest struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
type SetNotificationsURLRequest struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req SetApiURLRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, SetApiURLRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req SetIdentityURLRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, SetIdentityURLRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req SetNotificationsURLRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, SetNotificationsURLRequest{})
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package messages
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type DoLoginRequest struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Passwordless bool `json:"passwordless"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req DoLoginRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, DoLoginRequest{})
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package messages
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type GetCLICredentialsRequest struct {
|
||||
ApplicationName string
|
||||
}
|
||||
|
||||
type GetCLICredentialsResponse struct {
|
||||
Env map[string]string
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetCLICredentialsRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetCLICredentialsRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetCLICredentialsResponse
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetCLICredentialsResponse{})
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package messages
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type GetNotesRequest struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type GetNoteResponse struct {
|
||||
Found bool
|
||||
Result DecryptedNoteCipher
|
||||
}
|
||||
|
||||
type GetNotesResponse struct {
|
||||
Found bool
|
||||
Result []DecryptedNoteCipher
|
||||
}
|
||||
|
||||
type DecryptedNoteCipher struct {
|
||||
Name string
|
||||
Contents string
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetNotesRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetNotesRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetNoteResponse
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetNoteResponse{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetNotesResponse
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetNotesResponse{})
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package messages
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"hash/fnv"
|
||||
"reflect"
|
||||
|
||||
"github.com/quexten/goldwarden/logging"
|
||||
)
|
||||
|
||||
var log = logging.GetLogger("Goldwarden", "IPC Messages")
|
||||
|
||||
type IPCMessageType int64
|
||||
type IPCMessage struct {
|
||||
Type IPCMessageType `json:"type"`
|
||||
Payload []byte `json:"payload"`
|
||||
}
|
||||
|
||||
type parsePayload func([]byte) (interface{}, error)
|
||||
|
||||
var messages = map[string]parsePayload{}
|
||||
var messageTypes = map[IPCMessageType]string{}
|
||||
|
||||
func MessageTypeForEmptyPayload(emptyPayload interface{}) IPCMessageType {
|
||||
return hash(reflect.TypeOf(emptyPayload).Name())
|
||||
}
|
||||
|
||||
func hash(s string) IPCMessageType {
|
||||
h := fnv.New64()
|
||||
h.Write([]byte(s))
|
||||
return IPCMessageType(h.Sum64())
|
||||
}
|
||||
|
||||
func registerPayloadParser(payloadParser parsePayload, emptyPayload interface{}) {
|
||||
messages[reflect.TypeOf(emptyPayload).Name()] = payloadParser
|
||||
messageTypes[hash(reflect.TypeOf(emptyPayload).Name())] = reflect.TypeOf(emptyPayload).Name()
|
||||
}
|
||||
|
||||
func ParsePayload(message IPCMessage) interface{} {
|
||||
if _, ok := messageTypes[message.Type]; !ok {
|
||||
log.Error("Unregistered message type %s", string(message.Type))
|
||||
return nil
|
||||
}
|
||||
if payload, err := messages[messageTypes[message.Type]](message.Payload); err != nil {
|
||||
log.Error("Error parsing payload: %s", err.Error())
|
||||
return nil
|
||||
} else {
|
||||
return payload
|
||||
}
|
||||
}
|
||||
|
||||
func IPCMessageFromPayload(payload interface{}) (IPCMessage, error) {
|
||||
payloadTypeName := reflect.TypeOf(payload).Name()
|
||||
if _, ok := messages[payloadTypeName]; !ok {
|
||||
return IPCMessage{}, errors.New("Unregistered payload type " + payloadTypeName)
|
||||
}
|
||||
payloadJSON, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return IPCMessage{}, err
|
||||
}
|
||||
|
||||
messageType := hash(payloadTypeName)
|
||||
return IPCMessage{
|
||||
Type: messageType,
|
||||
Payload: payloadJSON,
|
||||
}, nil
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package messages
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type GetLoginRequest struct {
|
||||
Name string
|
||||
Username string
|
||||
UUID string
|
||||
OrgId string
|
||||
|
||||
GetList bool
|
||||
}
|
||||
|
||||
type GetLoginResponse struct {
|
||||
Found bool
|
||||
Result DecryptedLoginCipher
|
||||
}
|
||||
|
||||
type GetLoginsResponse struct {
|
||||
Found bool
|
||||
Result []DecryptedLoginCipher
|
||||
}
|
||||
|
||||
type DecryptedLoginCipher struct {
|
||||
Name string
|
||||
Username string
|
||||
Password string
|
||||
UUID string
|
||||
OrgaizationID string
|
||||
Notes string
|
||||
TwoFactorCode string
|
||||
}
|
||||
|
||||
type AddLoginRequest struct {
|
||||
Name string
|
||||
UUID string
|
||||
}
|
||||
|
||||
type AddLoginResponse struct {
|
||||
Name string
|
||||
UUID string
|
||||
}
|
||||
|
||||
type ListLoginsRequest struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetLoginRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetLoginRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetLoginResponse
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetLoginResponse{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetLoginsResponse
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetLoginsResponse{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req AddLoginRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, AddLoginRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req AddLoginResponse
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, AddLoginResponse{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req ListLoginsRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, ListLoginsRequest{})
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package messages
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type CreateSSHKeyRequest struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type CreateSSHKeyResponse struct {
|
||||
Digest string
|
||||
}
|
||||
|
||||
type GetSSHKeysRequest struct {
|
||||
}
|
||||
|
||||
type GetSSHKeysResponse struct {
|
||||
Keys []string
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req CreateSSHKeyRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, CreateSSHKeyRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req CreateSSHKeyResponse
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, CreateSSHKeyResponse{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetSSHKeysRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetSSHKeysRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetSSHKeysResponse
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetSSHKeysResponse{})
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package messages
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type LockVaultRequest struct {
|
||||
}
|
||||
|
||||
type UnlockVaultRequest struct {
|
||||
}
|
||||
|
||||
type UpdateVaultPINRequest struct {
|
||||
}
|
||||
|
||||
type WipeVaultRequest struct {
|
||||
}
|
||||
|
||||
type GetVaultPINRequest struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req LockVaultRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, LockVaultRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req UnlockVaultRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, UnlockVaultRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req UpdateVaultPINRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, UpdateVaultPINRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req WipeVaultRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, WipeVaultRequest{})
|
||||
|
||||
registerPayloadParser(func(payload []byte) (interface{}, error) {
|
||||
var req GetVaultPINRequest
|
||||
err := json.Unmarshal(payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req, nil
|
||||
}, GetVaultPINRequest{})
|
||||
}
|
Loading…
Reference in New Issue