move key store to reseed

This commit is contained in:
Matt Drollette
2014-12-10 20:04:21 -06:00
parent ffbc13d6de
commit 9e2d1ad715
8 changed files with 110 additions and 61 deletions

28
reseed/keystore.go Normal file
View 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"
}

View File

@@ -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
}