Commit 38cd7a81 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

refactor: use new Configuration struct for keysharecore.NewKeyshareCore() parameters

parent 2e78462c
......@@ -31,16 +31,23 @@ type (
// sessions
trustedKeys map[irma.PublicKeyIdentifier]*gabikeys.PublicKey
}
Configuration struct {
AESKeyID uint32
AESKey AesKey
SignKeyID uint32
SignKey *rsa.PrivateKey
}
)
func NewKeyshareCore(aesKeyID uint32, aesKey AesKey, signKeyID uint32, signKey *rsa.PrivateKey) *Core {
func NewKeyshareCore(conf *Configuration) *Core {
c := &Core{
decryptionKeys: map[uint32]AesKey{},
commitmentData: map[uint64]*big.Int{},
trustedKeys: map[irma.PublicKeyIdentifier]*gabikeys.PublicKey{},
}
c.setAESEncryptionKey(aesKeyID, aesKey)
c.setSignKey(signKeyID, signKey)
c.setAESEncryptionKey(conf.AESKeyID, conf.AESKey)
c.setSignKey(conf.SignKeyID, conf.SignKey)
return c
}
......
......@@ -24,7 +24,7 @@ func TestPinFunctionality(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 1, jwtTestKey)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key, SignKeyID: 1, SignKey: jwtTestKey})
// generate test pin
var bpin [64]byte
......@@ -62,7 +62,7 @@ func TestVerifyAccess(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 1, jwtTestKey)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key, SignKeyID: 1, SignKey: jwtTestKey})
// Generate test pins
var bpin [64]byte
......@@ -161,7 +161,7 @@ func TestProofFunctionality(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 1, jwtTestKey)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key, SignKeyID: 1, SignKey: jwtTestKey})
c.DangerousAddTrustedPublicKey(irma.PublicKeyIdentifier{Issuer: irma.NewIssuerIdentifier("test"), Counter: 1}, testPubK1)
// generate test pin
......@@ -211,7 +211,7 @@ func TestCorruptedPacket(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 1, jwtTestKey)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key, SignKeyID: 1, SignKey: jwtTestKey})
c.DangerousAddTrustedPublicKey(irma.PublicKeyIdentifier{Issuer: irma.NewIssuerIdentifier("test"), Counter: 1}, testPubK1)
// Test parameters
......@@ -255,7 +255,7 @@ func TestIncorrectPin(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 1, jwtTestKey)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key, SignKeyID: 1, SignKey: jwtTestKey})
c.DangerousAddTrustedPublicKey(irma.PublicKeyIdentifier{Issuer: irma.NewIssuerIdentifier("test"), Counter: 1}, testPubK1)
// Test parameters
......@@ -292,7 +292,7 @@ func TestMissingKey(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 1, jwtTestKey)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key, SignKeyID: 1, SignKey: jwtTestKey})
c.DangerousAddTrustedPublicKey(irma.PublicKeyIdentifier{Issuer: irma.NewIssuerIdentifier("test"), Counter: 1}, testPubK1)
// Test parameters
......@@ -325,7 +325,7 @@ func TestInvalidChallenge(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 1, jwtTestKey)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key, SignKeyID: 1, SignKey: jwtTestKey})
c.DangerousAddTrustedPublicKey(irma.PublicKeyIdentifier{Issuer: irma.NewIssuerIdentifier("test"), Counter: 1}, testPubK1)
// Test parameters
......@@ -366,7 +366,7 @@ func TestDoubleCommitUse(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 1, jwtTestKey)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key, SignKeyID: 1, SignKey: jwtTestKey})
c.DangerousAddTrustedPublicKey(irma.PublicKeyIdentifier{Issuer: irma.NewIssuerIdentifier("test"), Counter: 1}, testPubK1)
// Test parameters
......@@ -397,7 +397,7 @@ func TestNonExistingCommit(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 1, jwtTestKey)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key, SignKeyID: 1, SignKey: jwtTestKey})
c.DangerousAddTrustedPublicKey(irma.PublicKeyIdentifier{Issuer: irma.NewIssuerIdentifier("test"), Counter: 1}, testPubK1)
// Test parameters
......
......@@ -28,7 +28,7 @@ func TestPacketEncryptDecrypt(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 0, nil)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key})
// Test parameters
var testSecret = big.NewInt(5)
......@@ -56,7 +56,7 @@ func TestPacketAuthentication(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 0, nil)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key})
// Test parameters
var testSecret = big.NewInt(5)
......@@ -84,7 +84,7 @@ func TestMultiKey(t *testing.T) {
var key AesKey
_, err := rand.Read(key[:])
require.NoError(t, err)
c := NewKeyshareCore(1, key, 0, nil)
c := NewKeyshareCore(&Configuration{AESKeyID: 1, AESKey: key})
_, err = rand.Read(key[:])
require.NoError(t, err)
c.DangerousAddAESKey(2, key)
......
......@@ -141,7 +141,12 @@ func processConfiguration(conf *Configuration) (*keysharecore.Core, error) {
return nil, server.LogError(errors.WrapPrefix(err, "failed to load primary storage key", 0))
}
core := keysharecore.NewKeyshareCore(encID, encKey, conf.JwtKeyID, jwtPrivateKey)
core := keysharecore.NewKeyshareCore(&keysharecore.Configuration{
AESKeyID: encID,
AESKey: encKey,
SignKeyID: conf.JwtKeyID,
SignKey: jwtPrivateKey,
})
for _, keyFile := range conf.StorageFallbackKeyFiles {
id, key, err := readAESKey(keyFile)
if err != nil {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment