Check all SDP media sections for a fingerprint

Fix RemoteDescription parsing so that it parses all sections when
looking for a fingerprint, before it would fail if the first section
did not contain one
This commit is contained in:
AlexWoo(武杰)
2019-06-24 11:48:55 +08:00
committed by Sean DuBois
parent be3d922fbb
commit 3a15b2ccda
3 changed files with 51 additions and 8 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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())
}
}