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

Add to the PKIX name: Country, State/Province, Locality, Street Addre… #3785

Closed
wants to merge 1 commit into from
Closed
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
55 changes: 55 additions & 0 deletions builtin/logical/pki/cert_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ type creationBundle struct {
CommonName string
OU []string
Organization []string
Country []string
Province []string
Locality []string
StreetAddress []string
PostalCode []string
DNSNames []string
EmailAddresses []string
IPAddresses []net.IP
Expand Down Expand Up @@ -730,6 +735,46 @@ func generateCreationBundle(b *backend,
}
}

// Set C (country) values if specified in the role
country := []string{}
{
if role.Country != "" {
country = strutil.RemoveDuplicates(strutil.ParseStringSlice(role.Country, ","), false)
}
}

// Set ST (state, province) values if specified in the role
province := []string{}
{
if role.Province != "" {
province = strutil.RemoveDuplicates(strutil.ParseStringSlice(role.Province, ","), false)
}
}

// Set L (locality) values if specified in the role
locality := []string{}
{
if role.Locality != "" {
locality = strutil.RemoveDuplicates(strutil.ParseStringSlice(role.Locality, ","), false)
}
}

// Set streetAddress values if specified in the role
streetAddress := []string{}
{
if role.StreetAddress != "" {
streetAddress = strutil.RemoveDuplicates(strutil.ParseStringSlice(role.StreetAddress, ","), false)
}
}

// Set postalCode values if specified in the role
postalCode := []string{}
{
if role.PostalCode != "" {
postalCode = strutil.RemoveDuplicates(strutil.ParseStringSlice(role.PostalCode, ","), false)
}
}

// Get the TTL and verify it against the max allowed
var ttl time.Duration
var maxTTL time.Duration
Expand Down Expand Up @@ -798,6 +843,11 @@ func generateCreationBundle(b *backend,
CommonName: cn,
OU: ou,
Organization: organization,
Country: country,
Province: province,
Locality: locality,
StreetAddress: streetAddress,
PostalCode: postalCode,
DNSNames: dnsNames,
EmailAddresses: emailAddresses,
IPAddresses: ipAddresses,
Expand Down Expand Up @@ -891,6 +941,11 @@ func createCertificate(creationInfo *creationBundle) (*certutil.ParsedCertBundle
CommonName: creationInfo.CommonName,
OrganizationalUnit: creationInfo.OU,
Organization: creationInfo.Organization,
Country: creationInfo.Country,
Province: creationInfo.Province,
Locality: creationInfo.Locality,
StreetAddress: creationInfo.StreetAddress,
PostalCode: creationInfo.PostalCode,
}

certTemplate := &x509.Certificate{
Expand Down
45 changes: 45 additions & 0 deletions builtin/logical/pki/path_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,48 @@ include the Common Name (cn). Defaults to true.`,
this value in certificates issued by this role.`,
},

"country": &framework.FieldSchema{
Type: framework.TypeString,
Default: "",
Description: `If set, the C (Country) will be set to
this value in certificates issued by this role.`,
},

"province": &framework.FieldSchema{
Type: framework.TypeString,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use TypeCommaStringSlice and store the values as []string.

Default: "",
Description: `If set, the ST (Province) will be set to
this value in certificates issued by this role.`,
},

"locality": &framework.FieldSchema{
Type: framework.TypeString,
Default: "",
Description: `If set, the L (Locality) will be set to
this value in certificates issued by this role.`,
},

"organization": &framework.FieldSchema{
Type: framework.TypeString,
Default: "",
Description: `If set, the O (Organization) will be set to
this value in certificates issued by this role.`,
},

"street_address": &framework.FieldSchema{
Type: framework.TypeString,
Default: "",
Description: `If set, the streetAddress will be set to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't CamelCase streetAddress/postalCode.

this value in certificates issued by this role.`,
},

"postal_code": &framework.FieldSchema{
Type: framework.TypeString,
Default: "",
Description: `If set, the postalCode will be set to
this value in certificates issued by this role.`,
},

"generate_lease": &framework.FieldSchema{
Type: framework.TypeBool,
Default: false,
Expand Down Expand Up @@ -398,6 +433,11 @@ func (b *backend) pathRoleCreate(ctx context.Context, req *logical.Request, data
Organization: data.Get("organization").(string),
GenerateLease: new(bool),
NoStore: data.Get("no_store").(bool),
Country: data.Get("country").(string),
Province: data.Get("province").(string),
Locality: data.Get("locality").(string),
StreetAddress: data.Get("street_address").(string),
PostalCode: data.Get("postal_code").(string),
}

// no_store implies generate_lease := false
Expand Down Expand Up @@ -526,6 +566,11 @@ type roleEntry struct {
Organization string `json:"organization" mapstructure:"organization"`
GenerateLease *bool `json:"generate_lease,omitempty"`
NoStore bool `json:"no_store" mapstructure:"no_store"`
Country string `json:"country" mapstructure:"country"`
Province string `json:"province" mapstructure:"province"`
Locality string `json:"locality" mapstructure:"locality"`
StreetAddress string `json:"street_address" mapstructure:"street_address"`
PostalCode string `json:"postal_address" mapstructure:"postal_code"`

// Used internally for signing intermediates
AllowExpirationPastCA bool
Expand Down