@@ -43,6 +43,7 @@ type DTLSTransport struct {
4343 remoteCertificate []byte
4444 state DTLSTransportState
4545 srtpProtectionProfile srtp.ProtectionProfile
46+ cryptexMode srtp.CryptexMode
4647
4748 onStateChangeHandler func (DTLSTransportState )
4849 internalOnCloseHandler func ()
@@ -192,12 +193,20 @@ func (t *DTLSTransport) GetRemoteCertificate() []byte {
192193 return t .remoteCertificate
193194}
194195
195- func (t * DTLSTransport ) startSRTP () error {
196+ // startSRTP requires the caller holds the lock.
197+ func (t * DTLSTransport ) startSRTP () error { //nolint:cyclop
196198 srtpConfig := & srtp.Config {
197199 Profile : t .srtpProtectionProfile ,
198200 BufferFactory : t .api .settingEngine .BufferFactory ,
199201 LoggerFactory : t .api .settingEngine .LoggerFactory ,
200202 }
203+
204+ if t .cryptexMode == srtp .CryptexModeEnabled || t .cryptexMode == srtp .CryptexModeRequired {
205+ opt := srtp .Cryptex (t .cryptexMode )
206+ srtpConfig .LocalOptions = append (srtpConfig .LocalOptions , opt )
207+ srtpConfig .RemoteOptions = append (srtpConfig .RemoteOptions , opt )
208+ }
209+
201210 if t .api .settingEngine .replayProtection .SRTP != nil {
202211 srtpConfig .RemoteOptions = append (
203212 srtpConfig .RemoteOptions ,
@@ -567,3 +576,12 @@ func (t *DTLSTransport) streamsForSSRC(
567576 rtcpInterceptor : rtcpInterceptor ,
568577 }, nil
569578}
579+
580+ // rtpHeaderEncryptionNegotiated reports if RFC 9335 RTP Header Extension Encryption ("Cryptex")
581+ // has been negotiated and is enabled for this transceiver.
582+ func (t * DTLSTransport ) rtpHeaderEncryptionNegotiated () bool {
583+ t .lock .RLock ()
584+ defer t .lock .RUnlock ()
585+
586+ return t .cryptexMode == srtp .CryptexModeEnabled || t .cryptexMode == srtp .CryptexModeRequired
587+ }
0 commit comments