Packages
nerves_hub_link
0.10.0
2.12.0
2.11.1
2.11.0
retired
2.10.2
2.10.1
2.10.0
2.9.0
2.9.0-rc.3
2.9.0-rc.2
2.9.0-rc.1
2.8.1
2.8.0
2.7.3
2.7.2
2.7.0
retired
2.6.0
2.5.2
2.5.1
2.5.0
2.4.0
2.3.0
2.2.1
2.2.0
2.1.1
2.1.0
2.0.0
1.4.1
1.4.0
1.3.0
1.2.0
1.1.0
1.0.1
1.0.0
0.13.1
0.13.0
0.12.1
0.12.0
0.11.0
0.10.2
0.10.1
retired
0.10.0
retired
0.10.0-rc.0
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.6
Manage your Nerves fleet by connecting it to NervesHub
Retired package: Release invalid - A bug was discovered that fails to reboot after update
Current section
Files
Jump to
Current section
Files
lib/nerves_hub_link/certificate.ex
defmodule NervesHubLink.Certificate do
# Look for org here or from CLI config
org = Application.get_env(:nerves_hub_link, :org, Application.get_env(:nerve_hub_cli, :org))
@public_keys Application.get_env(:nerves_hub_link, :fwup_public_keys, [])
|> NervesHubCLI.resolve_fwup_public_keys(org)
ca_cert_path =
System.get_env("NERVES_HUB_CA_CERTS") || Application.get_env(:nerves_hub_link, :ca_certs) ||
Path.join([File.cwd!(), "ssl", "prod"])
ca_certs =
ca_cert_path
|> File.ls!()
|> Enum.map(&File.read!(Path.join(ca_cert_path, &1)))
|> Enum.map(&X509.Certificate.to_der(X509.Certificate.from_pem!(&1)))
if ca_certs == [], do: raise("Couldn't find NervesHub CA certificates in '#{ca_cert_path}'")
@ca_certs ca_certs
def key_pem_to_der(nil), do: <<>>
def key_pem_to_der(pem) do
case X509.PrivateKey.from_pem(pem) do
{:error, :not_found} -> <<>>
{:ok, decoded} -> X509.PrivateKey.to_der(decoded)
end
end
def pem_to_der(nil), do: <<>>
def pem_to_der(cert) do
case X509.Certificate.from_pem(cert) do
{:error, :not_found} -> <<>>
{:ok, decoded} -> X509.Certificate.to_der(decoded)
end
end
def ca_certs do
@ca_certs
end
@deprecated "Use fwup_public_keys/0 instead"
def public_keys do
fwup_public_keys()
end
def fwup_public_keys do
@public_keys
end
end