Skip to content

Commit 84e4f52

Browse files
committed
implement persistent Ignore/Deny list with Names and PGP ID
1 parent c40adad commit 84e4f52

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

src/pqi/authssl.cc

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
14261426

14271427
RsInfo() << __PRETTY_FUNCTION__ << " " << errMsg << std::endl;
14281428

1429-
if(rsEvents)
1429+
if(rsEvents && !isNotifyDenied(pgpId))
14301430
{
14311431
ev->mSslId = sslId;
14321432
ev->mSslCn = sslCn;
@@ -1467,7 +1467,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx)
14671467

14681468
Dbg1() << __PRETTY_FUNCTION__ << " " << errMsg << std::endl;
14691469

1470-
if(rsEvents)
1470+
if(rsEvents && !isNotifyDenied(pgpId))
14711471
{
14721472
ev->mSslId = sslId;
14731473
ev->mSslCn = sslCn;
@@ -1874,6 +1874,18 @@ bool AuthSSLimpl::saveList(bool& cleanup, std::list<RsItem*>& lst)
18741874
}
18751875
lst.push_back(vitem);
18761876

1877+
/* Save Deny List */
1878+
if (!mDenyList.empty()) {
1879+
RsConfigKeyValueSet* denyItem = new RsConfigKeyValueSet;
1880+
for (const auto& pair : mDenyList) {
1881+
RsTlvKeyValue kv;
1882+
kv.key = pair.first.toStdString();
1883+
kv.value = "DENY:" + pair.second;
1884+
denyItem->tlvkvs.pairs.push_back(kv);
1885+
}
1886+
lst.push_back(denyItem);
1887+
}
1888+
18771889
return true ;
18781890
}
18791891

@@ -1903,6 +1915,11 @@ bool AuthSSLimpl::loadList(std::list<RsItem*>& load)
19031915
continue;
19041916
}
19051917

1918+
if (kit->value.compare(0, 5, "DENY:") == 0) {
1919+
mDenyList[RsPgpId(kit->key)] = kit->value.substr(5);
1920+
continue;
1921+
}
1922+
19061923
X509 *peer = loadX509FromPEM(kit->value);
19071924
/* authenticate it */
19081925
uint32_t diagnos ;
@@ -1918,6 +1935,32 @@ bool AuthSSLimpl::loadList(std::list<RsItem*>& load)
19181935
return true;
19191936
}
19201937

1938+
void AuthSSLimpl::addNotifyDeny(const RsPgpId& pgpId, const std::string& name)
1939+
{
1940+
RsStackMutex stack(sslMtx);
1941+
mDenyList[pgpId] = name;
1942+
IndicateConfigChanged();
1943+
}
1944+
1945+
void AuthSSLimpl::removeNotifyDeny(const RsPgpId& pgpId)
1946+
{
1947+
RsStackMutex stack(sslMtx);
1948+
mDenyList.erase(pgpId);
1949+
IndicateConfigChanged();
1950+
}
1951+
1952+
bool AuthSSLimpl::isNotifyDenied(const RsPgpId& pgpId)
1953+
{
1954+
RsStackMutex stack(sslMtx);
1955+
return mDenyList.find(pgpId) != mDenyList.end();
1956+
}
1957+
1958+
void AuthSSLimpl::getNotifyDenyList(std::map<RsPgpId, std::string>& ids)
1959+
{
1960+
RsStackMutex stack(sslMtx);
1961+
ids = mDenyList;
1962+
}
1963+
19211964
const EVP_PKEY*RsX509Cert::getPubKey(const X509& x509)
19221965
{
19231966
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)

src/pqi/authssl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ class AuthSSL
112112

113113
virtual X509* SignX509ReqWithGPG(X509_REQ* req, long days) = 0;
114114

115+
virtual void addNotifyDeny(const RsPgpId& pgpId, const std::string& name) = 0;
116+
virtual void removeNotifyDeny(const RsPgpId& pgpId) = 0;
117+
virtual bool isNotifyDenied(const RsPgpId& pgpId) = 0;
118+
virtual void getNotifyDenyList(std::map<RsPgpId, std::string>& ids) = 0;
119+
115120
/**
116121
* @brief Verify PGP signature correcteness on given X509 certificate
117122
* Beware this doesn't check if the PGP signer is friend or not, just if the
@@ -207,6 +212,11 @@ class AuthSSLimpl : public AuthSSL, public p3Config
207212
bool decrypt(void *&out, int &outlen, const void *in, int inlen) override;
208213

209214
virtual X509* SignX509ReqWithGPG(X509_REQ *req, long days) override;
215+
216+
void addNotifyDeny(const RsPgpId& pgpId, const std::string& name) override;
217+
void removeNotifyDeny(const RsPgpId& pgpId) override;
218+
bool isNotifyDenied(const RsPgpId& pgpId) override;
219+
void getNotifyDenyList(std::map<RsPgpId, std::string>& ids) override;
210220

211221
/// @see AuthSSL
212222
bool AuthX509WithGPG(X509 *x509, bool verbose, uint32_t& auth_diagnostic) override;
@@ -265,4 +275,6 @@ class AuthSSLimpl : public AuthSSL, public p3Config
265275
RsPgpId _last_gpgid_to_connect;
266276
std::string _last_sslcn_to_connect;
267277
RsPeerId _last_sslid_to_connect;
278+
279+
std::map<RsPgpId, std::string> mDenyList;
268280
};

0 commit comments

Comments
 (0)