OPAL  Version 3.18.8
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 
27 #ifndef OPAL_RTP_H235_SESSION_H
28 #define OPAL_RTP_H235_SESSION_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #ifndef _PTLIB_H
35 #include <ptlib.h>
36 #endif
37 
38 #include <opal_config.h>
39 
40 #if OPAL_H235_6
41 
42 #include <rtp/rtp.h>
43 #include <rtp/rtpconn.h>
44 #include <ptclib/pssl.h>
45 
46 
47 class H2356_CryptoSuite;
48 
49 
50 #define H235_6_CODED_TO_CORRECT_SPECIFICATION 0
51 
52 
54 //
55 // this class holds the parameters required for an AES session
56 //
57 // Crypto modes are identified by key strings that are contained in PFactory<OpalSRTPParms>
58 // The following strings should be implemented:
59 //
60 // AES_128, AES_192, AES_256
61 //
62 
63 struct H2356_KeyInfo : public OpalMediaCryptoKeyInfo {
64  public:
65  H2356_KeyInfo(const H2356_CryptoSuite & cryptoSuite);
66 
67  virtual PObject * Clone() const;
68  virtual Comparison Compare(const PObject & other) 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, KeyExchangeModes modes) 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 OpalMediaCryptoKeyInfo * IsCryptoSecured(bool rx) const;
121 
122  virtual SendReceiveStatus OnSendData(RewriteMode & rewrite, RTP_DataFrame & frame, const PTime & now);
123  virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame, ReceiveType rxType, const PTime & now);
124  virtual bool IsEncrypted() const { return true; }
125 
126  protected:
127  struct Context {
128  Context(bool encrypt) : m_keyInfo(NULL), m_cipher(encrypt) { }
129  ~Context() { delete m_keyInfo; }
130 
131  bool Open(H2356_KeyInfo & info);
132  bool PreProcess(RTP_DataFrame & frame);
133  bool Encrypt(RTP_DataFrame & frame);
134  bool Decrypt(RTP_DataFrame & frame);
135 
136  H2356_KeyInfo * m_keyInfo;
137  PSSLCipherContext m_cipher;
138  RTP_DataFrame m_buffer;
139  PBYTEArray m_iv;
140  } m_rx, m_tx;
141 };
142 
143 
144 #endif // OPAL_H235_6
145 
146 #endif // OPAL_RTP_H235_SESSION_H
virtual bool Supports(const PCaselessString &proto) const =0
virtual bool ChangeSessionType(PCaselessString &mediaSession, KeyExchangeModes modes) const =0
const OpalMediaCryptoSuite & m_cryptoSuite
Definition: mediasession.h:308
Definition: h323caps.h:95
virtual bool SetAuthSalt(const PBYTEArray &key)=0
Definition: mediasession.h:321
Definition: mediasession.h:282
virtual PBYTEArray GetCipherKey() const =0
virtual PINDEX GetCipherKeyBits() const =0
Definition: rtp.h:540
Definition: mediasession.h:312
virtual OpalMediaCryptoKeyInfo * IsCryptoSecured(bool rx) const
virtual OpalMediaCryptoKeyInfo * CreateKeyInfo() const =0
virtual const PCaselessString & GetSessionType() const
Definition: rtp_session.h:111
Definition: rtp_session.h:90
virtual bool Close()
virtual OpalMediaCryptoKeyList & GetOfferedCryptoKeys()
virtual bool FromString(const PString &str)=0
virtual SendReceiveStatus OnSendData(RewriteMode &rewrite, RTP_DataFrame &frame, const PTime &now)
virtual PString ToString() const =0
virtual SendReceiveStatus OnReceiveData(RTP_DataFrame &frame, ReceiveType rxType, const PTime &now)
virtual void Randomise()=0
virtual bool ApplyCryptoKey(OpalMediaCryptoKeyList &keys, bool rx)
virtual bool IsEncrypted() const
Definition: rtp_session.h:273
virtual bool IsValid() const =0
const OpalMediaCryptoSuite & GetCryptoSuite() const
Definition: mediasession.h:302
virtual PBYTEArray GetAuthSalt() const =0
virtual PINDEX GetAuthSaltBits() const =0
virtual bool SetCipherKey(const PBYTEArray &key)=0