Skip to content

Commit 42924a5

Browse files
committed
Add PKCS11 related flags: --rsh-pkcs11-label, --rsh-pkcs11-flag
1 parent cfcaefb commit 42924a5

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

cli/cli.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ Not after (expires): %s (%s)
549549
AddGlobalFlag("rsh-insecure", "", "Disable SSL verification", false, false)
550550
AddGlobalFlag("rsh-client-cert", "", "Path to a PEM encoded client certificate", "", false)
551551
AddGlobalFlag("rsh-client-key", "", "Path to a PEM encoded private key", "", false)
552+
AddGlobalFlag("rsh-pkcs11-label", "", "Label of the PKCS11 token", "", false)
553+
AddGlobalFlag("rsh-pkcs11-path", "", "Path to the PKCS11 library", "", false)
552554
AddGlobalFlag("rsh-ca-cert", "", "Path to a PEM encoded CA cert", "", false)
553555
AddGlobalFlag("rsh-ignore-status-code", "", "Do not set exit code from HTTP status code", false, false)
554556
AddGlobalFlag("rsh-retry", "", "Number of times to retry on certain failures", 2, false)
@@ -764,6 +766,12 @@ func Run() (returnErr error) {
764766
if caCert, _ := GlobalFlags.GetString("rsh-ca-cert"); caCert != "" {
765767
viper.Set("rsh-ca-cert", caCert)
766768
}
769+
if pkcs11Label, _ := GlobalFlags.GetString("rsh-pkcs11-label"); pkcs11Label != "" {
770+
viper.Set("rsh-pkcs11-label", pkcs11Label)
771+
}
772+
if pkcs11Path, _ := GlobalFlags.GetString("rsh-pkcs11-path"); pkcs11Path != "" {
773+
viper.Set("rsh-pkcs11-path", pkcs11Path)
774+
}
767775
if query, _ := GlobalFlags.GetStringArray("rsh-query"); len(query) > 0 {
768776
viper.Set("rsh-query", query)
769777
}

cli/request.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ func MakeRequest(req *http.Request, options ...requestOption) (*http.Response, e
205205
if caCert := viper.GetString("rsh-ca-cert"); caCert != "" {
206206
config.TLS.CACert = caCert
207207
}
208+
if pkcs11Label := viper.GetString("rsh-pkcs11-label"); pkcs11Label != "" {
209+
config.TLS.PKCS11 = &PKCS11Config{
210+
Label: pkcs11Label,
211+
}
212+
}
213+
if pkcs11Path := viper.GetString("rsh-pkcs11-path"); pkcs11Path != "" {
214+
if config.TLS.PKCS11 != nil && config.TLS.PKCS11.Label != "" {
215+
config.TLS.PKCS11.Path = pkcs11Path
216+
}
217+
}
208218

209219
if config.TLS.InsecureSkipVerify {
210220
LogWarning("Disabling TLS security checks")

docs/configuration.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,23 @@ You can quickly determine which is being used via `restish localhost -v 2>&1 | g
2525

2626
The global options in addition to `--help` and `--version` are:
2727

28-
| Argument | Env Var | Example | Description |
29-
| --------------------------- | ------------------- | ------------------- | ------------------------------------------------------------------------------------------ |
30-
| `-f`, `--rsh-filter` | `RSH_FILTER` | `body.users[].id` | Filter response via [Shorthand query](https://github.com/danielgtaylor/shorthand#querying) |
31-
| `-H`, `--rsh-header` | `RSH_HEADER` | `Version:2020-05` | Set a header name/value |
32-
| `--rsh-insecure` | `RSH_INSECURE` | | Disable TLS certificate checks |
33-
| `--rsh-client-cert` | `RSH_CLIENT_CERT` | `/etc/ssl/cert.pem` | Path to a PEM encoded client certificate |
34-
| `--rsh-client-key` | `RSH_CLIENT_KEY` | `/etc/ssl/key.pem` | Path to a PEM encoded private key |
35-
| `--rsh-ca-cert` | `RSH_CA_CERT` | `/etc/ssl/ca.pem` | Path to a PEM encoded CA certificate |
36-
| `--rsh-no-paginate` | `RSH_NO_PAGINATE` | | Disable automatic `next` link pagination |
37-
| `-o`, `--rsh-output-format` | `RSH_OUTPUT_FORMAT` | `json` | [Output format](/output.md), defaults to `auto` |
38-
| `-p`, `--rsh-profile` | `RSH_PROFILE` | `testing` | Auth profile name, defaults to `default` |
39-
| `-q`, `--rsh-query` | `RSH_QUERY` | `search=foo` | Set a query parameter |
40-
| `-r`, `--rsh-raw` | `RSH_RAW` | | Raw output for shell processing |
41-
| `-s`, `--rsh-server` | `RSH_SERVER` | `https://foo.com` | Override API server base URL |
42-
| `-v`, `--rsh-verbose` | `RSH_VERBOSE` | | Enable verbose output |
28+
| Argument | Env Var | Example | Description |
29+
| --------------------------- | ------------------- | --------------------------------------| ------------------------------------------------------------------------------------------ |
30+
| `-f`, `--rsh-filter` | `RSH_FILTER` | `body.users[].id` | Filter response via [Shorthand query](https://github.com/danielgtaylor/shorthand#querying) |
31+
| `-H`, `--rsh-header` | `RSH_HEADER` | `Version:2020-05` | Set a header name/value |
32+
| `--rsh-insecure` | `RSH_INSECURE` | | Disable TLS certificate checks |
33+
| `--rsh-client-cert` | `RSH_CLIENT_CERT` | `/etc/ssl/cert.pem` | Path to a PEM encoded client certificate |
34+
| `--rsh-client-key` | `RSH_CLIENT_KEY` | `/etc/ssl/key.pem` | Path to a PEM encoded private key |
35+
| `--rsh-ca-cert` | `RSH_CA_CERT` | `/etc/ssl/ca.pem` | Path to a PEM encoded CA certificate |
36+
| `--rsh-pkcs11-label` | `RSH_PKCS11_LABEL` | | Label of the PKCS11 token |
37+
| `--rsh-pkcs11-path` | `RSH_PKCS11_PATH` | `/usr/lib/pkcs11/opensc-pkcs11.so` | Path to the PKCS11 library |
38+
| `--rsh-no-paginate` | `RSH_NO_PAGINATE` | | Disable automatic `next` link pagination |
39+
| `-o`, `--rsh-output-format` | `RSH_OUTPUT_FORMAT` | `json` | [Output format](/output.md), defaults to `auto` |
40+
| `-p`, `--rsh-profile` | `RSH_PROFILE` | `testing` | Auth profile name, defaults to `default` |
41+
| `-q`, `--rsh-query` | `RSH_QUERY` | `search=foo` | Set a query parameter |
42+
| `-r`, `--rsh-raw` | `RSH_RAW` | | Raw output for shell processing |
43+
| `-s`, `--rsh-server` | `RSH_SERVER` | `https://foo.com` | Override API server base URL |
44+
| `-v`, `--rsh-verbose` | `RSH_VERBOSE` | | Enable verbose output |
4345

4446
Configuration file keys are the same as long-form arguments without the `--` prefix.
4547

0 commit comments

Comments
 (0)