Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OTP 27 #73

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ jobs:
- pair:
elixir: '1.14.3'
otp: '25.3'
lint: lint
- pair:
elixir: '1.15.1'
otp: '26.0.2'
- pair:
elixir: '1.17.1'
otp: '27.0'
lint: lint
steps:
- uses: actions/checkout@v2

Expand Down
4 changes: 2 additions & 2 deletions lib/x509/date_time.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule X509.DateTime do
def utc_time(%DateTime{} = datetime) do
iso = DateTime.to_iso8601(datetime, :basic)
[_, date, time] = Regex.run(~r/^\d\d(\d{6})T(\d{6})(?:\.\d+)?Z$/, iso)
'#{date}#{time}Z'
~c"#{date}#{time}Z"
end

# Builds ASN.1 GeneralTime as charlist
Expand All @@ -40,7 +40,7 @@ defmodule X509.DateTime do
def general_time(%DateTime{} = datetime) do
iso = DateTime.to_iso8601(datetime, :basic)
[_, date, time] = Regex.run(~r/^(\d{8})T(\d{6})(?:\.\d+)?Z$/, iso)
'#{date}#{time}Z'
~c"#{date}#{time}Z"
end

def to_datetime({:utcTime, time}) do
Expand Down
4 changes: 2 additions & 2 deletions lib/x509/private_key.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ defmodule X509.PrivateKey do
def from_pem(pem, opts \\ []) do
password =
opts
|> Keyword.get(:password, '')
|> Keyword.get(:password, ~c"")
|> to_charlist()

pem
Expand Down Expand Up @@ -307,6 +307,6 @@ defmodule X509.PrivateKey do
end

defp cipher_info() do
{'DES-EDE3-CBC', :crypto.strong_rand_bytes(8)}
{~c"DES-EDE3-CBC", :crypto.strong_rand_bytes(8)}
end
end
2 changes: 1 addition & 1 deletion lib/x509/rdn_sequence.ex
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ defmodule X509.RDNSequence do
?A..?Z |> Enum.into([]),
?a..?z |> Enum.into([]),
?0..?9 |> Enum.into([]),
' \'()+,-./:=?'
~c" '()+,-./:=?"
]
|> List.flatten()

Expand Down
10 changes: 10 additions & 0 deletions lib/x509/test/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,19 @@ defmodule X509.Test.Server do
end

defp worker(socket, suite, response) do
# Default certificates and keys, which are overriden by sni_fun according
# to the specific test case. OTP 27 requires that valid certificates and
# keys are passed to the listener socket.
default_cert = X509.Certificate.to_der(suite.valid)
default_key = {:PrivateKeyInfo, X509.PrivateKey.to_der(suite.server_key, wrap: true)}
default_cacerts = suite.chain

opts =
[
active: false,
cert: default_cert,
key: default_key,
cacerts: default_cacerts,
sni_fun: X509.Test.Suite.sni_fun(suite),
reuse_sessions: false
] ++ log_opts()
Expand Down
1 change: 1 addition & 0 deletions lib/x509/test/suite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ defmodule X509.Test.Suite do
) do
[
cert: X509.Certificate.to_der(valid),
cacerts: [],
key: {:PrivateKeyInfo, X509.PrivateKey.to_der(server_key, wrap: true)}
]
end
Expand Down
8 changes: 4 additions & 4 deletions test/x509/certificate/extension_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ defmodule X509.Certificate.ExtensionTest do
assert certs.server
|> X509.Certificate.extension(:subject_alt_name)
|> extension(:extnValue) ==
[dNSName: '*.tools.ietf.org', dNSName: 'tools.ietf.org']
[dNSName: ~c"*.tools.ietf.org", dNSName: ~c"tools.ietf.org"]
end

test "crl_distribution_points", %{certs: certs} do
Expand All @@ -73,7 +73,7 @@ defmodule X509.Certificate.ExtensionTest do
{:DistributionPoint,
{:fullName,
[
uniformResourceIdentifier: 'http://crl.starfieldtech.com/sfig2s1-128.crl'
uniformResourceIdentifier: ~c"http://crl.starfieldtech.com/sfig2s1-128.crl"
]}, :asn1_NOVALUE, :asn1_NOVALUE}
]
end
Expand All @@ -83,10 +83,10 @@ defmodule X509.Certificate.ExtensionTest do
|> X509.Certificate.extension(:authority_info_access)
|> extension(:extnValue) == [
{:AccessDescription, {1, 3, 6, 1, 5, 5, 7, 48, 1},
{:uniformResourceIdentifier, 'http://ocsp.starfieldtech.com/'}},
{:uniformResourceIdentifier, ~c"http://ocsp.starfieldtech.com/"}},
{:AccessDescription, {1, 3, 6, 1, 5, 5, 7, 48, 2},
{:uniformResourceIdentifier,
'http://certificates.starfieldtech.com/repository/sfig2.crt'}}
~c"http://certificates.starfieldtech.com/repository/sfig2.crt"}}
]
end

Expand Down
2 changes: 1 addition & 1 deletion test/x509/certificate/validity_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule X509.Certificate.ValidityTest do
validity = X509.Certificate.Validity.new(not_before, not_after)
assert <<der::binary>> = :public_key.der_encode(:Validity, validity)

assert {:Validity, {:utcTime, '220101000000Z'}, {:generalTime, '20511231235959Z'}} =
assert {:Validity, {:utcTime, ~c"220101000000Z"}, {:generalTime, ~c"20511231235959Z"}} =
:public_key.der_decode(:Validity, der)
end
end
2 changes: 1 addition & 1 deletion test/x509/certificate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ defmodule X509.CertificateTest do
|> X509.Certificate.extension(:key_usage)
|> extension(:extnValue)

assert [rfc822Name: 'end.entity@example.com'] =
assert [rfc822Name: ~c"end.entity@example.com"] =
cert2
|> X509.Certificate.extension(:subject_alt_name)
|> extension(:extnValue)
Expand Down
2 changes: 0 additions & 2 deletions test/x509/private_key_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ defmodule X509.PrivateKeyTest do
test "new" do
assert match?(ec_private_key(), new_ec(:secp256r1))
assert match?(ec_private_key(), new_ec(oid(:secp256r1)))

assert_raise(FunctionClauseError, fn -> new_ec(:no_such_curve) end)
end

test "wrap and unwrap", context do
Expand Down
Loading
Loading