Skip to content
GitLab
Menu
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
78d2cd8a
Commit
78d2cd8a
authored
Sep 29, 2017
by
Sietse Ringers
Browse files
Finish removal of Manager and MetaStore singletons
parent
eec210bf
Changes
10
Hide whitespace changes
Inline
Side-by-side
attributes.go
View file @
78d2cd8a
...
@@ -60,30 +60,22 @@ func (al *AttributeList) UnmarshalJSON(bytes []byte) error {
...
@@ -60,30 +60,22 @@ func (al *AttributeList) UnmarshalJSON(bytes []byte) error {
if
err
:=
json
.
Unmarshal
(
bytes
,
&
ints
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
bytes
,
&
ints
);
err
!=
nil
{
return
err
return
err
}
}
list
,
err
:=
NewAttributeListFromInts
(
ints
)
list
:=
NewAttributeListFromInts
(
ints
,
nil
)
if
err
!=
nil
{
return
err
}
*
al
=
*
list
*
al
=
*
list
return
nil
return
nil
}
}
// NewAttributeListFromInts initializes a new AttributeList from a list of bigints.
// NewAttributeListFromInts initializes a new AttributeList from a list of bigints.
func
NewAttributeListFromInts
(
ints
[]
*
big
.
Int
,
store
*
ConfigurationStore
)
(
*
AttributeList
,
error
)
{
func
NewAttributeListFromInts
(
ints
[]
*
big
.
Int
,
store
*
ConfigurationStore
)
*
AttributeList
{
meta
:=
MetadataFromInt
(
ints
[
0
],
store
)
if
ints
[
0
]
==
nil
||
meta
.
CredentialType
()
==
nil
{
return
nil
,
errors
.
New
(
"Encountered credential of unknown type"
)
}
return
&
AttributeList
{
return
&
AttributeList
{
Ints
:
ints
,
Ints
:
ints
,
MetadataAttribute
:
m
eta
,
MetadataAttribute
:
M
eta
dataFromInt
(
ints
[
0
],
store
)
,
}
,
nil
}
}
}
func
(
al
*
AttributeList
)
Info
()
*
CredentialInfo
{
func
(
al
*
AttributeList
)
Info
()
*
CredentialInfo
{
if
al
.
info
==
nil
{
if
al
.
info
==
nil
{
al
.
info
=
NewCredentialInfo
(
al
.
Ints
)
al
.
info
=
NewCredentialInfo
(
al
.
Ints
,
al
.
store
)
}
}
return
al
.
info
return
al
.
info
}
}
...
@@ -144,7 +136,7 @@ func (attr *MetadataAttribute) Bytes() []byte {
...
@@ -144,7 +136,7 @@ func (attr *MetadataAttribute) Bytes() []byte {
// and returns this public key.
// and returns this public key.
func
(
attr
*
MetadataAttribute
)
PublicKey
()
*
gabi
.
PublicKey
{
func
(
attr
*
MetadataAttribute
)
PublicKey
()
*
gabi
.
PublicKey
{
if
attr
.
pk
==
nil
{
if
attr
.
pk
==
nil
{
attr
.
pk
=
MetaS
tore
.
PublicKey
(
attr
.
CredentialType
()
.
IssuerIdentifier
(),
attr
.
KeyCounter
())
attr
.
pk
=
attr
.
s
tore
.
PublicKey
(
attr
.
CredentialType
()
.
IssuerIdentifier
(),
attr
.
KeyCounter
())
}
}
return
attr
.
pk
return
attr
.
pk
}
}
...
@@ -197,7 +189,7 @@ func (attr *MetadataAttribute) setExpiryDate(timestamp *Timestamp) error {
...
@@ -197,7 +189,7 @@ func (attr *MetadataAttribute) setExpiryDate(timestamp *Timestamp) error {
// CredentialType returns the credential type of the current instance
// CredentialType returns the credential type of the current instance
// using the MetaStore.
// using the MetaStore.
func
(
attr
*
MetadataAttribute
)
CredentialType
()
*
CredentialType
{
func
(
attr
*
MetadataAttribute
)
CredentialType
()
*
CredentialType
{
return
MetaS
tore
.
hashToCredentialType
(
attr
.
field
(
credentialID
))
return
attr
.
s
tore
.
hashToCredentialType
(
attr
.
field
(
credentialID
))
}
}
func
(
attr
*
MetadataAttribute
)
setCredentialTypeIdentifier
(
id
string
)
{
func
(
attr
*
MetadataAttribute
)
setCredentialTypeIdentifier
(
id
string
)
{
...
@@ -295,7 +287,7 @@ func (disjunction *AttributeDisjunction) Satisfied() bool {
...
@@ -295,7 +287,7 @@ func (disjunction *AttributeDisjunction) Satisfied() bool {
}
}
// MatchesStore returns true if all attributes contained in the disjunction are
// MatchesStore returns true if all attributes contained in the disjunction are
// present in the
MetaS
tore.
// present in the
specified configuration s
tore.
func
(
disjunction
*
AttributeDisjunction
)
MatchesStore
(
store
*
ConfigurationStore
)
bool
{
func
(
disjunction
*
AttributeDisjunction
)
MatchesStore
(
store
*
ConfigurationStore
)
bool
{
for
ai
:=
range
disjunction
.
Values
{
for
ai
:=
range
disjunction
.
Values
{
creddescription
,
exists
:=
store
.
Credentials
[
ai
.
CredentialTypeIdentifier
()]
creddescription
,
exists
:=
store
.
Credentials
[
ai
.
CredentialTypeIdentifier
()]
...
...
credential.go
View file @
78d2cd8a
...
@@ -20,9 +20,9 @@ type CredentialInfo struct {
...
@@ -20,9 +20,9 @@ type CredentialInfo struct {
ID
string
// e.g., "irma-demo.RU.studentCard"
ID
string
// e.g., "irma-demo.RU.studentCard"
SignedOn
Timestamp
// Unix timestamp
SignedOn
Timestamp
// Unix timestamp
Expires
Timestamp
// Unix timestamp
Expires
Timestamp
// Unix timestamp
Type
*
CredentialType
// Credential information from
Meta
Store
Type
*
CredentialType
// Credential information from
Configuration
Store
Issuer
*
Issuer
// Issuer information from
Meta
Store
Issuer
*
Issuer
// Issuer information from
Configuration
Store
SchemeManager
*
SchemeManager
// Scheme manager information from
Meta
Store
SchemeManager
*
SchemeManager
// Scheme manager information from
Configuration
Store
Attributes
[]
TranslatedString
// Human-readable rendered attributes
Attributes
[]
TranslatedString
// Human-readable rendered attributes
Logo
string
// Path to logo on storage
Logo
string
// Path to logo on storage
}
}
...
@@ -30,8 +30,8 @@ type CredentialInfo struct {
...
@@ -30,8 +30,8 @@ type CredentialInfo struct {
// A CredentialInfoList is a list of credentials (implements sort.Interface).
// A CredentialInfoList is a list of credentials (implements sort.Interface).
type
CredentialInfoList
[]
*
CredentialInfo
type
CredentialInfoList
[]
*
CredentialInfo
func
NewCredentialInfo
(
ints
[]
*
big
.
Int
)
*
CredentialInfo
{
func
NewCredentialInfo
(
ints
[]
*
big
.
Int
,
store
*
ConfigurationStore
)
*
CredentialInfo
{
meta
:=
MetadataFromInt
(
ints
[
0
])
meta
:=
MetadataFromInt
(
ints
[
0
]
,
store
)
credtype
:=
meta
.
CredentialType
()
credtype
:=
meta
.
CredentialType
()
issid
:=
credtype
.
IssuerIdentifier
()
issid
:=
credtype
.
IssuerIdentifier
()
...
@@ -46,20 +46,20 @@ func NewCredentialInfo(ints []*big.Int) *CredentialInfo {
...
@@ -46,20 +46,20 @@ func NewCredentialInfo(ints []*big.Int) *CredentialInfo {
SignedOn
:
Timestamp
(
meta
.
SigningDate
()),
SignedOn
:
Timestamp
(
meta
.
SigningDate
()),
Expires
:
Timestamp
(
meta
.
Expiry
()),
Expires
:
Timestamp
(
meta
.
Expiry
()),
Type
:
credtype
,
Type
:
credtype
,
Issuer
:
MetaS
tore
.
Issuers
[
issid
],
Issuer
:
s
tore
.
Issuers
[
issid
],
SchemeManager
:
MetaS
tore
.
SchemeManagers
[
issid
.
SchemeManagerIdentifier
()],
SchemeManager
:
s
tore
.
SchemeManagers
[
issid
.
SchemeManagerIdentifier
()],
Attributes
:
attrs
,
Attributes
:
attrs
,
Logo
:
""
,
// TODO
Logo
:
""
,
// TODO
}
}
}
}
func
newCredential
(
gabicred
*
gabi
.
Credential
)
(
cred
*
credential
)
{
func
newCredential
(
gabicred
*
gabi
.
Credential
,
store
*
ConfigurationStore
)
(
cred
*
credential
)
{
meta
:=
MetadataFromInt
(
gabicred
.
Attributes
[
1
])
meta
:=
MetadataFromInt
(
gabicred
.
Attributes
[
1
]
,
store
)
cred
=
&
credential
{
cred
=
&
credential
{
Credential
:
gabicred
,
Credential
:
gabicred
,
MetadataAttribute
:
meta
,
MetadataAttribute
:
meta
,
}
}
cred
.
Pk
=
MetaS
tore
.
PublicKey
(
meta
.
CredentialType
()
.
IssuerIdentifier
(),
cred
.
KeyCounter
())
cred
.
Pk
=
s
tore
.
PublicKey
(
meta
.
CredentialType
()
.
IssuerIdentifier
(),
cred
.
KeyCounter
())
return
return
}
}
...
...
descriptions.go
View file @
78d2cd8a
...
@@ -133,8 +133,8 @@ func (sm *SchemeManager) Distributed() bool {
...
@@ -133,8 +133,8 @@ func (sm *SchemeManager) Distributed() bool {
}
}
// CurrentPublicKey returns the latest known public key of the issuer identified by this instance.
// CurrentPublicKey returns the latest known public key of the issuer identified by this instance.
func
(
id
*
Issuer
)
CurrentPublicKey
()
*
gabi
.
PublicKey
{
func
(
id
*
Issuer
)
CurrentPublicKey
(
store
*
ConfigurationStore
)
*
gabi
.
PublicKey
{
keys
:=
MetaS
tore
.
PublicKeys
[
id
.
Identifier
()]
keys
:=
s
tore
.
PublicKeys
[
id
.
Identifier
()]
if
keys
==
nil
||
len
(
keys
)
==
0
{
if
keys
==
nil
||
len
(
keys
)
==
0
{
return
nil
return
nil
}
}
...
@@ -142,8 +142,8 @@ func (id *Issuer) CurrentPublicKey() *gabi.PublicKey {
...
@@ -142,8 +142,8 @@ func (id *Issuer) CurrentPublicKey() *gabi.PublicKey {
}
}
// PublicKey returns the specified public key of the issuer identified by this instance.
// PublicKey returns the specified public key of the issuer identified by this instance.
func
(
id
*
Issuer
)
PublicKey
(
index
int
)
*
gabi
.
PublicKey
{
func
(
id
*
Issuer
)
PublicKey
(
index
int
,
store
*
ConfigurationStore
)
*
gabi
.
PublicKey
{
keys
:=
MetaS
tore
.
PublicKeys
[
id
.
Identifier
()]
keys
:=
s
tore
.
PublicKeys
[
id
.
Identifier
()]
if
keys
==
nil
||
index
>=
len
(
keys
)
{
if
keys
==
nil
||
index
>=
len
(
keys
)
{
return
nil
return
nil
}
}
...
...
irmago_test.go
View file @
78d2cd8a
...
@@ -47,9 +47,7 @@ func parseStorage(t *testing.T) *CredentialManager {
...
@@ -47,9 +47,7 @@ func parseStorage(t *testing.T) *CredentialManager {
}
}
func
teardown
(
t
*
testing
.
T
)
{
func
teardown
(
t
*
testing
.
T
)
{
MetaStore
=
newConfigurationStore
()
assert
.
NoError
(
t
,
os
.
RemoveAll
(
"testdata/storage/test"
))
assert
.
NoError
(
t
,
os
.
RemoveAll
(
"testdata/storage/test"
))
// TODO first RemoveAll?!
}
}
// A convenience function for initializing big integers from known correct (10
// A convenience function for initializing big integers from known correct (10
...
@@ -124,37 +122,37 @@ func verifyKeyshareIsUnmarshaled(t *testing.T, manager *CredentialManager) {
...
@@ -124,37 +122,37 @@ func verifyKeyshareIsUnmarshaled(t *testing.T, manager *CredentialManager) {
verifyPaillierKey
(
t
,
manager
.
paillierKeyCache
)
verifyPaillierKey
(
t
,
manager
.
paillierKeyCache
)
}
}
func
verifyStoreIsLoaded
(
t
*
testing
.
T
)
{
func
verifyStoreIsLoaded
(
t
*
testing
.
T
,
store
*
ConfigurationStore
)
{
assert
.
NotNil
(
t
,
MetaS
tore
.
Issuers
[
NewIssuerIdentifier
(
"irma-demo.RU"
)]
.
CurrentPublicKey
()
.
N
,
"irma-demo.RU public key has no modulus"
)
assert
.
NotNil
(
t
,
s
tore
.
Issuers
[
NewIssuerIdentifier
(
"irma-demo.RU"
)]
.
CurrentPublicKey
(
store
)
.
N
,
"irma-demo.RU public key has no modulus"
)
assert
.
Equal
(
t
,
assert
.
Equal
(
t
,
"Irma Demo"
,
"Irma Demo"
,
MetaS
tore
.
SchemeManagers
[
NewSchemeManagerIdentifier
(
"irma-demo"
)]
.
Name
[
"en"
],
s
tore
.
SchemeManagers
[
NewSchemeManagerIdentifier
(
"irma-demo"
)]
.
Name
[
"en"
],
"irma-demo scheme manager has unexpected name"
)
"irma-demo scheme manager has unexpected name"
)
assert
.
Equal
(
t
,
assert
.
Equal
(
t
,
"Radboud Universiteit Nijmegen"
,
"Radboud Universiteit Nijmegen"
,
MetaS
tore
.
Issuers
[
NewIssuerIdentifier
(
"irma-demo.RU"
)]
.
Name
[
"en"
],
s
tore
.
Issuers
[
NewIssuerIdentifier
(
"irma-demo.RU"
)]
.
Name
[
"en"
],
"irma-demo.RU issuer has unexpected name"
)
"irma-demo.RU issuer has unexpected name"
)
assert
.
Equal
(
t
,
assert
.
Equal
(
t
,
"Student Card"
,
"Student Card"
,
MetaS
tore
.
Credentials
[
NewCredentialTypeIdentifier
(
"irma-demo.RU.studentCard"
)]
.
ShortName
[
"en"
],
s
tore
.
Credentials
[
NewCredentialTypeIdentifier
(
"irma-demo.RU.studentCard"
)]
.
ShortName
[
"en"
],
"irma-demo.RU.studentCard has unexpected name"
)
"irma-demo.RU.studentCard has unexpected name"
)
assert
.
Equal
(
t
,
assert
.
Equal
(
t
,
"studentID"
,
"studentID"
,
MetaS
tore
.
Credentials
[
NewCredentialTypeIdentifier
(
"irma-demo.RU.studentCard"
)]
.
Attributes
[
2
]
.
ID
,
s
tore
.
Credentials
[
NewCredentialTypeIdentifier
(
"irma-demo.RU.studentCard"
)]
.
Attributes
[
2
]
.
ID
,
"irma-demo.RU.studentCard.studentID has unexpected name"
)
"irma-demo.RU.studentCard.studentID has unexpected name"
)
// Hash algorithm pseudocode:
// Hash algorithm pseudocode:
// Base64(SHA256("irma-demo.RU.studentCard")[0:16])
// Base64(SHA256("irma-demo.RU.studentCard")[0:16])
assert
.
Contains
(
t
,
MetaS
tore
.
reverseHashes
,
"1stqlPad5edpfS1Na1U+DA=="
,
assert
.
Contains
(
t
,
s
tore
.
reverseHashes
,
"1stqlPad5edpfS1Na1U+DA=="
,
"irma-demo.RU.studentCard had improper hash"
)
"irma-demo.RU.studentCard had improper hash"
)
assert
.
Contains
(
t
,
MetaS
tore
.
reverseHashes
,
"CLjnADMBYlFcuGOT7Z0xRg=="
,
assert
.
Contains
(
t
,
s
tore
.
reverseHashes
,
"CLjnADMBYlFcuGOT7Z0xRg=="
,
"irma-demo.MijnOverheid.root had improper hash"
)
"irma-demo.MijnOverheid.root had improper hash"
)
}
}
func
TestAndroidParse
(
t
*
testing
.
T
)
{
func
TestAndroidParse
(
t
*
testing
.
T
)
{
manager
:=
parseStorage
(
t
)
manager
:=
parseStorage
(
t
)
verifyStoreIsLoaded
(
t
)
verifyStoreIsLoaded
(
t
,
manager
.
Store
)
parseAndroidStorage
(
t
,
manager
)
parseAndroidStorage
(
t
,
manager
)
verifyManagerIsUnmarshaled
(
t
,
manager
)
verifyManagerIsUnmarshaled
(
t
,
manager
)
...
...
keyshare.go
View file @
78d2cd8a
...
@@ -139,7 +139,7 @@ func startKeyshareSession(
...
@@ -139,7 +139,7 @@ func startKeyshareSession(
)
{
)
{
ksscount
:=
0
ksscount
:=
0
for
_
,
managerID
:=
range
session
.
SchemeManagers
()
{
for
_
,
managerID
:=
range
session
.
SchemeManagers
()
{
if
credManager
.
s
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
credManager
.
S
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
ksscount
++
ksscount
++
if
_
,
registered
:=
credManager
.
keyshareServers
[
managerID
];
!
registered
{
if
_
,
registered
:=
credManager
.
keyshareServers
[
managerID
];
!
registered
{
err
:=
errors
.
New
(
"Not registered to keyshare server of scheme manager "
+
managerID
.
String
())
err
:=
errors
.
New
(
"Not registered to keyshare server of scheme manager "
+
managerID
.
String
())
...
@@ -166,7 +166,7 @@ func startKeyshareSession(
...
@@ -166,7 +166,7 @@ func startKeyshareSession(
askPin
:=
false
askPin
:=
false
for
_
,
managerID
:=
range
session
.
SchemeManagers
()
{
for
_
,
managerID
:=
range
session
.
SchemeManagers
()
{
if
!
ks
.
credManager
.
s
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
!
ks
.
credManager
.
S
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
continue
continue
}
}
...
@@ -234,7 +234,7 @@ func (ks *keyshareSession) VerifyPin(attempts int) {
...
@@ -234,7 +234,7 @@ func (ks *keyshareSession) VerifyPin(attempts int) {
// If all is ok, success will be true.
// If all is ok, success will be true.
func
(
ks
*
keyshareSession
)
verifyPinAttempt
(
pin
string
)
(
success
bool
,
tries
int
,
blocked
int
,
err
error
)
{
func
(
ks
*
keyshareSession
)
verifyPinAttempt
(
pin
string
)
(
success
bool
,
tries
int
,
blocked
int
,
err
error
)
{
for
_
,
managerID
:=
range
ks
.
session
.
SchemeManagers
()
{
for
_
,
managerID
:=
range
ks
.
session
.
SchemeManagers
()
{
if
!
ks
.
credManager
.
s
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
!
ks
.
credManager
.
S
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
continue
continue
}
}
...
@@ -285,7 +285,7 @@ func (ks *keyshareSession) GetCommitments() {
...
@@ -285,7 +285,7 @@ func (ks *keyshareSession) GetCommitments() {
for
_
,
builder
:=
range
ks
.
builders
{
for
_
,
builder
:=
range
ks
.
builders
{
pk
:=
builder
.
PublicKey
()
pk
:=
builder
.
PublicKey
()
managerID
:=
NewIssuerIdentifier
(
pk
.
Issuer
)
.
SchemeManagerIdentifier
()
managerID
:=
NewIssuerIdentifier
(
pk
.
Issuer
)
.
SchemeManagerIdentifier
()
if
!
ks
.
credManager
.
s
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
!
ks
.
credManager
.
S
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
continue
continue
}
}
if
_
,
contains
:=
pkids
[
managerID
];
!
contains
{
if
_
,
contains
:=
pkids
[
managerID
];
!
contains
{
...
@@ -297,7 +297,7 @@ func (ks *keyshareSession) GetCommitments() {
...
@@ -297,7 +297,7 @@ func (ks *keyshareSession) GetCommitments() {
// Now inform each keyshare server of with respect to which public keys
// Now inform each keyshare server of with respect to which public keys
// we want them to send us commitments
// we want them to send us commitments
for
_
,
managerID
:=
range
ks
.
session
.
SchemeManagers
()
{
for
_
,
managerID
:=
range
ks
.
session
.
SchemeManagers
()
{
if
!
ks
.
credManager
.
s
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
!
ks
.
credManager
.
S
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
continue
continue
}
}
...
@@ -401,7 +401,7 @@ func (ks *keyshareSession) finishDisclosureOrSigning(challenge *big.Int, respons
...
@@ -401,7 +401,7 @@ func (ks *keyshareSession) finishDisclosureOrSigning(challenge *big.Int, respons
for
i
,
builder
:=
range
ks
.
builders
{
for
i
,
builder
:=
range
ks
.
builders
{
// Parse each received JWT
// Parse each received JWT
managerID
:=
NewIssuerIdentifier
(
builder
.
PublicKey
()
.
Issuer
)
.
SchemeManagerIdentifier
()
managerID
:=
NewIssuerIdentifier
(
builder
.
PublicKey
()
.
Issuer
)
.
SchemeManagerIdentifier
()
if
!
ks
.
credManager
.
s
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
if
!
ks
.
credManager
.
S
tore
.
SchemeManagers
[
managerID
]
.
Distributed
()
{
continue
continue
}
}
msg
:=
struct
{
msg
:=
struct
{
...
...
manager.go
View file @
78d2cd8a
...
@@ -21,7 +21,7 @@ type CredentialManager struct {
...
@@ -21,7 +21,7 @@ type CredentialManager struct {
keyshareServers
map
[
SchemeManagerIdentifier
]
*
keyshareServer
keyshareServers
map
[
SchemeManagerIdentifier
]
*
keyshareServer
paillierKeyCache
*
paillierPrivateKey
paillierKeyCache
*
paillierPrivateKey
s
tore
*
ConfigurationStore
S
tore
*
ConfigurationStore
}
}
// CredentialInfoList returns a list of information of all contained credentials.
// CredentialInfoList returns a list of information of all contained credentials.
...
@@ -94,7 +94,7 @@ func (cm *CredentialManager) credential(id CredentialTypeIdentifier, counter int
...
@@ -94,7 +94,7 @@ func (cm *CredentialManager) credential(id CredentialTypeIdentifier, counter int
err
=
errors
.
New
(
"signature file not found"
)
err
=
errors
.
New
(
"signature file not found"
)
return
nil
,
err
return
nil
,
err
}
}
meta
:=
MetadataFromInt
(
ints
[
1
])
meta
:=
MetadataFromInt
(
ints
[
1
]
,
cm
.
Store
)
pk
:=
meta
.
PublicKey
()
pk
:=
meta
.
PublicKey
()
if
pk
==
nil
{
if
pk
==
nil
{
return
nil
,
errors
.
New
(
"unknown public key"
)
return
nil
,
errors
.
New
(
"unknown public key"
)
...
@@ -103,7 +103,7 @@ func (cm *CredentialManager) credential(id CredentialTypeIdentifier, counter int
...
@@ -103,7 +103,7 @@ func (cm *CredentialManager) credential(id CredentialTypeIdentifier, counter int
Attributes
:
ints
,
Attributes
:
ints
,
Signature
:
sig
,
Signature
:
sig
,
Pk
:
pk
,
Pk
:
pk
,
})
}
,
cm
.
Store
)
cm
.
credentials
[
id
][
counter
]
=
cred
cm
.
credentials
[
id
][
counter
]
=
cred
}
}
...
@@ -113,10 +113,7 @@ func (cm *CredentialManager) credential(id CredentialTypeIdentifier, counter int
...
@@ -113,10 +113,7 @@ func (cm *CredentialManager) credential(id CredentialTypeIdentifier, counter int
// addCredential adds the specified credential to the CredentialManager, saving its signature
// addCredential adds the specified credential to the CredentialManager, saving its signature
// imediately, and optionally cm.attributes as well.
// imediately, and optionally cm.attributes as well.
func
(
cm
*
CredentialManager
)
addCredential
(
cred
*
credential
,
storeAttributes
bool
)
(
err
error
)
{
func
(
cm
*
CredentialManager
)
addCredential
(
cred
*
credential
,
storeAttributes
bool
)
(
err
error
)
{
attrs
,
err
:=
NewAttributeListFromInts
(
cred
.
Attributes
[
1
:
])
attrs
:=
NewAttributeListFromInts
(
cred
.
Attributes
[
1
:
],
cm
.
Store
)
if
err
!=
nil
{
return
err
}
id
:=
cred
.
CredentialType
()
.
Identifier
()
id
:=
cred
.
CredentialType
()
.
Identifier
()
cm
.
attributes
[
id
]
=
append
(
cm
.
attrs
(
id
),
attrs
)
cm
.
attributes
[
id
]
=
append
(
cm
.
attrs
(
id
),
attrs
)
...
@@ -142,7 +139,7 @@ func (cm *CredentialManager) Candidates(disjunction *AttributeDisjunction) []*At
...
@@ -142,7 +139,7 @@ func (cm *CredentialManager) Candidates(disjunction *AttributeDisjunction) []*At
for
_
,
attribute
:=
range
disjunction
.
Attributes
{
for
_
,
attribute
:=
range
disjunction
.
Attributes
{
credID
:=
attribute
.
CredentialTypeIdentifier
()
credID
:=
attribute
.
CredentialTypeIdentifier
()
if
!
cm
.
s
tore
.
Contains
(
credID
)
{
if
!
cm
.
S
tore
.
Contains
(
credID
)
{
continue
continue
}
}
creds
:=
cm
.
credentials
[
credID
]
creds
:=
cm
.
credentials
[
credID
]
...
@@ -155,8 +152,7 @@ func (cm *CredentialManager) Candidates(disjunction *AttributeDisjunction) []*At
...
@@ -155,8 +152,7 @@ func (cm *CredentialManager) Candidates(disjunction *AttributeDisjunction) []*At
if
attribute
.
IsCredential
()
{
if
attribute
.
IsCredential
()
{
candidates
=
append
(
candidates
,
id
)
candidates
=
append
(
candidates
,
id
)
}
else
{
}
else
{
// Ignoring error of unknown credential type, would have happened during initialization
attrs
:=
NewAttributeListFromInts
(
cred
.
Attributes
[
1
:
],
cm
.
Store
)
attrs
,
_
:=
NewAttributeListFromInts
(
cred
.
Attributes
[
1
:
])
val
:=
attrs
.
Attribute
(
attribute
)
val
:=
attrs
.
Attribute
(
attribute
)
if
val
==
""
{
// This won't handle empty attributes correctly
if
val
==
""
{
// This won't handle empty attributes correctly
continue
continue
...
@@ -203,7 +199,7 @@ func (cm *CredentialManager) groupCredentials(choice *DisclosureChoice) (map[Cre
...
@@ -203,7 +199,7 @@ func (cm *CredentialManager) groupCredentials(choice *DisclosureChoice) (map[Cre
if
identifier
.
IsCredential
()
{
if
identifier
.
IsCredential
()
{
continue
// In this case we only disclose the metadata attribute, which is already handled
continue
// In this case we only disclose the metadata attribute, which is already handled
}
}
index
,
err
:=
cm
.
s
tore
.
Credentials
[
identifier
.
CredentialTypeIdentifier
()]
.
IndexOf
(
identifier
)
index
,
err
:=
cm
.
S
tore
.
Credentials
[
identifier
.
CredentialTypeIdentifier
()]
.
IndexOf
(
identifier
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -225,7 +221,7 @@ type IrmaSession interface {
...
@@ -225,7 +221,7 @@ type IrmaSession interface {
DisjunctionList
()
AttributeDisjunctionList
DisjunctionList
()
AttributeDisjunctionList
DisclosureChoice
()
*
DisclosureChoice
DisclosureChoice
()
*
DisclosureChoice
SetDisclosureChoice
(
choice
*
DisclosureChoice
)
SetDisclosureChoice
(
choice
*
DisclosureChoice
)
Distributed
()
bool
Distributed
(
store
*
ConfigurationStore
)
bool
SchemeManagers
()
[]
SchemeManagerIdentifier
SchemeManagers
()
[]
SchemeManagerIdentifier
}
}
...
@@ -267,7 +263,7 @@ func (cm *CredentialManager) IssuanceProofBuilders(request *IssuanceRequest) (ga
...
@@ -267,7 +263,7 @@ func (cm *CredentialManager) IssuanceProofBuilders(request *IssuanceRequest) (ga
proofBuilders
:=
gabi
.
ProofBuilderList
([]
gabi
.
ProofBuilder
{})
proofBuilders
:=
gabi
.
ProofBuilderList
([]
gabi
.
ProofBuilder
{})
for
_
,
futurecred
:=
range
request
.
Credentials
{
for
_
,
futurecred
:=
range
request
.
Credentials
{
pk
:=
cm
.
s
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
)
credBuilder
:=
gabi
.
NewCredentialBuilder
(
pk
,
request
.
GetContext
(),
cm
.
secretkey
,
state
.
nonce2
)
request
.
state
.
builders
=
append
(
request
.
state
.
builders
,
credBuilder
)
request
.
state
.
builders
=
append
(
request
.
state
.
builders
,
credBuilder
)
proofBuilders
=
append
(
proofBuilders
,
credBuilder
)
proofBuilders
=
append
(
proofBuilders
,
credBuilder
)
...
@@ -303,7 +299,7 @@ func (cm *CredentialManager) ConstructCredentials(msg []*gabi.IssueSignatureMess
...
@@ -303,7 +299,7 @@ func (cm *CredentialManager) ConstructCredentials(msg []*gabi.IssueSignatureMess
// we save none of them to fail the session cleanly
// we save none of them to fail the session cleanly
creds
:=
[]
*
gabi
.
Credential
{}
creds
:=
[]
*
gabi
.
Credential
{}
for
i
,
sig
:=
range
msg
{
for
i
,
sig
:=
range
msg
{
attrs
,
err
:=
request
.
Credentials
[
i
]
.
AttributeList
()
attrs
,
err
:=
request
.
Credentials
[
i
]
.
AttributeList
(
cm
.
Store
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -315,7 +311,7 @@ func (cm *CredentialManager) ConstructCredentials(msg []*gabi.IssueSignatureMess
...
@@ -315,7 +311,7 @@ func (cm *CredentialManager) ConstructCredentials(msg []*gabi.IssueSignatureMess
}
}
for
_
,
cred
:=
range
creds
{
for
_
,
cred
:=
range
creds
{
cm
.
addCredential
(
newCredential
(
cred
),
true
)
cm
.
addCredential
(
newCredential
(
cred
,
cm
.
Store
),
true
)
}
}
return
nil
return
nil
...
@@ -342,7 +338,7 @@ func (cm *CredentialManager) paillierKey(wait bool) *paillierPrivateKey {
...
@@ -342,7 +338,7 @@ func (cm *CredentialManager) paillierKey(wait bool) *paillierPrivateKey {
func
(
cm
*
CredentialManager
)
unenrolledKeyshareServers
()
[]
*
SchemeManager
{
func
(
cm
*
CredentialManager
)
unenrolledKeyshareServers
()
[]
*
SchemeManager
{
list
:=
[]
*
SchemeManager
{}
list
:=
[]
*
SchemeManager
{}
for
name
,
manager
:=
range
cm
.
s
tore
.
SchemeManagers
{
for
name
,
manager
:=
range
cm
.
S
tore
.
SchemeManagers
{
if
_
,
contains
:=
cm
.
keyshareServers
[
name
];
len
(
manager
.
KeyshareServer
)
>
0
&&
!
contains
{
if
_
,
contains
:=
cm
.
keyshareServers
[
name
];
len
(
manager
.
KeyshareServer
)
>
0
&&
!
contains
{
list
=
append
(
list
,
manager
)
list
=
append
(
list
,
manager
)
}
}
...
@@ -352,7 +348,7 @@ func (cm *CredentialManager) unenrolledKeyshareServers() []*SchemeManager {
...
@@ -352,7 +348,7 @@ func (cm *CredentialManager) unenrolledKeyshareServers() []*SchemeManager {
// KeyshareEnroll attempts to register at the keyshare server of the specified scheme manager.
// KeyshareEnroll attempts to register at the keyshare server of the specified scheme manager.
func
(
cm
*
CredentialManager
)
KeyshareEnroll
(
managerID
SchemeManagerIdentifier
,
email
,
pin
string
)
error
{
func
(
cm
*
CredentialManager
)
KeyshareEnroll
(
managerID
SchemeManagerIdentifier
,
email
,
pin
string
)
error
{
manager
,
ok
:=
cm
.
s
tore
.
SchemeManagers
[
managerID
]
manager
,
ok
:=
cm
.
S
tore
.
SchemeManagers
[
managerID
]
if
!
ok
{
if
!
ok
{
return
errors
.
New
(
"Unknown scheme manager"
)
return
errors
.
New
(
"Unknown scheme manager"
)
}
}
...
...
requests.go
View file @
78d2cd8a
...
@@ -111,7 +111,7 @@ type issuanceState struct {
...
@@ -111,7 +111,7 @@ type issuanceState struct {
}
}
// AttributeList returns the list of attributes from this credential request.
// AttributeList returns the list of attributes from this credential request.
func
(
cr
*
CredentialRequest
)
AttributeList
()
(
*
AttributeList
,
error
)
{
func
(
cr
*
CredentialRequest
)
AttributeList
(
store
*
ConfigurationStore
)
(
*
AttributeList
,
error
)
{
meta
:=
NewMetadataAttribute
()
meta
:=
NewMetadataAttribute
()
meta
.
setKeyCounter
(
cr
.
KeyCounter
)
meta
.
setKeyCounter
(
cr
.
KeyCounter
)
meta
.
setCredentialTypeIdentifier
(
cr
.
Credential
.
String
())
meta
.
setCredentialTypeIdentifier
(
cr
.
Credential
.
String
())
...
@@ -122,7 +122,7 @@ func (cr *CredentialRequest) AttributeList() (*AttributeList, error) {
...
@@ -122,7 +122,7 @@ func (cr *CredentialRequest) AttributeList() (*AttributeList, error) {
}
}
attrs
:=
make
([]
*
big
.
Int
,
len
(
cr
.
Attributes
)
+
1
,
len
(
cr
.
Attributes
)
+
1
)
attrs
:=
make
([]
*
big
.
Int
,
len
(
cr
.
Attributes
)
+
1
,
len
(
cr
.
Attributes
)
+
1
)
credtype
:=
MetaS
tore
.
Credentials
[
*
cr
.
Credential
]
credtype
:=
s
tore
.
Credentials
[
*
cr
.
Credential
]
if
credtype
==
nil
{
if
credtype
==
nil
{
return
nil
,
errors
.
New
(
"Unknown credential type"
)
return
nil
,
errors
.
New
(
"Unknown credential type"
)
}
}
...
@@ -139,7 +139,7 @@ func (cr *CredentialRequest) AttributeList() (*AttributeList, error) {
...
@@ -139,7 +139,7 @@ func (cr *CredentialRequest) AttributeList() (*AttributeList, error) {
}
}
}
}
return
NewAttributeListFromInts
(
attrs
)
return
NewAttributeListFromInts
(
attrs
,
store
),
nil
}
}
func
newIssuanceState
()
(
*
issuanceState
,
error
)
{
func
newIssuanceState
()
(
*
issuanceState
,
error
)
{
...
@@ -154,9 +154,9 @@ func newIssuanceState() (*issuanceState, error) {
...
@@ -154,9 +154,9 @@ func newIssuanceState() (*issuanceState, error) {
}
}
// Distributed indicates if a keyshare is involved in this session.
// Distributed indicates if a keyshare is involved in this session.
func
(
ir
*
IssuanceRequest
)
Distributed
()
bool
{
func
(
ir
*
IssuanceRequest
)
Distributed
(
store
*
ConfigurationStore
)
bool
{
for
_
,
manager
:=
range
ir
.
SchemeManagers
()
{
for
_
,
manager
:=
range
ir
.
SchemeManagers
()
{
if
MetaS
tore
.
SchemeManagers
[
manager
]
.
Distributed
()
{
if
s
tore
.
SchemeManagers
[
manager
]
.
Distributed
()
{
return
true
return
true
}
}
}
}
...
@@ -193,9 +193,9 @@ func (ir *IssuanceRequest) GetNonce() *big.Int { return ir.Nonce }
...
@@ -193,9 +193,9 @@ func (ir *IssuanceRequest) GetNonce() *big.Int { return ir.Nonce }
func
(
ir
*
IssuanceRequest
)
SetNonce
(
nonce
*
big
.
Int
)
{
ir
.
Nonce
=
nonce
}
func
(
ir
*
IssuanceRequest
)
SetNonce
(
nonce
*
big
.
Int
)
{
ir
.
Nonce
=
nonce
}
// Distributed indicates if a keyshare is involved in this session.
// Distributed indicates if a keyshare is involved in this session.
func
(
dr
*
DisclosureRequest
)
Distributed
()
bool
{
func
(
dr
*
DisclosureRequest
)
Distributed
(
store
*
ConfigurationStore
)
bool
{
for
_
,
manager
:=
range
dr
.
SchemeManagers
()
{
for
_
,
manager
:=
range
dr
.
SchemeManagers
()
{
if
MetaS
tore
.
SchemeManagers
[
manager
]
.
Distributed
()
{
if
s
tore
.
SchemeManagers
[
manager
]
.
Distributed
()
{
return
true
return
true
}
}
}
}
...
...
session.go
View file @
78d2cd8a
...
@@ -190,7 +190,7 @@ func (session *session) do(proceed bool) {
...
@@ -190,7 +190,7 @@ func (session *session) do(proceed bool) {
}
}
session
.
Handler
.
StatusUpdate
(
session
.
Action
,
StatusCommunicating
)
session
.
Handler
.
StatusUpdate
(
session
.
Action
,
StatusCommunicating
)
if
!
session
.
irmaSession
.
Distributed
()
{
if
!
session
.
irmaSession
.
Distributed
(
session
.
credManager
.
Store