Exemple #1
0
func getEncrypted(key, keyring string, store backend.Store) ([]byte, error) {
	var (
		value    []byte
		passring keyctl.Keyring
		pkr      prompt.PassphraseKeyring
	)
	kr, err := os.Open(secretKeyring)
	if err != nil {
		return value, err
	}
	defer kr.Close()
	data, err := store.Get(key)
	if err != nil {
		return value, err
	}
	if passring, err = SessionKeyring(); err == nil {
		pkr = prompt.PassphraseKeyring{Keyring: passring}
	}

	if passring != nil {
		pkr.Prompt = prompt.NewPrompter(prompt.PassphrasePrompt)
		value, err = secconf.DecodeVia(data, kr, pkr)
	} else {
		value, err = secconf.Decode(data, kr)
	}
	if err != nil {
		return value, err
	}
	return value, err

}
Exemple #2
0
func listPlain(key string, store backend.Store) (backend.KVPairs, error) {
	data, err := store.List(key)
	if err != nil {
		return nil, err
	}
	return data, err
}
Exemple #3
0
func listEncrypted(key, keyring string, store backend.Store) (backend.KVPairs, error) {
	var (
		passring keyctl.Keyring
		pkr      prompt.PassphraseKeyring
	)
	kr, err := os.Open(secretKeyring)
	if err != nil {
		return nil, err
	}
	defer kr.Close()

	data, err := store.List(key)
	if err != nil {
		return nil, err
	}
	if passring, err = SessionKeyring(); err == nil {
		pkr = prompt.PassphraseKeyring{Keyring: passring}
		pkr.Prompt = prompt.NewPrompter(prompt.PassphrasePrompt)
	}
	for i, kv := range data {
		if passring != nil {
			data[i].Value, err = secconf.DecodeVia(kv.Value, kr, pkr)
		} else {
			data[i].Value, err = secconf.Decode(kv.Value, kr)
		}
		kr.Seek(0, 0)
		if err != nil {
			return nil, err
		}
	}
	return data, err
}
Exemple #4
0
func getPlain(key string, store backend.Store) ([]byte, error) {
	var value []byte
	data, err := store.Get(key)
	if err != nil {
		return value, err
	}
	return data, err
}
Exemple #5
0
func setEncrypted(key, keyring string, d []byte, store backend.Store, keySelector pubkeyFilter) error {
	kr, err := os.Open(keyring)
	if err != nil {
		return err
	}
	defer kr.Close()
	secureValue, err := secconf.EncodeWith(d, kr, keySelector)
	if err != nil {
		return err
	}
	err = store.Set(key, secureValue)
	return err
}
Exemple #6
0
func setPlain(key string, store backend.Store, d []byte) error {
	err := store.Set(key, d)
	return err

}