|
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: Contains a default cryptographic context for SRTP/SRTCP streams. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __SRTP_CRYPTOCONTEXT_H__ |
|
22 #define __SRTP_CRYPTOCONTEXT_H__ |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include "srtpdef.h" |
|
27 #include <srtpcryptoparams.h> |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class CSRTPMasterKey; |
|
31 class CSRTPMasterSalt; |
|
32 class CSRTPCryptoHandler; |
|
33 class TSrtpCryptoParams; |
|
34 /** |
|
35 * Contains a cryptographic context. |
|
36 */ |
|
37 class CSRTPCryptoContext : public CBase |
|
38 { |
|
39 //public: // enumerations |
|
40 |
|
41 |
|
42 public: // Construction |
|
43 |
|
44 /** |
|
45 * Use this function if the stream will use the SRTP session's default |
|
46 * cryptographic context. CSrtpSession take the ownership of |
|
47 * CSRTPCryptoContext if CSrtpSession is created with CSRTPCryptoContext |
|
48 * as input parameter. |
|
49 * @param aKey The master key. |
|
50 * @param aSalt The master salt. |
|
51 * @param aCryptoParams. Crypto Context parameters. |
|
52 * @leave KErrNone if success, system-wide error code otherwise |
|
53 */ |
|
54 IMPORT_C static CSRTPCryptoContext* NewL( const CSRTPMasterKey* aKey, |
|
55 const CSRTPMasterSalt* aSalt, |
|
56 const TSrtpCryptoParams& aCryptoParams); |
|
57 |
|
58 /** |
|
59 * Use this function if the stream will use the SRTP session's default |
|
60 * cryptographic context. |
|
61 * @param aKey The master key. |
|
62 * @param aSalt The master salt. |
|
63 * @param aCryptoParams. Crypto Context parameters. |
|
64 * @leave KErrNone if success, system-wide error code otherwise |
|
65 */ |
|
66 IMPORT_C static CSRTPCryptoContext* NewLC( const CSRTPMasterKey* aKey, |
|
67 const CSRTPMasterSalt* aSalt, |
|
68 const TSrtpCryptoParams& aCryptoParams ); |
|
69 |
|
70 /** |
|
71 * Destructor |
|
72 * |
|
73 */ |
|
74 ~CSRTPCryptoContext(); |
|
75 |
|
76 /* |
|
77 * Gets current master key |
|
78 * @return CSRTPMasterKey |
|
79 */ |
|
80 IMPORT_C const CSRTPMasterKey& MasterKey() const; |
|
81 |
|
82 /* |
|
83 * Sets master key, the new master key will be used in encryptiuon |
|
84 * and decryption. The previous master key will be deleted. |
|
85 * @param aKey new master key |
|
86 */ |
|
87 IMPORT_C void SetMasterKey( const CSRTPMasterKey* aKey); |
|
88 |
|
89 /* |
|
90 * Gets current master salt |
|
91 * @return CSRTPMasterSalt |
|
92 */ |
|
93 IMPORT_C const CSRTPMasterSalt& MasterSalt() const; |
|
94 |
|
95 /* |
|
96 * Sets master salt, the new master salt key will be used in encryptiuon |
|
97 * and decryption. The previous master salt key will be deleted. |
|
98 * @param aSalt new master salt |
|
99 */ |
|
100 IMPORT_C void SetMasterSalt(const CSRTPMasterSalt* aSalt); |
|
101 |
|
102 |
|
103 /* |
|
104 * Check the validity of the whole TCryptoContext |
|
105 * @return validity of this CryptoContext |
|
106 */ |
|
107 IMPORT_C TBool Valid() const; |
|
108 |
|
109 /* |
|
110 * Gets CryptoParams |
|
111 * @return TSrtpCryptoParams Cryptocontext parameters |
|
112 */ |
|
113 IMPORT_C const TSrtpCryptoParams& CryptoParams() ; |
|
114 |
|
115 /* |
|
116 * Feeback from Applicaiton to indicate that if the local ROC is |
|
117 * synchronized with the sender in RCC mode3.If it is not set, |
|
118 * "Not-Synchronized" will be default. If it is synchronized, |
|
119 * the packet would hence be processed using the local ROC. |
|
120 * Defined in RFC srtp-rcc-04 section 4. |
|
121 * @param aSync True if it is synchronized, False otherwise. |
|
122 */ |
|
123 IMPORT_C void SetRCCm3Sync(TBool aSync) ; |
|
124 |
|
125 /* |
|
126 * Check if the crypto context is equal |
|
127 * @param aContext True if it is equal, False otherwise. |
|
128 */ |
|
129 TBool IsEqual(const CSRTPCryptoContext& aContext); |
|
130 |
|
131 /* |
|
132 * Add cryptocontext user |
|
133 * @param aObserver new CSRTPCryptoHandler instance |
|
134 */ |
|
135 void AddCryptoChangeObserver(CSRTPCryptoHandler *aObserver); |
|
136 |
|
137 /* |
|
138 * Remove cryptocontext user |
|
139 * @param aObserver CSRTPCryptoHandler instance |
|
140 */ |
|
141 void RemoveCryptoChangeObserver(CSRTPCryptoHandler *aObserver); |
|
142 |
|
143 protected: |
|
144 |
|
145 /* |
|
146 * Update crypto parameters, internal use only |
|
147 * @param aCryptoParams a new crypto parameters |
|
148 */ |
|
149 void UpdateCryptoParams(const TSrtpCryptoParams& aCryptoParams ); |
|
150 |
|
151 private: |
|
152 |
|
153 /* copy constructor */ |
|
154 CSRTPCryptoContext(const TSrtpCryptoParams& aCryptoParams ); |
|
155 |
|
156 void ConstructL ( const CSRTPMasterKey* aKey, |
|
157 const CSRTPMasterSalt* aSalt); |
|
158 |
|
159 |
|
160 /* assignment operator */ |
|
161 const CSRTPCryptoContext& operator=(const CSRTPCryptoContext& aContext); |
|
162 |
|
163 TBool FindHandler( CSRTPCryptoHandler *aObserver ); |
|
164 |
|
165 private: // from Array |
|
166 |
|
167 |
|
168 /** |
|
169 * list of CSRTPCryptoHandler objects |
|
170 * owned by CSRTPCryptoContext object. |
|
171 */ |
|
172 TSglQue<CSRTPCryptoHandler> iHandlerList; |
|
173 |
|
174 /** |
|
175 * CSRTPCryptoHandler iterator. |
|
176 * Owned by CSRTPCryptoContext object. |
|
177 */ |
|
178 TSglQueIter<CSRTPCryptoHandler> iHandlerIter; |
|
179 |
|
180 |
|
181 |
|
182 private: // data |
|
183 const CSRTPMasterKey *iKey; // TSRTPMasterKey definitions |
|
184 const CSRTPMasterSalt *iSalt; // TSRTPMasterSalt definitions |
|
185 TSrtpCryptoParams iCryptoParams; |
|
186 static const TInt iObserverOffset; |
|
187 |
|
188 |
|
189 private: |
|
190 #ifdef EUNIT_TESTING |
|
191 friend class UT_CSRTPCryptoContext; |
|
192 friend class UT_CSRTPCryptoHandlerSRTCP; |
|
193 #endif |
|
194 }; |
|
195 |
|
196 |
|
197 #endif // __SRTP_CRYPTOCONTEXT_H__ |