OPAL  Version 3.14.3
srtp_session.h
Go to the documentation of this file.
1 /*
2  * srtp_session.h
3  *
4  * SRTP protocol session handler
5  *
6  * OPAL Library
7  *
8  * Copyright (C) 2012 Vox Lucida Pty. Ltd.
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 Vox Lucida
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 32177 $
27  * $Author: rjongbloed $
28  * $Date: 2014-06-19 12:50:25 +1000 (Thu, 19 Jun 2014) $
29  */
30 
31 #ifndef OPAL_RTP_SRTP_SESSION_H
32 #define OPAL_RTP_SRTP_SESSION_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #ifndef _PTLIB_H
39 #include <ptlib.h>
40 #endif
41 
42 #include <opal_config.h>
43 
44 #include <rtp/rtp.h>
45 #include <rtp/rtpconn.h>
46 
47 #if OPAL_SRTP
48 
49 class OpalSRTPCryptoSuite;
50 
51 
53 //
54 // this class holds the parameters required for an SRTP session
55 //
56 // Crypto modes are identified by key strings that are contained in PFactory<OpalSRTPParms>
57 // The following strings should be implemented:
58 //
59 // AES_CM_128_HMAC_SHA1_80,
60 // AES_CM_128_HMAC_SHA1_32,
61 // AES_CM_128_NULL_AUTH,
62 // NULL_CIPHER_HMAC_SHA1_80
63 // STRONGHOLD
64 //
65 
66 struct OpalSRTPKeyInfo : public OpalMediaCryptoKeyInfo {
67  public:
68  OpalSRTPKeyInfo(const OpalSRTPCryptoSuite & cryptoSuite);
69 
70  PObject * Clone() const;
71 
72  virtual bool IsValid() const;
73  virtual void Randomise();
74  virtual bool FromString(const PString & str);
75  virtual PString ToString() const;
76  virtual bool SetCipherKey(const PBYTEArray & key);
77  virtual bool SetAuthSalt(const PBYTEArray & key);
78  virtual PBYTEArray GetCipherKey() const;
79  virtual PBYTEArray GetAuthSalt() const;
80 
81  const OpalSRTPCryptoSuite & GetCryptoSuite() const { return m_cryptoSuite; }
82 
83  protected:
84  const OpalSRTPCryptoSuite & m_cryptoSuite;
85  PBYTEArray m_key;
86  PBYTEArray m_salt;
87 };
88 
89 
90 class OpalSRTPCryptoSuite : public OpalMediaCryptoSuite
91 {
92  PCLASSINFO(OpalSRTPCryptoSuite, OpalMediaCryptoSuite);
93  protected:
94  OpalSRTPCryptoSuite() { }
95 
96  public:
97 #if OPAL_H235_8
98  virtual H235SecurityCapability * CreateCapability(const H323Capability & mediaCapability) const;
99 #endif
100  virtual bool Supports(const PCaselessString & proto) const;
101  virtual bool ChangeSessionType(PCaselessString & mediaSession) const;
102 
103  virtual OpalMediaCryptoKeyInfo * CreateKeyInfo() const;
104 
105  virtual void SetCryptoPolicy(struct crypto_policy_t & policy) const = 0;
106 };
107 
108 class OpalLibSRTP
109 {
110  protected:
111  OpalLibSRTP();
112  ~OpalLibSRTP();
113 
114  bool ProtectRTP(RTP_DataFrame & frame);
115  bool ProtectRTCP(RTP_ControlFrame & frame);
116  bool UnprotectRTP(RTP_DataFrame & frame);
117  bool UnprotectRTCP(RTP_ControlFrame & frame);
118 
119  struct Context;
120  Context * m_rx;
121  Context * m_tx;
122 };
123 
124 
127 class OpalSRTPSession : public OpalRTPSession, OpalLibSRTP
128 {
129  PCLASSINFO(OpalSRTPSession, OpalRTPSession);
130  public:
131  static const PCaselessString & RTP_SAVP();
132  static const PCaselessString & RTP_SAVPF();
133 
134  OpalSRTPSession(const Init & init);
135  ~OpalSRTPSession();
136 
137  virtual const PCaselessString & GetSessionType() const { return RTP_SAVP(); }
138  virtual bool Close();
140  virtual bool ApplyCryptoKey(OpalMediaCryptoKeyList & keys, bool rx);
141  virtual bool IsCryptoSecured(bool rx) const;
142 
143  virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame, bool rewriteHeader);
144  virtual SendReceiveStatus OnSendControl(RTP_ControlFrame & frame);
145  virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
146  virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
147 };
148 
149 
150 #endif // OPAL_SRTP
151 
152 #endif // OPAL_RTP_SRTP_SESSION_H