2023-03-15 16:00:52 +00:00
/ * *
* Copyright ( c ) HashiCorp , Inc .
* SPDX - License - Identifier : MPL - 2.0
* /
2023-02-24 15:56:12 +00:00
import Model , { attr } from '@ember-data/model' ;
2022-12-21 16:30:24 +00:00
import { withFormFields } from 'vault/decorators/model-form-fields' ;
import lazyCapabilities , { apiPath } from 'vault/macros/lazy-capabilities' ;
2023-02-24 15:56:12 +00:00
import { service } from '@ember/service' ;
2022-09-20 15:25:57 +00:00
2023-01-12 23:33:14 +00:00
const issuerUrls = [ 'issuingCertificates' , 'crlDistributionPoints' , 'ocspServers' ] ;
2023-02-24 15:56:12 +00:00
const inputFields = [
'issuerName' ,
'leafNotAfterBehavior' ,
'usage' ,
'manualChain' ,
'revocationSignatureAlgorithm' ,
... issuerUrls ,
] ;
const displayFields = [
{
2023-04-11 21:04:35 +00:00
default : [ 'certificate' , 'caChain' , 'commonName' , 'issuerName' , 'issuerId' , 'keyId' ] ,
// also displays parsedCertificate values in the template
2023-02-24 15:56:12 +00:00
} ,
{ 'Issuer URLs' : issuerUrls } ,
] ;
@ withFormFields ( inputFields , displayFields )
export default class PkiIssuerModel extends Model {
@ service secretMountPath ;
// TODO use openAPI after removing route extension (see pki/roles route for example)
2023-01-12 23:33:14 +00:00
get useOpenAPI ( ) {
return false ;
2022-12-21 16:30:24 +00:00
}
2023-02-24 15:56:12 +00:00
get backend ( ) {
return this . secretMountPath . currentPath ;
}
2023-02-03 21:07:59 +00:00
get issuerRef ( ) {
return this . issuerName || this . issuerId ;
}
2023-02-24 15:56:12 +00:00
// READ ONLY
@ attr isDefault ;
2023-03-31 21:47:23 +00:00
@ attr ( 'string' , { label : 'Issuer ID' , detailLinkTo : 'issuers.issuer.details' } ) issuerId ;
@ attr ( 'string' , { label : 'Default key ID' , detailLinkTo : 'keys.key.details' } ) keyId ;
2023-02-24 15:56:12 +00:00
@ attr ( { label : 'CA Chain' , masked : true } ) caChain ;
@ attr ( { masked : true } ) certificate ;
2023-04-28 15:05:12 +00:00
@ attr ( 'string' ) serialNumber ;
2022-09-20 15:25:57 +00:00
2023-02-24 15:56:12 +00:00
// parsed from certificate contents in serializer (see parse-pki-cert.js)
2023-04-11 21:04:35 +00:00
@ attr parsedCertificate ;
@ attr ( 'string' ) commonName ;
2023-04-28 15:05:12 +00:00
@ attr isRoot ;
2023-04-11 21:04:35 +00:00
2023-03-31 21:47:23 +00:00
@ attr subjectSerialNumber ; // this is not the UUID serial number field randomly generated by Vault for leaf certificates
2023-02-24 15:56:12 +00:00
@ attr ( { label : 'Subject Alternative Names (SANs)' } ) altNames ;
@ attr ( { label : 'IP SANs' } ) ipSans ;
@ attr ( { label : 'URI SANs' } ) uriSans ;
@ attr ( { label : 'Other SANs' } ) otherSans ;
2022-12-21 16:30:24 +00:00
2023-02-24 15:56:12 +00:00
// UPDATING
2023-01-12 23:33:14 +00:00
@ attr ( 'string' ) issuerName ;
@ attr ( {
label : 'Leaf notAfter behavior' ,
subText :
'What happens when a leaf certificate is issued, but its NotAfter field (and therefore its expiry date) exceeds that of this issuer.' ,
docLink : '/vault/api-docs/secret/pki#update-issuer' ,
editType : 'yield' ,
valueOptions : [ 'err' , 'truncate' , 'permit' ] ,
} )
leafNotAfterBehavior ;
@ attr ( {
2023-02-08 16:42:02 +00:00
subText : 'Allowed usages for this issuer. It can always be read.' ,
2023-01-12 23:33:14 +00:00
editType : 'yield' ,
valueOptions : [
{ label : 'Issuing certificates' , value : 'issuing-certificates' } ,
{ label : 'Signing CRLs' , value : 'crl-signing' } ,
{ label : 'Signing OCSPs' , value : 'ocsp-signing' } ,
] ,
} )
usage ;
@ attr ( 'string' , {
subText :
"An advanced field useful when automatic chain building isn't desired. The first element must be the present issuer's reference." ,
} )
manualChain ;
2023-02-24 15:56:12 +00:00
@ attr ( {
subText :
'The signature algorithm to use when building CRLs. The default value (empty string) is for Go to select the signature algorithm automatically, which may not always work.' ,
noDefault : true ,
possibleValues : [
'sha256withrsa' ,
'ecdsawithsha384' ,
'sha256withrsapss' ,
'ed25519' ,
'sha384withrsapss' ,
'sha512withrsapss' ,
'pureed25519' ,
'sha384withrsa' ,
'sha512withrsa' ,
'ecdsawithsha256' ,
'ecdsawithsha512' ,
] ,
} )
revocationSignatureAlgorithm ;
2023-01-12 23:33:14 +00:00
@ attr ( 'string' , {
subText :
2023-04-19 16:16:30 +00:00
'The URL values for the Issuing Certificate field; these are different URLs for the same resource.' ,
2023-01-12 23:33:14 +00:00
editType : 'stringArray' ,
} )
issuingCertificates ;
@ attr ( 'string' , {
label : 'CRL distribution points' ,
subText : 'Specifies the URL values for the CRL Distribution Points field.' ,
2023-02-02 17:23:15 +00:00
editType : 'stringArray' ,
2023-01-12 23:33:14 +00:00
} )
crlDistributionPoints ;
@ attr ( 'string' , {
label : 'OCSP servers' ,
subText : 'Specifies the URL values for the OCSP Servers field.' ,
2023-02-02 17:23:15 +00:00
editType : 'stringArray' ,
2023-01-12 23:33:14 +00:00
} )
ocspServers ;
2023-02-24 15:56:12 +00:00
// IMPORTING
@ attr ( 'string' ) pemBundle ;
// readonly attrs returned after importing
@ attr importedIssuers ;
@ attr importedKeys ;
@ attr mapping ;
2022-12-21 16:30:24 +00:00
@ lazyCapabilities ( apiPath ` ${ 'backend' } /issuer/ ${ 'issuerId' } ` ) issuerPath ;
@ lazyCapabilities ( apiPath ` ${ 'backend' } /root/rotate/exported ` ) rotateExported ;
@ lazyCapabilities ( apiPath ` ${ 'backend' } /root/rotate/internal ` ) rotateInternal ;
@ lazyCapabilities ( apiPath ` ${ 'backend' } /root/rotate/existing ` ) rotateExisting ;
2023-04-05 21:25:55 +00:00
@ lazyCapabilities ( apiPath ` ${ 'backend' } /root ` , 'backend' ) deletePath ;
2022-12-21 16:30:24 +00:00
@ lazyCapabilities ( apiPath ` ${ 'backend' } /intermediate/cross-sign ` ) crossSignPath ;
@ lazyCapabilities ( apiPath ` ${ 'backend' } /issuer/ ${ 'issuerId' } /sign-intermediate ` ) signIntermediate ;
get canRotateIssuer ( ) {
return (
this . rotateExported . get ( 'canUpdate' ) !== false ||
this . rotateExisting . get ( 'canUpdate' ) !== false ||
this . rotateInternal . get ( 'canUpdate' ) !== false
) ;
2022-09-20 15:25:57 +00:00
}
2022-12-21 16:30:24 +00:00
get canCrossSign ( ) {
return this . crossSignPath . get ( 'canUpdate' ) !== false ;
2022-09-20 15:25:57 +00:00
}
2022-12-21 16:30:24 +00:00
get canSignIntermediate ( ) {
return this . signIntermediate . get ( 'canUpdate' ) !== false ;
}
get canConfigure ( ) {
return this . issuerPath . get ( 'canUpdate' ) !== false ;
2022-09-20 15:25:57 +00:00
}
2023-04-05 21:25:55 +00:00
get canDeleteAllIssuers ( ) {
return this . deletePath . get ( 'isLoading' ) || this . deletePath . get ( 'canDelete' ) !== false ;
}
2022-09-20 15:25:57 +00:00
}