-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Volodymyr Khoroz <[email protected]>
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package keys | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
//"github.com/foundriesio/fioctl/client" | ||
"github.com/foundriesio/fioctl/subcommands" | ||
"github.com/foundriesio/fioctl/x509" | ||
) | ||
|
||
func init() { | ||
cmd := &cobra.Command{ | ||
Use: "re-sign-device-ca <PKI Directory> [<Old PKI Directory>]", | ||
Short: "Re-sign all existing Device CAs with a new root CA for your Factory PKI", | ||
Run: doReSignDeviceCaRenewal, | ||
Args: cobra.RangeArgs(1, 2), | ||
Long: `Re-sign all existing Device CAs with a new root CA for your Factory PKI. | ||
Both currently active and disabled Device CAs are being re-signed. | ||
All their properties are preserved, including a serial number. | ||
Only the signature and authority key ID are being changed. | ||
This allows old certificates (issued by a previous root CA) to continue being used to issue device client certificates. | ||
Re-signed device CA certificates are stored in the provided PKI directory. | ||
An old PKI directory is used to locate corresponding private keys, and copy them into the PKI directory. | ||
Each located device CA gets the same file name, as it was in the old PKI directory. | ||
If a device CA certificate cannot be located in an old PKI directory - it does not get stored locally. | ||
If an old PKI directory argument is not provided, new certificates are not stored locally. | ||
`, | ||
} | ||
caRenewalCmd.AddCommand(cmd) | ||
cmd.Flags().StringVarP(&hsmModule, "hsm-module", "", "", "Load a root CA key from a PKCS#11 compatible HSM using this module") | ||
cmd.Flags().StringVarP(&hsmPin, "hsm-pin", "", "", "The PKCS#11 PIN to log into the HSM") | ||
cmd.Flags().StringVarP(&hsmTokenLabel, "hsm-token-label", "", "", "The label of the HSM token holding the root CA key") | ||
} | ||
|
||
func doReSignDeviceCaRenewal(cmd *cobra.Command, args []string) { | ||
factory := viper.GetString("factory") | ||
certsDir := args[0] | ||
oldCertsDir := args[1] | ||
subcommands.DieNotNil(os.Chdir(certsDir)) | ||
hsm, err := x509.ValidateHsmArgs( | ||
hsmModule, hsmPin, hsmTokenLabel, "--hsm-module", "--hsm-pin", "--hsm-token-label") | ||
subcommands.DieNotNil(err) | ||
x509.InitHsm(hsm) | ||
|
||
// TBD: load serial-to-filename map from oldCertsDir | ||
// TBD: fetch current device CAs from the server, re-sign them, store locally (if matched), and upload back. | ||
// TBD - linter | ||
fmt.Println(factory, oldCertsDir) | ||
} | ||
|
||
// TBD: commands to add: | ||
// # Re-sign existing TLS certs. As we don't care for their serial numbers - it is an alias to "fioctl keys rotate-tls". | ||
// - fioctl keys renewal re-sign-tls <PKI Directory> | ||
// # Revoke a specific root CA by its serial number. Cannot revoke currently active root CA. | ||
// # This also revokes the cross-signed renewal bundle root CAs, associated with this root CA. | ||
// - fioctl keys renewal revoke-root <PKI Directory> --serial | ||
|
||
// There will be no such command as `fioctl keys renewal finish`. | ||
// Otherwise, users would often abuse it, leading to devices losing connectivity. | ||
// Having harder to grasp command names, like e.g. revoke-root makes this process more controlled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters