Skip to content

Commit

Permalink
Remove tampering code
Browse files Browse the repository at this point in the history
  • Loading branch information
aalda committed Mar 26, 2019
1 parent ebd1127 commit 7bf60f6
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 222 deletions.
100 changes: 0 additions & 100 deletions api/tampering/tamper_api.go

This file was deleted.

32 changes: 1 addition & 31 deletions balloon/balloon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,38 +236,8 @@ func TestTamperAndVerify(t *testing.T) {
require.Error(t, err)
}

func TestDeleteAndVerify(t *testing.T) {
log.SetLogger("TestDeleteAndVerify", log.SILENT)

store, closeF := storage_utils.OpenRocksDBStore(t, "/var/tmp/balloon.test.3")
defer closeF()

b, err := NewBalloon(store, hashing.NewSha256Hasher)
assert.NoError(t, err)

event := hashing.Digest("Never knows best")
eventDigest := b.hasher.Do(event)

snapshot, mutations, err := b.Add(event)
store.Mutate(mutations)

memProof, err := b.QueryMembership(event, snapshot.Version)
assert.NoError(t, err)
assert.True(t, memProof.Verify(event, snapshot), "The proof should verify correctly")

err = store.Delete(storage.IndexPrefix, eventDigest)
assert.NoError(t, err, "store delete returned non nil value")

tampered, _ := store.Get(storage.IndexPrefix, eventDigest)
assert.Nil(t, tampered)

proof, err := b.QueryMembership(event, snapshot.Version)
assert.False(t, proof.Exists, "Member must not exist on qed after its deletion")
assert.NoErrorf(t, err, "Ballon must return a proof for a non-existen event: %v", err)
}

func TestGenIncrementalAndVerify(t *testing.T) {
log.SetLogger("TestDeleteAndVerify", log.SILENT)
log.SetLogger("TestGenIncrementalAndVerify", log.SILENT)

store, closeF := storage_utils.OpenRocksDBStore(t, "/var/tmp/balloon.test.3")
defer closeF()
Expand Down
5 changes: 0 additions & 5 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ func newStartCommand(ctx *cmdContext) *cobra.Command {
f.StringVar(&conf.GossipAddr, "gossip-addr", ":8400", "Gossip: management endpoint bind address (host:port)")
f.StringSliceVar(&conf.GossipJoinAddr, "gossip-join-addr", []string{}, "Gossip: Comma-delimited list of nodes ([host]:port), through which a cluster can be joined")

// INFO: testing purposes
// FIXME: return to false in the next milestone
f.BoolVar(&conf.EnableTampering, "tampering", true, "Allow tampering api for proof demostrations")
_ = f.MarkHidden("tampering")

// Lookups
v.BindPFlag("server.node-id", f.Lookup("node-id"))
v.BindPFlag("server.key", f.Lookup("keypath"))
Expand Down
4 changes: 0 additions & 4 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ type Config struct {
// Path to the private key file used to sign snapshots.
PrivateKeyPath string

// Enables tampering endpoint.
EnableTampering bool

// Enable TLS service
EnableTLS bool

Expand All @@ -91,7 +88,6 @@ func DefaultConfig() *Config {
GossipJoinAddr: []string{},
DBPath: currentDir + "/db",
RaftPath: currentDir + "/wal",
EnableTampering: false,
EnableTLS: false,
SSLCertificate: "",
SSLCertificateKey: "",
Expand Down
30 changes: 0 additions & 30 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ import (
"io/ioutil"
"net/http"
"os"
"strconv"

"github.com/prometheus/client_golang/prometheus"

"github.com/bbva/qed/api/apihttp"
"github.com/bbva/qed/api/mgmthttp"
"github.com/bbva/qed/api/tampering"
"github.com/bbva/qed/gossip"
"github.com/bbva/qed/gossip/member"
"github.com/bbva/qed/gossip/sender"
"github.com/bbva/qed/hashing"
"github.com/bbva/qed/log"
"github.com/bbva/qed/metrics"
"github.com/bbva/qed/protocol"
Expand All @@ -56,7 +53,6 @@ type Server struct {
httpServer *http.Server
mgmtServer *http.Server
raftBalloon *raftwal.RaftBalloon
tamperingServer *http.Server
metricsServer *metrics.Server
prometheusRegistry *prometheus.Registry
signer sign.Signer
Expand Down Expand Up @@ -173,13 +169,6 @@ func NewServer(conf *Config) (*Server, error) {
mgmtMux := mgmthttp.NewMgmtHttp(server.raftBalloon)
server.mgmtServer = newHTTPServer(conf.MgmtAddr, mgmtMux)

// Get id from the last number of any server Addr (HttpAddr in this case)
id, _ := strconv.Atoi(conf.HTTPAddr[len(conf.HTTPAddr)-1:])
if conf.EnableTampering {
tamperMux := tampering.NewTamperingAPI(store, hashing.NewSha256Hasher())
server.tamperingServer = newHTTPServer(fmt.Sprintf("localhost:1880%d", id), tamperMux)
}

return server, nil
}

Expand Down Expand Up @@ -221,16 +210,6 @@ func (s *Server) Start() error {
s.metricsServer.Start()
}()

if s.tamperingServer != nil {
log.Info(">>>>>>>>>>>>>>>>>>> Tampering is enabled! DO NOT RUN THIS IN PRODUCTION! <<<<<<<<<<<<<<<<<<<")
go func() {
log.Debug(" * Starting tampering HTTP server in addr: localhost:8081")
if err := s.tamperingServer.ListenAndServe(); err != http.ErrServerClosed {
log.Errorf("Can't start tampering HTTP server: %s", err)
}
}()
}

if s.conf.EnableTLS {
go func() {
log.Debug(" * Starting QED API HTTPS server in addr: ", s.conf.HTTPAddr)
Expand Down Expand Up @@ -292,15 +271,6 @@ func (s *Server) Stop() error {

log.Debugf("Done.\n")

if s.tamperingServer != nil {
log.Debugf("Tampering enabled: stopping server...")
if err := s.tamperingServer.Shutdown(context.Background()); err != nil { // TODO include timeout instead nil
log.Error(err)
return err
}
log.Debugf("Done.\n")
}

log.Debugf("Stopping MGMT server...")
if err := s.mgmtServer.Shutdown(context.Background()); err != nil { // TODO include timeout instead nil
log.Error(err)
Expand Down
7 changes: 0 additions & 7 deletions storage/badger/badger_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,6 @@ func (s BadgerStore) Close() error {
return s.db.Close()
}

func (s BadgerStore) Delete(prefix byte, key []byte) error {
return s.db.Update(func(txn *b.Txn) error {
k := append([]byte{prefix}, key...)
return txn.Delete(k)
})
}

// Borrowed from github.com/dgraph-io/badger/backup.go
func writeTo(entry *protos.KVPair, w io.Writer) error {
if err := binary.Write(w, binary.LittleEndian, uint64(entry.Size())); err != nil {
Expand Down
33 changes: 0 additions & 33 deletions storage/badger/badger_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,39 +121,6 @@ func TestGetRange(t *testing.T) {

}

func TestDelete(t *testing.T) {
store, closeF := openBadgerStore(t)
defer closeF()

prefix := byte(0x0)
tests := []struct {
testname string
key, value []byte
expectedError error
}{
{"Delete key", []byte("Key"), []byte("Value"), storage.ErrKeyNotFound},
}

for _, test := range tests {

// err := store.Mutate({prefix, test.key, test.value))
err := store.Mutate([]*storage.Mutation{
{prefix, test.key, test.value},
})
require.NoError(t, err, "Error mutating in test: %s", test.testname)

_, err = store.Get(prefix, test.key)
require.NoError(t, err, "Error getting key in test: %s", test.testname)

err = store.Delete(prefix, test.key)
require.NoError(t, err, "Error deleting in test: %s", test.testname)

_, err = store.Get(prefix, test.key)
require.Equalf(t, test.expectedError, err, "Error getting non-existent key in test: %s", test.testname)
}

}

func TestGetAll(t *testing.T) {

prefix := storage.HyperCachePrefix
Expand Down
5 changes: 0 additions & 5 deletions storage/rocks/rocksdb_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,6 @@ func (s RocksDBStore) Close() error {
return nil
}

func (s RocksDBStore) Delete(prefix byte, key []byte) error {
k := append([]byte{prefix}, key...)
return s.db.Delete(rocksdb.NewDefaultWriteOptions(), k)
}

// Take a snapshot of the store, and returns and id
// to be used in the back up process. The state of the
// snapshot is stored in the store instance.
Expand Down
5 changes: 0 additions & 5 deletions storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ type Store interface {
Close() error
}

type DeletableStore interface {
Store
Delete(prefix byte, key []byte) error
}

type ManagedStore interface {
Store
Backup(w io.Writer, until uint64) error
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func getSnapshot(version uint64) (*protocol.SignedSnapshot, error) {
return s, nil
}

func TestAgentsWithoutTampering(t *testing.T) {
func TestAgents(t *testing.T) {
bStore, aStore := setupStore(t)
bServer, aServer := setupServer(0, "", false, t)
bAuditor, aAuditor := setupAuditor(0, t)
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ func setupServer(id int, joinAddr string, tls bool, t *testing.T) (scope.TestF,
conf.SSLCertificate = fmt.Sprintf("%s/.ssh/server.crt", usr.HomeDir)
conf.SSLCertificateKey = fmt.Sprintf("%s/.ssh/server.key", usr.HomeDir)
}
conf.EnableTampering = true
conf.EnableTLS = tls

srv, err = server.NewServer(conf)
Expand Down

0 comments on commit 7bf60f6

Please sign in to comment.