From c79afa5f0bee8014d455ecdaa77b75caa3d2a5cb Mon Sep 17 00:00:00 2001 From: Alexander Petrovsky Date: Fri, 7 Jan 2022 17:56:50 +0300 Subject: [PATCH] Introduce ranch_transport:peercert/1 callback --- src/ranch_ssl.erl | 6 ++++++ src/ranch_tcp.erl | 5 +++++ src/ranch_transport.erl | 1 + test/ranch_erlang_transport.erl | 6 ++++++ 4 files changed, 18 insertions(+) diff --git a/src/ranch_ssl.erl b/src/ranch_ssl.erl index ff5831e8fd..2090fa108b 100644 --- a/src/ranch_ssl.erl +++ b/src/ranch_ssl.erl @@ -43,6 +43,7 @@ -export([controlling_process/2]). -export([peername/1]). -export([sockname/1]). +-export([peercert/1]). -export([shutdown/2]). -export([close/1]). -export([cleanup/1]). @@ -296,6 +297,11 @@ peername(Socket) -> sockname(Socket) -> ssl:sockname(Socket). +-spec peercert(ssl:sslsocket()) + -> {ok, public_key:der_encoded()} | {error, any()}. +peercert(Socket) -> + ssl:peercert(Socket). + -spec shutdown(ssl:sslsocket(), read | write | read_write) -> ok | {error, atom()}. shutdown(Socket, How) -> diff --git a/src/ranch_tcp.erl b/src/ranch_tcp.erl index 354128905b..6319a00d68 100644 --- a/src/ranch_tcp.erl +++ b/src/ranch_tcp.erl @@ -42,6 +42,7 @@ -export([controlling_process/2]). -export([peername/1]). -export([sockname/1]). +-export([peercert/1]). -export([shutdown/2]). -export([close/1]). -export([cleanup/1]). @@ -265,6 +266,10 @@ peername(Socket) -> sockname(Socket) -> inet:sockname(Socket). +-spec peercert(inet:socket()) -> no_return(). +peercert(_Socket) -> + error(not_supported). + -spec shutdown(inet:socket(), read | write | read_write) -> ok | {error, atom()}. shutdown(Socket, How) -> diff --git a/src/ranch_transport.erl b/src/ranch_transport.erl index 52eeba3fd6..c6b5ec66f3 100644 --- a/src/ranch_transport.erl +++ b/src/ranch_transport.erl @@ -64,6 +64,7 @@ -> {ok, {inet:ip_address(), inet:port_number()} | {local, binary()}} | {error, atom()}. -callback sockname(socket()) -> {ok, {inet:ip_address(), inet:port_number()} | {local, binary()}} | {error, atom()}. +-callback peercert(socket()) -> {ok, public_key:der_encoded()} | {error, any()}. -callback shutdown(socket(), read | write | read_write) -> ok | {error, atom()}. -callback close(socket()) -> ok. diff --git a/test/ranch_erlang_transport.erl b/test/ranch_erlang_transport.erl index 4bb999c39d..da5340facf 100644 --- a/test/ranch_erlang_transport.erl +++ b/test/ranch_erlang_transport.erl @@ -40,6 +40,7 @@ -export([controlling_process/2]). -export([peername/1]). -export([sockname/1]). +-export([peercert/1]). -export([shutdown/2]). -export([close/1]). -export([cleanup/1]). @@ -160,6 +161,11 @@ peername(_Socket) -> sockname(_Socket) -> {ok, {{127, 0, 0, 1}, 12710}}. +-spec peercert(reference()) + -> no_return(). +peercert(_Socket) -> + error(not_supported). + -spec shutdown(reference(), read | write | read_write) -> ok | {error, atom()}. shutdown(_Socket, _How) ->