virgil-crypto 2.0.2b2 → 2.0.6r1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -1
- data/Gemfile +3 -0
- data/Rakefile +5 -4
- data/bin/console +1 -0
- data/ext/native/src/CMakeLists.txt +55 -3
- data/ext/native/src/ChangeLog +30 -0
- data/ext/native/src/VERSION +1 -1
- data/ext/native/src/lib/include/virgil/crypto/VirgilCryptoException.h +7 -0
- data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilPBKDF.h +1 -1
- data/ext/native/src/lib/src/VirgilAsn1Writer.cxx +4 -4
- data/ext/native/src/lib/src/VirgilCryptoException.cxx +4 -0
- data/ext/native/src/lib/src/stream/VirgilStreamDataSource.cxx +1 -1
- data/ext/native/src/libs_ext/mbedtls/mbedtls.cmake +2 -2
- data/ext/native/src/tests/test_asn1_writer.cxx +6 -70
- data/ext/native/src/tests/test_cipher.cxx +20 -0
- data/ext/native/src/tests/test_stream_data_source.cxx +58 -0
- data/ext/native/src/utils/build.sh +8 -3
- data/ext/native/src/wrappers/go/CMakeLists.txt +92 -0
- data/ext/native/src/wrappers/net/CMakeLists.txt +1 -1
- data/ext/native/src/wrappers/net/src/VirgilStreamDataSink.cs +1 -3
- data/ext/native/src/wrappers/net/src/VirgilStreamDataSource.cs +1 -3
- data/ext/native/src/wrappers/ruby/CMakeLists.txt +4 -6
- data/ext/native/src/wrappers/swig/common.i +7 -0
- data/ext/native/src/wrappers/swig/go/common.i.in +66 -0
- data/ext/native/src/wrappers/swig/util.i +1 -0
- data/ext/rakefile.rb +65 -0
- data/lib/virgil/crypto.rb +2 -2
- data/lib/virgil/crypto/bytes.rb +4 -0
- data/lib/virgil/crypto/version.rb +1 -1
- data/lib/virgil/crypto/virgil_stream_data_sink.rb +4 -3
- data/lib/virgil/crypto/virgil_stream_data_source.rb +4 -3
- data/lib/virgil/native_crypto.rb +100 -0
- data/lib/virgil/os.rb +17 -0
- data/virgil-crypto.gemspec +12 -6
- metadata +20 -13
- data/ext/native/extconf.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 061bfd4a2b1cf1a2eb066d41304ba70f2ddab57a
|
4
|
+
data.tar.gz: 11b8b78fb1270dfad90dd2fc450fe2916aa4362c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1612f74573fe63d3b097a8181844beed801720e580f96c35a1fe1fcbf4f1bc1d60a3510eaa3b367cd44ce0883edb6a2fc3658d4a2ab8d5f4bf0e91b0f20f9f5c
|
7
|
+
data.tar.gz: 66c023d4b2007ba70e820791365569bba4ce3af5bc0ccf1fc7ed35c58048d47753c98eaf5916ce03b38fa7bae3fdd06d22ec45c02f32575b0adb7d53cb9198b8
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require 'rake/extensiontask'
|
3
3
|
require 'rake/testtask'
|
4
|
-
|
5
|
-
Rake::ExtensionTask.new('native')
|
4
|
+
require 'mkmf'
|
6
5
|
|
7
6
|
Rake::TestTask.new do |t|
|
8
|
-
|
9
|
-
|
7
|
+
t.libs << 'test'
|
8
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
9
|
end
|
11
10
|
|
12
11
|
task :default => :test
|
12
|
+
|
13
|
+
|
data/bin/console
CHANGED
@@ -41,10 +41,12 @@
|
|
41
41
|
# - PLATFORM - name of target platform (optional).
|
42
42
|
# - PLATFORM_VERSION - minimum supported version of the target platform (optional).
|
43
43
|
# - PLATFORM_ARCH - target platform processor architecture (optional).
|
44
|
+
# - ADD_COMPILER_INFO - define whether to add compiler info to the library full name (optional).
|
44
45
|
#
|
45
46
|
# - LIB_LOW_LEVEL_API - boolean value that defines whether to include low-level API or not.
|
46
47
|
# - LIB_FILE_IO - boolean value that defines whether to include module depends on file IO or not.
|
47
48
|
# or separate utilities.
|
49
|
+
# - LIB_STATIC_RUNTIME - сauses library to use the static version of the run-time library.
|
48
50
|
# - INSTALL_CORE_LIBS - boolean value that defines whether install core library and it's dependencies or not,
|
49
51
|
# if this value is NO or undefined - only wrapped library will be installed.
|
50
52
|
# - INSTALL_EXT_HEADERS - boolean value that defines whether install third-party library headers or not.
|
@@ -95,9 +97,9 @@ project (VirgilSecurity)
|
|
95
97
|
|
96
98
|
# Set library version
|
97
99
|
set (VIRGIL_VERSION_MAJOR 2)
|
98
|
-
set (VIRGIL_VERSION_MINOR
|
99
|
-
set (VIRGIL_VERSION_PATCH
|
100
|
-
set (VIRGIL_VERSION_FEATURE)
|
100
|
+
set (VIRGIL_VERSION_MINOR 1)
|
101
|
+
set (VIRGIL_VERSION_PATCH 0)
|
102
|
+
set (VIRGIL_VERSION_FEATURE dev)
|
101
103
|
set (VIRGIL_VERSION ${VIRGIL_VERSION_MAJOR}.${VIRGIL_VERSION_MINOR}.${VIRGIL_VERSION_PATCH})
|
102
104
|
set (VIRGIL_SOVERSION 2)
|
103
105
|
|
@@ -116,6 +118,34 @@ set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
|
116
118
|
# Build shared library if defined
|
117
119
|
set (BUILD_SHARED_LIBS OFF CACHE BOOL "Force to create shared libraries")
|
118
120
|
|
121
|
+
# Configure redefine compiler options if requested
|
122
|
+
if (NOT CMAKE_CROSSCOMPILING AND WIN32 AND NOT CYGWIN)
|
123
|
+
set (LIB_STATIC_RUNTIME ON CACHE BOOL "Causes library to use the static version of the run-time library.")
|
124
|
+
else ()
|
125
|
+
set (LIB_STATIC_RUNTIME OFF CACHE BOOL "Causes library to use the static version of the run-time library.")
|
126
|
+
endif ()
|
127
|
+
|
128
|
+
# Configure additional parameters for library full name
|
129
|
+
set (ADD_COMPILER_INFO OFF CACHE BOOL "Define whether to add compiler info to the library full name")
|
130
|
+
|
131
|
+
# Define COMPILER
|
132
|
+
string (TOLOWER "${CMAKE_CXX_COMPILER_ID}" COMPILER_ID)
|
133
|
+
if (COMPILER_ID STREQUAL "gnu")
|
134
|
+
set (COMPILER "gcc")
|
135
|
+
else ()
|
136
|
+
set (COMPILER "${COMPILER_ID}")
|
137
|
+
endif ()
|
138
|
+
set (COMPILER_ID)
|
139
|
+
|
140
|
+
# Define COMPILER_VERSION
|
141
|
+
if (CMAKE_CXX_COMPILER_VERSION)
|
142
|
+
string (
|
143
|
+
REGEX REPLACE
|
144
|
+
"([0-9]+)([.][0-9]+)?([.][0-9]+)?([.][0-9]+)?" "\\1\\2"
|
145
|
+
COMPILER_VERSION "${CMAKE_CXX_COMPILER_VERSION}"
|
146
|
+
)
|
147
|
+
endif ()
|
148
|
+
|
119
149
|
# Add find_host_* utilities
|
120
150
|
include (find_host_utils)
|
121
151
|
|
@@ -152,6 +182,20 @@ if (NOT CMAKE_CROSSCOMPILING)
|
|
152
182
|
endif ()
|
153
183
|
endif (NOT CMAKE_CROSSCOMPILING)
|
154
184
|
|
185
|
+
if (LIB_STATIC_RUNTIME)
|
186
|
+
foreach (compile_flags
|
187
|
+
CMAKE_C_FLAGS
|
188
|
+
CMAKE_C_FLAGS_DEBUG
|
189
|
+
CMAKE_C_FLAGS_RELEASE
|
190
|
+
CMAKE_CXX_FLAGS
|
191
|
+
CMAKE_CXX_FLAGS_DEBUG
|
192
|
+
CMAKE_CXX_FLAGS_RELEASE
|
193
|
+
)
|
194
|
+
string (REPLACE "/MD" "/MT" ${compile_flags} "${${compile_flags}}")
|
195
|
+
string (REPLACE "/MDd" "/MTd" ${compile_flags} "${${compile_flags}}")
|
196
|
+
endforeach ()
|
197
|
+
endif (LIB_STATIC_RUNTIME)
|
198
|
+
|
155
199
|
# Define optimization features
|
156
200
|
set (ED25519_AMD64_OPTIMIZATION ON CACHE BOOL "Defines whether to enable AMD64 optimization for Ed25519 algorithms")
|
157
201
|
|
@@ -318,6 +362,14 @@ if (PLATFORM_ARCH)
|
|
318
362
|
set (LIB_NAME_FULL "${LIB_NAME_FULL}-${PLATFORM_ARCH}")
|
319
363
|
endif (PLATFORM_ARCH)
|
320
364
|
|
365
|
+
if (ADD_COMPILER_INFO)
|
366
|
+
if (COMPILER AND COMPILER_VERSION)
|
367
|
+
set (LIB_NAME_FULL "${LIB_NAME_FULL}-${COMPILER}-${COMPILER_VERSION}")
|
368
|
+
else ()
|
369
|
+
message (FATAL_ERROR "ADD_COMPILER_INFO defined, but can not deduce compiler version.")
|
370
|
+
endif ()
|
371
|
+
endif ()
|
372
|
+
|
321
373
|
message (STATUS "Library full name: ${LIB_NAME_FULL}")
|
322
374
|
|
323
375
|
file (WRITE "${CMAKE_CURRENT_BINARY_DIR}/lib_name_full.txt" "${LIB_NAME_FULL}")
|
data/ext/native/src/ChangeLog
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
virgil ChangeLog (Sorted per date)
|
2
2
|
|
3
|
+
= Version 2.0.4 released 2017-01-10
|
4
|
+
|
5
|
+
## Bugfix
|
6
|
+
|
7
|
+
* [GO] Fix: VirgilByteArray is missed in Golang wrapper
|
8
|
+
* [Lib] Fix: Got exception when encrypt data in 32 bit architecture
|
9
|
+
* [PHP] Fix: Some constants are missed in the PHP wrapper
|
10
|
+
|
11
|
+
## Changes
|
12
|
+
|
13
|
+
* [Lib] Add getter VirgilCryptoException::condition()
|
14
|
+
* [Build] Add compiler version to the built archive name (optional)
|
15
|
+
|
16
|
+
= Version 2.0.3 released 2016-12-08
|
17
|
+
|
18
|
+
## Bugfix
|
19
|
+
|
20
|
+
* [.NET] Fix namespaces in the .NET wrapper's addons
|
21
|
+
* [Lib] Fix VirgilStreamDataSource::hasData() infinite if closed file stream is given
|
22
|
+
|
23
|
+
## Changes
|
24
|
+
|
25
|
+
* [Build] Use static linkage to windows runtime libraries for wrappers
|
26
|
+
* [Lib] Remove restriction for ASN.1 length
|
27
|
+
* [Lib] Update mbed TLS dependency to version 2.4.0
|
28
|
+
|
29
|
+
## Features
|
30
|
+
|
31
|
+
* [GO] Add Go to the wrappers
|
32
|
+
|
3
33
|
= Version 2.0.2 released 2016-11-02
|
4
34
|
|
5
35
|
## Bugfix
|
data/ext/native/src/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0
|
1
|
+
2.1.0-dev
|
@@ -76,6 +76,13 @@ public:
|
|
76
76
|
*/
|
77
77
|
VirgilCryptoException(int ev, const std::error_category& ecat, const char* what);
|
78
78
|
|
79
|
+
/**
|
80
|
+
* Get underlying error condition.
|
81
|
+
*
|
82
|
+
* @return Error condition.
|
83
|
+
*/
|
84
|
+
const std::error_condition& condition() const;
|
85
|
+
|
79
86
|
/**
|
80
87
|
* Get string identifying exception.
|
81
88
|
*
|
@@ -55,7 +55,7 @@ public:
|
|
55
55
|
* @property kIterationCount_Default
|
56
56
|
* @brief Default iteration count.
|
57
57
|
*/
|
58
|
-
static
|
58
|
+
static constexpr unsigned int kIterationCount_Default = 2048;
|
59
59
|
public:
|
60
60
|
/**
|
61
61
|
* @brief Defines specific password based key derivation function algorithm
|
@@ -57,7 +57,7 @@ static const size_t kAsn1LengthValueSize = 3;
|
|
57
57
|
static const size_t kAsn1IntegerValueSize = kAsn1TagValueSize + kAsn1LengthValueSize + 8;
|
58
58
|
static const size_t kAsn1BoolValueSize = 3;
|
59
59
|
static const size_t kAsn1NullValueSize = kAsn1TagValueSize + 1;
|
60
|
-
static const size_t kAsn1SizeMax =
|
60
|
+
static const size_t kAsn1SizeMax = 0xFFFFFFFF; // According to MbedTLS restriction on TAG: LENGTH
|
61
61
|
static const size_t kAsn1ContextTagMax = 0x1E;
|
62
62
|
|
63
63
|
#define RETURN_POINTER_DIFF_AFTER_INVOCATION(pointer, invocation) \
|
@@ -307,9 +307,9 @@ void VirgilAsn1Writer::ensureBufferEnough(size_t len) {
|
|
307
307
|
if (len > unusedSpace) {
|
308
308
|
const size_t usedSpace = bufLen_ - unusedSpace;
|
309
309
|
const size_t requiredLenMin = len + usedSpace;
|
310
|
-
|
311
|
-
|
312
|
-
|
310
|
+
if (requiredLenMin > kAsn1SizeMax) {
|
311
|
+
throw make_error(VirgilCryptoError::ExceededMaxSize, "ASN.1 structure size limit was exceeded.");
|
312
|
+
}
|
313
313
|
const size_t requiredLenMax =
|
314
314
|
(size_t) 1 << (size_t) (std::ceil(std::log((double) requiredLenMin) / std::log(2.0)));
|
315
315
|
const size_t adjustedLen = requiredLenMax > kAsn1SizeMax ? kAsn1SizeMax : requiredLenMax;
|
@@ -72,6 +72,10 @@ const char* VirgilCryptoException::what() const noexcept {
|
|
72
72
|
return what_.c_str();
|
73
73
|
}
|
74
74
|
|
75
|
+
const std::error_condition& VirgilCryptoException::condition() const {
|
76
|
+
return condition_;
|
77
|
+
}
|
78
|
+
|
75
79
|
std::string virgil::crypto::backtrace_exception(const std::exception& exception, size_t level) {
|
76
80
|
std::ostringstream sstr;
|
77
81
|
sstr << std::string(4 * level, ' ') << exception.what();
|
@@ -89,8 +89,8 @@ endif ()
|
|
89
89
|
|
90
90
|
ExternalProject_Add (${PROJECT_NAME}
|
91
91
|
DOWNLOAD_DIR "@VIRGIL_DEPENDS_PACKAGE_DOWNLOAD_DIR@"
|
92
|
-
URL "https://github.com/VirgilSecurity/mbedtls/archive/mbedtls-2.
|
93
|
-
URL_HASH SHA1=
|
92
|
+
URL "https://github.com/VirgilSecurity/mbedtls/archive/mbedtls-2.4.0-virgil-2.0.1.tar.gz"
|
93
|
+
URL_HASH SHA1=8fe17bd30e644cefffdb2811c51c0e603e00e09b
|
94
94
|
PREFIX "@VIRGIL_DEPENDS_PACKAGE_BUILD_DIR@"
|
95
95
|
CMAKE_ARGS "@VIRGIL_DEPENDS_CMAKE_ARGS@" "${MBEDTLS_CMAKE_ARGS}"
|
96
96
|
UPDATE_COMMAND ${CMAKE_COMMAND} -E copy_directory
|
@@ -51,8 +51,8 @@ using virgil::crypto::VirgilByteArrayUtils;
|
|
51
51
|
using virgil::crypto::VirgilCryptoException;
|
52
52
|
using virgil::crypto::foundation::asn1::VirgilAsn1Writer;
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
constexpr size_t kAsn1SizeMax = 10 * 1024 * 1024; // 10MB, really not maximum but good enough
|
55
|
+
constexpr size_t kAsn1LengthMax = kAsn1SizeMax - 2 /* minus 2 tags size */;
|
56
56
|
|
57
57
|
TEST_CASE("ASN.1 write: use small buffer", "[asn1-writer]") {
|
58
58
|
VirgilAsn1Writer asn1Writer(1);
|
@@ -97,7 +97,7 @@ TEST_CASE("ASN.1 write: use small buffer", "[asn1-writer]") {
|
|
97
97
|
|
98
98
|
SECTION ("with max octet string") {
|
99
99
|
VirgilByteArray octetString = VirgilByteArray(kAsn1LengthMax, 0xAB);
|
100
|
-
VirgilByteArray asn1Expected = VirgilByteArrayUtils::hexToBytes("
|
100
|
+
VirgilByteArray asn1Expected = VirgilByteArrayUtils::hexToBytes("04839ffffe");
|
101
101
|
asn1Expected.insert(asn1Expected.end(), octetString.begin(), octetString.end());
|
102
102
|
asn1Writer.writeOctetString(octetString);
|
103
103
|
VirgilByteArray asn1 = asn1Writer.finish();
|
@@ -112,18 +112,13 @@ TEST_CASE("ASN.1 write: use small buffer", "[asn1-writer]") {
|
|
112
112
|
|
113
113
|
SECTION ("with max UTF8 string") {
|
114
114
|
VirgilByteArray utf8String = VirgilByteArray(kAsn1LengthMax, 0x41);
|
115
|
-
VirgilByteArray asn1Expected = VirgilByteArrayUtils::hexToBytes("
|
115
|
+
VirgilByteArray asn1Expected = VirgilByteArrayUtils::hexToBytes("0c839ffffe");
|
116
116
|
asn1Expected.insert(asn1Expected.end(), utf8String.begin(), utf8String.end());
|
117
117
|
asn1Writer.writeUTF8String(utf8String);
|
118
118
|
VirgilByteArray asn1 = asn1Writer.finish();
|
119
119
|
REQUIRE(VirgilByteArrayUtils::bytesToHex(asn1) == VirgilByteArrayUtils::bytesToHex(asn1Expected));
|
120
120
|
}
|
121
121
|
|
122
|
-
SECTION ("with oversized UTF8 string") {
|
123
|
-
VirgilByteArray utf8String = VirgilByteArray(kAsn1SizeMax + 1, 0x41);
|
124
|
-
REQUIRE_THROWS(asn1Writer.writeUTF8String(utf8String));
|
125
|
-
}
|
126
|
-
|
127
122
|
SECTION ("with context tag over UTF8 string") {
|
128
123
|
size_t len = asn1Writer.writeUTF8String(VirgilByteArrayUtils::hexToBytes("4142434445464748494a4b4c4d4e4f"));
|
129
124
|
asn1Writer.writeContextTag(1, len);
|
@@ -142,11 +137,6 @@ TEST_CASE("ASN.1 write: use small buffer", "[asn1-writer]") {
|
|
142
137
|
REQUIRE(VirgilByteArrayUtils::bytesToHex(asn1) == VirgilByteArrayUtils::bytesToHex(data));
|
143
138
|
}
|
144
139
|
|
145
|
-
SECTION ("with oversized RAW buffer") {
|
146
|
-
VirgilByteArray data = VirgilByteArray(kAsn1SizeMax + 1, 0x41);
|
147
|
-
REQUIRE_THROWS(asn1Writer.writeData(data));
|
148
|
-
}
|
149
|
-
|
150
140
|
SECTION ("with OID") {
|
151
141
|
std::string oid =
|
152
142
|
VirgilByteArrayUtils::bytesToString(VirgilByteArrayUtils::hexToBytes("4142434445464748494a4b4c4d4e4f"));
|
@@ -157,18 +147,13 @@ TEST_CASE("ASN.1 write: use small buffer", "[asn1-writer]") {
|
|
157
147
|
|
158
148
|
SECTION ("with max OID") {
|
159
149
|
std::string oid = VirgilByteArrayUtils::bytesToString(VirgilByteArray(kAsn1LengthMax, 0x41));
|
160
|
-
VirgilByteArray asn1Expected = VirgilByteArrayUtils::hexToBytes("
|
150
|
+
VirgilByteArray asn1Expected = VirgilByteArrayUtils::hexToBytes("06839ffffe");
|
161
151
|
asn1Expected.insert(asn1Expected.end(), oid.begin(), oid.end());
|
162
152
|
asn1Writer.writeOID(oid);
|
163
153
|
VirgilByteArray asn1 = asn1Writer.finish();
|
164
154
|
REQUIRE(VirgilByteArrayUtils::bytesToHex(asn1) == VirgilByteArrayUtils::bytesToHex(asn1Expected));
|
165
155
|
}
|
166
156
|
|
167
|
-
SECTION ("with oversized OID") {
|
168
|
-
std::string oid = VirgilByteArrayUtils::bytesToString(VirgilByteArray(kAsn1SizeMax + 1, 0x41));
|
169
|
-
REQUIRE_THROWS(asn1Writer.writeOID(oid));
|
170
|
-
}
|
171
|
-
|
172
157
|
SECTION ("with sequence over UTF8 string") {
|
173
158
|
size_t len = asn1Writer.writeUTF8String(VirgilByteArrayUtils::hexToBytes("4142434445464748494a4b4c4d4e4f"));
|
174
159
|
asn1Writer.writeSequence(len);
|
@@ -200,7 +185,7 @@ TEST_CASE("ASN.1 write: use small buffer", "[asn1-writer]") {
|
|
200
185
|
utf8String.insert(utf8String.end(), utf8StringHead.begin(), utf8StringHead.end());
|
201
186
|
utf8String.insert(utf8String.end(), utf8StringBody.begin(), utf8StringBody.end());
|
202
187
|
|
203
|
-
VirgilByteArray asn1Expected = VirgilByteArrayUtils::hexToBytes("
|
188
|
+
VirgilByteArray asn1Expected = VirgilByteArrayUtils::hexToBytes("31839ffffe");
|
204
189
|
asn1Expected.insert(asn1Expected.end(), utf8String.begin(), utf8String.end());
|
205
190
|
|
206
191
|
std::vector<VirgilByteArray> set;
|
@@ -212,55 +197,6 @@ TEST_CASE("ASN.1 write: use small buffer", "[asn1-writer]") {
|
|
212
197
|
}
|
213
198
|
}
|
214
199
|
|
215
|
-
TEST_CASE("ASN.1 write: check overflows ", "[asn1-writer]") {
|
216
|
-
VirgilAsn1Writer asn1Writer;
|
217
|
-
|
218
|
-
VirgilByteArray data(kAsn1SizeMax);
|
219
|
-
asn1Writer.writeData(data);
|
220
|
-
|
221
|
-
SECTION("with integer") {
|
222
|
-
REQUIRE_THROWS(asn1Writer.writeInteger(1));
|
223
|
-
}
|
224
|
-
|
225
|
-
SECTION("with bool") {
|
226
|
-
REQUIRE_THROWS(asn1Writer.writeBool(true));
|
227
|
-
}
|
228
|
-
|
229
|
-
SECTION("with NULL") {
|
230
|
-
REQUIRE_THROWS(asn1Writer.writeNull());
|
231
|
-
}
|
232
|
-
|
233
|
-
SECTION("with octet string") {
|
234
|
-
REQUIRE_THROWS(asn1Writer.writeOctetString(VirgilByteArray(1, 0xff)));
|
235
|
-
}
|
236
|
-
|
237
|
-
SECTION("with UTF8 string") {
|
238
|
-
REQUIRE_THROWS(asn1Writer.writeUTF8String(VirgilByteArray(1, 0x41)));
|
239
|
-
}
|
240
|
-
|
241
|
-
SECTION("with context tag") {
|
242
|
-
REQUIRE_THROWS(asn1Writer.writeContextTag(1, data.size()));
|
243
|
-
}
|
244
|
-
|
245
|
-
SECTION("with RAW buffer") {
|
246
|
-
REQUIRE_THROWS(asn1Writer.writeData(VirgilByteArray(1, 0xff)));
|
247
|
-
}
|
248
|
-
|
249
|
-
SECTION("with OID") {
|
250
|
-
REQUIRE_THROWS(asn1Writer.writeOID(std::string("\x2A")));
|
251
|
-
}
|
252
|
-
|
253
|
-
SECTION("with sequence") {
|
254
|
-
REQUIRE_THROWS(asn1Writer.writeSequence(data.size()));
|
255
|
-
}
|
256
|
-
|
257
|
-
SECTION("with set") {
|
258
|
-
std::vector<VirgilByteArray> set;
|
259
|
-
set.push_back(VirgilByteArrayUtils::hexToBytes("0500"));
|
260
|
-
REQUIRE_THROWS(asn1Writer.writeSet(set));
|
261
|
-
}
|
262
|
-
}
|
263
|
-
|
264
200
|
TEST_CASE("ASN.1 write: check step by step ASN.1 buffer grows", "[asn1-writer]") {
|
265
201
|
VirgilAsn1Writer asn1Writer(1);
|
266
202
|
size_t len = 0;
|
@@ -400,3 +400,23 @@ TEST_CASE("VirgilCipher: check recipient existence", "[cipher]") {
|
|
400
400
|
REQUIRE_FALSE(restoredCipher.keyRecipientExists(aliceId));
|
401
401
|
}
|
402
402
|
}
|
403
|
+
|
404
|
+
TEST_CASE("VirgilCipher: add 512 recipients", "[cipher]") {
|
405
|
+
VirgilCipher cipher;
|
406
|
+
VirgilKeyPair commonKeyPair = VirgilKeyPair::generateRecommended();
|
407
|
+
VirgilByteArray testData =
|
408
|
+
VirgilByteArrayUtils::stringToBytes("this string will be encrypted for a lot of recipients");
|
409
|
+
|
410
|
+
for (auto i = 0; i < 512; ++i) {
|
411
|
+
std::string recipientId = "recipient-" + std::to_string(i);
|
412
|
+
cipher.addKeyRecipient(VirgilByteArrayUtils::stringToBytes(recipientId), commonKeyPair.publicKey());
|
413
|
+
}
|
414
|
+
VirgilByteArray lastRecipientId = VirgilByteArrayUtils::stringToBytes("recipient-511");
|
415
|
+
|
416
|
+
VirgilByteArray encryptedData;
|
417
|
+
VirgilByteArray decryptedData;
|
418
|
+
REQUIRE_NOTHROW(encryptedData = cipher.encrypt(testData));
|
419
|
+
cipher = VirgilCipher(); // Make new cipher
|
420
|
+
REQUIRE_NOTHROW(decryptedData = cipher.decryptWithKey(encryptedData, lastRecipientId, commonKeyPair.privateKey()));
|
421
|
+
REQUIRE(testData == decryptedData);
|
422
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (C) 2015-2016 Virgil Security Inc.
|
3
|
+
*
|
4
|
+
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
5
|
+
*
|
6
|
+
* All rights reserved.
|
7
|
+
*
|
8
|
+
* Redistribution and use in source and binary forms, with or without
|
9
|
+
* modification, are permitted provided that the following conditions are
|
10
|
+
* met:
|
11
|
+
*
|
12
|
+
* (1) Redistributions of source code must retain the above copyright
|
13
|
+
* notice, this list of conditions and the following disclaimer.
|
14
|
+
*
|
15
|
+
* (2) Redistributions in binary form must reproduce the above copyright
|
16
|
+
* notice, this list of conditions and the following disclaimer in
|
17
|
+
* the documentation and/or other materials provided with the
|
18
|
+
* distribution.
|
19
|
+
*
|
20
|
+
* (3) Neither the name of the copyright holder nor the names of its
|
21
|
+
* contributors may be used to endorse or promote products derived from
|
22
|
+
* this software without specific prior written permission.
|
23
|
+
*
|
24
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
25
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
26
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
27
|
+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
28
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
29
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
30
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
31
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
32
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
33
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
34
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
35
|
+
*/
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @file test_stream_data_source.cxx
|
39
|
+
* @brief Covers class VirgilDataSreamSource
|
40
|
+
*/
|
41
|
+
|
42
|
+
#if LIB_FILE_IO
|
43
|
+
|
44
|
+
#include "catch.hpp"
|
45
|
+
|
46
|
+
#include <virgil/crypto/stream/VirgilStreamDataSource.h>
|
47
|
+
|
48
|
+
#include <fstream>
|
49
|
+
|
50
|
+
using virgil::crypto::stream::VirgilStreamDataSource;
|
51
|
+
|
52
|
+
TEST_CASE("VirgilStreamDataSource: check data existence in the bad stream", "[stream-data-source]") {
|
53
|
+
std::fstream nonExistingFile("invalid_path_to_file");
|
54
|
+
VirgilStreamDataSource dataSource(nonExistingFile);
|
55
|
+
REQUIRE_FALSE(dataSource.hasData());
|
56
|
+
}
|
57
|
+
|
58
|
+
#endif // LIB_FILE_IO
|