Commit e49c7e6a authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Update protocol

parent 2fb8b5c2
......@@ -135,3 +135,9 @@ func (id *CredentialTypeIdentifier) UnmarshalJSON(b []byte) error {
id.metaObjectIdentifier = metaObjectIdentifier(val)
return nil
}
// TODO this also for the other identifiers
func (id *IssuerIdentifier) UnmarshalText(text []byte) error {
*id = NewIssuerIdentifier(string(text))
return nil
}
......@@ -4,11 +4,12 @@ import (
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"math/big"
"strconv"
"math/big"
"strings"
"github.com/mhe/gabi"
)
......@@ -68,16 +69,22 @@ type publicKeyIdentifier struct {
Counter uint `json:"counter"`
}
// TODO update protocol so this can go away
func (pki *publicKeyIdentifier) MarshalJSON() ([]byte, error) {
temp := struct {
Issuer map[string]string `json:"issuer"`
Counter uint `json:"counter"`
}{
Issuer: map[string]string{"identifier": pki.Issuer},
Counter: pki.Counter,
func (pki *publicKeyIdentifier) UnmarshalText(text []byte) error {
str := string(text)
index := strings.LastIndex(str, "-")
if index == -1 {
return errors.New("Invalid publicKeyIdentifier")
}
counter, err := strconv.Atoi(str[index+1:])
if err != nil {
return err
}
return json.Marshal(temp)
*pki = publicKeyIdentifier{Issuer: str[:index], Counter: uint(counter)}
return nil
}
func (pki *publicKeyIdentifier) MarshalText() (text []byte, err error) {
return []byte(fmt.Sprintf("%s-%d", pki.Issuer, pki.Counter)), nil
}
type proofPCommitmentMap struct {
......@@ -415,32 +422,3 @@ func (ks *keyshareSession) finishDisclosureOrSigning(challenge *big.Int, respons
}
ks.sessionHandler.KeyshareDone(list)
}
// TODO this message is ugly, should update protocol
func (comms *proofPCommitmentMap) UnmarshalJSON(bytes []byte) error {
comms.Commitments = map[publicKeyIdentifier]*gabi.ProofPCommitment{}
temp := struct {
C [][]*json.RawMessage `json:"c"`
}{}
if err := json.Unmarshal(bytes, &temp); err != nil {
return err
}
for _, raw := range temp.C {
tempPkID := struct {
Issuer struct {
Identifier string `json:"identifier"`
} `json:"issuer"`
Counter uint `json:"counter"`
}{}
comm := gabi.ProofPCommitment{}
if err := json.Unmarshal([]byte(*raw[0]), &tempPkID); err != nil {
return err
}
if err := json.Unmarshal([]byte(*raw[1]), &comm); err != nil {
return err
}
pkid := publicKeyIdentifier{Issuer: tempPkID.Issuer.Identifier, Counter: tempPkID.Counter}
comms.Commitments[pkid] = &comm
}
return nil
}
......@@ -59,25 +59,6 @@ type SessionInfo struct {
Keys map[IssuerIdentifier]int `json:"keys"`
}
/*
So apparently, in the old Java implementation we forgot to write a (de)serialization for the Java
equivalent of the type IssuerIdentifier. This means a Java IssuerIdentifier does not serialize to
a string, but to e.g. `{"identifier":"irma-demo.RU"}`.
This is a complex data type, so not suitable to act as keys in a JSON map. Consequentially,
Gson serializes the `json:"keys"` field not as a map, but as a list consisting of pairs where
the first item of the pair is a serialized IssuerIdentifier as above, and the second item
of the pair is the corresponding key counter from the original map.
This is a bit of a mess to have to deserialize. See below. In a future version of the protocol,
this will have to be fixed both in the Java world and here in Go.
*/
type jsonSessionInfo struct {
Jwt string `json:"jwt"`
Nonce *big.Int `json:"nonce"`
Context *big.Int `json:"context"`
Keys [][]interface{} `json:"keys"`
}
// Statuses
const (
StatusConnected = Status("connected")
......@@ -148,35 +129,3 @@ func jwtDecode(jwt string, body interface{}) (string, error) {
}
return header.Issuer, json.Unmarshal(bodybytes, body)
}
// UnmarshalJSON unmarshals session information.
func (si *SessionInfo) UnmarshalJSON(b []byte) error {
temp := &jsonSessionInfo{}
err := json.Unmarshal(b, temp)
if err != nil {
return err
}
si.Jwt = temp.Jwt
si.Nonce = temp.Nonce
si.Context = temp.Context
si.Keys = make(map[IssuerIdentifier]int, len(temp.Keys))
for _, item := range temp.Keys {
var idmap map[string]interface{}
var idstr string
var counter float64
var ok bool
if idmap, ok = item[0].(map[string]interface{}); !ok {
return errors.New("Failed to deserialize session info")
}
if idstr, ok = idmap["identifier"].(string); !ok {
return errors.New("Failed to deserialize session info")
}
if counter, ok = item[1].(float64); !ok {
return errors.New("Failed to deserialize session info")
}
id := NewIssuerIdentifier(idstr)
si.Keys[id] = int(counter)
}
return nil
}
......@@ -43,7 +43,7 @@ type session struct {
// Supported protocol versions. Minor version numbers should be reverse sorted.
var supportedVersions = map[int][]int{
2: {2, 1},
3: {0},
}
func calcVersion(qr *Qr) (string, error) {
......
......@@ -26,7 +26,11 @@ func (th TestHandler) Cancelled(action Action) {
th.c <- &Error{}
}
func (th TestHandler) Failure(action Action, err *Error) {
th.c <- err
select {
case th.c <- err:
default:
th.t.Fatal(err)
}
}
func (th TestHandler) UnsatisfiableRequest(action Action, missing AttributeDisjunctionList) {
th.c <- &Error{
......@@ -153,7 +157,7 @@ func sessionHelper(t *testing.T, jwtcontents interface{}, url string, init bool)
parseAndroidStorage(t)
}
url = "http://localhost:8081/irma_api_server/api/v2/" + url
url = "http://localhost:8081/irma_api_server/api/v3/" + url
//url = "https://demo.irmacard.org/tomcat/irma_api_server/api/v2/" + url
headerbytes, err := json.Marshal(&map[string]string{"alg": "none", "typ": "JWT"})
......
......@@ -9,7 +9,7 @@
<en>A test scheme manager with a scheme manager.</en>
<nl>Een test-scheme manager met een keyshare server.</nl>
</Description>
<KeyshareServer>http://localhost:8080/irma_keyshare_server/api/v1</KeyshareServer>
<KeyshareServer>http://localhost:8080/irma_keyshare_server/api/v2</KeyshareServer>
<KeyshareWebsite>http://localhost:8080/irma_keyshare_server/mijnirma/</KeyshareWebsite>
<KeyshareAttribute>test.test.mijnirma.email</KeyshareAttribute>
<Contact>https://privacybydesign.foundation/</Contact>
......
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