fix(backup): checksum is base64-of-SHA256 to match cms restore verification
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
62b245d24f
commit
e12160f05c
@ -4,7 +4,7 @@ import (
|
|||||||
"archive/zip"
|
"archive/zip"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -100,8 +100,7 @@ func BuildArchive(ctx context.Context, w io.Writer, in BuildInput) (*Manifest, [
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Checksum of the unencrypted dump.
|
// Checksum of the unencrypted dump.
|
||||||
sum := sha256.Sum256(in.Dump)
|
checksum := computeChecksum(in.Dump)
|
||||||
checksum := hex.EncodeToString(sum[:])
|
|
||||||
|
|
||||||
// Encrypt the dump.
|
// Encrypt the dump.
|
||||||
encryptedDump, encParams, err := EncryptWithPassword(in.Dump, in.Password)
|
encryptedDump, encParams, err := EncryptWithPassword(in.Dump, in.Password)
|
||||||
@ -222,3 +221,11 @@ func BuildArchive(ctx context.Context, w io.Writer, in BuildInput) (*Manifest, [
|
|||||||
func closeBestEffort(c io.Closer) {
|
func closeBestEffort(c io.Closer) {
|
||||||
_ = c.Close()
|
_ = c.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// computeChecksum calculates the SHA-256 hash of data, base64-encoded —
|
||||||
|
// byte-identical to the cms computeChecksum so the existing cms restore path
|
||||||
|
// (verifyChecksum) accepts archives built by this package.
|
||||||
|
func computeChecksum(data []byte) string {
|
||||||
|
hash := sha256.Sum256(data)
|
||||||
|
return base64.StdEncoding.EncodeToString(hash[:])
|
||||||
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/base64"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -70,7 +70,7 @@ func TestBuildArchiveRoundTrip(t *testing.T) {
|
|||||||
t.Fatalf("counts: media=%d brand=%d", manifest.MediaCount, manifest.BrandCount)
|
t.Fatalf("counts: media=%d brand=%d", manifest.MediaCount, manifest.BrandCount)
|
||||||
}
|
}
|
||||||
wantSum := sha256.Sum256(dump)
|
wantSum := sha256.Sum256(dump)
|
||||||
if manifest.Checksum != hex.EncodeToString(wantSum[:]) {
|
if manifest.Checksum != base64.StdEncoding.EncodeToString(wantSum[:]) {
|
||||||
t.Fatalf("checksum mismatch")
|
t.Fatalf("checksum mismatch")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user