Skip to content

Commit

Permalink
Add check for content hash in repair flow
Browse files Browse the repository at this point in the history
  • Loading branch information
KrishnaDeqode committed Jun 17, 2020
1 parent e126bd7 commit 7cbb7c0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions zboxcore/sdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package sdk

import (
"context"
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math/bits"
"os"
"path/filepath"
Expand Down Expand Up @@ -293,6 +296,15 @@ func (a *Allocation) uploadOrUpdateFile(localpath string, remotepath string, sta
if !repairRequired {
return fmt.Errorf("Repair not required")
}

file, _ := ioutil.ReadFile(localpath)
hash := sha1.New()
hash.Write(file)
contentHash := hex.EncodeToString(hash.Sum(nil))
if contentHash != fileRef.ActualFileHash {
return fmt.Errorf("Content hash doesn't match")
}

uploadReq.filemeta.Hash = fileRef.ActualFileHash
uploadReq.uploadMask = (^found & uploadReq.uploadMask)
uploadReq.fullconsensus = float32(bits.TrailingZeros32(uploadReq.uploadMask + 1))
Expand Down

0 comments on commit 7cbb7c0

Please sign in to comment.