Esempio n. 1
0
// CreatePEM takes a file name and a pem writer, creates a file and writes the pem bytes out
func CreatePEM(pemFile string, writer security.PEMWriter) error {
	f, err := os.Create(pemFile)
	if err != nil {
		return err
	}

	writer.WritePEM(f)
	f.Chmod(0400)

	return nil
}
Esempio n. 2
0
// SendPEMWriter writes the specified pem object and handles the ack
func (p *Protocol) SendPEMWriter(pem security.PEMWriter) error {
	var err error

	if err = pem.WritePEM(p.conn); err != nil {
		return err
	}
	_, err = p.conn.Write([]byte("\x00"))
	if err != nil {
		return err
	}

	return nil
}
Esempio n. 3
0
// setPEM stores a security PEM Writer in the state
func (s *State) setPEM(path string, pem security.PEMWriter) error {
	var (
		pemBuf bytes.Buffer
		err    error
	)
	if err = pem.WritePEM(&pemBuf); err != nil {
		return err
	}

	_, err = s.etc.Set(path, pemBuf.String(), 0)
	if err != nil {
		return err
	}

	return nil
}