Exemplo n.º 1
0
func (node *nodeImpl) getTCAClient() (*grpc.ClientConn, obcca.TCAPClient, error) {
	node.debug("Getting TCA client...")

	conn, err := node.getClientConn(node.conf.getTCAPAddr(), node.conf.getTCAServerName())
	if err != nil {
		node.error("Failed getting client connection: [%s]", err)
	}

	client := obcca.NewTCAPClient(conn)

	node.debug("Getting TCA client...done")

	return conn, client, nil
}
Exemplo n.º 2
0
func (client *clientImpl) tcaCreateCertificateSet(num int) ([]byte, [][]byte, error) {
	sockP, err := grpc.Dial(client.node.conf.getTCAPAddr(), grpc.WithInsecure())
	if err != nil {
		client.node.log.Error("Failed tca dial in [%s].", err.Error())

		return nil, nil, err
	}
	defer sockP.Close()

	tcaP := obcca.NewTCAPClient(sockP)

	now := time.Now()
	timestamp := google_protobuf.Timestamp{int64(now.Second()), int32(now.Nanosecond())}
	req := &obcca.TCertCreateSetReq{
		&timestamp,
		&obcca.Identity{Id: client.node.enrollID},
		uint32(num),
		nil,
	}
	rawReq, err := proto.Marshal(req)
	if err != nil {
		client.node.log.Error("Failed marshaling request [%s] [%s].", err.Error())
		return nil, nil, err
	}

	// 2. Sign rawReq
	client.node.log.Debug("Signing req  ", utils.EncodeBase64(rawReq))
	r, s, err := client.node.ecdsaSignWithEnrollmentKey(rawReq)
	if err != nil {
		client.node.log.Error("Failed creating signature [%s] [%s].", err.Error())
		return nil, nil, err
	}

	R, _ := r.MarshalText()
	S, _ := s.MarshalText()

	// 3. Append the signature
	req.Sig = &obcca.Signature{obcca.CryptoType_ECDSA, R, S}

	// 4. Send request
	certSet, err := tcaP.CreateCertificateSet(context.Background(), req)
	if err != nil {
		client.node.log.Error("Failed requesting tca create certificate set [%s].", err.Error())

		return nil, nil, err
	}

	return certSet.Key, certSet.Certs, nil
}
Exemplo n.º 3
0
func (node *nodeImpl) callTCAReadCertificate(ctx context.Context, in *obcca.TCertReadReq, opts ...grpc.CallOption) (*obcca.Cert, error) {
	sockP, err := grpc.Dial(node.conf.getTCAPAddr(), grpc.WithInsecure())
	if err != nil {
		node.log.Error("Failed tca dial in [%s].", err.Error())

		return nil, err
	}
	defer sockP.Close()

	tcaP := obcca.NewTCAPClient(sockP)

	cert, err := tcaP.ReadCertificate(context.Background(), in)
	if err != nil {
		node.log.Error("Failed requesting tca read certificate [%s].", err.Error())

		return nil, err
	}

	return cert, nil
}