Skip to content
GitLab
Menu
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
4bc1dabd
Commit
4bc1dabd
authored
Jan 30, 2019
by
Sietse Ringers
Browse files
Remove old log entries in update 6 instead of attempting to convert them
parent
db143b0b
Changes
1
Hide whitespace changes
Inline
Side-by-side
irmaclient/updates.go
View file @
4bc1dabd
package
irmaclient
import
(
"encoding/json"
"regexp"
"time"
"github.com/go-errors/errors"
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/gabi/big"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/fs"
)
...
...
@@ -69,100 +64,9 @@ var clientUpdates = []func(client *Client) error{
// 5: Remove the test scheme manager which was erroneously included in a production build
nil
,
// No longer necessary, also broke many unit tests
// 6: Guess and include version protocol in issuance logs, and convert log entry structure
// from Response to either IssueCommitment or ProofList
// 6: Remove earlier log items of wrong format
func
(
client
*
Client
)
(
err
error
)
{
logs
,
err
:=
client
.
Logs
()
if
err
!=
nil
{
return
}
// The logs read above do not contain the Response field as it has been removed from the LogEntry struct.
// So read the logs again into a slice of a temp struct that does contain this field.
type
oldLogEntry
struct
{
Response
json
.
RawMessage
ProofList
gabi
.
ProofList
SessionInfo
struct
{
Nonce
*
big
.
Int
`json:"nonce"`
Context
*
big
.
Int
`json:"context"`
Jwt
string
`json:"jwt"`
Keys
map
[
irma
.
IssuerIdentifier
]
int
`json:"keys"`
}
}
var
oldLogs
[]
*
oldLogEntry
if
err
=
client
.
storage
.
load
(
&
oldLogs
,
logsFile
);
err
!=
nil
{
return
}
// Sanity check, this should be true as both log slices were read from the same source
if
len
(
oldLogs
)
!=
len
(
logs
)
{
return
errors
.
New
(
"Log count does not match"
)
}
for
i
,
entry
:=
range
logs
{
oldEntry
:=
oldLogs
[
i
]
if
len
(
oldEntry
.
Response
)
==
0
{
return
errors
.
New
(
"Log entry had no Response field"
)
}
var
jwt
irma
.
RequestorJwt
jwt
,
err
=
irma
.
ParseRequestorJwt
(
string
(
entry
.
Type
),
oldEntry
.
SessionInfo
.
Jwt
)
if
err
!=
nil
{
return
err
}
entry
.
request
=
jwt
.
SessionRequest
()
// Ugly hack alert: unfortunately the protocol version that was used in the session is nowhere recorded.
// This means that we cannot be sure whether or not we should byteshift the presence bit out of the attributes
// that was introduced in version 2.3 of the protocol. The only thing that I can think of to determine this
// is to check if the attributes are human-readable, i.e., alphanumeric: if the presence bit is present and
// we do not shift it away, then they almost certainly will not be.
if
entry
.
Type
==
irma
.
ActionIssuing
&&
entry
.
Version
==
nil
{
for
_
,
attr
:=
range
entry
.
request
.
(
*
irma
.
IssuanceRequest
)
.
Credentials
[
0
]
.
Attributes
{
if
regexp
.
MustCompile
(
"^
\\
w"
)
.
Match
([]
byte
(
attr
))
{
entry
.
Version
=
irma
.
NewVersion
(
2
,
2
)
}
else
{
entry
.
Version
=
irma
.
NewVersion
(
2
,
3
)
}
break
}
}
if
entry
.
Version
==
nil
{
entry
.
Version
=
irma
.
NewVersion
(
2
,
3
)
}
entry
.
request
.
SetNonce
(
oldEntry
.
SessionInfo
.
Nonce
)
entry
.
request
.
SetContext
(
oldEntry
.
SessionInfo
.
Context
)
entry
.
request
.
SetVersion
(
entry
.
Version
)
if
err
:=
entry
.
setSessionRequest
();
err
!=
nil
{
return
err
}
switch
entry
.
Type
{
case
actionRemoval
:
// nop
case
irma
.
ActionSigning
:
fallthrough
case
irma
.
ActionDisclosing
:
proofs
:=
[]
*
gabi
.
ProofD
{}
if
err
=
json
.
Unmarshal
(
oldEntry
.
Response
,
&
proofs
);
err
!=
nil
{
return
}
entry
.
Disclosure
=
&
irma
.
Disclosure
{}
for
_
,
proof
:=
range
proofs
{
entry
.
Disclosure
.
Proofs
=
append
(
entry
.
Disclosure
.
Proofs
,
proof
)
}
case
irma
.
ActionIssuing
:
entry
.
IssueCommitment
=
&
irma
.
IssueCommitmentMessage
{}
if
err
=
json
.
Unmarshal
(
oldEntry
.
Response
,
entry
.
IssueCommitment
);
err
!=
nil
{
return
err
}
isreq
:=
entry
.
request
.
(
*
irma
.
IssuanceRequest
)
for
_
,
cred
:=
range
isreq
.
Credentials
{
cred
.
KeyCounter
=
oldEntry
.
SessionInfo
.
Keys
[
cred
.
CredentialTypeID
.
IssuerIdentifier
()]
}
default
:
return
errors
.
New
(
"Invalid log type"
)
}
}
return
client
.
storage
.
StoreLogs
(
logs
)
return
client
.
storage
.
StoreLogs
([]
*
LogEntry
{})
},
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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