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

Renaming packages

parent 45250a0d
......@@ -9,8 +9,8 @@ import (
"github.com/Sirupsen/logrus"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/test"
"github.com/privacybydesign/irmago/irmaserver"
"github.com/privacybydesign/irmago/irmaserver/irmarequestor"
"github.com/privacybydesign/irmago/server"
"github.com/privacybydesign/irmago/server/irmarequestor"
"github.com/stretchr/testify/require"
)
......@@ -22,7 +22,7 @@ func StartIrmaServer(t *testing.T) {
logger := logrus.New()
logger.Level = logrus.WarnLevel
logger.Formatter = &logrus.TextFormatter{}
require.NoError(t, irmarequestor.Initialize(&irmaserver.Configuration{
require.NoError(t, irmarequestor.Initialize(&server.Configuration{
Logger: logger,
IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"),
PrivateKeysPath: filepath.Join(testdata, "privatekeys"),
......@@ -40,7 +40,7 @@ func StopIrmaServer() {
irmaServer.Close()
}
func newSessionHelper(t *testing.T, request irma.SessionRequest) *irmaserver.SessionResult {
func newSessionHelper(t *testing.T, request irma.SessionRequest) *server.SessionResult {
StartIrmaServer(t)
defer StopIrmaServer()
......@@ -48,9 +48,9 @@ func newSessionHelper(t *testing.T, request irma.SessionRequest) *irmaserver.Ses
defer test.ClearTestStorage(t)
clientChan := make(chan *SessionResult)
serverChan := make(chan *irmaserver.SessionResult)
serverChan := make(chan *server.SessionResult)
qr, token, err := irmarequestor.StartSession(request, func(result *irmaserver.SessionResult) {
qr, token, err := irmarequestor.StartSession(request, func(result *server.SessionResult) {
serverChan <- result
})
require.NoError(t, err)
......
......@@ -9,8 +9,8 @@ import (
"github.com/Sirupsen/logrus"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/test"
"github.com/privacybydesign/irmago/irmaserver"
"github.com/privacybydesign/irmago/irmaserver/server"
"github.com/privacybydesign/irmago/server"
"github.com/privacybydesign/irmago/server/irmaserver"
"github.com/stretchr/testify/require"
)
......@@ -22,8 +22,8 @@ func StartRequestorServer() {
logger.Formatter = &logrus.TextFormatter{}
go func() {
err := server.Start(&server.Configuration{
Configuration: &irmaserver.Configuration{
err := irmaserver.Start(&irmaserver.Configuration{
Configuration: &server.Configuration{
Logger: logger,
IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"),
PrivateKeysPath: filepath.Join(testdata, "privatekeys"),
......@@ -38,10 +38,10 @@ func StartRequestorServer() {
}
func StopRequestorServer() {
server.Stop()
irmaserver.Stop()
}
func serverSessionHelper(t *testing.T, request irma.SessionRequest) *irmaserver.SessionResult {
func serverSessionHelper(t *testing.T, request irma.SessionRequest) *server.SessionResult {
client := parseStorage(t)
defer test.ClearTestStorage(t)
......@@ -64,7 +64,7 @@ func serverSessionHelper(t *testing.T, request irma.SessionRequest) *irmaserver.
require.NoError(t, clientResult.Err)
}
var result irmaserver.SessionResult
var result server.SessionResult
transport.Get("result/"+token, &result)
return &result
}
......
package irmaserver
package server
import (
"encoding/json"
......
......@@ -13,10 +13,10 @@ import (
"github.com/mhe/gabi"
"github.com/mhe/gabi/big"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/irmaserver"
"github.com/privacybydesign/irmago/server"
)
func Initialize(configuration *irmaserver.Configuration) error {
func Initialize(configuration *server.Configuration) error {
conf = configuration
if conf.Logger == nil {
......@@ -24,7 +24,7 @@ func Initialize(configuration *irmaserver.Configuration) error {
conf.Logger.Level = logrus.DebugLevel
conf.Logger.Formatter = &logrus.TextFormatter{}
}
irmaserver.Logger = conf.Logger
server.Logger = conf.Logger
if conf.IrmaConfiguration == nil {
var err error
......@@ -102,7 +102,7 @@ func StartSession(request irma.SessionRequest) (*irma.Qr, string, error) {
}, session.token, nil
}
func GetSessionResult(token string) *irmaserver.SessionResult {
func GetSessionResult(token string) *server.SessionResult {
session := sessions.get(token)
if session == nil {
return nil
......@@ -115,7 +115,7 @@ func HandleProtocolMessage(
method string,
headers map[string][]string,
message []byte,
) (status int, output []byte, result *irmaserver.SessionResult) {
) (status int, output []byte, result *server.SessionResult) {
// Parse path into session and action
if len(path) > 0 { // Remove any starting and trailing slash
if path[0] == '/' {
......@@ -130,7 +130,7 @@ func HandleProtocolMessage(
matches := pattern.FindStringSubmatch(path)
if len(matches) != 3 {
conf.Logger.Warnf("Invalid URL: %s", path)
status, output = irmaserver.JsonResponse(nil, irmaserver.RemoteError(irmaserver.ErrorInvalidRequest, ""))
status, output = server.JsonResponse(nil, server.RemoteError(server.ErrorInvalidRequest, ""))
return
}
......@@ -140,7 +140,7 @@ func HandleProtocolMessage(
session := sessions.get(token)
if session == nil {
conf.Logger.Warnf("Session not found: %s", token)
status, output = irmaserver.JsonResponse(nil, irmaserver.RemoteError(irmaserver.ErrorSessionUnknown, ""))
status, output = server.JsonResponse(nil, server.RemoteError(server.ErrorSessionUnknown, ""))
return
}
session.Lock()
......@@ -170,53 +170,53 @@ func HandleProtocolMessage(
min := &irma.ProtocolVersion{}
max := &irma.ProtocolVersion{}
if err := json.Unmarshal([]byte(h.Get(irma.MinVersionHeader)), min); err != nil {
status, output = irmaserver.JsonResponse(nil, session.fail(irmaserver.ErrorMalformedInput, err.Error()))
status, output = server.JsonResponse(nil, session.fail(server.ErrorMalformedInput, err.Error()))
return
}
if err := json.Unmarshal([]byte(h.Get(irma.MaxVersionHeader)), max); err != nil {
status, output = irmaserver.JsonResponse(nil, session.fail(irmaserver.ErrorMalformedInput, err.Error()))
status, output = server.JsonResponse(nil, session.fail(server.ErrorMalformedInput, err.Error()))
return
}
status, output = irmaserver.JsonResponse(session.handleGetRequest(min, max))
status, output = server.JsonResponse(session.handleGetRequest(min, max))
return
}
status, output = irmaserver.JsonResponse(nil, session.fail(irmaserver.ErrorInvalidRequest, ""))
status, output = server.JsonResponse(nil, session.fail(server.ErrorInvalidRequest, ""))
return
default:
if method != http.MethodPost {
status, output = irmaserver.JsonResponse(nil, session.fail(irmaserver.ErrorInvalidRequest, ""))
status, output = server.JsonResponse(nil, session.fail(server.ErrorInvalidRequest, ""))
return
}
if verb == "commitments" && session.action == irma.ActionIssuing {
commitments := &gabi.IssueCommitmentMessage{}
if err := irma.UnmarshalValidate(message, commitments); err != nil {
status, output = irmaserver.JsonResponse(nil, session.fail(irmaserver.ErrorMalformedInput, ""))
status, output = server.JsonResponse(nil, session.fail(server.ErrorMalformedInput, ""))
return
}
status, output = irmaserver.JsonResponse(session.handlePostCommitments(commitments))
status, output = server.JsonResponse(session.handlePostCommitments(commitments))
return
}
if verb == "proofs" && session.action == irma.ActionDisclosing {
proofs := gabi.ProofList{}
if err := irma.UnmarshalValidate(message, &proofs); err != nil {
status, output = irmaserver.JsonResponse(nil, session.fail(irmaserver.ErrorMalformedInput, ""))
status, output = server.JsonResponse(nil, session.fail(server.ErrorMalformedInput, ""))
return
}
status, output = irmaserver.JsonResponse(session.handlePostProofs(proofs))
status, output = server.JsonResponse(session.handlePostProofs(proofs))
return
}
if verb == "proofs" && session.action == irma.ActionSigning {
signature := &irma.SignedMessage{}
if err := irma.UnmarshalValidate(message, signature); err != nil {
status, output = irmaserver.JsonResponse(nil, session.fail(irmaserver.ErrorMalformedInput, ""))
status, output = server.JsonResponse(nil, session.fail(server.ErrorMalformedInput, ""))
return
}
status, output = irmaserver.JsonResponse(session.handlePostSignature(signature))
status, output = server.JsonResponse(session.handlePostSignature(signature))
return
}
status, output = irmaserver.JsonResponse(nil, session.fail(irmaserver.ErrorInvalidRequest, ""))
status, output = server.JsonResponse(nil, session.fail(server.ErrorInvalidRequest, ""))
return
}
}
......@@ -3,7 +3,7 @@ package backend
import (
"github.com/mhe/gabi"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/irmaserver"
"github.com/privacybydesign/irmago/server"
)
// This file contains the handler functions for the protocol messages, receiving and returning normally
......@@ -11,7 +11,7 @@ import (
// Maintaining the session state is done here, as well as checking whether the session is in the
// appropriate status before handling the request.
var conf *irmaserver.Configuration
var conf *server.Configuration
func (session *session) handleDelete() {
if session.finished() {
......@@ -19,29 +19,29 @@ func (session *session) handleDelete() {
}
session.markAlive()
session.result = &irmaserver.SessionResult{Token: session.token, Status: irmaserver.StatusCancelled}
session.setStatus(irmaserver.StatusCancelled)
session.result = &server.SessionResult{Token: session.token, Status: server.StatusCancelled}
session.setStatus(server.StatusCancelled)
}
func (session *session) handleGetRequest(min, max *irma.ProtocolVersion) (irma.SessionRequest, *irma.RemoteError) {
if session.status != irmaserver.StatusInitialized {
return nil, irmaserver.RemoteError(irmaserver.ErrorUnexpectedRequest, "Session already started")
if session.status != server.StatusInitialized {
return nil, server.RemoteError(server.ErrorUnexpectedRequest, "Session already started")
}
session.markAlive()
var err error
if session.version, err = chooseProtocolVersion(min, max); err != nil {
return nil, session.fail(irmaserver.ErrorProtocolVersion, "")
return nil, session.fail(server.ErrorProtocolVersion, "")
}
session.request.SetVersion(session.version)
session.setStatus(irmaserver.StatusConnected)
session.setStatus(server.StatusConnected)
return session.request, nil
}
func (session *session) handlePostSignature(signature *irma.SignedMessage) (*irma.ProofStatus, *irma.RemoteError) {
if session.status != irmaserver.StatusConnected {
return nil, irmaserver.RemoteError(irmaserver.ErrorUnexpectedRequest, "Session not yet started or already finished")
if session.status != server.StatusConnected {
return nil, server.RemoteError(server.ErrorUnexpectedRequest, "Session not yet started or already finished")
}
session.markAlive()
......@@ -51,21 +51,21 @@ func (session *session) handlePostSignature(signature *irma.SignedMessage) (*irm
session.result.Disclosed, session.result.ProofStatus, err = signature.Verify(
conf.IrmaConfiguration, session.request.(*irma.SignatureRequest))
if err == nil {
session.setStatus(irmaserver.StatusDone)
session.setStatus(server.StatusDone)
} else {
session.setStatus(irmaserver.StatusCancelled)
session.setStatus(server.StatusCancelled)
if err == irma.ErrorMissingPublicKey {
rerr = session.fail(irmaserver.ErrorUnknownPublicKey, err.Error())
rerr = session.fail(server.ErrorUnknownPublicKey, err.Error())
} else {
rerr = session.fail(irmaserver.ErrorUnknown, err.Error())
rerr = session.fail(server.ErrorUnknown, err.Error())
}
}
return &session.result.ProofStatus, rerr
}
func (session *session) handlePostProofs(proofs gabi.ProofList) (*irma.ProofStatus, *irma.RemoteError) {
if session.status != irmaserver.StatusConnected {
return nil, irmaserver.RemoteError(irmaserver.ErrorUnexpectedRequest, "Session not yet started or already finished")
if session.status != server.StatusConnected {
return nil, server.RemoteError(server.ErrorUnexpectedRequest, "Session not yet started or already finished")
}
session.markAlive()
......@@ -74,35 +74,35 @@ func (session *session) handlePostProofs(proofs gabi.ProofList) (*irma.ProofStat
session.result.Disclosed, session.result.ProofStatus, err = irma.ProofList(proofs).Verify(
conf.IrmaConfiguration, session.request.(*irma.DisclosureRequest))
if err == nil {
session.setStatus(irmaserver.StatusDone)
session.setStatus(server.StatusDone)
} else {
session.setStatus(irmaserver.StatusCancelled)
session.setStatus(server.StatusCancelled)
if err == irma.ErrorMissingPublicKey {
rerr = session.fail(irmaserver.ErrorUnknownPublicKey, err.Error())
rerr = session.fail(server.ErrorUnknownPublicKey, err.Error())
} else {
rerr = session.fail(irmaserver.ErrorUnknown, err.Error())
rerr = session.fail(server.ErrorUnknown, err.Error())
}
}
return &session.result.ProofStatus, rerr
}
func (session *session) handlePostCommitments(commitments *gabi.IssueCommitmentMessage) ([]*gabi.IssueSignatureMessage, *irma.RemoteError) {
if session.status != irmaserver.StatusConnected {
return nil, irmaserver.RemoteError(irmaserver.ErrorUnexpectedRequest, "Session not yet started or already finished")
if session.status != server.StatusConnected {
return nil, server.RemoteError(server.ErrorUnexpectedRequest, "Session not yet started or already finished")
}
session.markAlive()
request := session.request.(*irma.IssuanceRequest)
discloseCount := len(request.Disclose)
if len(commitments.Proofs) != len(request.Credentials)+discloseCount {
return nil, session.fail(irmaserver.ErrorAttributesMissing, "")
return nil, session.fail(server.ErrorAttributesMissing, "")
}
// Compute list of public keys against which to verify the received proofs
disclosureproofs := irma.ProofList(commitments.Proofs[:discloseCount])
pubkeys, err := disclosureproofs.ExtractPublicKeys(conf.IrmaConfiguration)
if err != nil {
return nil, session.fail(irmaserver.ErrorInvalidProofs, err.Error())
return nil, session.fail(server.ErrorInvalidProofs, err.Error())
}
for _, cred := range request.Credentials {
iss := cred.CredentialTypeID.IssuerIdentifier()
......@@ -117,7 +117,7 @@ func (session *session) handlePostCommitments(commitments *gabi.IssueCommitmentM
if conf.IrmaConfiguration.SchemeManagers[schemeid].Distributed() {
proofP, err := session.getProofP(commitments, schemeid)
if err != nil {
return nil, session.fail(irmaserver.ErrorKeyshareProofMissing, err.Error())
return nil, session.fail(server.ErrorKeyshareProofMissing, err.Error())
}
proof.MergeProofP(proofP, pubkey)
}
......@@ -128,16 +128,16 @@ func (session *session) handlePostCommitments(commitments *gabi.IssueCommitmentM
conf.IrmaConfiguration, request.Disclose, request.Context, request.Nonce, pubkeys, false)
if err != nil {
if err == irma.ErrorMissingPublicKey {
return nil, session.fail(irmaserver.ErrorUnknownPublicKey, "")
return nil, session.fail(server.ErrorUnknownPublicKey, "")
} else {
return nil, session.fail(irmaserver.ErrorUnknown, "")
return nil, session.fail(server.ErrorUnknown, "")
}
}
if session.result.ProofStatus == irma.ProofStatusExpired {
return nil, session.fail(irmaserver.ErrorAttributesExpired, "")
return nil, session.fail(server.ErrorAttributesExpired, "")
}
if session.result.ProofStatus != irma.ProofStatusValid {
return nil, session.fail(irmaserver.ErrorInvalidProofs, "")
return nil, session.fail(server.ErrorInvalidProofs, "")
}
// Compute CL signatures
......@@ -149,15 +149,15 @@ func (session *session) handlePostCommitments(commitments *gabi.IssueCommitmentM
proof := commitments.Proofs[i+discloseCount].(*gabi.ProofU)
attributes, err := cred.AttributeList(conf.IrmaConfiguration, 0x03)
if err != nil {
return nil, session.fail(irmaserver.ErrorIssuanceFailed, err.Error())
return nil, session.fail(server.ErrorIssuanceFailed, err.Error())
}
sig, err := issuer.IssueSignature(proof.U, attributes.Ints, commitments.Nonce2)
if err != nil {
return nil, session.fail(irmaserver.ErrorIssuanceFailed, err.Error())
return nil, session.fail(server.ErrorIssuanceFailed, err.Error())
}
sigs = append(sigs, sig)
}
session.setStatus(irmaserver.StatusDone)
session.setStatus(server.StatusDone)
return sigs, nil
}
......@@ -8,30 +8,30 @@ import (
"github.com/go-errors/errors"
"github.com/mhe/gabi"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/irmaserver"
"github.com/privacybydesign/irmago/server"
)
// Session helpers
func (session *session) finished() bool {
return session.status == irmaserver.StatusDone ||
session.status == irmaserver.StatusCancelled ||
session.status == irmaserver.StatusTimeout
return session.status == server.StatusDone ||
session.status == server.StatusCancelled ||
session.status == server.StatusTimeout
}
func (session *session) markAlive() {
session.lastActive = time.Now()
}
func (session *session) setStatus(status irmaserver.Status) {
func (session *session) setStatus(status server.Status) {
session.status = status
session.result.Status = status
}
func (session *session) fail(err irmaserver.Error, message string) *irma.RemoteError {
rerr := irmaserver.RemoteError(err, message)
session.setStatus(irmaserver.StatusCancelled)
session.result = &irmaserver.SessionResult{Err: rerr, Token: session.token, Status: irmaserver.StatusCancelled}
func (session *session) fail(err server.Error, message string) *irma.RemoteError {
rerr := server.RemoteError(err, message)
session.setStatus(server.StatusCancelled)
session.result = &server.SessionResult{Err: rerr, Token: session.token, Status: server.StatusCancelled}
return rerr
}
......
......@@ -8,7 +8,7 @@ import (
"github.com/mhe/gabi"
"github.com/mhe/gabi/big"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/irmaserver"
"github.com/privacybydesign/irmago/server"
)
type session struct {
......@@ -19,10 +19,10 @@ type session struct {
version *irma.ProtocolVersion
request irma.SessionRequest
status irmaserver.Status
status server.Status
lastActive time.Time
returned bool
result *irmaserver.SessionResult
result *server.SessionResult
kssProofs map[irma.SchemeManagerIdentifier]*gabi.ProofP
}
......@@ -86,7 +86,7 @@ func (s memorySessionStore) deleteExpired() {
if !session.finished() {
conf.Logger.Infof("Session %s expired", token)
session.markAlive()
session.setStatus(irmaserver.StatusTimeout)
session.setStatus(server.StatusTimeout)
} else {
conf.Logger.Infof("Deleting %s", token)
expired = append(expired, token)
......@@ -118,11 +118,11 @@ func newSession(action irma.Action, request irma.SessionRequest) *session {
request: request,
lastActive: time.Now(),
token: token,
result: &irmaserver.SessionResult{
result: &server.SessionResult{
Token: token,
},
}
s.setStatus(irmaserver.StatusInitialized)
s.setStatus(server.StatusInitialized)
nonce, _ := gabi.RandomBigInt(gabi.DefaultSystemParameters[2048].Lstatzk)
request.SetNonce(nonce)
request.SetContext(one)
......
package irmaserver
package server
type Error struct {
Type ErrorType `json:"error"`
......
......@@ -5,15 +5,15 @@ import (
"net/http"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/irmaserver"
"github.com/privacybydesign/irmago/irmaserver/backend"
"github.com/privacybydesign/irmago/server"
"github.com/privacybydesign/irmago/server/backend"
)
type SessionHandler func(*irmaserver.SessionResult)
type SessionHandler func(*server.SessionResult)
var handlers = make(map[string]SessionHandler)
func Initialize(configuration *irmaserver.Configuration) error {
func Initialize(configuration *server.Configuration) error {
return backend.Initialize(configuration)
}
......@@ -28,7 +28,7 @@ func StartSession(request irma.SessionRequest, handler SessionHandler) (*irma.Qr
return qr, token, nil
}
func GetSessionResult(token string) *irmaserver.SessionResult {
func GetSessionResult(token string) *server.SessionResult {
return backend.GetSessionResult(token)
}
......
......@@ -6,8 +6,8 @@ import (
"strconv"
"github.com/go-errors/errors"
"github.com/privacybydesign/irmago/irmaserver"
"github.com/privacybydesign/irmago/irmaserver/server"
"github.com/privacybydesign/irmago/server"
"github.com/privacybydesign/irmago/server/irmaserver"
)
func main() {
......@@ -31,8 +31,8 @@ func main() {
return
}
err = server.Start(&server.Configuration{
Configuration: &irmaserver.Configuration{
err = irmaserver.Start(&irmaserver.Configuration{
Configuration: &server.Configuration{
IrmaConfigurationPath: os.Args[2],
},
Port: port,
......
package server
package irmaserver
import (
"fmt"
......@@ -8,16 +8,16 @@ import (
"github.com/go-chi/chi"
"github.com/go-errors/errors"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/irmaserver"
"github.com/privacybydesign/irmago/irmaserver/irmarequestor"
"github.com/privacybydesign/irmago/server"
"github.com/privacybydesign/irmago/server/irmarequestor"
)
type Configuration struct {
*irmaserver.Configuration
*server.Configuration
Port int
}
var server *http.Server
var s *http.Server
// Start the server. If successful then it will not return until Stop() is called.
func Start(conf *Configuration) error {
......@@ -36,8 +36,8 @@ func Start(conf *Configuration) error {
router.Get("/result/{token}", handleResult)
// Start server
server = &http.Server{Addr: fmt.Sprintf(":%d", conf.Port), Handler: router}
err := server.ListenAndServe()
s = &http.Server{Addr: fmt.Sprintf(":%d", conf.Port), Handler: router}
err := s.ListenAndServe()
if err == http.ErrServerClosed {
return nil // Server was closed normally
}
......@@ -45,46 +45,46 @@ func Start(conf *Configuration) error {
}
func Stop() {
server.Close()
s.Close()
}
func handleCreate(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
irmaserver.WriteError(w, irmaserver.ErrorInvalidRequest, err.Error())
server.WriteError(w, server.ErrorInvalidRequest, err.Error())
return
}
request, err := parseRequest(body)
if err != nil {
irmaserver.WriteError(w, irmaserver.ErrorInvalidRequest, err.Error())
server.WriteError(w, server.ErrorInvalidRequest, err.Error())
return
}
qr, _, err := irmarequestor.StartSession(request, nil)
if err != nil {
irmaserver.WriteError(w, irmaserver.ErrorInvalidRequest, err.Error())
server.WriteError(w, server.ErrorInvalidRequest, err.Error())
return
}
irmaserver.WriteJson(w, qr)
server.WriteJson(w, qr)
}
func handleStatus(w http.ResponseWriter, r *http.Request) {
res := irmarequestor.GetSessionResult(chi.URLParam(r, "token"))
if res == nil {
irmaserver.WriteError(w, irmaserver.ErrorSessionUnknown, "")
server.WriteError(w, server.ErrorSessionUnknown, "")