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 {
if val == nil {
continue
}
al.strings[i] = translateAttribute(val)
al.strings[i] = NewTranslatedString(val)
}
}
return al.strings
}
// Localize raw attribute values (to be implemented)
func translateAttribute(attr *string) TranslatedString {
// NewTranslatedString returns a TranslatedString containing the specified string for each supported language,
// or nil when attr is nil.
func NewTranslatedString(attr *string) TranslatedString {
if attr == nil {
return nil
}
......
......@@ -92,12 +92,12 @@ func (th TestHandler) Failure(err *irma.SessionError) {
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{
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{
Attributes: []*irma.AttributeIdentifier{},
}
......@@ -111,14 +111,14 @@ func (th TestHandler) RequestVerificationPermission(request irma.DisclosureReque
}
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{
BaseRequest: request.BaseRequest,
Content: request.Disclose,
}
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)
}
func (th TestHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) {
......@@ -171,10 +171,10 @@ func (th *ManualTestHandler) Success(result string) {
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)
}
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)
}
......@@ -182,7 +182,7 @@ func (th *ManualTestHandler) RequestIssuancePermission(request irma.IssuanceRequ
func (th *ManualTestHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) {
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
for _, cand := range request.Candidates {
choice.Attributes = append(choice.Attributes, cand[0])
......
......@@ -18,7 +18,7 @@ var _ Handler = (*keyshareEnrollmentHandler)(nil)
// 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
smi := request.Credentials[0].CredentialTypeID.IssuerIdentifier().SchemeManagerIdentifier()
attr := irma.NewAttributeTypeIdentifier(h.client.Configuration.SchemeManagers[smi].KeyshareAttribute)
......@@ -55,10 +55,10 @@ func (h *keyshareEnrollmentHandler) fail(err error) {
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
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)
}
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)
}
func (h *keyshareEnrollmentHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) {
......@@ -79,6 +79,6 @@ func (h *keyshareEnrollmentHandler) KeyshareEnrollmentDeleted(manager irma.Schem
func (h *keyshareEnrollmentHandler) KeyshareEnrollmentMissing(manager irma.SchemeManagerIdentifier) {
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"))
}
......@@ -29,16 +29,16 @@ type Handler interface {
Success(result string)
Cancelled()
Failure(err *irma.SessionError)
UnsatisfiableRequest(ServerName string, missing irma.AttributeDisjunctionList)
UnsatisfiableRequest(ServerName irma.TranslatedString, missing irma.AttributeDisjunctionList)
KeyshareBlocked(manager irma.SchemeManagerIdentifier, duration int)
KeyshareEnrollmentIncomplete(manager irma.SchemeManagerIdentifier)
KeyshareEnrollmentMissing(manager irma.SchemeManagerIdentifier)
KeyshareEnrollmentDeleted(manager irma.SchemeManagerIdentifier)
RequestIssuancePermission(request irma.IssuanceRequest, ServerName string, callback PermissionHandler)
RequestVerificationPermission(request irma.DisclosureRequest, ServerName string, callback PermissionHandler)
RequestSignaturePermission(request irma.SignatureRequest, ServerName string, callback PermissionHandler)
RequestIssuancePermission(request irma.IssuanceRequest, ServerName irma.TranslatedString, callback PermissionHandler)
RequestVerificationPermission(request irma.DisclosureRequest, ServerName irma.TranslatedString, callback PermissionHandler)
RequestSignaturePermission(request irma.SignatureRequest, ServerName irma.TranslatedString, callback PermissionHandler)
RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool))
RequestPin(remainingAttempts int, callback PinHandler)
......@@ -232,9 +232,10 @@ func (session *session) processSessionInfo() {
}
}
serverName := irma.NewTranslatedString(&session.ServerName)
candidates, missing := session.client.CheckSatisfiability(session.request.ToDisclose())
if len(missing) > 0 {
session.Handler.UnsatisfiableRequest(session.ServerName, missing)
session.Handler.UnsatisfiableRequest(serverName, missing)
return
}
session.request.SetCandidates(candidates)
......@@ -249,13 +250,13 @@ func (session *session) processSessionInfo() {
switch session.Action {
case irma.ActionDisclosing:
session.Handler.RequestVerificationPermission(
*session.request.(*irma.DisclosureRequest), session.ServerName, callback)
*session.request.(*irma.DisclosureRequest), serverName, callback)
case irma.ActionSigning:
session.Handler.RequestSignaturePermission(
*session.request.(*irma.SignatureRequest), session.ServerName, callback)
*session.request.(*irma.SignatureRequest), serverName, callback)
case irma.ActionIssuing:
session.Handler.RequestIssuancePermission(
*session.request.(*irma.IssuanceRequest), session.ServerName, callback)
*session.request.(*irma.IssuanceRequest), serverName, callback)
default:
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
return &DisclosedAttribute{
Identifier: attrid,
RawValue: attrval,
Value: translateAttribute(attrval),
Value: NewTranslatedString(attrval),
}, attrval, nil
}
......@@ -408,7 +408,7 @@ func ParseApiServerJwt(inputJwt string, signingKey *rsa.PublicKey) (map[Attribut
disclosedAttributes[id] = &DisclosedAttribute{
Identifier: id,
RawValue: &value,
Value: translateAttribute(&value),
Value: NewTranslatedString(&value),
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