Skip to content

Commit

Permalink
Add selfsigned certificate by default in prod config
Browse files Browse the repository at this point in the history
This permit to enable the https port on node startup
  • Loading branch information
Neylix committed Oct 15, 2022
1 parent 2010acf commit cc14359
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,6 @@ config :archethic, ArchethicWeb.Endpoint,
otp_app: :archethic,
port: System.get_env("ARCHETHIC_HTTPS_PORT", "50000") |> String.to_integer(),
sni_fun: &ArchethicWeb.Domain.sni/1,
keyfile: System.get_env("ARCHETHIC_WEB_SSL_KEYFILE", ""),
certfile: System.get_env("ARCHETHIC_WEB_SSL_CERTFILE", "")
keyfile: System.get_env("ARCHETHIC_WEB_SSL_KEYFILE", "priv/cert/selfsigned_key.pem"),
certfile: System.get_env("ARCHETHIC_WEB_SSL_CERTFILE", "priv/cert/selfsigned.pem")
]
16 changes: 14 additions & 2 deletions lib/archethic_web/domain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,20 @@ defmodule ArchethicWeb.Domain do
keyfile = Keyword.fetch!(https_conf, :keyfile)
certfile = Keyword.fetch!(https_conf, :certfile)

key = File.read!(keyfile) |> read_pem() |> hd()
cert = File.read!(certfile) |> read_pem() |> hd() |> elem(1)
key_content =
case File.read(keyfile) do
{:ok, content} -> content
{:error, _} -> File.read!(Application.app_dir(:archethic, keyfile))
end

cert_content =
case File.read(certfile) do
{:ok, content} -> content
{:error, _} -> File.read!(Application.app_dir(:archethic, certfile))
end

key = key_content |> read_pem() |> hd()
cert = cert_content |> read_pem() |> hd() |> elem(1)

[key: key, cert: cert]
end
Expand Down

0 comments on commit cc14359

Please sign in to comment.