Example #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

}
Example #2
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
}
Example #3
0
// Get retrieves and decodes a secconf value stored at key.
func (c configManager) Get(key string) ([]byte, error) {
	value, err := c.store.Get(key)
	if err != nil {
		return nil, err
	}
	return secconf.Decode(value, bytes.NewBuffer(c.keystore))
}
Example #4
0
// List retrieves and decodes all secconf value stored under key.
func (c configManager) List(key string) (KVPairs, error) {
	list, err := c.store.List(key)
	retList := make(KVPairs, len(list))
	if err != nil {
		return nil, err
	}
	for i, kv := range list {
		retList[i].Key = kv.Key
		retList[i].Value, err = secconf.Decode(kv.Value, bytes.NewBuffer(c.keystore))
		if err != nil {
			return nil, err
		}
	}
	return retList, nil
}
Example #5
0
func (c configManager) Watch(key string, stop chan bool) <-chan *Response {
	resp := make(chan *Response, 0)
	backendResp := c.store.Watch(key, stop)
	go func() {
		for {
			select {
			case <-stop:
				return
			case r := <-backendResp:
				if r.Error != nil {
					resp <- &Response{nil, r.Error}
					continue
				}
				value, err := secconf.Decode(r.Value, bytes.NewBuffer(c.keystore))
				resp <- &Response{value, err}
			}
		}
	}()
	return resp
}