OPAL  Version 3.14.3
h235_session.h
Go to the documentation of this file.
1 /*
2  * h235_session.h
3  *
4  * H.235 encrypted RTP protocol session handler
5  *
6  * OPAL Library
7  *
8  * Copyright (C) 2013 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$
29  */
30 
31 #ifndef OPAL_RTP_H235_SESSION_H
32 #define OPAL_RTP_H235_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 #if OPAL_H235_6
45 
46 #include <rtp/rtp.h>
47 #include <rtp/rtpconn.h>
48 #include <ptclib/pssl.h>
49 
50 
51 class H2356_CryptoSuite;
52 
53 
55 //
56 // this class holds the parameters required for an AES session
57 //
58 // Crypto modes are identified by key strings that are contained in PFactory<OpalSRTPParms>
59 // The following strings should be implemented:
60 //
61 // AES_128, AES_192, AES_256
62 //
63 
64 struct H2356_KeyInfo : public OpalMediaCryptoKeyInfo {
65  public:
66  H2356_KeyInfo(const H2356_CryptoSuite & cryptoSuite);
67 
68  PObject * Clone() const;
69 
70  virtual bool IsValid() const;
71  virtual void Randomise();
72  virtual bool FromString(const PString & str);
73  virtual PString ToString() const;
74  virtual bool SetCipherKey(const PBYTEArray & key);
75  virtual bool SetAuthSalt(const PBYTEArray & key);
76  virtual PBYTEArray GetCipherKey() const;
77  virtual PBYTEArray GetAuthSalt() const;
78  virtual PINDEX GetAuthSaltBits() const { return 0; }
79 
80  const H2356_CryptoSuite & GetCryptoSuite() const { return m_cryptoSuite; }
81 
82  protected:
83  const H2356_CryptoSuite & m_cryptoSuite;
84  PBYTEArray m_key;
85 };
86 
87 
88 class H2356_CryptoSuite : public OpalMediaCryptoSuite
89 {
90  PCLASSINFO(H2356_CryptoSuite, OpalMediaCryptoSuite);
91  protected:
92  H2356_CryptoSuite() { }
93 
94  public:
95  virtual H235SecurityCapability * CreateCapability(const H323Capability & mediaCapability) const;
96  virtual bool Supports(const PCaselessString & proto) const;
97  virtual bool ChangeSessionType(PCaselessString & mediaSession) const;
98 
99  virtual OpalMediaCryptoKeyInfo * CreateKeyInfo() const;
100 
101  virtual PINDEX GetCipherKeyBits() const = 0;
102  virtual PINDEX GetAuthSaltBits() const { return 0; }
103 };
104 
107 class H2356_Session : public OpalRTPSession
108 {
109  PCLASSINFO(H2356_Session, OpalRTPSession);
110  public:
111  static const PCaselessString & SessionType();
112 
113  H2356_Session(const Init & init);
114  ~H2356_Session();
115 
116  virtual const PCaselessString & GetSessionType() const;
117  virtual bool Close();
119  virtual bool ApplyCryptoKey(OpalMediaCryptoKeyList & keys, bool rx);
120  virtual bool IsCryptoSecured(bool rx) const;
121 
122  virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame, bool rewriteHeader);
123  virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame, PINDEX pduSize);
124 
125  protected:
126  struct Context {
127  Context(bool encrypt) : m_keyInfo(NULL), m_cipher(encrypt) { }
128  ~Context() { delete m_keyInfo; }
129 
130  bool Open(H2356_KeyInfo & info);
131  bool PreProcess(RTP_DataFrame & frame);
132  bool Encrypt(RTP_DataFrame & frame);
133  bool Decrypt(RTP_DataFrame & frame);
134 
135  H2356_KeyInfo * m_keyInfo;
136  PSSLCipherContext m_cipher;
137  RTP_DataFrame m_buffer;
138  PBYTEArray m_iv;
139  } m_rx, m_tx;
140 };
141 
142 
143 #endif // OPAL_H235_6
144 
145 #endif // OPAL_RTP_H235_SESSION_H