sdp_srtp.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2006 - 2007, Mikael Magnusson
  5. *
  6. * Mikael Magnusson <mikma@users.sourceforge.net>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file sdp_srtp.h
  19. *
  20. * \brief SRTP and SDP Security descriptions
  21. *
  22. * Specified in RFC 4568
  23. * Specified in RFC 3711
  24. *
  25. * \author Mikael Magnusson <mikma@users.sourceforge.net>
  26. */
  27. #ifndef _SDP_SRTP_H
  28. #define _SDP_SRTP_H
  29. #include <asterisk/rtp_engine.h>
  30. struct ast_sdp_crypto;
  31. /*! \brief structure for secure RTP audio */
  32. struct ast_sdp_srtp {
  33. unsigned int flags;
  34. struct ast_sdp_crypto *crypto;
  35. };
  36. /* SRTP flags */
  37. #define AST_SRTP_CRYPTO_OFFER_OK (1 << 1)
  38. #define AST_SRTP_CRYPTO_TAG_32 (1 << 2)
  39. #define AST_SRTP_CRYPTO_TAG_80 (1 << 3)
  40. /*!
  41. * \brief allocate a ast_sdp_srtp structure
  42. * \retval a new malloc'd ast_sdp_srtp structure on success
  43. * \retval NULL on failure
  44. */
  45. struct ast_sdp_srtp *ast_sdp_srtp_alloc(void);
  46. /*!
  47. * \brief free a ast_sdp_srtp structure
  48. * \param srtp a ast_sdp_srtp structure
  49. */
  50. void ast_sdp_srtp_destroy(struct ast_sdp_srtp *srtp);
  51. /*! \brief Initialize an return an ast_sdp_crypto struct
  52. *
  53. * \details
  54. * This function allocates a new ast_sdp_crypto struct and initializes its values
  55. *
  56. * \retval NULL on failure
  57. * \retval a pointer to a new ast_sdp_crypto structure
  58. */
  59. struct ast_sdp_crypto *ast_sdp_crypto_alloc(void);
  60. /*! \brief Destroy a previously allocated ast_sdp_crypto struct */
  61. void ast_sdp_crypto_destroy(struct ast_sdp_crypto *crypto);
  62. /*! \brief Parse the a=crypto line from SDP and set appropriate values on the
  63. * ast_sdp_crypto struct.
  64. *
  65. * The attribute line should already have "a=crypto:" removed.
  66. *
  67. * \param p A valid ast_sdp_crypto struct
  68. * \param attr the a:crypto line from SDP
  69. * \param rtp The rtp instance associated with the SDP being parsed
  70. * \param srtp SRTP structure
  71. *
  72. * \retval 0 success
  73. * \retval nonzero failure
  74. */
  75. int ast_sdp_crypto_process(struct ast_rtp_instance *rtp, struct ast_sdp_srtp *srtp, const char *attr);
  76. /*! \brief Generate an SRTP a=crypto offer
  77. *
  78. * \details
  79. * The offer is stored on the ast_sdp_crypto struct in a_crypto
  80. *
  81. * \param p A valid ast_sdp_crypto struct
  82. * \param taglen Length
  83. *
  84. * \retval 0 success
  85. * \retval nonzero failure
  86. */
  87. int ast_sdp_crypto_build_offer(struct ast_sdp_crypto *p, int taglen);
  88. /*! \brief Get the crypto attribute line for the srtp structure
  89. *
  90. * The attribute line does not contain the initial "a=crypto:" and does
  91. * not terminate with "\r\n".
  92. *
  93. * \param srtp The ast_sdp_srtp structure for which to get an attribute line
  94. * \param dtls_enabled Whether this connection is encrypted with datagram TLS
  95. * \param default_taglen_32 Whether to default to a tag length of 32 instead of 80
  96. *
  97. * \retval An attribute line containing cryptographic information
  98. * \retval NULL if the srtp structure does not require an attribute line containing crypto information
  99. */
  100. const char *ast_sdp_srtp_get_attrib(struct ast_sdp_srtp *srtp, int dtls_enabled, int default_taglen_32);
  101. /*! \brief Get the RTP profile in use by a media session
  102. *
  103. * \param sdes_active Whether the media session is using SDES-SRTP
  104. * \param instance The RTP instance associated with this media session
  105. * \param using_avpf Whether the media session is using early feedback (AVPF)
  106. * \param force_avp Force SAVP or SAVPF profile when DTLS is in use
  107. *
  108. * \retval A non-allocated string describing the profile in use (does not need to be freed)
  109. */
  110. char *ast_sdp_get_rtp_profile(unsigned int sdes_active, struct ast_rtp_instance *instance, unsigned int using_avpf,
  111. unsigned int force_avp);
  112. #endif /* _SDP_CRYPTO_H */