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
459ae208
Commit
459ae208
authored
Feb 07, 2018
by
Sietse Ringers
Browse files
Export Configuration.Path
parent
e1e0e9ae
Changes
3
Hide whitespace changes
Inline
Side-by-side
credinfo.go
View file @
459ae208
package
irma
import
(
"fmt"
"math/big"
"strings"
"github.com/privacybydesign/irmago/internal/fs"
)
// CredentialInfo contains all information of an IRMA credential.
...
...
@@ -38,14 +35,6 @@ func NewCredentialInfo(ints []*big.Int, conf *Configuration) *CredentialInfo {
attrs
[
i
]
=
TranslatedString
(
map
[
string
]
string
{
"en"
:
val
,
"nl"
:
val
})
}
path
:=
fmt
.
Sprintf
(
"%s/%s/%s/Issues/%s/logo.png"
,
conf
.
path
,
credtype
.
SchemeManagerID
,
credtype
.
IssuerID
,
credtype
.
ID
)
exists
,
err
:=
fs
.
PathExists
(
path
)
if
err
!=
nil
{
return
nil
}
if
!
exists
{
path
=
""
}
id
:=
credtype
.
Identifier
()
issid
:=
id
.
IssuerIdentifier
()
return
&
CredentialInfo
{
...
...
@@ -56,7 +45,7 @@ func NewCredentialInfo(ints []*big.Int, conf *Configuration) *CredentialInfo {
SignedOn
:
Timestamp
(
meta
.
SigningDate
()),
Expires
:
Timestamp
(
meta
.
Expiry
()),
Attributes
:
attrs
,
Logo
:
path
,
Logo
:
credtype
.
Logo
(
conf
)
,
Hash
:
NewAttributeListFromInts
(
ints
,
conf
)
.
Hash
(),
}
}
...
...
descriptions.go
View file @
459ae208
...
...
@@ -2,8 +2,10 @@ package irma
import
(
"encoding/xml"
"fmt"
"github.com/go-errors/errors"
"github.com/privacybydesign/irmago/internal/fs"
)
// This file contains data types for scheme managers, issuers, credential types
...
...
@@ -147,6 +149,15 @@ func (ct *CredentialType) SchemeManagerIdentifier() SchemeManagerIdentifier {
return
NewSchemeManagerIdentifier
(
ct
.
SchemeManagerID
)
}
func
(
ct
*
CredentialType
)
Logo
(
conf
*
Configuration
)
string
{
path
:=
fmt
.
Sprintf
(
"%s/%s/%s/Issues/%s/logo.png"
,
conf
.
Path
,
ct
.
SchemeManagerID
,
ct
.
IssuerID
,
ct
.
ID
)
exists
,
err
:=
fs
.
PathExists
(
path
)
if
err
!=
nil
||
!
exists
{
return
""
}
return
path
}
// Identifier returns the identifier of the specified issuer description.
func
(
id
*
Issuer
)
Identifier
()
IssuerIdentifier
{
return
NewIssuerIdentifier
(
id
.
SchemeManagerID
+
"."
+
id
.
ID
)
...
...
irmaconfig.go
View file @
459ae208
...
...
@@ -38,15 +38,16 @@ type Configuration struct {
Issuers
map
[
IssuerIdentifier
]
*
Issuer
CredentialTypes
map
[
CredentialTypeIdentifier
]
*
CredentialType
// Path to the irma_configuration folder that this instance represents
Path
string
// DisabledSchemeManagers keeps track of scheme managers that did not parse succesfully
// (i.e., invalid signature, parsing error), and the problem that occurred when parsing them
DisabledSchemeManagers
map
[
SchemeManagerIdentifier
]
*
SchemeManagerError
// TODO: what can we say about the consistency of this Configuration if this is not empty?
publicKeys
map
[
IssuerIdentifier
]
map
[
int
]
*
gabi
.
PublicKey
reverseHashes
map
[
string
]
CredentialTypeIdentifier
initialized
bool
path
string
assets
string
}
...
...
@@ -83,14 +84,14 @@ func (sme SchemeManagerError) Error() string {
// ParseFolder() should be called to parse the specified path.
func
NewConfiguration
(
path
string
,
assets
string
)
(
conf
*
Configuration
,
err
error
)
{
conf
=
&
Configuration
{
p
ath
:
path
,
P
ath
:
path
,
assets
:
assets
,
}
if
err
=
fs
.
EnsureDirectoryExists
(
conf
.
p
ath
);
err
!=
nil
{
if
err
=
fs
.
EnsureDirectoryExists
(
conf
.
P
ath
);
err
!=
nil
{
return
nil
,
err
}
if
conf
.
assets
!=
""
&&
fs
.
Empty
(
conf
.
p
ath
)
{
if
conf
.
assets
!=
""
&&
fs
.
Empty
(
conf
.
P
ath
)
{
if
err
=
conf
.
CopyFromAssets
(
false
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -111,7 +112,7 @@ func (conf *Configuration) ParseFolder() (err error) {
conf
.
reverseHashes
=
make
(
map
[
string
]
CredentialTypeIdentifier
)
var
mgrerr
*
SchemeManagerError
err
=
iterateSubfolders
(
conf
.
p
ath
,
func
(
dir
string
)
error
{
err
=
iterateSubfolders
(
conf
.
P
ath
,
func
(
dir
string
)
error
{
manager
:=
&
SchemeManager
{
ID
:
filepath
.
Base
(
dir
),
Status
:
SchemeManagerStatusUnprocessed
,
Valid
:
false
}
err
:=
conf
.
parseSchemeManagerFolder
(
dir
,
manager
)
if
err
==
nil
{
...
...
@@ -271,7 +272,7 @@ func (conf *Configuration) parseIssuerFolders(manager *SchemeManager, path strin
// parse $schememanager/$issuer/PublicKeys/$i.xml for $i = 1, ...
func
(
conf
*
Configuration
)
parseKeysFolder
(
manager
*
SchemeManager
,
issuerid
IssuerIdentifier
)
error
{
path
:=
fmt
.
Sprintf
(
"%s/%s/%s/PublicKeys/*.xml"
,
conf
.
p
ath
,
issuerid
.
SchemeManagerIdentifier
()
.
Name
(),
issuerid
.
Name
())
path
:=
fmt
.
Sprintf
(
"%s/%s/%s/PublicKeys/*.xml"
,
conf
.
P
ath
,
issuerid
.
SchemeManagerIdentifier
()
.
Name
(),
issuerid
.
Name
())
files
,
err
:=
filepath
.
Glob
(
path
)
if
err
!=
nil
{
return
err
...
...
@@ -284,7 +285,7 @@ func (conf *Configuration) parseKeysFolder(manager *SchemeManager, issuerid Issu
if
err
!=
nil
{
continue
}
bts
,
found
,
err
:=
conf
.
ReadAuthenticatedFile
(
manager
,
relativePath
(
conf
.
p
ath
,
file
))
bts
,
found
,
err
:=
conf
.
ReadAuthenticatedFile
(
manager
,
relativePath
(
conf
.
P
ath
,
file
))
if
err
!=
nil
||
!
found
{
return
err
}
...
...
@@ -355,7 +356,7 @@ func (conf *Configuration) pathToDescription(manager *SchemeManager, path string
return
false
,
nil
}
bts
,
found
,
err
:=
conf
.
ReadAuthenticatedFile
(
manager
,
relativePath
(
conf
.
p
ath
,
path
))
bts
,
found
,
err
:=
conf
.
ReadAuthenticatedFile
(
manager
,
relativePath
(
conf
.
P
ath
,
path
))
if
!
found
{
return
false
,
nil
}
...
...
@@ -384,7 +385,7 @@ func (conf *Configuration) CopyFromAssets(parse bool) error {
if
conf
.
assets
==
""
{
return
nil
}
if
err
:=
fs
.
CopyDirectory
(
conf
.
assets
,
conf
.
p
ath
);
err
!=
nil
{
if
err
:=
fs
.
CopyDirectory
(
conf
.
assets
,
conf
.
P
ath
);
err
!=
nil
{
return
err
}
if
parse
{
...
...
@@ -400,7 +401,7 @@ func (conf *Configuration) CopyManagerFromAssets(managerID SchemeManagerIdentifi
}
_
=
fs
.
CopyDirectory
(
filepath
.
Join
(
conf
.
assets
,
manager
.
ID
),
filepath
.
Join
(
conf
.
p
ath
,
manager
.
ID
),
filepath
.
Join
(
conf
.
P
ath
,
manager
.
ID
),
)
return
true
}
...
...
@@ -452,7 +453,7 @@ func (conf *Configuration) RemoveSchemeManager(id SchemeManagerIdentifier, fromS
delete
(
conf
.
SchemeManagers
,
id
)
if
fromStorage
{
return
os
.
RemoveAll
(
fmt
.
Sprintf
(
"%s/%s"
,
conf
.
p
ath
,
id
.
String
()))
return
os
.
RemoveAll
(
fmt
.
Sprintf
(
"%s/%s"
,
conf
.
P
ath
,
id
.
String
()))
}
return
nil
}
...
...
@@ -461,12 +462,12 @@ func (conf *Configuration) RemoveSchemeManager(id SchemeManagerIdentifier, fromS
// provided its signature is valid.
func
(
conf
*
Configuration
)
AddSchemeManager
(
manager
*
SchemeManager
)
error
{
name
:=
manager
.
ID
if
err
:=
fs
.
EnsureDirectoryExists
(
fmt
.
Sprintf
(
"%s/%s"
,
conf
.
p
ath
,
name
));
err
!=
nil
{
if
err
:=
fs
.
EnsureDirectoryExists
(
fmt
.
Sprintf
(
"%s/%s"
,
conf
.
P
ath
,
name
));
err
!=
nil
{
return
err
}
t
:=
NewHTTPTransport
(
manager
.
URL
)
path
:=
fmt
.
Sprintf
(
"%s/%s"
,
conf
.
p
ath
,
name
)
path
:=
fmt
.
Sprintf
(
"%s/%s"
,
conf
.
P
ath
,
name
)
if
err
:=
t
.
GetFile
(
"description.xml"
,
path
+
"/description.xml"
);
err
!=
nil
{
return
err
}
...
...
@@ -477,14 +478,14 @@ func (conf *Configuration) AddSchemeManager(manager *SchemeManager) error {
return
err
}
return
conf
.
parseSchemeManagerFolder
(
filepath
.
Join
(
conf
.
p
ath
,
name
),
manager
)
return
conf
.
parseSchemeManagerFolder
(
filepath
.
Join
(
conf
.
P
ath
,
name
),
manager
)
}
// DownloadSchemeManagerSignature downloads, stores and verifies the latest version
// of the index file and signature of the specified manager.
func
(
conf
*
Configuration
)
DownloadSchemeManagerSignature
(
manager
*
SchemeManager
)
(
err
error
)
{
t
:=
NewHTTPTransport
(
manager
.
URL
)
path
:=
fmt
.
Sprintf
(
"%s/%s"
,
conf
.
p
ath
,
manager
.
ID
)
path
:=
fmt
.
Sprintf
(
"%s/%s"
,
conf
.
P
ath
,
manager
.
ID
)
index
:=
filepath
.
Join
(
path
,
"index"
)
sig
:=
filepath
.
Join
(
path
,
"index.sig"
)
...
...
@@ -559,7 +560,7 @@ func (conf *Configuration) Download(set *IrmaIdentifierSet) (*IrmaIdentifierSet,
if
_
,
contains
=
conf
.
Issuers
[
issid
];
!
contains
{
manager
:=
issid
.
SchemeManagerIdentifier
()
url
:=
conf
.
SchemeManagers
[
manager
]
.
URL
+
"/"
+
issid
.
Name
()
path
:=
fmt
.
Sprintf
(
"%s/%s/%s"
,
conf
.
p
ath
,
manager
.
String
(),
issid
.
Name
())
path
:=
fmt
.
Sprintf
(
"%s/%s/%s"
,
conf
.
P
ath
,
manager
.
String
(),
issid
.
Name
())
if
err
=
transport
.
GetFile
(
url
+
"/description.xml"
,
path
+
"/description.xml"
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -579,7 +580,7 @@ func (conf *Configuration) Download(set *IrmaIdentifierSet) (*IrmaIdentifierSet,
if
pk
==
nil
{
manager
:=
issid
.
SchemeManagerIdentifier
()
suffix
:=
fmt
.
Sprintf
(
"/%s/PublicKeys/%d.xml"
,
issid
.
Name
(),
count
)
path
:=
fmt
.
Sprintf
(
"%s/%s/%s"
,
conf
.
p
ath
,
manager
.
String
(),
suffix
)
path
:=
fmt
.
Sprintf
(
"%s/%s/%s"
,
conf
.
P
ath
,
manager
.
String
(),
suffix
)
if
err
=
transport
.
GetFile
(
conf
.
SchemeManagers
[
manager
]
.
URL
+
suffix
,
path
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -591,7 +592,7 @@ func (conf *Configuration) Download(set *IrmaIdentifierSet) (*IrmaIdentifierSet,
if
_
,
contains
:=
conf
.
CredentialTypes
[
credid
];
!
contains
{
issuer
:=
credid
.
IssuerIdentifier
()
manager
:=
issuer
.
SchemeManagerIdentifier
()
local
:=
fmt
.
Sprintf
(
"%s/%s/%s/Issues"
,
conf
.
p
ath
,
manager
.
Name
(),
issuer
.
Name
())
local
:=
fmt
.
Sprintf
(
"%s/%s/%s/Issues"
,
conf
.
P
ath
,
manager
.
Name
(),
issuer
.
Name
())
if
err
:=
fs
.
EnsureDirectoryExists
(
local
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -662,7 +663,7 @@ func (i SchemeManagerIndex) FromString(s string) error {
// parseIndex parses the index file of the specified manager.
func
(
conf
*
Configuration
)
parseIndex
(
name
string
,
manager
*
SchemeManager
)
error
{
path
:=
filepath
.
Join
(
conf
.
p
ath
,
name
,
"index"
)
path
:=
filepath
.
Join
(
conf
.
P
ath
,
name
,
"index"
)
if
err
:=
fs
.
AssertPathExists
(
path
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Missing scheme manager index file; tried %s"
,
path
)
}
...
...
@@ -684,7 +685,7 @@ func (conf *Configuration) VerifySchemeManager(manager *SchemeManager) error {
}
for
file
:=
range
manager
.
index
{
exists
,
err
:=
fs
.
PathExists
(
filepath
.
Join
(
conf
.
p
ath
,
file
))
exists
,
err
:=
fs
.
PathExists
(
filepath
.
Join
(
conf
.
P
ath
,
file
))
if
err
!=
nil
{
return
err
}
...
...
@@ -709,7 +710,7 @@ func (conf *Configuration) ReadAuthenticatedFile(manager *SchemeManager, path st
return
nil
,
false
,
nil
}
bts
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
conf
.
p
ath
,
path
))
bts
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
conf
.
P
ath
,
path
))
if
err
!=
nil
{
return
nil
,
true
,
err
}
...
...
@@ -736,7 +737,7 @@ func (conf *Configuration) VerifySignature(id SchemeManagerIdentifier) (valid bo
}
}()
dir
:=
filepath
.
Join
(
conf
.
p
ath
,
id
.
String
())
dir
:=
filepath
.
Join
(
conf
.
P
ath
,
id
.
String
())
if
err
:=
fs
.
AssertPathExists
(
dir
+
"/index"
,
dir
+
"/index.sig"
,
dir
+
"/pk.pem"
);
err
!=
nil
{
return
false
,
errors
.
New
(
"Missing scheme manager index file, signature, or public key"
)
}
...
...
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