~sgiath/spaceboy

afe1361c1322ec0734a0cb7ab6bb259136038fb0 — Sgiath 2 months ago bc23ea8
Update project dependencies

Signed-off-by: Sgiath <sgiath@pm.me>
M example/Dockerfile => example/Dockerfile +1 -1
@@ 1,4 1,4 @@
FROM hexpm/elixir:1.11.4-erlang-23.3.1-alpine-3.13.3 AS build
FROM hexpm/elixir:1.12.0-erlang-24.0-alpine-3.13.3 AS build

# install build dependencies
RUN --mount=type=cache,sharing=locked,target=/var/cache/apk \

M example/lib/example/controller.ex => example/lib/example/controller.ex +0 -3
@@ 74,9 74,6 @@ defmodule Example.Controller do
    ```
    #{inspect(data)}
    ```

    ## Fingerprint
    #{PeerCert.fingerprint(pc)}
    """)
  end


M example/mix.exs => example/mix.exs +2 -2
@@ 8,7 8,7 @@ defmodule Example.MixProject do
      version: "0.1.0",

      # Elixir config
      elixir: "~> 1.11",
      elixir: "~> 1.12",
      start_permanent: Mix.env() == :prod,
      deps: deps(),



@@ 36,7 36,7 @@ defmodule Example.MixProject do
    [
      {:spaceboy, path: "../"},
      {:jason, "~> 1.2"},
      {:telemetry, "~> 0.4"}
      {:telemetry, "~> 1.0"}
    ]
  end
end

M example/mix.lock => example/mix.lock +1 -1
@@ 2,6 2,6 @@
  "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
  "mime": {:hex, :mime, "1.6.0", "dabde576a497cef4bbdd60aceee8160e02a6c89250d6c0b29e56c0dfb00db3d2", [:mix], [], "hexpm", "31a1a8613f8321143dde1dafc36006a17d28d02bdfecb9e95a880fa7aabd19a7"},
  "ranch": {:hex, :ranch, "2.0.0", "fbf3d79661c071543256f9051caf19d65daa6df1cf6824d8f37a49b19a66f703", [:rebar3], [], "hexpm", "c20a4840c7d6623c19812d3a7c828b2f1bd153ef0f124cb69c54fe51d8a42ae0"},
  "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},
  "telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"},
  "typed_struct": {:hex, :typed_struct, "0.2.1", "e1993414c371f09ff25231393b6430bd89d780e2a499ae3b2d2b00852f593d97", [:mix], [], "hexpm", "8f5218c35ec38262f627b2c522542f1eae41f625f92649c0af701a6fab2e11b3"},
}

M lib/mix/tasks/spaceboy/gen.cert.ex => lib/mix/tasks/spaceboy/gen.cert.ex +6 -8
@@ 5,12 5,10 @@ defmodule Mix.Tasks.Spaceboy.Gen.Cert do
  Generates self-signed certificate for localhost and saves it at `priv/ssl/`

  By default uses EC `prime256v1` as it is the most widely supported EC algorithm.
  But once Erlang adds support for `ED25519` curve I will switch it to this one
  But once support for `ED25519` curve will grow I will switch it to this one
  for security reasons and to promote good practices. If you want to use ED25519
  even now you can use `--ed25519` option in this task.

  https://github.com/erlang/otp/issues/4637

  When first used it copies default `openssl.cnf` to your `priv/ssl/` directory
  and generates self-sgined certificate for `localhost` and `127.0.0.1`. If you
  want certificate for different hosts and IPs you can edit the generated


@@ 24,8 22,7 @@ defmodule Mix.Tasks.Spaceboy.Gen.Cert do

      mix spaceboy.gen.cert --days 36500

  You can specify to generate private key with ED25519 algorithm (currently not
  supported by Erlang):
  You can specify to generate private key with ED25519 algorithm:

      mix spaceboy.gen.cert --ed25519



@@ 44,7 41,7 @@ defmodule Mix.Tasks.Spaceboy.Gen.Cert do
  @cnf_default Application.app_dir(:spaceboy, "priv/openssl.cnf")

  @secp [
    "-algorithm=EC",
    "-algorithm=ec",
    "-pkeyopt=ec_paramgen_curve:prime256v1"
  ]
  @ed25519 [


@@ 74,7 71,8 @@ defmodule Mix.Tasks.Spaceboy.Gen.Cert do
      IO.puts("""
      \n#{IO.ANSI.yellow()}#{IO.ANSI.bright()}# OpenSSL Config#{IO.ANSI.reset()}
      Created default openssl config file at #{path(@cnf_path)}
      It won't be overwriten so you can edit it will be used on subsequent cert generations.
      It won't be overwriten so you can edit it and it will be used on subsequent cert
      generations.
      """)
    end
  end


@@ 122,7 120,7 @@ defmodule Mix.Tasks.Spaceboy.Gen.Cert do
    Generated self-signed certificate at #{path(@cert_path)}
    You can inspect your certificate with this command:

        #{IO.ANSI.bright()}openssl x509 -in priv/ssl/cert.pem -text -noout#{IO.ANSI.reset()}
        #{IO.ANSI.bright()}openssl x509 -in #{@cert_path} -text -noout#{IO.ANSI.reset()}
    """)
  end


M lib/spaceboy/certificate.ex => lib/spaceboy/certificate.ex +5 -32
@@ 13,23 13,6 @@ defmodule Spaceboy.PeerCert do
        }

  @doc ~S"""
  Get the fingerprint for the Public Key of the certificate
  """
  @spec fingerprint(cert :: peer_cert) :: binary()
  def fingerprint(cert) when is_binary(cert) do
    pk =
      cert
      |> otp_cert()
      |> tbs_cert()
      |> subject_public_key_info()
      |> public_key()

    :public_key.ssh_hostkey_fingerprint(:sha256, pk)
  end

  def fingerprint(error), do: error

  @doc ~S"""
  Extract RDN Sequences from certificate
  """
  @spec rdn(peer_cert :: peer_cert) :: rdn | :no_peercert


@@ 58,26 41,13 @@ defmodule Spaceboy.PeerCert do
  defp subject(data) when Record.is_record(data, :OTPTBSCertificate),
    do: elem(data, 6)

  defp subject_public_key_info(data) when Record.is_record(data, :OTPTBSCertificate),
    do: elem(data, 7)

  defp ec_point(data) when Record.is_record(data, :OTPSubjectPublicKeyInfo), do: elem(data, 2)

  defp key_algo(data) when Record.is_record(data, :OTPSubjectPublicKeyInfo), do: elem(data, 1)

  defp named_curve(data) when Record.is_record(data, :PublicKeyAlgorithm), do: elem(data, 2)

  defp public_key(data) when Record.is_record(data, :OTPSubjectPublicKeyInfo) do
    {ec_point(data), data |> key_algo() |> named_curve()}
  end

  defp decode_rdn_sequence({:rdnSequence, [data]}) do
  defp decode_rdn_sequence({:rdnSequence, data}) when is_list(data) do
    attribute_type_and_value(data)
  end

  defp attribute_type_and_value(rdn_sequence, acc \\ %{})

  defp attribute_type_and_value([attr | attributes], acc)
  defp attribute_type_and_value([[attr] | attributes], acc)
       when Record.is_record(attr, :AttributeTypeAndValue) do
    type = attr |> elem(1) |> oid_alias()
    value = attr |> elem(2) |> munge_utf8()


@@ 89,8 59,11 @@ defmodule Spaceboy.PeerCert do

  defp oid_alias({2, 5, 4, 3}), do: :common_name
  defp oid_alias({2, 5, 4, 6}), do: :country
  defp oid_alias({2, 5, 4, 7}), do: :city
  defp oid_alias({2, 5, 4, 8}), do: :location
  defp oid_alias({2, 5, 4, 10}), do: :organization
  defp oid_alias({2, 5, 4, 11}), do: :organization_unit
  defp oid_alias({1, 2, 840, 113_549, 1, 9, 1}), do: :email
  defp oid_alias(_oid_name), do: :unknown

  defp munge_utf8({:utf8String, data}), do: data

M lib/spaceboy/middleware/telemetry.ex => lib/spaceboy/middleware/telemetry.ex +1 -1
@@ 6,7 6,7 @@ if Code.ensure_loaded?(:telemetry) do
    This middleware is only defined if you manually install optional dependency
    `:telemetry`.

          {:telemetry, "~> 0.4"},
          {:telemetry, "~> 1.0"},

    When plugged, the event prefix is a required option:


M mix.exs => mix.exs +3 -3
@@ 7,7 7,7 @@ defmodule Spaceboy.MixProject do
    [
      app: :spaceboy,
      version: @version,
      elixir: "~> 1.11",
      elixir: "~> 1.12",
      consolidate_protocols: Mix.env() != :test,
      deps: deps(),
      package: package(),


@@ 26,7 26,7 @@ defmodule Spaceboy.MixProject do

  def application do
    [
      extra_applications: [:logger, :eex, :public_key]
      extra_applications: [:logger, :eex, :public_key, :ssh]
    ]
  end



@@ 39,7 39,7 @@ defmodule Spaceboy.MixProject do

      # Optional
      {:jason, "~> 1.2", optional: true},
      {:telemetry, "~> 0.4", optional: true},
      {:telemetry, "~> 1.0", optional: true},

      # Dev deps
      {:credo, "~> 1.5", only: :dev, runtime: false},

M mix.lock => mix.lock +2 -2
@@ 1,6 1,6 @@
%{
  "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
  "credo": {:hex, :credo, "1.5.5", "e8f422026f553bc3bebb81c8e8bf1932f498ca03339856c7fec63d3faac8424b", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "dd8623ab7091956a855dc9f3062486add9c52d310dfd62748779c4315d8247de"},
  "credo": {:hex, :credo, "1.5.6", "e04cc0fdc236fefbb578e0c04bd01a471081616e741d386909e527ac146016c6", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4b52a3e558bd64e30de62a648518a5ea2b6e3e5d2b164ef5296244753fc7eb17"},
  "earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"},
  "ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"},
  "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},


@@ 11,6 11,6 @@
  "mime": {:hex, :mime, "1.6.0", "dabde576a497cef4bbdd60aceee8160e02a6c89250d6c0b29e56c0dfb00db3d2", [:mix], [], "hexpm", "31a1a8613f8321143dde1dafc36006a17d28d02bdfecb9e95a880fa7aabd19a7"},
  "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
  "ranch": {:hex, :ranch, "2.0.0", "fbf3d79661c071543256f9051caf19d65daa6df1cf6824d8f37a49b19a66f703", [:rebar3], [], "hexpm", "c20a4840c7d6623c19812d3a7c828b2f1bd153ef0f124cb69c54fe51d8a42ae0"},
  "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"},
  "telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"},
  "typed_struct": {:hex, :typed_struct, "0.2.1", "e1993414c371f09ff25231393b6430bd89d780e2a499ae3b2d2b00852f593d97", [:mix], [], "hexpm", "8f5218c35ec38262f627b2c522542f1eae41f625f92649c0af701a6fab2e11b3"},
}