Commit 4d97255d authored by David Venhoek's avatar David Venhoek
Browse files

Merge branch 'master' into david-pinchange

parents b02aa5fd 1b853dc0
// Package irmago is work in progress on an IRMA client in Go.
//It will (de)serialize credentials from/to storage,
// and be the client (like the IRMA Android app,
// https://github.com/credentials/irma_android_cardemu) in the IRMA protocol (see
// https://credentials.github.io/protocols/irma-protocol).
// Package irma contains generic IRMA strucs and logic of use to all IRMA participants.
// It parses irma_configuration folders to scheme managers, issuers, credential types and public keys,
// it contains various messages from the IRMA protocol, and parses IRMA metadata attributes.
package irma
......@@ -111,6 +111,9 @@ func (id CredentialTypeIdentifier) IssuerIdentifier() IssuerIdentifier {
// CredentialTypeIdentifier returns the CredentialTypeIdentifier of the attribute identifier.
func (id AttributeTypeIdentifier) CredentialTypeIdentifier() CredentialTypeIdentifier {
if id.IsCredential() {
return NewCredentialTypeIdentifier(id.String())
}
return NewCredentialTypeIdentifier(id.Parent())
}
......
......@@ -43,7 +43,7 @@ type Client struct {
// Stuff we manage on disk
secretkey *secretKey
attributes map[irma.CredentialTypeIdentifier][]*irma.AttributeList
credentials map[irma.CredentialTypeIdentifier]map[int]*credential
credentialsCache map[irma.CredentialTypeIdentifier]map[int]*credential
keyshareServers map[irma.SchemeManagerIdentifier]*keyshareServer
paillierKeyCache *paillierPrivateKey
logs []*LogEntry
......@@ -128,7 +128,7 @@ func New(
}
cm := &Client{
credentials: make(map[irma.CredentialTypeIdentifier]map[int]*credential),
credentialsCache: make(map[irma.CredentialTypeIdentifier]map[int]*credential),
keyshareServers: make(map[irma.SchemeManagerIdentifier]*keyshareServer),
attributes: make(map[irma.CredentialTypeIdentifier][]*irma.AttributeList),
irmaConfigurationPath: irmaConfigurationPath,
......@@ -226,18 +226,18 @@ func (client *Client) addCredential(cred *credential, storeAttributes bool) (err
}
// If this is a singleton credential type, ensure we have at most one by removing any previous instance
if !id.Empty() && cred.CredentialType().IsSingleton && len(client.creds(id)) > 0 {
if !id.Empty() && cred.CredentialType().IsSingleton && len(client.attrs(id)) > 0 {
client.remove(id, 0, false) // Index is 0, because if we're here we have exactly one
}
// Append the new cred to our attributes and credentials
client.attributes[id] = append(client.attrs(id), cred.AttributeList())
if !id.Empty() {
if _, exists := client.credentials[id]; !exists {
client.credentials[id] = make(map[int]*credential)
if _, exists := client.credentialsCache[id]; !exists {
client.credentialsCache[id] = make(map[int]*credential)
}
counter := len(client.attributes[id]) - 1
client.credentials[id][counter] = cred
client.credentialsCache[id][counter] = cred
}
if err = client.storage.StoreSignature(cred); err != nil {
......@@ -274,10 +274,10 @@ func (client *Client) remove(id irma.CredentialTypeIdentifier, index int, storen
}
// Remove credential
if creds, exists := client.credentials[id]; exists {
if creds, exists := client.credentialsCache[id]; exists {
if _, exists := creds[index]; exists {
delete(creds, index)
client.credentials[id] = creds
client.credentialsCache[id] = creds
}
}
......@@ -354,10 +354,10 @@ func (client *Client) attrs(id irma.CredentialTypeIdentifier) []*irma.AttributeL
// creds returns cm.credentials[id], initializing it to an empty map if neccesary
func (client *Client) creds(id irma.CredentialTypeIdentifier) map[int]*credential {
list, exists := client.credentials[id]
list, exists := client.credentialsCache[id]
if !exists {
list = make(map[int]*credential)
client.credentials[id] = list
client.credentialsCache[id] = list
}
return list
}
......@@ -428,10 +428,10 @@ func (client *Client) credential(id irma.CredentialTypeIdentifier, counter int)
if err != nil {
return nil, err
}
client.credentials[id][counter] = cred
client.credentialsCache[id][counter] = cred
}
return client.credentials[id][counter], nil
return client.credentialsCache[id][counter], nil
}
// Methods used in the IRMA protocol
......
// Package irmaclient implements an IRMA client, that can manage and use IRMA attributes.
// It (de)serializes them from/to storage, acts as the client in the IRMA protocol
// (see https://credentials.github.io/protocols/irma-protocol), and also in the IRMA
// keyshare protocol (see http://credentials.github.io/protocols/keyshare-protocol).
package irmaclient
......@@ -2,10 +2,10 @@ package irmaclient
import (
"encoding/json"
"errors"
"math/big"
"os"
"testing"
"errors"
"github.com/mhe/gabi"
"github.com/privacybydesign/irmago"
......@@ -107,9 +107,10 @@ func verifyClientIsUnmarshaled(t *testing.T, client *Client) {
func verifyCredentials(t *testing.T, client *Client) {
var pk *gabi.PublicKey
var err error
for credtype, credsmap := range client.credentials {
for index, cred := range credsmap {
for credtype, credsmap := range client.attributes {
for index, attrs := range credsmap {
cred, err := client.credential(attrs.CredentialType().Identifier(), index)
require.NoError(t, err)
pk, err = cred.PublicKey()
require.NoError(t, err)
require.True(t,
......
......@@ -8,11 +8,12 @@ import (
"testing"
"time"
"math/big"
"github.com/go-errors/errors"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/test"
"github.com/stretchr/testify/require"
"math/big"
)
type TestHandler struct {
......@@ -210,6 +211,14 @@ func TestDisclosureSession(t *testing.T) {
sessionHelper(t, jwtcontents, "verification", nil)
}
func TestNoAttributeDisclosureSession(t *testing.T) {
id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard")
name := "testsp"
jwtcontents := getDisclosureJwt(name, id)
sessionHelper(t, jwtcontents, "verification", nil)
}
func TestIssuanceSession(t *testing.T) {
id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
name := "testip"
......@@ -370,8 +379,8 @@ func keyshareSessions(t *testing.T, client *Client) {
func TestKeyshareChangePin(t *testing.T) {
client := parseStorage(t)
require.NoError(t, client.keyshareChangePinWorker(irma.NewSchemeManagerIdentifier("test"), "12345", "54321"));
require.NoError(t, client.keyshareChangePinWorker(irma.NewSchemeManagerIdentifier("test"), "54321", "12345"));
require.NoError(t, client.keyshareChangePinWorker(irma.NewSchemeManagerIdentifier("test"), "12345", "54321"))
require.NoError(t, client.keyshareChangePinWorker(irma.NewSchemeManagerIdentifier("test"), "54321", "12345"))
test.ClearTestStorage(t)
}
......
......@@ -198,7 +198,7 @@ func (client *Client) ParseAndroidStorage() (present bool, err error) {
}
}
if len(client.credentials) > 0 {
if len(client.credentialsCache) > 0 {
if err = client.storage.StoreAttributes(client.attributes); err != nil {
return
}
......
// irmameta parses and prints info about the specified metadata attribute.
package main
import (
......@@ -15,7 +16,7 @@ import (
func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: irmago metadata_attribute_in_decimal path_to_irma_configuration")
fmt.Println("Usage: irmago path_to_irma_configuration metadata_attribute_in_decimal")
}
metaint, ok := new(big.Int).SetString(os.Args[2], 10)
......
// schememgr manages signatures on IRMA scheme managers.
// It can generate public-private keypairs for signing their directory structures,
// as well as creating and verifying these signatures.
package main
import "github.com/privacybydesign/irmago/schememgr/cmd"
......
Markdown is supported
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