-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(resolution): restore hex.Decode/Encode when loading/storing ciphered data from database #395
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ package resolution | |||||
|
||||||
import ( | ||||||
"bytes" | ||||||
"encoding/hex" | ||||||
"encoding/json" | ||||||
"time" | ||||||
|
||||||
|
@@ -166,6 +167,9 @@ func Create(dbp zesty.DBProvider, t *task.Task, resolverInputs map[string]interf | |||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
dst := make([]byte, 0, hex.EncodedLen(len(encryptedSteps))) | ||||||
hex.Encode(dst, encryptedSteps) | ||||||
r.EncryptedSteps = encryptedSteps | ||||||
|
||||||
err = tt.ValidateResolverInputs(resolverInputs) | ||||||
|
@@ -247,7 +251,17 @@ func load(dbp zesty.DBProvider, publicID string, locked bool, lockNoWait bool) ( | |||||
return nil, err | ||||||
} | ||||||
|
||||||
compressedSteps, err := models.EncryptionKey.Decrypt(r.EncryptedSteps, []byte(r.PublicID)) | ||||||
dst := make([]byte, 0, hex.DecodedLen(len(r.EncryptedSteps))) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// if we can't hex Decode, we might be in the case of a Resolution row in database that was | ||||||
// created between the v1.21.1 and v1.21.3 that was bugged, and failed to hex Encode/Decode the | ||||||
// ciphered data. We need to keep backward compatibility for those, but this should not happen | ||||||
// often. | ||||||
// See https://github.com/ovh/utask/commit/bf23fbb10b62bb487ac4ea01b1e519f85480e58b and migration | ||||||
// from symmecrypt.Key.DecryptMarshal to symmecrypt.Key.Decrypt | ||||||
_, _ = hex.Decode(dst, r.EncryptedSteps) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably check returned |
||||||
|
||||||
compressedSteps, err := models.EncryptionKey.Decrypt(dst, []byte(r.PublicID)) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
@@ -377,6 +391,8 @@ func (r *Resolution) Update(dbp zesty.DBProvider) (err error) { | |||||
return err | ||||||
} | ||||||
|
||||||
dst := make([]byte, 0, hex.EncodedLen(len(compressedSteps))) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
hex.Encode(dst, compressedSteps) | ||||||
encryptedSteps, err := models.EncryptionKey.Encrypt(compressedSteps, []byte(r.PublicID)) | ||||||
if err != nil { | ||||||
return err | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the official documentation, it uses the size of the buffer: https://pkg.go.dev/encoding/hex#Encode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: (correcting myself) the functions uses the byte slice indexes, and not append, so the slice must be of the proper length, enough capacity with a 0 length won't work.