patch login bug in cli

This commit is contained in:
Maidul Islam
2023-02-23 14:14:41 -05:00
parent 4276fb54cc
commit df52c56e83
+15 -3
View File
@@ -120,6 +120,7 @@ var loginCmd = &cobra.Command{
var decryptedPrivateKey []byte var decryptedPrivateKey []byte
if loginTwoResponse.EncryptionVersion == 1 { if loginTwoResponse.EncryptionVersion == 1 {
log.Debug("Login version 1")
encryptedPrivateKey, _ := base64.StdEncoding.DecodeString(loginTwoResponse.EncryptedPrivateKey) encryptedPrivateKey, _ := base64.StdEncoding.DecodeString(loginTwoResponse.EncryptedPrivateKey)
tag, err := base64.StdEncoding.DecodeString(loginTwoResponse.Tag) tag, err := base64.StdEncoding.DecodeString(loginTwoResponse.Tag)
if err != nil { if err != nil {
@@ -134,11 +135,15 @@ var loginCmd = &cobra.Command{
paddedPassword := fmt.Sprintf("%032s", password) paddedPassword := fmt.Sprintf("%032s", password)
key := []byte(paddedPassword) key := []byte(paddedPassword)
decryptedPrivateKey, err := crypto.DecryptSymmetric(key, encryptedPrivateKey, tag, IV) computedDecryptedPrivateKey, err := crypto.DecryptSymmetric(key, encryptedPrivateKey, tag, IV)
if err != nil || len(decryptedPrivateKey) == 0 { if err != nil || len(computedDecryptedPrivateKey) == 0 {
util.HandleError(err) util.HandleError(err)
} }
decryptedPrivateKey = computedDecryptedPrivateKey
} else if loginTwoResponse.EncryptionVersion == 2 { } else if loginTwoResponse.EncryptionVersion == 2 {
log.Debug("Login version 2")
protectedKey, err := base64.StdEncoding.DecodeString(loginTwoResponse.ProtectedKey) protectedKey, err := base64.StdEncoding.DecodeString(loginTwoResponse.ProtectedKey)
if err != nil { if err != nil {
util.HandleError(err) util.HandleError(err)
@@ -191,14 +196,21 @@ var loginCmd = &cobra.Command{
util.HandleError(err) util.HandleError(err)
} }
decryptedPrivateKey, err = crypto.DecryptSymmetric(decryptedProtectedKeyInHex, encryptedPrivateKey, nonProtectedTag, nonProtectedIv) computedDecryptedPrivateKey, err := crypto.DecryptSymmetric(decryptedProtectedKeyInHex, encryptedPrivateKey, nonProtectedTag, nonProtectedIv)
if err != nil { if err != nil {
util.HandleError(err) util.HandleError(err)
} }
decryptedPrivateKey = computedDecryptedPrivateKey
} else { } else {
util.PrintErrorMessageAndExit("Insufficient details to decrypt private key") util.PrintErrorMessageAndExit("Insufficient details to decrypt private key")
} }
if string(decryptedPrivateKey) == "" || email == "" || loginTwoResponse.Token == "" {
log.Debugf("[decryptedPrivateKey=%s] [email=%s] [loginTwoResponse.Token=%s]", string(decryptedPrivateKey), email, loginTwoResponse.Token)
util.PrintErrorMessageAndExit("We were unable to fetch required details to complete your login. Run with -d to see more info")
}
userCredentialsToBeStored := &models.UserCredentials{ userCredentialsToBeStored := &models.UserCredentials{
Email: email, Email: email,
PrivateKey: string(decryptedPrivateKey), PrivateKey: string(decryptedPrivateKey),