2015-11-16 16:42:06 +00:00
package pki
2019-04-12 21:54:35 +00:00
import "github.com/hashicorp/vault/sdk/framework"
2015-11-16 16:42:06 +00:00
// addIssueAndSignCommonFields adds fields common to both CA and non-CA issuing
// and signing
func addIssueAndSignCommonFields ( fields map [ string ] * framework . FieldSchema ) map [ string ] * framework . FieldSchema {
2016-03-17 20:28:40 +00:00
fields [ "exclude_cn_from_sans" ] = & framework . FieldSchema {
Type : framework . TypeBool ,
Default : false ,
Description : ` If true , the Common Name will not be
included in DNS or Email Subject Alternate Names .
Defaults to false ( CN is included ) . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "Exclude Common Name from Subject Alternative Names (SANs)" ,
} ,
2016-03-17 20:28:40 +00:00
}
2015-11-16 16:42:06 +00:00
fields [ "format" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Default : "pem" ,
2016-02-01 18:19:41 +00:00
Description : ` Format for returned data . Can be "pem" , "der" ,
or "pem_bundle" . If "pem_bundle" any private
2016-02-01 22:20:16 +00:00
key and issuing cert will be appended to the
certificate pem . Defaults to "pem" . ` ,
2019-02-14 17:42:44 +00:00
AllowedValues : [ ] interface { } { "pem" , "der" , "pem_bundle" } ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Value : "pem" ,
} ,
2015-11-16 16:42:06 +00:00
}
2017-11-06 17:05:07 +00:00
fields [ "private_key_format" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Default : "der" ,
Description : ` Format for the returned private key .
Generally the default will be controlled by the "format"
parameter as either base64 - encoded DER or PEM - encoded DER .
However , this can be set to "pkcs8" to have the returned
private key contain base64 - encoded pkcs8 or PEM - encoded
pkcs8 instead . Defaults to "der" . ` ,
2019-02-14 17:42:44 +00:00
AllowedValues : [ ] interface { } { "" , "der" , "pem" , "pkcs8" } ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Value : "der" ,
} ,
2017-11-06 17:05:07 +00:00
}
2015-11-16 16:42:06 +00:00
fields [ "ip_sans" ] = & framework . FieldSchema {
2018-06-15 19:32:25 +00:00
Type : framework . TypeCommaStringSlice ,
2015-11-16 16:42:06 +00:00
Description : ` The requested IP SANs , if any , in a
comma - delimited list ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "IP Subject Alternative Names (SANs)" ,
} ,
2015-11-16 16:42:06 +00:00
}
2018-06-15 19:32:25 +00:00
fields [ "uri_sans" ] = & framework . FieldSchema {
Type : framework . TypeCommaStringSlice ,
Description : ` The requested URI SANs , if any , in a
comma - delimited list . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "URI Subject Alternative Names (SANs)" ,
} ,
2018-06-15 19:32:25 +00:00
}
2018-02-16 22:19:34 +00:00
fields [ "other_sans" ] = & framework . FieldSchema {
Type : framework . TypeCommaStringSlice ,
Description : ` Requested other SANs , in an array with the format
< oid > ; UTF8 : < utf8 string value > for each entry . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "Other SANs" ,
} ,
2018-02-16 22:19:34 +00:00
}
2015-11-16 16:42:06 +00:00
return fields
}
// addNonCACommonFields adds fields with help text specific to non-CA
// certificate issuing and signing
func addNonCACommonFields ( fields map [ string ] * framework . FieldSchema ) map [ string ] * framework . FieldSchema {
fields = addIssueAndSignCommonFields ( fields )
fields [ "role" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` The desired role with configuration for this
request ` ,
}
fields [ "common_name" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` The requested common name ; if you want more than
one , specify the alternative names in the
alt_names map . If email protection is enabled
in the role , this may be an email address . ` ,
}
fields [ "alt_names" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` The requested Subject Alternative Names , if any ,
in a comma - delimited list . If email protection
is enabled for the role , this may contain
email addresses . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "DNS/Email Subject Alternative Names (SANs)" ,
} ,
2015-11-16 16:42:06 +00:00
}
2018-06-05 03:18:39 +00:00
fields [ "serial_number" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` The requested serial number , if any . If you want
more than one , specify alternative names in
the alt_names map using OID 2.5 .4 .5 . ` ,
}
2015-11-16 16:42:06 +00:00
fields [ "ttl" ] = & framework . FieldSchema {
2017-08-31 19:46:13 +00:00
Type : framework . TypeDurationSecond ,
2015-11-16 16:42:06 +00:00
Description : ` The requested Time To Live for the certificate ;
sets the expiration date . If not specified
the role default , backend default , or system
default TTL is used , in that order . Cannot
2018-05-09 14:29:54 +00:00
be larger than the role max TTL . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "TTL" ,
} ,
2015-11-16 16:42:06 +00:00
}
2022-01-31 21:37:50 +00:00
fields [ "not_after" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` Set the not after field of the certificate with specified date value .
The value format should be given in UTC format YYYY - MM - ddTHH : MM : SSZ ` ,
}
2015-11-16 16:42:06 +00:00
return fields
}
// addCACommonFields adds fields with help text specific to CA
// certificate issuing and signing
func addCACommonFields ( fields map [ string ] * framework . FieldSchema ) map [ string ] * framework . FieldSchema {
fields = addIssueAndSignCommonFields ( fields )
fields [ "alt_names" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` The requested Subject Alternative Names , if any ,
in a comma - delimited list . May contain both
DNS names and email addresses . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "DNS/Email Subject Alternative Names (SANs)" ,
} ,
2015-11-16 16:42:06 +00:00
}
fields [ "common_name" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` The requested common name ; if you want more than
one , specify the alternative names in the alt_names
map . If not specified when signing , the common
name will be taken from the CSR ; other names
must still be specified in alt_names or ip_sans . ` ,
}
fields [ "ttl" ] = & framework . FieldSchema {
2017-08-31 19:46:13 +00:00
Type : framework . TypeDurationSecond ,
2015-11-16 16:42:06 +00:00
Description : ` The requested Time To Live for the certificate ;
sets the expiration date . If not specified
the role default , backend default , or system
default TTL is used , in that order . Cannot
be larger than the mount max TTL . Note :
this only has an effect when generating
a CA cert or signing a CA cert , not when
generating a CSR for an intermediate CA . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "TTL" ,
} ,
2015-11-16 16:42:06 +00:00
}
2018-02-16 22:19:34 +00:00
fields [ "ou" ] = & framework . FieldSchema {
Type : framework . TypeCommaStringSlice ,
Description : ` If set , OU ( OrganizationalUnit ) will be set to
this value . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "OU (Organizational Unit)" ,
} ,
2018-02-16 22:19:34 +00:00
}
fields [ "organization" ] = & framework . FieldSchema {
Type : framework . TypeCommaStringSlice ,
Description : ` If set , O ( Organization ) will be set to
this value . ` ,
}
fields [ "country" ] = & framework . FieldSchema {
Type : framework . TypeCommaStringSlice ,
Description : ` If set , Country will be set to
this value . ` ,
}
fields [ "locality" ] = & framework . FieldSchema {
Type : framework . TypeCommaStringSlice ,
Description : ` If set , Locality will be set to
this value . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "Locality/City" ,
} ,
2018-02-16 22:19:34 +00:00
}
fields [ "province" ] = & framework . FieldSchema {
Type : framework . TypeCommaStringSlice ,
Description : ` If set , Province will be set to
this value . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "Province/State" ,
} ,
2018-02-16 22:19:34 +00:00
}
fields [ "street_address" ] = & framework . FieldSchema {
Type : framework . TypeCommaStringSlice ,
Description : ` If set , Street Address will be set to
this value . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "Street Address" ,
} ,
2018-02-16 22:19:34 +00:00
}
fields [ "postal_code" ] = & framework . FieldSchema {
Type : framework . TypeCommaStringSlice ,
Description : ` If set , Postal Code will be set to
this value . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "Postal Code" ,
} ,
2018-02-16 22:19:34 +00:00
}
2018-06-05 03:18:39 +00:00
fields [ "serial_number" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` The requested serial number , if any . If you want
more than one , specify alternative names in
the alt_names map using OID 2.5 .4 .5 . ` ,
}
2021-11-11 00:09:06 +00:00
fields [ "not_after" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` Set the not after field of the certificate with specified date value .
The value format should be given in UTC format YYYY - MM - ddTHH : MM : SSZ ` ,
}
2018-06-05 03:18:39 +00:00
2015-11-16 16:42:06 +00:00
return fields
}
// addCAKeyGenerationFields adds fields with help text specific to CA key
// generation and exporting
func addCAKeyGenerationFields ( fields map [ string ] * framework . FieldSchema ) map [ string ] * framework . FieldSchema {
fields [ "exported" ] = & framework . FieldSchema {
Type : framework . TypeString ,
2022-01-27 04:06:25 +00:00
Description : ` Must be "internal" , "exported" or "kms" . If set to
2015-11-16 16:42:06 +00:00
"exported" , the generated private key will be
returned . This is your * only * chance to retrieve
the private key ! ` ,
2022-01-27 04:06:25 +00:00
AllowedValues : [ ] interface { } { "internal" , "external" , "kms" } ,
}
fields [ "managed_key_name" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` The name of the managed key to use when the exported
2022-01-28 16:14:20 +00:00
type is kms . When kms type is the key type , this field or managed_key_id
is required . Ignored for other types . ` ,
}
fields [ "managed_key_id" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Description : ` The name of the managed key to use when the exported
type is kms . When kms type is the key type , this field or managed_key_name
is required . Ignored for other types . ` ,
2015-11-16 16:42:06 +00:00
}
fields [ "key_bits" ] = & framework . FieldSchema {
Type : framework . TypeInt ,
Add universal default key_bits value for PKI endpoints (#13080)
* Allow universal default for key_bits
This allows the key_bits field to take a universal default value, 0,
which, depending on key_type, gets adjusted appropriately into a
specific default value (rsa->2048, ec->256, ignored under ed25519).
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
* Handle universal default key size in certutil
Also move RSA < 2048 error message into certutil directly, instead of in
ca_util/path_roles.
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
* Add missing RSA key sizes to pki/backend_test.go
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
* Switch to returning updated values
When determining the default, don't pass in pointer types, but instead
return the newly updated value.
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
* Add changelog entry
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
* Re-add fix for ed25519 from #13254
Ed25519 internally specifies a hash length; by changing the default from
256 to 0, we fail validation in ValidateSignatureLength(...) unless we
specify the key algorithm.
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2021-12-13 20:26:42 +00:00
Default : 0 ,
Description : ` The number of bits to use . Allowed values are
0 ( universal default ) ; with rsa key_type : 2048 ( default ) , 3072 , or
4096 ; with ec key_type : 224 , 256 ( default ) , 384 , or 521 ; ignored with
ed25519 . ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Add universal default key_bits value for PKI endpoints (#13080)
* Allow universal default for key_bits
This allows the key_bits field to take a universal default value, 0,
which, depending on key_type, gets adjusted appropriately into a
specific default value (rsa->2048, ec->256, ignored under ed25519).
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
* Handle universal default key size in certutil
Also move RSA < 2048 error message into certutil directly, instead of in
ca_util/path_roles.
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
* Add missing RSA key sizes to pki/backend_test.go
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
* Switch to returning updated values
When determining the default, don't pass in pointer types, but instead
return the newly updated value.
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
* Add changelog entry
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
* Re-add fix for ed25519 from #13254
Ed25519 internally specifies a hash length; by changing the default from
256 to 0, we fail validation in ValidateSignatureLength(...) unless we
specify the key algorithm.
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2021-12-13 20:26:42 +00:00
Value : 0 ,
2019-06-21 15:08:08 +00:00
} ,
2015-11-16 16:42:06 +00:00
}
2021-09-10 21:39:05 +00:00
fields [ "signature_bits" ] = & framework . FieldSchema {
2021-11-11 00:09:06 +00:00
Type : framework . TypeInt ,
2021-11-12 17:18:38 +00:00
Default : 0 ,
2021-09-10 21:39:05 +00:00
Description : ` The number of bits to use in the signature
2021-11-12 17:18:38 +00:00
algorithm ; accepts 256 for SHA - 2 - 256 , 384 for SHA - 2 - 384 , and 512 for
SHA - 2 - 512. Defaults to 0 to automatically detect based on key length
( SHA - 2 - 256 for RSA keys , and matching the curve size for NIST P - Curves ) . ` ,
2021-09-10 21:39:05 +00:00
DisplayAttrs : & framework . DisplayAttributes {
2021-11-12 17:18:38 +00:00
Value : 0 ,
2021-09-10 21:39:05 +00:00
} ,
}
2015-11-16 16:42:06 +00:00
fields [ "key_type" ] = & framework . FieldSchema {
Type : framework . TypeString ,
Default : "rsa" ,
Description : ` The type of key to use ; defaults to RSA . "rsa"
2021-10-05 15:28:49 +00:00
"ec" and "ed25519" are the only valid values . ` ,
AllowedValues : [ ] interface { } { "rsa" , "ec" , "ed25519" } ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Value : "rsa" ,
} ,
2015-11-16 16:42:06 +00:00
}
return fields
}
// addCAIssueFields adds fields common to CA issuing, e.g. when returning
// an actual certificate
func addCAIssueFields ( fields map [ string ] * framework . FieldSchema ) map [ string ] * framework . FieldSchema {
fields [ "max_path_length" ] = & framework . FieldSchema {
Type : framework . TypeInt ,
Default : - 1 ,
Description : "The maximum allowable path length" ,
}
2017-08-15 20:10:36 +00:00
fields [ "permitted_dns_domains" ] = & framework . FieldSchema {
Type : framework . TypeCommaStringSlice ,
Description : ` Domains for which this certificate is allowed to sign or issue child certificates. If set, all DNS names (subject and alt) on child certs must be exact matches or subsets of the given domains (see https://tools.ietf.org/html/rfc5280#section-4.2.1.10). ` ,
2019-06-21 15:08:08 +00:00
DisplayAttrs : & framework . DisplayAttributes {
Name : "Permitted DNS Domains" ,
} ,
2017-08-15 20:10:36 +00:00
}
2015-11-16 16:42:06 +00:00
return fields
}