diff --git a/README.md b/README.md index 02831dac..aebb701b 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu * [Alex Harford](https://github.com/alexjh) * [Aleksandr Razumov](https://github.com/ernado) * [mchlrhw](https://github.com/mchlrhw) +* [AlexWoo(武杰)](https://github.com/AlexWoo) *Fix RemoteDescription parsing for certificate fingerprint* ### License MIT License - see [LICENSE](LICENSE) for full text diff --git a/peerconnection.go b/peerconnection.go index 374ffae6..bf6d30ce 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -874,7 +874,12 @@ func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error { weOffer = false } + fingerprint, haveFingerprint := desc.parsed.Attribute("fingerprint") for _, m := range pc.RemoteDescription().parsed.MediaDescriptions { + if !haveFingerprint { + fingerprint, haveFingerprint = m.Attribute("fingerprint") + } + for _, a := range m.Attributes { switch { case a.IsICECandidate(): @@ -899,20 +904,16 @@ func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error { } } - fingerprint, ok := desc.parsed.Attribute("fingerprint") - if !ok { - fingerprint, ok = desc.parsed.MediaDescriptions[0].Attribute("fingerprint") - if !ok { - return fmt.Errorf("could not find fingerprint") - } + if !haveFingerprint { + return fmt.Errorf("could not find fingerprint") } - var fingerprintHash string + parts := strings.Split(fingerprint, " ") if len(parts) != 2 { return fmt.Errorf("invalid fingerprint") } fingerprint = parts[1] - fingerprintHash = parts[0] + fingerprintHash := parts[0] // Create the SCTP transport sctp := pc.api.NewSCTPTransport(pc.dtlsTransport) diff --git a/peerconnection_test.go b/peerconnection_test.go index 86f93c97..487c2bcc 100644 --- a/peerconnection_test.go +++ b/peerconnection_test.go @@ -418,3 +418,44 @@ func TestMultipleOfferAnswer(t *testing.T) { t.Errorf("Second Offer: got error: %v", err) } } + +func TestNoFingerprintInFirstMediaIfSetRemoteDescription(t *testing.T) { + const sdpNoFingerprintInFirstMedia = `v=0 +o=- 143087887 1561022767 IN IP4 192.168.84.254 +s=VideoRoom 404986692241682 +t=0 0 +a=group:BUNDLE audio +a=msid-semantic: WMS 2867270241552712 +m=video 0 UDP/TLS/RTP/SAVPF 0 +c=IN IP4 192.168.84.254 +a=inactive +m=audio 9 UDP/TLS/RTP/SAVPF 111 +c=IN IP4 192.168.84.254 +a=recvonly +a=mid:audio +a=rtcp-mux +a=ice-ufrag:AS/w +a=ice-pwd:9NOgoAOMALYu/LOpA1iqg/ +a=ice-options:trickle +a=fingerprint:sha-256 D2:B9:31:8F:DF:24:D8:0E:ED:D2:EF:25:9E:AF:6F:B8:34:AE:53:9C:E6:F3:8F:F2:64:15:FA:E8:7F:53:2D:38 +a=setup:active +a=rtpmap:111 opus/48000/2 +a=candidate:1 1 udp 2013266431 192.168.84.254 46492 typ host +a=end-of-candidates +` + + pc, err := NewPeerConnection(Configuration{}) + if err != nil { + t.Error(err.Error()) + } + + desc := SessionDescription{ + Type: SDPTypeOffer, + SDP: sdpNoFingerprintInFirstMedia, + } + + err = pc.SetRemoteDescription(desc) + if err != nil { + t.Error(err.Error()) + } +}