Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Store account publicKey

Neeraj Gupta02b08da7eab1
diff --git a/pkg/account.go b/pkg/account.go
index c2efabe052..692a08b70f 100644
--- a/pkg/account.go
+++ b/pkg/account.go
@@ -3,6 +3,7 @@ package pkg
import (
"cli-go/internal/api"
"cli-go/pkg/model"
+ "cli-go/utils/encoding"
"context"
"encoding/json"
"fmt"
@@ -83,6 +84,7 @@ func (c *ClICtrl) storeAccount(_ context.Context, email string, userID int64, ap
SecretKey: *model.MakeEncString(secretInfo.SecretKey, secret),
Token: *model.MakeEncString(secretInfo.Token, secret),
App: app,
+ PublicKey: encoding.EncodeBase64(secretInfo.PublicKey),
}
accInfoBytes, err := json.Marshal(accInfo)
if err != nil {
diff --git a/pkg/key_holder.go b/pkg/key_holder.go
index 939a4ac462..f3e2664992 100644
--- a/pkg/key_holder.go
+++ b/pkg/key_holder.go
@@ -2,6 +2,7 @@ package pkg
import (
"cli-go/pkg/model"
+ "cli-go/utils/encoding"
"context"
)
@@ -25,6 +26,7 @@ func (k *KeyHolder) LoadSecrets(account model.Account, cliKey []byte) (*accSecre
Token: tokenKey,
MasterKey: masterKey,
SecretKey: secretKey,
+ PublicKey: encoding.DecodeBase64(account.PublicKey),
}
return k.AccountSecrets[account.AccountKey()], nil
}
diff --git a/pkg/model/account.go b/pkg/model/account.go
index 779b123a7b..8556ec8abb 100644
--- a/pkg/model/account.go
+++ b/pkg/model/account.go
@@ -11,6 +11,8 @@ type Account struct {
App api.App `json:"app" binding:"required"`
MasterKey EncString `json:"masterKey" binding:"required"`
SecretKey EncString `json:"secretKey" binding:"required"`
+ // PublicKey corresponding to the secret key
+ PublicKey string `json:"publicKey" binding:"required"`
Token EncString `json:"token" binding:"required"`
}
diff --git a/pkg/sign_in.go b/pkg/sign_in.go
index 180183fe2b..44abdbde44 100644
--- a/pkg/sign_in.go
+++ b/pkg/sign_in.go
@@ -15,6 +15,7 @@ type accSecretInfo struct {
MasterKey []byte
SecretKey []byte
Token []byte
+ PublicKey []byte
}
func (c *ClICtrl) signInViaPassword(ctx context.Context, email string, srpAttr *api.SRPAttributes) (*api.AuthorizationResponse, []byte, error) {
@@ -65,6 +66,7 @@ func (c *ClICtrl) decryptAccSecretInfo(
var currentKeyEncKey []byte
var err error
var masterKey, secretKey, tokenKey []byte
+ var publicKey = encoding.DecodeBase64(authResp.KeyAttributes.PublicKey)
for {
if keyEncKey == nil {
// CLI prompt for password
@@ -106,7 +108,7 @@ func (c *ClICtrl) decryptAccSecretInfo(
}
tokenKey, err = enteCrypto.SealedBoxOpen(
encoding.DecodeBase64(authResp.EncryptedToken),
- encoding.DecodeBase64(authResp.KeyAttributes.PublicKey),
+ publicKey,
secretKey,
)
if err != nil {
@@ -119,6 +121,7 @@ func (c *ClICtrl) decryptAccSecretInfo(
MasterKey: masterKey,
SecretKey: secretKey,
Token: tokenKey,
+ PublicKey: publicKey,
}, nil
}