Skip to content

Commit 90919b2

Browse files
added subject parameters to certificate enrollment. (#5)
1 parent 75a67c4 commit 90919b2

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

backend.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ func (b *backend) initialize(ctx context.Context, req *logical.InitializationReq
7878
}
7979

8080
// Generate keypair and CSR
81-
func (b *backend) generateCSR(cn string, ip_sans []string, dns_sans []string) (string, []byte) {
81+
func (b *backend) generateCSR(cn string, ip_sans []string, dns_sans []string, o []string, ou []string, l []string, p []string, c []string, zip []string) (string, []byte) {
8282
keyBytes, _ := rsa.GenerateKey(rand.Reader, 2048)
8383
subj := pkix.Name{
84-
CommonName: cn,
84+
Country: c,
85+
Organization: o,
86+
OrganizationalUnit: ou,
87+
Locality: l,
88+
Province: p,
89+
CommonName: cn,
90+
PostalCode: zip,
8591
}
8692
rawSubj := subj.ToRDNSequence()
8793
asn1Subj, _ := asn1.Marshal(rawSubj)

fields.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,48 @@ be larger than the role max TTL.`,
6767
},
6868
}
6969

70+
// fields["email"] = &framework.FieldSchema{
71+
// Type: framework.TypeCommaStringSlice,
72+
// Description: `Email address to be associated with the certificate`,
73+
// Required: false,
74+
// }
75+
76+
fields["c"] = &framework.FieldSchema{
77+
Type: framework.TypeCommaStringSlice,
78+
Description: `Country for the certificate. If omitted, the value associated with the role is used.`,
79+
Required: false,
80+
}
81+
82+
fields["ou"] = &framework.FieldSchema{
83+
Type: framework.TypeCommaStringSlice,
84+
Description: `Organizational Unit for the certificate. If omitted, the value associated with the role is used.`,
85+
Required: false,
86+
}
87+
88+
fields["o"] = &framework.FieldSchema{
89+
Type: framework.TypeCommaStringSlice,
90+
Description: `Organization for the certificate. If omitted, the value associated with the role is used.`,
91+
Required: false,
92+
}
93+
94+
fields["l"] = &framework.FieldSchema{
95+
Type: framework.TypeCommaStringSlice,
96+
Description: `Locality for the certificate. If omitted, the value associated with the role is used.`,
97+
Required: false,
98+
}
99+
100+
fields["p"] = &framework.FieldSchema{
101+
Type: framework.TypeCommaStringSlice,
102+
Description: `Province for the certificate. If omitted, the value associated with the role is used.`,
103+
Required: false,
104+
}
105+
106+
fields["zip"] = &framework.FieldSchema{
107+
Type: framework.TypeCommaStringSlice,
108+
Description: `Postal code for the certificate. If omitted, the value associated with the role is used.`,
109+
Required: false,
110+
}
111+
70112
return fields
71113
}
72114

path_issue_sign.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,38 @@ func (b *backend) pathIssueSignCert(ctx context.Context, req *logical.Request, d
184184
return nil, fmt.Errorf("Subject Alternative Name " + dns_sans[u] + " not allowed for provided role")
185185
}
186186
}
187+
ou, ok := data.GetOk("ou")
188+
if !ok {
189+
ou = role.OU
190+
}
191+
192+
o, ok := data.GetOk("o")
193+
if !ok {
194+
o = role.Organization
195+
}
196+
197+
c, ok := data.GetOk("c")
198+
if !ok {
199+
c = role.Country
200+
}
201+
202+
l, ok := data.GetOk("l")
203+
if !ok {
204+
l = role.Locality
205+
}
206+
207+
p, ok := data.GetOk("p")
208+
if !ok {
209+
p = role.Province
210+
}
211+
212+
z, ok := data.GetOk("z")
213+
if !ok {
214+
z = role.PostalCode
215+
}
187216

188217
//generate and submit CSR
189-
csr, key := b.generateCSR(cn.(string), ip_sans, dns_sans)
218+
csr, key := b.generateCSR(cn.(string), ip_sans, dns_sans, o.([]string), ou.([]string), l.([]string), p.([]string), c.([]string), z.([]string))
190219
certs, serial, errr := b.submitCSR(ctx, req, csr, caName, templateName)
191220

192221
if errr != nil {
@@ -218,6 +247,8 @@ This path allows requesting a certificate to be issued according to the
218247
policy of the given role. The certificate will only be issued if the
219248
requested details are allowed by the role policy.
220249
250+
The values for C, O, OU, L, S, P (province) and zip (postal code) will be retreived from the role if not supplied as parameters.
251+
221252
This path returns a certificate and a private key. If you want a workflow
222253
that does not expose a private key, generate a CSR locally and use the
223254
sign path instead.

0 commit comments

Comments
 (0)