@@ -46,24 +46,22 @@ static LogCounter
46
46
47
47
const string PemBeginCertificateTag = " -----BEGIN CERTIFICATE-----" ;
48
48
49
- PeerConnection::PeerConnection (Configuration config_)
50
- : config(std::move(config_)) {
49
+ PeerConnection::PeerConnection (Configuration config_) : config(std::move(config_)) {
51
50
PLOG_VERBOSE << " Creating PeerConnection" ;
52
51
53
-
54
52
if (config.certificatePemFile && config.keyPemFile ) {
55
53
std::promise<certificate_ptr> cert;
56
54
cert.set_value (std::make_shared<Certificate>(
57
- config.certificatePemFile ->find (PemBeginCertificateTag) != string::npos
58
- ? Certificate::FromString (*config.certificatePemFile , *config.keyPemFile )
59
- : Certificate::FromFile (*config.certificatePemFile , *config.keyPemFile ,
60
- config.keyPemPass .value_or (" " ))));
55
+ config.certificatePemFile ->find (PemBeginCertificateTag) != string::npos
56
+ ? Certificate::FromString (*config.certificatePemFile , *config.keyPemFile )
57
+ : Certificate::FromFile (*config.certificatePemFile , *config.keyPemFile ,
58
+ config.keyPemPass .value_or (" " ))));
61
59
mCertificate = cert.get_future ();
62
60
} else if (!config.certificatePemFile && !config.keyPemFile ) {
63
61
mCertificate = make_certificate (config.certificateType );
64
62
} else {
65
63
throw std::invalid_argument (
66
- " Either none or both certificate and key PEM files must be specified" );
64
+ " Either none or both certificate and key PEM files must be specified" );
67
65
}
68
66
69
67
if (config.portRangeEnd && config.portRangeBegin > config.portRangeEnd )
@@ -229,13 +227,15 @@ shared_ptr<DtlsTransport> PeerConnection::initDtlsTransport() {
229
227
230
228
PLOG_VERBOSE << " Starting DTLS transport" ;
231
229
232
- auto fingerprintAlgorithm = CertificateFingerprint::Algorithm::Sha256;
233
- if (auto remote = remoteDescription (); remote && remote->fingerprint ()) {
234
- fingerprintAlgorithm = remote->fingerprint ()->algorithm ;
230
+ CertificateFingerprint::Algorithm fingerprintAlgorithm;
231
+ {
232
+ std::lock_guard lock (mRemoteDescription );
233
+ if (mRemoteDescription && mRemoteDescription ->fingerprint ()) {
234
+ mRemoteFingerprintAlgorithm = mRemoteDescription ->fingerprint ()->algorithm ;
235
+ }
236
+ fingerprintAlgorithm = mRemoteFingerprintAlgorithm ;
235
237
}
236
238
237
- mRemoteFingerprintAlgorithm = fingerprintAlgorithm;
238
-
239
239
auto lower = std::atomic_load (&mIceTransport );
240
240
if (!lower)
241
241
throw std::logic_error (" No underlying ICE transport for DTLS transport" );
@@ -443,23 +443,24 @@ void PeerConnection::rollbackLocalDescription() {
443
443
444
444
bool PeerConnection::checkFingerprint (const std::string &fingerprint) {
445
445
std::lock_guard lock (mRemoteDescriptionMutex );
446
- if (!mRemoteDescription || !mRemoteDescription ->fingerprint ())
446
+ mRemoteFingerprint = fingerprint;
447
+
448
+ if (!mRemoteDescription || !mRemoteDescription ->fingerprint () || mRemoteFingerprintAlgorithm != mRemoteDescription ->fingerprint ()->algorithm )
447
449
return false ;
448
450
449
- if (config.disableFingerprintVerification ) {
451
+ if (config.disableFingerprintVerification ) {
450
452
PLOG_VERBOSE << " Skipping fingerprint validation" ;
451
- mRemoteFingerprint = fingerprint;
452
453
return true ;
453
454
}
454
455
455
456
auto expectedFingerprint = mRemoteDescription ->fingerprint ()->value ;
456
457
if (expectedFingerprint == fingerprint) {
457
458
PLOG_VERBOSE << " Valid fingerprint \" " << fingerprint << " \" " ;
458
- mRemoteFingerprint = fingerprint;
459
459
return true ;
460
460
}
461
461
462
- PLOG_ERROR << " Invalid fingerprint \" " << fingerprint << " \" , expected \" " << expectedFingerprint << " \" " ;
462
+ PLOG_ERROR << " Invalid fingerprint \" " << fingerprint << " \" , expected \" "
463
+ << expectedFingerprint << " \" " ;
463
464
return false ;
464
465
}
465
466
@@ -555,7 +556,7 @@ void PeerConnection::forwardMedia([[maybe_unused]] message_ptr message) {
555
556
void PeerConnection::dispatchMedia ([[maybe_unused]] message_ptr message) {
556
557
#if RTC_ENABLE_MEDIA
557
558
std::shared_lock lock (mTracksMutex ); // read-only
558
- if (mTrackLines .size ()== 1 ) {
559
+ if (mTrackLines .size () == 1 ) {
559
560
if (auto track = mTrackLines .front ().lock ())
560
561
track->incoming (message);
561
562
return ;
@@ -742,7 +743,7 @@ void PeerConnection::iterateDataChannels(
742
743
{
743
744
std::shared_lock lock (mDataChannelsMutex ); // read-only
744
745
locked.reserve (mDataChannels .size ());
745
- for (auto it = mDataChannels .begin (); it != mDataChannels .end (); ++it) {
746
+ for (auto it = mDataChannels .begin (); it != mDataChannels .end (); ++it) {
746
747
auto channel = it->second .lock ();
747
748
if (channel && !channel->isClosed ())
748
749
locked.push_back (std::move (channel));
@@ -811,7 +812,7 @@ void PeerConnection::iterateTracks(std::function<void(shared_ptr<Track> track)>
811
812
{
812
813
std::shared_lock lock (mTracksMutex ); // read-only
813
814
locked.reserve (mTrackLines .size ());
814
- for (auto it = mTrackLines .begin (); it != mTrackLines .end (); ++it) {
815
+ for (auto it = mTrackLines .begin (); it != mTrackLines .end (); ++it) {
815
816
auto track = it->lock ();
816
817
if (track && !track->isClosed ())
817
818
locked.push_back (std::move (track));
@@ -1308,6 +1309,7 @@ void PeerConnection::resetCallbacks() {
1308
1309
}
1309
1310
1310
1311
CertificateFingerprint PeerConnection::remoteFingerprint () {
1312
+ std::lock_guard lock (mRemoteDescriptionMutex );
1311
1313
if (mRemoteFingerprint )
1312
1314
return {CertificateFingerprint{mRemoteFingerprintAlgorithm , *mRemoteFingerprint }};
1313
1315
else
0 commit comments