Add support for TLS SNI
Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
This commit is contained in:
parent
82f44f2db1
commit
e1c98ceaf7
|
@ -149,6 +149,7 @@ private:
|
|||
private:
|
||||
sockaddr_storage fAddress;
|
||||
status_t fStatus;
|
||||
BString fHostName;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@ public:
|
|||
virtual ssize_t Write(const void* buffer, size_t size);
|
||||
|
||||
protected:
|
||||
status_t _SetupCommon();
|
||||
status_t _SetupConnect();
|
||||
status_t _SetupCommon(const char* host = NULL);
|
||||
status_t _SetupConnect(const char* host = NULL);
|
||||
status_t _SetupAccept();
|
||||
|
||||
private:
|
||||
|
|
|
@ -129,7 +129,8 @@ BNetworkAddress::BNetworkAddress(const in6_addr& address, uint16 port)
|
|||
BNetworkAddress::BNetworkAddress(const BNetworkAddress& other)
|
||||
:
|
||||
fAddress(other.fAddress),
|
||||
fStatus(other.fStatus)
|
||||
fStatus(other.fStatus),
|
||||
fHostName(other.fHostName)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -151,6 +152,7 @@ BNetworkAddress::Unset()
|
|||
{
|
||||
fAddress.ss_family = AF_UNSPEC;
|
||||
fAddress.ss_len = 2;
|
||||
fHostName = "";
|
||||
fStatus = B_OK;
|
||||
}
|
||||
|
||||
|
@ -170,15 +172,13 @@ BNetworkAddress::SetTo(const char* host, uint16 port, uint32 flags)
|
|||
|
||||
uint32 cookie = 0;
|
||||
status = resolver->GetNextAddress(AF_INET6, &cookie, *this);
|
||||
if (status == B_OK) {
|
||||
fStatus = B_OK;
|
||||
return B_OK;
|
||||
if (status != B_OK) {
|
||||
cookie = 0;
|
||||
status = resolver->GetNextAddress(&cookie, *this);
|
||||
if (status != B_OK)
|
||||
Unset();
|
||||
}
|
||||
|
||||
cookie = 0;
|
||||
status = resolver->GetNextAddress(&cookie, *this);
|
||||
if (status != B_OK)
|
||||
Unset();
|
||||
fHostName = host;
|
||||
fStatus = status;
|
||||
return status;
|
||||
}
|
||||
|
@ -199,15 +199,13 @@ BNetworkAddress::SetTo(const char* host, const char* service, uint32 flags)
|
|||
|
||||
uint32 cookie = 0;
|
||||
status = resolver->GetNextAddress(AF_INET6, &cookie, *this);
|
||||
if (status == B_OK) {
|
||||
fStatus = B_OK;
|
||||
return B_OK;
|
||||
if (status != B_OK) {
|
||||
cookie = 0;
|
||||
status = resolver->GetNextAddress(&cookie, *this);
|
||||
if (status != B_OK)
|
||||
Unset();
|
||||
}
|
||||
|
||||
cookie = 0;
|
||||
status = resolver->GetNextAddress(&cookie, *this);
|
||||
if (status != B_OK)
|
||||
Unset();
|
||||
fHostName = host;
|
||||
fStatus = status;
|
||||
return status;
|
||||
}
|
||||
|
@ -235,6 +233,7 @@ BNetworkAddress::SetTo(int family, const char* host, uint16 port, uint32 flags)
|
|||
status = resolver->GetNextAddress(&cookie, *this);
|
||||
if (status != B_OK)
|
||||
Unset();
|
||||
fHostName = host;
|
||||
fStatus = status;
|
||||
return status;
|
||||
}
|
||||
|
@ -263,6 +262,7 @@ BNetworkAddress::SetTo(int family, const char* host, const char* service,
|
|||
status = resolver->GetNextAddress(&cookie, *this);
|
||||
if (status != B_OK)
|
||||
Unset();
|
||||
fHostName = host;
|
||||
fStatus = status;
|
||||
return status;
|
||||
}
|
||||
|
@ -372,6 +372,7 @@ BNetworkAddress::SetTo(const BNetworkAddress& other)
|
|||
{
|
||||
fAddress = other.fAddress;
|
||||
fStatus = other.fStatus;
|
||||
fHostName = other.fHostName;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1047,7 +1048,7 @@ BString
|
|||
BNetworkAddress::HostName() const
|
||||
{
|
||||
// TODO: implement host name lookup
|
||||
return ToString(false);
|
||||
return fHostName;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1159,6 +1160,7 @@ BNetworkAddress&
|
|||
BNetworkAddress::operator=(const BNetworkAddress& other)
|
||||
{
|
||||
memcpy(&fAddress, &other.fAddress, other.fAddress.ss_len);
|
||||
fHostName = other.fHostName;
|
||||
fStatus = other.fStatus;
|
||||
|
||||
return *this;
|
||||
|
@ -1291,6 +1293,8 @@ BNetworkAddress::_ParseLinkAddress(const char* address)
|
|||
|
||||
address += 3;
|
||||
}
|
||||
|
||||
fHostName = address;
|
||||
|
||||
SetToLinkLevel(linkAddress, length);
|
||||
return B_OK;
|
||||
|
|
|
@ -297,7 +297,7 @@ BSecureSocket::Connect(const BNetworkAddress& peer, bigtime_t timeout)
|
|||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
return _SetupConnect();
|
||||
return _SetupConnect(peer.HostName().String());
|
||||
}
|
||||
|
||||
|
||||
|
@ -381,7 +381,7 @@ BSecureSocket::Write(const void* buffer, size_t size)
|
|||
|
||||
|
||||
status_t
|
||||
BSecureSocket::_SetupCommon()
|
||||
BSecureSocket::_SetupCommon(const char* host)
|
||||
{
|
||||
// Do this only after BSocket::Connect has checked wether we're already
|
||||
// connected. We don't want to kill an existing SSL session, as that would
|
||||
|
@ -399,15 +399,20 @@ BSecureSocket::_SetupCommon()
|
|||
BIO_set_fd(fPrivate->fBIO, fSocket, BIO_NOCLOSE);
|
||||
SSL_set_bio(fPrivate->fSSL, fPrivate->fBIO, fPrivate->fBIO);
|
||||
SSL_set_ex_data(fPrivate->fSSL, Private::sDataIndex, this);
|
||||
if (host != NULL) {
|
||||
BString hostString = host;
|
||||
if (hostString != "")
|
||||
SSL_set_tlsext_host_name(fPrivate->fSSL, host);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BSecureSocket::_SetupConnect()
|
||||
BSecureSocket::_SetupConnect(const char* host)
|
||||
{
|
||||
status_t error = _SetupCommon();
|
||||
status_t error = _SetupCommon(host);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
|
@ -529,14 +534,14 @@ BSecureSocket::InitCheck()
|
|||
|
||||
|
||||
status_t
|
||||
BSecureSocket::_SetupCommon()
|
||||
BSecureSocket::_SetupCommon(const char* host)
|
||||
{
|
||||
return B_UNSUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BSecureSocket::_SetupConnect()
|
||||
BSecureSocket::_SetupConnect(const char* host)
|
||||
{
|
||||
return B_UNSUPPORTED;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue