Skip to content

Commit

Permalink
Only return passwords that include letters.
Browse files Browse the repository at this point in the history
Password decryption can fail if the database password is all numbers because ruby will read it as an integer instead of a string.

== Checking deployment status ==
rake aborted!
NoMethodError: undefined method `empty?' for 8783875645714351:Integer
.../gems/manageiq-password-1.2.0/lib/manageiq/password.rb:165:in `remove_erb'
.../gems/manageiq-password-1.2.0/lib/manageiq/password.rb:90:in `try_decrypt'
/var/www/miq/vmdb/lib/vmdb/settings_walker.rb:76:in `block in decrypt_passwords!'
  • Loading branch information
bdunne committed Feb 6, 2024
1 parent 7bacf4f commit 57227fd
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/rand"
"encoding/base64"
"encoding/hex"
"regexp"
)

func randomBytes(n int) []byte {
Expand All @@ -20,6 +21,13 @@ func generateEncryptionKey() string {
}

func generatePassword() string {
buf := randomBytes(8)
return hex.EncodeToString(buf)
for {
buf := randomBytes(8)
password := hex.EncodeToString(buf)
if match, err := regexp.MatchString(`\D+`, password); err == nil && match {
// Only return if a letter is included.
// Password decryption can fail if the database password is all numbers because ruby will read it as an integer instead of a string.
return password
}
}
}

0 comments on commit 57227fd

Please sign in to comment.