WARNING: The online documentation has moved to https://docs.pjsip.org.

Visit the new documentation at https://docs.pjsip.org:

BLOG | DOCUMENTATION | GITHUB

Home --> Documentations --> PJMEDIA Reference

Secure RTP (SRTP) Media Transport

Media transport adapter to add SRTP feature to existing transports. More...

Data Structures

struct  pjmedia_srtp_crypto
 
struct  pjmedia_srtp_cb
 
struct  pjmedia_srtp_roc
 
struct  pjmedia_srtp_setting
 
struct  pjmedia_srtp_info
 
struct  pjmedia_srtp_dtls_nego_param
 

Enumerations

enum  pjmedia_srtp_crypto_option {
  PJMEDIA_SRTP_NO_ENCRYPTION = 1 ,
  PJMEDIA_SRTP_NO_AUTHENTICATION = 2
}
 
enum  pjmedia_srtp_use {
  PJMEDIA_SRTP_DISABLED ,
  PJMEDIA_SRTP_UNKNOWN = PJMEDIA_SRTP_DISABLED ,
  PJMEDIA_SRTP_OPTIONAL ,
  PJMEDIA_SRTP_MANDATORY
}
 
enum  pjmedia_srtp_keying_method {
  PJMEDIA_SRTP_KEYING_SDES ,
  PJMEDIA_SRTP_KEYING_DTLS_SRTP ,
  PJMEDIA_SRTP_KEYINGS_COUNT
}
 

Functions

pj_status_t pjmedia_srtp_init_lib (pjmedia_endpt *endpt)
 
void pjmedia_srtp_setting_default (pjmedia_srtp_setting *opt)
 
pj_status_t pjmedia_srtp_enum_crypto (unsigned *count, pjmedia_srtp_crypto crypto[])
 
pj_status_t pjmedia_srtp_enum_keying (unsigned *count, pjmedia_srtp_keying_method keying[])
 
pj_status_t pjmedia_transport_srtp_create (pjmedia_endpt *endpt, pjmedia_transport *tp, const pjmedia_srtp_setting *opt, pjmedia_transport **p_tp)
 
pj_status_t pjmedia_transport_srtp_get_setting (pjmedia_transport *srtp, pjmedia_srtp_setting *opt)
 
pj_status_t pjmedia_transport_srtp_modify_setting (pjmedia_transport *srtp, const pjmedia_srtp_setting *opt)
 
pj_status_t pjmedia_transport_srtp_dtls_get_fingerprint (pjmedia_transport *srtp, const char *hash, char *buf, pj_size_t *len)
 
pj_status_t pjmedia_transport_srtp_dtls_start_nego (pjmedia_transport *srtp, const pjmedia_srtp_dtls_nego_param *param)
 
pj_status_t pjmedia_transport_srtp_start (pjmedia_transport *srtp, const pjmedia_srtp_crypto *tx, const pjmedia_srtp_crypto *rx)
 
pj_status_t pjmedia_transport_srtp_stop (pjmedia_transport *srtp)
 
pj_status_t pjmedia_transport_srtp_decrypt_pkt (pjmedia_transport *tp, pj_bool_t is_rtp, void *pkt, int *pkt_len)
 
pjmedia_transportpjmedia_transport_srtp_get_member (pjmedia_transport *srtp)
 

Detailed Description

This module implements SRTP as described by RFC 3711, using RFC 4568 as key exchange method. It implements Media Transport to integrate with the rest of PJMEDIA framework.

As we know, media transport is separated from the stream object (which does the encoding/decoding of PCM frames, (de)packetization of RTP/RTCP packets, and de-jitter buffering). The connection between stream and media transport is established when the stream is created (we need to specify media transport during stream creation), and the interconnection can be depicted from the diagram below:

I think the diagram above is self-explanatory.

SRTP functionality is implemented as some kind of "adapter", which is plugged between the stream and the actual media transport that does sending/receiving RTP/RTCP packets. When SRTP is used, the interconnection between stream and transport is like the diagram below:

So to stream, the SRTP transport behaves as if it is a media transport (because it is a media transport), and to the media transport it behaves as if it is a stream. The SRTP object then forwards RTP packets back and forth between stream and the actual transport, encrypting/decrypting the RTP/RTCP packets as necessary.

The neat thing about this design is the SRTP "adapter" then can be used to encrypt any kind of media transports. We currently have UDP and ICE media transports that can benefit SRTP, and we could add SRTP to any media transports that will be added in the future.

Enumeration Type Documentation

◆ pjmedia_srtp_crypto_option

Crypto option.

Enumerator
PJMEDIA_SRTP_NO_ENCRYPTION 

When this flag is specified, encryption will be disabled.

PJMEDIA_SRTP_NO_AUTHENTICATION 

When this flag is specified, authentication will be disabled.

◆ pjmedia_srtp_use

This enumeration specifies the behavior of the SRTP transport regarding media security offer and answer.

Enumerator
PJMEDIA_SRTP_DISABLED 

When this flag is specified, SRTP will be disabled, and the transport will reject RTP/SAVP offer.

PJMEDIA_SRTP_UNKNOWN 

When this flag is specified, SRTP setting is unknown. This is to set the initial remote's SRTP usage. It will be set later after remote's policy in the SDP is received.

PJMEDIA_SRTP_OPTIONAL 

When this flag is specified, SRTP will be advertised as optional and incoming SRTP offer will be accepted.

PJMEDIA_SRTP_MANDATORY 

When this flag is specified, the transport will require that RTP/SAVP media shall be used.

◆ pjmedia_srtp_keying_method

This enumeration specifies SRTP keying methods.

Enumerator
PJMEDIA_SRTP_KEYING_SDES 

Session Description (SDES).

PJMEDIA_SRTP_KEYING_DTLS_SRTP 

DTLS-SRTP.

PJMEDIA_SRTP_KEYINGS_COUNT 

Number of keying method.

Function Documentation

◆ pjmedia_srtp_init_lib()

pj_status_t pjmedia_srtp_init_lib ( pjmedia_endpt endpt)

Initialize SRTP library. This function should be called before any SRTP functions, however calling pjmedia_transport_srtp_create() will also invoke this function. This function will also register SRTP library deinitialization to pj_atexit(), so the deinitialization of SRTP library will be performed automatically by PJLIB destructor.

Parameters
endptThe media endpoint instance.
Returns
PJ_SUCCESS on success.

◆ pjmedia_srtp_setting_default()

void pjmedia_srtp_setting_default ( pjmedia_srtp_setting opt)

Initialize SRTP setting with its default values.

Parameters
optSRTP setting to be initialized.

◆ pjmedia_srtp_enum_crypto()

pj_status_t pjmedia_srtp_enum_crypto ( unsigned *  count,
pjmedia_srtp_crypto  crypto[] 
)

Enumerate available SRTP crypto name.

Parameters
countOn input, specifies the maximum length of crypto array. On output, the number of available crypto initialized by this function.
cryptoThe SRTP crypto array output.
Returns
PJ_SUCCESS on success.

◆ pjmedia_srtp_enum_keying()

pj_status_t pjmedia_srtp_enum_keying ( unsigned *  count,
pjmedia_srtp_keying_method  keying[] 
)

Enumerate available SRTP keying methods.

Parameters
countOn input, specifies the maximum length of keying method array. On output, the number of available keying method initialized by this function.
keyingThe SRTP keying method array output.
Returns
PJ_SUCCESS on success.

◆ pjmedia_transport_srtp_create()

pj_status_t pjmedia_transport_srtp_create ( pjmedia_endpt endpt,
pjmedia_transport tp,
const pjmedia_srtp_setting opt,
pjmedia_transport **  p_tp 
)

Create an SRTP media transport.

Parameters
endptThe media endpoint instance.
tpThe actual media transport to send and receive RTP/RTCP packets. This media transport will be kept as member transport of this SRTP instance.
optOptional settings. If NULL is given, default settings will be used.
p_tpPointer to receive the transport SRTP instance.
Returns
PJ_SUCCESS on success.

◆ pjmedia_transport_srtp_get_setting()

pj_status_t pjmedia_transport_srtp_get_setting ( pjmedia_transport srtp,
pjmedia_srtp_setting opt 
)

Get current SRTP media transport setting.

Parameters
srtpThe SRTP transport.
optStructure to receive the SRTP setting
Returns
PJ_SUCCESS on success.

◆ pjmedia_transport_srtp_modify_setting()

pj_status_t pjmedia_transport_srtp_modify_setting ( pjmedia_transport srtp,
const pjmedia_srtp_setting opt 
)

Modify SRTP media transport setting.

Parameters
srtpThe SRTP transport.
optNew setting
Returns
PJ_SUCCESS on success.

◆ pjmedia_transport_srtp_dtls_get_fingerprint()

pj_status_t pjmedia_transport_srtp_dtls_get_fingerprint ( pjmedia_transport srtp,
const char *  hash,
char *  buf,
pj_size_t len 
)

Get fingerprint of local DTLS-SRTP certificate.

Parameters
srtpThe SRTP transport.
hashFingerprint hash algorithm, currently valid values are "SHA-256" and "SHA-1".
bufBuffer for fingerprint output. The output will be formatted as "SHA-256/1 XX:XX:XX..." and null terminated.
lenOn input, the size of the buffer. On output, the length of the fingerprint.
Returns
PJ_SUCCESS on success.

◆ pjmedia_transport_srtp_dtls_start_nego()

pj_status_t pjmedia_transport_srtp_dtls_start_nego ( pjmedia_transport srtp,
const pjmedia_srtp_dtls_nego_param param 
)

Manually start DTLS-SRTP negotiation with the given parameters. Application only needs to call this function when the SRTP transport is used without SDP offer/answer. When SDP offer/answer framework is used, the DTLS-SRTP negotiation will be handled by pjmedia_transport_media_create(), pjmedia_transport_media_start(), pjmedia_transport_media_encode_sdp(), and pjmedia_transport_media_stop().

When the negotiation completes, application will be notified via SRTP callback on_srtp_nego_complete(), if set. If the negotiation is successful, SRTP will be automatically started.

Note that if the SRTP member transport is an ICE transport, application should only call this function after ICE negotiation is completed successfully.

Parameters
srtpThe SRTP transport.
paramDTLS-SRTP nego parameter.
Returns
PJ_SUCCESS on success.

◆ pjmedia_transport_srtp_start()

pj_status_t pjmedia_transport_srtp_start ( pjmedia_transport srtp,
const pjmedia_srtp_crypto tx,
const pjmedia_srtp_crypto rx 
)

Manually start SRTP session with the given parameters. Application only needs to call this function when the SRTP transport is used without SDP offer/answer. When SDP offer/answer framework is used, the SRTP transport will be started/stopped by pjmedia_transport_media_start() and pjmedia_transport_media_stop() respectively.

Please note that even if an RTP stream is only one direction, application will still need to provide both crypto suites, because it is needed by RTCP.

If application specifies the crypto keys, the keys for transmit and receive direction MUST be different.

Parameters
srtpThe SRTP transport.
txCrypto suite setting for transmit direction.
rxCrypto suite setting for receive direction.
Returns
PJ_SUCCESS on success.

◆ pjmedia_transport_srtp_stop()

pj_status_t pjmedia_transport_srtp_stop ( pjmedia_transport srtp)

Stop SRTP session.

Parameters
srtpThe SRTP media transport.
Returns
PJ_SUCCESS on success.
See also
pjmedia_transport_srtp_start()

◆ pjmedia_transport_srtp_decrypt_pkt()

pj_status_t pjmedia_transport_srtp_decrypt_pkt ( pjmedia_transport tp,
pj_bool_t  is_rtp,
void *  pkt,
int *  pkt_len 
)

This is a utility function to decrypt SRTP packet using SRTP transport. This function is not part of SRTP transport's API, but it can be used to decrypt SRTP packets from non-network (for example, from a saved file) without having to use the transport framework. See pcaputil.c in the samples collection on how to use this function.

Parameters
tpThe SRTP transport.
is_rtpSet to non-zero if the packet is SRTP, otherwise set to zero if the packet is SRTCP.
pktOn input, it contains SRTP or SRTCP packet. On output, it contains the decrypted RTP/RTCP packet.
pkt_lenOn input, specify the length of the buffer. On output, it will be filled with the actual length of decrypted packet.
Returns
PJ_SUCCESS on success.

◆ pjmedia_transport_srtp_get_member()

pjmedia_transport * pjmedia_transport_srtp_get_member ( pjmedia_transport srtp)

Query member transport of SRTP.

Parameters
srtpThe SRTP media transport.
Returns
member media transport.

References PJ_END_DECL.

 


PJMEDIA small footprint Open Source media stack
Copyright (C) 2006-2008 Teluu Inc.