move key store to reseed
This commit is contained in:
28
reseed/keystore.go
Normal file
28
reseed/keystore.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package reseed
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type KeyStore struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
func (ks *KeyStore) ReseederCertificate(signer []byte) (*x509.Certificate, error) {
|
||||
certFile := filepath.Base(SignerFilename(string(signer)))
|
||||
certString, err := ioutil.ReadFile(filepath.Join(ks.Path, "reseed", certFile))
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
certPem, _ := pem.Decode(certString)
|
||||
return x509.ParseCertificate(certPem.Bytes)
|
||||
}
|
||||
|
||||
func SignerFilename(signer string) string {
|
||||
return strings.Replace(signer, "@", "_at_", 2) + ".crt"
|
||||
}
|
||||
@@ -30,3 +30,23 @@ func zipSeeds(seeds Seed) ([]byte, error) {
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func uzipSeeds(c []byte) ([]byte, error) {
|
||||
input := bytes.NewReader(c)
|
||||
zipReader, err := zip.NewReader(input, int64(len(c)))
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var uncompressed []byte
|
||||
for _, f := range zipReader.File {
|
||||
rc, err := f.Open()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
uncompressed = append(uncompressed, []byte(f.Name+"\n")...)
|
||||
rc.Close()
|
||||
}
|
||||
|
||||
return uncompressed, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user