diff options
Diffstat (limited to '')
-rw-r--r-- | cmd/verify.go | 29 | ||||
-rw-r--r-- | core/storage.go | 52 | ||||
-rw-r--r-- | fsverify-paper.md | 11 | ||||
-rw-r--r-- | my.db | bin | 32768 -> 32768 bytes | |||
-rw-r--r-- | part.fsverify | bin | 32967 -> 32968 bytes |
5 files changed, 65 insertions, 27 deletions
diff --git a/cmd/verify.go b/cmd/verify.go index dc7a700..2f18d34 100644 --- a/cmd/verify.go +++ b/cmd/verify.go @@ -21,10 +21,23 @@ func NewVerifyCommand() *cobra.Command { func ValidateCommand(_ *cobra.Command, args []string) error { + /* node := core.Node{ + BlockStart: 0, + BlockEnd: 4000, + BlockSum: "ba0064e29f79feddc3b7912c697a80c93ada98a916b19573ff41598c17177b92", + PrevNodeSum: "Entrypoint", + } + + err := core.AddNode(node, nil) + if err != nil { + return err + }*/ + header, err := core.ReadHeader("/dev/sda") fmt.Printf("Magic Number: %d\n", header.MagicNumber) - fmt.Printf("Signature: %s\n" + header.Signature) + fmt.Printf("Signature: %s", header.Signature) fmt.Printf("FsSize: %d\n", header.FilesystemSize) + fmt.Printf("FsUnit: %d\n", header.FilesystemUnit) fmt.Printf("Table Size: %d\n", header.TableSize) fmt.Printf("Table Size Unit: %d\n", header.TableUnit) if err != nil { @@ -40,7 +53,7 @@ func ValidateCommand(_ *cobra.Command, args []string) error { return err } - getnode, err := core.GetNode("aaaa", db) + getnode, err := core.GetNode("Entrypoint", db) if err != nil { return err } @@ -56,5 +69,15 @@ func ValidateCommand(_ *cobra.Command, args []string) error { } hash, err := core.CalculateBlockHash(part) fmt.Println(hash) - return err + if err != nil { + return err + } + + err = core.VerifyBlock(part, getnode) + if err != nil { + fmt.Println("fail") + return err + } + fmt.Printf("Block '%s' ranging from %d to %d matches!\n", getnode.PrevNodeSum, getnode.BlockStart, getnode.BlockEnd) + return nil } diff --git a/core/storage.go b/core/storage.go index 363db0f..f6f1ffd 100644 --- a/core/storage.go +++ b/core/storage.go @@ -15,6 +15,7 @@ type Header struct { MagicNumber int Signature string FilesystemSize int + FilesystemUnit int TableSize int TableUnit int } @@ -26,6 +27,25 @@ type Node struct { PrevNodeSum string } +func parseUnitSpec(size []byte) int { + switch size[0] { + case 0: + return 1 + case 1: + return 1000 + case 2: + return 1000000 + case 3: + return 1000000000 + case 4: + return 1000000000000 + case 5: + return 1000000000000000 + default: + return -1 + } +} + func ReadHeader(partition string) (Header, error) { _, exist := os.Stat(partition) if os.IsNotExist(exist) { @@ -42,7 +62,8 @@ func ReadHeader(partition string) (Header, error) { MagicNumber := make([]byte, 2) UntrustedHash := make([]byte, 100) TrustedHash := make([]byte, 88) - FileSystemSize := make([]byte, 4) + FilesystemSize := make([]byte, 4) + FilesystemUnit := make([]byte, 1) TableSize := make([]byte, 4) TableUnit := make([]byte, 1) @@ -61,7 +82,11 @@ func ReadHeader(partition string) (Header, error) { if err != nil { return Header{}, err } - _, err = reader.Read(FileSystemSize) + _, err = reader.Read(FilesystemSize) + if err != nil { + return Header{}, err + } + _, err = reader.Read(FilesystemUnit) if err != nil { return Header{}, err } @@ -75,23 +100,12 @@ func ReadHeader(partition string) (Header, error) { } header.Signature = fmt.Sprintf("untrusted comment: signature from minisign secret key\r\n%s\r\ntrusted comment: timestamp:0\tfile:fsverify\thashed\r\n%s\r\n", UntrustedHash, TrustedHash) - header.FilesystemSize = int(binary.BigEndian.Uint16(FileSystemSize)) + header.FilesystemSize = int(binary.BigEndian.Uint16(FilesystemSize)) header.TableSize = int(binary.BigEndian.Uint32(TableSize)) - switch TableUnit[0] { - case 0: - header.TableUnit = 1 - case 1: - header.TableUnit = 1000 - case 2: - header.TableUnit = 1000000 - case 3: - header.TableUnit = 1000000000 - case 4: - header.TableUnit = 1000000000000 - case 5: - header.TableUnit = 1000000000000000 - default: - return Header{}, fmt.Errorf("Unknown TableUnit %d", TableUnit) + header.FilesystemUnit = parseUnitSpec(FilesystemUnit) + header.TableUnit = parseUnitSpec(TableUnit) + if header.FilesystemUnit == -1 || header.TableUnit == -1 { + return Header{}, fmt.Errorf("Error: unit size for Filesystem or Table invalid: fs: %x, table: %x", FilesystemUnit, TableUnit) } return header, nil } @@ -108,7 +122,7 @@ func ReadDB(partition string) (string, error) { defer part.Close() reader := bufio.NewReader(part) - _, err = reader.Read(make([]byte, 199)) + _, err = reader.Read(make([]byte, 200)) if err != nil { fmt.Println(err) return "", err diff --git a/fsverify-paper.md b/fsverify-paper.md index 819c422..ba50847 100644 --- a/fsverify-paper.md +++ b/fsverify-paper.md @@ -2,20 +2,21 @@ The FsVerify partition contains a header with the necessary metadata for the filesystem verification, and a bbolt database containing all File and Directory nodes to be checked. ## Partition Header -`<magic number> <untrusted signature hash> <trusted signature hash> <filesystem size> <table size> <table unit>` +`<magic number> <untrusted signature hash> <trusted signature hash> <filesystem size> <filesystem unit> <table size> <table unit>` Field|Size|Purpose|Value -----|----|-------|----- magic number|2 bytes|sanity check|0xACAB untrusted signature hash|100 bytes|untrusted signature from minisign trusted signature hash|88 bytes|trusted signature from minisign -filesystem size|4 bytes|size of the original filesystem in gb +filesystem size|4 bytes|size of the original filesystem in <table unit\> +filesystem unit|1 byte|unit of the filesystem size|0x0: bytes, 0x1: kilobytes, 0x2: megabytes, 0x3: gigabytes, 0x4: terabytes, 0x5: petabytes table size|4 bytes| size of the table in <table unit\> table unit|1 byte|unit of the table size|0x0: bytes, 0x1: kilobytes, 0x2: megabytes, 0x3: gigabytes, 0x4: terabytes, 0x5: petabytes -Due to the filesystem and table size field, which can go up to 0xFFFFFFFF (16777215), the maximum supported partition size and table size is 16777215gb (~16pb) +Due to the filesystem and table size field, which can go up to 0xFFFFFFFF (16777215), the maximum supported partition size and table size is 16777215pb -The entire Head should be a total of 199 bytes long, reaching from 0x0 to 0xC7 +The entire Head should be a total of 200 bytes long, reaching from 0x0 to 0xC8 ## Partition Contents / Database The main database containing the checksums is a [bbolt](https://github.com/etcd-io/bbolt) datbase consisting of a single bucket called `Nodes` @@ -62,7 +63,7 @@ through this, the slightest change in one of the nodes will result in a wrong ha Modified value ``` -The first Node will have `PrevNodeSum` as "Entrypoint" as the PrevNodeSum field is also used to access each node, using EntryPoint allows fsverify to start the verification by always being able to read the first node +The first Node will have `PrevNodeSum` as "Entrypoint" since the PrevNodeSum field is also used to access each node, using EntryPoint allows fsverify to start the verification by always being able to read the first node # Verification Process Binary files differdiff --git a/part.fsverify b/part.fsverify Binary files differindex bd59960..cca63e4 100644 --- a/part.fsverify +++ b/part.fsverify |