Ejemplo n.º 1
0
// GetCertificateSigningRequest retrieves a certificate signing request file for a given host name from the depot
func GetCertificateSigningRequest(d Depot, name string) (crt *pkix.CertificateSigningRequest, err error) {
	b, err := d.Get(CsrTag(name))
	if err != nil {
		return nil, err
	}
	return pkix.NewCertificateSigningRequestFromPEM(b)
}
			fakeCertstrapPKIX.CreateCertificateAuthority,
			fakeCertstrapPKIX.CreateCertificateSigningRequest,
			fakeCertstrapPKIX.CreateCertificateHost,
		)

		var err error
		caPrivateKey, caPublicKey, err = decodeAndParsePrivateKey(caPrivateKeyPEM)
		Expect(err).NotTo(HaveOccurred())

		privateKey, publicKey, err = decodeAndParsePrivateKey(privateKeyPEM)
		Expect(err).NotTo(HaveOccurred())

		ca, err = certstrappkix.NewCertificateFromPEM([]byte(caPEM))
		Expect(err).NotTo(HaveOccurred())

		csr, err = certstrappkix.NewCertificateSigningRequestFromPEM([]byte(csrPEM))
		Expect(err).NotTo(HaveOccurred())

		signedCertificate, err = certstrappkix.NewCertificateFromPEM([]byte(certificatePEM))
		Expect(err).NotTo(HaveOccurred())

		fakeCertstrapPKIX.CreateCertificateAuthorityCall.Returns.Certificate = ca
		fakeCertstrapPKIX.CreateCertificateSigningRequestCall.Returns.CertificateSigningRequest = csr
		fakeCertstrapPKIX.CreateCertificateHostCall.Returns.Certificate = signedCertificate

		fakePrivateKeyGenerator.GenerateKeyCall.Stub = func() (*rsa.PrivateKey, error) {
			if fakePrivateKeyGenerator.GenerateKeyCall.CallCount == 0 {
				return caPrivateKey, nil
			}

			return privateKey, nil