Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions | Variables
sdp_srtp.c File Reference

SRTP and SDP Security descriptions. More...

#include "asterisk.h"
#include "asterisk/linkedlists.h"
#include "asterisk/logger.h"
#include "asterisk/sdp_srtp.h"
Include dependency graph for sdp_srtp.c:

Go to the source code of this file.

Functions

struct ast_sdp_cryptoast_sdp_crypto_alloc (void)
 Initialize an return an ast_sdp_crypto struct. More...
 
int ast_sdp_crypto_build_offer (struct ast_sdp_crypto *p, int taglen)
 Generate an SRTP a=crypto offer. More...
 
void ast_sdp_crypto_destroy (struct ast_sdp_crypto *crypto)
 Destroy a previously allocated ast_sdp_crypto struct. More...
 
int ast_sdp_crypto_process (struct ast_rtp_instance *rtp, struct ast_sdp_srtp *srtp, const char *attr)
 Parse the a=crypto line from SDP and set appropriate values on the ast_sdp_crypto struct. More...
 
int ast_sdp_crypto_register (struct ast_sdp_crypto_api *api)
 Register SDP SRTP crypto processing routines. More...
 
void ast_sdp_crypto_unregister (struct ast_sdp_crypto_api *api)
 Unregister SDP SRTP crypto processing routines. More...
 
char * ast_sdp_get_rtp_profile (unsigned int sdes_active, struct ast_rtp_instance *instance, unsigned int using_avpf, unsigned int force_avp)
 Get the RTP profile in use by a media session. More...
 
struct ast_sdp_srtpast_sdp_srtp_alloc (void)
 allocate a ast_sdp_srtp structure More...
 
void ast_sdp_srtp_destroy (struct ast_sdp_srtp *srtp)
 free a ast_sdp_srtp structure More...
 
const char * ast_sdp_srtp_get_attrib (struct ast_sdp_srtp *srtp, int dtls_enabled, int default_taglen_32)
 Get the crypto attribute line for the srtp structure. More...
 

Variables

static struct ast_sdp_crypto_apisdp_crypto_api
 

Detailed Description

SRTP and SDP Security descriptions.

Specified in RFC 3711, 6188, 7714, and 4568

Author
Mikael Magnusson mikma.nosp@m.@use.nosp@m.rs.so.nosp@m.urce.nosp@m.forge.nosp@m..net

Definition in file sdp_srtp.c.

Function Documentation

◆ ast_sdp_crypto_alloc()

struct ast_sdp_crypto * ast_sdp_crypto_alloc ( void  )

Initialize an return an ast_sdp_crypto struct.

This function allocates a new ast_sdp_crypto struct and initializes its values

Return values
NULLon failure
Returns
a pointer to a new ast_sdp_crypto structure

Definition at line 71 of file sdp_srtp.c.

72{
73 if (!sdp_crypto_api) {
74 return NULL;
75 }
76 return sdp_crypto_api->alloc();
77}
#define NULL
Definition: resample.c:96
static struct ast_sdp_crypto_api * sdp_crypto_api
Definition: sdp_srtp.c:39
sdp_crypto_alloc_cb alloc
Definition: sdp_srtp.h:130

References ast_sdp_crypto_api::alloc, NULL, and sdp_crypto_api.

Referenced by setup_srtp().

◆ ast_sdp_crypto_build_offer()

int ast_sdp_crypto_build_offer ( struct ast_sdp_crypto p,
int  taglen 
)

Generate an SRTP a=crypto offer.

The offer is stored on the ast_sdp_crypto struct in a_crypto

Parameters
pA valid ast_sdp_crypto struct
taglenLength
Return values
0success
nonzerofailure

Definition at line 87 of file sdp_srtp.c.

88{
89 if (!sdp_crypto_api) {
90 return -1;
91 }
92 return sdp_crypto_api->build_offer(p, taglen);
93}
sdp_crypto_build_offer_cb build_offer
Definition: sdp_srtp.h:132

References ast_sdp_crypto_api::build_offer, and sdp_crypto_api.

◆ ast_sdp_crypto_destroy()

void ast_sdp_crypto_destroy ( struct ast_sdp_crypto crypto)

Destroy a previously allocated ast_sdp_crypto struct.

Definition at line 64 of file sdp_srtp.c.

65{
66 if (sdp_crypto_api) {
67 sdp_crypto_api->dtor(crypto);
68 }
69}
sdp_crypto_destroy_cb dtor
Definition: sdp_srtp.h:128

References ast_sdp_srtp::crypto, ast_sdp_crypto_api::dtor, and sdp_crypto_api.

Referenced by ast_sdp_srtp_destroy().

◆ ast_sdp_crypto_process()

int ast_sdp_crypto_process ( struct ast_rtp_instance rtp,
struct ast_sdp_srtp srtp,
const char *  attr 
)

Parse the a=crypto line from SDP and set appropriate values on the ast_sdp_crypto struct.

The attribute line should already have "a=crypto:" removed.

Parameters
rtpThe rtp instance associated with the SDP being parsed
srtpSRTP structure
attrthe a:crypto line from SDP
Return values
0success
nonzerofailure

Definition at line 79 of file sdp_srtp.c.

80{
81 if (!sdp_crypto_api) {
82 return -1;
83 }
84 return sdp_crypto_api->parse_offer(rtp, srtp, attr);
85}
sdp_crypto_parse_offer_cb parse_offer
Definition: sdp_srtp.h:134

References ast_sdp_crypto_api::parse_offer, and sdp_crypto_api.

Referenced by setup_sdes_srtp().

◆ ast_sdp_crypto_register()

int ast_sdp_crypto_register ( struct ast_sdp_crypto_api api)

Register SDP SRTP crypto processing routines.

Since
14.0.0
Parameters
apiCallbacks to register.
Return values
0on success.
-1on error.

Definition at line 123 of file sdp_srtp.c.

124{
125 if (sdp_crypto_api) {
126 return -1;
127 }
128 sdp_crypto_api = api;
129 return 0;
130}

References sdp_crypto_api.

Referenced by res_srtp_init().

◆ ast_sdp_crypto_unregister()

void ast_sdp_crypto_unregister ( struct ast_sdp_crypto_api api)

Unregister SDP SRTP crypto processing routines.

Since
14.0.0
Parameters
apiCallbacks to unregister.

Definition at line 132 of file sdp_srtp.c.

133{
134 if (sdp_crypto_api == api) {
136 }
137}

References NULL, and sdp_crypto_api.

Referenced by res_srtp_shutdown().

◆ ast_sdp_get_rtp_profile()

char * ast_sdp_get_rtp_profile ( unsigned int  sdes_active,
struct ast_rtp_instance instance,
unsigned int  using_avpf,
unsigned int  force_avp 
)

Get the RTP profile in use by a media session.

Parameters
sdes_activeWhether the media session is using SDES-SRTP
instanceThe RTP instance associated with this media session
using_avpfWhether the media session is using early feedback (AVPF)
force_avpForce SAVP or SAVPF profile when DTLS is in use
Returns
A non-allocated string describing the profile in use (does not need to be freed)

Definition at line 103 of file sdp_srtp.c.

105{
106 struct ast_rtp_engine_dtls *dtls;
107
108 if ((dtls = ast_rtp_instance_get_dtls(instance)) && dtls->active(instance)) {
109 if (force_avp) {
110 return using_avpf ? "RTP/SAVPF" : "RTP/SAVP";
111 } else {
112 return using_avpf ? "UDP/TLS/RTP/SAVPF" : "UDP/TLS/RTP/SAVP";
113 }
114 } else {
115 if (using_avpf) {
116 return sdes_active ? "RTP/SAVPF" : "RTP/AVPF";
117 } else {
118 return sdes_active ? "RTP/SAVP" : "RTP/AVP";
119 }
120 }
121}
struct ast_rtp_engine_dtls * ast_rtp_instance_get_dtls(struct ast_rtp_instance *instance)
Obtain a pointer to the DTLS support present on an RTP instance.
Definition: rtp_engine.c:3211
Structure that represents the optional DTLS SRTP support within an RTP engine.
Definition: rtp_engine.h:621
int(* active)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:625

References ast_rtp_engine_dtls::active, and ast_rtp_instance_get_dtls().

Referenced by create_outgoing_sdp_stream().

◆ ast_sdp_srtp_alloc()

struct ast_sdp_srtp * ast_sdp_srtp_alloc ( void  )

allocate a ast_sdp_srtp structure

Returns
a new malloc'd ast_sdp_srtp structure on success
Return values
NULLon failure

Definition at line 41 of file sdp_srtp.c.

42{
44 ast_debug(1, "No SRTP module loaded, can't setup SRTP session.\n");
45 return NULL;
46 }
47
48 return ast_calloc(1, sizeof(struct ast_sdp_srtp));
49}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_debug(level,...)
Log a DEBUG message.
int ast_rtp_engine_srtp_is_registered(void)
Definition: rtp_engine.c:2931
structure for secure RTP audio
Definition: sdp_srtp.h:38

References ast_calloc, ast_debug, ast_rtp_engine_srtp_is_registered(), and NULL.

Referenced by add_crypto_to_stream(), res_sdp_srtp_get_attr(), and setup_srtp().

◆ ast_sdp_srtp_destroy()

void ast_sdp_srtp_destroy ( struct ast_sdp_srtp srtp)

free a ast_sdp_srtp structure

Parameters
srtpa ast_sdp_srtp structure

Definition at line 51 of file sdp_srtp.c.

52{
53 struct ast_sdp_srtp *next;
54
55 for (next = AST_LIST_NEXT(srtp, sdp_srtp_list);
56 srtp;
57 srtp = next, next = srtp ? AST_LIST_NEXT(srtp, sdp_srtp_list) : NULL) {
59 srtp->crypto = NULL;
60 ast_free(srtp);
61 }
62}
#define ast_free(a)
Definition: astmm.h:180
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
void ast_sdp_crypto_destroy(struct ast_sdp_crypto *crypto)
Destroy a previously allocated ast_sdp_crypto struct.
Definition: sdp_srtp.c:64
struct ast_sdp_srtp * next
Definition: sdp_srtp.h:41
struct ast_sdp_srtp::@278 sdp_srtp_list
struct ast_sdp_crypto * crypto
Definition: sdp_srtp.h:40

References ast_free, AST_LIST_NEXT, ast_sdp_crypto_destroy(), ast_sdp_srtp::crypto, ast_sdp_srtp::next, NULL, and ast_sdp_srtp::sdp_srtp_list.

Referenced by session_media_dtor().

◆ ast_sdp_srtp_get_attrib()

const char * ast_sdp_srtp_get_attrib ( struct ast_sdp_srtp srtp,
int  dtls_enabled,
int  default_taglen_32 
)

Get the crypto attribute line for the srtp structure.

The attribute line does not contain the initial "a=crypto:" and does not terminate with "\r\n".

Parameters
srtpThe ast_sdp_srtp structure for which to get an attribute line
dtls_enabledWhether this connection is encrypted with datagram TLS
default_taglen_32Whether to default to a tag length of 32 instead of 80
Returns
An attribute line containing cryptographic information
Return values
NULLif the srtp structure does not require an attribute line containing crypto information

Definition at line 95 of file sdp_srtp.c.

96{
97 if (!sdp_crypto_api) {
98 return NULL;
99 }
100 return sdp_crypto_api->get_attr(srtp, dtls_enabled, default_taglen_32);
101}
sdp_srtp_get_attr_cb get_attr
Definition: sdp_srtp.h:136

References ast_sdp_crypto_api::get_attr, NULL, and sdp_crypto_api.

Referenced by add_crypto_to_stream().

Variable Documentation

◆ sdp_crypto_api

struct ast_sdp_crypto_api* sdp_crypto_api
static