forked from minvws/nl-covid19-coronacheck-mobile-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathholder.go
87 lines (68 loc) · 2.35 KB
/
holder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package mobilecore
import (
"encoding/json"
hcertholder "github.com/minvws/nl-covid19-coronacheck-hcert/holder"
idemixholder "github.com/minvws/nl-covid19-coronacheck-idemix/holder"
"github.com/privacybydesign/gabi"
"os"
"path"
)
const (
HOLDER_CONFIG_FILENAME = "config.json"
HOLDER_PUBLIC_KEYS_FILENAME = "public_keys.json"
)
var (
holderConfig *holderConfiguration
domesticHolder *idemixholder.Holder
europeanHolder *hcertholder.Holder
lastCredBuilders []gabi.ProofBuilder
)
type holderConfiguration struct {
// Until business rules are part of the config, we don't need anything from here
}
func InitializeHolder(configDirectoryPath string) *Result {
configPath := path.Join(configDirectoryPath, HOLDER_CONFIG_FILENAME)
pksPath := path.Join(configDirectoryPath, HOLDER_PUBLIC_KEYS_FILENAME)
// Load config
configJson, err := os.ReadFile(configPath)
if err != nil {
return WrappedErrorResult(err, "Could not read holder config file")
}
err = json.Unmarshal(configJson, &holderConfig)
if err != nil {
return WrappedErrorResult(err, "Could not JSON unmarshal holder config")
}
// Read public keys
publicKeysConfig, err := NewPublicKeysConfig(pksPath, false)
if err != nil {
return WrappedErrorResult(err, "Could not load public keys config")
}
// Initialize holders
domesticHolder = idemixholder.New(publicKeysConfig.FindAndCacheDomestic)
europeanHolder = hcertholder.New()
return &Result{nil, ""}
}
// DEPRECATED: See deprecation of LoadDomesticIssuerPks
var HasLoadedDomesticIssuerPks bool = false
// DEPRECATED: Remove this method when the mobile apps have migrated to using
// InitializeHolder and the holder package directly
func LoadDomesticIssuerPks(annotatedPksJson []byte) *Result {
holderConfig = &holderConfiguration{}
// Unmarshal JSON list of keys
annotatedPks := make([]*AnnotatedDomesticPk, 0)
err := json.Unmarshal(annotatedPksJson, &annotatedPks)
if err != nil {
return WrappedErrorResult(err, "Could not unmarshal annotated issuer public keys")
}
// Transform legacy keys
publicKeysConfig := &PublicKeysConfig{
LegacyDomesticPks: annotatedPks,
}
publicKeysConfig.TransformLegacyDomesticPks()
// Initialize holders
domesticHolder = idemixholder.New(publicKeysConfig.FindAndCacheDomestic)
europeanHolder = hcertholder.New()
// Set loaded status
HasLoadedDomesticIssuerPks = true
return &Result{nil, ""}
}