-
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.
An idea is to continue building Fioctl statically, and provide HSM support by wrapping pkcs11-tool. The tool is available for Linux, Windows, and Darwin; a user can also build from source. Signed-off-by: Volodymyr Khoroz <[email protected]>
- Loading branch information
Showing
8 changed files
with
215 additions
and
61 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
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
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
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,14 @@ | ||
//go:build windows || !bashPKI | ||
|
||
package x509 | ||
|
||
import ( | ||
"testing" | ||
"fmt" | ||
) | ||
|
||
func TestHsm(t *testing.T) { | ||
storage := &KeyStorageHsm{HsmInfo{"/usr/lib/softhsm/libsofthsm2.so", "1234", "mine"}} | ||
|
||
fmt.Println(CreateFactoryCa(storage, "test")) | ||
} |
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,38 @@ | ||
//go:build windows || !bashPKI | ||
|
||
package x509 | ||
|
||
import ( | ||
"crypto" | ||
"crypto/ecdsa" | ||
"crypto/elliptic" | ||
"crypto/rand" | ||
"crypto/x509" | ||
"encoding/pem" | ||
"os" | ||
|
||
"github.com/foundriesio/fioctl/subcommands" | ||
) | ||
|
||
func genAndSaveKeyToFile(fn string) (crypto.Signer, crypto.PublicKey) { | ||
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||
subcommands.DieNotNil(err) | ||
|
||
keyRaw, err := x509.MarshalECPrivateKey(priv) | ||
subcommands.DieNotNil(err) | ||
|
||
keyBlock := &pem.Block{Type: "EC PRIVATE KEY", Bytes: keyRaw} | ||
|
||
factoryKeyBytes := pem.EncodeToMemory(keyBlock) | ||
err = os.WriteFile(fn, factoryKeyBytes, 0600) | ||
subcommands.DieNotNil(err) | ||
return priv, &priv.PublicKey | ||
} | ||
|
||
func loadKeyFromFile(fn string) crypto.Signer { | ||
keyPem := readFile(fn) | ||
caPrivateKeyPemBlock, _ := pem.Decode([]byte(keyPem)) | ||
caPrivateKey, err := x509.ParseECPrivateKey(caPrivateKeyPemBlock.Bytes) | ||
subcommands.DieNotNil(err) | ||
return caPrivateKey | ||
} |
Oops, something went wrong.