os/security/cryptoservices/filebasedcertificateandkeystores/source/certapps/server/CCertAppsConduit.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/source/certapps/server/CCertAppsConduit.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,180 @@
1.4 +/*
1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "CCertAppsConduit.h"
1.23 +#include "CFSCertAppsServer.h"
1.24 +#include <certificateapps.h>
1.25 +#include "fstokencliserv.h"
1.26 +#include "fstokenutil.h"
1.27 +#include "fsmarshaller.h"
1.28 +
1.29 +_LIT_SECURITY_POLICY_C1(KAddRemovePolicy, ECapabilityWriteDeviceData);
1.30 +
1.31 +CCertAppsConduit* CCertAppsConduit::NewL(CFSCertAppsServer& aServer)
1.32 + {
1.33 + CCertAppsConduit* self = new (ELeave) CCertAppsConduit(aServer);
1.34 + CleanupStack::PushL(self);
1.35 + self->ConstructL();
1.36 + CleanupStack::Pop(self);
1.37 + return self;
1.38 + }
1.39 +
1.40 +CCertAppsConduit::CCertAppsConduit(CFSCertAppsServer& aServer) :
1.41 + iServer(aServer)
1.42 + {
1.43 + }
1.44 +
1.45 +void CCertAppsConduit::ConstructL()
1.46 + {
1.47 + }
1.48 +
1.49 +CCertAppsConduit::~CCertAppsConduit()
1.50 + {
1.51 + }
1.52 +
1.53 +void CCertAppsConduit::ServiceCertAppsRequestL(const RMessage2& aMessage)
1.54 + {
1.55 + switch(aMessage.Function())
1.56 + {
1.57 + case EAddApp:
1.58 + AddL(aMessage);
1.59 + break;
1.60 +
1.61 + case ERemoveApp:
1.62 + RemoveL(aMessage);
1.63 + break;
1.64 +
1.65 + case EGetAppCount:
1.66 + ApplicationCountL(aMessage);
1.67 + break;
1.68 +
1.69 + case EGetApps:
1.70 + ApplicationsL(aMessage);
1.71 + break;
1.72 +
1.73 + case EGetApplication:
1.74 + ApplicationL(aMessage);
1.75 + break;
1.76 +
1.77 + default:
1.78 + // Client made an illegal request
1.79 + PanicClient(aMessage, EPanicInvalidRequest);
1.80 + }
1.81 +
1.82 + aMessage.Complete(KErrNone);
1.83 + }
1.84 +
1.85 +void CCertAppsConduit::AddL(const RMessage2& aMessage) const
1.86 + {
1.87 + // Add message is composed of the following structure
1.88 + // Parameter 1 - TPckg<TCertificateAppInfo>
1.89 +
1.90 + // Check the calling process has the correct capabilities
1.91 + if (!KAddRemovePolicy.CheckPolicy(aMessage))
1.92 + {
1.93 + User::Leave(KErrPermissionDenied);
1.94 + }
1.95 +
1.96 + TCertificateAppInfo appInfo;
1.97 + TPckg<TCertificateAppInfo> pckg(appInfo);
1.98 + aMessage.ReadL(1, pckg);
1.99 +
1.100 + // Now that we have extracted the appInfo, we can call the
1.101 + // real server
1.102 + iServer.AddL(appInfo);
1.103 + }
1.104 +
1.105 +void CCertAppsConduit::RemoveL(const RMessage2& aMessage) const
1.106 + {
1.107 + // Remove message is composed of a single TPckg<TUid>
1.108 +
1.109 + // Check the calling process has the correct capabilities
1.110 + if (!KAddRemovePolicy.CheckPolicy(aMessage))
1.111 + {
1.112 + User::Leave(KErrPermissionDenied);
1.113 + }
1.114 +
1.115 + TUid uid;
1.116 + TPckg<TUid> pckg(uid);
1.117 + aMessage.ReadL(1, pckg);
1.118 + iServer.RemoveL(uid);
1.119 + }
1.120 +
1.121 +void CCertAppsConduit::ApplicationCountL(const RMessage2& aMessage) const
1.122 + {
1.123 + // This message contains a single output descriptor of type
1.124 + // TPckg<TInt>
1.125 + TInt appCount = iServer.ApplicationCountL();
1.126 + aMessage.WriteL(1, TPckg<TInt>(appCount));
1.127 + }
1.128 +
1.129 +void CCertAppsConduit::ApplicationsL(const RMessage2& aMessage) const
1.130 + {
1.131 + // This message contains the following parameters:
1.132 + // Param1: [IN] TInt - maximum buffer length allowed
1.133 + // Param2: [OUT] TDes8 - The buffer to write into; if buffer size too
1.134 + // small then will return KErrOverflow with param 2 being
1.135 + // required size
1.136 +
1.137 + // Firstly, the maximum allowable length of the buffer
1.138 +
1.139 + // now get the array to be transmitted
1.140 + RArray<TCertificateAppInfo> arr;
1.141 + CleanupClosePushL(arr);
1.142 +
1.143 + // retrieve the array and marshall them into the message
1.144 + iServer.ApplicationsL(arr);
1.145 +
1.146 + TInt reqdSize = TokenDataMarshaller::Size(arr);
1.147 + TInt bufLen = User::LeaveIfError(aMessage.GetDesLength(2));
1.148 +
1.149 + if (reqdSize <= bufLen)
1.150 + {
1.151 + HBufC8* buf = HBufC8::NewMaxLC(reqdSize);
1.152 + TPtr8 ptr(buf->Des());
1.153 + TokenDataMarshaller::Write(arr, ptr);
1.154 + aMessage.WriteL(2, ptr);
1.155 + CleanupStack::PopAndDestroy(buf);
1.156 + }
1.157 + else
1.158 + {
1.159 + aMessage.WriteL(2, TPckg<TInt>(reqdSize));
1.160 + User::Leave(KErrOverflow);
1.161 + }
1.162 +
1.163 + CleanupStack::PopAndDestroy(&arr);
1.164 + }
1.165 +
1.166 +void CCertAppsConduit::ApplicationL(const RMessage2& aMessage) const
1.167 + {
1.168 + // The parameters for the ApplicationL function are as follows:
1.169 + // Param1: [IN] TUid - The Uid of the app to retrieve
1.170 + // Param2: [OUT] TCertificateAppInfo - The app info returned
1.171 +
1.172 + // Read the UID first
1.173 + TUid uid;
1.174 + TPckg<TUid> pckgUid(uid);
1.175 + aMessage.ReadL(1, pckgUid);
1.176 +
1.177 + // Now call the server
1.178 + TCertificateAppInfo appInfo;
1.179 + iServer.ApplicationL(uid, appInfo);
1.180 +
1.181 + // Now wrap the returned parameters into packages
1.182 + aMessage.WriteL(2, TPckg<TCertificateAppInfo>(appInfo));
1.183 + }