Skip to content

Fixed: Allow tags on command line #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("tag", 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("tag"),
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
Loading