Exemplo n.º 1
0
// loadValidateKeyByName loads a key by filename and strores it in the struct
// The function is threadsafe and panics if the key file is invalid
func loadValidateKeyByName(filenames []string) {
	var tempKeys []*fernet.Key

	keyPaths := util.GetPaths(filenames)

	for _, path := range keyPaths {

		log.Debugf("Attempting to load validation key from %s", path)
		b, err := ioutil.ReadFile(path)

		if err != nil {
			log.Errorf("Could not open a key file %s", path)
		} else {
			k, err := fernet.DecodeKey(string(b))

			if err != nil {
				log.Errorf("Could not parse a key from %s", path)
			} else {
				log.Debugf("Successfully loaded validation key from %s", path)
				tempKeys = append(tempKeys, k)
			}
		}

	}
	if len(tempKeys) == 0 {
		panic("Could not read any validation keys")
	}
	// Store only after we are sure loading was good
	validateLock.Lock()
	defer validateLock.Unlock()
	keys = tempKeys
}
Exemplo n.º 2
0
Arquivo: Mint.go Projeto: livenson/fox
// loadMintKeyByName loads a key by filename and strores it in the struct
// The function is threadsafe and panics if the key file is invalid
func LoadMintKeyByName(filename string) {

	keyPath := util.GetPaths([]string{filename})[0]

	log.Debugf("Attempting to load mint key from %s", keyPath)
	b, err := ioutil.ReadFile(keyPath)

	if err != nil {
		panic(err)
	}

	k, err := fernet.DecodeKey(string(b))

	if err != nil {
		panic(err)
	}

	log.Debugf("Successfully loaded mint key from %s", keyPath)
	// Store only after we are sure loading was good
	mintLock.Lock()
	defer mintLock.Unlock()
	key = k
}