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
aadcf3c5
Commit
aadcf3c5
authored
Jul 26, 2017
by
Sietse Ringers
Browse files
Rename CredentialIdentifier -> CredentialTypeIdentifier
parent
3a6e8e88
Changes
7
Hide whitespace changes
Inline
Side-by-side
attributes.go
View file @
aadcf3c5
...
@@ -154,7 +154,7 @@ func (attr *MetadataAttribute) CredentialType() *CredentialType {
...
@@ -154,7 +154,7 @@ func (attr *MetadataAttribute) CredentialType() *CredentialType {
return
MetaStore
.
hashToCredentialType
(
attr
.
field
(
credentialID
))
return
MetaStore
.
hashToCredentialType
(
attr
.
field
(
credentialID
))
}
}
func
(
attr
*
MetadataAttribute
)
setCredentialIdentifier
(
id
string
)
{
func
(
attr
*
MetadataAttribute
)
setCredential
Type
Identifier
(
id
string
)
{
bytes
:=
sha256
.
Sum256
([]
byte
(
id
))
bytes
:=
sha256
.
Sum256
([]
byte
(
id
))
attr
.
setField
(
credentialID
,
bytes
[
:
16
])
attr
.
setField
(
credentialID
,
bytes
[
:
16
])
}
}
...
...
descriptions.go
View file @
aadcf3c5
...
@@ -48,7 +48,7 @@ type CredentialType struct {
...
@@ -48,7 +48,7 @@ type CredentialType struct {
// ContainsAttribute tests whether the specified attribute is contained in this
// ContainsAttribute tests whether the specified attribute is contained in this
// credentialtype.
// credentialtype.
func
(
ct
*
CredentialType
)
ContainsAttribute
(
ai
AttributeIdentifier
)
bool
{
func
(
ct
*
CredentialType
)
ContainsAttribute
(
ai
AttributeIdentifier
)
bool
{
if
ai
.
CredentialIdentifier
()
.
String
()
!=
ct
.
Identifier
()
.
String
()
{
if
ai
.
Credential
Type
Identifier
()
.
String
()
!=
ct
.
Identifier
()
.
String
()
{
return
false
return
false
}
}
for
_
,
desc
:=
range
ct
.
Attributes
{
for
_
,
desc
:=
range
ct
.
Attributes
{
...
@@ -106,8 +106,8 @@ func (ts *TranslatedString) Translation(lang string) string {
...
@@ -106,8 +106,8 @@ func (ts *TranslatedString) Translation(lang string) string {
}
}
// Identifier returns the identifier of the specified credential type.
// Identifier returns the identifier of the specified credential type.
func
(
ct
*
CredentialType
)
Identifier
()
CredentialIdentifier
{
func
(
ct
*
CredentialType
)
Identifier
()
Credential
Type
Identifier
{
return
NewCredentialIdentifier
(
ct
.
SchemeManagerID
+
"."
+
ct
.
IssuerID
+
"."
+
ct
.
ID
)
return
NewCredential
Type
Identifier
(
ct
.
SchemeManagerID
+
"."
+
ct
.
IssuerID
+
"."
+
ct
.
ID
)
}
}
// IssuerIdentifier returns the issuer identifier of the specified credential type.
// IssuerIdentifier returns the issuer identifier of the specified credential type.
...
...
identifiers.go
View file @
aadcf3c5
...
@@ -14,8 +14,8 @@ type IssuerIdentifier struct {
...
@@ -14,8 +14,8 @@ type IssuerIdentifier struct {
objectIdentifier
objectIdentifier
}
}
// CredentialIdentifier identifies a credentialtype. For example "irma-demo.RU.studentCard".
// Credential
Type
Identifier identifies a credentialtype. For example "irma-demo.RU.studentCard".
type
CredentialIdentifier
struct
{
type
Credential
Type
Identifier
struct
{
objectIdentifier
objectIdentifier
}
}
...
@@ -48,9 +48,9 @@ func NewIssuerIdentifier(id string) IssuerIdentifier {
...
@@ -48,9 +48,9 @@ func NewIssuerIdentifier(id string) IssuerIdentifier {
return
IssuerIdentifier
{
objectIdentifier
(
id
)}
return
IssuerIdentifier
{
objectIdentifier
(
id
)}
}
}
// NewCredentialIdentifier converts the specified identifier to a CredentialIdentifier.
// NewCredential
Type
Identifier converts the specified identifier to a Credential
Type
Identifier.
func
NewCredentialIdentifier
(
id
string
)
CredentialIdentifier
{
func
NewCredential
Type
Identifier
(
id
string
)
Credential
Type
Identifier
{
return
CredentialIdentifier
{
objectIdentifier
(
id
)}
return
Credential
Type
Identifier
{
objectIdentifier
(
id
)}
}
}
// NewAttributeIdentifier converts the specified identifier to a AttributeIdentifier.
// NewAttributeIdentifier converts the specified identifier to a AttributeIdentifier.
...
@@ -64,11 +64,11 @@ func (id IssuerIdentifier) SchemeManagerIdentifier() SchemeManagerIdentifier {
...
@@ -64,11 +64,11 @@ func (id IssuerIdentifier) SchemeManagerIdentifier() SchemeManagerIdentifier {
}
}
// IssuerIdentifier returns the IssuerIdentifier of the credential identifier.
// IssuerIdentifier returns the IssuerIdentifier of the credential identifier.
func
(
id
CredentialIdentifier
)
IssuerIdentifier
()
IssuerIdentifier
{
func
(
id
Credential
Type
Identifier
)
IssuerIdentifier
()
IssuerIdentifier
{
return
NewIssuerIdentifier
(
id
.
Parent
())
return
NewIssuerIdentifier
(
id
.
Parent
())
}
}
// CredentialIdentifier returns the CredentialIdentifier of the attribute identifier.
// Credential
Type
Identifier returns the Credential
Type
Identifier of the attribute identifier.
func
(
id
AttributeIdentifier
)
CredentialIdentifier
()
CredentialIdentifier
{
func
(
id
AttributeIdentifier
)
Credential
Type
Identifier
()
Credential
Type
Identifier
{
return
NewCredentialIdentifier
(
id
.
Parent
())
return
NewCredential
Type
Identifier
(
id
.
Parent
())
}
}
irmago_test.go
View file @
aadcf3c5
...
@@ -55,7 +55,7 @@ func parseAndroidStorage(t *testing.T) {
...
@@ -55,7 +55,7 @@ func parseAndroidStorage(t *testing.T) {
}
}
func
verifyStoreIsUnmarshaled
(
t
*
testing
.
T
)
{
func
verifyStoreIsUnmarshaled
(
t
*
testing
.
T
)
{
cred
,
err
:=
Manager
.
Credential
(
NewCredentialIdentifier
(
"irma-demo.RU.studentCard"
),
0
)
cred
,
err
:=
Manager
.
Credential
(
NewCredential
Type
Identifier
(
"irma-demo.RU.studentCard"
),
0
)
assert
.
NoError
(
t
,
err
,
"could not fetch credential"
)
assert
.
NoError
(
t
,
err
,
"could not fetch credential"
)
assert
.
NotNil
(
t
,
cred
,
"Credential should exist"
)
assert
.
NotNil
(
t
,
cred
,
"Credential should exist"
)
assert
.
NotNil
(
t
,
cred
.
Attributes
[
0
],
"Metadata attribute of irma-demo.RU.studentCard should not be nil"
)
assert
.
NotNil
(
t
,
cred
.
Attributes
[
0
],
"Metadata attribute of irma-demo.RU.studentCard should not be nil"
)
...
@@ -102,12 +102,12 @@ func TestParseStore(t *testing.T) {
...
@@ -102,12 +102,12 @@ func TestParseStore(t *testing.T) {
"irma-demo.RU issuer has unexpected name"
)
"irma-demo.RU issuer has unexpected name"
)
assert
.
Equal
(
t
,
assert
.
Equal
(
t
,
"Student Card"
,
"Student Card"
,
MetaStore
.
Credentials
[
NewCredentialIdentifier
(
"irma-demo.RU.studentCard"
)]
.
ShortName
.
Translation
(
"en"
),
MetaStore
.
Credentials
[
NewCredential
Type
Identifier
(
"irma-demo.RU.studentCard"
)]
.
ShortName
.
Translation
(
"en"
),
"irma-demo.RU.studentCard has unexpected name"
)
"irma-demo.RU.studentCard has unexpected name"
)
assert
.
Equal
(
t
,
assert
.
Equal
(
t
,
"studentID"
,
"studentID"
,
MetaStore
.
Credentials
[
NewCredentialIdentifier
(
"irma-demo.RU.studentCard"
)]
.
Attributes
[
2
]
.
ID
,
MetaStore
.
Credentials
[
NewCredential
Type
Identifier
(
"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:
...
@@ -144,7 +144,7 @@ func TestMetadataCompatibility(t *testing.T) {
...
@@ -144,7 +144,7 @@ func TestMetadataCompatibility(t *testing.T) {
assert
.
NotNil
(
t
,
attr
.
CredentialType
(),
"attr.CredentialType() should not be nil"
)
assert
.
NotNil
(
t
,
attr
.
CredentialType
(),
"attr.CredentialType() should not be nil"
)
assert
.
Equal
(
t
,
assert
.
Equal
(
t
,
NewCredentialIdentifier
(
"irma-demo.RU.studentCard"
),
NewCredential
Type
Identifier
(
"irma-demo.RU.studentCard"
),
attr
.
CredentialType
()
.
Identifier
(),
attr
.
CredentialType
()
.
Identifier
(),
"Metadata credential type was not irma-demo.RU.studentCard"
,
"Metadata credential type was not irma-demo.RU.studentCard"
,
)
)
...
...
manager.go
View file @
aadcf3c5
...
@@ -18,13 +18,13 @@ var Manager = newCredentialManager()
...
@@ -18,13 +18,13 @@ var Manager = newCredentialManager()
type
CredentialManager
struct
{
type
CredentialManager
struct
{
secretkey
*
big
.
Int
secretkey
*
big
.
Int
storagePath
string
storagePath
string
attributes
map
[
CredentialIdentifier
][]
*
AttributeList
attributes
map
[
Credential
Type
Identifier
][]
*
AttributeList
credentials
map
[
CredentialIdentifier
]
map
[
int
]
*
Credential
credentials
map
[
Credential
Type
Identifier
]
map
[
int
]
*
Credential
}
}
func
newCredentialManager
()
*
CredentialManager
{
func
newCredentialManager
()
*
CredentialManager
{
return
&
CredentialManager
{
return
&
CredentialManager
{
credentials
:
make
(
map
[
CredentialIdentifier
]
map
[
int
]
*
Credential
),
credentials
:
make
(
map
[
Credential
Type
Identifier
]
map
[
int
]
*
Credential
),
}
}
}
}
...
@@ -50,7 +50,7 @@ func (cm *CredentialManager) Init(path string) (err error) {
...
@@ -50,7 +50,7 @@ func (cm *CredentialManager) Init(path string) (err error) {
}
}
// attrs returns cm.attributes[id], initializing it to an empty slice if neccesary
// attrs returns cm.attributes[id], initializing it to an empty slice if neccesary
func
(
cm
*
CredentialManager
)
attrs
(
id
CredentialIdentifier
)
[]
*
AttributeList
{
func
(
cm
*
CredentialManager
)
attrs
(
id
Credential
Type
Identifier
)
[]
*
AttributeList
{
list
,
exists
:=
cm
.
attributes
[
id
]
list
,
exists
:=
cm
.
attributes
[
id
]
if
!
exists
{
if
!
exists
{
list
=
make
([]
*
AttributeList
,
0
,
1
)
list
=
make
([]
*
AttributeList
,
0
,
1
)
...
@@ -60,7 +60,7 @@ func (cm *CredentialManager) attrs(id CredentialIdentifier) []*AttributeList {
...
@@ -60,7 +60,7 @@ func (cm *CredentialManager) attrs(id CredentialIdentifier) []*AttributeList {
}
}
// creds returns cm.credentials[id], initializing it to an empty map if neccesary
// creds returns cm.credentials[id], initializing it to an empty map if neccesary
func
(
cm
*
CredentialManager
)
creds
(
id
CredentialIdentifier
)
map
[
int
]
*
Credential
{
func
(
cm
*
CredentialManager
)
creds
(
id
Credential
Type
Identifier
)
map
[
int
]
*
Credential
{
list
,
exists
:=
cm
.
credentials
[
id
]
list
,
exists
:=
cm
.
credentials
[
id
]
if
!
exists
{
if
!
exists
{
list
=
make
(
map
[
int
]
*
Credential
)
list
=
make
(
map
[
int
]
*
Credential
)
...
@@ -70,7 +70,7 @@ func (cm *CredentialManager) creds(id CredentialIdentifier) map[int]*Credential
...
@@ -70,7 +70,7 @@ func (cm *CredentialManager) creds(id CredentialIdentifier) map[int]*Credential
}
}
// Attributes returns the attribute list of the requested credential, or nil if we do not have it.
// Attributes returns the attribute list of the requested credential, or nil if we do not have it.
func
(
cm
*
CredentialManager
)
Attributes
(
id
CredentialIdentifier
,
counter
int
)
(
attributes
*
AttributeList
)
{
func
(
cm
*
CredentialManager
)
Attributes
(
id
Credential
Type
Identifier
,
counter
int
)
(
attributes
*
AttributeList
)
{
list
:=
cm
.
attrs
(
id
)
list
:=
cm
.
attrs
(
id
)
if
len
(
list
)
<=
counter
{
if
len
(
list
)
<=
counter
{
return
return
...
@@ -79,7 +79,7 @@ func (cm *CredentialManager) Attributes(id CredentialIdentifier, counter int) (a
...
@@ -79,7 +79,7 @@ func (cm *CredentialManager) Attributes(id CredentialIdentifier, counter int) (a
}
}
// Credential returns the requested credential, or nil if we do not have it.
// Credential returns the requested credential, or nil if we do not have it.
func
(
cm
*
CredentialManager
)
Credential
(
id
CredentialIdentifier
,
counter
int
)
(
cred
*
Credential
,
err
error
)
{
func
(
cm
*
CredentialManager
)
Credential
(
id
Credential
Type
Identifier
,
counter
int
)
(
cred
*
Credential
,
err
error
)
{
// If the requested credential is not in credential map, we check if its attributes were
// If the requested credential is not in credential map, we check if its attributes were
// deserialized during Init(). If so, there should be a corresponding signature file,
// deserialized during Init(). If so, there should be a corresponding signature file,
// so we read that, construct the credential, and add it to the credential map
// so we read that, construct the credential, and add it to the credential map
...
...
storage.go
View file @
aadcf3c5
...
@@ -112,7 +112,7 @@ func (cm *CredentialManager) storeSignature(cred *Credential, counter int) (err
...
@@ -112,7 +112,7 @@ func (cm *CredentialManager) storeSignature(cred *Credential, counter int) (err
}
}
func
(
cm
*
CredentialManager
)
storeAttributes
()
(
err
error
)
{
func
(
cm
*
CredentialManager
)
storeAttributes
()
(
err
error
)
{
// Unfortunately, the type of cm.attributes (map[CredentialIdentifier][]*AttributeList)
// Unfortunately, the type of cm.attributes (map[Credential
Type
Identifier][]*AttributeList)
// cannot be passed directly to json.Marshal(), so we copy it into a temp list.
// cannot be passed directly to json.Marshal(), so we copy it into a temp list.
temp
:=
make
(
map
[
string
][]
*
AttributeList
)
temp
:=
make
(
map
[
string
][]
*
AttributeList
)
for
credid
,
list
:=
range
cm
.
attributes
{
for
credid
,
list
:=
range
cm
.
attributes
{
...
@@ -128,7 +128,7 @@ func (cm *CredentialManager) storeAttributes() (err error) {
...
@@ -128,7 +128,7 @@ func (cm *CredentialManager) storeAttributes() (err error) {
return
return
}
}
func
(
cm
*
CredentialManager
)
loadSignature
(
id
CredentialIdentifier
,
counter
int
)
(
signature
*
gabi
.
CLSignature
,
err
error
)
{
func
(
cm
*
CredentialManager
)
loadSignature
(
id
Credential
Type
Identifier
,
counter
int
)
(
signature
*
gabi
.
CLSignature
,
err
error
)
{
path
:=
cm
.
signatureFilename
(
id
.
String
(),
counter
)
path
:=
cm
.
signatureFilename
(
id
.
String
(),
counter
)
exists
,
err
:=
pathExists
(
path
)
exists
,
err
:=
pathExists
(
path
)
if
err
!=
nil
||
!
exists
{
if
err
!=
nil
||
!
exists
{
...
@@ -166,8 +166,8 @@ func (cm *CredentialManager) loadSecretKey() (*big.Int, error) {
...
@@ -166,8 +166,8 @@ func (cm *CredentialManager) loadSecretKey() (*big.Int, error) {
return
sk
,
nil
return
sk
,
nil
}
}
func
(
cm
*
CredentialManager
)
loadAttributes
()
(
list
map
[
CredentialIdentifier
][]
*
AttributeList
,
err
error
)
{
func
(
cm
*
CredentialManager
)
loadAttributes
()
(
list
map
[
Credential
Type
Identifier
][]
*
AttributeList
,
err
error
)
{
list
=
make
(
map
[
CredentialIdentifier
][]
*
AttributeList
)
list
=
make
(
map
[
Credential
Type
Identifier
][]
*
AttributeList
)
temp
:=
make
(
map
[
string
][]
*
AttributeList
)
temp
:=
make
(
map
[
string
][]
*
AttributeList
)
exists
,
err
:=
pathExists
(
cm
.
path
(
attributesFile
))
exists
,
err
:=
pathExists
(
cm
.
path
(
attributesFile
))
...
@@ -185,7 +185,7 @@ func (cm *CredentialManager) loadAttributes() (list map[CredentialIdentifier][]*
...
@@ -185,7 +185,7 @@ func (cm *CredentialManager) loadAttributes() (list map[CredentialIdentifier][]*
}
}
for
credid
,
attrs
:=
range
temp
{
for
credid
,
attrs
:=
range
temp
{
list
[
NewCredentialIdentifier
(
credid
)]
=
attrs
list
[
NewCredential
Type
Identifier
(
credid
)]
=
attrs
}
}
return
list
,
nil
return
list
,
nil
}
}
store.go
View file @
aadcf3c5
...
@@ -20,10 +20,10 @@ var MetaStore = newConfigurationStore()
...
@@ -20,10 +20,10 @@ var MetaStore = newConfigurationStore()
type
ConfigurationStore
struct
{
type
ConfigurationStore
struct
{
SchemeManagers
map
[
SchemeManagerIdentifier
]
*
SchemeManager
SchemeManagers
map
[
SchemeManagerIdentifier
]
*
SchemeManager
Issuers
map
[
IssuerIdentifier
]
*
Issuer
Issuers
map
[
IssuerIdentifier
]
*
Issuer
Credentials
map
[
CredentialIdentifier
]
*
CredentialType
Credentials
map
[
Credential
Type
Identifier
]
*
CredentialType
PublicKeys
map
[
IssuerIdentifier
][]
*
gabi
.
PublicKey
PublicKeys
map
[
IssuerIdentifier
][]
*
gabi
.
PublicKey
reverseHashes
map
[
string
]
CredentialIdentifier
reverseHashes
map
[
string
]
Credential
Type
Identifier
initialized
bool
initialized
bool
}
}
...
@@ -31,9 +31,9 @@ func newConfigurationStore() (store *ConfigurationStore) {
...
@@ -31,9 +31,9 @@ func newConfigurationStore() (store *ConfigurationStore) {
store
=
&
ConfigurationStore
{
store
=
&
ConfigurationStore
{
SchemeManagers
:
make
(
map
[
SchemeManagerIdentifier
]
*
SchemeManager
),
SchemeManagers
:
make
(
map
[
SchemeManagerIdentifier
]
*
SchemeManager
),
Issuers
:
make
(
map
[
IssuerIdentifier
]
*
Issuer
),
Issuers
:
make
(
map
[
IssuerIdentifier
]
*
Issuer
),
Credentials
:
make
(
map
[
CredentialIdentifier
]
*
CredentialType
),
Credentials
:
make
(
map
[
Credential
Type
Identifier
]
*
CredentialType
),
PublicKeys
:
make
(
map
[
IssuerIdentifier
][]
*
gabi
.
PublicKey
),
PublicKeys
:
make
(
map
[
IssuerIdentifier
][]
*
gabi
.
PublicKey
),
reverseHashes
:
make
(
map
[
string
]
CredentialIdentifier
),
reverseHashes
:
make
(
map
[
string
]
Credential
Type
Identifier
),
}
}
return
return
}
}
...
@@ -48,7 +48,7 @@ func (store *ConfigurationStore) PublicKey(id IssuerIdentifier, counter int) *ga
...
@@ -48,7 +48,7 @@ func (store *ConfigurationStore) PublicKey(id IssuerIdentifier, counter int) *ga
return
nil
return
nil
}
}
func
(
store
*
ConfigurationStore
)
addReverseHash
(
credid
CredentialIdentifier
)
{
func
(
store
*
ConfigurationStore
)
addReverseHash
(
credid
Credential
Type
Identifier
)
{
hash
:=
sha256
.
Sum256
([]
byte
(
credid
.
String
()))
hash
:=
sha256
.
Sum256
([]
byte
(
credid
.
String
()))
store
.
reverseHashes
[
base64
.
StdEncoding
.
EncodeToString
(
hash
[
:
16
])]
=
credid
store
.
reverseHashes
[
base64
.
StdEncoding
.
EncodeToString
(
hash
[
:
16
])]
=
credid
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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