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

Make remote server name in irmaclient api translatable

parent ae6c4356
...@@ -98,14 +98,15 @@ func (al *AttributeList) Strings() []TranslatedString { ...@@ -98,14 +98,15 @@ func (al *AttributeList) Strings() []TranslatedString {
if val == nil { if val == nil {
continue continue
} }
al.strings[i] = translateAttribute(val) al.strings[i] = NewTranslatedString(val)
} }
} }
return al.strings return al.strings
} }
// Localize raw attribute values (to be implemented) // NewTranslatedString returns a TranslatedString containing the specified string for each supported language,
func translateAttribute(attr *string) TranslatedString { // or nil when attr is nil.
func NewTranslatedString(attr *string) TranslatedString {
if attr == nil { if attr == nil {
return nil return nil
} }
......
...@@ -92,12 +92,12 @@ func (th TestHandler) Failure(err *irma.SessionError) { ...@@ -92,12 +92,12 @@ func (th TestHandler) Failure(err *irma.SessionError) {
th.t.Fatal(err) th.t.Fatal(err)
} }
} }
func (th TestHandler) UnsatisfiableRequest(serverName string, missing irma.AttributeDisjunctionList) { func (th TestHandler) UnsatisfiableRequest(serverName irma.TranslatedString, missing irma.AttributeDisjunctionList) {
th.Failure(&irma.SessionError{ th.Failure(&irma.SessionError{
ErrorType: irma.ErrorType("UnsatisfiableRequest"), ErrorType: irma.ErrorType("UnsatisfiableRequest"),
}) })
} }
func (th TestHandler) RequestVerificationPermission(request irma.DisclosureRequest, ServerName string, callback irmaclient.PermissionHandler) { func (th TestHandler) RequestVerificationPermission(request irma.DisclosureRequest, ServerName irma.TranslatedString, callback irmaclient.PermissionHandler) {
choice := &irma.DisclosureChoice{ choice := &irma.DisclosureChoice{
Attributes: []*irma.AttributeIdentifier{}, Attributes: []*irma.AttributeIdentifier{},
} }
...@@ -111,14 +111,14 @@ func (th TestHandler) RequestVerificationPermission(request irma.DisclosureReque ...@@ -111,14 +111,14 @@ func (th TestHandler) RequestVerificationPermission(request irma.DisclosureReque
} }
callback(true, choice) callback(true, choice)
} }
func (th TestHandler) RequestIssuancePermission(request irma.IssuanceRequest, ServerName string, callback irmaclient.PermissionHandler) { func (th TestHandler) RequestIssuancePermission(request irma.IssuanceRequest, ServerName irma.TranslatedString, callback irmaclient.PermissionHandler) {
dreq := irma.DisclosureRequest{ dreq := irma.DisclosureRequest{
BaseRequest: request.BaseRequest, BaseRequest: request.BaseRequest,
Content: request.Disclose, Content: request.Disclose,
} }
th.RequestVerificationPermission(dreq, ServerName, callback) th.RequestVerificationPermission(dreq, ServerName, callback)
} }
func (th TestHandler) RequestSignaturePermission(request irma.SignatureRequest, ServerName string, callback irmaclient.PermissionHandler) { func (th TestHandler) RequestSignaturePermission(request irma.SignatureRequest, ServerName irma.TranslatedString, callback irmaclient.PermissionHandler) {
th.RequestVerificationPermission(request.DisclosureRequest, ServerName, callback) th.RequestVerificationPermission(request.DisclosureRequest, ServerName, callback)
} }
func (th TestHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) { func (th TestHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) {
...@@ -171,10 +171,10 @@ func (th *ManualTestHandler) Success(result string) { ...@@ -171,10 +171,10 @@ func (th *ManualTestHandler) Success(result string) {
th.c <- retval th.c <- retval
} }
func (th *ManualTestHandler) RequestSignaturePermission(request irma.SignatureRequest, requesterName string, ph irmaclient.PermissionHandler) { func (th *ManualTestHandler) RequestSignaturePermission(request irma.SignatureRequest, requesterName irma.TranslatedString, ph irmaclient.PermissionHandler) {
th.RequestVerificationPermission(request.DisclosureRequest, requesterName, ph) th.RequestVerificationPermission(request.DisclosureRequest, requesterName, ph)
} }
func (th *ManualTestHandler) RequestIssuancePermission(request irma.IssuanceRequest, issuerName string, ph irmaclient.PermissionHandler) { func (th *ManualTestHandler) RequestIssuancePermission(request irma.IssuanceRequest, issuerName irma.TranslatedString, ph irmaclient.PermissionHandler) {
ph(true, nil) ph(true, nil)
} }
...@@ -182,7 +182,7 @@ func (th *ManualTestHandler) RequestIssuancePermission(request irma.IssuanceRequ ...@@ -182,7 +182,7 @@ func (th *ManualTestHandler) RequestIssuancePermission(request irma.IssuanceRequ
func (th *ManualTestHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) { func (th *ManualTestHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) {
th.Failure(&irma.SessionError{Err: errors.New("Unexpected session type")}) th.Failure(&irma.SessionError{Err: errors.New("Unexpected session type")})
} }
func (th *ManualTestHandler) RequestVerificationPermission(request irma.DisclosureRequest, verifierName string, ph irmaclient.PermissionHandler) { func (th *ManualTestHandler) RequestVerificationPermission(request irma.DisclosureRequest, verifierName irma.TranslatedString, ph irmaclient.PermissionHandler) {
var choice irma.DisclosureChoice var choice irma.DisclosureChoice
for _, cand := range request.Candidates { for _, cand := range request.Candidates {
choice.Attributes = append(choice.Attributes, cand[0]) choice.Attributes = append(choice.Attributes, cand[0])
......
...@@ -18,7 +18,7 @@ var _ Handler = (*keyshareEnrollmentHandler)(nil) ...@@ -18,7 +18,7 @@ var _ Handler = (*keyshareEnrollmentHandler)(nil)
// Session handlers in the order they are called // Session handlers in the order they are called
func (h *keyshareEnrollmentHandler) RequestIssuancePermission(request irma.IssuanceRequest, ServerName string, callback PermissionHandler) { func (h *keyshareEnrollmentHandler) RequestIssuancePermission(request irma.IssuanceRequest, ServerName irma.TranslatedString, callback PermissionHandler) {
// Fetch the username from the credential request and save it along with the scheme manager // Fetch the username from the credential request and save it along with the scheme manager
smi := request.Credentials[0].CredentialTypeID.IssuerIdentifier().SchemeManagerIdentifier() smi := request.Credentials[0].CredentialTypeID.IssuerIdentifier().SchemeManagerIdentifier()
attr := irma.NewAttributeTypeIdentifier(h.client.Configuration.SchemeManagers[smi].KeyshareAttribute) attr := irma.NewAttributeTypeIdentifier(h.client.Configuration.SchemeManagers[smi].KeyshareAttribute)
...@@ -55,10 +55,10 @@ func (h *keyshareEnrollmentHandler) fail(err error) { ...@@ -55,10 +55,10 @@ func (h *keyshareEnrollmentHandler) fail(err error) {
func (h *keyshareEnrollmentHandler) StatusUpdate(action irma.Action, status irma.Status) {} func (h *keyshareEnrollmentHandler) StatusUpdate(action irma.Action, status irma.Status) {}
// The methods below should never be called, so we let each of them fail the session // The methods below should never be called, so we let each of them fail the session
func (h *keyshareEnrollmentHandler) RequestVerificationPermission(request irma.DisclosureRequest, ServerName string, callback PermissionHandler) { func (h *keyshareEnrollmentHandler) RequestVerificationPermission(request irma.DisclosureRequest, ServerName irma.TranslatedString, callback PermissionHandler) {
callback(false, nil) callback(false, nil)
} }
func (h *keyshareEnrollmentHandler) RequestSignaturePermission(request irma.SignatureRequest, ServerName string, callback PermissionHandler) { func (h *keyshareEnrollmentHandler) RequestSignaturePermission(request irma.SignatureRequest, ServerName irma.TranslatedString, callback PermissionHandler) {
callback(false, nil) callback(false, nil)
} }
func (h *keyshareEnrollmentHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) { func (h *keyshareEnrollmentHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) {
...@@ -79,6 +79,6 @@ func (h *keyshareEnrollmentHandler) KeyshareEnrollmentDeleted(manager irma.Schem ...@@ -79,6 +79,6 @@ func (h *keyshareEnrollmentHandler) KeyshareEnrollmentDeleted(manager irma.Schem
func (h *keyshareEnrollmentHandler) KeyshareEnrollmentMissing(manager irma.SchemeManagerIdentifier) { func (h *keyshareEnrollmentHandler) KeyshareEnrollmentMissing(manager irma.SchemeManagerIdentifier) {
h.fail(errors.New("Keyshare enrollment failed: unenrolled")) h.fail(errors.New("Keyshare enrollment failed: unenrolled"))
} }
func (h *keyshareEnrollmentHandler) UnsatisfiableRequest(ServerName string, missing irma.AttributeDisjunctionList) { func (h *keyshareEnrollmentHandler) UnsatisfiableRequest(ServerName irma.TranslatedString, missing irma.AttributeDisjunctionList) {
h.fail(errors.New("Keyshare enrollment failed: unsatisfiable")) h.fail(errors.New("Keyshare enrollment failed: unsatisfiable"))
} }
...@@ -29,16 +29,16 @@ type Handler interface { ...@@ -29,16 +29,16 @@ type Handler interface {
Success(result string) Success(result string)
Cancelled() Cancelled()
Failure(err *irma.SessionError) Failure(err *irma.SessionError)
UnsatisfiableRequest(ServerName string, missing irma.AttributeDisjunctionList) UnsatisfiableRequest(ServerName irma.TranslatedString, missing irma.AttributeDisjunctionList)
KeyshareBlocked(manager irma.SchemeManagerIdentifier, duration int) KeyshareBlocked(manager irma.SchemeManagerIdentifier, duration int)
KeyshareEnrollmentIncomplete(manager irma.SchemeManagerIdentifier) KeyshareEnrollmentIncomplete(manager irma.SchemeManagerIdentifier)
KeyshareEnrollmentMissing(manager irma.SchemeManagerIdentifier) KeyshareEnrollmentMissing(manager irma.SchemeManagerIdentifier)
KeyshareEnrollmentDeleted(manager irma.SchemeManagerIdentifier) KeyshareEnrollmentDeleted(manager irma.SchemeManagerIdentifier)
RequestIssuancePermission(request irma.IssuanceRequest, ServerName string, callback PermissionHandler) RequestIssuancePermission(request irma.IssuanceRequest, ServerName irma.TranslatedString, callback PermissionHandler)
RequestVerificationPermission(request irma.DisclosureRequest, ServerName string, callback PermissionHandler) RequestVerificationPermission(request irma.DisclosureRequest, ServerName irma.TranslatedString, callback PermissionHandler)
RequestSignaturePermission(request irma.SignatureRequest, ServerName string, callback PermissionHandler) RequestSignaturePermission(request irma.SignatureRequest, ServerName irma.TranslatedString, callback PermissionHandler)
RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool))
RequestPin(remainingAttempts int, callback PinHandler) RequestPin(remainingAttempts int, callback PinHandler)
...@@ -232,9 +232,10 @@ func (session *session) processSessionInfo() { ...@@ -232,9 +232,10 @@ func (session *session) processSessionInfo() {
} }
} }
serverName := irma.NewTranslatedString(&session.ServerName)
candidates, missing := session.client.CheckSatisfiability(session.request.ToDisclose()) candidates, missing := session.client.CheckSatisfiability(session.request.ToDisclose())
if len(missing) > 0 { if len(missing) > 0 {
session.Handler.UnsatisfiableRequest(session.ServerName, missing) session.Handler.UnsatisfiableRequest(serverName, missing)
return return
} }
session.request.SetCandidates(candidates) session.request.SetCandidates(candidates)
...@@ -249,13 +250,13 @@ func (session *session) processSessionInfo() { ...@@ -249,13 +250,13 @@ func (session *session) processSessionInfo() {
switch session.Action { switch session.Action {
case irma.ActionDisclosing: case irma.ActionDisclosing:
session.Handler.RequestVerificationPermission( session.Handler.RequestVerificationPermission(
*session.request.(*irma.DisclosureRequest), session.ServerName, callback) *session.request.(*irma.DisclosureRequest), serverName, callback)
case irma.ActionSigning: case irma.ActionSigning:
session.Handler.RequestSignaturePermission( session.Handler.RequestSignaturePermission(
*session.request.(*irma.SignatureRequest), session.ServerName, callback) *session.request.(*irma.SignatureRequest), serverName, callback)
case irma.ActionIssuing: case irma.ActionIssuing:
session.Handler.RequestIssuancePermission( session.Handler.RequestIssuancePermission(
*session.request.(*irma.IssuanceRequest), session.ServerName, callback) *session.request.(*irma.IssuanceRequest), serverName, callback)
default: default:
panic("Invalid session type") // does not happen, session.Action has been checked earlier panic("Invalid session type") // does not happen, session.Action has been checked earlier
} }
......
...@@ -208,7 +208,7 @@ func parseAttribute(index int, metadata *MetadataAttribute, attr *big.Int) (*Dis ...@@ -208,7 +208,7 @@ func parseAttribute(index int, metadata *MetadataAttribute, attr *big.Int) (*Dis
return &DisclosedAttribute{ return &DisclosedAttribute{
Identifier: attrid, Identifier: attrid,
RawValue: attrval, RawValue: attrval,
Value: translateAttribute(attrval), Value: NewTranslatedString(attrval),
}, attrval, nil }, attrval, nil
} }
...@@ -408,7 +408,7 @@ func ParseApiServerJwt(inputJwt string, signingKey *rsa.PublicKey) (map[Attribut ...@@ -408,7 +408,7 @@ func ParseApiServerJwt(inputJwt string, signingKey *rsa.PublicKey) (map[Attribut
disclosedAttributes[id] = &DisclosedAttribute{ disclosedAttributes[id] = &DisclosedAttribute{
Identifier: id, Identifier: id,
RawValue: &value, RawValue: &value,
Value: translateAttribute(&value), Value: NewTranslatedString(&value),
Status: AttributeProofStatusPresent, Status: AttributeProofStatusPresent,
} }
} }
......
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