Asterisk - The Open Source Telephony Project  18.5.0
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
apointer to a new ast_sdp_crypto structure

Definition at line 71 of file sdp_srtp.c.

References ast_sdp_crypto_api::alloc, and NULL.

Referenced by process_crypto(), and setup_srtp().

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

◆ 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.

References ast_sdp_crypto_api::build_offer.

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

◆ 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.

References ast_sdp_crypto_api::dtor.

Referenced by ast_sdp_srtp_destroy().

65 {
66  if (sdp_crypto_api) {
67  sdp_crypto_api->dtor(crypto);
68  }
69 }
static struct ast_sdp_crypto_api * sdp_crypto_api
Definition: sdp_srtp.c:39
sdp_crypto_destroy_cb dtor
Definition: sdp_srtp.h:128

◆ 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
pA valid ast_sdp_crypto struct
attrthe a:crypto line from SDP
rtpThe rtp instance associated with the SDP being parsed
srtpSRTP structure
Return values
0success
nonzerofailure

Definition at line 79 of file sdp_srtp.c.

References ast_sdp_crypto_api::parse_offer.

Referenced by process_crypto(), and setup_sdes_srtp().

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

◆ 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.

Referenced by res_srtp_init().

124 {
125  if (sdp_crypto_api) {
126  return -1;
127  }
128  sdp_crypto_api = api;
129  return 0;
130 }
static struct ast_sdp_crypto_api * sdp_crypto_api
Definition: sdp_srtp.c:39

◆ 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.
Returns
Nothing

Definition at line 132 of file sdp_srtp.c.

References NULL.

Referenced by res_srtp_shutdown().

133 {
134  if (sdp_crypto_api == api) {
136  }
137 }
static struct ast_sdp_crypto_api * sdp_crypto_api
Definition: sdp_srtp.c:39
#define NULL
Definition: resample.c:96

◆ 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
Return values
Anon-allocated string describing the profile in use (does not need to be freed)

Definition at line 103 of file sdp_srtp.c.

References ast_rtp_engine_dtls::active, and ast_rtp_instance_get_dtls().

Referenced by add_sdp(), and create_outgoing_sdp_stream().

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 }
Structure that represents the optional DTLS SRTP support within an RTP engine.
Definition: rtp_engine.h:570
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:3011
int(* active)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:574

◆ ast_sdp_srtp_alloc()

struct ast_sdp_srtp* ast_sdp_srtp_alloc ( void  )

allocate a ast_sdp_srtp structure

Return values
anew malloc'd ast_sdp_srtp structure on success
NULLon failure

Definition at line 41 of file sdp_srtp.c.

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

Referenced by add_crypto_to_stream(), dialog_initialize_dtls_srtp(), process_crypto(), process_sdp(), res_sdp_srtp_get_attr(), setup_srtp(), and sip_call().

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 }
structure for secure RTP audio
Definition: sdp_srtp.h:37
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
int ast_rtp_engine_srtp_is_registered(void)
Definition: rtp_engine.c:2731

◆ 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.

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 dialog_clean_rtp(), process_sdp(), session_media_dtor(), and sip_pvt_dtor().

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 }
structure for secure RTP audio
Definition: sdp_srtp.h:37
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
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:40
#define NULL
Definition: resample.c:96
struct ast_sdp_crypto * crypto
Definition: sdp_srtp.h:39
#define ast_free(a)
Definition: astmm.h:182
struct ast_sdp_srtp::@318 sdp_srtp_list

◆ 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
Return values
Anattribute line containing cryptographic information
NULLif the srtp structure does not require an attribute line containing crypto information

Definition at line 95 of file sdp_srtp.c.

References ast_sdp_crypto_api::get_attr, and NULL.

Referenced by add_crypto_to_stream(), and crypto_get_attrib().

96 {
97  if (!sdp_crypto_api) {
98  return NULL;
99  }
100  return sdp_crypto_api->get_attr(srtp, dtls_enabled, default_taglen_32);
101 }
static struct ast_sdp_crypto_api * sdp_crypto_api
Definition: sdp_srtp.c:39
#define NULL
Definition: resample.c:96
sdp_srtp_get_attr_cb get_attr
Definition: sdp_srtp.h:136

Variable Documentation

◆ sdp_crypto_api

struct ast_sdp_crypto_api* sdp_crypto_api
static

Registered SDP crypto API

Definition at line 39 of file sdp_srtp.c.