Skip to content

Commit d9fd053

Browse files
authored
Update modified time when ETag check succeeded (#475)
IB-7029 Signed-off-by: Raul Metsma <[email protected]>
1 parent 73a53dc commit d9fd053

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

.github/workflows/build.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
container: ${{ matrix.container }}
6565
strategy:
6666
matrix:
67-
container: ['fedora:33']
67+
container: ['fedora:33', 'fedora:34']
6868
env:
6969
MAKEFLAGS: -j3
7070
steps:
@@ -77,8 +77,7 @@ jobs:
7777
- name: Install Deps
7878
run: |
7979
dnf install -y \
80-
cmake openssl-devel xerces-c-devel \
81-
xml-security-c-devel zlib-devel vim-common \
80+
gcc-c++ cmake openssl-devel xerces-c-devel xml-security-c-devel zlib-devel vim-common \
8281
https://www.codesynthesis.com/download/xsd/4.0/linux-gnu/x86_64/xsd-4.0.0-1.x86_64.rpm
8382
- name: Build
8483
run: |

src/crypto/TSL.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ TSL TSL::parseTSL(const string &url, const vector<X509Cert> &certs,
284284
THROW("TSL %s (%llu) is expired", territory.c_str(), tsl.sequenceNumber());
285285
if((CONF(TSLOnlineDigest)) && (File::modifiedTime(path) < (time(nullptr) - (60 * 60 * 24))))
286286
{
287-
tsl.validateETag(url, timeout);
288-
File::updateModifiedTime(path, time(nullptr));
287+
if(tsl.validateETag(url, timeout))
288+
File::updateModifiedTime(path, time(nullptr));
289289
}
290290
DEBUG("TSL %s (%llu) signature is valid", territory.c_str(), tsl.sequenceNumber());
291291
return tsl;
@@ -603,25 +603,22 @@ void TSL::validate(const vector<X509Cert> &certs)
603603
* @param timeout Time to wait for downloading
604604
* @throws Exception if ETag does not match cached ETag and TSL loading should be triggered
605605
*/
606-
void TSL::validateETag(const string &url, int timeout)
606+
bool TSL::validateETag(const string &url, int timeout)
607607
{
608608
Connect::Result r;
609609
try {
610610
r = Connect(url, "HEAD", timeout).exec({{"Accept-Encoding", "gzip"}});
611611
if(!r.isOK())
612-
return;
612+
return false;
613613
} catch(const Exception &e) {
614614
debugException(e);
615615
DEBUG("Failed to get ETag %s", url.c_str());
616-
return;
616+
return false;
617617
}
618618

619619
map<string,string>::const_iterator it = r.headers.find("ETag");
620620
if(it == r.headers.cend())
621-
{
622-
validateRemoteDigest(url, timeout);
623-
return;
624-
}
621+
return validateRemoteDigest(url, timeout);
625622

626623
DEBUG("Remote ETag: %s", it->second.c_str());
627624
ifstream is(File::encodeName(path + ".etag"));
@@ -632,6 +629,7 @@ void TSL::validateETag(const string &url, int timeout)
632629
DEBUG("Cached ETag: %s", etag.c_str());
633630
if(etag != it->second)
634631
THROW("Remote ETag does not match");
632+
return true;
635633
}
636634

637635
bool TSL::validateRemoteDigest(const string &url, int timeout)

src/crypto/TSL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TSL
5858
private:
5959
std::vector<std::string> pivotURLs() const;
6060
std::vector<X509Cert> signingCerts() const;
61-
void validateETag(const std::string &url, int timeout);
61+
bool validateETag(const std::string &url, int timeout);
6262
bool validateRemoteDigest(const std::string &url, int timeout);
6363

6464
static void debugException(const Exception &e);

0 commit comments

Comments
 (0)