-
Notifications
You must be signed in to change notification settings - Fork 1
/
keystore.go
54 lines (39 loc) · 1.08 KB
/
keystore.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
package main
import (
"crypto/ecdsa"
"log"
"os"
"github.com/dnstapir/tapir"
"gopkg.in/yaml.v3"
)
func genKeyStore() map[string]string {
var ks = make(map[string]string)
keyStoreData, err := os.ReadFile(Gconfig.KeyStore.Path)
if err != nil {
log.Fatalf("Error from ReadFile(%s): %v", Gconfig.KeyStore.Path, err)
}
err = yaml.Unmarshal(keyStoreData, &ks)
if err != nil {
log.Fatalf("Error when unmarshaling keystore contents: %v", err)
}
return ks
}
func GetValidationKeyByKeyName(keyname string) *ecdsa.PublicKey {
ks := genKeyStore()
key, err := tapir.FetchMqttValidatorKey("KEYSTORE: "+ keyname, ks[keyname])
if err != nil {
log.Printf("Error getting key %s from keystore", keyname)
return nil
}
return key
}
// Unused, for now
func GetSigningKeyByKeyName(keyname string) *ecdsa.PrivateKey {
ks := genKeyStore()
key, err := tapir.FetchMqttSigningKey("KEYSTORE: "+ keyname, ks[keyname])
if err != nil {
log.Printf("Error getting key %s from keystore", keyname)
return nil
}
return key
}