Skip to content

Commit 7304bdc

Browse files
committed
robust deny-check for zero-IDs & suppress notifications in listener
1 parent e6c5c84 commit 7304bdc

2 files changed

Lines changed: 55 additions & 14 deletions

File tree

src/pqi/authssl.cc

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,8 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
13541354

13551355
RsInfo() << __PRETTY_FUNCTION__ << " " << errMsg << std::endl;
13561356

1357+
1358+
13571359
if(rsEvents && !isNotifyDenied(pgpId) && !isStringDenied(pgpId.toStdString()))
13581360
{
13591361
ev->mSslCn = sslCn;
@@ -1376,6 +1378,8 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
13761378

13771379
RsInfo() << __PRETTY_FUNCTION__ << " " << errMsg << std::endl;
13781380

1381+
1382+
13791383
if(rsEvents && !isNotifyDenied(pgpId) && !isStringDenied(pgpId.toStdString()))
13801384
{
13811385
ev->mSslId = sslId;
@@ -1434,6 +1438,8 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
14341438

14351439
RsInfo() << __PRETTY_FUNCTION__ << " " << errMsg << std::endl;
14361440

1441+
1442+
14371443
if(rsEvents && !isNotifyDenied(pgpId))
14381444
{
14391445
ev->mSslId = sslId;
@@ -1475,6 +1481,8 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
14751481

14761482
Dbg1() << __PRETTY_FUNCTION__ << " " << errMsg << std::endl;
14771483

1484+
1485+
14781486
if(rsEvents && !isNotifyDenied(pgpId))
14791487
{
14801488
ev->mSslId = sslId;
@@ -1943,6 +1951,17 @@ bool AuthSSLimpl::loadList(std::list<RsItem*>& load)
19431951
return true;
19441952
}
19451953

1954+
1955+
1956+
const EVP_PKEY*RsX509Cert::getPubKey(const X509& x509)
1957+
{
1958+
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
1959+
return x509.cert_info->key->pkey;
1960+
#else
1961+
return X509_get0_pubkey(&x509);
1962+
#endif
1963+
}
1964+
19461965
void AuthSSLimpl::addNotifyDeny(const RsPgpId& pgpId, const std::string& name)
19471966
{
19481967
RsStackMutex stack(sslMtx);
@@ -1960,20 +1979,19 @@ void AuthSSLimpl::removeNotifyDeny(const RsPgpId& pgpId)
19601979
bool AuthSSLimpl::isNotifyDenied(const RsPgpId& pgpId)
19611980
{
19621981
RsStackMutex stack(sslMtx);
1963-
return mDenyList.find(pgpId) != mDenyList.end();
1982+
if(mDenyList.find(pgpId) != mDenyList.end()) return true;
1983+
1984+
if(pgpId.isNull()) {
1985+
std::string s = pgpId.toStdString();
1986+
for(const auto& pair : mDenyList) {
1987+
if(pair.first.toStdString() == s) return true;
1988+
}
1989+
}
1990+
return false;
19641991
}
19651992

19661993
void AuthSSLimpl::getNotifyDenyList(std::map<RsPgpId, std::string>& ids)
19671994
{
19681995
RsStackMutex stack(sslMtx);
19691996
ids = mDenyList;
19701997
}
1971-
1972-
const EVP_PKEY*RsX509Cert::getPubKey(const X509& x509)
1973-
{
1974-
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
1975-
return x509.cert_info->key->pkey;
1976-
#else
1977-
return X509_get0_pubkey(&x509);
1978-
#endif
1979-
}

src/pqi/pqissllistener.cc

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,33 @@ int pqissllistenbase::continueSSL(IncomingSSLInfo& incoming_connexion_info, bool
493493

494494
if(vres == X509_V_OK && nullptr != rsEvents)
495495
{
496-
auto ev = std::make_shared<RsAuthSslConnectionAutenticationEvent>();
497-
ev->mLocator = RsUrl(incoming_connexion_info.addr);
498-
ev->mErrorCode = RsAuthSslError::MISSING_AUTHENTICATION_INFO;
499-
rsEvents->postEvent(ev);
496+
// Check if denied before posting event
497+
bool denied = false;
498+
X509 *x509_check = SSL_get_peer_certificate(incoming_connexion_info.ssl);
499+
RsPgpId checkedPgpId; // Default 0
500+
if(x509_check) {
501+
checkedPgpId = RsX509Cert::getCertIssuer(*x509_check);
502+
X509_free(x509_check);
503+
}
504+
505+
if(AuthSSL::instance().isNotifyDenied(checkedPgpId)) {
506+
denied = true;
507+
}
508+
509+
if(!denied) {
510+
auto ev = std::make_shared<RsAuthSslConnectionAutenticationEvent>();
511+
ev->mLocator = RsUrl(incoming_connexion_info.addr);
512+
// Try to fill in more info if available
513+
if((x509_check = SSL_get_peer_certificate(incoming_connexion_info.ssl))) {
514+
ev->mPgpId = RsX509Cert::getCertIssuer(*x509_check);
515+
ev->mSslId = RsX509Cert::getCertSslId(*x509_check);
516+
ev->mSslCn = RsX509Cert::getCertName(*x509_check);
517+
X509_free(x509_check);
518+
}
519+
520+
ev->mErrorCode = RsAuthSslError::MISSING_AUTHENTICATION_INFO;
521+
rsEvents->postEvent(ev);
522+
}
500523
}
501524
closeConnection(fd, incoming_connexion_info.ssl);
502525

0 commit comments

Comments
 (0)