Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Mechanism of moving credentials from UI client to daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
stenya committed May 5, 2020
1 parent ef600d7 commit c3fda0a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
42 changes: 20 additions & 22 deletions protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ func (p *Protocol) processRequest(conn net.Conn, message string) {
}

log.Info(fmt.Sprintf("%sConnected client version: '%s' [set KeepDaemonAlone = %t]", p.connLogID(conn), req.Version, req.KeepDaemonAlone))

// When upgrading from old client version, it is necessary to copy current credentials from UI client
if len(req.SetRawCredentials.AccountID) > 0 && len(req.SetRawCredentials.Session) > 0 {
r := req.SetRawCredentials
if err := p._service.SetRawCredentials(r.AccountID,
r.Session,
r.OvpnUser,
r.OvpnPass,
r.WgPublicKey,
r.WgPrivateKey,
r.WgLocalIP,
r.WgKeyGenerated); err != nil {
// failed to save RAW credentials
err := fmt.Errorf("failed to register RAW credentials: %w", err)
log.Error(err)
p.sendErrorResponse(conn, reqCmd, err)
return
}
}

// send back Hello message with account session info
p.sendResponse(conn, p.createHelloResponse(), req.Idx)

Expand Down Expand Up @@ -560,28 +580,6 @@ func (p *Protocol) processRequest(conn net.Conn, message string) {
p.sendResponse(conn, &types.EmptyResp{}, reqCmd.Idx)
break

case "SetCredentials":
var r types.SetCredentials
if err := json.Unmarshal(messageData, &r); err != nil {
p.sendErrorResponse(conn, reqCmd, err)
break
}

if err := p._service.SetRawCredentials(r.AccountID,
r.Session,
r.OvpnUser,
r.OvpnPass,
r.WgPublicKey,
r.WgPrivateKey,
r.WgLocalIP,
r.WgKeyGenerated); err != nil {
p.sendErrorResponse(conn, reqCmd, err)
} else {
p.sendResponse(conn, &types.EmptyResp{}, reqCmd.Idx)
}

break

case "SessionNew":
var req types.SessionNew
if err := json.Unmarshal(messageData, &req); err != nil {
Expand Down
29 changes: 16 additions & 13 deletions protocol/types/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ type Hello struct {
// KeepDaemonAlone == false (default) - VPN disconnects when client disconnects from a daemon
// KeepDaemonAlone == true - do nothing when client disconnects from a daemon (if VPN is connected - do not disconnect)
KeepDaemonAlone bool

// Register credentials (if not logged in)
// Used when updating from an old client version
SetRawCredentials RawCredentials
}

// RawCredentials - RAW credentials
type RawCredentials struct {
AccountID string
Session string
OvpnUser string
OvpnPass string
WgPublicKey string
WgPrivateKey string
WgLocalIP string
WgKeyGenerated int64 // Unix time
}

// GetServers request servers list
Expand Down Expand Up @@ -167,16 +183,3 @@ type WireGuardSetKeysRotationInterval struct {
CommandBase
Interval int64
}

// SetCredentials - manually set RAW credentials
type SetCredentials struct {
CommandBase
AccountID string
Session string
OvpnUser string
OvpnPass string
WgPublicKey string
WgPrivateKey string
WgLocalIP string
WgKeyGenerated int64 // Unix time
}

0 comments on commit c3fda0a

Please sign in to comment.