Skip to content

Commit

Permalink
Support exporting RSA keys
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnayak committed Oct 26, 2017
1 parent 9ea5196 commit 4acd786
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 0 additions & 3 deletions builtin/logical/transit/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ func createBackendWithStorage(t *testing.T) (*backend, logical.Storage) {
}

func TestTransit_RSA(t *testing.T) {
fmt.Printf("now running rsa-2048\n")
testTransit_RSA(t, "rsa-2048")

fmt.Printf("now running rsa-4096\n")
testTransit_RSA(t, "rsa-4096")
}

Expand Down
10 changes: 10 additions & 0 deletions builtin/logical/transit/path_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ func getExportKey(policy *keysutil.Policy, key *keysutil.KeyEntry, exportType st
switch policy.Type {
case keysutil.KeyType_AES256_GCM96:
return strings.TrimSpace(base64.StdEncoding.EncodeToString(key.Key)), nil

case keysutil.KeyType_RSA2048, keysutil.KeyType_RSA4096:
derBytes := x509.MarshalPKCS1PrivateKey(key.RSAKey)
pemBlock := &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: derBytes,
}
pemBytes := pem.EncodeToMemory(pemBlock)
return string(pemBytes), nil

}

case exportTypeSigningKey:
Expand Down
2 changes: 1 addition & 1 deletion builtin/logical/transit/path_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (b *backend) pathPolicyRead(
return nil, fmt.Errorf("error marshaling RSA public key: %v", err)
}
pemBlock := &pem.Block{
Type: "PUBLIC KEY",
Type: "RSA PUBLIC KEY",
Bytes: derBytes,
}
pemBytes := pem.EncodeToMemory(pemBlock)
Expand Down

0 comments on commit 4acd786

Please sign in to comment.