os/security/cryptoservices/filebasedcertificateandkeystores/source/keystore/Client/ClientOpenedKeys.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/source/keystore/Client/ClientOpenedKeys.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,306 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004-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 <e32base.h>
    1.23 +#include <ct.h>
    1.24 +#include <mctkeystore.h>
    1.25 +#include "ClientOpenedKeys.h"
    1.26 +#include "cfskeystoreclient.h"
    1.27 +#include "hash.h"
    1.28 +#include <mctkeystoreuids.h>
    1.29 +
    1.30 +
    1.31 +// COpenedKey //////////////////////////////////////////////////////////////////
    1.32 +	
    1.33 +COpenedKey::~COpenedKey()
    1.34 +	{
    1.35 +	iClient->ReleaseObject(iHandle);
    1.36 +	delete iLabel;
    1.37 +	}
    1.38 +
    1.39 +// CRSARepudiableSigner ////////////////////////////////////////////////////////
    1.40 +
    1.41 +CRSARepudiableSigner* CRSARepudiableSigner::New(CFSKeyStoreClient* aClient)
    1.42 +	{
    1.43 +	return new CRSARepudiableSigner(aClient);
    1.44 +	}
    1.45 +
    1.46 +CRSARepudiableSigner::CRSARepudiableSigner(CFSKeyStoreClient* aClient)
    1.47 +		: MCTSigner<CRSASignature*>(aClient->Token())
    1.48 +	{
    1.49 +	iClient = aClient;
    1.50 +	iHandle.iTokenHandle = aClient->Token().Handle();
    1.51 +	iHandle.iObjectId = 0;
    1.52 +	}
    1.53 +
    1.54 +CRSARepudiableSigner::~CRSARepudiableSigner()
    1.55 +	{
    1.56 +	delete iDigest;
    1.57 +	}
    1.58 +
    1.59 +void CRSARepudiableSigner::Release()
    1.60 +	{
    1.61 +	MCTTokenObject::Release();
    1.62 +	}
    1.63 +
    1.64 +const TDesC& CRSARepudiableSigner::Label() const
    1.65 +	{
    1.66 +	return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
    1.67 +	}
    1.68 +
    1.69 +MCTToken& CRSARepudiableSigner::Token() const
    1.70 +	{
    1.71 +	return iClient->Token();
    1.72 +	}
    1.73 +
    1.74 +TUid CRSARepudiableSigner::Type() const
    1.75 +	{
    1.76 +	return KRSARepudiableSignerUID;
    1.77 +	}
    1.78 +
    1.79 +TCTTokenObjectHandle CRSARepudiableSigner::Handle() const
    1.80 +	{
    1.81 +	return iHandle;
    1.82 +	}
    1.83 +
    1.84 +void CRSARepudiableSigner::SignMessage(const TDesC8& aPlaintext, 
    1.85 +  				CRSASignature*& aSignature, 
    1.86 +  				TRequestStatus& aStatus)
    1.87 +	{
    1.88 +	// Hash the data on the client side
    1.89 +	TRAPD(err, iDigest = CSHA1::NewL());
    1.90 +	if (err != KErrNone)
    1.91 +		{
    1.92 +		TRequestStatus* status = &aStatus;
    1.93 +		User::RequestComplete(status, err);
    1.94 +		}
    1.95 +    else
    1.96 +        {
    1.97 +        iDigest->Update(aPlaintext);	
    1.98 +        Sign(iDigest->Final(), aSignature, aStatus);
    1.99 +        }
   1.100 +	}
   1.101 +
   1.102 +void CRSARepudiableSigner::Sign(const TDesC8& aPlaintext, 
   1.103 +  				CRSASignature*& aSignature, 
   1.104 +  				TRequestStatus& aStatus)
   1.105 +	{
   1.106 +	iClient->RepudiableRSASign(Handle(),aPlaintext, aSignature, aStatus);
   1.107 +	}
   1.108 +
   1.109 +void CRSARepudiableSigner::CancelSign()
   1.110 +	{
   1.111 +	iClient->CancelRepudiableRSASign();
   1.112 +	}
   1.113 +
   1.114 +// CDSARepudiableSigner ////////////////////////////////////////////////////////
   1.115 +
   1.116 +CDSARepudiableSigner* CDSARepudiableSigner::New(CFSKeyStoreClient* aClient)
   1.117 +	{
   1.118 +	return new CDSARepudiableSigner(aClient);
   1.119 +	}
   1.120 +
   1.121 +CDSARepudiableSigner::CDSARepudiableSigner(CFSKeyStoreClient* aClient)
   1.122 +		: MCTSigner<CDSASignature*>(aClient->Token())
   1.123 +	{
   1.124 +	iClient = aClient;
   1.125 +	iHandle.iTokenHandle = aClient->Token().Handle();
   1.126 +	iHandle.iObjectId = 0;
   1.127 +	}
   1.128 +
   1.129 +
   1.130 +CDSARepudiableSigner::~CDSARepudiableSigner()
   1.131 +	{
   1.132 +	delete iDigest;
   1.133 +	}
   1.134 +
   1.135 +void CDSARepudiableSigner::Release()
   1.136 +	{
   1.137 +	MCTTokenObject::Release();
   1.138 +	}
   1.139 +
   1.140 +const TDesC& CDSARepudiableSigner::Label() const
   1.141 +	{
   1.142 +	return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
   1.143 +	}
   1.144 +
   1.145 +MCTToken& CDSARepudiableSigner::Token() const
   1.146 +	{
   1.147 +	return iClient->Token();
   1.148 +	}
   1.149 +
   1.150 +TUid CDSARepudiableSigner::Type() const
   1.151 +	{
   1.152 +	return KDSARepudiableSignerUID;
   1.153 +	}
   1.154 +
   1.155 +TCTTokenObjectHandle CDSARepudiableSigner::Handle() const
   1.156 +	{
   1.157 +	return iHandle;
   1.158 +	}
   1.159 +
   1.160 +void CDSARepudiableSigner::SignMessage(const TDesC8& aPlaintext, 
   1.161 +  				CDSASignature*& aSignature, 
   1.162 + 				TRequestStatus& aStatus)
   1.163 +	{
   1.164 +	// Hash the data on the client side
   1.165 +	TRAPD(err, iDigest = CSHA1::NewL());
   1.166 +	if (err != KErrNone)
   1.167 +		{
   1.168 +		TRequestStatus* status = &aStatus;
   1.169 +		User::RequestComplete(status, err);
   1.170 +		}
   1.171 +    else
   1.172 +        {
   1.173 +        iDigest->Update(aPlaintext);
   1.174 +        Sign(iDigest->Final(), aSignature, aStatus);
   1.175 +        }
   1.176 +	}
   1.177 +
   1.178 +void CDSARepudiableSigner::Sign(const TDesC8& aPlaintext, 
   1.179 +  				CDSASignature*& aSignature, 
   1.180 + 				TRequestStatus& aStatus)
   1.181 +	{
   1.182 +	iClient->RepudiableDSASign(Handle(),aPlaintext, aSignature, aStatus);
   1.183 +	}
   1.184 +
   1.185 +void CDSARepudiableSigner::CancelSign()
   1.186 +	{
   1.187 +	iClient->CancelRepudiableDSASign();
   1.188 +	}
   1.189 +
   1.190 +// CFSRSADecryptor /////////////////////////////////////////////////////////////
   1.191 +
   1.192 +CFSRSADecryptor* CFSRSADecryptor::New(CFSKeyStoreClient* aClient)
   1.193 +	{
   1.194 +	return new CFSRSADecryptor(aClient);
   1.195 +	}
   1.196 +
   1.197 +CFSRSADecryptor::CFSRSADecryptor(CFSKeyStoreClient* aClient)
   1.198 +		: MCTDecryptor(aClient->Token())
   1.199 +	{
   1.200 +	iClient = aClient;
   1.201 +	iHandle.iTokenHandle = aClient->Token().Handle();
   1.202 +	iHandle.iObjectId = 0;
   1.203 +	}
   1.204 +
   1.205 +CFSRSADecryptor::~CFSRSADecryptor()
   1.206 +	{
   1.207 +	}
   1.208 +
   1.209 +void CFSRSADecryptor::Release()
   1.210 +	{
   1.211 +	MCTTokenObject::Release();
   1.212 +	}
   1.213 +
   1.214 +const TDesC& CFSRSADecryptor::Label() const
   1.215 +	{
   1.216 +	return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
   1.217 +	}
   1.218 +
   1.219 +MCTToken& CFSRSADecryptor::Token() const
   1.220 +	{
   1.221 +	return iClient->Token();
   1.222 +	}
   1.223 +
   1.224 +TUid CFSRSADecryptor::Type() const
   1.225 +	{
   1.226 +	return KPrivateDecryptorUID;
   1.227 +	}
   1.228 +
   1.229 +TCTTokenObjectHandle CFSRSADecryptor::Handle() const
   1.230 +	{
   1.231 +	return iHandle;
   1.232 +	}
   1.233 +
   1.234 +void CFSRSADecryptor::Decrypt(const TDesC8& aCiphertext,
   1.235 +			TDes8& aPlaintext, 
   1.236 +			TRequestStatus& aStatus
   1.237 +	)
   1.238 +	{
   1.239 +	iClient->Decrypt(Handle(),aCiphertext,aPlaintext, aStatus);
   1.240 +	}
   1.241 +
   1.242 +void CFSRSADecryptor::CancelDecrypt()
   1.243 +	{
   1.244 +	iClient->CancelDecrypt();
   1.245 +	}
   1.246 +
   1.247 +// CDHAgreement ////////////////////////////////////////////////////////////////
   1.248 +
   1.249 +CDHAgreement* CDHAgreement::New(CFSKeyStoreClient* aClient)
   1.250 +	{
   1.251 +	return new CDHAgreement(aClient);
   1.252 +	}
   1.253 +
   1.254 +CDHAgreement::CDHAgreement(CFSKeyStoreClient* aClient)
   1.255 +	: MCTDH(aClient->Token())
   1.256 +	{
   1.257 +	iClient = aClient;
   1.258 +	iHandle.iTokenHandle = aClient->Token().Handle();
   1.259 +	iHandle.iObjectId = 0;
   1.260 +	}
   1.261 +
   1.262 +CDHAgreement::~CDHAgreement()
   1.263 +	{
   1.264 +	}
   1.265 +
   1.266 +void CDHAgreement::Release()
   1.267 +	{
   1.268 +	MCTTokenObject::Release();
   1.269 +	}
   1.270 +
   1.271 +const TDesC& CDHAgreement::Label() const
   1.272 +	{
   1.273 +	return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
   1.274 +	}
   1.275 +
   1.276 +MCTToken& CDHAgreement::Token() const
   1.277 +	{
   1.278 +	return iClient->Token();
   1.279 +	}
   1.280 +
   1.281 +TUid CDHAgreement::Type() const
   1.282 +	{
   1.283 +	return KKeyAgreementUID;
   1.284 +	}
   1.285 +
   1.286 +TCTTokenObjectHandle CDHAgreement::Handle() const
   1.287 +	{
   1.288 +	return iHandle;
   1.289 +	}
   1.290 +
   1.291 +/** Returns the public key ('Big X') for the supplied set of parameters */
   1.292 +void CDHAgreement::PublicKey(const TInteger& aN, const TInteger& aG, 
   1.293 +							 CDHPublicKey*& aX, TRequestStatus& aStatus)
   1.294 +	{
   1.295 +	iClient->DHPublicKey(Handle(), aN, aG, aX, aStatus);
   1.296 +	}
   1.297 +
   1.298 +/** Agrees a session key given the public key of the other party */
   1.299 +void CDHAgreement::Agree(const CDHPublicKey& iY, HBufC8*& aAgreedKey,
   1.300 +						 TRequestStatus& aStatus)
   1.301 +	{
   1.302 +	iClient->DHAgree(Handle(), iY, aAgreedKey, aStatus);
   1.303 +	}
   1.304 +
   1.305 +/** Cancels either a PublicKey or Agree operation */
   1.306 +void CDHAgreement::CancelAgreement()
   1.307 +	{
   1.308 +	iClient->CancelDH();
   1.309 +	}