Ticket #12388: 0001-Add-support-for-TLS-SNI.patch

File 0001-Add-support-for-TLS-SNI.patch, 5.8 KB (added by markh, 4 years ago)
  • headers/os/net/NetworkAddress.h

    From 0f0a1dfd2fa25b0d0a0f5b0fc997a858eee04f64 Mon Sep 17 00:00:00 2001
    From: Mark Hellegers <mark@firedisk.net>
    Date: Sun, 22 May 2016 21:02:03 +0200
    Subject: [PATCH] Add support for TLS SNI
    
    ---
     headers/os/net/NetworkAddress.h               |  1 +
     headers/os/net/SecureSocket.h                 |  4 +--
     src/kits/network/libnetapi/NetworkAddress.cpp | 40 +++++++++++++++------------
     src/kits/network/libnetapi/SecureSocket.cpp   | 17 ++++++++----
     4 files changed, 36 insertions(+), 26 deletions(-)
    
    diff --git a/headers/os/net/NetworkAddress.h b/headers/os/net/NetworkAddress.h
    index 865ed73..717108a 100644
    a b private:  
    149149private:
    150150            sockaddr_storage    fAddress;
    151151            status_t            fStatus;
     152            BString             fHostName;
    152153};
    153154
    154155
  • headers/os/net/SecureSocket.h

    diff --git a/headers/os/net/SecureSocket.h b/headers/os/net/SecureSocket.h
    index ebf1e15..fe55cc6 100644
    a b public:  
    4242    virtual ssize_t             Write(const void* buffer, size_t size);
    4343
    4444protected:
    45             status_t            _SetupCommon();
    46             status_t            _SetupConnect();
     45            status_t            _SetupCommon(const char* host = NULL);
     46            status_t            _SetupConnect(const char* host = NULL);
    4747            status_t            _SetupAccept();
    4848
    4949private:
  • src/kits/network/libnetapi/NetworkAddress.cpp

    diff --git a/src/kits/network/libnetapi/NetworkAddress.cpp b/src/kits/network/libnetapi/NetworkAddress.cpp
    index 57de4bc..2bfbcd1 100644
    a b BNetworkAddress::BNetworkAddress(const in6_addr& address, uint16 port)  
    129129BNetworkAddress::BNetworkAddress(const BNetworkAddress& other)
    130130    :
    131131    fAddress(other.fAddress),
    132     fStatus(other.fStatus)
     132    fStatus(other.fStatus),
     133    fHostName(other.fHostName)
    133134{
    134135}
    135136
    BNetworkAddress::Unset()  
    151152{
    152153    fAddress.ss_family = AF_UNSPEC;
    153154    fAddress.ss_len = 2;
     155    fHostName = "";
    154156    fStatus = B_OK;
    155157}
    156158
    BNetworkAddress::SetTo(const char* host, uint16 port, uint32 flags)  
    170172
    171173    uint32 cookie = 0;
    172174    status = resolver->GetNextAddress(AF_INET6, &cookie, *this);
    173     if (status == B_OK) {
    174         fStatus = B_OK;
    175         return B_OK;
     175    if (status != B_OK) {
     176        cookie = 0;
     177        status = resolver->GetNextAddress(&cookie, *this);
     178        if (status != B_OK)
     179            Unset();
    176180    }
    177 
    178     cookie = 0;
    179     status = resolver->GetNextAddress(&cookie, *this);
    180     if (status != B_OK)
    181         Unset();
     181    fHostName = host;
    182182    fStatus = status;
    183183    return status;
    184184}
    BNetworkAddress::SetTo(const char* host, const char* service, uint32 flags)  
    199199
    200200    uint32 cookie = 0;
    201201    status = resolver->GetNextAddress(AF_INET6, &cookie, *this);
    202     if (status == B_OK) {
    203         fStatus = B_OK;
    204         return B_OK;
     202    if (status != B_OK) {
     203        cookie = 0;
     204        status = resolver->GetNextAddress(&cookie, *this);
     205        if (status != B_OK)
     206            Unset();
    205207    }
    206 
    207     cookie = 0;
    208     status = resolver->GetNextAddress(&cookie, *this);
    209     if (status != B_OK)
    210         Unset();
     208    fHostName = host;
    211209    fStatus = status;
    212210    return status;
    213211}
    BNetworkAddress::SetTo(int family, const char* host, uint16 port, uint32 flags)  
    235233    status = resolver->GetNextAddress(&cookie, *this);
    236234    if (status != B_OK)
    237235        Unset();
     236    fHostName = host;
    238237    fStatus = status;
    239238    return status;
    240239}
    BNetworkAddress::SetTo(int family, const char* host, const char* service,  
    263262    status = resolver->GetNextAddress(&cookie, *this);
    264263    if (status != B_OK)
    265264        Unset();
     265    fHostName = host;
    266266    fStatus = status;
    267267    return status;
    268268}
    BNetworkAddress::SetTo(const BNetworkAddress& other)  
    372372{
    373373    fAddress = other.fAddress;
    374374    fStatus = other.fStatus;
     375    fHostName = other.fHostName;
    375376}
    376377
    377378
    BString  
    10471048BNetworkAddress::HostName() const
    10481049{
    10491050    // TODO: implement host name lookup
    1050     return ToString(false);
     1051    return fHostName;
    10511052}
    10521053
    10531054
    BNetworkAddress&  
    11591160BNetworkAddress::operator=(const BNetworkAddress& other)
    11601161{
    11611162    memcpy(&fAddress, &other.fAddress, other.fAddress.ss_len);
     1163    fHostName = other.fHostName;
    11621164    fStatus = other.fStatus;
    11631165
    11641166    return *this;
    BNetworkAddress::_ParseLinkAddress(const char* address)  
    12911293
    12921294        address += 3;
    12931295    }
     1296   
     1297    fHostName = address;
    12941298
    12951299    SetToLinkLevel(linkAddress, length);
    12961300    return B_OK;
  • src/kits/network/libnetapi/SecureSocket.cpp

    diff --git a/src/kits/network/libnetapi/SecureSocket.cpp b/src/kits/network/libnetapi/SecureSocket.cpp
    index ef66cf8..773a6eb 100644
    a b BSecureSocket::Connect(const BNetworkAddress& peer, bigtime_t timeout)  
    297297    if (status != B_OK)
    298298        return status;
    299299
    300     return _SetupConnect();
     300    return _SetupConnect(peer.HostName().String());
    301301}
    302302
    303303
    BSecureSocket::Write(const void* buffer, size_t size)  
    381381
    382382
    383383status_t
    384 BSecureSocket::_SetupCommon()
     384BSecureSocket::_SetupCommon(const char* host)
    385385{
    386386    // Do this only after BSocket::Connect has checked wether we're already
    387387    // connected. We don't want to kill an existing SSL session, as that would
    BSecureSocket::_SetupCommon()  
    399399    BIO_set_fd(fPrivate->fBIO, fSocket, BIO_NOCLOSE);
    400400    SSL_set_bio(fPrivate->fSSL, fPrivate->fBIO, fPrivate->fBIO);
    401401    SSL_set_ex_data(fPrivate->fSSL, Private::sDataIndex, this);
     402    if (host != NULL) {
     403        BString hostString = host;
     404        if (hostString != "")
     405            SSL_set_tlsext_host_name(fPrivate->fSSL, host);
     406    }
    402407
    403408    return B_OK;
    404409}
    405410
    406411
    407412status_t
    408 BSecureSocket::_SetupConnect()
     413BSecureSocket::_SetupConnect(const char* host)
    409414{
    410     status_t error = _SetupCommon();
     415    status_t error = _SetupCommon(host);
    411416    if (error != B_OK)
    412417        return error;
    413418
    BSecureSocket::InitCheck()  
    529534
    530535
    531536status_t
    532 BSecureSocket::_SetupCommon()
     537BSecureSocket::_SetupCommon(const char* host)
    533538{
    534539    return B_UNSUPPORTED;
    535540}
    536541
    537542
    538543status_t
    539 BSecureSocket::_SetupConnect()
     544BSecureSocket::_SetupConnect(const char* host)
    540545{
    541546    return B_UNSUPPORTED;
    542547}