extract the user principal from client certificate in vertx

752 Views Asked by At

I am using Vertx framework for my API and have enabled https on it successfully.

For user authentication/authorization, I wan't to use client certificates i.e. who can access which APIs. The flow will:

  1. When a client makes a API hit, it presents its certificate to Vertx server. This certificate should contain username as CN.
  2. Vertx server should validate the client certificate and extract the Common name from it and then do the authorization based on this username.

How do I read the client certificate to extract cn i.e. user principal ?

1

There are 1 best solutions below

1
tsegismont On

When you have an io.vertx.core.http.HttpConnection you can write:

connection.sslSession().getPeerPrincipal().getName()