-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
pki-certificate.js
134 lines (125 loc) · 3.46 KB
/
pki-certificate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import Model, { attr } from '@ember-data/model';
import { alias } from '@ember/object/computed';
import { computed } from '@ember/object';
import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities';
import fieldToAttrs, { expandAttributeMeta } from 'vault/utils/field-to-attrs';
export default Model.extend({
idPrefix: 'cert/',
backend: attr('string', {
readOnly: true,
}),
//the id prefixed with `cert/` so we can use it as the *secret param for the secret show route
idForNav: attr('string', {
readOnly: true,
}),
DISPLAY_FIELDS: computed(function() {
return [
'certificate',
'commonName',
'issuingCa',
'caChain',
'privateKey',
'privateKeyType',
'revocationTime',
'issueDate',
'expiryDate',
'serialNumber',
];
}),
commonName: attr('string'),
expiryDate: attr('string', {
label: 'Expiration date',
}),
issueDate: attr('string'),
role: attr('object', {
readOnly: true,
}),
revocationTime: attr('number'),
altNames: attr('string', {
label: 'DNS/Email Subject Alternative Names (SANs)',
}),
ipSans: attr('string', {
label: 'IP Subject Alternative Names (SANs)',
}),
otherSans: attr({
editType: 'stringArray',
label: 'Other SANs',
helpText:
'The format is the same as OpenSSL: <oid>;<type>:<value> where the only current valid type is UTF8',
}),
ttl: attr({
label: 'TTL',
editType: 'ttl',
}),
format: attr('string', {
defaultValue: 'pem',
possibleValues: ['pem', 'der', 'pem_bundle'],
}),
excludeCnFromSans: attr('boolean', {
label: 'Exclude Common Name from Subject Alternative Names (SANs)',
defaultValue: false,
}),
certificate: attr('string', {
masked: true,
}),
issuingCa: attr('string', {
label: 'Issuing CA',
masked: true,
}),
caChain: attr('string', {
label: 'CA chain',
masked: true,
}),
privateKey: attr('string', {
masked: true,
}),
privateKeyType: attr('string'),
serialNumber: attr('string'),
fieldsToAttrs(fieldGroups) {
return fieldToAttrs(this, fieldGroups);
},
fieldDefinition: computed(function() {
const groups = [
{ default: ['commonName', 'format'] },
{ Options: ['altNames', 'ipSans', 'ttl', 'excludeCnFromSans', 'otherSans'] },
];
return groups;
}),
fieldGroups: computed('fieldDefinition', function() {
return this.fieldsToAttrs(this.fieldDefinition);
}),
attrs: computed('DISPLAY_FIELDS', 'certificate', 'csr', function() {
let keys = this.certificate || this.csr ? this.DISPLAY_FIELDS.slice(0) : [];
return expandAttributeMeta(this, keys);
}),
toCreds: computed(
'certificate',
'issuingCa',
'caChain',
'privateKey',
'privateKeyType',
'revocationTime',
'serialNumber',
function() {
const props = {
certificate: this.certificate,
issuingCa: this.issuingCa,
caChain: this.caChain,
privateKey: this.privateKey,
privateKeyType: this.privateKeyType,
revocationTime: this.revocationTime,
serialNumber: this.serialNumber,
};
const propsWithVals = Object.keys(props).reduce((ret, prop) => {
if (props[prop]) {
ret[prop] = props[prop];
return ret;
}
return ret;
}, {});
return JSON.stringify(propsWithVals, null, 2);
}
),
revokePath: lazyCapabilities(apiPath`${'backend'}/revoke`, 'backend'),
canRevoke: alias('revokePath.canUpdate'),
});