OPAL  Version 3.12.9
srtp_session.h
Go to the documentation of this file.
1 /*
2  * srtp.h
3  *
4  * SRTP protocol handler
5  *
6  * OPAL Library
7  *
8  * Copyright (C) 2006 Post Increment
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is OPAL Library.
21  *
22  * The Initial Developer of the Original Code is Post Increment
23  * Portions of this code were written with the assistance of funding from
24  * US Joint Forces Command Joint Concept Development & Experimentation (J9)
25  * http://www.jfcom.mil/about/abt_j9.htm
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 28689 $
30  * $Author: rjongbloed $
31  * $Date: 2012-12-19 10:25:06 +1100 (Wed, 19 Dec 2012) $
32  */
33 
34 #ifndef OPAL_RTP_SRTP_H
35 #define OPAL_RTP_SRTP_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #ifndef _PTLIB_H
42 #include <ptlib.h>
43 #endif
44 
45 #include <opal/buildopts.h>
46 
47 #include <rtp/rtp.h>
48 #include <rtp/rtpconn.h>
49 
50 #if OPAL_SRTP
51 
52 class OpalSRTPCryptoSuite;
53 
54 
56 //
57 // this class holds the parameters required for an SRTP session
58 //
59 // Crypto modes are identified by key strings that are contained in PFactory<OpalSRTPParms>
60 // The following strings should be implemented:
61 //
62 // AES_CM_128_HMAC_SHA1_80,
63 // AES_CM_128_HMAC_SHA1_32,
64 // AES_CM_128_NULL_AUTH,
65 // NULL_CIPHER_HMAC_SHA1_80
66 // STRONGHOLD
67 //
68 
69 struct OpalSRTPKeyInfo : public OpalMediaCryptoKeyInfo {
70  public:
71  OpalSRTPKeyInfo(const OpalSRTPCryptoSuite & cryptoSuite);
72 
73  PObject * Clone() const;
74 
75  virtual bool IsValid() const;
76  virtual void Randomise();
77  virtual bool FromString(const PString & str);
78  virtual PString ToString() const;
79 
80  bool SetCipherKey(const PBYTEArray & key);
81  bool SetAuthSalt(const PBYTEArray & key);
82 
83  PBYTEArray GetCipherKey() const { return m_key; }
84  PBYTEArray GetAuthSalt() const { return m_salt; }
85 
86  const OpalSRTPCryptoSuite & GetCryptoSuite() const { return m_cryptoSuite; }
87 
88  protected:
89  const OpalSRTPCryptoSuite & m_cryptoSuite;
90  PBYTEArray m_key;
91  PBYTEArray m_salt;
92 };
93 
94 
95 class OpalSRTPCryptoSuite : public OpalMediaCryptoSuite
96 {
97  PCLASSINFO(OpalSRTPCryptoSuite, OpalMediaCryptoSuite);
98  protected:
99  OpalSRTPCryptoSuite() { }
100 
101  public:
102  virtual bool Supports(const PCaselessString & proto) const;
103  virtual bool ChangeSessionType(PCaselessString & mediaSession) const;
104 
105  virtual OpalMediaCryptoKeyInfo * CreateKeyInfo() const;
106 
107  virtual PINDEX GetCipherKeyBits() const = 0;
108  virtual PINDEX GetAuthSaltBits() const = 0;
109 
110  virtual void SetCryptoPolicy(struct crypto_policy_t & policy) const = 0;
111 };
112 
113 class OpalLibSRTP
114 {
115  protected:
116  OpalLibSRTP();
117  ~OpalLibSRTP();
118 
119  bool ProtectRTP(RTP_DataFrame & frame);
120  bool ProtectRTCP(RTP_ControlFrame & frame);
121  bool UnprotectRTP(RTP_DataFrame & frame);
122  bool UnprotectRTCP(RTP_ControlFrame & frame);
123 
124  struct Context;
125  Context * m_rx;
126  Context * m_tx;
127 };
128 
129 
132 class OpalSRTPSession : public OpalRTPSession, OpalLibSRTP
133 {
134  PCLASSINFO(OpalSRTPSession, OpalRTPSession);
135  public:
136  static const PCaselessString & RTP_SAVP();
137  static const PCaselessString & RTP_SAVPF();
138 
139  OpalSRTPSession(const Init & init);
140  ~OpalSRTPSession();
141 
142  virtual const PCaselessString & GetSessionType() const { return RTP_SAVP(); }
143  virtual bool Close();
145  virtual bool ApplyCryptoKey(OpalMediaCryptoKeyList & keys, bool rx);
146 
147  virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame);
148  virtual SendReceiveStatus OnSendControl(RTP_ControlFrame & frame);
149  virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
150  virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
151 };
152 
153 
154 #endif // OPAL_SRTP
155 
156 #endif // OPAL_RTP_SRTP_H