|
1 /* |
|
2 * Copyright (c) 2006 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: Mcc crypto context. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // System includes |
|
22 #include <e32base.h> |
|
23 #include <mmccsrtpmasterkey.h> |
|
24 #include <mmccsrtpmastersalt.h> |
|
25 #include <mmccsrtpcryptoparams.h> |
|
26 |
|
27 #include "mmcccryptocontext.h" |
|
28 #include "mcccontrollerlogs.h" |
|
29 |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // TMccCryptoContext::ValidateContext |
|
36 // |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 TInt TMccCryptoContext::ValidateContext() const |
|
40 { |
|
41 // Checks Master key validity |
|
42 if ( iSrtpMasterKey.iMasterKey.Length() != KMccSRTPDefaultMasterKeyLength/8 ) |
|
43 { |
|
44 __CONTROLLER( "TMccCryptoContext::ValidateContext - Master Key Length Invalid" ) |
|
45 return KErrArgument; |
|
46 } |
|
47 |
|
48 if ( iSrtpMasterKey.iEncKeyBitLength != KMccSRTPDefSessionEncryptionKeyLength ) |
|
49 { |
|
50 __CONTROLLER( "TMccCryptoContext::ValidateContext - Encryption Key Length Invalid" ) |
|
51 return KErrArgument; |
|
52 } |
|
53 |
|
54 if ( iSrtpMasterKey.iAuthKeyBitLength != KMccSRTPDefSessionAuthenticationKeyLength ) |
|
55 { |
|
56 __CONTROLLER( "TMccCryptoContext::ValidateContext - Authentication Key Length Invalid" ) |
|
57 return KErrArgument; |
|
58 } |
|
59 |
|
60 // Checks master salt validity |
|
61 if ( iSrtpMasterSalt.iMasterSalt.Length() != KMccSRTPDefaultMasterSaltLength/8 ) |
|
62 { |
|
63 __CONTROLLER( "TMccCryptoContext::ValidateContext - Master Salt Length Invalid" ) |
|
64 return KErrArgument; |
|
65 } |
|
66 |
|
67 if ( iSrtpMasterSalt.iSaltKeyLength != KMccSRTPDefSessionSaltingKeyLength ) |
|
68 { |
|
69 __CONTROLLER( "TMccCryptoContext::ValidateContext - Salt Key Length Invalid" ) |
|
70 return KErrArgument; |
|
71 } |
|
72 |
|
73 // Checks crypto params validity |
|
74 if ( ( iSrtpCryptoParams.iSrtpEncAlg != ESrtpEncAES_CM && |
|
75 iSrtpCryptoParams.iSrtpEncAlg != ESrtpNullAlg ) && |
|
76 ( iSrtpCryptoParams.iSrtcpEncAlg != ESrtpEncAES_CM && |
|
77 iSrtpCryptoParams.iSrtcpEncAlg != ESrtpNullAlg ) ) |
|
78 { |
|
79 __CONTROLLER( "TMccCryptoContext::ValidateContext - Crypto Params Enc Invalid" ) |
|
80 return KErrArgument; |
|
81 } |
|
82 |
|
83 if ( ( iSrtpCryptoParams.iSrtpAuthAlg != ESrtpAuthHMAC_SHA1 && |
|
84 iSrtpCryptoParams.iSrtpAuthAlg != ESrtpAuthNull && |
|
85 iSrtpCryptoParams.iSrtpAuthAlg != ESrtpAuthRCCm1 && |
|
86 iSrtpCryptoParams.iSrtpAuthAlg != ESrtpAuthRCCm2 && |
|
87 iSrtpCryptoParams.iSrtpAuthAlg != ESrtpAuthRCCm3 ) || |
|
88 ( iSrtpCryptoParams.iSrtcpAuthAlg != ESrtpAuthHMAC_SHA1 && |
|
89 iSrtpCryptoParams.iSrtcpAuthAlg != ESrtpAuthNull ) ) |
|
90 { |
|
91 __CONTROLLER( "TMccCryptoContext::ValidateContext - Crypto Params AuthAlg Invalid" ) |
|
92 return KErrArgument; |
|
93 } |
|
94 |
|
95 if ( iSrtpCryptoParams.iSrtpAuthAlg == ESrtpAuthHMAC_SHA1 && |
|
96 ( iSrtpCryptoParams.iSrtpAuthTagLen != KMccSRTPAuthTagLength80 && |
|
97 iSrtpCryptoParams.iSrtpAuthTagLen != KMccSRTPAuthTagLength32 ) ) |
|
98 { |
|
99 __CONTROLLER( "TMccCryptoContext::ValidateContext - Crypto Params SRTP AuthTag32 Invalid" ) |
|
100 return KErrArgument; |
|
101 } |
|
102 |
|
103 if ( iSrtpCryptoParams.iSrtcpAuthAlg == ESrtpAuthHMAC_SHA1 && |
|
104 ( iSrtpCryptoParams.iSrtcpAuthTagLen != KMccSRTPAuthTagLength80 && |
|
105 iSrtpCryptoParams.iSrtcpAuthTagLen != KMccSRTPAuthTagLength32 ) ) |
|
106 { |
|
107 __CONTROLLER( "TMccCryptoContext::ValidateContext - Crypto Params SRTCP AuthTag32 Invalid" ) |
|
108 return KErrArgument; |
|
109 } |
|
110 |
|
111 if ( ( iSrtpCryptoParams.iSrtpAuthAlg == ESrtpAuthRCCm1 || |
|
112 iSrtpCryptoParams.iSrtpAuthAlg == ESrtpAuthRCCm2 ) && |
|
113 iSrtpCryptoParams.iSrtpAuthTagLen != KMccSRTPAuthTagLength112 ) |
|
114 { |
|
115 __CONTROLLER( "TMccCryptoContext::ValidateContext - Crypto Params SRTP AuthTag112 Invalid" ) |
|
116 return KErrArgument; |
|
117 } |
|
118 |
|
119 if ( iSrtpCryptoParams.iSrtpAuthAlg == ESrtpAuthRCCm3 && |
|
120 iSrtpCryptoParams.iSrtpAuthTagLen != KMccSRTPAuthTagLength32 ) |
|
121 { |
|
122 __CONTROLLER( "TMccCryptoContext::ValidateContext - Crypto Params SRTP RCC3 && AuthTag32 Invalid" ) |
|
123 return KErrArgument; |
|
124 } |
|
125 |
|
126 if ( ( iSrtpCryptoParams.iSrtpAuthAlg == ESrtpAuthNull && |
|
127 iSrtpCryptoParams.iSrtpAuthTagLen != 0 ) && |
|
128 ( iSrtpCryptoParams.iSrtpAuthAlg == ESrtpAuthNull && |
|
129 iSrtpCryptoParams.iSrtpAuthTagLen != 0) ) |
|
130 { |
|
131 __CONTROLLER( "TMccCryptoContext::ValidateContext - Crypto Params SRTP AuthNull Invalid" ) |
|
132 return KErrArgument; |
|
133 } |
|
134 |
|
135 if ( iSrtpCryptoParams.iPrefixLen != KMccSRTPPrefixLength ) |
|
136 { |
|
137 __CONTROLLER( "TMccCryptoContext::ValidateContext - Crypto Params Prefix Invalid" ) |
|
138 return KErrArgument; |
|
139 } |
|
140 |
|
141 if ( !iSrtpCryptoParams.iROCTransRate ) |
|
142 { |
|
143 __CONTROLLER( "TMccCryptoContext::ValidateContext - Crypto Params ROCTransRate Invalid" ) |
|
144 return KErrArgument; |
|
145 } |
|
146 |
|
147 return KErrNone; |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // TMccCryptoContext::UpdateContext |
|
152 // |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 TInt TMccCryptoContext::UpdateContext( TMccCryptoContext& aCandidate ) |
|
156 { |
|
157 iSrtpMasterKey = aCandidate.iSrtpMasterKey; |
|
158 iSrtpMasterSalt = aCandidate.iSrtpMasterSalt; |
|
159 |
|
160 return KErrNone; |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // TMccCryptoContext::GetDestinationInfo |
|
165 // |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 TInt TMccCryptoContext::GetDestinationInfo( TUint32& aSessionId, TUint32& aLinkId, |
|
169 TUint32& aStreamId, TUint32& aEndPointId ) const |
|
170 { |
|
171 if ( !iBindingDone ) |
|
172 { |
|
173 return KErrNotFound; |
|
174 } |
|
175 |
|
176 aSessionId = iSessionId; |
|
177 aLinkId = iLinkId; |
|
178 aStreamId = iStreamId; |
|
179 aEndPointId = iEndPointId; |
|
180 return KErrNone; |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // TMccCryptoContext::GetDestinationInfo |
|
185 // |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 TInt TMccCryptoContext::SetDestinationInfo( TUint32 aSessionId, TUint32 aLinkId, |
|
189 TUint32 aStreamId, TUint32 aEndPointId ) |
|
190 { |
|
191 iSessionId = aSessionId; |
|
192 iLinkId = aLinkId; |
|
193 iStreamId = aStreamId; |
|
194 iEndPointId = aEndPointId; |
|
195 |
|
196 iBindingDone = ETrue; |
|
197 return KErrNone; |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // TMccCryptoContext::SetMasterKey |
|
202 // |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 void TMccCryptoContext::SetMasterKey( const TMccSrtpMasterKey& aSrtpMasterKey ) |
|
206 { |
|
207 iSrtpMasterKey = aSrtpMasterKey; |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // TMccCryptoContext::SetMasterSalt |
|
212 // |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 void TMccCryptoContext::SetMasterSalt( const TMccSrtpMasterSalt& aSrtpMasterSalt ) |
|
216 { |
|
217 iSrtpMasterSalt = aSrtpMasterSalt; |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // TMccCryptoContext::SetCryptoParams |
|
222 // |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void TMccCryptoContext::SetCryptoParams( const TMccSrtpCryptoParams& aSrtpCryptoParams ) |
|
226 { |
|
227 iSrtpCryptoParams = aSrtpCryptoParams; |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // TMccCryptoContext::MasterKey |
|
232 // |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 const TMccSrtpMasterKey& TMccCryptoContext::MasterKey() const |
|
236 { |
|
237 return iSrtpMasterKey; |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // TMccCryptoContext::MasterSalt |
|
242 // |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 const TMccSrtpMasterSalt& TMccCryptoContext::MasterSalt() const |
|
246 { |
|
247 return iSrtpMasterSalt; |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // TMccCryptoContext::CryptoParams |
|
252 // |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 const TMccSrtpCryptoParams& TMccCryptoContext::CryptoParams() const |
|
256 { |
|
257 return iSrtpCryptoParams; |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // TMccCryptoContext::ContextId |
|
262 // |
|
263 // --------------------------------------------------------------------------- |
|
264 // |
|
265 TUint32 TMccCryptoContext::ContextId() const |
|
266 { |
|
267 return iContextId; |
|
268 } |
|
269 // End of File |