os/security/cryptoservices/filebasedcertificateandkeystores/source/certapps/server/CCertAppsConduit.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "CCertAppsConduit.h"
sl@0
    20
#include "CFSCertAppsServer.h"
sl@0
    21
#include <certificateapps.h>
sl@0
    22
#include "fstokencliserv.h"
sl@0
    23
#include "fstokenutil.h"
sl@0
    24
#include "fsmarshaller.h"
sl@0
    25
sl@0
    26
_LIT_SECURITY_POLICY_C1(KAddRemovePolicy, ECapabilityWriteDeviceData);
sl@0
    27
sl@0
    28
CCertAppsConduit* CCertAppsConduit::NewL(CFSCertAppsServer& aServer)
sl@0
    29
	{
sl@0
    30
	CCertAppsConduit* self = new (ELeave) CCertAppsConduit(aServer);
sl@0
    31
	CleanupStack::PushL(self);
sl@0
    32
	self->ConstructL();
sl@0
    33
	CleanupStack::Pop(self);
sl@0
    34
	return self;
sl@0
    35
	}
sl@0
    36
sl@0
    37
CCertAppsConduit::CCertAppsConduit(CFSCertAppsServer& aServer) :
sl@0
    38
	iServer(aServer)
sl@0
    39
	{
sl@0
    40
	}
sl@0
    41
sl@0
    42
void CCertAppsConduit::ConstructL()
sl@0
    43
	{
sl@0
    44
	}
sl@0
    45
sl@0
    46
CCertAppsConduit::~CCertAppsConduit()
sl@0
    47
	{
sl@0
    48
	}
sl@0
    49
sl@0
    50
void CCertAppsConduit::ServiceCertAppsRequestL(const RMessage2& aMessage)
sl@0
    51
	{
sl@0
    52
	switch(aMessage.Function())
sl@0
    53
		{
sl@0
    54
		case EAddApp:
sl@0
    55
			AddL(aMessage);
sl@0
    56
			break;
sl@0
    57
sl@0
    58
		case ERemoveApp:
sl@0
    59
			RemoveL(aMessage);
sl@0
    60
			break;
sl@0
    61
sl@0
    62
		case EGetAppCount:
sl@0
    63
			ApplicationCountL(aMessage);
sl@0
    64
			break;
sl@0
    65
sl@0
    66
		case EGetApps:
sl@0
    67
			ApplicationsL(aMessage);
sl@0
    68
			break;
sl@0
    69
sl@0
    70
		case EGetApplication:
sl@0
    71
			ApplicationL(aMessage);
sl@0
    72
			break;
sl@0
    73
sl@0
    74
		default:
sl@0
    75
			// Client made an illegal request
sl@0
    76
			PanicClient(aMessage, EPanicInvalidRequest);
sl@0
    77
		}
sl@0
    78
	
sl@0
    79
	aMessage.Complete(KErrNone);
sl@0
    80
	}
sl@0
    81
sl@0
    82
void CCertAppsConduit::AddL(const RMessage2& aMessage) const
sl@0
    83
	{
sl@0
    84
	// Add message is composed of the following structure
sl@0
    85
	// Parameter 1 - TPckg<TCertificateAppInfo>
sl@0
    86
sl@0
    87
	// Check the calling process has the correct capabilities
sl@0
    88
	if (!KAddRemovePolicy.CheckPolicy(aMessage))
sl@0
    89
		{
sl@0
    90
		User::Leave(KErrPermissionDenied);
sl@0
    91
		}
sl@0
    92
sl@0
    93
	TCertificateAppInfo appInfo;
sl@0
    94
	TPckg<TCertificateAppInfo> pckg(appInfo);
sl@0
    95
	aMessage.ReadL(1, pckg);
sl@0
    96
sl@0
    97
	// Now that we have extracted the appInfo, we can call the
sl@0
    98
	// real server
sl@0
    99
	iServer.AddL(appInfo);
sl@0
   100
	}
sl@0
   101
sl@0
   102
void CCertAppsConduit::RemoveL(const RMessage2& aMessage) const
sl@0
   103
	{
sl@0
   104
	// Remove message is composed of a single TPckg<TUid>
sl@0
   105
sl@0
   106
	// Check the calling process has the correct capabilities
sl@0
   107
	if (!KAddRemovePolicy.CheckPolicy(aMessage))
sl@0
   108
		{
sl@0
   109
		User::Leave(KErrPermissionDenied);
sl@0
   110
		}
sl@0
   111
sl@0
   112
	TUid uid;
sl@0
   113
	TPckg<TUid> pckg(uid);
sl@0
   114
	aMessage.ReadL(1, pckg);
sl@0
   115
	iServer.RemoveL(uid);
sl@0
   116
	}
sl@0
   117
sl@0
   118
void CCertAppsConduit::ApplicationCountL(const RMessage2& aMessage) const
sl@0
   119
	{
sl@0
   120
	// This message contains a single output descriptor of type
sl@0
   121
	// TPckg<TInt>
sl@0
   122
	TInt appCount = iServer.ApplicationCountL();
sl@0
   123
	aMessage.WriteL(1, TPckg<TInt>(appCount));
sl@0
   124
	}
sl@0
   125
sl@0
   126
void CCertAppsConduit::ApplicationsL(const RMessage2& aMessage) const
sl@0
   127
	{
sl@0
   128
	// This message contains the following parameters:
sl@0
   129
	// Param1: [IN] TInt - maximum buffer length allowed
sl@0
   130
	// Param2: [OUT] TDes8 - The buffer to write into; if buffer size too
sl@0
   131
	//               small then will return KErrOverflow with param 2 being 
sl@0
   132
	//               required size
sl@0
   133
sl@0
   134
	// Firstly, the maximum allowable length of the buffer
sl@0
   135
	
sl@0
   136
	// now get the array to be transmitted
sl@0
   137
	RArray<TCertificateAppInfo> arr;
sl@0
   138
	CleanupClosePushL(arr);
sl@0
   139
sl@0
   140
	// retrieve the array and marshall them into the message
sl@0
   141
	iServer.ApplicationsL(arr);
sl@0
   142
sl@0
   143
	TInt reqdSize = TokenDataMarshaller::Size(arr);
sl@0
   144
	TInt bufLen = User::LeaveIfError(aMessage.GetDesLength(2));
sl@0
   145
sl@0
   146
	if (reqdSize <= bufLen)
sl@0
   147
		{
sl@0
   148
		HBufC8* buf = HBufC8::NewMaxLC(reqdSize);
sl@0
   149
		TPtr8 ptr(buf->Des());
sl@0
   150
		TokenDataMarshaller::Write(arr, ptr);
sl@0
   151
		aMessage.WriteL(2, ptr);
sl@0
   152
		CleanupStack::PopAndDestroy(buf);
sl@0
   153
		}
sl@0
   154
	else
sl@0
   155
		{
sl@0
   156
		aMessage.WriteL(2, TPckg<TInt>(reqdSize));
sl@0
   157
		User::Leave(KErrOverflow);
sl@0
   158
		}
sl@0
   159
sl@0
   160
	CleanupStack::PopAndDestroy(&arr);
sl@0
   161
	}
sl@0
   162
sl@0
   163
void CCertAppsConduit::ApplicationL(const RMessage2& aMessage) const
sl@0
   164
	{
sl@0
   165
	// The parameters for the ApplicationL function are as follows:
sl@0
   166
	// Param1: [IN] TUid - The Uid of the app to retrieve
sl@0
   167
	// Param2: [OUT] TCertificateAppInfo - The app info returned
sl@0
   168
sl@0
   169
	// Read the UID first
sl@0
   170
	TUid uid;
sl@0
   171
	TPckg<TUid> pckgUid(uid);
sl@0
   172
	aMessage.ReadL(1, pckgUid);
sl@0
   173
sl@0
   174
	// Now call the server
sl@0
   175
	TCertificateAppInfo appInfo;
sl@0
   176
	iServer.ApplicationL(uid, appInfo);
sl@0
   177
sl@0
   178
	// Now wrap the returned parameters into packages
sl@0
   179
	aMessage.WriteL(2, TPckg<TCertificateAppInfo>(appInfo));
sl@0
   180
	}