Skip to content

Commit 2b3fe95

Browse files
committed
Initial commit
0 parents  commit 2b3fe95

39 files changed

Lines changed: 8645 additions & 0 deletions

.gitignore

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool
12+
*.out
13+
coverage.out
14+
coverage.html
15+
16+
# Dependency directories
17+
vendor/
18+
19+
# Go workspace file
20+
go.work
21+
22+
# IDE specific files
23+
.vscode/
24+
.idea/
25+
*.swp
26+
*.swo
27+
*~
28+
29+
# OS specific files
30+
.DS_Store
31+
Thumbs.db
32+
33+
# Build artifacts
34+
securelog
35+
bin/
36+
dist/
37+
38+
# Test data
39+
testdata/tmp*
40+
*.db
41+
*.dat
42+
*.idx
43+
44+
# Logs
45+
*.log
46+
revive.log
47+
48+
# Temporary files
49+
tmp/
50+
temp/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Nagy Károly Gábriel <k@jpi.io>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Makefile for SecureLog - Dual MAC Secure Logging System
2+
# https://github.com/karasz/securelog
3+
4+
.PHONY: all build test lint fmt vet revive clean install help spell
5+
6+
# Go parameters
7+
GOCMD=go
8+
GOBUILD=$(GOCMD) build
9+
GOTEST=$(GOCMD) test
10+
GOGET=$(GOCMD) get
11+
GOFMT=$(GOCMD) fmt
12+
GOVET=$(GOCMD) vet
13+
GOMOD=$(GOCMD) mod
14+
15+
# Binary name
16+
BINARY_NAME=securelog
17+
18+
# Build flags
19+
LDFLAGS=-ldflags "-s -w"
20+
21+
# Default target
22+
all: fmt vet lint test build
23+
24+
## help: Show this help message
25+
help:
26+
@echo 'Usage:'
27+
@echo ' make [target]'
28+
@echo ''
29+
@echo 'Targets:'
30+
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
31+
32+
## build: Build the project
33+
build:
34+
@echo "Building..."
35+
$(GOBUILD) $(LDFLAGS) -v ./...
36+
37+
## test: Run tests
38+
test:
39+
@echo "Running tests..."
40+
$(GOTEST) -v -race -coverprofile=coverage.out ./...
41+
@echo ""
42+
@echo "Coverage summary:"
43+
@$(GOCMD) tool cover -func=coverage.out | tail -1
44+
45+
## test-short: Run tests without race detector (faster)
46+
test-short:
47+
@echo "Running tests (short)..."
48+
$(GOTEST) -v ./...
49+
50+
## coverage: Run tests and show coverage report in browser
51+
coverage: test
52+
@echo "Opening coverage report in browser..."
53+
$(GOCMD) tool cover -html=coverage.out
54+
55+
## bench: Run benchmarks
56+
bench:
57+
@echo "Running benchmarks..."
58+
$(GOTEST) -bench=. -benchmem ./...
59+
60+
## fmt: Format Go code
61+
fmt:
62+
@echo "Formatting code..."
63+
@$(GOFMT) ./...
64+
@echo "Code formatted successfully"
65+
66+
## vet: Run go vet
67+
vet:
68+
@echo "Running go vet..."
69+
@$(GOVET) ./...
70+
@echo "go vet passed"
71+
72+
## lint: Run linters (revive + staticcheck)
73+
lint: revive staticcheck
74+
75+
## revive: Run revive linter
76+
revive:
77+
@echo "Running revive..."
78+
@if ! command -v revive > /dev/null 2>&1; then \
79+
if [ -f $(HOME)/go/bin/revive ]; then \
80+
$(HOME)/go/bin/revive -config revive.toml -formatter friendly -exclude proto/... ./...; \
81+
else \
82+
echo "Installing revive..." && $(GOGET) github.com/mgechev/revive@latest && $(HOME)/go/bin/revive -config revive.toml -formatter friendly -exclude proto/... ./...; \
83+
fi \
84+
else \
85+
revive -config revive.toml -formatter friendly -exclude proto/... ./...; \
86+
fi
87+
88+
## staticcheck: Run staticcheck
89+
staticcheck:
90+
@echo "Running staticcheck..."
91+
@if ! command -v staticcheck > /dev/null 2>&1; then \
92+
if [ -f $(HOME)/go/bin/staticcheck ]; then \
93+
$(HOME)/go/bin/staticcheck ./...; \
94+
else \
95+
echo "Installing staticcheck..." && $(GOGET) honnef.co/go/tools/cmd/staticcheck@latest && $(HOME)/go/bin/staticcheck ./...; \
96+
fi \
97+
else \
98+
staticcheck ./...; \
99+
fi
100+
101+
## spell: Run spell checker (cspell)
102+
spell:
103+
@echo "Running spell checker..."
104+
@if ! command -v cspell > /dev/null 2>&1; then \
105+
echo "cspell not found. Install with: npm install -g cspell"; \
106+
echo "Or use: npx cspell"; \
107+
exit 1; \
108+
fi
109+
@cspell --no-progress "**/*.{go,md,txt,toml,yml,yaml}" --exclude "vendor/**" --exclude "*.log"
110+
111+
## check: Run all checks (fmt, vet, lint, spell, test)
112+
check: fmt vet lint spell test
113+
@echo ""
114+
@echo "✓ All checks passed!"
115+
116+
## clean: Remove build artifacts and test files
117+
clean:
118+
@echo "Cleaning..."
119+
@rm -f $(BINARY_NAME)
120+
@rm -f coverage.out
121+
@rm -rf testdata/tmp*
122+
@$(GOCMD) clean -testcache
123+
@echo "Cleaned successfully"
124+
125+
## deps: Download dependencies
126+
deps:
127+
@echo "Downloading dependencies..."
128+
@$(GOMOD) download
129+
@$(GOMOD) tidy
130+
131+
## deps-update: Update dependencies
132+
deps-update:
133+
@echo "Updating dependencies..."
134+
@$(GOGET) -u ./...
135+
@$(GOMOD) tidy
136+
137+
## install-tools: Install development tools
138+
install-tools:
139+
@echo "Installing development tools..."
140+
@$(GOGET) github.com/mgechev/revive@latest
141+
@$(GOGET) honnef.co/go/tools/cmd/staticcheck@latest
142+
@$(GOGET) github.com/securego/gosec/v2/cmd/gosec@latest
143+
@echo ""
144+
@echo "Go tools installed successfully"
145+
@echo ""
146+
@echo "To install cspell (spell checker), run:"
147+
@echo " npm install -g cspell"
148+
@echo "Or use npx: npx cspell"
149+
150+
## verify: Verify dependencies and check for issues
151+
verify:
152+
@echo "Verifying dependencies..."
153+
@$(GOMOD) verify
154+
@echo "Dependencies verified"
155+
156+
## security: Run security checks with gosec
157+
security:
158+
@echo "Running security checks..."
159+
@if ! command -v gosec > /dev/null 2>&1; then \
160+
if [ -f $(HOME)/go/bin/gosec ]; then \
161+
$(HOME)/go/bin/gosec -quiet ./...; \
162+
else \
163+
echo "Installing gosec..." && $(GOGET) github.com/securego/gosec/v2/cmd/gosec@latest && $(HOME)/go/bin/gosec -quiet ./...; \
164+
fi \
165+
else \
166+
gosec -quiet ./...; \
167+
fi
168+
169+
## ci: Run CI pipeline (fmt, vet, lint, spell, test)
170+
ci: deps verify fmt vet lint spell test
171+
@echo ""
172+
@echo "✓ CI pipeline completed successfully!"
173+
174+
## doc: Generate and serve documentation
175+
doc:
176+
@echo "Starting documentation server at http://localhost:6060"
177+
@which godoc > /dev/null || (echo "Installing godoc..." && $(GOGET) golang.org/x/tools/cmd/godoc@latest)
178+
@godoc -http=:6060
179+
180+
.DEFAULT_GOAL := help

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# securelog — Dual MAC Private-Verifiable Secure Logger (Go)
2+
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/karasz/securelog.svg)](https://pkg.go.dev/github.com/karasz/securelog)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/karasz/securelog)](https://goreportcard.com/report/github.com/karasz/securelog)
5+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6+
7+
SecureLog is a production-focused implementation of the Dual MAC private-verifiable logging protocol. It keeps audit trails append-only, forward-secure, and verifiable by both semi-trusted auditors and a trusted authority. For the full academic background, see [doc/ACADEMICS.md](doc/ACADEMICS.md).
8+
9+
## Highlights
10+
- Dual MAC chains (`μ_V`, `μ_T`) to catch tampering by compromised verifiers.
11+
- Forward-secure key evolution with per-entry key rotation.
12+
- Pluggable transports (folder, HTTP, local) and storage backends (POSIX files, SQLite).
13+
- Pure Go, no CGO requirements in the default configuration.
14+
15+
## Quick Start
16+
17+
```go
18+
package main
19+
20+
import (
21+
"log"
22+
"time"
23+
24+
"github.com/karasz/securelog"
25+
)
26+
27+
func main() {
28+
store, _ := securelog.OpenFileStore("/var/log/securelog")
29+
logger, _ := securelog.New(securelog.Config{AnchorEvery: 100}, store)
30+
31+
commit, openMsg, _ := logger.InitProtocol("app-log-001")
32+
33+
// transmit commit/openMsg to the trusted server here
34+
_ = commit
35+
_ = openMsg
36+
37+
logger.Append([]byte("user login: alice"), time.Now())
38+
logger.Append([]byte("file access: /etc/passwd"), time.Now())
39+
40+
closeMsg, _ := logger.CloseProtocol("app-log-001")
41+
log.Printf("final tag: %x", closeMsg.FinalTagT)
42+
}
43+
```
44+
45+
For end-to-end examples (including transports) check the `example_*.go` files.
46+
47+
## Storage Backends
48+
- **File store (default)** — append-only binary format with POSIX locks; ideal for production.
49+
- **SQLite store** — ACID semantics and ad-hoc queries via SQLite (`modernc.org/sqlite`).
50+
51+
Both implement the same `Store` interface, so swapping backends is a one-line change.
52+
53+
## Transports
54+
- **Folder transport** for local/offline workflows.
55+
- **HTTP transport** for remote trusted servers.
56+
- **Local transport** for in-process testing.
57+
58+
Detailed diagrams and usage notes live in [doc/TRANSPORT.md](doc/TRANSPORT.md).
59+
60+
## Documentation
61+
- [doc/ACADEMICS.md](doc/ACADEMICS.md) — paper references and detailed research context.
62+
- [doc/TRANSPORT.md](doc/TRANSPORT.md) — transport layer protocol and folder layout.
63+
- `example_*.go` — runnable snippets that stitch storage, transports, and verifiers together.
64+
65+
## Development
66+
67+
```
68+
make fmt # gofmt on the tree
69+
make lint # revive + staticcheck + gosec
70+
make test # go test -race -cover ./...
71+
make check # run the full battery (fmt, vet, lint, spell, test)
72+
```
73+
74+
Go 1.21 or newer is recommended.

0 commit comments

Comments
 (0)