Skip to content
Open
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
14 changes: 9 additions & 5 deletions lib/socket/ssl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ defmodule Socket.SSL do
"""
@spec ciphers :: [:ssl.erl_cipher_suite]
def ciphers do
:ssl.cipher_suites
# NOTE: Figure out if these defaults are sufficient or this needs to be parametrized
:ssl.cipher_suites(:all, :"tlsv1.3")
end

@doc """
Expand All @@ -70,7 +71,7 @@ defmodule Socket.SSL do
@spec error(term) :: String.t
def error(code) do
case :ssl.format_error(code) do
'Unexpected error:' ++ _ ->
~c"Unexpected error:" ++ _ ->
nil

message ->
Expand Down Expand Up @@ -249,7 +250,7 @@ defmodule Socket.SSL do
timeout = options[:timeout] || :infinity
options = Keyword.delete(options, :timeout)

:ssl.ssl_accept(wrap, arguments(options), timeout)
:ssl.handshake(wrap, arguments(options), timeout)
end

@doc """
Expand All @@ -269,7 +270,7 @@ defmodule Socket.SSL do
def handshake(socket, options \\ []) when socket |> Record.is_record(:sslsocket) do
timeout = options[:timeout] || :infinity

:ssl.ssl_accept(socket, timeout)
:ssl.handshake(socket, timeout)
end

@doc """
Expand Down Expand Up @@ -360,7 +361,10 @@ defmodule Socket.SSL do
[{ :server_name_indication, :disable }]

{ :server_name, name } ->
[{ :server_name_indication, String.to_charlist(name) }]
[
{ :server_name_indication, String.to_charlist(name) },
{ :customize_hostname_check, [{:match_fun, :public_key.pkix_verify_hostname_match_fun(:https)}] }
]

{ :cert, [path: path] } ->
[{ :certfile, path }]
Expand Down
6 changes: 5 additions & 1 deletion lib/socket/tcp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Socket.TCP do
@spec error(term) :: String.t
def error(code) do
case :inet.format_error(code) do
'unknown POSIX error' ->
~c"unknown POSIX error" ->
nil

message ->
Expand Down Expand Up @@ -199,6 +199,10 @@ defmodule Socket.TCP do

{ :error, reason } ->
{ :error, reason }

# NOTE: This is a moot clause just to fixup typing violation warning
_ ->
:ok
end
end

Expand Down
15 changes: 6 additions & 9 deletions lib/socket/web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Socket.Web do

"""

use Bitwise
import Bitwise
import Kernel, except: [length: 1, send: 2]
alias __MODULE__, as: W

Expand Down Expand Up @@ -166,9 +166,6 @@ defmodule Socket.Web do

e in [Socket.Error] ->
{ :error, e.message }

e in [Socket.TCP.Error, Socket.SSL.Error] ->
{ :error, e.code }
end
end

Expand Down Expand Up @@ -396,7 +393,7 @@ defmodule Socket.Web do
{ :error, e.message }

e in [Socket.Error] ->
{ :error, e.code }
{ :error, e.message }
end
end

Expand Down Expand Up @@ -550,25 +547,25 @@ defmodule Socket.Web do
# more data, this means we can optimize and do it 4 bytes at a time and then
# fallback to the smaller sizes
defp unmask(key, << data :: 32, rest :: binary >>, acc) do
unmask(key, rest, << acc :: binary, data ^^^ key :: 32 >>)
unmask(key, rest, << acc :: binary, bxor(data, key) :: 32 >>)
end

defp unmask(key, << data :: 24 >>, acc) do
<< key :: 24, _ :: 8 >> = << key :: 32 >>

unmask(key, <<>>, << acc :: binary, data ^^^ key :: 24 >>)
unmask(key, <<>>, << acc :: binary, bxor(data, key) :: 24 >>)
end

defp unmask(key, << data :: 16 >>, acc) do
<< key :: 16, _ :: 16 >> = << key :: 32 >>

unmask(key, <<>>, << acc :: binary, data ^^^ key :: 16 >>)
unmask(key, <<>>, << acc :: binary, bxor(data, key) :: 16 >>)
end

defp unmask(key, << data :: 8 >>, acc) do
<< key :: 8, _ :: 24 >> = << key :: 32 >>

unmask(key, <<>>, << acc :: binary, data ^^^ key :: 8 >>)
unmask(key, <<>>, << acc :: binary, bxor(data, key) :: 8 >>)
end

defp unmask(_, <<>>, acc) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Socket.Mixfile do

# Configuration for the OTP application
def application do
[ applications: [:crypto, :ssl] ]
[ extra_applications: [:crypto, :ssl] ]
end

defp deps do
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%{
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.18.2", "993e0a95e9fbb790ac54ea58e700b45b299bd48bc44b4ae0404f28161f37a83e", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm", "1b34655872366414f69dd987cb121c049f76984b6ac69f52fff6d8fd64d29cfd"},
"ex_doc": {:hex, :ex_doc, "0.18.2", "993e0a95e9fbb790ac54ea58e700b45b299bd48bc44b4ae0404f28161f37a83e", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm", "eacdfd22d5c7e5f3fda086214c69a8b6ca4298ad90d99f399d591f14eead6a61"},
}