Skip to content
Open
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
1b76e52
Added CDocV1 tests
Jan 9, 2026
7a2b181
Added CDoc1 tests and cleaned up testing
Jan 9, 2026
2629756
More CDocCipher cleanups
Jan 13, 2026
4febb5c
Fix windows build
Jan 13, 2026
dd2cf68
Fix initializer order for gcc
Jan 13, 2026
5e4e80f
Use again absolute paths for tests
Jan 13, 2026
bb66be5
Create test tmp path if not exist
Jan 13, 2026
a4efe25
Change SID/MID callback signature to handle QR codes
Jan 14, 2026
0cab1cb
Apply suggestions from code review
lauris71 Jan 14, 2026
0da1fd8
Update cdoc/cdoc-tool.cpp
lauris71 Jan 14, 2026
75d1101
Update cdoc/cdoc-tool.cpp
lauris71 Jan 14, 2026
5b32d9f
Merge branch 'open-eid:master' into master
lauris71 Jan 14, 2026
87e5493
Merge branch 'master' into sid2
Jan 14, 2026
53a6898
Some fixes from ai security audit
May 20, 2026
47715fe
Fixed cdoc-tool index usage
May 22, 2026
fef2389
Update cdoc/cdoc-tool.cpp
lauris71 May 25, 2026
8848542
Update cdoc/cdoc-tool.cpp
lauris71 May 25, 2026
bf5ca62
Some more AI issue fixes
May 26, 2026
0a6b12b
Hardcode SSL timeout
May 27, 2026
a4dafb9
Fixed xstream uint overflow and tool logging
May 27, 2026
8c9b789
Some more fixes
May 27, 2026
e9a8a6e
Secure tool key handling, use explicid compile time definitions for k…
May 27, 2026
fa288ee
Fixed potential tar size overflow and secured proxy password
May 27, 2026
b89e4f1
Windows build fix
May 27, 2026
d0e0c90
Revert proxy password for now
May 27, 2026
87d1547
Make proxy password string_view
May 29, 2026
3631991
Disable potential Bleichenbacher attack for CDoc1 RSA encryption
Jun 1, 2026
7e6cdaa
Moved fix to main decryptRSA method
Jun 1, 2026
f01510a
Added ct.h
Jun 1, 2026
0aec4a1
Bleichenbacher fix for NCrypt backend
Jun 1, 2026
6f37761
Some cleanups
Jun 1, 2026
cc19133
All C,H & M fixes from Caludo Opus review
Jun 5, 2026
6bd12a8
Merge branch 'open-eid:master' into master
lauris71 Jun 5, 2026
8102224
Update cdoc-tool
Jun 5, 2026
c3d8dd2
Merge branch 'open-eid:master' into master
lauris71 Jun 11, 2026
bb9945c
Merge branch 'master' into ai-security
Jun 11, 2026
08ca9e5
Make default KDF iter 600000
Jun 11, 2026
004ce57
Added std_string_view.i
Jun 16, 2026
212825a
Fixed label parsing on Ubuntu 22
Jun 16, 2026
6db3372
Include <string.h>
Jun 17, 2026
8a2f494
Use explicit_bzero on glibc
Jun 17, 2026
573f147
Use SecureZeroMemory on windows
Jun 17, 2026
2d552cb
Use OPENSSL_cleanse for secure cleanup
Jun 17, 2026
f63ed77
Fixed inverted constant-time comparison
Jun 17, 2026
a6fc79a
Merge branch 'open-eid:master' into master
lauris71 Jun 17, 2026
88f1fa7
Merge commit 'a6fc79ad2e3c4d9d34157742f84db1c0c25faca3' into ai-security
Jun 17, 2026
578ff3a
Merge branch 'ai-security' into sid2
Jul 2, 2026
c0626a0
Update cdoc/CDocCipher.cpp
metsma Jul 2, 2026
eb091c3
Fix build for SIDMID
Jul 2, 2026
0e544fc
Fixed PKCS11 and NCrypt RSA handling and check all random() calls for…
Jul 2, 2026
3641679
Fix share encryption
Jul 3, 2026
3e62abe
Fixed PKCS11 public key loading
Jul 3, 2026
68cc522
Merge branch 'open-eid:master' into master
lauris71 Jul 3, 2026
32995f7
Merge branch 'master' into sid2
Jul 3, 2026
ed72221
fixes
Jul 15, 2026
5769447
Fixed label UTF-8 escaping if locale is not C
Jul 15, 2026
a7b7c6b
Merge branch 'open-eid:master' into master
lauris71 Jul 15, 2026
1225355
Fixed label generation for non-C locales
Jul 15, 2026
4ba85f1
Merge branch 'master' of github.com:lauris71/libcdoc
Jul 15, 2026
e5ac2a3
Merge branch 'open-eid:master' into master
lauris71 Jul 24, 2026
1df498c
Working authentication
Jul 24, 2026
463bfd5
Merge branch 'master' into ai-security
Jul 24, 2026
dc23ffa
Added SecureTarget class
Jul 24, 2026
139d1a7
Fixed N1 (out-of-bounds read) from 2026-07 report
Jul 27, 2026
e37902c
Added Utils.cpp to test build
Jul 27, 2026
e7ad099
Delete reader and writer in TestPasswordWithlabel
Jul 27, 2026
5743645
Clean up z_stream on zlib errors
Jul 27, 2026
6ae5ab9
Fixed N3 (base64 decode throws on errors) from 202607 report
Jul 27, 2026
90c72e6
Initial working SID decryption
Aug 4, 2026
31fb917
Preliminary configuration settings for MID
Aug 4, 2026
eaf6bff
Check that we have session disclosures for all share servers before c…
Aug 5, 2026
a63652e
Added CDoc2Reader.cpp changes
Aug 5, 2026
976cab5
Merge branch 'ai-security' into sid2
Aug 5, 2026
9b65423
More fixes to SID
Aug 5, 2026
adc94f4
Validate auth and rp server signatures
Aug 6, 2026
df0a4ed
Preliminary working MobileId authentication
Aug 7, 2026
b638e6d
Added MID signature and certificate validation
Aug 7, 2026
36545e6
Fixed keyshare KEK creatin, urlencode untrusted path components, log …
Aug 12, 2026
8492680
Verify shares recipient and vc code
Aug 12, 2026
9b01b40
Made SessionData public
Aug 14, 2026
08b5d44
Added tests for MID/SID (not automatic)
Aug 14, 2026
2481367
Reworking CDocTool.java
Aug 17, 2026
e2d7828
Minor fixes: removed AES-CBC, N4, N5
Aug 17, 2026
b47770c
fixed N7 (zstream max size), N8 (PBKDF limits), N9 (logging), N10 (th…
Aug 17, 2026
662da29
Added comment about N12 (OpenSSL fast-path timing), fixed N13 (decode…
Aug 17, 2026
311be5b
Fixed N17 (time parsing errors) and N18 (clean FMK in CDocCipher)
Aug 17, 2026
fb37985
Fixed N20 (handle exactly 100 byte tar filenames), N21 (treat PKCS11 …
Aug 18, 2026
0892d09
Minor logging cleanups
Aug 18, 2026
9743447
fixed libcoc::LOG...
Aug 18, 2026
11bfdad
Remove apostrofes from numberl literals
Aug 18, 2026
dce0136
Use swig workaround for new configuration keys
Aug 18, 2026
75bb399
Merge branch 'ai-security' into sid2
Aug 18, 2026
b4d4bd1
Added get() and post() virtual methods to NetworkBackend, plus SID/MI…
Aug 19, 2026
f7d15a9
Cleaned up (both C and Java) api
Aug 24, 2026
b30321a
Made SID/MID display text configurable
Aug 24, 2026
6193802
use core names for old openSSL
Aug 25, 2026
9cb19fe
Small fixes
Aug 25, 2026
fd03e1e
unittests now has SID/MID test with RIA dev servers (not run by default)
Aug 28, 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
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ jobs:
with:
name: ${{ matrix.target }}
path: ${{ env.DEST }}
sanitizers:
name: Run unit tests with ASan+UBSan
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install dependencies
run: sudo apt update -qq && sudo apt install --no-install-recommends -y ninja-build libboost-test-dev ${UBUNTU_DEPS}
- name: Configure
run: cmake --preset sanitize
- name: Build
run: cmake --build --preset sanitize --target unittests
- name: Test
run: ctest --test-dir build/sanitize --output-on-failure
windows:
name: Build on Windows
runs-on: ${{ matrix.image }}
Expand Down
21 changes: 20 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"rhs": "Darwin"
},
"cacheVariables": {
"CMAKE_OSX_ARCHITECTURES": "arm64;x86_64",
"CMAKE_OSX_ARCHITECTURES": "arm64",
"CMAKE_OSX_DEPLOYMENT_TARGET": "14.0",
"CMAKE_FIND_ROOT_PATH": "$env{DEST};/opt/homebrew",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
Expand Down Expand Up @@ -124,10 +124,29 @@
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "$env{PLATFORM}-windows-static-md"
}
},
{
"name": "sanitize",
"displayName": "Sanitizers (ASan+UBSan)",
"description": "Debug build with AddressSanitizer and UndefinedBehaviorSanitizer for running the unit tests (system dependencies, no vcpkg; requires boost-test, openssl, libxml2, zlib and flatbuffers development packages)",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_FLAGS": "-fsanitize=address,undefined -fno-omit-frame-pointer",
"CMAKE_EXE_LINKER_FLAGS": "-fsanitize=address,undefined",
"CMAKE_SHARED_LINKER_FLAGS": "-fsanitize=address,undefined",
"CMAKE_DISABLE_FIND_PACKAGE_SWIG": "YES",
"CMAKE_DISABLE_FIND_PACKAGE_Doxygen": "YES"
}
}
],
"buildPresets":
[
{
"name": "sanitize",
"configurePreset": "sanitize"
},
{
"name": "macos",
"configurePreset": "macos"
Expand Down
7 changes: 3 additions & 4 deletions cdoc/CDoc1Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,21 @@ CDoc1Reader::getFMK(std::vector<uint8_t>& fmk, unsigned int lock_idx)
// The downstream AES decrypt at the body level is what tells
// success from failure.
} else {
std::vector<uint8_t> key;
int result = crypto->deriveConcatKDF(key,
SecureTarget key;
int result = crypto->deriveConcatKDF(key.getTarget(),
lock.getBytes(Lock::Params::KEY_MATERIAL),
lock.getString(Lock::Params::CONCAT_DIGEST),
lock.getBytes(Lock::Params::ALGORITHM_ID),
lock.getBytes(Lock::Params::PARTY_UINFO),
lock.getBytes(Lock::Params::PARTY_VINFO),
lock_idx);
if (result < 0) {
libcdoc::cleanse(key);
setLastError(FAIL_MSG);
LOG_ERROR("{}", last_error);
return libcdoc::CRYPTO_ERROR;
}
fmk = libcdoc::Crypto::AESWrap(key, lock.encrypted_fmk, false);
libcdoc::cleanse(key);
key.cleanse();
// AESWrap returns {} on failure. Pad the candidate to expected
// length so the failure shape matches the RSA path; the bytes
// are arbitrary because the body decrypt is going to reject
Expand Down
191 changes: 128 additions & 63 deletions cdoc/CDoc2Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,15 @@
// exceptions). All early returns below previously had to remember to
// call libcdoc::cleanse(kek) - which several of them did not. With the
// guard the wipe is unconditional.
std::vector<uint8_t> kek;
libcdoc::Cleanser kek_guard(kek);
SecureTarget kek;

if (lock.type == Lock::Type::PASSWORD) {
// Password
LOG_DBG("password");
std::string info_str = libcdoc::CDoc2::getSaltForExpand(lock.label);
LOG_DBG("info: {}", toHex(info_str));
std::vector<uint8_t> kek_pm;
libcdoc::Cleanser kek_pm_guard(kek_pm);
if (auto rv = crypto->extractHKDF(kek_pm, lock.getBytes(Lock::SALT), lock.getBytes(Lock::PW_SALT), lock.getInt(Lock::KDF_ITER), lock_idx); rv != libcdoc::OK) {
SecureTarget kek_pm;
if (auto rv = crypto->extractHKDF(kek_pm.getTarget(), lock.getBytes(Lock::SALT), lock.getBytes(Lock::PW_SALT), lock.getInt(Lock::KDF_ITER), lock_idx); rv != libcdoc::OK) {
setLastError(crypto->getLastErrorStr(rv));
LOG_ERROR("{}", last_error);
return rv;
Expand All @@ -170,9 +168,8 @@
LOG_DBG("symmetric");
std::string info_str = libcdoc::CDoc2::getSaltForExpand(lock.label);
LOG_DBG("info: {}", toHex(info_str));
std::vector<uint8_t> kek_pm;
libcdoc::Cleanser kek_pm_guard(kek_pm);
if (auto rv = crypto->extractHKDF(kek_pm, lock.getBytes(Lock::SALT), {}, 0, lock_idx); rv != libcdoc::OK) {
SecureTarget kek_pm;
if (auto rv = crypto->extractHKDF(kek_pm.getTarget(), lock.getBytes(Lock::SALT), {}, 0, lock_idx); rv != libcdoc::OK) {
setLastError(crypto->getLastErrorStr(rv));
LOG_ERROR("{}", last_error);
return rv;
Expand All @@ -182,11 +179,10 @@
kek = libcdoc::Crypto::expand(kek_pm, info_str, 32);
} else if ((lock.type == Lock::Type::PUBLIC_KEY) || (lock.type == Lock::Type::SERVER)) {
// Public/private key
std::vector<uint8_t> key_material;
SecureTarget key_material;
// SERVER path fetches key_material over the network; PUBLIC_KEY
// takes it from the lock. Either way it gets fed into ECDH or RSA
// and is sensitive enough to wipe in-scope.
libcdoc::Cleanser key_material_guard(key_material);
if(lock.type == Lock::Type::SERVER) {
if(!conf) {
setLastError("Configuration is missing");
Expand All @@ -206,7 +202,7 @@
return libcdoc::CONFIGURATION_ERROR;
}
std::string transaction_id = lock.getString(Lock::Params::TRANSACTION_ID);
int result = network->fetchKey(key_material, fetch_url, transaction_id);
int result = network->fetchKey(key_material.getTarget(), fetch_url, transaction_id);
if (result < 0) {
setLastError(network->getLastErrorStr(result));
return result;
Expand All @@ -219,16 +215,15 @@
LOG_TRACE_KEY("Key material: {}", key_material);

if (lock.isRSA()) {
int result = crypto->decryptRSA(kek, key_material, true, lock_idx);
int result = crypto->decryptRSA(kek.getTarget(), key_material, true, lock_idx);
if (result < 0) {
setLastError(crypto->getLastErrorStr(result));
LOG_ERROR("{}", last_error);
return result;
}
} else {
std::vector<uint8_t> kek_pm;
libcdoc::Cleanser kek_pm_guard(kek_pm);
int result = crypto->deriveHMACExtract(kek_pm, key_material, toUint8Vector(libcdoc::CDoc2::KEKPREMASTER), lock_idx);
SecureTarget kek_pm;
int result = crypto->deriveHMACExtract(kek_pm.getTarget(), key_material, toUint8Vector(libcdoc::CDoc2::KEKPREMASTER), lock_idx);
if (result < 0) {
setLastError(crypto->getLastErrorStr(result));
LOG_ERROR("{}", last_error);
Expand All @@ -248,85 +243,156 @@
/* SHARE_URLS */
/* url,share_id;url,share_id... */
std::string all = lock.getString(Lock::SHARE_URLS);
std::vector<std::string> strs = split(all, ';');
if (strs.empty()){
std::vector<std::string> servers = split(all, ';');
if (servers.empty()){
setLastError("Lock does not contain server info");
LOG_ERROR("{}", last_error);
return libcdoc::DATA_FORMAT_ERROR;
}
std::vector<ShareData> shares;
for (auto& str : strs) {
std::vector<std::string> parts = split(str, ',');
for (auto& server : servers) {
std::vector<std::string> parts = split(server, ',');
if (parts.size() != 2) {
setLastError("Invalid server info in lock");
LOG_ERROR("{}", last_error);
return libcdoc::DATA_FORMAT_ERROR;
}
std::string url = parts[0];
std::string id = parts[1];
LOG_DBG("Share {} url {}", id, url);
LOG_DBG("Share {} url {}", parts[1], parts[0]);
shares.emplace_back(parts[0], parts[1]);
}

// Get authentication token
std::string auth_url = conf->getValue({}, Configuration::AUTH_SERVER);
if (auth_url.empty()) {
setLastError(FORMAT("No AUTH_SERVER found"));
LOG_ERROR("{}", last_error);
return libcdoc::CONFIGURATION_ERROR;
}
// auth_url = "https://cdoc2-auth.dev.riaint.ee";
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
// fixme:
std::string signer = conf->getValue(Configuration::SHARE_SIGNER);
LOG_DBG("Signer: {}", signer);
bool mid = false;
if (signer == Configuration::SHARE_SIGNER_SID) {
//
} else if (signer == Configuration::SHARE_SIGNER_MID) {
mid = true;
} else {
setLastError(t_("Unknown or missing signer type"));
LOG_ERROR("Unknown or missing signer type");
return libcdoc::CONFIGURATION_ERROR;
}
std::string phone;
if (mid) {
phone = conf->getValue({}, Configuration::PHONE_NUMBER);
if (phone.empty()) {
setLastError(t_("Missing phone number"));
LOG_ERROR("Missing phone number");
return libcdoc::CONFIGURATION_ERROR;
}
}

SessionData session;
if (auto rv = network->authenticateForShares(auth_url, rcpt_id, phone, session.token, session.cert); rv != OK) {
setLastError(network->getLastErrorStr(rv));
LOG_ERROR("{}", last_error);
return rv;
}

// S1: only contact share servers that the authentication server has
// authorized for this session. The session token carries one
// disclosure per authorized server; a container pointing to any other
// server would otherwise receive the session token and the user's
// credentials (SSRF / credential exfiltration). N-of-N reconstruction
// needs every share, so an unauthorized server rejects the container.
{
SessionToken stoken(session.token);
for (const auto& share : shares) {
if (!stoken.hasDisclosureForUrl(share.base_url)) {
setLastError(FORMAT("Share server {} is not authorized by the authentication session", share.base_url));
LOG_ERROR("{}", last_error);
return libcdoc::DATA_FORMAT_ERROR;
}
}
}

// S8: validate the authentication session client-side - the session
// certificate must belong to the lock recipient and the session token
// must not be expired. Also learns the schemeName/rpName claims needed
// to verify the signed ticket later.
std::string scheme_name, rp_name, v_err;
if (auto rv = validateSessionData(crypto, rcpt_id, mid, session.token, session.cert, scheme_name, rp_name, v_err); rv != OK) {
setLastError(v_err);
LOG_ERROR("{}", last_error);
return rv;
}

// Get nonces
for (auto& share : shares) {
std::vector<uint8_t> nonce;
result_t result = network->fetchNonce(nonce, url, id);
result_t result = network->fetchNonce(nonce, share.base_url, share.share_id, session.token, session.cert);
if (result != libcdoc::OK) {
setLastError(network->getLastErrorStr(result));
LOG_ERROR("Cannot fetch nonce from server {}", url);
LOG_ERROR("Cannot fetch nonce {} from server {}", share.share_id, share.base_url);
return result;
}
LOG_DBG("Nonce: {}", std::string(nonce.cbegin(), nonce.cend()));
ShareData acc(url, id, std::string(nonce.cbegin(), nonce.cend()));
shares.push_back(std::move(acc));
share.nonce = std::string(nonce.cbegin(), nonce.cend());
}

std::string rp_url = conf->getValue({}, Configuration::RP_SERVER);
if (rp_url.empty()) {
setLastError(FORMAT("No RP_SERVER found"));
LOG_ERROR("{}", last_error);
return libcdoc::CONFIGURATION_ERROR;
}
// rp_url = "https://cdoc2-rp.dev.riaint.ee/"
/* Create tickets from shares */
std::vector<std::string> tickets;
std::vector<uint8_t> cert;
std::vector<std::string> auth_tokens;
AuthenticationData auth;
result_t result = NOT_IMPLEMENTED;
std::string signer = conf->getValue(Configuration::SHARE_SIGNER);
LOG_DBG("Signer: {}", signer);
if (signer == "SMART_ID") {
// "https://sid.demo.sk.ee/smart-id-rp/v2"
std::string url = conf->getValue(Configuration::SID_DOMAIN, Configuration::BASE_URL);
// "00000000-0000-0000-0000-000000000000"
std::string relyingPartyUUID = conf->getValue(Configuration::SID_DOMAIN, Configuration::RP_UUID);
// "DEMO"
std::string relyingPartyName = conf->getValue(Configuration::SID_DOMAIN, Configuration::RP_NAME);
SIDSigner signer(url, relyingPartyUUID, relyingPartyName, rcpt_id, network);
result = signer.generateTickets(tickets, shares);

if (!mid) {
SIDSigner signer(rp_url, session, rcpt_id, network);
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
result = signer.generateTickets(auth_tokens, shares);
if (result != OK) {
setLastError(signer.error);
} else {
cert = std::move(signer.cert);
auth.cert = std::move(signer.cert);
auth.params = std::move(signer.params);
}
} else if (signer == "MOBILE_ID") {
// "https://sid.demo.sk.ee/smart-id-rp/v2"
std::string url = conf->getValue(Configuration::MID_DOMAIN, Configuration::BASE_URL);
// "00000000-0000-0000-0000-000000000000"
std::string relyingPartyUUID = conf->getValue(Configuration::MID_DOMAIN, Configuration::RP_UUID);
// "DEMO"
std::string relyingPartyName = conf->getValue(Configuration::MID_DOMAIN, Configuration::RP_NAME);
// "37200000566"
std::string phone = conf->getValue(Configuration::MID_DOMAIN, Configuration::PHONE_NUMBER);
MIDSigner signer(url, relyingPartyUUID, relyingPartyName, phone, rcpt_id, network);
result = signer.generateTickets(tickets, shares);
} else {
MIDSigner signer(rp_url, phone, session, rcpt_id, network);
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
result = signer.generateTickets(auth_tokens, shares);
if (result != OK) {
setLastError(signer.error);
} else {
cert = std::move(signer.cert);
auth.cert = std::move(signer.cert);
auth.params = std::move(signer.params);
}
} else {
setLastError(t_("Unknown or missing signer type"));
LOG_ERROR("Unknown or missing signer type");
return result;
}
if (result != libcdoc::OK) {
LOG_ERROR("Cannot generate share tickets");
return result;
}
kek.resize(32);
std::fill(kek.begin(), kek.end(), 0);
for (unsigned int i = 0; i < tickets.size(); i++) {
// S8: verify the signed auth ticket client-side before spending it -
// the signing certificate must belong to rcpt_id and the ACSP_V2
// signature must verify (binds identity, the consent text shown to
// the user, and freshness). All tickets share the same signed JWT,
// so validating the first one covers them all.
if (!auth_tokens.empty() && !mid) {
std::vector params = fromBase64URL(auth.params[network->X_CDOC2_SID_RPV3_SIGNATURE_PARAMETERS]);
if (auto rv = validateAuthTicket(crypto, rcpt_id, auth_tokens[0], auth.cert, std::string(params.cbegin(), params.cend()), scheme_name, rp_name, v_err); rv != OK) {
setLastError(v_err);
LOG_ERROR("{}", last_error);
return rv;
}
}
std::vector<uint8_t>& kek_build = kek.getTarget(32);
std::fill(kek_build.begin(), kek_build.end(), 0);
for (unsigned int i = 0; i < auth_tokens.size(); i++) {
NetworkBackend::ShareInfo share;
result = network->fetchShare(share, shares[i].base_url, shares[i].share_id, tickets[i], cert);
result = network->fetchShare(share, shares[i].base_url, shares[i].share_id, session.token, session.cert, auth_tokens[i], auth.cert, auth.params);
if (result != libcdoc::OK) {
setLastError(network->getLastErrorStr(result));
LOG_ERROR("Cannot fetch share {}", i);
Expand All @@ -336,7 +402,7 @@
// remaining shares it reconstructs the KEK. Wipe it after
// XOR-ing it into kek so it does not linger on the heap.
libcdoc::Cleanser share_guard(share.share);
if (auto err = libcdoc::Crypto::xor_data(kek, kek, share.share); err != libcdoc::OK) {
if (auto err = libcdoc::Crypto::xor_data(kek_build, kek_build, share.share); err != libcdoc::OK) {
setLastError("Failed to derive kek");
LOG_ERROR("Failed to derive kek");
return err;
Expand Down Expand Up @@ -365,8 +431,7 @@
fmk.clear();
return err;
}
std::vector<uint8_t> hhk = libcdoc::Crypto::expand(fmk, libcdoc::CDoc2::HMAC);
libcdoc::Cleanser hhk_guard(hhk);
SecureTarget hhk = libcdoc::Crypto::expand(fmk, libcdoc::CDoc2::HMAC);

LOG_TRACE_KEY("xor: {}", lock.encrypted_fmk);
LOG_TRACE_KEY("fmk: {}", fmk);
Expand Down
Loading
Loading