0

I am currently trying to add grpc-web to a React-App but I just can't make it work with TLS. I don't even know how to import client certificates properly.

I am using grpc with tls and in general the setup is working. Meaning if I use a simple node app (no frontend) all my implemented services work as intended.

So I know with @grpc/grpc-js I can do the following:

import { credentials as _credentials } from '@grpc/grpc-js';
import { readFileSync } from 'fs';


const credentials = _credentials.createSsl(
    readFileSync(__dirname + '../certs/ca.crt'),
    readFileSync(__dirname + '../certs/client.key'),
    readFileSync(__dirname + '../certs/client.crt')
)

But grpc-web does not have the credentials object. What I currently have is just:

const { ProjectMeta, Affirm } = require('./base_pb.js');
const { ProjectClient } = require('./base_grpc_web_pb.js');

// No idea how to import these correctly
// const credentials = ???

let client = new ProjectClient('https://localhost:8443', credentials, null);

I get even more confused when I look at the definition of ProjectClient in base_grpc_web_pb.js.

proto.base.ProjectClient =
    function(hostname, credentials, options) {
  if (!options) options = {};
  options.format = 'text';

  /**
   * @private @const {!grpc.web.GrpcWebClientBase} The client
   */
  this.client_ = new grpc.web.GrpcWebClientBase(options);

  /**
   * @private @const {string} The hostname
   */
  this.hostname_ = hostname;

};

The credentials parameter is not even used???

On the side of grpcwebproxy I just get:

2021/10/22 10:36:16 http: TLS handshake error from [::1]:59530: remote error: tls: unknown certificate

... which is expected I guess?

Hope anyone can help me out with this. Thanks!

David
  • 106
  • 2
  • 10
  • It looks like you are trying to use a client side certificate from a browser? If so [this answer](https://stackoverflow.com/a/14632891/11810946) is relevant. Short answer - requests for client certificates are handled by the browser and cannot be controlled from Javascript - the certificate generally comes from an OS store. – Brits Oct 23 '21 at 04:06

0 Answers0