Commit 465d68ee authored by Sietse Ringers's avatar Sietse Ringers
Browse files

WIP on MetaStore singleton removal

parent 3512d652
......@@ -37,8 +37,9 @@ type metadataField struct {
// MetadataAttribute represent a metadata attribute. Contains the credential type, signing date, validity, and the public key counter.
type MetadataAttribute struct {
Int *big.Int
pk *gabi.PublicKey
Int *big.Int
pk *gabi.PublicKey
store *ConfigurationStore
}
// AttributeList contains attributes, excluding the secret key,
......@@ -68,8 +69,8 @@ func (al *AttributeList) UnmarshalJSON(bytes []byte) error {
}
// NewAttributeListFromInts initializes a new AttributeList from a list of bigints.
func NewAttributeListFromInts(ints []*big.Int) (*AttributeList, error) {
meta := MetadataFromInt(ints[0])
func NewAttributeListFromInts(ints []*big.Int, store *ConfigurationStore) (*AttributeList, error) {
meta := MetadataFromInt(ints[0], store)
if ints[0] == nil || meta.CredentialType() == nil {
return nil, errors.New("Encountered credential of unknown type")
}
......@@ -112,8 +113,8 @@ func (al *AttributeList) Attribute(identifier AttributeTypeIdentifier) string {
}
// MetadataFromInt wraps the given Int
func MetadataFromInt(i *big.Int) *MetadataAttribute {
return &MetadataAttribute{Int: i}
func MetadataFromInt(i *big.Int, store *ConfigurationStore) *MetadataAttribute {
return &MetadataAttribute{Int: i, store: store}
}
// NewMetadataAttribute constructs a new instance containing the default values:
......@@ -122,7 +123,7 @@ func MetadataFromInt(i *big.Int) *MetadataAttribute {
// 0 as keycounter
// ValidityDefault (half a year) as default validity.
func NewMetadataAttribute() *MetadataAttribute {
val := MetadataAttribute{new(big.Int), nil}
val := MetadataAttribute{new(big.Int), nil, nil}
val.setField(versionField, metadataVersion)
val.setSigningDate()
val.setKeyCounter(0)
......@@ -295,9 +296,9 @@ func (disjunction *AttributeDisjunction) Satisfied() bool {
// MatchesStore returns true if all attributes contained in the disjunction are
// present in the MetaStore.
func (disjunction *AttributeDisjunction) MatchesStore() bool {
func (disjunction *AttributeDisjunction) MatchesStore(store *ConfigurationStore) bool {
for ai := range disjunction.Values {
creddescription, exists := MetaStore.Credentials[ai.CredentialTypeIdentifier()]
creddescription, exists := store.Credentials[ai.CredentialTypeIdentifier()]
if !exists {
return false
}
......
......@@ -136,7 +136,7 @@ func startKeyshareSession(
) {
ksscount := 0
for _, managerID := range session.SchemeManagers() {
if MetaStore.SchemeManagers[managerID].Distributed() {
if credManager.store.SchemeManagers[managerID].Distributed() {
ksscount++
if _, registered := credManager.keyshareServers[managerID]; !registered {
err := errors.New("Not registered to keyshare server of scheme manager " + managerID.String())
......@@ -163,7 +163,7 @@ func startKeyshareSession(
askPin := false
for _, managerID := range session.SchemeManagers() {
if !MetaStore.SchemeManagers[managerID].Distributed() {
if !ks.credManager.store.SchemeManagers[managerID].Distributed() {
continue
}
......@@ -231,7 +231,7 @@ func (ks *keyshareSession) VerifyPin(attempts int) {
// If all is ok, success will be true.
func (ks *keyshareSession) verifyPinAttempt(pin string) (success bool, tries int, blocked int, err error) {
for _, managerID := range ks.session.SchemeManagers() {
if !MetaStore.SchemeManagers[managerID].Distributed() {
if !ks.credManager.store.SchemeManagers[managerID].Distributed() {
continue
}
......@@ -282,7 +282,7 @@ func (ks *keyshareSession) GetCommitments() {
for _, builder := range ks.builders {
pk := builder.PublicKey()
managerID := NewIssuerIdentifier(pk.Issuer).SchemeManagerIdentifier()
if !MetaStore.SchemeManagers[managerID].Distributed() {
if !ks.credManager.store.SchemeManagers[managerID].Distributed() {
continue
}
if _, contains := pkids[managerID]; !contains {
......@@ -294,7 +294,7 @@ func (ks *keyshareSession) GetCommitments() {
// Now inform each keyshare server of with respect to which public keys
// we want them to send us commitments
for _, managerID := range ks.session.SchemeManagers() {
if !MetaStore.SchemeManagers[managerID].Distributed() {
if !ks.credManager.store.SchemeManagers[managerID].Distributed() {
continue
}
......@@ -398,7 +398,7 @@ func (ks *keyshareSession) finishDisclosureOrSigning(challenge *big.Int, respons
for i, builder := range ks.builders {
// Parse each received JWT
managerID := NewIssuerIdentifier(builder.PublicKey().Issuer).SchemeManagerIdentifier()
if !MetaStore.SchemeManagers[managerID].Distributed() {
if !ks.credManager.store.SchemeManagers[managerID].Distributed() {
continue
}
msg := struct {
......
......@@ -14,13 +14,14 @@ import (
// CredentialManager manages credentials.
type CredentialManager struct {
secretkey *big.Int
storagePath string
attributes map[CredentialTypeIdentifier][]*AttributeList
credentials map[CredentialTypeIdentifier]map[int]*credential
keyshareServers map[SchemeManagerIdentifier]*keyshareServer
secretkey *big.Int
storagePath string
attributes map[CredentialTypeIdentifier][]*AttributeList
credentials map[CredentialTypeIdentifier]map[int]*credential
keyshareServers map[SchemeManagerIdentifier]*keyshareServer
paillierKeyCache *paillierPrivateKey
store *ConfigurationStore
}
// CredentialList returns a list of information of all contained credentials.
......@@ -141,7 +142,7 @@ func (cm *CredentialManager) Candidates(disjunction *AttributeDisjunction) []*At
for _, attribute := range disjunction.Attributes {
credID := attribute.CredentialTypeIdentifier()
if !MetaStore.Contains(credID) {
if !cm.store.Contains(credID) {
continue
}
creds := cm.credentials[credID]
......@@ -202,7 +203,7 @@ func (cm *CredentialManager) groupCredentials(choice *DisclosureChoice) (map[Cre
if identifier.IsCredential() {
continue // In this case we only disclose the metadata attribute, which is already handled
}
index, err := MetaStore.Credentials[identifier.CredentialTypeIdentifier()].IndexOf(identifier)
index, err := cm.store.Credentials[identifier.CredentialTypeIdentifier()].IndexOf(identifier)
if err != nil {
return nil, err
}
......@@ -266,7 +267,7 @@ func (cm *CredentialManager) IssuanceProofBuilders(request *IssuanceRequest) (ga
proofBuilders := gabi.ProofBuilderList([]gabi.ProofBuilder{})
for _, futurecred := range request.Credentials {
pk := MetaStore.PublicKey(futurecred.Credential.IssuerIdentifier(), futurecred.KeyCounter)
pk := cm.store.PublicKey(futurecred.Credential.IssuerIdentifier(), futurecred.KeyCounter)
credBuilder := gabi.NewCredentialBuilder(pk, request.GetContext(), cm.secretkey, state.nonce2)
request.state.builders = append(request.state.builders, credBuilder)
proofBuilders = append(proofBuilders, credBuilder)
......@@ -341,7 +342,7 @@ func (cm *CredentialManager) paillierKey(wait bool) *paillierPrivateKey {
func (cm *CredentialManager) unenrolledKeyshareServers() []*SchemeManager {
list := []*SchemeManager{}
for name, manager := range MetaStore.SchemeManagers {
for name, manager := range cm.store.SchemeManagers {
if _, contains := cm.keyshareServers[name]; len(manager.KeyshareServer) > 0 && !contains {
list = append(list, manager)
}
......@@ -351,7 +352,7 @@ func (cm *CredentialManager) unenrolledKeyshareServers() []*SchemeManager {
// KeyshareEnroll attempts to register at the keyshare server of the specified scheme manager.
func (cm *CredentialManager) KeyshareEnroll(managerID SchemeManagerIdentifier, email, pin string) error {
manager, ok := MetaStore.SchemeManagers[managerID]
manager, ok := cm.store.SchemeManagers[managerID]
if !ok {
return errors.New("Unknown scheme manager")
}
......
......@@ -51,7 +51,8 @@ func NewCredentialManager(
keyshareServers: make(map[SchemeManagerIdentifier]*keyshareServer),
}
if err = MetaStore.ParseFolder(irmaConfigurationPath); err != nil {
cm.store = newConfigurationStore()
if err = cm.store.ParseFolder(irmaConfigurationPath); err != nil {
return nil, err
}
......
......@@ -40,7 +40,7 @@ func newConfigurationStore() (store *ConfigurationStore) {
// PublicKey returns the specified public key, or nil if not present in the ConfigurationStore.
func (store *ConfigurationStore) PublicKey(id IssuerIdentifier, counter int) *gabi.PublicKey {
if list, ok := MetaStore.PublicKeys[id]; ok {
if list, ok := store.PublicKeys[id]; ok {
if len(list) > counter {
return list[counter]
}
......@@ -75,7 +75,7 @@ func (store *ConfigurationStore) ParseFolder(path string) error {
return err
}
if exists {
MetaStore.SchemeManagers[manager.Identifier()] = manager
store.SchemeManagers[manager.Identifier()] = manager
return store.parseIssuerFolders(dir)
}
return nil
......@@ -116,7 +116,7 @@ func (store *ConfigurationStore) parseKeysFolder(issuer *Issuer, path string) er
return err
}
pk.Issuer = issuer.Identifier().String()
MetaStore.PublicKeys[issuer.Identifier()] = append(MetaStore.PublicKeys[issuer.Identifier()], pk)
store.PublicKeys[issuer.Identifier()] = append(store.PublicKeys[issuer.Identifier()], pk)
}
return 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