|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: SRTP session class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __SRTP_SESSION_H__ |
|
22 #define __SRTP_SESSION_H__ |
|
23 |
|
24 // INCLUDES |
|
25 #include <in_sock.h> |
|
26 // FORWARD DECLARATIONS |
|
27 class CSRTPStream; |
|
28 class CSRTPCryptoContext; |
|
29 class MSRTPReKeyingObserver; |
|
30 |
|
31 /** |
|
32 * Contains an SRTP session |
|
33 */ |
|
34 class CSRTPSession : public CBase |
|
35 { |
|
36 public: // construction |
|
37 /** |
|
38 * Two-phased constructor. |
|
39 * Use this function if each stream will have its own cryptographic |
|
40 * context. |
|
41 * @param aDestination The destination address, including the port. |
|
42 * @leave KErrNone if success, system-wide error code otherwise |
|
43 */ |
|
44 IMPORT_C static CSRTPSession* NewL(const TInetAddr& aDestination ); |
|
45 |
|
46 /** |
|
47 * Two-phased constructor. |
|
48 * Use this function if all streams will use the same cryptographic |
|
49 * context. |
|
50 * @param aDestination The destination address, including the port |
|
51 * @param aCon The default cryptographic context for the session, |
|
52 * ownership is transferred. |
|
53 * @param aObs The callback object |
|
54 * @leave KErrNone if success, system-wide error code otherwise |
|
55 */ |
|
56 IMPORT_C static CSRTPSession* NewL( const TInetAddr& aDestination, |
|
57 CSRTPCryptoContext* aCon, |
|
58 MSRTPReKeyingObserver& aObs ); |
|
59 |
|
60 /** |
|
61 * Two-phased constructor. Creates a new CSRTPSession instance |
|
62 * and pushes it to CleanupStack. |
|
63 * Use this function if each stream will have its own cryptographic |
|
64 * context. |
|
65 * @param aDestination The destination address, including the port. |
|
66 * @leave KErrNone if success, system-wide error code otherwise |
|
67 */ |
|
68 IMPORT_C static CSRTPSession* NewLC(const TInetAddr& aDestination ); |
|
69 |
|
70 /** |
|
71 * Two-phased constructor. Creates a new CSRTPSession instance |
|
72 * and pushes it to CleanupStack. |
|
73 * Use this function if all streams will use the same cryptographic |
|
74 * context. |
|
75 * @param aDestination The destination address, including the port |
|
76 * @param aCon The default cryptographic context for the session, |
|
77 * ownership is transferred. |
|
78 * @param aObs The callback object |
|
79 * @leave KErrNone if success, system-wide error code otherwise |
|
80 */ |
|
81 IMPORT_C static CSRTPSession* NewLC(const TInetAddr& aDestination, |
|
82 CSRTPCryptoContext* aCon, |
|
83 MSRTPReKeyingObserver& aObs); |
|
84 /** |
|
85 * Destructor, remove and delete all the stream in the session |
|
86 */ |
|
87 ~CSRTPSession(); |
|
88 |
|
89 /** |
|
90 * Retrieve CSSRTPStream object associated with given SSRC. |
|
91 * Note that if there are any duplicates the first one is returned. |
|
92 * Otherwise, Multiple SRTP streams with identical SSRCs and with same |
|
93 * stream type (In/Out stream) are not supported. |
|
94 * @param aSSRC - [input] SSRC of interest |
|
95 * @param aInInStream - True if stream type is CStreamIn, False otherwise |
|
96 * @return CSSRTPStream object if successful; Leave if not found. |
|
97 */ |
|
98 IMPORT_C CSRTPStream& StreamL(TUint aSSRC, TBool aIsInStream); |
|
99 |
|
100 /** |
|
101 * Session should find the match stream and protect stream |
|
102 * Note that if there are no matching stream, the function leave |
|
103 * @param aSSRC - [input] SSRC of interest |
|
104 * @param aPacket - [input] packet to be protected, the length of descriptor |
|
105 * should be the same with the actual data, otherwise encoding will not be |
|
106 * correct. |
|
107 * @return HBufC8 protected packet |
|
108 */ |
|
109 IMPORT_C HBufC8* ProtectRTPL(TUint aSSRC, const TDesC8& aPacket); |
|
110 |
|
111 |
|
112 /** |
|
113 * Session should find the match stream and protect packet |
|
114 * Note that if there are no matching stream, the function leave |
|
115 * @param aSSRC - [input] SSRC of interest |
|
116 * @param aPacket - [input] packet to be protected, the length of descriptor |
|
117 * should be the same with the actual data. |
|
118 * @return HBufC8 protected packet |
|
119 */ |
|
120 IMPORT_C HBufC8* ProtectRTCPL(TUint aSSRC, const TDesC8& aPacket); |
|
121 |
|
122 |
|
123 /** |
|
124 * SRTPSession find the match stream and unprotect stream |
|
125 * Note that if there are no matching stream, the function leave |
|
126 * In late binding cases, session will try to find the stream |
|
127 * which SSRC is equal to zero and unprotect the packet. |
|
128 * If the autenticate for the packet is successful, SSRC will be set to this stream. |
|
129 * @param aSSRC - [input] SSRC of interest |
|
130 * @param aPacket - [input] packet to be Unprotected |
|
131 * @return HBufC8 Unprotected packet |
|
132 */ |
|
133 IMPORT_C HBufC8* UnprotectRTPL(TUint aSSRC, const TDesC8& aPacket); |
|
134 |
|
135 /** |
|
136 * SRTPSession find the match stream and unprotect packet |
|
137 * Note that if there are no matching stream, the function leaves |
|
138 * SRTP must have been recive earlier otherwise the function will leave |
|
139 * with KErrNotFound--no SSRC matching stream found |
|
140 * Note that the streamIn must have to be created to receive RTCP report if |
|
141 * there is only one streamOut. |
|
142 * @param aSSRC - [input] SSRC of interest |
|
143 * @param aPacket - [input] packet to be Unprotected |
|
144 * @return HBufC8 Unprotected packet |
|
145 */ |
|
146 IMPORT_C HBufC8* UnprotectRTCPL(TUint aSSRC, const TDesC8& aPacket); |
|
147 |
|
148 /** |
|
149 * Return the destination address set in NewL |
|
150 * @return aDestination The destination address, including the port. |
|
151 */ |
|
152 IMPORT_C const TInetAddr& RemoteAddr() ; |
|
153 |
|
154 /** |
|
155 * Set/Update crypto context sharing between streams |
|
156 * Crypto context ownershíp is transfered. |
|
157 * Note that to update crypto context, the states and the number of packets received |
|
158 * will be reset. ROC will not be re-intialized. This can be used |
|
159 * only when keys lifetime has not expired. |
|
160 * RFC 4568 6.5, 6.4 |
|
161 * @param CSRTPCryptoContext |
|
162 * @leave KErrNone if success, system-wide error code otherwise |
|
163 */ |
|
164 IMPORT_C void SetCryptoContextL(CSRTPCryptoContext* aCon); |
|
165 |
|
166 /** |
|
167 * Get cryptographic context associated for this session |
|
168 * @return CSRTPCryptoContext |
|
169 */ |
|
170 CSRTPCryptoContext& GetCryptoContext(); |
|
171 |
|
172 /** |
|
173 * Add given stream to the list of CSRTPStream objects |
|
174 * @param aStream The stream to be added to list |
|
175 * @return void |
|
176 */ |
|
177 void AddStreamToList(CSRTPStream *aStream); |
|
178 |
|
179 /** |
|
180 * Remove given stream from the list of CSRTPStream objects |
|
181 * @param aStream The stream to be removed |
|
182 * @return void |
|
183 */ |
|
184 void RemoveStreamFromList(CSRTPStream *aStream); |
|
185 |
|
186 /** |
|
187 * Call for Rekey |
|
188 * @param aStream the stream which needs to be rekey |
|
189 * @param aIsStrmCrypto True if stream has it's own crypto, false otherwise |
|
190 * @return void |
|
191 */ |
|
192 void ReKeyNeeded(const CSRTPStream& aStream, TBool aIsStrmCrypto); |
|
193 |
|
194 |
|
195 private: //methods |
|
196 |
|
197 CSRTPSession (const TInetAddr& aDestination, |
|
198 MSRTPReKeyingObserver& aObs); |
|
199 |
|
200 CSRTPSession(const TInetAddr& aDestination); |
|
201 |
|
202 void ConstructL ( CSRTPCryptoContext* aCon ); |
|
203 |
|
204 TBool FindStream(TUint aSSRC, TBool aIsInStream); |
|
205 |
|
206 HBufC8* FindLateBindingStreamAndUnprotectRTPL(TUint aSSRC, |
|
207 const TDesC8& aPacket); |
|
208 HBufC8* FindLateBindingStreamAndUnprotectRTCPL(TUint aSSRC, |
|
209 const TDesC8& aPacket); |
|
210 |
|
211 void RemoveAllStream( ); |
|
212 |
|
213 private: // from Array |
|
214 /** |
|
215 * iStreamLink, Link to list. |
|
216 */ |
|
217 TSglQueLink iStreamLink; |
|
218 |
|
219 /** |
|
220 * list of CSRTPStream objects |
|
221 */ |
|
222 TSglQue<CSRTPStream> iStreamList; |
|
223 |
|
224 /** |
|
225 * CSRTPStream iterator. |
|
226 */ |
|
227 TSglQueIter<CSRTPStream> iStreamIter; |
|
228 |
|
229 private: //data |
|
230 /* |
|
231 destination address |
|
232 */ |
|
233 const TInetAddr& iDestination; |
|
234 /* |
|
235 crypto context, owned |
|
236 */ |
|
237 CSRTPCryptoContext* iContext; |
|
238 /* |
|
239 observer (application) |
|
240 */ |
|
241 MSRTPReKeyingObserver* iObserver; |
|
242 |
|
243 TUint8 iStreamCount; |
|
244 |
|
245 protected: |
|
246 /* |
|
247 * Session is created with cryptographic context |
|
248 */ |
|
249 TBool iSesssionCrypto; |
|
250 /* |
|
251 * True if Rekey is called, False otherwise |
|
252 */ |
|
253 TBool iRekey; |
|
254 |
|
255 private: |
|
256 friend class CSRTPStream; |
|
257 #ifdef EUNIT_TESTING |
|
258 friend class UT_CSRTPSession; |
|
259 #endif |
|
260 |
|
261 }; |
|
262 |
|
263 #endif // __SRTP_SESSION_H__ |