Beispiel #1
0
Datei: main.go Projekt: polvi/cad
func main() {
	flag.Parse()

	c, err := client.NewCaClient(*cadAddr, false, "", "")
	if err != nil {
		fmt.Println(err)
		return
	}
	csr, priv, err := x509ez.CreateMinCertificateRequest()
	if err != nil {
		fmt.Println(err)
		return
	}
	cert, err := c.SignCert(csr, time.Duration(10*time.Second))
	if err != nil {
		fmt.Println(err)
		return
	}
	if err := x509ez.WriteCertToFile(cert, *certOutFile); err != nil {
		fmt.Println(err)
		return
	}
	if err := x509ez.WriteKeyToFile(priv, *keyOutFile); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("wrote keys, sleeping until", cert.NotAfter)
	time.Sleep(cert.NotAfter.Sub(time.Now()))
}
Beispiel #2
0
func NewCaServerFromParent(parentAddr string, refreshToken string) (*CaServer, error) {
	c, err := client.NewCaClient(parentAddr, false, "", "")
	if err != nil {
		return nil, err
	}
	csr, priv, err := x509ez.CreateMinCertificateRequest()
	if err != nil {
		return nil, err
	}
	signedCert, err := c.SignCa(csr, time.Duration(1*time.Hour))
	if err != nil {
		return nil, err
	}
	parentCert, err := c.ParentCert()
	if err != nil {
		return nil, err
	}
	return &CaServer{
		cert:   signedCert,
		priv:   priv,
		client: c,
		parent: parentCert,
	}, nil
}