00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef OPAL_RTP_SRTP_H
00035 #define OPAL_RTP_SRTP_H
00036
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040
00041 #ifndef _PTLIB_H
00042 #include <ptlib.h>
00043 #endif
00044
00045 #include <opal/buildopts.h>
00046
00047 #include <rtp/rtp.h>
00048 #include <rtp/rtpconn.h>
00049
00050 #if OPAL_SRTP
00051
00052 class OpalSRTPCryptoSuite;
00053
00054
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 struct OpalSRTPKeyInfo : public OpalMediaCryptoKeyInfo {
00070 public:
00071 OpalSRTPKeyInfo(const OpalSRTPCryptoSuite & cryptoSuite);
00072
00073 PObject * Clone() const;
00074
00075 virtual bool IsValid() const;
00076 virtual void Randomise();
00077 virtual bool FromString(const PString & str);
00078 virtual PString ToString() const;
00079
00080 bool SetCipherKey(const PBYTEArray & key);
00081 bool SetAuthSalt(const PBYTEArray & key);
00082
00083 PBYTEArray GetCipherKey() const { return m_key; }
00084 PBYTEArray GetAuthSalt() const { return m_salt; }
00085
00086 const OpalSRTPCryptoSuite & GetCryptoSuite() const { return m_cryptoSuite; }
00087
00088 protected:
00089 const OpalSRTPCryptoSuite & m_cryptoSuite;
00090 PBYTEArray m_key;
00091 PBYTEArray m_salt;
00092 };
00093
00094
00095 class OpalSRTPCryptoSuite : public OpalMediaCryptoSuite
00096 {
00097 PCLASSINFO(OpalSRTPCryptoSuite, OpalMediaCryptoSuite);
00098 protected:
00099 OpalSRTPCryptoSuite() { }
00100
00101 public:
00102 virtual bool Supports(const PCaselessString & proto) const;
00103 virtual bool ChangeSessionType(PCaselessString & mediaSession) const;
00104
00105 virtual OpalMediaCryptoKeyInfo * CreateKeyInfo() const;
00106
00107 virtual PINDEX GetCipherKeyBits() const = 0;
00108 virtual PINDEX GetAuthSaltBits() const = 0;
00109
00110 virtual void SetCryptoPolicy(struct crypto_policy_t & policy) const = 0;
00111 };
00112
00113 class OpalLibSRTP
00114 {
00115 protected:
00116 OpalLibSRTP();
00117 ~OpalLibSRTP();
00118
00119 bool ProtectRTP(RTP_DataFrame & frame);
00120 bool ProtectRTCP(RTP_ControlFrame & frame);
00121 bool UnprotectRTP(RTP_DataFrame & frame);
00122 bool UnprotectRTCP(RTP_ControlFrame & frame);
00123
00124 struct Context;
00125 Context * m_rx;
00126 Context * m_tx;
00127 };
00128
00129
00132 class OpalSRTPSession : public OpalRTPSession, OpalLibSRTP
00133 {
00134 PCLASSINFO(OpalSRTPSession, OpalRTPSession);
00135 public:
00136 static const PCaselessString & RTP_SAVP();
00137 static const PCaselessString & RTP_SAVPF();
00138
00139 OpalSRTPSession(const Init & init);
00140 ~OpalSRTPSession();
00141
00142 virtual const PCaselessString & GetSessionType() const { return RTP_SAVP(); }
00143 virtual bool Close();
00144 virtual OpalMediaCryptoKeyList & GetOfferedCryptoKeys();
00145 virtual bool ApplyCryptoKey(OpalMediaCryptoKeyList & keys, bool rx);
00146
00147 virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame);
00148 virtual SendReceiveStatus OnSendControl(RTP_ControlFrame & frame);
00149 virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
00150 virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
00151 };
00152
00153
00154 #endif // OPAL_SRTP
00155
00156 #endif // OPAL_RTP_SRTP_H