Repository: scionproto/scion
Pull request #3630 (2020-01-21 16:25:35)

keyconf: Remove unused code


<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/scionproto/scion/3630)
<!-- Reviewable:end -->



Patch:
diff --git a/go/lib/keyconf/BUILD.bazel b/go/lib/keyconf/BUILD.bazel
index c535ab187..05eaccb76 100644
--- a/go/lib/keyconf/BUILD.bazel
+++ b/go/lib/keyconf/BUILD.bazel
@@ -32,11 +32,9 @@ go_test(
     embed = [":go_default_library"],
     deps = [
         "//go/lib/addr:go_default_library",
-        "//go/lib/common:go_default_library",
         "//go/lib/scrypto:go_default_library",
         "//go/lib/util:go_default_library",
         "//go/lib/xtest:go_default_library",
-        "@com_github_smartystreets_goconvey//convey:go_default_library",
         "@com_github_stretchr_testify//assert:go_default_library",
         "@com_github_stretchr_testify//require:go_default_library",
         "@org_golang_x_crypto//ed25519:go_default_library",
diff --git a/go/lib/keyconf/keyconf.go b/go/lib/keyconf/keyconf.go
index c6f50d59a..7dd065bf7 100644
--- a/go/lib/keyconf/keyconf.go
+++ b/go/lib/keyconf/keyconf.go
@@ -27,29 +27,9 @@ import (
 	"github.com/scionproto/scion/go/lib/scrypto"
 )
 
-type Conf struct {
-	// IssSigKey is the AS issuer signing Key.
-	IssSigKey common.RawBytes
-	// DecryptKey is the AS decryption key.
-	DecryptKey common.RawBytes
-	// OffRootKey is the AS offline root key.
-	OffRootKey common.RawBytes
-	// OnRootKey is the AS online root key.
-	OnRootKey common.RawBytes
-	// SignKey is the AS signing key.
-	SignKey common.RawBytes
-	// Master contains the AS master keys.
-	Master Master
-}
-
 const (
-	IssSigKeyFile = "core-sig.seed" // TODO(roosd): rename "core-sig.key" -> "iss-sig.key"
-	DecKeyFile    = "as-decrypt.key"
-	OffKeyFile    = "offline-root.seed"
-	OnKeyFile     = "online-root.seed"
-	SigKeyFile    = "as-sig.seed"
-	MasterKey0    = "master0.key"
-	MasterKey1    = "master1.key"
+	MasterKey0 = "master0.key"
+	MasterKey1 = "master1.key"
 
 	// FIXME(roosd): removed unused keys above.
 
@@ -74,55 +54,8 @@ const (
 	ErrUnknown common.ErrMsg = "Unknown algorithm"
 )
 
-// Load loads key configuration from specified path.
-// issSigKey, onKey, offKey, master can be set true, to load the respective keys.
-func Load(path string, issSigKey, onKey, offKey, master bool) (*Conf, error) {
-	conf := &Conf{}
-	var err error
-	conf.DecryptKey, err = loadKeyCond(filepath.Join(path, DecKeyFile),
-		scrypto.Curve25519xSalsa20Poly1305, true)
-	if err != nil {
-		return nil, err
-	}
-	conf.SignKey, err = loadKeyCond(filepath.Join(path, SigKeyFile), scrypto.Ed25519, true)
-	if err != nil {
-		return nil, err
-	}
-	conf.IssSigKey, err = loadKeyCond(filepath.Join(path, IssSigKeyFile),
-		scrypto.Ed25519, issSigKey)
-	if err != nil {
-		return nil, err
-	}
-	conf.OffRootKey, err = loadKeyCond(filepath.Join(path, OffKeyFile), scrypto.Ed25519, offKey)
-	if err != nil {
-		return nil, err
-	}
-	conf.OnRootKey, err = loadKeyCond(filepath.Join(path, OnKeyFile), scrypto.Ed25519, onKey)
-	if err != nil {
-		return nil, err
-	}
-	if conf.Master, err = loadMasterCond(path, master); err != nil {
-		return nil, err
-	}
-	return conf, nil
-}
-
-func loadKeyCond(file string, algo string, load bool) (common.RawBytes, error) {
-	if !load {
-		return nil, nil
-	}
-	return LoadKey(file, algo)
-}
-
-func loadMasterCond(path string, load bool) (Master, error) {
-	if !load {
-		return Master{}, nil
-	}
-	return LoadMaster(path)
-}
-
 // LoadKey decodes a base64 encoded key stored in file and returns the raw bytes.
-func LoadKey(file string, algo string) (common.RawBytes, error) {
+func loadKey(file string, algo string) (common.RawBytes, error) {
 	b, err := ioutil.ReadFile(file)
 	if err != nil {
 		return nil, common.NewBasicError(ErrOpen, err)
@@ -143,26 +76,18 @@ func LoadKey(file string, algo string) (common.RawBytes, error) {
 	}
 }
 
-func (c *Conf) String() string {
-	return fmt.Sprintf("DecryptKey:%s SigningKey:%s IssSigningKey: %s "+
-		"OfflineRootKey:%s OnlineRootKey:%s Master:%s",
-		//XXX(shitz): Uncomment for debugging.
-		//c.DecryptKey, c.SignKey, c.IssSigKey, c.OffRootKey, c.OnRootKey, c.Master)
-		"<redacted>", "<redacted>", "<redacted>", "<redacted>", "<redacted>", "<redacted>")
-}
-
 type Master struct {
-	Key0 common.RawBytes
-	Key1 common.RawBytes
+	Key0 []byte
+	Key1 []byte
 }
 
 func LoadMaster(path string) (Master, error) {
 	var err error
 	m := Master{}
-	if m.Key0, err = LoadKey(filepath.Join(path, MasterKey0), RawKey); err != nil {
+	if m.Key0, err = loadKey(filepath.Join(path, MasterKey0), RawKey); err != nil {
 		return m, err
 	}
-	if m.Key1, err = LoadKey(filepath.Join(path, MasterKey1), RawKey); err != nil {
+	if m.Key1, err = loadKey(filepath.Join(path, MasterKey1), RawKey); err != nil {
 		return m, err
 	}
 	return m, nil


Test patch:
diff --git a/go/lib/keyconf/keyconf_test.go b/go/lib/keyconf/keyconf_test.go
index 1731c21e7..6e793a72b 100644
--- a/go/lib/keyconf/keyconf_test.go
+++ b/go/lib/keyconf/keyconf_test.go
@@ -18,64 +18,18 @@ import (
 	"encoding/base64"
 	"testing"
 
-	. "github.com/smartystreets/goconvey/convey"
-	"golang.org/x/crypto/ed25519"
-
-	"github.com/scionproto/scion/go/lib/common"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 )
 
 var (
 	mstr0, _ = base64.StdEncoding.DecodeString("rJMIe7UcHTQxm9l13TuI3A==")
 	mstr1, _ = base64.StdEncoding.DecodeString("WIn/OaISXyOCLehKNHcMKg==")
-
-	asSigSeed, _   = base64.StdEncoding.DecodeString("6N/rjhlQjzpSeem1v2J9jmfbc8hOzlzU3M/CebbnYL8=")
-	issSigSeed, _  = base64.StdEncoding.DecodeString("sp1uEH8wiMRkZR152ptC9mRCzIwIw00ASWKjD0TD21o=")
-	onlineSeed, _  = base64.StdEncoding.DecodeString("dh8V4fyRp2TcEZ5qnGBF/HvYJvkPZx5kcAH9BWQJmq0=")
-	offlineSeed, _ = base64.StdEncoding.DecodeString("ESJaansU6zVF1bqYwNPY9OOt8NaU7QYWIMjV1x+lAdQ=")
-
-	asSig   = common.RawBytes(ed25519.NewKeyFromSeed(asSigSeed))
-	issSig  = common.RawBytes(ed25519.NewKeyFromSeed(issSigSeed))
-	online  = common.RawBytes(ed25519.NewKeyFromSeed(onlineSeed))
-	offline = common.RawBytes(ed25519.NewKeyFromSeed(offlineSeed))
-
-	decrypt, _ = base64.StdEncoding.DecodeString("fYUmQn48f0cBUUwcOpmpeZlviHXVF68XWWEMGeZvw6Y=")
 )
 
-func Test_Load(t *testing.T) {
-	Convey("Load keyconf", t, func() {
-
-		checkConf := func(c *Conf, err error, asSig, decrypt, mstr0, mstr1, issSig, online,
-			offline common.RawBytes) {
-
-			SoMsg("err", err, ShouldBeNil)
-			SoMsg("mstr0", c.Master.Key0, ShouldResemble, mstr0)
-			SoMsg("mstr1", c.Master.Key1, ShouldResemble, mstr1)
-			SoMsg("decrypt", c.DecryptKey, ShouldResemble, decrypt)
-			SoMsg("asSig", c.SignKey, ShouldResemble, asSig)
-			SoMsg("issSig", c.IssSigKey, ShouldResemble, issSig)
-			SoMsg("online", c.OnRootKey, ShouldResemble, online)
-			SoMsg("offline", c.OffRootKey, ShouldResemble, offline)
-		}
-
-		Convey("Load all", func() {
-			c, err := Load("testdata", true, true, true, true)
-			checkConf(c, err, asSig, decrypt, mstr0, mstr1, issSig, online, offline)
-		})
-		Convey("Load master keys", func() {
-			c, err := Load("testdata", false, false, false, true)
-			checkConf(c, err, asSig, decrypt, mstr0, mstr1, nil, nil, nil)
-		})
-		Convey("Load issuer signing key", func() {
-			c, err := Load("testdata", true, false, false, false)
-			checkConf(c, err, asSig, decrypt, nil, nil, issSig, nil, nil)
-		})
-		Convey("Load online root key", func() {
-			c, err := Load("testdata", false, true, false, false)
-			checkConf(c, err, asSig, decrypt, nil, nil, nil, online, nil)
-		})
-		Convey("Load offline root key", func() {
-			c, err := Load("testdata", false, false, true, false)
-			checkConf(c, err, asSig, decrypt, nil, nil, nil, nil, offline)
-		})
-	})
+func TestLoadMaster(t *testing.T) {
+	m, err := LoadMaster("testdata")
+	require.NoError(t, err)
+	assert.Equal(t, mstr0, m.Key0)
+	assert.Equal(t, mstr1, m.Key1)
 }
diff --git a/go/lib/keyconf/testdata/as-decrypt.key b/go/lib/keyconf/testdata/as-decrypt.key
deleted file mode 100644
index 7c17259ef..000000000
--- a/go/lib/keyconf/testdata/as-decrypt.key
+++ /dev/null
@@ -1,1 +0,0 @@
-fYUmQn48f0cBUUwcOpmpeZlviHXVF68XWWEMGeZvw6Y=
diff --git a/go/lib/keyconf/testdata/as-sig.seed b/go/lib/keyconf/testdata/as-sig.seed
deleted file mode 100644
index b49af16a6..000000000
--- a/go/lib/keyconf/testdata/as-sig.seed
+++ /dev/null
@@ -1,1 +0,0 @@
-6N/rjhlQjzpSeem1v2J9jmfbc8hOzlzU3M/CebbnYL8=
diff --git a/go/lib/keyconf/testdata/core-sig.seed b/go/lib/keyconf/testdata/core-sig.seed
deleted file mode 100644
index a7c12a63a..000000000
--- a/go/lib/keyconf/testdata/core-sig.seed
+++ /dev/null
@@ -1,1 +0,0 @@
-sp1uEH8wiMRkZR152ptC9mRCzIwIw00ASWKjD0TD21o=
diff --git a/go/lib/keyconf/testdata/offline-root.seed b/go/lib/keyconf/testdata/offline-root.seed
deleted file mode 100644
index 68e492f94..000000000
--- a/go/lib/keyconf/testdata/offline-root.seed
+++ /dev/null
@@ -1,1 +0,0 @@
-ESJaansU6zVF1bqYwNPY9OOt8NaU7QYWIMjV1x+lAdQ=
diff --git a/go/lib/keyconf/testdata/online-root.seed b/go/lib/keyconf/testdata/online-root.seed
deleted file mode 100644
index 9207e2316..000000000
--- a/go/lib/keyconf/testdata/online-root.seed
+++ /dev/null
@@ -1,1 +0,0 @@
-dh8V4fyRp2TcEZ5qnGBF/HvYJvkPZx5kcAH9BWQJmq0=