-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Custom extended key usage for PKI #4667
Changes from 3 commits
218bf7b
f981461
bfc8700
ac2f7ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,12 @@ To remove all key usages from being set, set | |
this value to an empty list.`, | ||
}, | ||
|
||
"ext_key_usage_oids": &framework.FieldSchema{ | ||
Type: framework.TypeCommaStringSlice, | ||
Default: []string{}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't set an empty default here -- it's done automatically! |
||
Description: `A comma-separated string or list of extended key usage oids.`, | ||
}, | ||
|
||
"use_csr_common_name": &framework.FieldSchema{ | ||
Type: framework.TypeBool, | ||
Default: true, | ||
|
@@ -451,6 +457,7 @@ func (b *backend) pathRoleCreate(ctx context.Context, req *logical.Request, data | |
UseCSRCommonName: data.Get("use_csr_common_name").(bool), | ||
UseCSRSANs: data.Get("use_csr_sans").(bool), | ||
KeyUsage: data.Get("key_usage").([]string), | ||
ExtKeyUsageOIDs: data.Get("ext_key_usage_oids").([]string), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a check on the values similar to the PolicyIdentifiers check below? That way we'll know there won't be an error when generating a cert, instead of silently ignoring it. |
||
OU: data.Get("ou").([]string), | ||
Organization: data.Get("organization").([]string), | ||
Country: data.Get("country").([]string), | ||
|
@@ -495,6 +502,15 @@ func (b *backend) pathRoleCreate(ctx context.Context, req *logical.Request, data | |
return errResp, nil | ||
} | ||
|
||
if len(entry.ExtKeyUsageOIDs) > 0 { | ||
for _, oidstr := range entry.ExtKeyUsageOIDs { | ||
_, err := stringToOid(oidstr) | ||
if err != nil { | ||
return logical.ErrorResponse(fmt.Sprintf("%q could not be parsed as a valid oid for an extended key usage", oidstr)), nil | ||
} | ||
} | ||
} | ||
|
||
if len(entry.PolicyIdentifiers) > 0 { | ||
for _, oidstr := range entry.PolicyIdentifiers { | ||
_, err := stringToOid(oidstr) | ||
|
@@ -588,6 +604,7 @@ type roleEntry struct { | |
RequireCN bool `json:"require_cn" mapstructure:"require_cn"` | ||
AllowedOtherSANs []string `json:"allowed_other_sans" mapstructure:"allowed_other_sans"` | ||
PolicyIdentifiers []string `json:"policy_identifiers" mapstructure:"policy_identifiers"` | ||
ExtKeyUsageOIDs []string `json:"ext_key_usage_oids" mapstructure:"ext_key_usage_oids"` | ||
BasicConstraintsValidForNonCA bool `json:"basic_constraints_valid_for_non_ca" mapstructure:"basic_constraints_valid_for_non_ca"` | ||
|
||
// Used internally for signing intermediates | ||
|
@@ -616,6 +633,7 @@ func (r *roleEntry) ToResponseData() map[string]interface{} { | |
"key_type": r.KeyType, | ||
"key_bits": r.KeyBits, | ||
"key_usage": r.KeyUsage, | ||
"ext_key_usage_oids": r.ExtKeyUsageOIDs, | ||
"ou": r.OU, | ||
"organization": r.Organization, | ||
"country": r.Country, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be in
signCertificate
too