createTemplateData create a new template data with subject and sans based on the information in the certificate request, and the maxPathLen for intermediate certificates.
(cr *x509.CertificateRequest, maxPathLen int, omitCNSAN bool)
| 455 | // the information in the certificate request, and the maxPathLen for |
| 456 | // intermediate certificates. |
| 457 | func createTemplateData(cr *x509.CertificateRequest, maxPathLen int, omitCNSAN bool) x509util.TemplateData { |
| 458 | var sans []string |
| 459 | sans = append(sans, cr.DNSNames...) |
| 460 | sans = append(sans, cr.EmailAddresses...) |
| 461 | for _, v := range cr.IPAddresses { |
| 462 | sans = append(sans, v.String()) |
| 463 | } |
| 464 | for _, v := range cr.URIs { |
| 465 | sans = append(sans, v.String()) |
| 466 | } |
| 467 | |
| 468 | if !omitCNSAN && len(sans) == 0 && cr.Subject.CommonName != "" { |
| 469 | sans = append(sans, cr.Subject.CommonName) |
| 470 | } |
| 471 | |
| 472 | data := x509util.NewTemplateData() |
| 473 | data.SetCertificateRequest(cr) |
| 474 | data.Set("MaxPathLen", maxPathLen) |
| 475 | data.SetSubject(x509util.Subject{ |
| 476 | Country: cr.Subject.Country, |
| 477 | Organization: cr.Subject.Organization, |
| 478 | OrganizationalUnit: cr.Subject.OrganizationalUnit, |
| 479 | Locality: cr.Subject.Locality, |
| 480 | Province: cr.Subject.Province, |
| 481 | StreetAddress: cr.Subject.StreetAddress, |
| 482 | PostalCode: cr.Subject.PostalCode, |
| 483 | SerialNumber: cr.Subject.SerialNumber, |
| 484 | CommonName: cr.Subject.CommonName, |
| 485 | ExtraNames: x509util.NewExtraNames(cr.Subject.ExtraNames), |
| 486 | }) |
| 487 | data.SetSANs(sans) |
| 488 | return data |
| 489 | } |
no test coverage detected
searching dependent graphs…