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
808a5303
Commit
808a5303
authored
Oct 13, 2019
by
Sietse Ringers
Browse files
fix: downloading demo private keys of demo schemes
parent
41877c5c
Changes
2
Hide whitespace changes
Inline
Side-by-side
irmaconfig.go
View file @
808a5303
...
...
@@ -1278,15 +1278,10 @@ func (conf *Configuration) UpdateSchemeManager(id SchemeManagerIdentifier, downl
}
}
manager
.
index
=
newIndex
if
manager
.
Demo
{
// Download private keys if needed.
// These are unsigned so partial download isn't really an option.
if
err
:=
conf
.
downloadPrivateKeys
(
manager
);
err
!=
nil
{
return
err
}
if
err
:=
conf
.
downloadDemoPrivateKeys
(
manager
);
err
!=
nil
{
return
err
}
return
}
...
...
schemes.go
View file @
808a5303
...
...
@@ -3,6 +3,9 @@ package irma
import
(
"fmt"
"path/filepath"
"strings"
"github.com/privacybydesign/irmago/internal/fs"
)
// SchemeManagerPointer points to a remote IRMA scheme, containing information to download the scheme,
...
...
@@ -45,7 +48,15 @@ func (conf *Configuration) DownloadDefaultSchemes() error {
return
nil
}
func
(
conf
*
Configuration
)
downloadPrivateKeys
(
scheme
*
SchemeManager
)
error
{
// downloadDemoPrivateKeys attempts to download the scheme and issuer private keys, if the scheme is
// a demo scheme and if they are not already present in the scheme, without failing if any of them
// is not available.
func
(
conf
*
Configuration
)
downloadDemoPrivateKeys
(
scheme
*
SchemeManager
)
error
{
if
!
scheme
.
Demo
{
return
nil
}
Logger
.
Debugf
(
"Attempting downloading of private keys of scheme %s"
,
scheme
.
ID
)
transport
:=
NewHTTPTransport
(
scheme
.
URL
)
err
:=
transport
.
GetFile
(
"sk.pem"
,
filepath
.
Join
(
conf
.
Path
,
scheme
.
ID
,
"sk.pem"
))
...
...
@@ -53,18 +64,25 @@ func (conf *Configuration) downloadPrivateKeys(scheme *SchemeManager) error {
Logger
.
Warnf
(
"Downloading private key of scheme %s failed "
,
scheme
.
ID
)
}
for
issid
:=
range
conf
.
Issuers
{
// For all public keys that this issuer has in storage, see if a corresponding private key can be downloaded
indices
,
err
:=
conf
.
PublicKeyIndices
(
issid
)
if
err
!=
nil
{
return
err
pkpath
:=
fmt
.
Sprintf
(
pubkeyPattern
,
conf
.
Path
,
scheme
.
ID
,
"*"
)
files
,
err
:=
filepath
.
Glob
(
pkpath
)
if
err
!=
nil
{
return
err
}
// For each public key, attempt to download a corresponding private key
for
_
,
file
:=
range
files
{
i
:=
strings
.
LastIndex
(
pkpath
,
"PublicKeys"
)
skpath
:=
file
[
:
i
]
+
strings
.
Replace
(
file
[
i
:
],
"PublicKeys"
,
"PrivateKeys"
,
1
)
parts
:=
strings
.
Split
(
skpath
,
"/"
)
local
:=
filepath
.
FromSlash
(
skpath
)
exists
,
err
:=
fs
.
PathExists
(
local
)
if
exists
||
err
!=
nil
{
continue
}
for
_
,
index
:=
range
indices
{
remote
:=
fmt
.
Sprintf
(
"%s/PrivateKeys/%d.xml"
,
issid
.
Name
(),
index
)
local
:=
filepath
.
Join
(
conf
.
Path
,
scheme
.
ID
,
remote
)
if
err
=
transport
.
GetFile
(
remote
,
filepath
.
FromSlash
(
local
));
err
!=
nil
{
Logger
.
Warnf
(
"Downloading private key %d of issuer %s failed"
,
index
,
issid
.
String
())
}
remote
:=
strings
.
Join
(
parts
[
len
(
parts
)
-
3
:
len
(
parts
)],
"/"
)
if
err
=
transport
.
GetFile
(
remote
,
local
);
err
!=
nil
{
Logger
.
Warnf
(
"Downloading private key %s failed: %s"
,
skpath
,
err
)
}
}
...
...
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