Browse Source

Pick correct fingerprint when different attributes are present

Paul-Louis Ageneau 1 year ago
parent
commit
7fa3341454
1 changed files with 11 additions and 6 deletions
  1. 11 6
      src/description.cpp

+ 11 - 6
src/description.cpp

@@ -120,12 +120,17 @@ Description::Description(const string &sdp, Type type, Role role)
 					mRole = Role::ActPass;
 					mRole = Role::ActPass;
 
 
 			} else if (key == "fingerprint") {
 			} else if (key == "fingerprint") {
-				if (match_prefix(value, "sha-256 ") || match_prefix(value, "SHA-256 ")) {
-					string fingerprint{value.substr(8)};
-					trim_begin(fingerprint);
-					setFingerprint(std::move(fingerprint));
-				} else {
-					PLOG_WARNING << "Unknown SDP fingerprint format: " << value;
+				// RFC 8122: The fingerprint attribute may be either a session-level or a
+				// media-level SDP attribute. If it is a session-level attribute, it applies to all
+				// TLS sessions for which no media-level fingerprint attribute is defined.
+				if (!mFingerprint || index == 0) { // first media overrides session-level
+					if (match_prefix(value, "sha-256 ") || match_prefix(value, "SHA-256 ")) {
+						string fingerprint{value.substr(8)};
+						trim_begin(fingerprint);
+						setFingerprint(std::move(fingerprint));
+					} else {
+						PLOG_WARNING << "Unknown SDP fingerprint format: " << value;
+					}
 				}
 				}
 			} else if (key == "ice-ufrag") {
 			} else if (key == "ice-ufrag") {
 				// RFC 8839: The "ice-pwd" and "ice-ufrag" attributes can appear at either the
 				// RFC 8839: The "ice-pwd" and "ice-ufrag" attributes can appear at either the