Skip to content

Commit 742e829

Browse files
authored
Merge pull request #402 from simplito/rc-2.7
Version 2.7.4
2 parents e67703c + 05d2dd3 commit 742e829

34 files changed

Lines changed: 755 additions & 59 deletions

conanfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ poco/1.13.2
33
pson/1.0.7
44
openssl/[>=3.0 <3.1]
55
gmp/6.2.1
6-
privmxdrvcrypto/1.0.2
6+
privmxdrvcrypto/1.0.3
77
privmxdrvecc/1.0.2
88
privmxdrvnet/1.0.3
99
gtest/[^1.15.0]

crypto/base/include/privmx/crypto/Crypto.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class Crypto
3939
static std::string aes256CbcPkcs7Decrypt(const std::string& data, const std::string& key, const std::string& iv);
4040
static std::string aes256CbcNoPadEncrypt(const std::string& data, const std::string& key, const std::string& iv);
4141
static std::string aes256CbcNoPadDecrypt(const std::string& data, const std::string& key, const std::string& iv);
42+
static std::string aes256GcmEncrypt(const std::string& data, const std::string& key, const std::string& iv, const std::string& aad = "");
43+
static std::string aes256GcmDecrypt(const std::string& data, const std::string& key, const std::string& iv, const std::string& aad = "");
4244
static std::string prf_tls12(const std::string& key, const std::string& seed, size_t length);
4345
static std::string pbkdf2(const std::string& password, const std::string& salt, size_t rounds, size_t length, const std::string& algorithm);
4446
static std::string kdf(size_t length, const std::string& key, const std::string& label);
@@ -127,6 +129,16 @@ inline std::string Crypto::aes256CbcNoPadDecrypt(const std::string& data, const
127129
return crypto_service->aes256CbcNoPadDecrypt(data, key, iv);
128130
}
129131

132+
inline std::string Crypto::aes256GcmEncrypt(const std::string& data, const std::string& key, const std::string& iv, const std::string& aad) {
133+
auto crypto_service = CryptoEnv::getEnv()->getCryptoService();
134+
return crypto_service->aes256GcmEncrypt(data, key, iv, aad);
135+
}
136+
137+
inline std::string Crypto::aes256GcmDecrypt(const std::string& data, const std::string& key, const std::string& iv, const std::string& aad) {
138+
auto crypto_service = CryptoEnv::getEnv()->getCryptoService();
139+
return crypto_service->aes256GcmDecrypt(data, key, iv, aad);
140+
}
141+
130142
inline std::string Crypto::prf_tls12(const std::string& key, const std::string& seed, size_t length) {
131143
auto crypto_service = CryptoEnv::getEnv()->getCryptoService();
132144
return crypto_service->prf_tls12(key, seed, length);

crypto/base/include/privmx/crypto/CryptoService.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class CryptoService
4141
virtual std::string aes256CbcPkcs7Decrypt(const std::string& data, const std::string& key, const std::string& iv) const = 0;
4242
virtual std::string aes256CbcNoPadEncrypt(const std::string& data, const std::string& key, const std::string& iv) const = 0;
4343
virtual std::string aes256CbcNoPadDecrypt(const std::string& data, const std::string& key, const std::string& iv) const = 0;
44+
virtual std::string aes256GcmEncrypt(const std::string& data, const std::string& key, const std::string& iv, const std::string& aad) const = 0;
45+
virtual std::string aes256GcmDecrypt(const std::string& data, const std::string& key, const std::string& iv, const std::string& aad) const = 0;
4446
virtual std::string prf_tls12(const std::string& key, const std::string& seed, size_t length) const = 0;
4547
virtual std::string kdf(size_t length, const std::string& key, const std::string& label) const = 0;
4648
virtual std::string generateIv(const std::string& key, Poco::Int32 idx) const = 0;

crypto/driver/include/privmx/crypto/driver/CryptoService.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class CryptoService : public privmx::crypto::CryptoService
3636
virtual std::string aes256CbcPkcs7Decrypt(const std::string& data, const std::string& key, const std::string& iv) const override;
3737
virtual std::string aes256CbcNoPadEncrypt(const std::string& data, const std::string& key, const std::string& iv) const override;
3838
virtual std::string aes256CbcNoPadDecrypt(const std::string& data, const std::string& key, const std::string& iv) const override;
39+
virtual std::string aes256GcmEncrypt(const std::string& data, const std::string& key, const std::string& iv, const std::string& aad) const override;
40+
virtual std::string aes256GcmDecrypt(const std::string& data, const std::string& key, const std::string& iv, const std::string& aad) const override;
3941
virtual std::string prf_tls12(const std::string& key, const std::string& seed, size_t length) const override;
4042
virtual std::string kdf(size_t length, const std::string& key, const std::string& label) const override;
4143
virtual std::string generateIv(const std::string& key, Poco::Int32 idx) const override;

crypto/driver/src/CryptoService.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,38 @@ string driverimpl::CryptoService::aes256CbcNoPadDecrypt(const string& data, cons
199199
return res;
200200
}
201201

202+
std::string driverimpl::CryptoService::aes256GcmEncrypt(const std::string& data, const std::string& key, const std::string& iv, const std::string& aad) const {
203+
char* out;
204+
unsigned int outlen;
205+
char* tag;
206+
unsigned int taglen;
207+
int status = privmxDrvCrypto_aeadEncrypt(key.data(), iv.data(), aad.data(), aad.size(), data.data(), data.size(), "AES-256-GCM", &out, &outlen, &tag, &taglen);
208+
if (status != 0) {
209+
throw PrivmxDriverCryptoException("aes256GcmEncrypt: " + to_string(status));
210+
}
211+
string out_str(out, outlen);
212+
string tag_str(tag, taglen);
213+
privmxDrvCrypto_freeMem(out);
214+
privmxDrvCrypto_freeMem(tag);
215+
return out_str+tag_str;
216+
}
217+
218+
std::string driverimpl::CryptoService::aes256GcmDecrypt(const std::string& data, const std::string& key, const std::string& iv, const std::string& aad) const {
219+
if(data.size() < 16) {
220+
throw PrivmxDriverCryptoException("aes256GcmDecrypt: no tag");
221+
}
222+
std::string tag = data.substr(data.size()-16, 16);
223+
std::string dataWithoutTag = data.substr(0, data.size()-16);
224+
char* out;
225+
unsigned int outlen;
226+
int status = privmxDrvCrypto_aeadDecrypt(key.data(), iv.data(), aad.data(), aad.size(), dataWithoutTag.data(), dataWithoutTag.size(), tag.data(), tag.size(), "AES-256-GCM", &out, &outlen);
227+
if (status != 0) {
228+
throw PrivmxDriverCryptoException("aes256GcmDecrypt: " + to_string(status));
229+
}
230+
string res(out, outlen);
231+
privmxDrvCrypto_freeMem(out);
232+
return res;
233+
}
202234

203235
string driverimpl::CryptoService::prf_tls12(const string& key, const string& seed, size_t length) const {
204236
string a = seed;

endpoint/programs/stream_testing/single_video_receiver.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class OnTrackImpl : public stream::OnTrackInterface {
150150
}
151151
}
152152
virtual void OnData(std::shared_ptr<stream::Data> data) override {
153+
153154
if(data->type == stream::DataType::VIDEO) {
154155
auto videoData = std::dynamic_pointer_cast<stream::VideoData>(data);
155156
// selecting most active video track to render
@@ -162,9 +163,13 @@ class OnTrackImpl : public stream::OnTrackInterface {
162163
_renderer.OnFrame(videoData->w, videoData->h, videoData->frameData);
163164
}
164165
--_videoTrackC;
165-
}
166-
if(data->type == stream::DataType::AUDIO) {
166+
} else if(data->type == stream::DataType::AUDIO) {
167167
auto audioData = std::dynamic_pointer_cast<stream::AudioData>(data);
168+
} else if(data->type == stream::DataType::PLAIN) {
169+
auto plainData = std::dynamic_pointer_cast<stream::PlainData>(data);
170+
LOG_INFO("Recived plain data: ", plainData->data.stdString());
171+
} else {
172+
LOG_FATAL("DataType::UNKNOWN")
168173
}
169174
}
170175
private:
@@ -231,6 +236,7 @@ int main(int argc, char** argv) {
231236
std::cout << "stream.metadata:" << (stream.metadata.has_value() ? stream.metadata.value() : "") << std::endl;
232237
for(auto track : stream.tracks) {
233238
std::cout << "stream.track[].mid:" << track.mid << std::endl;
239+
std::cout << "stream.track[].type:" << track.type << std::endl;
234240
streamsId.push_back(stream::StreamSubscription{stream.id, track.mid});
235241
}
236242
break;

endpoint/programs/stream_testing/single_video_sender.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@ int main(int argc, char** argv) {
103103
streamApi.addTrack(streamHandle, desktopDevice, stream::MediaTrackConstrains{.idealFps=30});
104104
break;
105105
}
106+
auto dataTrack = streamApi.addTrack(streamHandle, stream::MediaDevice{.name="", .id="", .type=stream::DeviceType::Plain}, stream::MediaTrackConstrains{});
106107

107108
streamApi.publishStream(streamHandle);
108-
std::this_thread::sleep_for(std::chrono::seconds(600));
109+
for(int i = 0; i < 300; i++) {
110+
std::this_thread::sleep_for(std::chrono::seconds(2));
111+
streamApi.sendData(streamHandle, core::Buffer::from("ping"));
112+
}
109113
streamApi.unpublishStream(streamHandle);
110114
std::this_thread::sleep_for(std::chrono::seconds(2));
111115
streamApi.leaveStreamRoom(streamRoomId);

endpoint/stream/stream/include/privmx/endpoint/stream/ServerTypes.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ ENDPOINT_SERVER_TYPE(StreamUnpublishModel)
281281
TYPE_END
282282

283283
ENDPOINT_SERVER_TYPE(StreamTrickleModel)
284-
OBJECT_PTR_FIELD(candidate)
284+
OBJECT_PTR_FIELD(rtcCandidate)
285285
INT64_FIELD(sessionId)
286286
TYPE_END
287287

endpoint/stream/stream/include_pub/privmx/endpoint/stream/StreamException.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, StreamIsPublished, "Stream i
8585
DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, CannotExtractStreamUpdatedEventException, "Cannot extract StreamUpdatedEvent", 0x0023)
8686
DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, NullCallbackException, "Callback must not be null", 0x0024)
8787
DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, UnknownTypeException, "Unknown type encountered", 0x0025)
88+
DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, ThereCanBeOnlyOneDataTrackException, "There can be only one dataTrack per user in StreamRoom", 0x0026)
89+
DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, DataTrackNotInitializedException, "Data track not initialized", 0x0027);
90+
91+
DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, NoStreamEncryptionKeyException, "No stream encryption key", 0x0028);
92+
DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, NoStreamDecryptionKeyException, "No stream decryption key", 0x0029);
93+
DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, InvalidEncryptionKeyIdLengthException, "Invalid encryption key id length", 0x002A);
94+
DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, InvalidMessageHeaderLengthException, "Invalid message header length", 0x002B);
95+
DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, UnsupportedMessageFormatVersionException, "Unsupported message format version length", 0x002C);
8896
} // stream
8997
} // endpoint
9098
} // privmx

endpoint/stream/stream/src/Events.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ StreamUnpublishedEvent Events::extractStreamUnpublishedEvent(const core::EventHo
219219
}
220220

221221
bool Events::isStreamLeftEvent(const core::EventHolder& handler) {
222-
return handler.type() == "streamCustom";
222+
return handler.type() == "streamLeft";
223223
}
224224

225225
StreamLeftEvent Events::extractStreamLeftEvent(const core::EventHolder& handler) {

0 commit comments

Comments
 (0)