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
4b0c6374
Commit
4b0c6374
authored
Sep 29, 2017
by
Sietse Ringers
Browse files
Move/rename some methods
parent
78d2cd8a
Changes
4
Hide whitespace changes
Inline
Side-by-side
irmago_test.go
View file @
4b0c6374
...
...
@@ -193,7 +193,7 @@ func TestMetadataAttribute(t *testing.T) {
}
func
TestMetadataCompatibility
(
t
*
testing
.
T
)
{
store
:=
n
ewConfigurationStore
()
store
:=
N
ewConfigurationStore
()
require
.
NoError
(
t
,
store
.
ParseFolder
(
"testdata/irma_configuration"
))
// An actual metadata attribute of an IRMA credential extracted from the IRMA app
...
...
@@ -214,7 +214,7 @@ func TestMetadataCompatibility(t *testing.T) {
}
func
TestAttributeDisjunctionMarshaling
(
t
*
testing
.
T
)
{
store
:=
n
ewConfigurationStore
()
store
:=
N
ewConfigurationStore
()
store
.
ParseFolder
(
"testdata/irma_configuration"
)
disjunction
:=
AttributeDisjunction
{}
...
...
oldstorage.go
0 → 100644
View file @
4b0c6374
package
irmago
import
(
"encoding/json"
"encoding/xml"
"errors"
"html"
"io/ioutil"
"math/big"
"github.com/mhe/gabi"
)
// ParseAndroidStorage parses an Android cardemu.xml shared preferences file
// from the old Android IRMA app, parsing its credentials into the current instance,
// and saving them to storage.
// CAREFUL: this method overwrites any existing secret keys and attributes on storage.
func
(
cm
*
CredentialManager
)
ParseAndroidStorage
()
(
err
error
)
{
exists
,
err
:=
PathExists
(
cm
.
path
(
cardemuXML
))
if
err
!=
nil
{
return
}
if
!
exists
{
return
errors
.
New
(
"cardemu.xml not found at "
+
cardemuXML
)
}
bytes
,
err
:=
ioutil
.
ReadFile
(
cm
.
path
(
cardemuXML
))
if
err
!=
nil
{
return
}
parsedxml
:=
struct
{
Strings
[]
struct
{
Name
string
`xml:"name,attr"`
Content
string
`xml:",chardata"`
}
`xml:"string"`
}{}
xml
.
Unmarshal
(
bytes
,
&
parsedxml
)
parsedjson
:=
make
(
map
[
string
][]
*
struct
{
Signature
*
gabi
.
CLSignature
`json:"signature"`
Pk
*
gabi
.
PublicKey
`json:"-"`
Attributes
[]
*
big
.
Int
`json:"attributes"`
SharedPoints
[]
*
big
.
Int
`json:"public_sks"`
})
cm
.
keyshareServers
=
make
(
map
[
SchemeManagerIdentifier
]
*
keyshareServer
)
for
_
,
xmltag
:=
range
parsedxml
.
Strings
{
if
xmltag
.
Name
==
"credentials"
{
jsontag
:=
html
.
UnescapeString
(
xmltag
.
Content
)
if
err
=
json
.
Unmarshal
([]
byte
(
jsontag
),
&
parsedjson
);
err
!=
nil
{
return
}
}
if
xmltag
.
Name
==
"keyshare"
{
jsontag
:=
html
.
UnescapeString
(
xmltag
.
Content
)
if
err
=
json
.
Unmarshal
([]
byte
(
jsontag
),
&
cm
.
keyshareServers
);
err
!=
nil
{
return
}
}
if
xmltag
.
Name
==
"KeyshareKeypairs"
{
jsontag
:=
html
.
UnescapeString
(
xmltag
.
Content
)
keys
:=
make
([]
*
paillierPrivateKey
,
0
,
3
)
if
err
=
json
.
Unmarshal
([]
byte
(
jsontag
),
&
keys
);
err
!=
nil
{
return
}
cm
.
paillierKeyCache
=
keys
[
0
]
}
}
for
_
,
list
:=
range
parsedjson
{
cm
.
secretkey
=
list
[
0
]
.
Attributes
[
0
]
for
_
,
oldcred
:=
range
list
{
gabicred
:=
&
gabi
.
Credential
{
Attributes
:
oldcred
.
Attributes
,
Signature
:
oldcred
.
Signature
,
}
if
oldcred
.
SharedPoints
!=
nil
&&
len
(
oldcred
.
SharedPoints
)
>
0
{
gabicred
.
Signature
.
KeyshareP
=
oldcred
.
SharedPoints
[
0
]
}
cred
:=
newCredential
(
gabicred
,
cm
.
Store
)
if
cred
.
CredentialType
()
==
nil
{
return
errors
.
New
(
"cannot add unknown credential type"
)
}
err
=
cm
.
addCredential
(
cred
,
false
)
if
err
!=
nil
{
return
err
}
}
}
if
len
(
cm
.
credentials
)
>
0
{
err
=
cm
.
storeAttributes
()
if
err
!=
nil
{
return
err
}
err
=
cm
.
storeSecretKey
(
cm
.
secretkey
)
if
err
!=
nil
{
return
err
}
}
if
len
(
cm
.
keyshareServers
)
>
0
{
err
=
cm
.
storeKeyshareServers
()
if
err
!=
nil
{
return
err
}
}
err
=
cm
.
storePaillierKeys
()
if
err
!=
nil
{
return
err
}
if
cm
.
paillierKeyCache
==
nil
{
cm
.
paillierKey
(
false
)
// trigger calculating a new one
}
return
}
storage.go
View file @
4b0c6374
...
...
@@ -2,9 +2,7 @@ package irmago
import
(
"encoding/json"
"encoding/xml"
"errors"
"html"
"io/ioutil"
"os"
"strconv"
...
...
@@ -51,7 +49,7 @@ func NewCredentialManager(
keyshareServers
:
make
(
map
[
SchemeManagerIdentifier
]
*
keyshareServer
),
}
cm
.
Store
=
n
ewConfigurationStore
()
cm
.
Store
=
N
ewConfigurationStore
()
if
err
=
cm
.
Store
.
ParseFolder
(
irmaConfigurationPath
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -90,112 +88,6 @@ func NewCredentialManager(
return
cm
,
nil
}
// ParseAndroidStorage parses an Android cardemu.xml shared preferences file
// from the old Android IRMA app, parsing its credentials into the current instance,
// and saving them to storage.
// CAREFUL: this method overwrites any existing secret keys and attributes on storage.
func
(
cm
*
CredentialManager
)
ParseAndroidStorage
()
(
err
error
)
{
exists
,
err
:=
PathExists
(
cm
.
path
(
cardemuXML
))
if
err
!=
nil
{
return
}
if
!
exists
{
return
errors
.
New
(
"cardemu.xml not found at "
+
cardemuXML
)
}
bytes
,
err
:=
ioutil
.
ReadFile
(
cm
.
path
(
cardemuXML
))
if
err
!=
nil
{
return
}
parsedxml
:=
struct
{
Strings
[]
struct
{
Name
string
`xml:"name,attr"`
Content
string
`xml:",chardata"`
}
`xml:"string"`
}{}
xml
.
Unmarshal
(
bytes
,
&
parsedxml
)
parsedjson
:=
make
(
map
[
string
][]
*
struct
{
Signature
*
gabi
.
CLSignature
`json:"signature"`
Pk
*
gabi
.
PublicKey
`json:"-"`
Attributes
[]
*
big
.
Int
`json:"attributes"`
SharedPoints
[]
*
big
.
Int
`json:"public_sks"`
})
cm
.
keyshareServers
=
make
(
map
[
SchemeManagerIdentifier
]
*
keyshareServer
)
for
_
,
xmltag
:=
range
parsedxml
.
Strings
{
if
xmltag
.
Name
==
"credentials"
{
jsontag
:=
html
.
UnescapeString
(
xmltag
.
Content
)
if
err
=
json
.
Unmarshal
([]
byte
(
jsontag
),
&
parsedjson
);
err
!=
nil
{
return
}
}
if
xmltag
.
Name
==
"keyshare"
{
jsontag
:=
html
.
UnescapeString
(
xmltag
.
Content
)
if
err
=
json
.
Unmarshal
([]
byte
(
jsontag
),
&
cm
.
keyshareServers
);
err
!=
nil
{
return
}
}
if
xmltag
.
Name
==
"KeyshareKeypairs"
{
jsontag
:=
html
.
UnescapeString
(
xmltag
.
Content
)
keys
:=
make
([]
*
paillierPrivateKey
,
0
,
3
)
if
err
=
json
.
Unmarshal
([]
byte
(
jsontag
),
&
keys
);
err
!=
nil
{
return
}
cm
.
paillierKeyCache
=
keys
[
0
]
}
}
for
_
,
list
:=
range
parsedjson
{
cm
.
secretkey
=
list
[
0
]
.
Attributes
[
0
]
for
_
,
oldcred
:=
range
list
{
gabicred
:=
&
gabi
.
Credential
{
Attributes
:
oldcred
.
Attributes
,
Signature
:
oldcred
.
Signature
,
}
if
oldcred
.
SharedPoints
!=
nil
&&
len
(
oldcred
.
SharedPoints
)
>
0
{
gabicred
.
Signature
.
KeyshareP
=
oldcred
.
SharedPoints
[
0
]
}
cred
:=
newCredential
(
gabicred
,
cm
.
Store
)
if
cred
.
CredentialType
()
==
nil
{
return
errors
.
New
(
"cannot add unknown credential type"
)
}
err
=
cm
.
addCredential
(
cred
,
false
)
if
err
!=
nil
{
return
err
}
}
}
if
len
(
cm
.
credentials
)
>
0
{
err
=
cm
.
storeAttributes
()
if
err
!=
nil
{
return
err
}
err
=
cm
.
storeSecretKey
(
cm
.
secretkey
)
if
err
!=
nil
{
return
err
}
}
if
len
(
cm
.
keyshareServers
)
>
0
{
err
=
cm
.
storeKeyshareServers
()
if
err
!=
nil
{
return
err
}
}
err
=
cm
.
storePaillierKeys
()
if
err
!=
nil
{
return
err
}
if
cm
.
paillierKeyCache
==
nil
{
cm
.
paillierKey
(
false
)
// trigger calculating a new one
}
return
}
func
(
cm
*
CredentialManager
)
path
(
file
string
)
string
{
return
cm
.
storagePath
+
"/"
+
file
}
...
...
store.go
View file @
4b0c6374
...
...
@@ -13,7 +13,6 @@ import (
)
// ConfigurationStore keeps track of scheme managers, issuers, credential types and public keys.
// Use the global MetaStore instance.
type
ConfigurationStore
struct
{
SchemeManagers
map
[
SchemeManagerIdentifier
]
*
SchemeManager
Issuers
map
[
IssuerIdentifier
]
*
Issuer
...
...
@@ -24,7 +23,7 @@ type ConfigurationStore struct {
initialized
bool
}
func
n
ewConfigurationStore
()
(
store
*
ConfigurationStore
)
{
func
N
ewConfigurationStore
()
(
store
*
ConfigurationStore
)
{
store
=
&
ConfigurationStore
{
SchemeManagers
:
make
(
map
[
SchemeManagerIdentifier
]
*
SchemeManager
),
Issuers
:
make
(
map
[
IssuerIdentifier
]
*
Issuer
),
...
...
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