Skip to content
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

Add parameter for OU name #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
27 changes: 16 additions & 11 deletions certgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
ed25519Key = flag.Bool("ed25519", false, "Generate an Ed25519 key")
orgName = flag.String("org-name", "Certgen Development", "Organization name used when generating the certs")
commonName = flag.String("common-name", "", "Common name for client cert")
ouName = flag.String("ou-name", "", "Organizational unit name for cert. Defaults to username@hostname")
isNoCA = flag.Bool("no-ca", false, "whether this cert should not be its own Certificate Authority")
isClient = flag.Bool("client", false, "whether this cert is a client certificate")
validFrom = flag.String("start-date", "", "Creation date formatted as Jan 1 15:04:05 2011")
Expand All @@ -54,18 +55,22 @@ func publicKey(priv interface{}) interface{} {
}
}

var userAndHostname string
var organizationalUnit string

func init() {
u, err := user.Current()
if err == nil {
userAndHostname = u.Username + "@"
}
if h, err := os.Hostname(); err == nil {
userAndHostname += h
}
if err == nil && u.Name != "" && u.Name != u.Username {
userAndHostname += " (" + u.Name + ")"
if *ouName == "" {
u, err := user.Current()
if err == nil {
organizationalUnit = u.Username + "@"
}
if h, err := os.Hostname(); err == nil {
organizationalUnit += h
}
if err == nil && u.Name != "" && u.Name != u.Username {
organizationalUnit += " (" + u.Name + ")"
}
} else {
organizationalUnit = *ouName
}
}

Expand Down Expand Up @@ -124,7 +129,7 @@ func main() {
SerialNumber: serialNumber,
Subject: pkix.Name{
Organization: []string{*orgName},
OrganizationalUnit: []string{userAndHostname},
OrganizationalUnit: []string{organizationalUnit},
},
NotBefore: notBefore,
NotAfter: notAfter,
Expand Down