Skip to content

Commit

Permalink
Fixed: Allow tags on command line
Browse files Browse the repository at this point in the history
  • Loading branch information
Satyam Sinha authored and brianonn committed Dec 6, 2024
1 parent a145f53 commit 0c4a45f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func addPKIXFlags(cmd *cobra.Command) {
cmd.Flags().StringSlice("address", nil, "Address that will be written the the subject.")
cmd.Flags().StringSlice("dns", nil, "List of alternate DNS names.")
cmd.Flags().StringSlice("ip", nil, "List of alternate ips.")
cmd.Flags().StringSlice("tags", nil, "List of tags.")
}

func addSigningFlags(cmd *cobra.Command) {
Expand Down Expand Up @@ -200,6 +201,7 @@ func generateCertificate() {
viper.GetStringSlice("org-unit"),
viper.GetStringSlice("dns"),
viper.GetStringSlice("ip"),
viper.GetStringSlice("tags"),
getValidity(viper.GetDuration("validity"), viper.GetBool("is-ca")),
viper.GetStringSlice("policy"),
); err != nil {
Expand Down
13 changes: 13 additions & 0 deletions tgnoob/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/asn1"
"encoding/json"
"encoding/pem"
"fmt"
"net"
Expand Down Expand Up @@ -54,6 +55,7 @@ func GenerateCertificate(
orgUnit []string,
dns []string,
ips []string,
tags []string,
duration time.Duration,
policies []string,
) error {
Expand Down Expand Up @@ -128,6 +130,17 @@ func GenerateCertificate(
}
options = append(options, tglib.OptIssueIPSANs(netips...))

tagsj, err := json.Marshal(tags)
if err != nil {
return fmt.Errorf("unable to process tags: %s", err.Error())
}
options = append(options, tglib.OptIssueExtraExtensions([]pkix.Extension{
{
Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 50798, 1, 1},
Value: tagsj,
},
}))

asnIdentifiers, err := makePolicies(policies)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions tgnoob/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func Test_GenerateCertificate(t *testing.T) {
[]string{}, // orgUnit
[]string{}, // dns
[]string{}, // ips
[]string{}, // tags
time.Second, // duration
[]string{}, // policies
)
Expand Down Expand Up @@ -83,6 +84,7 @@ func Test_GenerateCertificate(t *testing.T) {
[]string{}, // orgUnit
[]string{}, // dns
[]string{}, // ips
[]string{}, // tags
time.Second, // duration
[]string{}, // policies
)
Expand Down
4 changes: 4 additions & 0 deletions tgnoob/noob.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func CreateCA(
[]string{}, // orgUnit
[]string{}, // dns
[]string{}, // ips
[]string{}, // tags
14*24*time.Hour, // duration
[]string{}, // policies
); err != nil {
Expand Down Expand Up @@ -114,6 +115,7 @@ func CreateSignedCA(
[]string{}, // orgUnit
[]string{}, // dns
[]string{}, // ips
[]string{}, // tags
14*24*time.Hour, // duration
[]string{}, // policies
); err != nil {
Expand Down Expand Up @@ -173,6 +175,7 @@ func CreateClientCertificate(
[]string{}, // orgUnit
dns, // dns
ips, // ips
[]string{}, // tags
14*24*time.Hour, // duration
[]string{}, // policies
); err != nil {
Expand Down Expand Up @@ -231,6 +234,7 @@ func CreateServerCertificate(
[]string{}, // orgUnit
dns, // dns
ips, // ips
[]string{}, // tags
14*24*time.Hour, // duration
[]string{}, // policies
); err != nil {
Expand Down

0 comments on commit 0c4a45f

Please sign in to comment.