~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/audio/audiortp/AudioSrtpSession.h

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
13
 *  GNU General Public License for more details.
14
 
 * 
 
14
 *
15
15
 *  You should have received a copy of the GNU General Public License
16
16
 *  along with this program; if not, write to the Free Software
17
17
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
40
40
class ManagerImpl;
41
41
class SIPCall;
42
42
 
43
 
/* 
44
 
   Table from RFC 4568 6.2. Crypto-Suites, which define key parameters for supported 
 
43
/*
 
44
   Table from RFC 4568 6.2. Crypto-Suites, which define key parameters for supported
45
45
   cipher suite
46
46
 
47
47
   +---------------------+-------------+--------------+---------------+
64
64
*/
65
65
 
66
66
 
67
 
namespace sfl {
 
67
namespace sfl
 
68
{
68
69
 
69
 
    class SrtpException: public std::exception
70
 
    {
71
 
        virtual const char* what() const throw()
72
 
        {
73
 
        return "ZRTP ZID initialization failed.";
 
70
class SrtpException: public std::exception
 
71
{
 
72
        virtual const char* what() const throw() {
 
73
            return "ZRTP ZID initialization failed.";
74
74
        }
75
 
    };
76
 
 
77
 
    class AudioSrtpSession : public ost::SymmetricRTPSession, public AudioRtpSession<AudioSrtpSession> 
78
 
    {
79
 
        public:
80
 
 
81
 
            AudioSrtpSession(ManagerImpl * manager, SIPCall * sipcall);
82
 
 
83
 
            std::vector<std::string> getLocalCryptoInfo(void);
84
 
 
85
 
            void setRemoteCryptoInfo(sfl::SdesNegotiator& nego);
86
 
 
87
 
        private:
88
 
 
89
 
            void initializeLocalMasterKey(void);
90
 
 
91
 
            void initializeLocalMasterSalt(void);
92
 
 
93
 
            void initializeRemoteCryptoContext(void);
94
 
 
95
 
            void initializeLocalCryptoContext(void);
96
 
 
97
 
            std::string getBase64ConcatenatedKeys();
98
 
 
99
 
            void unBase64ConcatenatedKeys(std::string base64keys);
100
 
 
101
 
            char* encodeBase64(unsigned char *input, int length);
102
 
 
103
 
            char* decodeBase64(unsigned char *input, int length, int *length_out);
104
 
 
105
 
            /** Default local crypto suite is AES_CM_128_HMAC_SHA1_80*/
106
 
            int _localCryptoSuite;
107
 
 
108
 
            /** Remote crypto suite is initialized at AES_CM_128_HMAC_SHA1_80*/
109
 
            int _remoteCryptoSuite;
110
 
 
111
 
            uint8 _localMasterKey[16];
112
 
 
113
 
            /** local master key length in byte */
114
 
            int _localMasterKeyLength;
115
 
 
116
 
            uint8 _localMasterSalt[14];
117
 
 
118
 
            /** local master salt length in byte */
119
 
            int _localMasterSaltLength;
120
 
 
121
 
            uint8 _remoteMasterKey[16];
122
 
 
123
 
            /** remote master key length in byte */
124
 
            int _remoteMasterKeyLength;
125
 
 
126
 
            uint8 _remoteMasterSalt[14];
127
 
 
128
 
            /** remote master salt length in byte */
129
 
            int _remoteMasterSaltLength;
130
 
 
131
 
            ost::CryptoContext* _remoteCryptoCtx;
132
 
 
133
 
            ost::CryptoContext* _localCryptoCtx;
134
 
    };
135
 
   
 
75
};
 
76
 
 
77
class AudioSrtpSession : public AudioRtpSession
 
78
{
 
79
    public:
 
80
 
 
81
        /**
 
82
         * Constructor for this rtp session
 
83
         */
 
84
        AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall);
 
85
 
 
86
        ~AudioSrtpSession();
 
87
 
 
88
        /**
 
89
         * Used to get sdp crypto header to be included in sdp session. This
 
90
         * method must be called befor setRemoteCryptoInfo in case of an
 
91
         * outgoing call or after in case of an outgoing call.
 
92
         */
 
93
        std::vector<std::string> getLocalCryptoInfo (void);
 
94
 
 
95
        /**
 
96
         * Set remote crypto header from incoming sdp offer
 
97
         */
 
98
        void setRemoteCryptoInfo (sfl::SdesNegotiator& nego);
 
99
 
 
100
        /**
 
101
         * Init local crypto context for outgoing data
 
102
        * this method must be called before sending first Invite request
 
103
        * with SDP offer.
 
104
        */
 
105
        void initLocalCryptoInfo (void);
 
106
 
 
107
    private:
 
108
 
 
109
        /**
 
110
         * Init local master key according to current crypto context
 
111
         * as defined in SdesNegotiator.h
 
112
         */
 
113
        void initializeLocalMasterKey (void);
 
114
 
 
115
        /**
 
116
         * Init local master salt according to current crypto context
 
117
         * as defined in SdesNegotiator.h
 
118
         */
 
119
        void initializeLocalMasterSalt (void);
 
120
 
 
121
        /**
 
122
         * Init remote crypto context in audio srtp session. This method
 
123
         * must be called after unBase64ConcatenatedKeys.
 
124
         */
 
125
        void initializeRemoteCryptoContext (void);
 
126
 
 
127
        /**
 
128
         * Init local crypto context in audio srtp session. Make sure remote
 
129
         * crypto context is set before calling this method for incoming calls.
 
130
         */
 
131
        void initializeLocalCryptoContext (void);
 
132
 
 
133
        /**
 
134
         * Used to generate local keys to be included in SDP offer/answer.
 
135
         */
 
136
        std::string getBase64ConcatenatedKeys();
 
137
 
 
138
        /**
 
139
         * Used to retreive keys from base64 serialization
 
140
         */
 
141
        void unBase64ConcatenatedKeys (std::string base64keys);
 
142
 
 
143
        /**
 
144
         * Encode input data as base64
 
145
         */
 
146
        char* encodeBase64 (unsigned char *input, int length);
 
147
 
 
148
        /**
 
149
         * Decode base64 data
 
150
         */
 
151
        char* decodeBase64 (unsigned char *input, int length, int *length_out);
 
152
 
 
153
        /** Default local crypto suite is AES_CM_128_HMAC_SHA1_80*/
 
154
        int _localCryptoSuite;
 
155
 
 
156
        /** Remote crypto suite is initialized at AES_CM_128_HMAC_SHA1_80*/
 
157
        int _remoteCryptoSuite;
 
158
 
 
159
        uint8 _localMasterKey[16];
 
160
 
 
161
        /** local master key length in byte */
 
162
        int _localMasterKeyLength;
 
163
 
 
164
        uint8 _localMasterSalt[14];
 
165
 
 
166
        /** local master salt length in byte */
 
167
        int _localMasterSaltLength;
 
168
 
 
169
        uint8 _remoteMasterKey[16];
 
170
 
 
171
        /** remote master key length in byte */
 
172
        int _remoteMasterKeyLength;
 
173
 
 
174
        uint8 _remoteMasterSalt[14];
 
175
 
 
176
        /** remote master salt length in byte */
 
177
        int _remoteMasterSaltLength;
 
178
 
 
179
        /** Remote srtp crypto context to be set into incoming data queue. */
 
180
        ost::CryptoContext* _remoteCryptoCtx;
 
181
 
 
182
        /** Local srtp crypto context to be set into outgoing data queue. */
 
183
        ost::CryptoContext* _localCryptoCtx;
 
184
 
 
185
        /** Used to make sure remote crypto context not initialized wice. */
 
186
        bool _remoteOfferIsSet;
 
187
};
 
188
 
136
189
}
137
190
 
138
191
#endif // __AUDIO_SRTP_SESSION_H__