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
0bbd39cf
Commit
0bbd39cf
authored
Mar 14, 2020
by
Sietse Ringers
Browse files
refactor: rename internal/fs package to internal/common as it contains various stuff
parent
26a27cb4
Changes
24
Hide whitespace changes
Inline
Side-by-side
descriptions.go
View file @
0bbd39cf
...
...
@@ -6,7 +6,7 @@ import (
"path/filepath"
"github.com/go-errors/errors"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
)
// This file contains data types for scheme managers, issuers, credential types
...
...
@@ -199,7 +199,7 @@ func (ct *CredentialType) SchemeManagerIdentifier() SchemeManagerIdentifier {
func
(
ct
*
CredentialType
)
Logo
(
conf
*
Configuration
)
string
{
path
:=
filepath
.
Join
(
conf
.
Path
,
ct
.
SchemeManagerID
,
ct
.
IssuerID
,
"Issues"
,
ct
.
ID
,
"logo.png"
)
exists
,
err
:=
fs
.
PathExists
(
path
)
exists
,
err
:=
common
.
PathExists
(
path
)
if
err
!=
nil
||
!
exists
{
return
""
}
...
...
internal/
fs/fs
.go
→
internal/
common/common
.go
View file @
0bbd39cf
package
fs
package
common
import
(
"crypto/rand"
...
...
internal/servercore/sessions.go
View file @
0bbd39cf
...
...
@@ -9,7 +9,7 @@ import (
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/gabi/big"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/privacybydesign/irmago/server"
"github.com/sirupsen/logrus"
...
...
@@ -176,7 +176,7 @@ func (s *Server) newSession(action irma.Action, request irma.RequestorRequest) *
}
s
.
conf
.
Logger
.
WithFields
(
logrus
.
Fields
{
"session"
:
ses
.
token
})
.
Debug
(
"New session started"
)
nonce
:=
fs
.
RandomBigInt
(
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
gabi
.
DefaultSystemParameters
[
2048
]
.
Lstatzk
))
nonce
:=
common
.
RandomBigInt
(
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
gabi
.
DefaultSystemParameters
[
2048
]
.
Lstatzk
))
ses
.
request
.
Base
()
.
Nonce
=
nonce
ses
.
request
.
Base
()
.
Context
=
one
s
.
sessions
.
add
(
ses
)
...
...
internal/sessiontest/session_test.go
View file @
0bbd39cf
...
...
@@ -10,7 +10,7 @@ import (
"time"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/privacybydesign/irmago/internal/test"
"github.com/privacybydesign/irmago/irmaclient"
"github.com/privacybydesign/irmago/server"
...
...
@@ -445,13 +445,13 @@ func TestDownloadSchemeManager(t *testing.T) {
require
.
Contains
(
t
,
client
.
Configuration
.
CredentialTypes
,
irma
.
NewCredentialTypeIdentifier
(
"irma-demo.RU.studentCard"
))
basepath
:=
filepath
.
Join
(
handler
.
storage
,
"client"
,
"irma_configuration"
,
"irma-demo"
)
exists
,
err
:=
fs
.
PathExists
(
filepath
.
Join
(
basepath
,
"description.xml"
))
exists
,
err
:=
common
.
PathExists
(
filepath
.
Join
(
basepath
,
"description.xml"
))
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
exists
)
exists
,
err
=
fs
.
PathExists
(
filepath
.
Join
(
basepath
,
"RU"
,
"description.xml"
))
exists
,
err
=
common
.
PathExists
(
filepath
.
Join
(
basepath
,
"RU"
,
"description.xml"
))
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
exists
)
exists
,
err
=
fs
.
PathExists
(
filepath
.
Join
(
basepath
,
"RU"
,
"Issues"
,
"studentCard"
,
"description.xml"
))
exists
,
err
=
common
.
PathExists
(
filepath
.
Join
(
basepath
,
"RU"
,
"Issues"
,
"studentCard"
,
"description.xml"
))
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
exists
)
}
...
...
internal/test/testdata.go
View file @
0bbd39cf
...
...
@@ -13,7 +13,7 @@ import (
"testing"
"time"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/stretchr/testify/require"
)
...
...
@@ -74,7 +74,7 @@ func FindTestdataFolder(t *testing.T) string {
path
:=
"testdata"
for
i
:=
0
;
i
<
3
;
i
++
{
exists
,
err
:=
fs
.
PathExists
(
path
)
exists
,
err
:=
common
.
PathExists
(
path
)
checkError
(
t
,
err
)
if
exists
{
return
path
...
...
@@ -103,14 +103,14 @@ func ClearAllTestStorage() {
func
CreateTestStorage
(
t
*
testing
.
T
)
string
{
tmp
,
err
:=
ioutil
.
TempDir
(
""
,
"irmatest"
)
require
.
NoError
(
t
,
err
)
checkError
(
t
,
fs
.
EnsureDirectoryExists
(
filepath
.
Join
(
tmp
,
"client"
)))
checkError
(
t
,
common
.
EnsureDirectoryExists
(
filepath
.
Join
(
tmp
,
"client"
)))
return
tmp
}
func
SetupTestStorage
(
t
*
testing
.
T
)
string
{
storage
:=
CreateTestStorage
(
t
)
path
:=
FindTestdataFolder
(
t
)
err
:=
fs
.
CopyDirectory
(
filepath
.
Join
(
path
,
testStorageDir
),
filepath
.
Join
(
storage
,
"client"
))
err
:=
common
.
CopyDirectory
(
filepath
.
Join
(
path
,
testStorageDir
),
filepath
.
Join
(
storage
,
"client"
))
checkError
(
t
,
err
)
return
storage
}
...
...
irma/cmd/download.go
View file @
0bbd39cf
...
...
@@ -8,7 +8,7 @@ import (
"github.com/go-errors/errors"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/spf13/cobra"
)
...
...
@@ -24,7 +24,7 @@ var downloadCmd = &cobra.Command{
if
len
(
args
)
==
0
{
path
=
defaultIrmaconf
}
else
{
if
err
:=
fs
.
AssertPathExists
(
args
[
0
]);
err
==
nil
{
if
err
:=
common
.
AssertPathExists
(
args
[
0
]);
err
==
nil
{
path
=
args
[
0
]
urls
=
args
[
1
:
]
}
else
{
...
...
@@ -36,7 +36,7 @@ var downloadCmd = &cobra.Command{
if
defaultIrmaconf
==
""
{
die
(
"Failed to determine default irma_configuration path"
,
nil
)
}
if
err
:=
fs
.
EnsureDirectoryExists
(
defaultIrmaconf
);
err
!=
nil
{
if
err
:=
common
.
EnsureDirectoryExists
(
defaultIrmaconf
);
err
!=
nil
{
die
(
"Failed to create irma_configuration directory"
,
err
)
}
fmt
.
Println
(
"No irma_configuration path specified, using "
+
defaultIrmaconf
)
...
...
@@ -48,7 +48,7 @@ var downloadCmd = &cobra.Command{
}
func
downloadSchemeManager
(
dest
string
,
urls
[]
string
)
error
{
exists
,
err
:=
fs
.
PathExists
(
dest
)
exists
,
err
:=
common
.
PathExists
(
dest
)
if
err
!=
nil
{
return
errors
.
Errorf
(
"Could not check path existence: %s"
,
err
.
Error
())
}
...
...
@@ -72,7 +72,7 @@ func downloadSchemeManager(dest string, urls []string) error {
normalizedUrls
=
append
(
normalizedUrls
,
u
)
urlparts
:=
strings
.
Split
(
u
,
"/"
)
managerName
:=
urlparts
[
len
(
urlparts
)
-
1
]
if
err
=
fs
.
AssertPathNotExists
(
filepath
.
Join
(
dest
,
managerName
));
err
!=
nil
{
if
err
=
common
.
AssertPathNotExists
(
filepath
.
Join
(
dest
,
managerName
));
err
!=
nil
{
return
errors
.
Errorf
(
"Scheme manager %s already exists"
,
managerName
)
}
}
...
...
irma/cmd/issuer-keygen.go
View file @
0bbd39cf
...
...
@@ -10,7 +10,7 @@ import (
"github.com/go-errors/errors"
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/spf13/cobra"
)
...
...
@@ -79,7 +79,7 @@ IRMA applications.`,
return
err
}
}
if
err
=
fs
.
AssertPathExists
(
path
);
err
!=
nil
{
if
err
=
common
.
AssertPathExists
(
path
);
err
!=
nil
{
return
errors
.
WrapPrefix
(
err
,
"Nonexisting path specified"
,
0
)
}
...
...
@@ -101,14 +101,14 @@ IRMA applications.`,
defaultFilename
:=
strconv
.
Itoa
(
int
(
counter
))
+
".xml"
if
privkeyfile
==
""
{
keypath
:=
filepath
.
Join
(
path
,
"PrivateKeys"
)
if
err
=
fs
.
EnsureDirectoryExists
(
keypath
);
err
!=
nil
{
if
err
=
common
.
EnsureDirectoryExists
(
keypath
);
err
!=
nil
{
return
errors
.
WrapPrefix
(
err
,
"Failed to create"
+
keypath
,
0
)
}
privkeyfile
=
filepath
.
Join
(
keypath
,
defaultFilename
)
}
if
pubkeyfile
==
""
{
keypath
:=
filepath
.
Join
(
path
,
"PublicKeys"
)
if
err
=
fs
.
EnsureDirectoryExists
(
keypath
);
err
!=
nil
{
if
err
=
common
.
EnsureDirectoryExists
(
keypath
);
err
!=
nil
{
return
errors
.
WrapPrefix
(
err
,
"Failed to create"
+
keypath
,
0
)
}
pubkeyfile
=
filepath
.
Join
(
keypath
,
defaultFilename
)
...
...
irma/cmd/keygen.go
View file @
0bbd39cf
...
...
@@ -10,7 +10,7 @@ import (
"github.com/go-errors/errors"
"github.com/privacybydesign/gabi/signed"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/spf13/cobra"
)
...
...
@@ -30,10 +30,10 @@ var keygenCmd = &cobra.Command{
}
// For safety we enforce that we never overwrite a file
if
err
:=
fs
.
AssertPathNotExists
(
skfile
);
err
!=
nil
{
if
err
:=
common
.
AssertPathNotExists
(
skfile
);
err
!=
nil
{
return
errors
.
Errorf
(
"File %s already exists, not overwriting"
,
skfile
)
}
if
err
:=
fs
.
AssertPathNotExists
(
pkfile
);
err
!=
nil
{
if
err
:=
common
.
AssertPathNotExists
(
pkfile
);
err
!=
nil
{
return
errors
.
Errorf
(
"File %s already exists, not overwriting"
,
pkfile
)
}
...
...
irma/cmd/meta.go
View file @
0bbd39cf
...
...
@@ -10,7 +10,7 @@ import (
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/gabi/big"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/spf13/cobra"
)
...
...
@@ -46,7 +46,7 @@ var metaCmd = &cobra.Command{
}
func
printMetadataAttr
(
metaint
*
big
.
Int
,
confpath
string
)
error
{
if
err
:=
fs
.
AssertPathExists
(
confpath
);
err
!=
nil
{
if
err
:=
common
.
AssertPathExists
(
confpath
);
err
!=
nil
{
return
errors
.
WrapPrefix
(
err
,
"Cannot read irma_configuration"
,
0
)
}
conf
,
err
:=
irma
.
NewConfiguration
(
confpath
,
irma
.
ConfigurationOptions
{
ReadOnly
:
true
})
...
...
irma/cmd/request.go
View file @
0bbd39cf
...
...
@@ -14,7 +14,7 @@ import (
"github.com/go-errors/errors"
"github.com/mdp/qrterminal"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/privacybydesign/irmago/server"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
...
...
@@ -55,13 +55,13 @@ func configureJWTKey(authmethod, key string) (interface{}, jwt.SigningMethod, er
bts
[]
byte
)
// If the key refers to an existing file, use contents of the file as key
if
bts
,
err
=
fs
.
ReadKey
(
""
,
key
);
err
!=
nil
{
if
bts
,
err
=
common
.
ReadKey
(
""
,
key
);
err
!=
nil
{
bts
=
[]
byte
(
key
)
}
switch
authmethod
{
case
"hmac"
:
jwtalg
=
jwt
.
SigningMethodHS256
if
sk
,
err
=
fs
.
Base64Decode
(
bts
);
err
!=
nil
{
if
sk
,
err
=
common
.
Base64Decode
(
bts
);
err
!=
nil
{
return
nil
,
nil
,
err
}
case
"rsa"
:
...
...
irma/cmd/sign.go
View file @
0bbd39cf
...
...
@@ -14,7 +14,7 @@ import (
"github.com/go-errors/errors"
"github.com/privacybydesign/gabi/signed"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/spf13/cobra"
)
...
...
@@ -50,7 +50,7 @@ Careful: this command could fail and invalidate or destroy your scheme manager d
return
errors
.
WrapPrefix
(
err
,
"Failed to read private key:"
,
0
)
}
if
err
=
fs
.
AssertPathExists
(
confpath
);
err
!=
nil
{
if
err
=
common
.
AssertPathExists
(
confpath
);
err
!=
nil
{
return
err
}
...
...
@@ -80,7 +80,7 @@ func signManager(privatekey *ecdsa.PrivateKey, confpath string, skipverification
// Traverse dir and add file hashes to index
var
index
irma
.
SchemeManagerIndex
=
make
(
map
[
string
]
irma
.
ConfigurationFileHash
)
err
:=
fs
.
WalkDir
(
confpath
,
func
(
path
string
,
info
os
.
FileInfo
)
error
{
err
:=
common
.
WalkDir
(
confpath
,
func
(
path
string
,
info
os
.
FileInfo
)
error
{
return
calculateFileHash
(
path
,
info
,
confpath
,
index
)
})
if
err
!=
nil
{
...
...
irma/cmd/update.go
View file @
0bbd39cf
...
...
@@ -6,7 +6,7 @@ import (
"github.com/go-errors/errors"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/spf13/cobra"
)
...
...
@@ -44,7 +44,7 @@ var updateCmd = &cobra.Command{
func
updateSchemeManager
(
paths
[]
string
)
error
{
// Before doing anything, first check that all paths are scheme managers
for
_
,
path
:=
range
paths
{
if
err
:=
fs
.
AssertPathExists
(
filepath
.
Join
(
path
,
"index"
));
err
!=
nil
{
if
err
:=
common
.
AssertPathExists
(
filepath
.
Join
(
path
,
"index"
));
err
!=
nil
{
return
errors
.
Errorf
(
"%s is not a valid scheme manager (%s)"
,
path
,
err
.
Error
())
}
}
...
...
irma/cmd/verify.go
View file @
0bbd39cf
...
...
@@ -8,7 +8,7 @@ import (
"github.com/go-errors/errors"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/spf13/cobra"
)
...
...
@@ -45,7 +45,7 @@ func RunVerify(path string, verbose bool) error {
return
err
}
isScheme
,
err
:=
fs
.
PathExists
(
filepath
.
Join
(
path
,
"index"
))
isScheme
,
err
:=
common
.
PathExists
(
filepath
.
Join
(
path
,
"index"
))
if
err
!=
nil
{
return
err
}
...
...
irmaclient/client.go
View file @
0bbd39cf
...
...
@@ -13,7 +13,7 @@ import (
"github.com/privacybydesign/gabi/big"
"github.com/privacybydesign/gabi/revocation"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/sirupsen/logrus"
)
...
...
@@ -131,10 +131,10 @@ func New(
handler
ClientHandler
,
)
(
*
Client
,
error
)
{
var
err
error
if
err
=
fs
.
AssertPathExists
(
storagePath
);
err
!=
nil
{
if
err
=
common
.
AssertPathExists
(
storagePath
);
err
!=
nil
{
return
nil
,
err
}
if
err
=
fs
.
AssertPathExists
(
irmaConfigurationPath
);
err
!=
nil
{
if
err
=
common
.
AssertPathExists
(
irmaConfigurationPath
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -339,7 +339,7 @@ func (client *Client) addCredential(cred *credential) (err error) {
func
generateSecretKey
()
(
*
secretKey
,
error
)
{
return
&
secretKey
{
Key
:
fs
.
RandomBigInt
(
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
uint
(
gabi
.
DefaultSystemParameters
[
1024
]
.
Lm
))),
Key
:
common
.
RandomBigInt
(
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
uint
(
gabi
.
DefaultSystemParameters
[
1024
]
.
Lm
))),
},
nil
}
...
...
@@ -844,7 +844,7 @@ func (client *Client) Proofs(choice *irma.DisclosureChoice, request irma.Session
// generateIssuerProofNonce generates a nonce which the issuer must use in its gabi.ProofS.
func
generateIssuerProofNonce
()
(
*
big
.
Int
,
error
)
{
return
fs
.
RandomBigInt
(
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
uint
(
gabi
.
DefaultSystemParameters
[
4096
]
.
Lstatzk
))),
nil
return
common
.
RandomBigInt
(
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
uint
(
gabi
.
DefaultSystemParameters
[
4096
]
.
Lstatzk
))),
nil
}
// IssuanceProofBuilders constructs a list of proof builders in the issuance protocol
...
...
irmaclient/legacy.go
View file @
0bbd39cf
...
...
@@ -8,7 +8,7 @@ import (
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/gabi/revocation"
irma
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
)
// This file contains the legacy storage based on files. These functions are needed
...
...
@@ -36,7 +36,7 @@ func (f *fileStorage) path(p string) string {
}
func
(
f
*
fileStorage
)
load
(
dest
interface
{},
path
string
)
(
err
error
)
{
exists
,
err
:=
fs
.
PathExists
(
f
.
path
(
path
))
exists
,
err
:=
common
.
PathExists
(
f
.
path
(
path
))
if
err
!=
nil
||
!
exists
{
return
}
...
...
@@ -58,7 +58,7 @@ func (f *fileStorage) signatureFilename(attrs *irma.AttributeList) string {
func
(
f
*
fileStorage
)
LoadSignature
(
attrs
*
irma
.
AttributeList
)
(
signature
*
gabi
.
CLSignature
,
witness
*
revocation
.
Witness
,
err
error
)
{
sigpath
:=
f
.
signatureFilename
(
attrs
)
if
err
:=
fs
.
AssertPathExists
(
f
.
path
(
sigpath
));
err
!=
nil
{
if
err
:=
common
.
AssertPathExists
(
f
.
path
(
sigpath
));
err
!=
nil
{
return
nil
,
nil
,
err
}
sig
:=
&
clSignatureWitness
{}
...
...
irmaclient/storage.go
View file @
0bbd39cf
...
...
@@ -9,7 +9,7 @@ import (
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/gabi/revocation"
irma
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/go-errors/errors"
"go.etcd.io/bbolt"
...
...
@@ -55,7 +55,7 @@ func (s *storage) path(p string) string {
// backups to iCloud/Google disabled) is the responsibility of the user.
func
(
s
*
storage
)
Open
()
error
{
var
err
error
if
err
=
fs
.
AssertPathExists
(
s
.
storagePath
);
err
!=
nil
{
if
err
=
common
.
AssertPathExists
(
s
.
storagePath
);
err
!=
nil
{
return
err
}
s
.
db
,
err
=
bbolt
.
Open
(
s
.
path
(
databaseFile
),
0600
,
&
bbolt
.
Options
{
Timeout
:
1
*
time
.
Second
})
...
...
irmaconfig.go
View file @
0bbd39cf
...
...
@@ -34,7 +34,7 @@ import (
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/gabi/big"
"github.com/privacybydesign/gabi/signed"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/sirupsen/logrus"
)
...
...
@@ -138,11 +138,11 @@ func NewConfiguration(path string, opts ConfigurationOptions) (conf *Configurati
}
if
conf
.
assets
!=
""
{
// If an assets folder is specified, then it must exist
if
err
=
fs
.
AssertPathExists
(
conf
.
assets
);
err
!=
nil
{
if
err
=
common
.
AssertPathExists
(
conf
.
assets
);
err
!=
nil
{
return
nil
,
errors
.
WrapPrefix
(
err
,
"Nonexistent assets folder specified"
,
0
)
}
}
if
err
=
fs
.
EnsureDirectoryExists
(
conf
.
Path
);
err
!=
nil
{
if
err
=
common
.
EnsureDirectoryExists
(
conf
.
Path
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -172,7 +172,7 @@ func (conf *Configuration) ParseFolder() (err error) {
// Copy any new or updated scheme managers out of the assets into storage
if
conf
.
assets
!=
""
{
err
=
fs
.
IterateSubfolders
(
conf
.
assets
,
func
(
dir
string
,
_
os
.
FileInfo
)
error
{
err
=
common
.
IterateSubfolders
(
conf
.
assets
,
func
(
dir
string
,
_
os
.
FileInfo
)
error
{
scheme
:=
NewSchemeManagerIdentifier
(
filepath
.
Base
(
dir
))
uptodate
,
err
:=
conf
.
isUpToDate
(
scheme
)
if
err
!=
nil
{
...
...
@@ -190,7 +190,7 @@ func (conf *Configuration) ParseFolder() (err error) {
// Parse scheme managers in storage
var
mgrerr
*
SchemeManagerError
err
=
fs
.
IterateSubfolders
(
conf
.
Path
,
func
(
dir
string
,
_
os
.
FileInfo
)
error
{
err
=
common
.
IterateSubfolders
(
conf
.
Path
,
func
(
dir
string
,
_
os
.
FileInfo
)
error
{
manager
:=
NewSchemeManager
(
filepath
.
Base
(
dir
))
err
:=
conf
.
ParseSchemeManagerFolder
(
dir
,
manager
)
if
err
==
nil
{
...
...
@@ -464,7 +464,7 @@ func (conf *Configuration) Prune() {
}
func
(
conf
*
Configuration
)
parseIssuerFolders
(
manager
*
SchemeManager
,
path
string
)
error
{
return
fs
.
IterateSubfolders
(
path
,
func
(
dir
string
,
_
os
.
FileInfo
)
error
{
return
common
.
IterateSubfolders
(
path
,
func
(
dir
string
,
_
os
.
FileInfo
)
error
{
issuer
:=
&
Issuer
{}
exists
,
err
:=
conf
.
pathToDescription
(
manager
,
dir
+
"/description.xml"
,
issuer
)
if
err
!=
nil
{
...
...
@@ -608,7 +608,7 @@ func (conf *Configuration) matchKeyPattern(issuerid IssuerIdentifier, pattern st
// parse $schememanager/$issuer/Issues/*/description.xml
func
(
conf
*
Configuration
)
parseCredentialsFolder
(
manager
*
SchemeManager
,
issuer
*
Issuer
,
path
string
)
error
{
var
foundcred
bool
err
:=
fs
.
IterateSubfolders
(
path
,
func
(
dir
string
,
_
os
.
FileInfo
)
error
{
err
:=
common
.
IterateSubfolders
(
path
,
func
(
dir
string
,
_
os
.
FileInfo
)
error
{
cred
:=
&
CredentialType
{}
exists
,
err
:=
conf
.
pathToDescription
(
manager
,
dir
+
"/description.xml"
,
cred
)
if
err
!=
nil
{
...
...
@@ -718,7 +718,7 @@ func (conf *Configuration) CopyManagerFromAssets(scheme SchemeManagerIdentifier)
if
err
:=
os
.
RemoveAll
(
filepath
.
Join
(
conf
.
Path
,
name
));
err
!=
nil
{
return
false
,
err
}
return
true
,
fs
.
CopyDirectory
(
return
true
,
common
.
CopyDirectory
(
filepath
.
Join
(
conf
.
assets
,
name
),
filepath
.
Join
(
conf
.
Path
,
name
),
)
...
...
@@ -802,7 +802,7 @@ func (conf *Configuration) InstallSchemeManager(manager *SchemeManager, publicke
}
name
:=
manager
.
ID
if
err
:=
fs
.
EnsureDirectoryExists
(
filepath
.
Join
(
conf
.
Path
,
name
));
err
!=
nil
{
if
err
:=
common
.
EnsureDirectoryExists
(
filepath
.
Join
(
conf
.
Path
,
name
));
err
!=
nil
{
return
err
}
...
...
@@ -812,7 +812,7 @@ func (conf *Configuration) InstallSchemeManager(manager *SchemeManager, publicke
return
err
}
if
publickey
!=
nil
{
if
err
:=
fs
.
SaveFile
(
path
+
"/pk.pem"
,
publickey
);
err
!=
nil
{
if
err
:=
common
.
SaveFile
(
path
+
"/pk.pem"
,
publickey
);
err
!=
nil
{
return
err
}
}
else
{
...
...
@@ -1057,7 +1057,7 @@ func (i SchemeManagerIndex) Scheme() SchemeManagerIdentifier {
// parseIndex parses the index file of the specified manager.
func
(
conf
*
Configuration
)
parseIndex
(
name
string
,
manager
*
SchemeManager
)
(
SchemeManagerIndex
,
error
)
{
path
:=
filepath
.
Join
(
conf
.
Path
,
name
,
"index"
)
if
err
:=
fs
.
AssertPathExists
(
path
);
err
!=
nil
{
if
err
:=
common
.
AssertPathExists
(
path
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Missing scheme manager index file; tried %s"
,
path
)
}
indexbts
,
err
:=
ioutil
.
ReadFile
(
path
)
...
...
@@ -1073,7 +1073,7 @@ func (conf *Configuration) parseIndex(name string, manager *SchemeManager) (Sche
}
func
(
conf
*
Configuration
)
checkUnsignedFiles
(
name
string
,
index
SchemeManagerIndex
)
error
{
return
fs
.
WalkDir
(
filepath
.
Join
(
conf
.
Path
,
name
),
func
(
path
string
,
info
os
.
FileInfo
)
error
{
return
common
.
WalkDir
(
filepath
.
Join
(
conf
.
Path
,
name
),
func
(
path
string
,
info
os
.
FileInfo
)
error
{
relpath
,
err
:=
filepath
.
Rel
(
conf
.
Path
,
path
)
if
err
!=
nil
{
return
err
...
...
@@ -1130,7 +1130,7 @@ func (conf *Configuration) VerifySchemeManager(manager *SchemeManager) error {
var
exists
bool
for
file
:=
range
manager
.
index
{
exists
,
err
=
fs
.
PathExists
(
filepath
.
Join
(
conf
.
Path
,
file
))
exists
,
err
=
common
.
PathExists
(
filepath
.
Join
(
conf
.
Path
,
file
))
if
err
!=
nil
{
return
err
}
...
...
@@ -1182,7 +1182,7 @@ func (conf *Configuration) VerifySignature(id SchemeManagerIdentifier) (err erro
}()
dir
:=
filepath
.
Join
(
conf
.
Path
,
id
.
String
())
if
err
:=
fs
.
AssertPathExists
(
filepath
.
Join
(
dir
,
"index"
),
filepath
.
Join
(
dir
,
"index.sig"
),
filepath
.
Join
(
dir
,
"pk.pem"
));
err
!=
nil
{
if
err
:=
common
.
AssertPathExists
(
filepath
.
Join
(
dir
,
"index"
),
filepath
.
Join
(
dir
,
"index.sig"
),
filepath
.
Join
(
dir
,
"pk.pem"
));
err
!=
nil
{
return
errors
.
New
(
"Missing scheme manager index file, signature, or public key"
)
}
...
...
@@ -1268,7 +1268,7 @@ func (conf *Configuration) UpdateSchemeManager(id SchemeManagerIdentifier, downl
path
:=
filepath
.
Join
(
conf
.
Path
,
filename
)
oldHash
,
known
:=
manager
.
index
[
filename
]
var
have
bool
have
,
err
=
fs
.
PathExists
(
path
)
have
,
err
=
common
.
PathExists
(
path
)
if
err
!=
nil
{
return
err
}
...
...
@@ -1380,7 +1380,7 @@ func (conf *Configuration) validateIssuer(manager *SchemeManager, issuer *Issuer
if
err
=
validateDemoPrefix
(
issuer
.
Name
);
manager
.
Demo
&&
err
!=
nil
{
return
errors
.
Errorf
(
"Name of demo issuer %s invalid: %s"
,
issuer
.
ID
,
err
.
Error
())
}
if
err
=
fs
.
AssertPathExists
(
filepath
.
Join
(
dir
,
"logo.png"
));
err
!=
nil
{
if
err
=
common
.
AssertPathExists
(
filepath
.
Join
(
dir
,
"logo.png"
));
err
!=
nil
{
conf
.
Warnings
=
append
(
conf
.
Warnings
,
fmt
.
Sprintf
(
"Issuer %s has no logo.png"
,
issuerid
.
String
()))
}
return
nil
...
...
@@ -1404,7 +1404,7 @@ func (conf *Configuration) validateCredentialType(manager *SchemeManager, issuer
if
err
:=
validateDemoPrefix
(
cred
.
Name
);
manager
.
Demo
&&
err
!=
nil
{
return
errors
.
Errorf
(
"Name of demo credential %s invalid: %s"
,
cred
.
ID
,
err
.
Error
())
}
if
err
:=
fs
.
AssertPathExists
(
filepath
.
Join
(
dir
,
"logo.png"
));
err
!=
nil
{
if
err
:=
common
.
AssertPathExists
(
filepath
.
Join
(
dir
,
"logo.png"
));
err
!=
nil
{
conf
.
Warnings
=
append
(
conf
.
Warnings
,
fmt
.
Sprintf
(
"Credential type %s has no logo.png"
,
credid
.
String
()))
}
return
conf
.
validateAttributes
(
cred
)
...
...
@@ -1457,7 +1457,7 @@ func (conf *Configuration) validateScheme(scheme *SchemeManager, dir string) err
return
errors
.
Errorf
(
"Scheme %s has wrong directory name %s"
,
scheme
.
ID
,
filepath
.
Base
(
dir
))
}
if
scheme
.
KeyshareServer
!=
""
{
if
err
:=
fs
.
AssertPathExists
(
filepath
.
Join
(
dir
,
"kss-0.pem"
));
err
!=
nil
{
if
err
:=
common
.
AssertPathExists
(
filepath
.
Join
(
dir
,
"kss-0.pem"
));
err
!=
nil
{
scheme
.
Status
=
SchemeManagerStatusParsingError
return
errors
.
Errorf
(
"Scheme %s has keyshare URL but no keyshare public key kss-0.pem"
,
scheme
.
ID
)
}
...
...
@@ -1620,7 +1620,7 @@ func DefaultSchemesPath() string {
return
p
}
p
=
filepath
.
Join
(
p
,
"irma_configuration"
)
if
err
:=
fs
.
EnsureDirectoryExists
(
p
);
err
!=
nil
{
if
err
:=
common
.
EnsureDirectoryExists
(
p
);
err
!=
nil
{
return
""
}
return
p
...
...
@@ -1628,7 +1628,7 @@ func DefaultSchemesPath() string {
func
firstExistingPath
(
paths
[]
string
)
string
{
for
_
,
path
:=
range
paths
{
if
err
:=
fs
.
EnsureDirectoryExists
(
path
);
err
==
nil
{
if
err
:=
common
.
EnsureDirectoryExists
(
path
);
err
==
nil
{
return
path
}
}
...
...
irmago_test.go
View file @
0bbd39cf
...
...
@@ -11,7 +11,7 @@ import (
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/gabi/big"
"github.com/privacybydesign/gabi/revocation"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
"github.com/privacybydesign/irmago/internal/test"
"github.com/stretchr/testify/require"
)
...
...
@@ -35,7 +35,7 @@ func TestConfigurationAutocopy(t *testing.T) {
defer
test
.
ClearTestStorage
(
t
,
storage
)
path
:=
filepath
.
Join
(
"testdata"
,
"tmp"
,
"client"
,
"irma_configuration"
)
require
.
NoError
(
t
,
fs
.
CopyDirectory
(
filepath
.
Join
(
"testdata"
,
"irma_configuration"
),
path
))
require
.
NoError
(
t
,
common
.
CopyDirectory
(
filepath
.
Join
(
"testdata"
,
"irma_configuration"
),
path
))
conf
,
err
:=
NewConfiguration
(
path
,
ConfigurationOptions
{
Assets
:
filepath
.
Join
(
"testdata"
,
"irma_configuration_updated"
)})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
conf
.
ParseFolder
())
...
...
requests.go
View file @
0bbd39cf
...
...
@@ -14,7 +14,7 @@ import (
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/gabi/big"
"github.com/privacybydesign/gabi/revocation"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
)
const
(
...
...
@@ -800,7 +800,7 @@ func (t *Timestamp) Floor() Timestamp {
}
func
readTimestamp
(
path
string
)
(
*
Timestamp
,
bool
,
error
)
{
exists
,
err
:=
fs
.
PathExists
(
path
)
exists
,
err
:=
common
.
PathExists
(
path
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
...
...
schemes.go
View file @
0bbd39cf
...
...
@@ -5,7 +5,7 @@ import (
"path/filepath"
"strings"
"github.com/privacybydesign/irmago/internal/
fs
"
"github.com/privacybydesign/irmago/internal/
common
"
)
// SchemeManagerPointer points to a remote IRMA scheme, containing information to download the scheme,
...
...
@@ -76,7 +76,7 @@ func (conf *Configuration) downloadDemoPrivateKeys(scheme *SchemeManager) error
skpath
:=
file
[
:
i
]
+
strings
.
Replace
(
file
[
i
:
],