Skip to content

Commit

Permalink
Merge pull request #8631 from sirlatrom/fix-8630
Browse files Browse the repository at this point in the history
Read DNS names and Emails from certificate data if not found in SDK object
  • Loading branch information
tombuildsstuff authored Dec 16, 2020
2 parents 0428638 + 68e924d commit d62a36c
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keyvault

import (
"context"
"crypto/x509"
"encoding/base64"
"encoding/hex"
"fmt"
Expand Down Expand Up @@ -539,7 +540,7 @@ func resourceArmKeyVaultCertificateRead(d *schema.ResourceData, meta interface{}

d.Set("name", id.Name)

certificatePolicy := flattenKeyVaultCertificatePolicy(cert.Policy)
certificatePolicy := flattenKeyVaultCertificatePolicy(cert.Policy, cert.Cer)
if err := d.Set("certificate_policy", certificatePolicy); err != nil {
return fmt.Errorf("Error setting Key Vault Certificate Policy: %+v", err)
}
Expand Down Expand Up @@ -722,7 +723,7 @@ func expandKeyVaultCertificatePolicy(d *schema.ResourceData) keyvault.Certificat
return policy
}

func flattenKeyVaultCertificatePolicy(input *keyvault.CertificatePolicy) []interface{} {
func flattenKeyVaultCertificatePolicy(input *keyvault.CertificatePolicy, certData *[]byte) []interface{} {
if input == nil {
return []interface{}{}
}
Expand Down Expand Up @@ -805,6 +806,17 @@ func flattenKeyVaultCertificatePolicy(input *keyvault.CertificatePolicy) []inter
}

sanOutputs = append(sanOutputs, sanOutput)
} else if certData != nil && len(*certData) > 0 {
sanOutput := make(map[string]interface{})
cert, err := x509.ParseCertificate(*certData)
if err != nil {
log.Printf("[DEBUG] Unable to read certificate data: %v", err)
} else {
sanOutput["emails"] = set.FromStringSlice(cert.EmailAddresses)
sanOutput["dns_names"] = set.FromStringSlice(cert.DNSNames)
sanOutput["upns"] = set.FromStringSlice([]string{})
sanOutputs = append(sanOutputs, sanOutput)
}
}

certProps["key_usage"] = usages
Expand Down

0 comments on commit d62a36c

Please sign in to comment.