Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdp/offer.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ func SelectCrypto(offer, answer []srtp.Profile, swap bool) (*srtp.Config, *srtp.
prof := &off
if swap {
prof = &ans
// Echo the cipher suite tag of the offer, in the answer
prof.Index = off.Index
}
return c, prof, nil
}
Expand Down
50 changes: 50 additions & 0 deletions sdp/offer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,53 @@ a=rtcp-fb:* ccm tmmbr
},
v.CryptoProfiles)
}

// TestSelectCryptoSuiteTag ensures that when selecting a crypto suite from an offer/answer pair,
// the answer uses the same crypto suite tag as the offer, per RFC 4568 section 5.1.2 and 5.1.3.
func TestSelectCryptoSuiteTag(t *testing.T) {
answerProfiles := []srtp.Profile{
{Index: 1, Profile: "AES_CM_128_HMAC_SHA1_80"},
{Index: 2, Profile: "AES_CM_128_HMAC_SHA1_32"},
{Index: 3, Profile: "AES_256_CM_HMAC_SHA1_80"},
{Index: 4, Profile: "AES_256_CM_HMAC_SHA1_32"},
}

cases := []struct {
name string
offer []srtp.Profile
answer []srtp.Profile
exp *srtp.Profile
}{
{
name: "First",
offer: []srtp.Profile{
{Index: 1, Profile: "AES_CM_128_HMAC_SHA1_80"},
{Index: 2, Profile: "AES_CM_128_HMAC_SHA1_32"},
{Index: 3, Profile: "AES_256_CM_HMAC_SHA1_80"},
{Index: 4, Profile: "AES_256_CM_HMAC_SHA1_32"},
},
answer: answerProfiles,
exp: &srtp.Profile{Index: 1, Profile: "AES_CM_128_HMAC_SHA1_80"},
},
{
name: "Fifth",
offer: []srtp.Profile{
{Index: 1, Profile: "AEAD_AES_256_GCM"},
{Index: 2, Profile: "AEAD_AES_128_GCM"},
{Index: 3, Profile: "AES_256_CM_HMAC_SHA1_80"},
{Index: 4, Profile: "AES_256_CM_HMAC_SHA1_32"},
{Index: 5, Profile: "AES_CM_128_HMAC_SHA1_80"},
},
answer: answerProfiles,
exp: &srtp.Profile{Index: 5, Profile: "AES_CM_128_HMAC_SHA1_80"},
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
_, got, err := SelectCrypto(c.offer, c.answer, true)
require.NoError(t, err)
require.Equal(t, *c.exp, *got)
})
}
}
Loading