Skip to content

Commit

Permalink
Refactor: rename binding to pairing
Browse files Browse the repository at this point in the history
  • Loading branch information
ivard committed Nov 5, 2020
1 parent 4f0d836 commit cdcd016
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 135 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.6.0] - 2020-10-14
### Added
* Support for session binding to prevent shoulder surfing (i.e. make it impossible for someone in close physical proximity to a user to scan the QR code that was meant for the user)
* Introduced new frontend endpoints to manage session binding
* Support for device pairing to prevent shoulder surfing (i.e. make it impossible for someone in close physical proximity to a user to scan the QR code that was meant for the user)
* Introduced new frontend endpoints to manage device pairing
* Introduced `irmaclient` protocol version 2.7 including the necessary protocol changes
* The API of the `requestorserver` package has two new functions `SetFrontendOptions` and `BindingCompleted`
* A new server status `"BINDING"` is introduced
* The API of the `requestorserver` package has two new functions `SetFrontendOptions` and `PairingCompleted`
* A new server status `"PAIRING"` is introduced
* A new function `SessionStatus` is available in the API of the `requestorserver` to get a channel with status updates of an IRMA session

### Changes
Expand Down
8 changes: 4 additions & 4 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ var ForceHTTPS = true
const (
sessionChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
sessionTokenLength = 20
bindingCodeChars = "0123456789"
bindingCodeLength = 4
pairingCodeChars = "0123456789"
pairingCodeLength = 4
)

// AssertPathExists returns nil only if it has been successfully
Expand Down Expand Up @@ -278,8 +278,8 @@ func NewSessionToken() string {
return newRandomString(sessionTokenLength, sessionChars)
}

func NewBindingCode() string {
return newRandomString(bindingCodeLength, bindingCodeChars)
func NewPairingCode() string {
return newRandomString(pairingCodeLength, pairingCodeChars)
}

func newRandomString(count int, characterSet string) string {
Expand Down
12 changes: 6 additions & 6 deletions internal/sessiontest/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type TestHandler struct {
expectedServerName *irma.RequestorInfo
wait time.Duration
result string
bindingCodeChan chan string
pairingCodeChan chan string
dismisser irmaclient.SessionDismisser
frontendTransport *irma.HTTPTransport
}
Expand Down Expand Up @@ -153,14 +153,14 @@ func (th TestHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager
func (th TestHandler) RequestPin(remainingAttempts int, callback irmaclient.PinHandler) {
callback(true, "12345")
}
func (th TestHandler) BindingRequired(bindingCode string) {
// Send binding code via channel to calling test. This is done such that
func (th TestHandler) PairingRequired(pairingCode string) {
// Send pairing code via channel to calling test. This is done such that
// calling tests can detect it when this handler is skipped unexpectedly.
if th.bindingCodeChan != nil {
th.bindingCodeChan <- bindingCode
if th.pairingCodeChan != nil {
th.pairingCodeChan <- pairingCode
return
}
th.Failure(&irma.SessionError{ErrorType: irma.ErrorType("Binding required")})
th.Failure(&irma.SessionError{ErrorType: irma.ErrorType("Pairing required")})
}

type SessionResult struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/sessiontest/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestSessionUsingLegacyStorage(t *testing.T) {
sessionHelper(t, getDisclosureRequest(idRoot), "verification", client)
}

func TestWithoutBindingSupport(t *testing.T) {
func TestWithoutPairingSupport(t *testing.T) {
defaultMaxVersion := maxClientVersion
defer func() {
maxClientVersion = defaultMaxVersion
Expand All @@ -53,7 +53,7 @@ func TestWithoutBindingSupport(t *testing.T) {
t.Run("TestIssuanceOptionalZeroLengthAttributes", TestIssuanceOptionalZeroLengthAttributes)
t.Run("TestIssuanceOptionalSetAttributes", TestIssuanceOptionalSetAttributes)
t.Run("TestIssuanceSameAttributesNotSingleton", TestIssuanceSameAttributesNotSingleton)
t.Run("TestIssuanceBinding", TestIssuanceBinding)
t.Run("TestIssuancePairing", TestIssuancePairing)
t.Run("TestLargeAttribute", TestLargeAttribute)
t.Run("TestIssuanceSingletonCredential", TestIssuanceSingletonCredential)
t.Run("TestUnsatisfiableDisclosureSession", TestUnsatisfiableDisclosureSession)
Expand All @@ -68,5 +68,5 @@ func TestWithoutBindingSupport(t *testing.T) {
t.Run("TestStaticQRSession", TestStaticQRSession)
t.Run("TestIssuedCredentialIsStored", TestIssuedCredentialIsStored)
t.Run("TestPOSTSizeLimit", TestPOSTSizeLimit)
t.Run("TestDisableBinding", TestDisableBinding)
t.Run("TestDisablePairing", TestDisablePairing)
}
16 changes: 8 additions & 8 deletions internal/sessiontest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func sessionHelperWithFrontendOptions(
sessiontype string,
client *irmaclient.Client,
frontendOptionsHandler func(handler *TestHandler),
bindingHandler func(handler *TestHandler),
pairingHandler func(handler *TestHandler),
) {
if client == nil {
var handler *TestClientHandler
Expand All @@ -238,8 +238,8 @@ func sessionHelperWithFrontendOptions(
expectedServerName: expectedRequestorInfo(t, client.Configuration),
}

if frontendOptionsHandler != nil || bindingHandler != nil {
h.bindingCodeChan = make(chan string)
if frontendOptionsHandler != nil || pairingHandler != nil {
h.pairingCodeChan = make(chan string)
h.frontendTransport = irma.NewHTTPTransport(qr.URL, false)
h.frontendTransport.SetHeader(irma.AuthorizationHeader, string(frontendAuth))
}
Expand All @@ -251,8 +251,8 @@ func sessionHelperWithFrontendOptions(
require.NoError(t, err)
h.dismisser = client.NewSession(string(qrjson), h)

if bindingHandler != nil {
bindingHandler(h)
if pairingHandler != nil {
pairingHandler(h)
}

if result := <-c; result != nil {
Expand All @@ -277,13 +277,13 @@ func extractPrivateField(i interface{}, field string) interface{} {
return reflect.NewAt(rct.Type(), unsafe.Pointer(rct.UnsafeAddr())).Elem().Interface()
}

func setBindingMethod(method irma.BindingMethod, handler *TestHandler) string {
func setPairingMethod(method irma.PairingMethod, handler *TestHandler) string {
optionsRequest := irma.NewOptionsRequest()
optionsRequest.BindingMethod = method
optionsRequest.PairingMethod = method
options := &irma.SessionOptions{}
err := handler.frontendTransport.Post("frontend/options", options, optionsRequest)
require.NoError(handler.t, err)
return options.BindingCode
return options.PairingCode
}

func expectedRequestorInfo(t *testing.T, conf *irma.Configuration) *irma.RequestorInfo {
Expand Down
30 changes: 15 additions & 15 deletions internal/sessiontest/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,32 @@ func TestIssuanceSameAttributesNotSingleton(t *testing.T) {
require.Equal(t, prevLen+1, len(client.CredentialInfoList()))
}

func TestIssuanceBinding(t *testing.T) {
func TestIssuancePairing(t *testing.T) {
id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
request := getCombinedIssuanceRequest(id)

var bindingCode string
var pairingCode string
frontendOptionsHandler := func(handler *TestHandler) {
bindingCode = setBindingMethod(irma.BindingMethodPin, handler)
pairingCode = setPairingMethod(irma.PairingMethodPin, handler)
}
bindingHandler := func(handler *TestHandler) {
// Below protocol version 2.7 binding is not supported, so then the binding stage is expected to be skipped.
pairingHandler := func(handler *TestHandler) {
// Below protocol version 2.7 pairing is not supported, so then the pairing stage is expected to be skipped.
if extractClientMaxVersion(handler.client).Below(2, 7) {
return
}

require.Equal(t, bindingCode, <-handler.bindingCodeChan)
require.Equal(t, pairingCode, <-handler.pairingCodeChan)

// Check whether access to request endpoint is denied as long as binding is not finished
// Check whether access to request endpoint is denied as long as pairing is not finished
clientTransport := extractClientTransport(handler.dismisser)
err := clientTransport.Get("request", struct{}{})
require.Error(t, err)
sessionErr := err.(*irma.SessionError)
require.Equal(t, irma.ErrorApi, sessionErr.ErrorType)
require.Equal(t, server.ErrorBindingRequired.Status, sessionErr.RemoteError.Status)
require.Equal(t, string(server.ErrorBindingRequired.Type), sessionErr.RemoteError.ErrorName)
require.Equal(t, server.ErrorPairingRequired.Status, sessionErr.RemoteError.Status)
require.Equal(t, string(server.ErrorPairingRequired.Type), sessionErr.RemoteError.ErrorName)

// Check whether binding cannot be disabled again after client is connected.
// Check whether pairing cannot be disabled again after client is connected.
request := irma.NewOptionsRequest()
result := &irma.SessionOptions{}
err = handler.frontendTransport.Post("frontend/options", result, request)
Expand All @@ -154,10 +154,10 @@ func TestIssuanceBinding(t *testing.T) {
require.Equal(t, server.ErrorUnexpectedRequest.Status, sessionErr.RemoteError.Status)
require.Equal(t, string(server.ErrorUnexpectedRequest.Type), sessionErr.RemoteError.ErrorName)

err = handler.frontendTransport.Post("frontend/bindingcompleted", nil, nil)
err = handler.frontendTransport.Post("frontend/pairingcompleted", nil, nil)
require.NoError(t, err)
}
sessionHelperWithFrontendOptions(t, request, "issue", nil, frontendOptionsHandler, bindingHandler)
sessionHelperWithFrontendOptions(t, request, "issue", nil, frontendOptionsHandler, pairingHandler)
}

func TestLargeAttribute(t *testing.T) {
Expand Down Expand Up @@ -630,13 +630,13 @@ func TestPOSTSizeLimit(t *testing.T) {
require.Equal(t, "http: request body too large", rerr.Message)
}

func TestDisableBinding(t *testing.T) {
func TestDisablePairing(t *testing.T) {
id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
request := getCombinedIssuanceRequest(id)

frontendOptionsHandler := func(handler *TestHandler) {
_ = setBindingMethod(irma.BindingMethodPin, handler)
_ = setBindingMethod(irma.BindingMethodNone, handler)
_ = setPairingMethod(irma.PairingMethodPin, handler)
_ = setPairingMethod(irma.PairingMethodNone, handler)
}
sessionHelperWithFrontendOptions(t, request, "issue", nil, frontendOptionsHandler, nil)
}
Loading

0 comments on commit cdcd016

Please sign in to comment.