2015-11-18 15:16:09 +00:00
|
|
|
package pki
|
|
|
|
|
|
|
|
import (
|
2017-08-31 19:46:13 +00:00
|
|
|
"time"
|
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-05-09 15:43:11 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/certutil"
|
2019-04-13 07:44:06 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2015-11-18 15:16:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (b *backend) getGenerationParams(
|
|
|
|
data *framework.FieldData,
|
|
|
|
) (exported bool, format string, role *roleEntry, errorResp *logical.Response) {
|
|
|
|
exportedStr := data.Get("exported").(string)
|
|
|
|
switch exportedStr {
|
|
|
|
case "exported":
|
|
|
|
exported = true
|
|
|
|
case "internal":
|
|
|
|
default:
|
|
|
|
errorResp = logical.ErrorResponse(
|
2017-10-27 16:02:18 +00:00
|
|
|
`the "exported" path parameter must be "internal" or "exported"`)
|
2015-11-18 15:16:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
format = getFormat(data)
|
|
|
|
if format == "" {
|
|
|
|
errorResp = logical.ErrorResponse(
|
2017-10-27 16:02:18 +00:00
|
|
|
`the "format" path parameter must be "pem", "der", "der_pkcs", or "pem_bundle"`)
|
2015-11-18 15:16:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
role = &roleEntry{
|
2018-06-05 03:18:39 +00:00
|
|
|
TTL: time.Duration(data.Get("ttl").(int)) * time.Second,
|
|
|
|
KeyType: data.Get("key_type").(string),
|
|
|
|
KeyBits: data.Get("key_bits").(int),
|
2021-09-10 21:39:05 +00:00
|
|
|
SignatureBits: data.Get("signature_bits").(int),
|
2018-06-05 03:18:39 +00:00
|
|
|
AllowLocalhost: true,
|
|
|
|
AllowAnyName: true,
|
|
|
|
AllowIPSANs: true,
|
|
|
|
EnforceHostnames: false,
|
2018-06-15 19:32:25 +00:00
|
|
|
AllowedURISANs: []string{"*"},
|
2018-10-08 13:51:43 +00:00
|
|
|
AllowedOtherSANs: []string{"*"},
|
2018-06-05 03:18:39 +00:00
|
|
|
AllowedSerialNumbers: []string{"*"},
|
|
|
|
OU: data.Get("ou").([]string),
|
|
|
|
Organization: data.Get("organization").([]string),
|
|
|
|
Country: data.Get("country").([]string),
|
|
|
|
Locality: data.Get("locality").([]string),
|
|
|
|
Province: data.Get("province").([]string),
|
|
|
|
StreetAddress: data.Get("street_address").([]string),
|
|
|
|
PostalCode: data.Get("postal_code").([]string),
|
2015-11-18 15:16:09 +00:00
|
|
|
}
|
|
|
|
|
2016-02-18 22:55:47 +00:00
|
|
|
if role.KeyType == "rsa" && role.KeyBits < 2048 {
|
|
|
|
errorResp = logical.ErrorResponse("RSA keys < 2048 bits are unsafe and not supported")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-12 17:18:38 +00:00
|
|
|
if err := certutil.ValidateKeyTypeSignatureLength(role.KeyType, role.KeyBits, &role.SignatureBits); err != nil {
|
2019-05-09 15:43:11 +00:00
|
|
|
errorResp = logical.ErrorResponse(err.Error())
|
|
|
|
}
|
2015-11-18 15:16:09 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|