|
1 /* |
|
2 * Copyright (c) 2002 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 the License "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: Authentication utilities using White List. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "PushAuthenticationUtilities.h" |
|
23 #include "PushInitiatorList.h" |
|
24 #include "PushInitiator.h" |
|
25 #include "PushMtmSettings.h" |
|
26 #include "PushMtmUtilPanic.h" |
|
27 #include "PushMtmLog.h" |
|
28 #include <PushMessage.h> |
|
29 #include <PushEntry.h> |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 // --------------------------------------------------------- |
|
34 // TPushAuthenticationUtil::AuthenticateMsgL |
|
35 // --------------------------------------------------------- |
|
36 // |
|
37 EXPORT_C TBool TPushAuthenticationUtil::AuthenticateMsgL |
|
38 ( |
|
39 const CPushMtmSettings& aMtmSettings, |
|
40 const CPushMessage& aPushMsg |
|
41 ) |
|
42 { |
|
43 PUSHLOG_ENTERFN("TPushAuthenticationUtil::AuthenticateMsgL") |
|
44 |
|
45 // In case of white listing by default do not accept messages. |
|
46 TBool msgAuthenticated = EFalse; |
|
47 |
|
48 // Get server address. |
|
49 TPtrC8 srvAddress; |
|
50 if ( !aPushMsg.GetServerAddress( srvAddress ) ) |
|
51 { |
|
52 srvAddress.Set( KNullDesC8 ); |
|
53 } |
|
54 |
|
55 if ( srvAddress.Length() == 0 ) |
|
56 { |
|
57 PUSHLOG_WRITE(" No Server address") |
|
58 } |
|
59 else |
|
60 { |
|
61 PUSHLOG_WRITE_FORMAT(" Server address: <%S>",&srvAddress) |
|
62 |
|
63 CPushInitiator* sender = new (ELeave) CPushInitiator; |
|
64 CleanupStack::PushL( sender ); |
|
65 |
|
66 // Copy the 8-bit text into a 16-bit one. |
|
67 HBufC* from = HBufC::NewMaxLC( srvAddress.Length() ); |
|
68 |
|
69 from->Des().Copy( srvAddress ); |
|
70 sender->SetAddressL( *from, CPushInitiator::ETypeAny ); |
|
71 |
|
72 CleanupStack::PopAndDestroy( from ); // from |
|
73 |
|
74 CPushInitiatorList& whiteList = aMtmSettings.PushInitiatorList(); |
|
75 TInt index( 0 ); |
|
76 TInt err = whiteList.Find( *sender, index ); |
|
77 if ( !err ) |
|
78 { |
|
79 // Sender is in White list. |
|
80 msgAuthenticated = ETrue; |
|
81 PUSHLOG_WRITE(" Is in White List: msg accepted") |
|
82 } |
|
83 |
|
84 CleanupStack::PopAndDestroy( sender ); // sender |
|
85 } |
|
86 |
|
87 PUSHLOG_WRITE_FORMAT(" msgAuthenticated <%d>",msgAuthenticated) |
|
88 PUSHLOG_LEAVEFN("TPushAuthenticationUtil::AuthenticateMsgL") |
|
89 return msgAuthenticated; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------- |
|
93 // TPushAuthenticationUtil::AuthenticateMsgL |
|
94 // --------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C TBool TPushAuthenticationUtil::AuthenticateMsgL |
|
97 ( |
|
98 const CPushMtmSettings& aMtmSettings, |
|
99 const CPushMsgEntryBase& aPushMsg |
|
100 ) |
|
101 { |
|
102 PUSHLOG_ENTERFN("TPushAuthenticationUtil::AuthenticateMsgL 2") |
|
103 |
|
104 // In case of white listing by default do not accept messages. |
|
105 TBool msgAuthenticated = EFalse; |
|
106 |
|
107 // Get server address. |
|
108 TPtrC8 srvAddress = aPushMsg.From(); |
|
109 |
|
110 if ( srvAddress.Length() == 0 ) |
|
111 { |
|
112 PUSHLOG_WRITE(" Empty server address") |
|
113 } |
|
114 else |
|
115 { |
|
116 PUSHLOG_WRITE_FORMAT(" Server address: <%S>",&srvAddress) |
|
117 |
|
118 CPushInitiator* sender = new (ELeave) CPushInitiator; |
|
119 CleanupStack::PushL( sender ); |
|
120 |
|
121 // Copy the 8-bit text into a 16-bit one. |
|
122 HBufC* from = HBufC::NewMaxLC( srvAddress.Length() ); |
|
123 |
|
124 from->Des().Copy( srvAddress ); |
|
125 sender->SetAddressL( *from, CPushInitiator::ETypeAny ); |
|
126 |
|
127 CleanupStack::PopAndDestroy( from ); // from |
|
128 |
|
129 CPushInitiatorList& whiteList = aMtmSettings.PushInitiatorList(); |
|
130 TInt index( 0 ); |
|
131 TInt err = whiteList.Find( *sender, index ); |
|
132 if ( !err ) |
|
133 { |
|
134 // Sender is in White list. |
|
135 msgAuthenticated = ETrue; |
|
136 PUSHLOG_WRITE(" Is in White List: msg accepted") |
|
137 } |
|
138 |
|
139 CleanupStack::PopAndDestroy( sender ); // sender |
|
140 } |
|
141 |
|
142 PUSHLOG_WRITE_FORMAT(" msgAuthenticated <%d>",msgAuthenticated) |
|
143 PUSHLOG_LEAVEFN("TPushAuthenticationUtil::AuthenticateMsgL 2") |
|
144 return msgAuthenticated; |
|
145 } |
|
146 |
|
147 // End of file. |