java - gRPC: Generate certificateChainFile and privateKeyFile to make TLS/SSL work


Question: 

I want to make tls/ssl connection between client and server(Not mutual, one way).

This is my setup:

Server:

    Server server = ServerBuilder.forPort(8443)
        // Enable TLS
        .useTransportSecurity(certChainFile, privateKeyFile)
        .addService(new GreetingServiceImpl())
        .build();

Client

    // With server authentication SSL/TLS
   ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8443)
       .build();
   GreetingServiceGrpc.GreetingServiceBlockingStub stub =
            GreetingServiceGrpc.newBlockingStub(channel);

All I need is Terminal commands to generate certChainFile and privateKeyFile(in .pem) to pass these file to server code as shown above.




1 Answer: 

All I need is Terminal commands to generate certChainFile and privateKeyFile

openssl req -x509 -newkey rsa:1024 -keyout ./testkey.pem -out ./testcert.crt -days 999 -subj "/CN=localhost"

This command generates a an RSA key and a self-signed certificate.

But you need more than that.

  1. SSL by default checks the common name (CN) equals the hostname. Therefore you need to generate certificate which has CN=localhost

  2. the client must trust the server's certificate, so the certificate needs to be imported into the client's trustore (though I am not sure how to configure the trust-store for the client, I will leave it up to you).

 

More Articles


clone a git repository with SSH and libgit2sharp

I'm trying to use the library "libgit2sharp" to clone a repository via a SSH key and... I can't find anything... I can clone it via "https" but what I'd like to do is using an SSH key. It's really unclear if it is supported or not.

Split String With Numbers in R

This question already has an answer here: Split a string by any number of spaces 2 answers

Access remote git repo via ssh, using libgit2sharp

I'm trying to get a simple working example for cloning or accessing a remote git repository via ssh. After adding nuget package LibGit2Sharp-SSH v1.0.22, got a .Net Framework v4.6.1 console application like this:using LibGit2Sharp;using System;using System.IO;class Program{ static void Main(strin


javascript - onDelete not being called when deleting a node in Cloud Functions for Firebase

I am trying to build triggers for a firebase app around following and followers. Below is a snippet of my cloud code. I want to increase a counter when a user follows. For this I use oncreate (for when the user gains their first follower due the structure not existing until this point) and then I

php - mcrypt module open function is missing in php7.2.7

In PHP5 I was able to use mcrypt_module_open and now in PHP7.2.7 (which I just upgrade to) the function is missing and while searching, I discovered that it has been replaced by OpenSSL. My question is this: What is the equivalent of mcrypt_module_open in OPenSSL?

python - Heap that supports modification of its elements?

Here is my scenario. I want to implement A* (in Python) without having to resort to linear-time min or in operations. I need a heap to be able to efficiently get the lowest weight item. My immediate response was 'Easy! I'll use heapq!' Then I discovered that life is rarely as simple as we would like


java - Location mocking - google map detects the movement but my own application not triggering location change

I am facing a strange issue. I modified official mock provider source code provided by google to mock some route for my application.Using this code. mockLocation.setElapsedRealtimeNanos(elapsedTimeNanos); mockLocation.setTime(currentTime); // Set the loc

android - Can't find class [org/drinkless/td/libcore/telegram/TdApi$Object]

I am getting this error "Can't find class [org/drinkless/td/libcore/telegram/TdApi$Object]" but I haven't used this class anywhere in my project.I haven't used that class anywhere.But i am getting the above errorCan anyone please let me know how to solve the above error.

How do I cross-compile a Linux kernel to a MIPS little endian host?

The kernel in question is 2.6.18. If I callmake ARCH=mips CROSS_COMPILE=mipsel-linux- menuconfigthere will be only the option to build a big endian kernel in the menu. If I use ARCH=mipsel, it will complain about not having an arch/mipsel dir.How's this done?

php - Key for HMAC Algorithm

How to generate the secret key for the HMAC algorithm as I have to use it for data verification at the other clients end?Thanks in advance.