Skip to content
Snippets Groups Projects
Commit 4625ab38 authored by Viktor Popov's avatar Viktor Popov
Browse files

Added pem format for generated keys

parent 53319814
No related branches found
No related tags found
1 merge request!4Resolve "Make private key to be persisted just in PEM format"
......@@ -75,7 +75,9 @@ func (s *KeyStorageServerImpl) GenerateCertificate(ctx context.Context, in *api.
func generateCertificate(publicKeyBytes []byte, caCertFilePath string, caPrivateKeyFilePath string,
certificateData *api.GenerateCertificateRequest_CertificateData) ([]byte, error) {
publicKey, err := x509.ParsePKIXPublicKey(publicKeyBytes)
publicKeyPemBlock, _ := pem.Decode(publicKeyBytes)
publicKey, err := x509.ParsePKIXPublicKey(publicKeyPemBlock.Bytes)
if err != nil {
return nil, err
}
......
......@@ -24,6 +24,7 @@ import (
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/pem"
"code.vereign.com/code/viam-apis/data-storage-agent/client"
"code.vereign.com/code/viam-apis/key-storage-agent/api"
......@@ -129,15 +130,30 @@ func generateKeyPair(keySize int) ([]byte, []byte, error) {
publicKey := &privateKey.PublicKey
privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(privateKey)
pkcs8PrivateKeyBytes, err := x509.MarshalPKCS8PrivateKey(privateKey)
if err != nil {
return nil, nil, err
}
publicKeyBytes, err := x509.MarshalPKIXPublicKey(publicKey)
privateKeyPemBlock := &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: pkcs8PrivateKeyBytes,
}
privateKeyBytes := pem.EncodeToMemory(privateKeyPemBlock)
pkixPublicKeyBytes, err := x509.MarshalPKIXPublicKey(publicKey)
if err != nil {
return nil, nil, err
}
publicKeyPemBlock := &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: pkixPublicKeyBytes,
}
publicKeyBytes := pem.EncodeToMemory(publicKeyPemBlock)
return privateKeyBytes, publicKeyBytes, nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment