Authentication

After enabling TLS, clients can verify connecting servers and keep messages encrypted, but servers can not verify clients, so authentication is designed to provide a mechanism that servers can authenticate trusted clients.

Authentication provides another feature that gives a client a role name, then hstream will be based on the role to implement authorization.

hstream only support TLS authentication, which is an extension of default TLS, to enable TLS authentication, you need to create the corresponding key and certificate for a role, then give them to trusted clients, clients use the key and certificate(binding to a role) to connect to servers.

Create a trusted role

Generate a key:

  1. openssl genrsa -out role01.key.pem 2048

Convert it to PKCS 8 format(Java client require that):

  1. openssl pkcs8 -topk8 -inform PEM -outform PEM \
  2. -in role01.key.pem -out role01.key-pk8.pem -nocrypt

Generate the certificate request(Common Name is the role name):

  1. openssl req -config openssl.cnf \
  2. -key role01.key.pem -new -sha256 -out role01.csr.pem

Generate the signed certificate:

  1. openssl ca -config openssl.cnf -extensions usr_cert \
  2. -days 1000 -notext -md sha256 \
  3. -in role01.csr.pem -out signed.role01.cert.pem

Configuration

For hstream server, you can set tls-ca-path to enable TLS authentication, e.g.:

  1. # TLS options
  2. #
  3. # enable tls, which requires tls-key-path and tls-cert-path options
  4. enable-tls: true
  5. #
  6. # key file path for tls, can be generated by openssl
  7. tls-key-path: /path/to/the/server.key.pem
  8. #
  9. # the signed certificate by CA for the key(tls-key-path)
  10. tls-cert-path: /path/to/the/signed.server.cert.pem
  11. #
  12. # optional for tls, if tls-ca-path is not empty, then enable TLS authentication,
  13. # in the handshake phase,
  14. # the server will request and verify the client's certificate.
  15. tls-ca-path: /path/to/the/ca.cert.pem

For Java client:

  1. HStreamClient.builder()
  2. .serviceUrl(serviceUrl)
  3. // enable tls
  4. .enableTLS()
  5. .tlsCaPath("/path/to/ca.pem")
  6. // for authentication
  7. .enableTlsAuthentication()
  8. .tlsKeyPath("path/to/role01.key-pk8.pem")
  9. .tlsCertPath("path/to/signed.role01.cert.pem")
  10. .build()