Skip to content

Commit 0c4a45f

Browse files
Satyam Sinhabrianonn
authored andcommitted
Fixed: Allow tags on command line
1 parent a145f53 commit 0c4a45f

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func addPKIXFlags(cmd *cobra.Command) {
4848
cmd.Flags().StringSlice("address", nil, "Address that will be written the the subject.")
4949
cmd.Flags().StringSlice("dns", nil, "List of alternate DNS names.")
5050
cmd.Flags().StringSlice("ip", nil, "List of alternate ips.")
51+
cmd.Flags().StringSlice("tags", nil, "List of tags.")
5152
}
5253

5354
func addSigningFlags(cmd *cobra.Command) {
@@ -200,6 +201,7 @@ func generateCertificate() {
200201
viper.GetStringSlice("org-unit"),
201202
viper.GetStringSlice("dns"),
202203
viper.GetStringSlice("ip"),
204+
viper.GetStringSlice("tags"),
203205
getValidity(viper.GetDuration("validity"), viper.GetBool("is-ca")),
204206
viper.GetStringSlice("policy"),
205207
); err != nil {

tgnoob/helpers.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"crypto/x509"
1616
"crypto/x509/pkix"
1717
"encoding/asn1"
18+
"encoding/json"
1819
"encoding/pem"
1920
"fmt"
2021
"net"
@@ -54,6 +55,7 @@ func GenerateCertificate(
5455
orgUnit []string,
5556
dns []string,
5657
ips []string,
58+
tags []string,
5759
duration time.Duration,
5860
policies []string,
5961
) error {
@@ -128,6 +130,17 @@ func GenerateCertificate(
128130
}
129131
options = append(options, tglib.OptIssueIPSANs(netips...))
130132

133+
tagsj, err := json.Marshal(tags)
134+
if err != nil {
135+
return fmt.Errorf("unable to process tags: %s", err.Error())
136+
}
137+
options = append(options, tglib.OptIssueExtraExtensions([]pkix.Extension{
138+
{
139+
Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 50798, 1, 1},
140+
Value: tagsj,
141+
},
142+
}))
143+
131144
asnIdentifiers, err := makePolicies(policies)
132145
if err != nil {
133146
return err

tgnoob/helpers_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func Test_GenerateCertificate(t *testing.T) {
5151
[]string{}, // orgUnit
5252
[]string{}, // dns
5353
[]string{}, // ips
54+
[]string{}, // tags
5455
time.Second, // duration
5556
[]string{}, // policies
5657
)
@@ -83,6 +84,7 @@ func Test_GenerateCertificate(t *testing.T) {
8384
[]string{}, // orgUnit
8485
[]string{}, // dns
8586
[]string{}, // ips
87+
[]string{}, // tags
8688
time.Second, // duration
8789
[]string{}, // policies
8890
)

tgnoob/noob.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func CreateCA(
5757
[]string{}, // orgUnit
5858
[]string{}, // dns
5959
[]string{}, // ips
60+
[]string{}, // tags
6061
14*24*time.Hour, // duration
6162
[]string{}, // policies
6263
); err != nil {
@@ -114,6 +115,7 @@ func CreateSignedCA(
114115
[]string{}, // orgUnit
115116
[]string{}, // dns
116117
[]string{}, // ips
118+
[]string{}, // tags
117119
14*24*time.Hour, // duration
118120
[]string{}, // policies
119121
); err != nil {
@@ -173,6 +175,7 @@ func CreateClientCertificate(
173175
[]string{}, // orgUnit
174176
dns, // dns
175177
ips, // ips
178+
[]string{}, // tags
176179
14*24*time.Hour, // duration
177180
[]string{}, // policies
178181
); err != nil {
@@ -231,6 +234,7 @@ func CreateServerCertificate(
231234
[]string{}, // orgUnit
232235
dns, // dns
233236
ips, // ips
237+
[]string{}, // tags
234238
14*24*time.Hour, // duration
235239
[]string{}, // policies
236240
); err != nil {

0 commit comments

Comments
 (0)