Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
25ab007
Tar and workflow fixes and tests
Jan 23, 2026
98224e6
Merge branch 'open-eid:master' into master
lauris71 Jan 26, 2026
b4a1736
Create locks even if capsule is not supported
Jan 30, 2026
414452e
Update cdoc/CDoc2Reader.cpp
lauris71 Feb 2, 2026
0854344
Use toUint8Vector helper
Feb 2, 2026
777700c
Removed some extra check from parsing
Feb 2, 2026
8cdc652
Remove INVALID lock type and rename UNSUPPORTED to UNKNOWN
Feb 3, 2026
5ef36d7
Return NULL from frontend if CDoc constructor fails
Feb 4, 2026
f2c9091
Merge branch 'open-eid:master' into master
lauris71 Feb 4, 2026
b76e104
Merge branch 'open-eid:master' into master
lauris71 Feb 11, 2026
625c768
Remove label creation from Java test
Feb 11, 2026
678a318
Merge branch 'open-eid:master' into master
lauris71 Feb 12, 2026
372f7f7
Keep Java references in CDocReader and CDocWriter to prevent prematur…
Feb 12, 2026
e9155eb
Merge branch 'open-eid:master' into master
lauris71 Feb 12, 2026
4dc229f
Cleaned up logging
Feb 13, 2026
209042f
Renamed ILogger -> Logger
Feb 13, 2026
ee33b97
Added Logger.h
Feb 13, 2026
9930c35
Removed ConsoleLogger from public interface
Feb 13, 2026
ce13f36
Fixed WinBackend.cpp
Feb 13, 2026
4453784
Fixed WinBackend.cpp more
Feb 13, 2026
cb10179
One more Winbackend fix
Feb 13, 2026
1db00de
Merge branch 'open-eid:master' into master
lauris71 Feb 13, 2026
252333f
Merge branch 'logging'
Feb 13, 2026
985e226
Merge branch 'open-eid:master' into master
lauris71 Feb 17, 2026
7d5f35d
Export CDocCipher internally for cdoc-tool
Mar 3, 2026
40c6fe0
Merge branch 'open-eid:master' into master
lauris71 Mar 9, 2026
1022623
Fix label parsing
Mar 11, 2026
fe80e76
Handle "PaxHeaders" paths correctly
Mar 13, 2026
04fd236
Merge branch 'open-eid:master' into master
lauris71 Mar 13, 2026
1be01a7
Apply suggestions from code review
lauris71 Mar 16, 2026
c4ed519
Merge branch 'open-eid:master' into master
lauris71 Mar 25, 2026
7d533a0
Fix tar filenames if only PAX size is used
Mar 25, 2026
8bb1c86
Moved parseLabel to Lock, take minimum of expiry time
Mar 26, 2026
a9bb137
Fixed CDocTool.java
Mar 26, 2026
2af5e5a
Merge branch 'open-eid:master' into master
lauris71 Mar 26, 2026
af001aa
Merge commit '2af5e5a73ee3cfdc923ef3995c696e509c8cbee6' into rel1_7
Mar 27, 2026
84a4a92
Use property system for automatic label generation
Mar 27, 2026
129976b
Merge commit '7aa1eac3d147f40374be18cc1cdb189f5268a080'
Mar 27, 2026
e2d5b44
Merge branch 'master' into rel1_7
Mar 27, 2026
4fb60a3
remove final from CDoc2
Mar 27, 2026
7f94de4
Exclude CDoc2 from swig for the time being
Mar 27, 2026
3493f79
Remove commented-out code
Mar 27, 2026
cb79943
Remove 'final' once more
Mar 27, 2026
90fd645
Made CDoc2 back to namespace
Mar 27, 2026
5429a11
Moved label strings to Label namespace
Mar 27, 2026
992aa6d
#undef VERSION
Mar 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions cdoc/CDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,41 @@ struct FileInfo {
int64_t size;
};

#ifdef VERSION
#undef VERSION
#endif

namespace CDoc2 {
namespace Label {
/**
* @brief Recipient types for machine-readable labels
*
*/
static constexpr std::string_view TYPE_PASSWORD = "pw";
static constexpr std::string_view TYPE_SYMMETRIC = "secret";
static constexpr std::string_view TYPE_PUBLIC_KEY = "pub_key";
static constexpr std::string_view TYPE_CERTIFICATE = "cert";
static constexpr std::string_view TYPE_UNKNOWN = "Unknown";
static constexpr std::string_view TYPE_ID_CARD = "ID-card";
static constexpr std::string_view TYPE_DIGI_ID = "Digi-ID";
static constexpr std::string_view TYPE_DIGI_ID_E_RESIDENT = "Digi-ID E-RESIDENT";

/**
* @brief Recipient data for machine-readable labels
*
*/
static constexpr std::string_view VERSION = "v";
static constexpr std::string_view TYPE = "type";
static constexpr std::string_view FILE = "file";
static constexpr std::string_view LABEL = "label";
static constexpr std::string_view CN = "cn";
static constexpr std::string_view SERIAL_NUMBER = "serial_number";
static constexpr std::string_view LAST_NAME = "last_name";
static constexpr std::string_view FIRST_NAME = "first_name";
static constexpr std::string_view CERT_SHA1 = "cert_sha1";
}
}

}; // namespace libcdoc

#endif // CDOC_H
10 changes: 6 additions & 4 deletions cdoc/CDoc2.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef __CDOC2_H__
#define __CDOC2_H__

#include "CDoc.h"

#include <string_view>

namespace libcdoc {
Expand Down Expand Up @@ -57,10 +59,10 @@ constexpr std::string_view LABELBASE64IND{";base64,"};
* @brief EID type values for machine-readable label
*/
static constexpr std::string_view eid_strs[] = {
"Unknown",
"ID-card",
"Digi-ID",
"Digi-ID E-RESIDENT"
CDoc2::Label::TYPE_UNKNOWN,
CDoc2::Label::TYPE_ID_CARD,
CDoc2::Label::TYPE_DIGI_ID,
CDoc2::Label::TYPE_DIGI_ID_E_RESIDENT
};

} // namespace CDoc2
Expand Down
1 change: 0 additions & 1 deletion cdoc/CDoc2Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@ CDoc2Reader::CDoc2Reader(libcdoc::DataSource *src, bool take_ownership)
LOG_ERROR("{}", last_error);
return;
}
//if (libcdoc::CDoc2::LABEL.compare(0, libcdoc::CDoc2::LABEL.size(), (const char *) in)) return;

// Read 32-bit header length in big endian order
uint8_t c[4];
Expand Down
87 changes: 38 additions & 49 deletions cdoc/Recipient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,60 +121,44 @@ Recipient::isTheSameRecipient(const std::vector<uint8_t>& public_key) const
}

static void
buildLabel(std::ostream& ofs, std::string_view type, std::initializer_list<std::pair<std::string_view, std::string_view>> components)
buildLabel(std::ostream& ofs, std::string_view type, const std::map<std::string_view,std::string_view> lbl_parts, std::initializer_list<std::pair<std::string_view, std::string_view>> extra)
{
auto parts = lbl_parts;
if (parts.contains("v"))
parts.erase("v");
if (parts.contains("type"))
parts.erase("type");
for (const auto& [key, value] : extra) {
if (!value.empty())
parts[key] = value;
}
ofs << CDoc2::LABELPREFIX;
ofs << "v" << '=' << std::to_string(CDoc2::KEYLABELVERSION) << '&'
<< "type" << '=' << type;
for (const auto& [key, value] : components) {
ofs << CDoc2::Label::VERSION << '=' << std::to_string(CDoc2::KEYLABELVERSION) << '&'
<< CDoc2::Label::TYPE << '=' << type;
for (const auto& [key, value] : parts) {
if (!value.empty())
ofs << '&' << urlEncode(key) << '=' << urlEncode(value);
}
}

static void
BuildLabelEID(std::ostream& ofs, Certificate::EIDType type, const Certificate& x509)
{
buildLabel(ofs, CDoc2::eid_strs[type], {
{"cn", x509.getCommonName()},
{"serial_number", x509.getSerialNumber()},
{"last_name", x509.getSurname()},
{"first_name", x509.getGivenName()},
});
}

static void
BuildLabelCertificate(std::ostream &ofs, const std::string& file, const Certificate& x509)
BuildLabelEID(std::ostream& ofs, Certificate::EIDType type, const Certificate& x509, const std::map<std::string_view,std::string_view>& lbl_parts)
{
buildLabel(ofs, "cert", {
{"file", file},
{"cn", x509.getCommonName()},
{"cert_sha1", toHex(x509.getDigest())}

buildLabel(ofs, CDoc2::eid_strs[type], lbl_parts, {
{CDoc2::Label::CN, x509.getCommonName()},
{CDoc2::Label::SERIAL_NUMBER, x509.getSerialNumber()},
{CDoc2::Label::LAST_NAME, x509.getSurname()},
{CDoc2::Label::FIRST_NAME, x509.getGivenName()},
});
}

static void
BuildLabelPublicKey(std::ostream &ofs, const std::string& file)
BuildLabelCertificate(std::ostream &ofs, const Certificate& x509, const std::map<std::string_view,std::string_view>& lbl_parts)
{
buildLabel(ofs, "pub_key", {
{"file", file}
});
}

static void
BuildLabelSymmetricKey(std::ostream &ofs, const std::string& label, const std::string& file)
{
buildLabel(ofs, "secret", {
{"label", label},
{"file", file}
});
}

static void
BuildLabelPassword(std::ostream &ofs, const std::string& label)
{
buildLabel(ofs, "pw", {
{"label", label}
buildLabel(ofs, CDoc2::Label::TYPE_CERTIFICATE, lbl_parts, {
{CDoc2::Label::CN, x509.getCommonName()},
{CDoc2::Label::CERT_SHA1, toHex(x509.getDigest())}
});
}

Expand All @@ -183,37 +167,42 @@ Recipient::getLabel(const std::vector<std::pair<std::string_view, std::string_vi
{
LOG_DBG("Generating label");
if (!label.empty()) return label;
std::map<std::string_view,std::string_view> parts;
for (const auto& [key, value] : lbl_parts) {
if (!value.empty())
parts[key] = value;
}
for (const auto& [key, value] : extra) {
if (!value.empty())
parts[key] = value;
}
std::ostringstream ofs;
switch(type) {
case NONE:
LOG_DBG("The recipient is not initialized");
break;
case SYMMETRIC_KEY:
if (kdf_iter > 0) {
BuildLabelPassword(ofs, key_name);
buildLabel(ofs, CDoc2::Label::TYPE_PASSWORD, parts, {});
} else {
BuildLabelSymmetricKey(ofs, key_name, file_name);
buildLabel(ofs, CDoc2::Label::TYPE_SYMMETRIC, parts, {});
}
break;
case PUBLIC_KEY:
if (!cert.empty()) {
Certificate x509(cert);
if (auto eid = x509.getEIDType(); eid != Certificate::Unknown) {
BuildLabelEID(ofs, eid, x509);
BuildLabelEID(ofs, eid, x509, parts);
} else {
BuildLabelCertificate(ofs, file_name, x509);
BuildLabelCertificate(ofs, x509, parts);
}
} else {
BuildLabelPublicKey(ofs, file_name);
buildLabel(ofs, CDoc2::Label::TYPE_PUBLIC_KEY, parts, {});
}
break;
case KEYSHARE:
break;
}
for (const auto& [key, value] : extra) {
if (!value.empty())
ofs << '&' << urlEncode(key) << '=' << urlEncode(value);
}
LOG_DBG("Generated label: {}", ofs.str());
return ofs.str();
}
Expand Down
27 changes: 17 additions & 10 deletions cdoc/Recipient.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <string>
#include <vector>
#include <map>
#include <cstdint>

namespace libcdoc {
Expand Down Expand Up @@ -108,16 +109,6 @@ struct CDOC_EXPORT Recipient {
*
*/
uint64_t expiry_ts = 0;
/**
* @brief key/certificate filename for machine-readable label
*
*/
std::string file_name;
/**
* @brief public key/password name for machine-readable label
*
*/
std::string key_name;

/**
* @brief test whether the Recipient structure is initialized
Expand Down Expand Up @@ -234,9 +225,25 @@ struct CDOC_EXPORT Recipient {
*/
std::string getLabel(const std::vector<std::pair<std::string_view, std::string_view>> &extra) const;

/**
* @brief Set a property for automatic label generation
*
* @param key the property name
* @param value the property value
*/
void setLabelValue(std::string_view key, std::string_view value) {
if (!value.empty()) {
lbl_parts[std::string(key)] = value;
} else {
lbl_parts.erase(std::string(key));
}
}

bool operator== (const Recipient& other) const = default;
protected:
Recipient(Type _type) : type(_type) {};
private:
std::map<std::string,std::string> lbl_parts;
};

} // namespace libcdoc
Expand Down
3 changes: 3 additions & 0 deletions libcdoc.i
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
%ignore libcdoc::FileListConsumer;
%ignore libcdoc::FileListSource;

// Ignore until there is straightfoward string_view translation
%ignore libcdoc::CDoc2;

%ignore libcdoc::CDocWriter::createWriter(int version, DataConsumer *dst, bool take_ownership, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network);
%ignore libcdoc::CDocWriter::createWriter(int version, std::ostream& ofs, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network);
%ignore libcdoc::CDocWriter::encrypt(MultiDataSource& src, const std::vector<libcdoc::Recipient>& recipients);
Expand Down
Loading