Skip to content

Commit 4efa578

Browse files
committed
Add expire date to label
Signed-off-by: Raul Metsma <[email protected]>
1 parent 8e6d7b7 commit 4efa578

File tree

7 files changed

+45
-21
lines changed

7 files changed

+45
-21
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ jobs:
1414
container: ubuntu:${{ matrix.container }}
1515
strategy:
1616
matrix:
17-
container: ['22.04', '24.04', '24.10', '25.04']
17+
container: ['22.04', '24.04', '25.04']
1818
arch: ['amd64', 'arm64']
1919
env:
2020
DEBIAN_FRONTEND: noninteractive
2121
DEBFULLNAME: github-actions
2222
23+
JAVA_HOME: /usr/lib/jvm/java-17-openjdk-${{ matrix.arch }}
2324
steps:
2425
- name: Install dependencies
2526
run: apt update -qq && apt install --no-install-recommends -y lsb-release build-essential devscripts debhelper lintian pkg-config ${UBUNTU_DEPS} doxygen swig openjdk-17-jdk-headless libpython3-dev python3-setuptools libboost-test-dev
@@ -32,7 +33,7 @@ jobs:
3233
dch --distribution $(lsb_release -cs) -v ${VERSIONEX} "Release ${VERSIONEX}."
3334
- name: Build packages
3435
run: |
35-
JAVA_HOME=/usr/lib/jvm/java-17-openjdk-${{ matrix.arch }} dpkg-buildpackage -us -uc
36+
dpkg-buildpackage -us -uc
3637
mv ../libcdoc*.* .
3738
- name: Lintian
3839
run: lintian *.deb;
@@ -125,7 +126,7 @@ jobs:
125126
runs-on: ${{ matrix.image }}
126127
strategy:
127128
matrix:
128-
image: [windows-2022]
129+
image: [windows-2025]
129130
platform: [x64, arm64]
130131
env:
131132
CXXFLAGS: '/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR' # https://github.com/actions/runner-images/issues/10004
@@ -144,10 +145,7 @@ jobs:
144145
env:
145146
VCPKG_INSTALLED_DIR: ${{ github.workspace }}/build/vcpkg_installed
146147
- name: Install dependencies
147-
run: |
148-
choco install doxygen.install -y > $null
149-
Invoke-WebRequest -UserAgent "Wget" "https://sourceforge.net/projects/swig/files/swigwin/swigwin-4.3.0/swigwin-4.3.0.zip/download" -OutFile swig.zip
150-
tar xf swig.zip
148+
run: winget install --accept-package-agreements --accept-source-agreements doxygen swig
151149
- uses: actions/setup-java@v4
152150
with:
153151
distribution: 'temurin'
@@ -156,7 +154,6 @@ jobs:
156154
run: |
157155
cmake -A ${{ matrix.platform }} -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo `
158156
"-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" `
159-
"-DSWIG_EXECUTABLE=${{ github.workspace }}/swigwin-4.3.0/swig.exe" `
160157
-DVCPKG_TARGET_TRIPLET=${{ env.VCPKG_DEFAULT_TRIPLET }} `
161158
-DVCPKG_MANIFEST_FEATURES=tests `
162159
-DCMAKE_INSTALL_LIBDIR=bin

cdoc/Certificate.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ Certificate::getSerialNumber() const
7474
return getName(cert, NID_serialNumber);
7575
}
7676

77+
time_t
78+
Certificate::getNotAfter() const
79+
{
80+
if(!cert)
81+
return 0;
82+
tm tm{};
83+
if(ASN1_TIME_to_tm(X509_get0_notAfter(cert.get()), &tm) != 1)
84+
return 0;
85+
#ifdef _WIN32
86+
return _mkgmtime(&tm);
87+
#else
88+
return timegm(&tm);
89+
#endif
90+
}
91+
7792

7893

7994
std::vector<std::string>
@@ -85,8 +100,8 @@ Certificate::policies() const
85100
if(!cert)
86101
return list;
87102

88-
auto p = static_cast<CERTIFICATEPOLICIES *>(X509_get_ext_d2i(cert.get(), NID_certificate_policies, nullptr, nullptr));
89-
auto cp = std::unique_ptr<CERTIFICATEPOLICIES,decltype(&CERTIFICATEPOLICIES_free)>(p,CERTIFICATEPOLICIES_free);
103+
auto cp = make_unique_cast<CERTIFICATEPOLICIES_free>(X509_get_ext_d2i(
104+
cert.get(), NID_certificate_policies, nullptr, nullptr));
90105
if(!cp)
91106
return list;
92107

cdoc/Certificate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Certificate {
5050

5151
std::vector<uint8_t> getPublicKey() const;
5252
Algorithm getAlgorithm() const;
53+
time_t getNotAfter() const;
5354

5455
std::vector<uint8_t> getDigest();
5556
};

cdoc/Io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace libcdoc {
2828

29-
class DataSource;
29+
struct DataSource;
3030

3131
/**
3232
* @brief The DataConsumer class

cdoc/Recipient.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Recipient
104104
Recipient::makeEIDServer(std::vector<uint8_t> cert, std::string server_id)
105105
{
106106
Certificate x509(cert);
107-
auto label = BuildLabelEID(cert);
107+
auto label = BuildLabelEID(cert, time(nullptr) + 60 * 60 * 24 * 31 * 6); // 6 months
108108
return makeServer(std::move(label),
109109
x509.getPublicKey(), x509.getAlgorithm() == Certificate::Algorithm::RSA ? RSA : ECC, std::move(server_id));
110110
}
@@ -143,7 +143,7 @@ static constexpr std::string_view type_strs[] = {
143143
};
144144

145145
std::string
146-
Recipient::buildLabel(std::vector<std::pair<std::string_view, std::string_view>> components)
146+
Recipient::buildLabel(const std::vector<std::pair<std::string_view, std::string_view>> &components, time_t exp)
147147
{
148148
std::ostringstream ofs;
149149
ofs << LABELPREFIX;
@@ -155,11 +155,14 @@ Recipient::buildLabel(std::vector<std::pair<std::string_view, std::string_view>>
155155
first = false;
156156
}
157157
}
158+
if(exp > 0) {
159+
ofs << "&server_exp=" << exp;
160+
}
158161
return ofs.str();
159162
}
160163

161164
std::string
162-
Recipient::BuildLabelEID(int version, EIDType type, std::string_view cn, std::string_view serial_number, std::string_view last_name, std::string_view first_name)
165+
Recipient::BuildLabelEID(int version, EIDType type, std::string_view cn, std::string_view serial_number, std::string_view last_name, std::string_view first_name, time_t exp)
163166
{
164167
// In case of cards issued to an organization the first name (and last name) are missing. We ommit these parts.
165168
if (first_name.empty()) {
@@ -168,7 +171,7 @@ Recipient::BuildLabelEID(int version, EIDType type, std::string_view cn, std::st
168171
{"type", type_strs[type]},
169172
{"cn", cn},
170173
{"serial_number", serial_number}
171-
});
174+
}, exp);
172175
} else {
173176
return buildLabel({
174177
{"v", std::to_string(version)},
@@ -177,15 +180,15 @@ Recipient::BuildLabelEID(int version, EIDType type, std::string_view cn, std::st
177180
{"serial_number", serial_number},
178181
{"last_name", last_name},
179182
{"first_name", first_name}
180-
});
183+
}, exp);
181184
}
182185
}
183186

184187
std::string
185-
Recipient::BuildLabelEID(const std::vector<uint8_t>& cert)
188+
Recipient::BuildLabelEID(const std::vector<uint8_t>& cert, time_t exp)
186189
{
187190
Certificate x509(cert);
188-
return BuildLabelEID(CDoc2::KEYLABELVERSION, getEIDType(x509.policies()), x509.getCommonName(), x509.getSerialNumber(), x509.getSurname(), x509.getGivenName());
191+
return BuildLabelEID(CDoc2::KEYLABELVERSION, getEIDType(x509.policies()), x509.getCommonName(), x509.getSerialNumber(), x509.getSurname(), x509.getGivenName(), exp ? exp : x509.getNotAfter());
189192
}
190193

191194
std::string

cdoc/Recipient.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,10 @@ struct CDOC_EXPORT Recipient {
231231
/**
232232
* @brief build machine-readable CDoc2 label
233233
* @param components a list of string pairs
234+
* @param exp a expire date to added to label (if 0, no expire date is added)
234235
* @return a composed label
235236
*/
236-
static std::string buildLabel(std::vector<std::pair<std::string_view, std::string_view>> components);
237+
static std::string buildLabel(const std::vector<std::pair<std::string_view, std::string_view>> &components, time_t exp = 0);
237238
/**
238239
* @brief build machine-readable CDoc2 label for EID recipient
239240
* @param version the label version
@@ -242,16 +243,18 @@ struct CDOC_EXPORT Recipient {
242243
* @param serial_number the serial number
243244
* @param last_name the last name
244245
* @param first_name the first name
246+
* @param exp a expire date to added to label (if 0, no expire date is added)
245247
* @return a composed label
246248
*/
247-
static std::string BuildLabelEID(int version, EIDType type, std::string_view cn, std::string_view serial_number, std::string_view last_name, std::string_view first_name);
249+
static std::string BuildLabelEID(int version, EIDType type, std::string_view cn, std::string_view serial_number, std::string_view last_name, std::string_view first_name, time_t exp = 0);
248250
/**
249251
* @brief build machine-readable CDoc2 label for EID recipient filling info from certificate
250252
* @see BuildLabelEID
251253
* @param cert the certificate value (der-encoded)
254+
* @param exp a expire date to added to label (if 0, expire date is taken from certificate)
252255
* @return a composed label
253256
*/
254-
static std::string BuildLabelEID(const std::vector<uint8_t> &cert);
257+
static std::string BuildLabelEID(const std::vector<uint8_t> &cert, time_t exp = 0);
255258
/**
256259
* @brief build machine-readable CDoc2 label for certificate-based recipient
257260
* @param version the label version

cdoc/utils/memory.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ struct free_argument<R (*)(T *)>
3838
{
3939
using type = T;
4040
};
41+
template<class T, class R>
42+
struct free_argument<R (&)(T *)>
43+
{
44+
using type = T;
45+
};
4146

4247
template <class T>
4348
using unique_free_t = std::unique_ptr<T, void(*)(T*)>;

0 commit comments

Comments
 (0)