# srtp_session.h

Go to the documentation of this file.

    00001 /*
    00002  * srtp.h
    00003  *
    00004  * SRTP protocol handler
    00005  *
    00006  * OPAL Library
    00007  *
    00008  * Copyright (C) 2006 Post Increment
    00009  *
    00010  * The contents of this file are subject to the Mozilla Public License
    00011  * Version 1.0 (the "License"); you may not use this file except in
    00012  * compliance with the License. You may obtain a copy of the License at
    00013  * http://www.mozilla.org/MPL/
    00014  *
    00015  * Software distributed under the License is distributed on an "AS IS"
    00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
    00017  * the License for the specific language governing rights and limitations
    00018  * under the License.
    00019  *
    00020  * The Original Code is OPAL Library.
    00021  *
    00022  * The Initial Developer of the Original Code is Post Increment
    00023  *     Portions of this code were written with the assistance of funding from
    00024  *     US Joint Forces Command Joint Concept Development & Experimentation (J9)
    00025  *     http://www.jfcom.mil/about/abt_j9.htm
    00026  *
    00027  * Contributor(s): ______________________________________.
    00028  *
    00029  * $Revision: 28689 $
    00030  * $Author: rjongbloed $
    00031  * $Date: 2012-12-18 17:25:06 -0600 (Tue, 18 Dec 2012) $
    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 //  this class holds the parameters required for an SRTP session
    00058 //
    00059 //  Crypto modes are identified by key strings that are contained in PFactory<OpalSRTPParms>
    00060 //  The following strings should be implemented:
    00061 //
    00062 //     AES_CM_128_HMAC_SHA1_80,
    00063 //     AES_CM_128_HMAC_SHA1_32,
    00064 //     AES_CM_128_NULL_AUTH,
    00065 //     NULL_CIPHER_HMAC_SHA1_80
    00066 //     STRONGHOLD
    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