コード例 #1
0
ファイル: pkix.go プロジェクト: mcpherrinm/certstrap
// GetCertificate retrieves a certificate file for a given name from the depot
func GetCertificate(d Depot, name string) (crt *pkix.Certificate, err error) {
	b, err := d.Get(CrtTag(name))
	if err != nil {
		return nil, err
	}
	return pkix.NewCertificateFromPEM(b)
}
		generator = ssl.NewKeyPairGenerator(
			fakePrivateKeyGenerator.GenerateKey,
			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