Add more checks befor decrypting data
This commit is contained in:
parent
26cd6c5372
commit
4ab3d51996
3 changed files with 21 additions and 2 deletions
|
@ -292,7 +292,8 @@ func (r *SFTP) filename(t Type, id ID) string {
|
|||
return filepath.Join(r.dir(t), id.String())
|
||||
}
|
||||
|
||||
// Get returns the content stored under the given ID.
|
||||
// Get returns the content stored under the given ID. If the data doesn't match
|
||||
// the requested ID, ErrWrongData is returned.
|
||||
func (r *SFTP) Get(t Type, id ID) ([]byte, error) {
|
||||
// try to open file
|
||||
file, err := r.c.Open(r.filename(t, id))
|
||||
|
@ -307,6 +308,11 @@ func (r *SFTP) Get(t Type, id ID) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// check id
|
||||
if !Hash(buf).Equal(id) {
|
||||
return nil, ErrWrongData
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue