From 0c4a45f7f13eba3afa6e21fc5d65d9c534593d9c Mon Sep 17 00:00:00 2001 From: Satyam Sinha Date: Fri, 22 May 2020 22:21:39 -0700 Subject: [PATCH] Fixed: Allow tags on command line --- main.go | 2 ++ tgnoob/helpers.go | 13 +++++++++++++ tgnoob/helpers_test.go | 2 ++ tgnoob/noob.go | 4 ++++ 4 files changed, 21 insertions(+) diff --git a/main.go b/main.go index 1098a8f..afdee74 100644 --- a/main.go +++ b/main.go @@ -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) { @@ -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 { diff --git a/tgnoob/helpers.go b/tgnoob/helpers.go index 494c3d5..0212241 100644 --- a/tgnoob/helpers.go +++ b/tgnoob/helpers.go @@ -15,6 +15,7 @@ import ( "crypto/x509" "crypto/x509/pkix" "encoding/asn1" + "encoding/json" "encoding/pem" "fmt" "net" @@ -54,6 +55,7 @@ func GenerateCertificate( orgUnit []string, dns []string, ips []string, + tags []string, duration time.Duration, policies []string, ) error { @@ -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 diff --git a/tgnoob/helpers_test.go b/tgnoob/helpers_test.go index 783757f..6fb7c93 100644 --- a/tgnoob/helpers_test.go +++ b/tgnoob/helpers_test.go @@ -51,6 +51,7 @@ func Test_GenerateCertificate(t *testing.T) { []string{}, // orgUnit []string{}, // dns []string{}, // ips + []string{}, // tags time.Second, // duration []string{}, // policies ) @@ -83,6 +84,7 @@ func Test_GenerateCertificate(t *testing.T) { []string{}, // orgUnit []string{}, // dns []string{}, // ips + []string{}, // tags time.Second, // duration []string{}, // policies ) diff --git a/tgnoob/noob.go b/tgnoob/noob.go index 687a1cb..c1f02e6 100644 --- a/tgnoob/noob.go +++ b/tgnoob/noob.go @@ -57,6 +57,7 @@ func CreateCA( []string{}, // orgUnit []string{}, // dns []string{}, // ips + []string{}, // tags 14*24*time.Hour, // duration []string{}, // policies ); err != nil { @@ -114,6 +115,7 @@ func CreateSignedCA( []string{}, // orgUnit []string{}, // dns []string{}, // ips + []string{}, // tags 14*24*time.Hour, // duration []string{}, // policies ); err != nil { @@ -173,6 +175,7 @@ func CreateClientCertificate( []string{}, // orgUnit dns, // dns ips, // ips + []string{}, // tags 14*24*time.Hour, // duration []string{}, // policies ); err != nil { @@ -231,6 +234,7 @@ func CreateServerCertificate( []string{}, // orgUnit dns, // dns ips, // ips + []string{}, // tags 14*24*time.Hour, // duration []string{}, // policies ); err != nil {