-
Notifications
You must be signed in to change notification settings - Fork 12
/
glue.go
60 lines (49 loc) · 1.34 KB
/
glue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package golang
import (
"crypto/x509"
"github.com/davidkhala/goutils"
"github.com/davidkhala/goutils/crypto"
. "github.com/davidkhala/goutils/grpc"
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)
func (node Node) AsGRPCClient() (connect *grpc.ClientConn) {
var err error
var certificate *x509.Certificate
var tlsCARootCertBytes = node.TLSCARootByte
if tlsCARootCertBytes == nil {
tlsCARootCertBytes, err = goutils.ReadFile(node.TLSCARoot)
goutils.PanicError(err)
}
certificate = crypto.ParseCertPemOrPanic(tlsCARootCertBytes)
var param = Params{
SslTargetNameOverride: node.SslTargetNameOverride,
Certificate: certificate,
WaitForReady: true,
}
connect, err = Ping(node.Addr, param)
goutils.PanicError(err)
return
}
func LoadCryptoFrom(config CryptoConfig) *Crypto {
priv, err := GetPrivateKey(config.PrivKey)
goutils.PanicError(err)
cert, certBytes, err := GetCertificate(config.SignCert)
goutils.PanicError(err)
id := &msp.SerializedIdentity{
Mspid: config.MSPID,
IdBytes: certBytes,
}
creator, err := proto.Marshal(id)
goutils.PanicError(err)
_crypto := &Crypto{
Creator: creator,
PrivKey: priv,
SignCert: cert,
mspID: config.MSPID,
certificate: certBytes,
}
_crypto.SetDefaultDigest()
return _crypto
}