Skip to content

Commit

Permalink
Merge pull request #10 from cashapp/yoav.simplify-import-command
Browse files Browse the repository at this point in the history
Removed the --cert-file flag
  • Loading branch information
yoavamit authored Nov 3, 2022
2 parents 8dce84c + 9e0e3d6 commit c90a8ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ by setting the `PIVIT_ORG`, `PIVIT_ORG_UNIT`, and `PIVIT_EMAIL` environment vari

## Import certificate to Yubikey
```
pivit --import --cert-file [file]
pivit --import [file]
```

Imports a certificate from `file`.
Expand Down
28 changes: 15 additions & 13 deletions cmd/pivit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func runCommand() error {
verifyFlag := getopt.BoolLong("verify", 0, "verify a signature")
resetFlag := getopt.BoolLong("reset", 'r', "resets the smart card PIV applet and sets new PIN, random PUK, and PIN derived management key")
generateFlag := getopt.BoolLong("generate", 'g', "generates a new key pair and a certificate signing request")
importFlag := getopt.BoolLong("import", 'i', "imports a certificate to the PIV applet")
importOpt := getopt.StringLong("import", 'i', "", "imports a certificate to the PIV applet", "file")
printFlag := getopt.BoolLong("print", 'p', "prints the certificate and its fingerprint")

localUserOpt := getopt.StringLong("local-user", 'u', "", "use USER-ID to sign", "USER-ID")
Expand All @@ -30,20 +30,25 @@ func runCommand() error {
statusFdOpt := getopt.IntLong("status-fd", 0, -1, "write special status strings to the file descriptor n.", "n")
tsaOpt := getopt.StringLong("timestamp-authority", 't', "", "URL of RFC3161 timestamp authority to use for timestamping", "url")

certFileOpt := getopt.StringLong("cert-file", 0, "", "certificate file")

getopt.HelpColumn = 40
getopt.SetParameters("[files]")
getopt.Parse()
fileArgs := getopt.Args()

var importFlag bool
if len(*importOpt) > 0 {
importFlag = true
} else {
importFlag = false
}

if *helpFlag {
getopt.Usage()
return nil
}

if *signFlag {
if *verifyFlag || *generateFlag || *resetFlag || *importFlag || *printFlag {
if *verifyFlag || *generateFlag || *resetFlag || importFlag || *printFlag {
return errors.New("specify --help, --sign, --verify, --import, --generate, --reset or --print")
} else if len(*localUserOpt) == 0 {
return errors.New("specify a USER-ID to sign with")
Expand All @@ -52,7 +57,7 @@ func runCommand() error {
}

if *verifyFlag {
if *signFlag || *generateFlag || *resetFlag || *importFlag || *printFlag {
if *signFlag || *generateFlag || *resetFlag || importFlag || *printFlag {
return errors.New("specify --help, --sign, --verify, --import, --generate, --reset or --print")
} else if len(*localUserOpt) > 0 {
return errors.New("local-user cannot be specified for verification")
Expand All @@ -65,31 +70,28 @@ func runCommand() error {
}

if *resetFlag {
if *signFlag || *verifyFlag || *generateFlag || *importFlag || *printFlag {
if *signFlag || *verifyFlag || *generateFlag || importFlag || *printFlag {
return errors.New("specify --help, --sign, --verify, --import, --generate, --reset or --print")
}
return commandReset()
}

if *generateFlag {
if *signFlag || *verifyFlag || *resetFlag || *importFlag || *printFlag {
if *signFlag || *verifyFlag || *resetFlag || importFlag || *printFlag {
return errors.New("specify --help, --sign, --verify, --import, --generate, --reset or --print")
}
return commandGenerate()
}

if *importFlag {
if importFlag {
if *signFlag || *verifyFlag || *generateFlag || *resetFlag || *printFlag {
return errors.New("specify --help, --sign, --verify, --import, --generate, --reset or --print")
}
if *certFileOpt == "" {
return errors.New("specify --cert-file [file] for certificate import")
}
return commandImport(*certFileOpt)
return commandImport(*importOpt)
}

if *printFlag {
if *signFlag || *verifyFlag || *generateFlag || *resetFlag || *importFlag {
if *signFlag || *verifyFlag || *generateFlag || *resetFlag || importFlag {
return errors.New("specify --help, --sign, --verify, --import, --generate, --reset or --print")
}
return commandPrint()
Expand Down

0 comments on commit c90a8ab

Please sign in to comment.