ssl_certificates.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. .. _doc_ssl_certificates:
  2. TLS/SSL certificates
  3. ====================
  4. Introduction
  5. ------------
  6. It is often desired to use :abbr:`TLS (Transport Layer Security)` connections (also
  7. known as :abbr:`SSL (Secure Sockets Layer)` 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 will try to use the TLS certificate bundle provided by the operating system,
  14. but also includes the
  15. `TLS certificate bundle from Mozilla <https://github.com/godotengine/godot/blob/master/thirdparty/certs/ca-certificates.crt>`__
  16. as a fallback.
  17. You can alternatively force your own certificate bundle in the Project Settings:
  18. .. figure:: img/tls_certificates_project_setting.webp
  19. :align: center
  20. :alt: Setting the TLS certificate bundle override project setting
  21. Setting the TLS certificate bundle override project setting
  22. When set, this file *overrides* the operating system provided bundle by default.
  23. This file should contain any number of public certificates in
  24. `PEM format <https://en.wikipedia.org/wiki/Privacy-enhanced_Electronic_Mail>`__.
  25. There are two ways to obtain certificates:
  26. Obtain a certificate from a certificate authority
  27. -------------------------------------------------
  28. The main approach to getting a certificate is to use a certificate authority
  29. (CA) such as `Let's Encrypt <https://letsencrypt.org/>`__. This is a more
  30. cumbersome process than a self-signed certificate, but it's more "official" and
  31. ensures your identity is clearly represented. The resulting certificate is also
  32. trusted by applications such as web browsers, unlike a self-signed certificate
  33. which requires additional configuration on the client side before it's
  34. considered trusted.
  35. These certificates do not require any configuration on the client to work, since
  36. Godot already bundles the Mozilla certificate bundle in the editor and exported
  37. projects.
  38. Generate a self-signed certificate
  39. ----------------------------------
  40. For most use cases, it's recommended to go through certificate authority as the
  41. process is free with certificate authorities such as Let's Encrypt. However, if
  42. using a certificate authority is not an option, then you can generate a
  43. self-signed certificate and tell the client to consider your self-signed
  44. certificate as trusted.
  45. To create a self-signed certificate, generate a private and public key pair and
  46. add the public key (in PEM format) to the CRT file specified in the Project
  47. Settings.
  48. .. warning::
  49. The private key should **only** go to your server. The client must not have
  50. access to it: otherwise, the security of the certificate will be
  51. compromised.
  52. .. warning::
  53. When specifying a self-signed certificate as TLS bundle in the project
  54. settings, normal domain name validation is enforced via the certificate
  55. :abbr:`CN (common name)` and alternative names. See
  56. :ref:`TLSOptions <class_TLSOptions>` to customize domain name validation.
  57. For development purposes Godot can generate self-signed certificates via
  58. :ref:`Crypto.generate_self_signed_certificate
  59. <class_Crypto_method_generate_self_signed_certificate>`.
  60. Alternatively, OpenSSL has some documentation about `generating keys
  61. <https://raw.githubusercontent.com/openssl/openssl/master/doc/HOWTO/keys.txt>`__
  62. and `certificates <https://raw.githubusercontent.com/openssl/openssl/master/doc/HOWTO/certificates.txt>`__.