Skip to content

Commit

Permalink
Merge pull request #12 from libp2p/optimize-cert-chain-generation
Browse files Browse the repository at this point in the history
remove unneeded marshaling / unmarshaling when generating cert chain
  • Loading branch information
marten-seemann authored Feb 17, 2019
2 parents 517ac00 + 9f8a324 commit a16ab88
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions p2p/security/tls/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"math/big"
"time"

"github.com/gogo/protobuf/proto"
ic "github.com/libp2p/go-libp2p-crypto"
pb "github.com/libp2p/go-libp2p-crypto/pb"
peer "github.com/libp2p/go-libp2p-peer"
Expand Down Expand Up @@ -118,24 +117,20 @@ func keyToCertificate(sk ic.PrivKey) (crypto.PrivateKey, *x509.Certificate, erro

var privateKey crypto.PrivateKey
var publicKey crypto.PublicKey
keyBytes, err := sk.Bytes()
raw, err := sk.Raw()
if err != nil {
return nil, nil, err
}
pbmes := new(pb.PrivateKey)
if err := proto.Unmarshal(keyBytes, pbmes); err != nil {
return nil, nil, err
}
switch pbmes.GetType() {
switch sk.Type() {
case pb.KeyType_RSA:
k, err := x509.ParsePKCS1PrivateKey(pbmes.GetData())
k, err := x509.ParsePKCS1PrivateKey(raw)
if err != nil {
return nil, nil, err
}
publicKey = &k.PublicKey
privateKey = k
case pb.KeyType_ECDSA:
k, err := x509.ParseECPrivateKey(pbmes.GetData())
k, err := x509.ParseECPrivateKey(raw)
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit a16ab88

Please sign in to comment.