ssl_certificates.rst 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. .. _doc_ssl_certificates:
  2. SSL/TLS certificates
  3. ====================
  4. Introduction
  5. ------------
  6. It is often desired to use :abbr:`SSL (Secure Sockets Layer)` connections (also
  7. known as :abbr:`TLS (Transport Layer Security)` connections) for communications
  8. to avoid "man in the middle" attacks. Godot has a connection wrapper,
  9. :ref:`StreamPeerTLS <class_StreamPeerTLS>`, which can take a regular connection
  10. and add security around it. The :ref:`HTTPClient <class_HTTPClient>` and
  11. :ref:`HTTPRequest <class_HTTPRequest>` classes also support HTTPS using
  12. this same wrapper.
  13. Godot includes the
  14. `SSL certificate bundle from Mozilla <https://github.com/godotengine/godot/blob/master/thirdparty/certs/ca-certificates.crt>`__,
  15. but you can provide your own with a CRT file in the Project Settings:
  16. .. figure:: img/tls_certificates_project_setting.webp
  17. :align: center
  18. :alt: Setting the TLS certificate bundle override project setting
  19. Setting the TLS certificate bundle override project setting
  20. When set, this file *overrides* the Mozilla certificate bundle Godot uses
  21. by default. This file should contain any number of public certificates in
  22. `PEM format <https://en.wikipedia.org/wiki/Privacy-enhanced_Electronic_Mail>`__.
  23. Remember to add ``*.crt`` as the non-resource export filter to your export
  24. preset, so that the exporter recognizes this when exporting your project:
  25. .. figure:: img/tls_certificates_export_filter.webp
  26. :align: center
  27. :alt: Adding ``*.crt`` to non-resource export filter in the export preset
  28. Adding ``*.crt`` to non-resource export filter in the export preset
  29. There are two ways to obtain certificates:
  30. Acquire a certificate from a certificate authority
  31. --------------------------------------------------
  32. The main approach to getting a certificate is to use a certificate authority
  33. (CA) such as `Let's Encrypt <https://letsencrypt.org/>`__. This is a more
  34. cumbersome process than a self-signed certificate, but it's more "official" and
  35. ensures your identity is clearly represented. The resulting certificate is also
  36. trusted by applications such as web browsers, unlike a self-signed certificate
  37. which requires additional configuration on the client side before it's
  38. considered trusted.
  39. These certificates do not require any configuration on the client to work, since
  40. Godot already bundles the Mozilla certificate bundle in the editor and exported
  41. projects.
  42. Generate a self-signed certificate
  43. ----------------------------------
  44. For most use cases, it's recommended to go through certificate authority as the
  45. process is free with certificate authorities such as Let's Encrypt. However, if
  46. using a certificate authority is not an option, then you can generate a
  47. self-signed certificate and tell the client to consider your self-signed
  48. certificate as trusted.
  49. To create a self-signed certificate, generate a private and public key pair and
  50. add the public key (in PEM format) to the CRT file specified in the Project
  51. Settings.
  52. .. warning::
  53. The private key should **only** go to your server. The client must not have
  54. access to it: otherwise, the security of the certificate will be
  55. compromised.
  56. OpenSSL has `some documentation
  57. <https://raw.githubusercontent.com/openssl/openssl/master/doc/HOWTO/keys.txt>`__
  58. about this. For local development purposes **only**, `mkcert
  59. <https://github.com/FiloSottile/mkcert>`__ can be used as an alternative.