Exemplo n.º 1
0
func (s *fdbStore) SaveCertificate(cert *Certificate) error {
	c := s.db.Collection("certs/" + cert.ID())

	if cert.RevocationDesired {
		err := fdb.CreateEmpty(c, "revoke")
		if err != nil {
			return err
		}
	}

	if cert.Revoked {
		err := fdb.CreateEmpty(c, "revoked")
		if err != nil {
			return err
		}
	}

	if len(cert.Certificates) == 0 {
		return nil
	}

	fcert, err := c.Create("cert")
	if err != nil {
		return err
	}
	defer fcert.CloseAbort()

	fchain, err := c.Create("chain")
	if err != nil {
		return err
	}
	defer fchain.CloseAbort()

	ffullchain, err := c.Create("fullchain")
	if err != nil {
		return err
	}
	defer ffullchain.CloseAbort()

	err = acmeutils.SaveCertificates(io.MultiWriter(fcert, ffullchain), cert.Certificates[0])
	if err != nil {
		return err
	}

	for _, ec := range cert.Certificates[1:] {
		err = acmeutils.SaveCertificates(io.MultiWriter(fchain, ffullchain), ec)
		if err != nil {
			return err
		}
	}

	fcert.Close()
	fchain.Close()
	ffullchain.Close()

	return nil
}
Exemplo n.º 2
0
func generateHookPEM(info *responder.TLSSNIChallengeInfo) (string, error) {
	b := bytes.Buffer{}

	err := acmeutils.SaveCertificates(&b, info.Certificate)
	if err != nil {
		return "", err
	}

	err = acmeutils.SavePrivateKey(&b, info.Key)
	if err != nil {
		return "", err
	}

	return b.String(), nil
}