@@ -239,7 +239,7 @@ shared_ptr<DtlsTransport> PeerConnection::initDtlsTransport() {
239
239
throw std::logic_error (" No underlying ICE transport for DTLS transport" );
240
240
241
241
auto certificate = mCertificate .get ();
242
- auto verifierCallback = weak_bind (&PeerConnection::checkFingerprint, this , _1);
242
+ auto verifierCallback = weak_bind (&PeerConnection::checkFingerprint, this , _1, fingerprintAlgorithm );
243
243
auto dtlsStateChangeCallback =
244
244
[this , weak_this = weak_from_this ()](DtlsTransport::State transportState) {
245
245
auto shared_this = weak_this.lock ();
@@ -439,24 +439,36 @@ void PeerConnection::rollbackLocalDescription() {
439
439
}
440
440
}
441
441
442
- bool PeerConnection::checkFingerprint (const std::string &fingerprint) const {
442
+ bool PeerConnection::checkFingerprint (const std::string &fingerprint, const CertificateFingerprint::Algorithm &algorithm) {
443
443
std::lock_guard lock (mRemoteDescriptionMutex );
444
444
if (!mRemoteDescription || !mRemoteDescription ->fingerprint ())
445
445
return false ;
446
446
447
- if (config.disableFingerprintVerification )
448
- return true ;
449
-
450
447
auto expectedFingerprint = mRemoteDescription ->fingerprint ()->value ;
451
- if (expectedFingerprint == fingerprint) {
448
+ if (config. disableFingerprintVerification || expectedFingerprint == fingerprint) {
452
449
PLOG_VERBOSE << " Valid fingerprint \" " << fingerprint << " \" " ;
450
+ storeRemoteFingerprint (fingerprint, algorithm);
453
451
return true ;
454
452
}
455
453
456
454
PLOG_ERROR << " Invalid fingerprint \" " << fingerprint << " \" , expected \" " << expectedFingerprint << " \" " ;
457
455
return false ;
458
456
}
459
457
458
+ void PeerConnection::storeRemoteFingerprint (const std::string &value, const CertificateFingerprint::Algorithm &algorithm) {
459
+ auto iter = std::find_if (rFingerprints.begin (), rFingerprints.end (), [&](const RemoteFingerprint& existing){return existing.value == value;});
460
+ bool seenPreviously = iter != rFingerprints.end ();
461
+
462
+ if (seenPreviously) {
463
+ return ;
464
+ }
465
+
466
+ rFingerprints.push_back ({
467
+ value,
468
+ algorithm
469
+ });
470
+ }
471
+
460
472
void PeerConnection::forwardMessage (message_ptr message) {
461
473
if (!message) {
462
474
remoteCloseDataChannels ();
@@ -1301,6 +1313,13 @@ void PeerConnection::resetCallbacks() {
1301
1313
trackCallback = nullptr ;
1302
1314
}
1303
1315
1316
+ std::vector<struct RemoteFingerprint > PeerConnection::remoteFingerprints () {
1317
+ std::vector<struct RemoteFingerprint > ret;
1318
+ ret = rFingerprints;
1319
+
1320
+ return ret;
1321
+ }
1322
+
1304
1323
void PeerConnection::updateTrackSsrcCache (const Description &description) {
1305
1324
std::unique_lock lock (mTracksMutex ); // for safely writing to mTracksBySsrc
1306
1325
0 commit comments