Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
ebb610e8
Commit
ebb610e8
authored
Aug 29, 2017
by
Sietse Ringers
Browse files
Move session request from protocol to irmago
parent
1e108599
Changes
9
Hide whitespace changes
Inline
Side-by-side
irmago_test.go
View file @
ebb610e8
...
...
@@ -9,6 +9,7 @@ import (
"encoding/json"
"github.com/credentials/irmago"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
...
...
@@ -235,3 +236,14 @@ func TestCandidates(t *testing.T) {
teardown
(
t
)
}
func
TestTimestamp
(
t
*
testing
.
T
)
{
mytime
:=
irmago
.
Timestamp
(
time
.
Unix
(
1500000000
,
0
))
timestruct
:=
struct
{
Time
*
irmago
.
Timestamp
}{
Time
:
&
mytime
}
bytes
,
err
:=
json
.
Marshal
(
timestruct
)
require
.
NoError
(
t
,
err
)
timestruct
=
struct
{
Time
*
irmago
.
Timestamp
}{}
require
.
NoError
(
t
,
json
.
Unmarshal
(
bytes
,
&
timestruct
))
require
.
Equal
(
t
,
time
.
Time
(
*
timestruct
.
Time
)
.
Unix
(),
int64
(
1500000000
))
}
manager.go
View file @
ebb610e8
...
...
@@ -280,12 +280,12 @@ func (cm *CredentialManager) groupCredentials(choice *DisclosureChoice) (map[Cre
return
grouped
,
nil
}
type
S
essionRequest
interface
{
type
s
essionRequest
interface
{
GetNonce
()
*
big
.
Int
GetContext
()
*
big
.
Int
}
func
(
cm
*
CredentialManager
)
Proofs
(
choice
*
DisclosureChoice
,
request
S
essionRequest
,
issig
bool
)
(
gabi
.
ProofList
,
error
)
{
func
(
cm
*
CredentialManager
)
Proofs
(
choice
*
DisclosureChoice
,
request
s
essionRequest
,
issig
bool
)
(
gabi
.
ProofList
,
error
)
{
todisclose
,
err
:=
cm
.
groupCredentials
(
choice
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -308,11 +308,13 @@ type issuanceState struct {
nonce2
*
big
.
Int
}
func
(
cm
*
CredentialManager
)
IssueCommitments
(
choice
*
DisclosureChoice
,
request
S
essionRequest
)
(
gabi
.
IssueCommitmentMessage
,
error
)
{
func
(
cm
*
CredentialManager
)
IssueCommitments
(
choice
*
DisclosureChoice
,
request
s
essionRequest
)
(
*
gabi
.
IssueCommitmentMessage
,
error
)
{
cm
.
issuance
=
issuanceState
{[]
*
gabi
.
CredentialBuilder
{},
nil
}
todisclose
,
err
:=
cm
.
groupCredentials
(
choice
)
_
,
err
:=
cm
.
groupCredentials
(
choice
)
if
err
!=
nil
{
return
nil
,
err
}
return
nil
,
nil
}
protocol/messages.go
View file @
ebb610e8
...
...
@@ -2,17 +2,12 @@ package protocol
import
(
"fmt"
"strconv"
"time"
"math/big"
"github.com/credentials/irmago"
)
// Timestamp is a time.Time that marshals to Unix timestamps.
type
Timestamp
time
.
Time
// Status encodes the status of an IRMA session (e.g., connected).
type
Status
string
...
...
@@ -88,20 +83,3 @@ func (e *Error) Error() string {
return
string
(
e
.
ErrorCode
)
}
}
// MarshalJSON marshals a timestamp.
func
(
t
*
Timestamp
)
MarshalJSON
()
([]
byte
,
error
)
{
ts
:=
time
.
Time
(
*
t
)
.
Unix
()
stamp
:=
fmt
.
Sprint
(
ts
)
return
[]
byte
(
stamp
),
nil
}
// UnmarshalJSON unmarshals a timestamp.
func
(
t
*
Timestamp
)
UnmarshalJSON
(
b
[]
byte
)
error
{
ts
,
err
:=
strconv
.
Atoi
(
string
(
b
))
if
err
!=
nil
{
return
err
}
*
t
=
Timestamp
(
time
.
Unix
(
int64
(
ts
),
0
))
return
nil
}
protocol/protocol_test.go
View file @
ebb610e8
...
...
@@ -4,23 +4,10 @@ import (
"encoding/json"
"testing"
"time"
"github.com/credentials/irmago"
"github.com/stretchr/testify/require"
)
func
TestTimestamp
(
t
*
testing
.
T
)
{
mytime
:=
Timestamp
(
time
.
Unix
(
1500000000
,
0
))
timestruct
:=
struct
{
Time
*
Timestamp
}{
Time
:
&
mytime
}
bytes
,
err
:=
json
.
Marshal
(
timestruct
)
require
.
NoError
(
t
,
err
)
timestruct
=
struct
{
Time
*
Timestamp
}{}
require
.
NoError
(
t
,
json
.
Unmarshal
(
bytes
,
&
timestruct
))
require
.
Equal
(
t
,
time
.
Time
(
*
timestruct
.
Time
)
.
Unix
(),
int64
(
1500000000
))
}
func
TestServiceProvider
(
t
*
testing
.
T
)
{
var
spjwt
ServiceProviderJwt
...
...
protocol/requests.go
View file @
ebb610e8
package
protocol
import
(
"encoding/asn1"
"math/big"
"time"
"crypto/sha256"
"log"
"github.com/credentials/irmago"
)
type
SessionRequest
struct
{
Context
*
big
.
Int
`json:"nonce"`
Nonce
*
big
.
Int
`json:"context"`
}
type
DisclosureRequest
struct
{
SessionRequest
Content
irmago
.
AttributeDisjunctionList
`json:"content"`
}
type
SignatureRequest
struct
{
DisclosureRequest
Message
string
`json:"message"`
MessageType
string
`json:"messageType"`
}
type
IssuanceRequest
struct
{
SessionRequest
Credentials
[]
CredentialRequest
`json:"credentials"`
Disclose
irmago
.
AttributeDisjunctionList
`json:"disclose"`
}
type
CredentialRequest
struct
{
Validity
*
Timestamp
KeyCounter
int
Credential
irmago
.
CredentialTypeIdentifier
Attributes
map
[
string
]
string
}
type
ServerJwt
struct
{
ServerName
string
`json:"iss"`
IssuedAt
*
Timestamp
`json:"iat"`
Type
string
`json:"sub"`
ServerName
string
`json:"iss"`
IssuedAt
*
irmago
.
Timestamp
`json:"iat"`
Type
string
`json:"sub"`
}
type
ServiceProviderRequest
struct
{
Request
DisclosureRequest
`json:"request"`
Request
irmago
.
DisclosureRequest
`json:"request"`
}
type
SignatureServerRequest
struct
{
Request
SignatureRequest
`json:"request"`
Request
irmago
.
SignatureRequest
`json:"request"`
}
type
IdentityProviderRequest
struct
{
Request
IssuanceRequest
`json:"request"`
Request
irmago
.
IssuanceRequest
`json:"request"`
}
type
ServiceProviderJwt
struct
{
...
...
@@ -74,8 +39,8 @@ type IdentityProviderJwt struct {
Request
IdentityProviderRequest
`json:"iprequest"`
}
func
NewServiceProviderJwt
(
servername
string
,
dr
DisclosureRequest
)
*
ServiceProviderJwt
{
now
:=
Timestamp
(
time
.
Now
())
func
NewServiceProviderJwt
(
servername
string
,
dr
irmago
.
DisclosureRequest
)
*
ServiceProviderJwt
{
now
:=
irmago
.
Timestamp
(
time
.
Now
())
return
&
ServiceProviderJwt
{
ServerJwt
:
ServerJwt
{
ServerName
:
servername
,
...
...
@@ -86,8 +51,8 @@ func NewServiceProviderJwt(servername string, dr DisclosureRequest) *ServiceProv
}
}
func
NewSignatureServerJwt
(
servername
string
,
sr
SignatureRequest
)
*
SignatureServerJwt
{
now
:=
Timestamp
(
time
.
Now
())
func
NewSignatureServerJwt
(
servername
string
,
sr
irmago
.
SignatureRequest
)
*
SignatureServerJwt
{
now
:=
irmago
.
Timestamp
(
time
.
Now
())
return
&
SignatureServerJwt
{
ServerJwt
:
ServerJwt
{
ServerName
:
servername
,
...
...
@@ -98,8 +63,8 @@ func NewSignatureServerJwt(servername string, sr SignatureRequest) *SignatureSer
}
}
func
NewIdentityProviderJwt
(
servername
string
,
ir
IssuanceRequest
)
*
IdentityProviderJwt
{
now
:=
Timestamp
(
time
.
Now
())
func
NewIdentityProviderJwt
(
servername
string
,
ir
irmago
.
IssuanceRequest
)
*
IdentityProviderJwt
{
now
:=
irmago
.
Timestamp
(
time
.
Now
())
return
&
IdentityProviderJwt
{
ServerJwt
:
ServerJwt
{
ServerName
:
servername
,
...
...
@@ -110,38 +75,6 @@ func NewIdentityProviderJwt(servername string, ir IssuanceRequest) *IdentityProv
}
}
func
(
ir
*
IssuanceRequest
)
GetContext
()
*
big
.
Int
{
return
ir
.
Context
}
func
(
ir
*
IssuanceRequest
)
GetNonce
()
*
big
.
Int
{
return
ir
.
Nonce
}
func
(
dr
*
DisclosureRequest
)
GetContext
()
*
big
.
Int
{
return
dr
.
Context
}
func
(
dr
*
DisclosureRequest
)
GetNonce
()
*
big
.
Int
{
return
dr
.
Nonce
}
func
(
sr
*
SignatureRequest
)
GetContext
()
*
big
.
Int
{
return
sr
.
Context
}
func
(
sr
*
SignatureRequest
)
GetNonce
()
*
big
.
Int
{
hashbytes
:=
sha256
.
Sum256
([]
byte
(
sr
.
Message
))
hashint
:=
new
(
big
.
Int
)
.
SetBytes
(
hashbytes
[
:
])
// TODO the 2 should be abstracted away
asn1bytes
,
err
:=
asn1
.
Marshal
([]
interface
{}{
big
.
NewInt
(
2
),
sr
.
Nonce
,
hashint
})
if
err
!=
nil
{
log
.
Print
(
err
)
// TODO? does this happen?
}
asn1hash
:=
sha256
.
Sum256
(
asn1bytes
)
return
new
(
big
.
Int
)
.
SetBytes
(
asn1hash
[
:
])
}
func
(
spr
*
ServiceProviderJwt
)
DisjunctionList
()
irmago
.
AttributeDisjunctionList
{
return
spr
.
Request
.
Request
.
Content
}
...
...
protocol/session.go
View file @
ebb610e8
...
...
@@ -28,9 +28,9 @@ type Handler interface {
Failure
(
action
Action
,
err
*
Error
)
UnsatisfiableRequest
(
action
Action
,
missing
irmago
.
AttributeDisjunctionList
)
AskIssuancePermission
(
request
IssuanceRequest
,
ServerName
string
,
choice
PermissionHandler
)
AskVerificationPermission
(
request
DisclosureRequest
,
ServerName
string
,
choice
PermissionHandler
)
AskSignaturePermission
(
request
SignatureRequest
,
ServerName
string
,
choice
PermissionHandler
)
AskIssuancePermission
(
request
irmago
.
IssuanceRequest
,
ServerName
string
,
choice
PermissionHandler
)
AskVerificationPermission
(
request
irmago
.
DisclosureRequest
,
ServerName
string
,
choice
PermissionHandler
)
AskSignaturePermission
(
request
irmago
.
SignatureRequest
,
ServerName
string
,
choice
PermissionHandler
)
}
// A Session is an IRMA session.
...
...
protocol/session_test.go
View file @
ebb610e8
...
...
@@ -65,9 +65,9 @@ func (th TestHandler) Failure(action Action, err *Error) {
func
(
th
TestHandler
)
UnsatisfiableRequest
(
action
Action
,
missing
irmago
.
AttributeDisjunctionList
)
{
th
.
c
<-
&
Error
{}
}
func
(
th
TestHandler
)
AskIssuancePermission
(
request
IssuanceRequest
,
ServerName
string
,
choice
PermissionHandler
)
{
func
(
th
TestHandler
)
AskIssuancePermission
(
request
irmago
.
IssuanceRequest
,
ServerName
string
,
choice
PermissionHandler
)
{
}
func
(
th
TestHandler
)
AskVerificationPermission
(
request
DisclosureRequest
,
ServerName
string
,
callback
PermissionHandler
)
{
func
(
th
TestHandler
)
AskVerificationPermission
(
request
irmago
.
DisclosureRequest
,
ServerName
string
,
callback
PermissionHandler
)
{
choice
:=
&
irmago
.
DisclosureChoice
{
Attributes
:
[]
*
irmago
.
AttributeIdentifier
{},
}
...
...
@@ -80,12 +80,12 @@ func (th TestHandler) AskVerificationPermission(request DisclosureRequest, Serve
}
callback
(
true
,
choice
)
}
func
(
th
TestHandler
)
AskSignaturePermission
(
request
SignatureRequest
,
ServerName
string
,
choice
PermissionHandler
)
{
func
(
th
TestHandler
)
AskSignaturePermission
(
request
irmago
.
SignatureRequest
,
ServerName
string
,
choice
PermissionHandler
)
{
th
.
AskVerificationPermission
(
request
.
DisclosureRequest
,
ServerName
,
choice
)
}
func
getDisclosureJwt
(
name
string
,
id
irmago
.
AttributeTypeIdentifier
)
interface
{}
{
return
NewServiceProviderJwt
(
name
,
DisclosureRequest
{
return
NewServiceProviderJwt
(
name
,
irmago
.
DisclosureRequest
{
Content
:
irmago
.
AttributeDisjunctionList
([]
*
irmago
.
AttributeDisjunction
{
&
irmago
.
AttributeDisjunction
{
Label
:
"foo"
,
...
...
@@ -96,10 +96,10 @@ func getDisclosureJwt(name string, id irmago.AttributeTypeIdentifier) interface{
}
func
getSigningJwt
(
name
string
,
id
irmago
.
AttributeTypeIdentifier
)
interface
{}
{
return
NewSignatureServerJwt
(
name
,
SignatureRequest
{
return
NewSignatureServerJwt
(
name
,
irmago
.
SignatureRequest
{
Message
:
"test"
,
MessageType
:
"STRING"
,
DisclosureRequest
:
DisclosureRequest
{
DisclosureRequest
:
irmago
.
DisclosureRequest
{
Content
:
irmago
.
AttributeDisjunctionList
([]
*
irmago
.
AttributeDisjunction
{
&
irmago
.
AttributeDisjunction
{
Label
:
"foo"
,
...
...
@@ -112,22 +112,18 @@ func getSigningJwt(name string, id irmago.AttributeTypeIdentifier) interface{} {
func
TestSigningSession
(
t
*
testing
.
T
)
{
id
:=
irmago
.
NewAttributeTypeIdentifier
(
"irma-demo.RU.studentCard.studentID"
)
//url := "https://demo.irmacard.org/tomcat/irma_api_server/api/v2/verification"
url
:=
"http://localhost:8081/irma_api_server/api/v2/signature"
name
:=
"testsigclient"
jwtcontents
:=
getSigningJwt
(
name
,
id
)
sessionHelper
(
t
,
jwtcontents
,
url
)
sessionHelper
(
t
,
jwtcontents
,
"signature"
)
}
func
TestDisclosureSession
(
t
*
testing
.
T
)
{
id
:=
irmago
.
NewAttributeTypeIdentifier
(
"irma-demo.RU.studentCard.studentID"
)
//url := "https://demo.irmacard.org/tomcat/irma_api_server/api/v2/verification"
url
:=
"http://localhost:8081/irma_api_server/api/v2/verification"
name
:=
"testsp"
jwtcontents
:=
getDisclosureJwt
(
name
,
id
)
sessionHelper
(
t
,
jwtcontents
,
url
)
sessionHelper
(
t
,
jwtcontents
,
"verification"
)
}
func
sessionHelper
(
t
*
testing
.
T
,
jwtcontents
interface
{},
url
string
)
{
...
...
@@ -135,6 +131,9 @@ func sessionHelper(t *testing.T, jwtcontents interface{}, url string) {
parseStorage
(
t
)
parseAndroidStorage
(
t
)
//url = "http://localhost:8081/irma_api_server/api/v2/" + url
url
=
"https://demo.irmacard.org/tomcat/irma_api_server/api/v2/"
+
url
headerbytes
,
err
:=
json
.
Marshal
(
&
map
[
string
]
string
{
"alg"
:
"none"
,
"typ"
:
"JWT"
})
require
.
NoError
(
t
,
err
)
bodybytes
,
err
:=
json
.
Marshal
(
jwtcontents
)
...
...
protocol/transport.go
View file @
ebb610e8
...
...
@@ -17,7 +17,7 @@ type HTTPTransport struct {
type
ApiError
struct
{
Status
int
`json:"status"`
ErrorName
string
`json:"error"
'
`
ErrorName
string
`json:"error"`
Description
string
`json:"description"`
Message
string
`json:"message"`
Stacktrace
string
`json:"stacktrace"`
...
...
requests.go
0 → 100644
View file @
ebb610e8
package
irmago
import
(
"crypto/sha256"
"encoding/asn1"
"fmt"
"log"
"math/big"
"strconv"
"time"
)
// Timestamp is a time.Time that marshals to Unix timestamps.
type
Timestamp
time
.
Time
type
SessionRequest
struct
{
Context
*
big
.
Int
`json:"nonce"`
Nonce
*
big
.
Int
`json:"context"`
}
type
DisclosureRequest
struct
{
SessionRequest
Content
AttributeDisjunctionList
`json:"content"`
}
type
SignatureRequest
struct
{
DisclosureRequest
Message
string
`json:"message"`
MessageType
string
`json:"messageType"`
}
type
IssuanceRequest
struct
{
SessionRequest
Credentials
[]
CredentialRequest
`json:"credentials"`
Disclose
AttributeDisjunctionList
`json:"disclose"`
}
type
CredentialRequest
struct
{
Validity
*
Timestamp
KeyCounter
int
Credential
CredentialTypeIdentifier
Attributes
map
[
string
]
string
}
func
(
ir
*
IssuanceRequest
)
GetContext
()
*
big
.
Int
{
return
ir
.
Context
}
func
(
ir
*
IssuanceRequest
)
GetNonce
()
*
big
.
Int
{
return
ir
.
Nonce
}
func
(
dr
*
DisclosureRequest
)
GetContext
()
*
big
.
Int
{
return
dr
.
Context
}
func
(
dr
*
DisclosureRequest
)
GetNonce
()
*
big
.
Int
{
return
dr
.
Nonce
}
func
(
sr
*
SignatureRequest
)
GetContext
()
*
big
.
Int
{
return
sr
.
Context
}
func
(
sr
*
SignatureRequest
)
GetNonce
()
*
big
.
Int
{
hashbytes
:=
sha256
.
Sum256
([]
byte
(
sr
.
Message
))
hashint
:=
new
(
big
.
Int
)
.
SetBytes
(
hashbytes
[
:
])
// TODO the 2 should be abstracted away
asn1bytes
,
err
:=
asn1
.
Marshal
([]
interface
{}{
big
.
NewInt
(
2
),
sr
.
Nonce
,
hashint
})
if
err
!=
nil
{
log
.
Print
(
err
)
// TODO? does this happen?
}
asn1hash
:=
sha256
.
Sum256
(
asn1bytes
)
return
new
(
big
.
Int
)
.
SetBytes
(
asn1hash
[
:
])
}
// MarshalJSON marshals a timestamp.
func
(
t
*
Timestamp
)
MarshalJSON
()
([]
byte
,
error
)
{
ts
:=
time
.
Time
(
*
t
)
.
Unix
()
stamp
:=
fmt
.
Sprint
(
ts
)
return
[]
byte
(
stamp
),
nil
}
// UnmarshalJSON unmarshals a timestamp.
func
(
t
*
Timestamp
)
UnmarshalJSON
(
b
[]
byte
)
error
{
ts
,
err
:=
strconv
.
Atoi
(
string
(
b
))
if
err
!=
nil
{
return
err
}
*
t
=
Timestamp
(
time
.
Unix
(
int64
(
ts
),
0
))
return
nil
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment