Skip to content

Commit 2cca87f

Browse files
authored
Force utf8 codepage to windows cdoc-tool (#115)
1 parent f28785c commit 2cca87f

17 files changed

Lines changed: 112 additions & 26 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if(POLICY CMP0167)
44
cmake_policy(SET CMP0167 NEW)
55
endif()
66

7-
project(libcdoc VERSION 0.1.8)
7+
project(libcdoc VERSION 0.5.0)
88

99
macro(SET_ENV NAME DEF)
1010
if(DEFINED ENV{${NAME}})

cdoc/CDoc.h

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ namespace libcdoc {
3131
*/
3232
using result_t = int64_t;
3333

34-
3534
/**
3635
* @brief The public key type
3736
*/
@@ -140,8 +139,19 @@ enum {
140139
UNSPECIFIED_ERROR = -199,
141140
};
142141

142+
/**
143+
* @brief Get the standard text description of error code
144+
*
145+
* @param code the error code
146+
* @return the text description
147+
*/
143148
CDOC_EXPORT std::string getErrorStr(int64_t code);
144149

150+
/**
151+
* @brief Get the library version
152+
*
153+
* @return The version string
154+
*/
145155
CDOC_EXPORT std::string getVersion();
146156

147157
// Logging interface
@@ -177,15 +187,33 @@ enum LogLevel : uint8_t
177187
LEVEL_DEBUG,
178188

179189
/**
180-
* @brief Most verbose level. Used for development, NOP in production code.
190+
* @brief The most verbose level. Present only in development builds, ignored in production code.
181191
*/
182192
LEVEL_TRACE
183193
};
184194

185195
class Logger;
186196

197+
/**
198+
* @brief Set the Logger object for library
199+
*
200+
* @param logger the Logger implementation
201+
*/
187202
CDOC_EXPORT void setLogger(Logger *logger);
203+
/**
204+
* @brief Set logging level
205+
*
206+
* @param level the requested logging level
207+
*/
188208
CDOC_EXPORT void setLogLevel(LogLevel level);
209+
/**
210+
* @brief Log a message to the library logging system
211+
*
212+
* @param level logging level
213+
* @param file the source file name
214+
* @param line the line in source file
215+
* @param msg the message
216+
*/
189217
CDOC_EXPORT void log(LogLevel level, std::string_view file, int line, std::string_view msg);
190218

191219
/**
@@ -198,10 +226,6 @@ struct FileInfo {
198226
int64_t size;
199227
};
200228

201-
#ifdef VERSION
202-
#undef VERSION
203-
#endif
204-
205229
namespace CDoc2 {
206230
namespace Label {
207231
/**

cdoc/CDoc1Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int64_t CDoc1Writer::Private::writeDocument(bool use_ddoc, const std::vector<Rec
104104
});
105105
}));
106106
return writeElement(DENC, "EncryptionProperties", [&] -> int64_t {
107-
RET_ERROR(writeTextElement(DENC, "EncryptionProperty", {{"Name", "LibraryVersion"}}, "cdoc|0.0.1"));
107+
RET_ERROR(writeTextElement(DENC, "EncryptionProperty", {{"Name", "LibraryVersion"}}, VERSION_STR));
108108
RET_ERROR(writeTextElement(DENC, "EncryptionProperty", {{"Name", "DocumentFormat"}}, documentFormat));
109109
RET_ERROR(writeTextElement(DENC, "EncryptionProperty", {{"Name", "Filename"}}, use_ddoc ? "tmp.ddoc" : files.at(0).name));
110110
for(const FileEntry &file: files)

cdoc/CDoc2Reader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ CDoc2Reader::getFMK(std::vector<uint8_t>& fmk, unsigned int lock_idx)
226226
LOG_DBG("info: {}", toHex(info_str));
227227
kek = libcdoc::Crypto::expand(kek_pm, info_str, libcdoc::CDoc2::KEY_LEN);
228228
}
229+
#ifdef HAS_KEYSHARES
229230
} else if (lock.type == Lock::Type::SHARE_SERVER) {
230231
/* SALT */
231232
std::vector<uint8_t> salt = lock.getBytes(Lock::SALT);
@@ -325,6 +326,7 @@ CDoc2Reader::getFMK(std::vector<uint8_t>& fmk, unsigned int lock_idx)
325326
}
326327
}
327328
LOG_INFO("Fetched all shares");
329+
#endif
328330
} else {
329331
setLastError(t_("Unknown lock type"));
330332
LOG_ERROR("Unknown lock type: %d", (int) lock.type);
@@ -576,6 +578,7 @@ CDoc2Reader::Private::buildLock(Lock& lock, const cdoc20::header::RecipientRecor
576578
lock.setInt(Lock::KDF_ITER, capsule->kdf_iterations());
577579
}
578580
return;
581+
#ifdef HAS_KEYSHARES
579582
case Capsule::recipients_KeySharesCapsule:
580583
if (const auto *capsule = recipient.capsule_as_recipients_KeySharesCapsule()) {
581584
if (capsule->recipient_type() != cdoc20::recipients::KeyShareRecipientType::SID_MID) {
@@ -607,6 +610,7 @@ CDoc2Reader::Private::buildLock(Lock& lock, const cdoc20::header::RecipientRecor
607610
lock.setString(Lock::RECIPIENT_ID, recipient_id);
608611
}
609612
return;
613+
#endif
610614
default:
611615
LOG_ERROR("Unsupported capsule type");
612616
}

cdoc/CDoc2Writer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ CDoc2Writer::buildHeader(std::vector<uint8_t>& header, const std::vector<libcdoc
305305
} else {
306306
fb_rcpts.push_back(createSymmetricKeyCapsule(builder, rcpt, salt, xor_key));
307307
}
308+
#ifdef HAS_KEYSHARES
308309
} else if (rcpt.isKeyShare()) {
309310
std::string url_list = conf->getValue(rcpt.server_id, libcdoc::Configuration::SHARE_SERVER_URLS);
310311
if (url_list.empty())
@@ -388,6 +389,7 @@ CDoc2Writer::buildHeader(std::vector<uint8_t>& header, const std::vector<libcdoc
388389
builder.CreateVector(xor_key),
389390
cdoc20::header::FMKEncryptionMethod::XOR);
390391
fb_rcpts.push_back(offset);
392+
#endif
391393
} else {
392394
FAIL("Invalid recipient type", libcdoc::UNSPECIFIED_ERROR);
393395
}

cdoc/CDocCipher.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,11 @@ fill_recipients_from_rcpt_info(ToolConf& conf, ToolCrypto& crypto, std::vector<l
321321
key = libcdoc::Recipient::makeSymmetric(label, 65535);
322322
if (conf.gen_label)
323323
key.setLabelValue(CDoc2::Label::LABEL, rcpt.label);
324+
#ifdef HAS_KEYSHARES
324325
} else if (rcpt.type == RcptInfo::Type::SHARE) {
325326
LOG_DBG("Creating keyshare recipient:");
326327
key = libcdoc::Recipient::makeShare(label, conf.servers[0].ID, "PNOEE-" + rcpt.id);
328+
#endif
327329
}
328330

329331
rcpts.push_back(std::move(key));

cdoc/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ set(PUBLIC_HEADERS
2121
add_library(cdoc_ver INTERFACE)
2222
target_compile_definitions(cdoc_ver INTERFACE
2323
VERSION_STR="${VERSION}"
24-
$<$<PLATFORM_ID:Windows>:VERSION=${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},${BUILD_NUMBER}>
24+
$<$<PLATFORM_ID:Windows>:VERSION_NUMBER=${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},${BUILD_NUMBER}>
2525
$<$<PLATFORM_ID:Windows>:TARGET_NAME="$<TARGET_PROPERTY:NAME>">
2626
$<$<PLATFORM_ID:Windows>:$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:APP>>
2727
)
@@ -50,7 +50,7 @@ add_library(cdoc
5050
CDoc2Writer.cpp CDoc2Writer.h
5151
DDocReader.cpp DDocReader.h
5252
DDocWriter.cpp DDocWriter.h
53-
KeyShares.cpp KeyShares.h
53+
# KeyShares.cpp KeyShares.h
5454
XmlReader.cpp XmlReader.h
5555
XmlWriter.cpp XmlWriter.h
5656
RcptInfo.h
@@ -93,6 +93,9 @@ if(BUILD_TOOLS)
9393
add_executable(cdoc-tool cdoc-tool.cpp)
9494
target_include_directories(cdoc-tool PRIVATE ${OPENSSL_INCLUDE_DIR})
9595
target_link_libraries(cdoc-tool cdoc_ver cdoc)
96+
target_link_options(cdoc-tool PRIVATE
97+
$<$<PLATFORM_ID:Windows>: /MANIFEST:NO /MANIFEST:EMBED /MANIFESTINPUT:${CMAKE_CURRENT_SOURCE_DIR}/cdoc-tool.manifest>
98+
)
9699
set_target_properties(cdoc-tool PROPERTIES
97100
INSTALL_RPATH $<$<PLATFORM_ID:Darwin>:@executable_path/../lib>
98101
)

cdoc/Configuration.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct CDOC_EXPORT Configuration {
4242
* @brief Fetch URL of keyserver (Domain is server id)
4343
*/
4444
static constexpr char const *KEYSERVER_FETCH_URL = "KEYSERVER_FETCH_URL";
45+
#ifdef HAS_KEYSHARES
4546
/**
4647
* @brief JSON array of share server base urls (Domain is server id)
4748
*/
@@ -74,6 +75,7 @@ struct CDOC_EXPORT Configuration {
7475
* @brief Mobile ID phone number (domain is MOBILE_ID)
7576
*/
7677
static constexpr char const *PHONE_NUMBER = "PHONE_NUMBER";
78+
#endif
7779

7880
Configuration() = default;
7981
virtual ~Configuration() noexcept = default;
@@ -92,20 +94,20 @@ struct CDOC_EXPORT Configuration {
9294
virtual std::string getValue(std::string_view domain, std::string_view param) const {return {};}
9395

9496
/**
95-
* @brief get a value of configuration parameter from default domain
97+
* @brief get a value of configuration parameter from the default domain
9698
* @param param the parameter name.
9799
* @return a string value or empty string if parameter is not defined.
98100
*/
99101
std::string getValue(std::string_view param) const {return getValue({}, param);}
100102
/**
101-
* @brief get boolean value of configuration parameter from default domain
103+
* @brief get boolean value of configuration parameter from the default domain
102104
* @param param the parameter name
103105
* @param def_val the default value to return if parameter is not set
104106
* @return the parameter value
105107
*/
106108
bool getBoolean(std::string_view param, bool def_val = false) const;
107109
/**
108-
* @brief get integer value of configuration parameter from default domain
110+
* @brief get integer value of configuration parameter from the default domain
109111
* @param param the parameter name
110112
* @param def_val the default value to return if parameter is not set
111113
* @return the key value
@@ -117,7 +119,7 @@ struct CDOC_EXPORT Configuration {
117119
* @brief A Configuration object implementation that reads values from JSON file
118120
*
119121
* The file should represent a single object with key/value pairs
120-
* Domain should contain sub-objects with corresponding key/value pairs
122+
* Domains are sub-objects with corresponding key/value pairs
121123
* Strings are returned unquoted, everything else is returned as JSON
122124
*
123125
*/

cdoc/Lock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ struct CDOC_EXPORT Lock
6868
* @brief Public key stored on keyserver
6969
*/
7070
SERVER,
71+
#ifdef HAS_KEYSHARES
7172
/**
7273
* @brief Symmetric key distributed on several servers
7374
*/
7475
SHARE_SERVER
76+
#endif
7577
};
7678

7779
/**
@@ -114,10 +116,12 @@ struct CDOC_EXPORT Lock
114116
* @brief Keyshare recipient ID
115117
*/
116118
RECIPIENT_ID,
119+
#ifdef HAS_KEYSHARES
117120
/**
118121
* @brief Keyshare server urls (separated by ';')
119122
*/
120123
SHARE_URLS,
124+
#endif
121125
/**
122126
* @brief CDoc1 specific
123127
*/

cdoc/NetworkBackend.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct Private {
9292
}
9393
};
9494

95+
#ifdef HAS_KEYSHARES
9596
struct MIDSIDResultData {
9697
int code;
9798
std::string_view str;
@@ -135,6 +136,7 @@ getMIDSIDDescription(libcdoc::result_t code)
135136
}
136137
return {};
137138
}
139+
#endif
138140

139141
thread_local std::string error;
140142

@@ -150,9 +152,11 @@ libcdoc::NetworkBackend::getLastErrorStr(result_t code) const
150152
default:
151153
break;
152154
}
155+
#ifdef HAS_KEYSHARES
153156
std::string_view str = getMIDSIDDescription(code);
154157
if (!str.empty()) return std::string(str);
155-
return libcdoc::getErrorStr(code);
158+
#endif
159+
return libcdoc::getErrorStr(code);
156160
}
157161

158162
//
@@ -312,6 +316,7 @@ libcdoc::NetworkBackend::sendKey (CapsuleInfo& dst, const std::string& url, cons
312316
return OK;
313317
}
314318

319+
#ifdef HAS_KEYSHARES
315320
libcdoc::result_t
316321
libcdoc::NetworkBackend::sendShare(std::vector<uint8_t>& dst, const std::string& url, const std::string& recipient, const std::vector<uint8_t>& share)
317322
{
@@ -354,6 +359,7 @@ libcdoc::NetworkBackend::sendShare(std::vector<uint8_t>& dst, const std::string&
354359

355360
return OK;
356361
}
362+
#endif
357363

358364
libcdoc::result_t
359365
libcdoc::NetworkBackend::fetchKey (std::vector<uint8_t>& dst, const std::string& url, const std::string& transaction_id)
@@ -392,6 +398,7 @@ libcdoc::NetworkBackend::fetchKey (std::vector<uint8_t>& dst, const std::string&
392398
return libcdoc::OK;
393399
}
394400

401+
#ifdef HAS_KEYSHARES
395402
libcdoc::result_t
396403
libcdoc::NetworkBackend::fetchNonce(std::vector<uint8_t>& dst, const std::string& url, const std::string& share_id)
397404
{
@@ -475,6 +482,7 @@ libcdoc::NetworkBackend::fetchShare(ShareInfo& share, const std::string& url, co
475482
share = {std::move(shareval), std::move(recipient)};
476483
return OK;
477484
}
485+
#endif
478486

479487
ECDSA_SIG *
480488
ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM * /*inv*/, const BIGNUM * /*rp*/, EC_KEY *eckey)
@@ -527,6 +535,7 @@ rsa_sign(int type, const unsigned char *m, unsigned int m_len, unsigned char *si
527535
return 1;
528536
}
529537

538+
#ifdef HAS_KEYSHARES
530539
libcdoc::result_t
531540
libcdoc::NetworkBackend::showVerificationCode(unsigned int code)
532541
{
@@ -879,3 +888,4 @@ libcdoc::NetworkBackend::signMID(std::vector<uint8_t>& dst, std::vector<uint8_t>
879888

880889
return OK;
881890
}
891+
#endif

0 commit comments

Comments
 (0)