1
0
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:
nbari
2017-04-05 16:40:36 +02:00
parent 5aee4eae3d
commit 5fc244c42e
4 changed files with 32 additions and 9 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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)