Commit 1ea7670b authored by David Venhoek's avatar David Venhoek
Browse files

Added pinchange support to irmago.

parent 80a39715
......@@ -80,10 +80,16 @@ type KeyshareHandler interface {
EnrollmentSuccess(manager irma.SchemeManagerIdentifier)
}
type ChangepinHandler interface {
ChangepinFailure(manager irma.SchemeManagerIdentifier, err error)
ChangepinSuccess(manager irma.SchemeManagerIdentifier)
}
// ClientHandler informs the user that the configuration or the list of attributes
// that this client uses has been updated.
type ClientHandler interface {
KeyshareHandler
ChangepinHandler
UpdateConfiguration(new *irma.IrmaIdentifierSet)
UpdateAttributes()
......@@ -738,6 +744,41 @@ func (client *Client) keyshareEnrollWorker(managerID irma.SchemeManagerIdentifie
return nil
}
func (client *Client) KeyshareChangepin(manager irma.SchemeManagerIdentifier, oldpin string, newpin string) {
go func() {
err := client.keyshareChangepinWorker(manager, oldpin, newpin)
if err != nil {
client.handler.ChangepinFailure(manager, err)
} else {
client.handler.ChangepinSuccess(manager)
}
}()
}
func (client *Client) keyshareChangepinWorker(managerID irma.SchemeManagerIdentifier, oldpin string, newpin string) error {
kss, ok := client.keyshareServers[managerID]
if !ok {
return errors.New("Unknown keyshare server")
}
transport := irma.NewHTTPTransport(kss.URL)
message := keysharePinchange{
Username: kss.Username,
Oldpin: kss.HashedPin(oldpin),
Newpin: kss.HashedPin(newpin),
}
res := &keysharePinStatus{}
err := transport.Post("users/change/pin", res, message)
if err != nil {
return err
}
if res.Status != kssPinSuccess {
return errors.New("Pin change rejected")
}
return nil
}
// KeyshareRemove unenrolls the keyshare server of the specified scheme manager.
func (client *Client) KeyshareRemove(manager irma.SchemeManagerIdentifier) error {
if _, contains := client.keyshareServers[manager]; !contains {
......
......@@ -41,6 +41,19 @@ func (i *TestClientHandler) EnrollmentFailure(manager irma.SchemeManagerIdentifi
i.t.Fatal(err)
}
}
func (i *TestClientHandler) ChangepinSuccess(manager irma.SchemeManagerIdentifier) {
select {
case i.c <- nil: // nop
default: // nop
}
}
func (i *TestClientHandler) ChangepinFailure(manager irma.SchemeManagerIdentifier, err error) {
select {
case i.c <- err: //nop
default:
i.t.Fatal(err)
}
}
func parseStorage(t *testing.T) *Client {
require.NoError(t, fs.CopyDirectory("../testdata/teststorage", "../testdata/storage/test"))
......
......@@ -62,6 +62,12 @@ type keyshareEnrollment struct {
Language string `json:"language"`
}
type keysharePinchange struct {
Username string `json:"id"`
Oldpin string `json:"oldpin"`
Newpin string `json:"newpin"`
}
type keyshareAuthorization struct {
Status string `json:"status"`
Candidates []string `json:"candidates"`
......
......@@ -366,6 +366,16 @@ func keyshareSessions(t *testing.T, client *Client) {
sessionHelper(t, jwt, "signature", client)
}
// Test pinchange interaction
func TestKeyshareChangepin(t *testing.T) {
client := parseStorage(t)
require.NoError(t, client.keyshareChangepinWorker(irma.NewSchemeManagerIdentifier("test"), "12345", "54321"));
require.NoError(t, client.keyshareChangepinWorker(irma.NewSchemeManagerIdentifier("test"), "54321", "12345"));
test.ClearTestStorage(t)
}
// Enroll at a keyshare server and do an issuance, disclosure,
// and issuance session, also using irma-demo credentials deserialized from Android storage
func TestKeyshareEnrollmentAndSessions(t *testing.T) {
......
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