|
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: Class is used for configuring secure RTP. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "mmccsecureinterface.h" |
|
22 #include "mmccinterfacelogs.h" |
|
23 #include "mccdef.h" |
|
24 #include "mccinternaldef.h" |
|
25 #include "mmcccryptocontextcontainer.h" |
|
26 #include "mmcccryptocontext.h" |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CMccEvent::CMccEvent |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CMccSecureInterface::CMccSecureInterface( CMccInterface& aInterface ) |
|
37 : iInterface( aInterface ), iMessageDest( KMccControllerUidInterface ) |
|
38 { |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CMccInterface::ConstructL |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 void CMccSecureInterface::ConstructL( ) |
|
46 { |
|
47 __INTERFACE( "CMccSecureInterface::ConstructL" ) |
|
48 iInterface.GetController( iController ); |
|
49 |
|
50 iContextContainer = CMccCryptoContextContainer::NewL(); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CMccSecureInterface::NewL() |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C CMccSecureInterface* CMccSecureInterface::NewL( CMccInterface& aInterface ) |
|
58 { |
|
59 CMccSecureInterface* self = new(ELeave) CMccSecureInterface( aInterface ); |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL( ); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CMccSecureInterface::~CMccSecureInterface |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CMccSecureInterface::~CMccSecureInterface() |
|
71 { |
|
72 delete iContextContainer; |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CMccSecureInterface::CreateContext |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C TInt CMccSecureInterface::CreateContext( const TDesC8& aMasterKey, |
|
80 const TDesC8& aSaltKey, |
|
81 TUint32& aContextId, |
|
82 const TDesC8& aParams ) |
|
83 { |
|
84 __INTERFACE( "MccSecureInterface::CreateContext" ) |
|
85 |
|
86 TInt err = KErrNone; |
|
87 |
|
88 TMccSrtpMasterKeyPckg masterKeyPckg = |
|
89 static_cast<const TMccSrtpMasterKeyPckg&>( aMasterKey ); |
|
90 TMccSrtpMasterSaltPckg masterSaltPckg = |
|
91 static_cast<const TMccSrtpMasterSaltPckg&>( aSaltKey ); |
|
92 TMccSrtpCryptoParamsPckg cryptoParamsPckg = |
|
93 static_cast<const TMccSrtpCryptoParamsPckg&>( aParams ); |
|
94 |
|
95 err = iContextContainer->CreateContext( masterKeyPckg(), |
|
96 masterSaltPckg(), |
|
97 aContextId, |
|
98 cryptoParamsPckg() ); |
|
99 |
|
100 __INTERFACE_INT1( "MccSecureInterface::CreateContext, exit with ", err ) |
|
101 return err; |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CMccSecureInterface::UpdateContext |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C TInt CMccSecureInterface::UpdateContext( const TDesC8& aMasterKey, |
|
109 const TDesC8& aSaltKey, |
|
110 TUint32 aContextId, |
|
111 const TDesC8& aParams ) |
|
112 { |
|
113 __INTERFACE( "MccSecureInterface::UpdateContext" ) |
|
114 |
|
115 TInt err( KErrNone ); |
|
116 |
|
117 TMccCryptoContext* contextToUpdate; |
|
118 |
|
119 err = iContextContainer->GetContext( aContextId, contextToUpdate ); |
|
120 |
|
121 if ( KErrNone != err ) |
|
122 { |
|
123 return err; |
|
124 } |
|
125 |
|
126 TMccSrtpMasterKeyPckg masterKeyPckg = |
|
127 static_cast<const TMccSrtpMasterKeyPckg&>( aMasterKey ); |
|
128 TMccSrtpMasterSaltPckg masterSaltPckg = |
|
129 static_cast<const TMccSrtpMasterSaltPckg&>( aSaltKey ); |
|
130 TMccSrtpCryptoParamsPckg cryptoParamsPckg = |
|
131 static_cast<const TMccSrtpCryptoParamsPckg&>( aParams ); |
|
132 |
|
133 TMccCryptoContext cryptoContextCandidate( 0, |
|
134 masterKeyPckg(), |
|
135 masterSaltPckg(), |
|
136 cryptoParamsPckg() ); |
|
137 |
|
138 // Validate candidates params |
|
139 err = cryptoContextCandidate.ValidateContext(); |
|
140 |
|
141 if ( KErrNone != err ) |
|
142 { |
|
143 return err; |
|
144 } |
|
145 |
|
146 // Get crypto context binding destination |
|
147 // if returns KErrNotFound context isn't binded yet |
|
148 TMccSecurityDestination securityDest; |
|
149 |
|
150 err = contextToUpdate->GetDestinationInfo( securityDest.iSessionID, securityDest.iLinkID, |
|
151 securityDest.iStreamID, securityDest.iEndpointID ); |
|
152 |
|
153 if ( KErrNotFound != err ) |
|
154 { |
|
155 cryptoContextCandidate.SetDestinationInfo( securityDest.iSessionID, |
|
156 securityDest.iLinkID, |
|
157 securityDest.iStreamID, |
|
158 securityDest.iEndpointID ); |
|
159 |
|
160 TMccCryptoContextPckg cryptoContextPckg( cryptoContextCandidate ); |
|
161 |
|
162 TMccSecurityDestinationBuffer securityDestPckg( securityDest ); |
|
163 |
|
164 err = iController.CustomCommandSync( iMessageDest, |
|
165 EMccBindContextIntoStream, |
|
166 cryptoContextPckg, |
|
167 securityDestPckg ); |
|
168 if ( KErrNone != err ) |
|
169 { |
|
170 return err; |
|
171 } |
|
172 } |
|
173 |
|
174 err = iContextContainer->UpdateContext( aContextId, cryptoContextCandidate ); |
|
175 |
|
176 __INTERFACE_INT1( "MccSecureInterface::UpdateContext, exit with ", err ) |
|
177 return err; |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CMccSecureInterface::RemoveContext |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 EXPORT_C TInt CMccSecureInterface::RemoveContext( TUint32 aContextId ) |
|
185 { |
|
186 __INTERFACE( "MccSecureInterface::RemoveContext" ) |
|
187 |
|
188 TInt err( KErrNone ); |
|
189 |
|
190 |
|
191 TMccCryptoContext* contextToRemove; |
|
192 err = iContextContainer->GetContext( aContextId, contextToRemove ); |
|
193 |
|
194 if ( KErrNotFound == err ) |
|
195 { |
|
196 return err; |
|
197 } |
|
198 |
|
199 // Get crypto context binding destination |
|
200 // if returns KErrNotFound context isn't binded yet |
|
201 TMccSecurityDestination securityDest; |
|
202 |
|
203 err = contextToRemove->GetDestinationInfo( securityDest.iSessionID, securityDest.iLinkID, |
|
204 securityDest.iStreamID, securityDest.iEndpointID ); |
|
205 |
|
206 if ( KErrNotFound != err ) |
|
207 { |
|
208 TMccSecurityDestinationBuffer securityDestPckg( securityDest ); |
|
209 |
|
210 err = iController.CustomCommandSync( iMessageDest, |
|
211 EMccRemoveContext, |
|
212 KNullDesC8, |
|
213 securityDestPckg ); |
|
214 } |
|
215 |
|
216 |
|
217 |
|
218 err = iContextContainer->RemoveContext( aContextId ); |
|
219 |
|
220 __INTERFACE_INT1( "MccSecureInterface::RemoveContext, exit with ", err ) |
|
221 |
|
222 return err; |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------------------------- |
|
226 // CMccSecureInterface::Bind |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 EXPORT_C TInt CMccSecureInterface::Bind( TUint32 aSessionId, TUint32 aLinkId, |
|
230 TUint32 aStreamId, TUint32 aEndPointId, |
|
231 TUint32 aContextId ) |
|
232 { |
|
233 __INTERFACE( "MccSecureInterface::Bind IN" ) |
|
234 |
|
235 TInt err = KErrNone; |
|
236 |
|
237 TMccCryptoContext* context; |
|
238 |
|
239 err = iContextContainer->GetContext( aContextId, context ); |
|
240 |
|
241 if ( KErrNotFound == err ) |
|
242 { |
|
243 return err; |
|
244 } |
|
245 |
|
246 TMccSecurityDestination securityDest; |
|
247 |
|
248 err = context->GetDestinationInfo( securityDest.iSessionID, securityDest.iLinkID, |
|
249 securityDest.iStreamID, securityDest.iEndpointID ); |
|
250 |
|
251 // Checks if crypto context is already binded to destination. Can't bind twice |
|
252 if ( KErrNotFound != err ) |
|
253 { |
|
254 return KErrArgument; |
|
255 } |
|
256 |
|
257 TMccCryptoContextPckg cryptoContextPckg( *context ); |
|
258 |
|
259 securityDest.iSessionID = aSessionId; |
|
260 securityDest.iLinkID = aLinkId; |
|
261 securityDest.iStreamID = aStreamId; |
|
262 securityDest.iEndpointID = aEndPointId; |
|
263 |
|
264 TMccSecurityDestinationBuffer securityDestPckg( securityDest ); |
|
265 |
|
266 err = iController.CustomCommandSync( iMessageDest, |
|
267 EMccBindContextIntoStream, |
|
268 cryptoContextPckg, |
|
269 securityDestPckg |
|
270 ); |
|
271 |
|
272 __INTERFACE_INT1( "MccSecureInterface::Bind, exit with ", err ) |
|
273 |
|
274 if ( KErrNone == err ) |
|
275 { |
|
276 context->SetDestinationInfo( aSessionId, aLinkId, aStreamId, aEndPointId ); |
|
277 } |
|
278 return err; |
|
279 } |