Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhances VCert Provision - Filters if Cert is expired #498

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Feature: provision to cloud keystore
| cloudkeystore |
| GOOGLE |
| AWS |
| AZURE |

Scenario Outline: Enroll certificate, execute provisioning and then provisioning again for replace
Given I enroll a random certificate with defined platform VCP with -csr service -no-prompt
Expand Down
15 changes: 9 additions & 6 deletions pkg/venafi/cloud/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

package cloud

import "time"

type VenafiCertificate struct {
ID string `json:"id,omitempty"`
CertificateStatus string `json:"certificateStatus,omitempty"`
CertificateRequestId string `json:"certificateRequestId,omitempty"`
DekHash string `json:"dekHash,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
CertificateSource string `json:"certificateSource,omitempty"`
ID string `json:"id,omitempty"`
CertificateStatus string `json:"certificateStatus,omitempty"`
CertificateRequestId string `json:"certificateRequestId,omitempty"`
DekHash string `json:"dekHash,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
CertificateSource string `json:"certificateSource,omitempty"`
ValidityEnd time.Time `json:"validityEnd"`
}
24 changes: 18 additions & 6 deletions pkg/venafi/cloud/cloudproviders.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ func (c *Connector) ProvisionCertificate(req *domain.ProvisioningRequest, option
certificateIDString := *(reqData.CertificateID)
log.Printf("Certificate ID for provisioning: %s", certificateIDString)

// Is certificate generated by VCP?
log.Printf("Validating if certificate is generated by VCP")
err := c.validateIfCertIsVCPGeneratedByID(*(reqData.CertificateID))
// Is certificate valid for provisioning?
log.Printf("Validating if certificate is valid")
err := c.validateCertificate(*(reqData.CertificateID))
if err != nil {
return nil, err
}
log.Println("Certificate is valid for provisioning (VCP generated)")
log.Printf("Good certificate for provisioning!")

cloudKeystore := reqData.Keystore

Expand Down Expand Up @@ -175,7 +175,7 @@ func (c *Connector) ProvisionCertificateToMachineIdentity(req domain.Provisionin

// Is certificate generated by VCP?
log.Printf("validating if certificate is generated by VCP")
err := c.validateIfCertIsVCPGeneratedByID(certificateID)
err := c.validateCertificate(certificateID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -300,14 +300,26 @@ func setProvisioningOptions(options domain.ProvisioningOptions, keystoreType dom
return provisioningOptions, nil
}

func (c *Connector) validateIfCertIsVCPGeneratedByID(certificateId string) error {
func (c *Connector) validateCertificate(certificateId string) error {
cert, err := c.getCertificates(certificateId)
if err != nil {
return fmt.Errorf("error trying to get certificate details for cert with ID: %s, error: %s", certificateId, err.Error())
}

// Is certificate not expired?
log.Printf("Validating if certificate is not expired")
now := time.Now()
if now.Unix() > cert.ValidityEnd.Unix() {
return fmt.Errorf("error trying to provisioning certificate with ID: %s. Provided certificate is expired", certificateId)
}
log.Printf("Certificate is still valid")

// Is certificate generated by VCP?
log.Printf("Validating if certificate is generated by VCP")
if cert.DekHash == "" {
return fmt.Errorf("error trying to provisioning certificate with ID: %s. Provided certificate is not VCP generated", certificateId)
}
log.Println("Certificate is valid for provisioning (VCP generated)")
return nil
}

Expand Down