mirror of
https://github.com/ssh-vault/ssh-vault.git
synced 2025-12-25 00:21:00 +03:00
GetRSAPublicKey - need to improve this in order to support ed25519
This commit is contained in:
@@ -104,6 +104,10 @@ func main() {
|
||||
exit1(err)
|
||||
}
|
||||
|
||||
vault.PublicKey, err = vault.GetRSAPublicKey(PKCS8)
|
||||
if err != nil {
|
||||
exit1(err)
|
||||
}
|
||||
vault.Fingerprint, err = vault.GenFingerprint(PKCS8)
|
||||
if err != nil {
|
||||
exit1(err)
|
||||
|
||||
@@ -29,6 +29,11 @@ func TestCreate(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
vault.PublicKey, err = vault.GetRSAPublicKey(PKCS8)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
vault.Fingerprint, err = vault.GenFingerprint(PKCS8)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
22
vault.go
22
vault.go
@@ -79,15 +79,6 @@ func (v *vault) PKCS8() (*pem.Block, error) {
|
||||
|
||||
// Fingerprint return finerprint of ssh-key
|
||||
func (v *vault) GenFingerprint(p *pem.Block) (string, error) {
|
||||
pubkeyInterface, err := x509.ParsePKIXPublicKey(p.Bytes)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var ok bool
|
||||
v.PublicKey, ok = pubkeyInterface.(*rsa.PublicKey)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("No Public key found")
|
||||
}
|
||||
fingerPrint := md5.New()
|
||||
fingerPrint.Write(p.Bytes)
|
||||
return strings.Replace(fmt.Sprintf("% x",
|
||||
@@ -96,3 +87,16 @@ func (v *vault) GenFingerprint(p *pem.Block) (string, error) {
|
||||
":",
|
||||
-1), nil
|
||||
}
|
||||
|
||||
// GetRSAPublicKey return rsa.PublicKey
|
||||
func (v *vault) GetRSAPublicKey(p *pem.Block) (*rsa.PublicKey, error) {
|
||||
pubkeyInterface, err := x509.ParsePKIXPublicKey(p.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rsaPublicKey, ok := pubkeyInterface.(*rsa.PublicKey)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("No Public key found")
|
||||
}
|
||||
return rsaPublicKey, nil
|
||||
}
|
||||
|
||||
@@ -67,6 +67,11 @@ func TestVaultFunctions(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
vault.PublicKey, err = vault.GetRSAPublicKey(PKCS8)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
vault.Fingerprint, err = vault.GenFingerprint(PKCS8)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -154,6 +159,11 @@ func TestVaultFunctionsSTDOUT(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
vault.PublicKey, err = vault.GetRSAPublicKey(PKCS8)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
vault.Fingerprint, err = vault.GenFingerprint(PKCS8)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user