From 1692201fce644bcc3160d9d38cf691a884add283 Mon Sep 17 00:00:00 2001 From: Paul Schroeder Date: Wed, 7 Dec 2022 15:29:08 +0100 Subject: [PATCH 1/2] feat(add): Default public key to .pub if not given --- README.md | 10 ++++++---- cmd/add.go | 10 +++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index efd9a01..10c09cd 100644 --- a/README.md +++ b/README.md @@ -86,28 +86,30 @@ Injects SSL keys to `ssh-agent` stored in 1Password, Bitwarden and AWS S3. ## How to use it -1. Login to Bitwarden or 1Password with `bw` or `op`. If you are using S3, set your credentials. +1. Login to Bitwarden (and export its session key) or 1Password with `bw` or `op`. If you are using S3, set your credentials. 1. Add your key pairs to your password manager. +> **NOTE:** If not public key is given, the private one, postfixed with `.pub`, will be used. + For 1Password --- ```shell -ssh-manager add --name my-another-server --private-key $PK_PATH --public-key $PUB_KEY_PATH --provider op +ssh-manager add --name my-another-server --private-key $PK_PATH [ --public-key $PUB_KEY_PATH ] --provider op ``` For Bitwarden --- ```shell -ssh-manager add --name my-server --private-key $PK_PATH --public-key $PUB_KEY_PATH --provider bw +ssh-manager add --name my-server --private-key $PK_PATH [ --public-key $PUB_KEY_PATH ] --provider bw ``` For AWS S3 --- ```shell -ssh-manager add --name my-another-server --private-key $PK_PATH --public-key $PUB_KEY_PATH --provider s3 --bucket my-bucket +ssh-manager add --name my-another-server --private-key $PK_PATH [ --public-key $PUB_KEY_PATH ] --provider s3 --bucket my-bucket ``` ## Improvements to be made diff --git a/cmd/add.go b/cmd/add.go index 7b45251..29f19d6 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -21,10 +21,6 @@ func setupAddCommand(cmd *cobra.Command) { cmd.Flags().String("public-key", "", "Public Key file") - if err := cmd.MarkFlagRequired("public-key"); err != nil { - log.Fatalf("Lethal damage: %s\n\n", err) - } - cmd.Flags().String("private-key", "", "Private Key file") if err := cmd.MarkFlagRequired("private-key"); err != nil { @@ -52,14 +48,14 @@ func Add() *cobra.Command { providerName, _ := cmd.Flags().GetString("provider") bucket, _ := cmd.Flags().GetString("bucket") - publicKey, err := readFile(publicKeyFileName) + privateKey, err := readFile(privateKeyFileName) if err != nil { return err } - privateKey, err := readFile(privateKeyFileName) + publicKey, err := readFile(publicKeyFileName) if err != nil { - return err + publicKey = privateKey + ".pub" } item := provider.Item{ From 0875955a16c003e6b86d13bf08c06aee56c4aae4 Mon Sep 17 00:00:00 2001 From: Paul Schroeder Date: Wed, 7 Dec 2022 15:29:08 +0100 Subject: [PATCH 2/2] feat(add): Default public key to .pub if not given --- README.md | 10 ++++++---- cmd/add.go | 11 +++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index efd9a01..10c09cd 100644 --- a/README.md +++ b/README.md @@ -86,28 +86,30 @@ Injects SSL keys to `ssh-agent` stored in 1Password, Bitwarden and AWS S3. ## How to use it -1. Login to Bitwarden or 1Password with `bw` or `op`. If you are using S3, set your credentials. +1. Login to Bitwarden (and export its session key) or 1Password with `bw` or `op`. If you are using S3, set your credentials. 1. Add your key pairs to your password manager. +> **NOTE:** If not public key is given, the private one, postfixed with `.pub`, will be used. + For 1Password --- ```shell -ssh-manager add --name my-another-server --private-key $PK_PATH --public-key $PUB_KEY_PATH --provider op +ssh-manager add --name my-another-server --private-key $PK_PATH [ --public-key $PUB_KEY_PATH ] --provider op ``` For Bitwarden --- ```shell -ssh-manager add --name my-server --private-key $PK_PATH --public-key $PUB_KEY_PATH --provider bw +ssh-manager add --name my-server --private-key $PK_PATH [ --public-key $PUB_KEY_PATH ] --provider bw ``` For AWS S3 --- ```shell -ssh-manager add --name my-another-server --private-key $PK_PATH --public-key $PUB_KEY_PATH --provider s3 --bucket my-bucket +ssh-manager add --name my-another-server --private-key $PK_PATH [ --public-key $PUB_KEY_PATH ] --provider s3 --bucket my-bucket ``` ## Improvements to be made diff --git a/cmd/add.go b/cmd/add.go index 7b45251..3c0c97d 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -21,10 +21,6 @@ func setupAddCommand(cmd *cobra.Command) { cmd.Flags().String("public-key", "", "Public Key file") - if err := cmd.MarkFlagRequired("public-key"); err != nil { - log.Fatalf("Lethal damage: %s\n\n", err) - } - cmd.Flags().String("private-key", "", "Private Key file") if err := cmd.MarkFlagRequired("private-key"); err != nil { @@ -47,10 +43,13 @@ func Add() *cobra.Command { Short: "Add Manager key to given provider.", RunE: func(cmd *cobra.Command, args []string) error { name, _ := cmd.Flags().GetString("name") - publicKeyFileName, _ := cmd.Flags().GetString("public-key") - privateKeyFileName, _ := cmd.Flags().GetString("private-key") providerName, _ := cmd.Flags().GetString("provider") bucket, _ := cmd.Flags().GetString("bucket") + privateKeyFileName, _ := cmd.Flags().GetString("private-key") + publicKeyFileName, err := cmd.Flags().GetString("public-key") + if err != nil { + publicKeyFileName = privateKeyFileName + ".pub" + } publicKey, err := readFile(publicKeyFileName) if err != nil {