Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
465d68ee
Commit
465d68ee
authored
Sep 28, 2017
by
Sietse Ringers
Browse files
WIP on MetaStore singleton removal
parent
3512d652
Changes
5
Hide whitespace changes
Inline
Side-by-side
attributes.go
View file @
465d68ee
...
...
@@ -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
:=
MetaS
tore
.
Credentials
[
ai
.
CredentialTypeIdentifier
()]
creddescription
,
exists
:=
s
tore
.
Credentials
[
ai
.
CredentialTypeIdentifier
()]
if
!
exists
{
return
false
}
...
...
keyshare.go
View file @
465d68ee
...
...
@@ -136,7 +136,7 @@ func startKeyshareSession(
)
{
ksscount
:=
0
for
_
,
managerID
:=
range
session
.
SchemeManagers
()
{
if
MetaS
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
credManager
.
s
tore
.
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
!
MetaS
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
!
ks
.
credManager
.
s
tore
.
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
!
MetaS
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
!
ks
.
credManager
.
s
tore
.
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
!
MetaS
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
!
ks
.
credManager
.
s
tore
.
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
!
MetaS
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
!
ks
.
credManager
.
s
tore
.
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
!
MetaS
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
!
ks
.
credManager
.
s
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
continue
}
msg
:=
struct
{
...
...
manager.go
View file @
465d68ee
...
...
@@ -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
!
MetaS
tore
.
Contains
(
credID
)
{
if
!
cm
.
s
tore
.
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
:=
MetaS
tore
.
Credentials
[
identifier
.
CredentialTypeIdentifier
()]
.
IndexOf
(
identifier
)
index
,
err
:=
cm
.
s
tore
.
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
:=
MetaS
tore
.
PublicKey
(
futurecred
.
Credential
.
IssuerIdentifier
(),
futurecred
.
KeyCounter
)
pk
:=
cm
.
s
tore
.
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
MetaS
tore
.
SchemeManagers
{
for
name
,
manager
:=
range
cm
.
s
tore
.
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
:=
MetaS
tore
.
SchemeManagers
[
managerID
]
manager
,
ok
:=
cm
.
s
tore
.
SchemeManagers
[
managerID
]
if
!
ok
{
return
errors
.
New
(
"Unknown scheme manager"
)
}
...
...
storage.go
View file @
465d68ee
...
...
@@ -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
}
...
...
store.go
View file @
465d68ee
...
...
@@ -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
:=
MetaS
tore
.
PublicKeys
[
id
];
ok
{
if
list
,
ok
:=
s
tore
.
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
{
MetaS
tore
.
SchemeManagers
[
manager
.
Identifier
()]
=
manager
s
tore
.
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
()
MetaS
tore
.
PublicKeys
[
issuer
.
Identifier
()]
=
append
(
MetaS
tore
.
PublicKeys
[
issuer
.
Identifier
()],
pk
)
s
tore
.
PublicKeys
[
issuer
.
Identifier
()]
=
append
(
s
tore
.
PublicKeys
[
issuer
.
Identifier
()],
pk
)
}
return
nil
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment