makecert 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. #
  3. # Creates a trust collection certificate (ca.crt)
  4. # and self-signed server certificate (server.crt) and private key (server.pem)
  5. # and client certificate (client.crt) and key file (client.pem) for mutual TLS.
  6. # Replace "example.com" with the host name you'd like for your certificate.
  7. #
  8. # https://github.com/grpc/grpc-java/tree/master/examples
  9. #
  10. SIZE=2048
  11. CN_CA=foo
  12. CN_SERVER=example.com
  13. CN_CLIENT=localhost
  14. # CA
  15. openssl genrsa -out ca.key $SIZE
  16. openssl req -new -x509 -days 365 -key ca.key -out ca.crt -subj "/CN=${CN_CA}"
  17. # Server
  18. openssl genrsa -out server.key $SIZE
  19. openssl req -new -key server.key -out server.csr -subj "/CN=${CN_SERVER}"
  20. openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt
  21. # Client
  22. openssl genrsa -out client.key $SIZE
  23. openssl req -new -key client.key -out client.csr -subj "/CN=${CN_CLIENT}"
  24. openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt
  25. # netty only supports PKCS8 keys. openssl is used to convert from PKCS1 to PKCS8
  26. # http://netty.io/wiki/sslcontextbuilder-and-private-key.html
  27. openssl pkcs8 -topk8 -nocrypt -in client.key -out client.pem
  28. openssl pkcs8 -topk8 -nocrypt -in server.key -out server.pem
  29. # Server cert with explicit EC parameters (not supported)
  30. openssl ecparam -name prime256v1 -genkey -param_enc explicit -out server-explicit.key
  31. openssl req -new -x509 -days 365 -key server-explicit.key -out server-explicit.crt -subj "/CN=${CN_SERVER}"