Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Handle credential requests #112

Merged
merged 2 commits into from
Jan 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 64 additions & 32 deletions irmagobridge/session_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package irmagobridge

import (
"errors"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/irmaclient"
)
Expand Down Expand Up @@ -92,55 +93,86 @@ func (sh *SessionHandler) UnsatisfiableRequest(request irma.SessionRequest,
sendAction(action)
}

func CheckContainsCredentialIdentifiers(request *irma.DisclosureRequest) *irma.SessionError {
for _, discon := range request.Disclose {
for _, con := range discon {
for _, attrReq := range con {
if attrReq.Type.IsCredential() {
return &irma.SessionError{
ErrorType: irma.ErrorInvalidRequest,
Err: errors.New("Request should only contain AttributeIdentifiers"),
}
}
}
}
}
return nil
}

func (sh *SessionHandler) RequestIssuancePermission(request *irma.IssuanceRequest, candidates [][][]*irma.AttributeIdentifier, serverName irma.TranslatedString, ph irmaclient.PermissionHandler) {
logDebug("Handling RequestIssuancePermission")
disclose := request.Disclose
if disclose == nil {
disclose = irma.AttributeConDisCon{}
}
action := &OutgoingAction{
"type": "IrmaSession.RequestIssuancePermission",
"sessionId": sh.sessionID,
"serverName": serverName,
"issuedCredentials": request.CredentialInfoList,
"disclosures": disclose,
"disclosuresLabels": request.Labels,
"disclosuresCandidates": candidates,
err := CheckContainsCredentialIdentifiers(request.Disclosure())
if err != nil {
sh.Failure(err)
} else {
action := &OutgoingAction{
"type": "IrmaSession.RequestIssuancePermission",
"sessionId": sh.sessionID,
"serverName": serverName,
"issuedCredentials": request.CredentialInfoList,
"disclosures": disclose,
"disclosuresLabels": request.Labels,
"disclosuresCandidates": candidates,
}

sh.permissionHandler = ph
sendAction(action)
}

sh.permissionHandler = ph
sendAction(action)
}

func (sh *SessionHandler) RequestVerificationPermission(request *irma.DisclosureRequest, candidates [][][]*irma.AttributeIdentifier, serverName irma.TranslatedString, ph irmaclient.PermissionHandler) {
logDebug("Handling RequestVerificationPermission")
action := &OutgoingAction{
"type": "IrmaSession.RequestVerificationPermission",
"sessionId": sh.sessionID,
"serverName": serverName,
"disclosures": request.Disclose,
"disclosuresLabels": request.Labels,
"disclosuresCandidates": candidates,
err := CheckContainsCredentialIdentifiers(request)
if err != nil {
sh.Failure(err)
} else {
action := &OutgoingAction{
"type": "IrmaSession.RequestVerificationPermission",
"sessionId": sh.sessionID,
"serverName": serverName,
"disclosures": request.Disclose,
"disclosuresLabels": request.Labels,
"disclosuresCandidates": candidates,
}

sh.permissionHandler = ph
sendAction(action)
}

sh.permissionHandler = ph
sendAction(action)
}

func (sh *SessionHandler) RequestSignaturePermission(request *irma.SignatureRequest, candidates [][][]*irma.AttributeIdentifier, serverName irma.TranslatedString, ph irmaclient.PermissionHandler) {
logDebug("Handling RequestSignaturePermission")
action := &OutgoingAction{
"type": "IrmaSession.RequestSignaturePermission",
"sessionId": sh.sessionID,
"serverName": serverName,
"disclosures": request.Disclose,
"disclosuresLabels": request.Labels,
"disclosuresCandidates": candidates,
"message": request.Message,
err := CheckContainsCredentialIdentifiers(request.Disclosure())
if err != nil {
sh.Failure(err)
} else {
action := &OutgoingAction{
"type": "IrmaSession.RequestSignaturePermission",
"sessionId": sh.sessionID,
"serverName": serverName,
"disclosures": request.Disclose,
"disclosuresLabels": request.Labels,
"disclosuresCandidates": candidates,
"message": request.Message,
}

sh.permissionHandler = ph
sendAction(action)
}

sh.permissionHandler = ph
sendAction(action)
}

func (sh *SessionHandler) RequestPin(remainingAttempts int, ph irmaclient.PinHandler) {
Expand Down