os/security/cryptoservices/filebasedcertificateandkeystores/source/keystore/Client/ClientOpenedKeys.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2004-2009 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: 
    15 *
    16 */
    17 
    18 
    19 #include <e32base.h>
    20 #include <ct.h>
    21 #include <mctkeystore.h>
    22 #include "ClientOpenedKeys.h"
    23 #include "cfskeystoreclient.h"
    24 #include "hash.h"
    25 #include <mctkeystoreuids.h>
    26 
    27 
    28 // COpenedKey //////////////////////////////////////////////////////////////////
    29 	
    30 COpenedKey::~COpenedKey()
    31 	{
    32 	iClient->ReleaseObject(iHandle);
    33 	delete iLabel;
    34 	}
    35 
    36 // CRSARepudiableSigner ////////////////////////////////////////////////////////
    37 
    38 CRSARepudiableSigner* CRSARepudiableSigner::New(CFSKeyStoreClient* aClient)
    39 	{
    40 	return new CRSARepudiableSigner(aClient);
    41 	}
    42 
    43 CRSARepudiableSigner::CRSARepudiableSigner(CFSKeyStoreClient* aClient)
    44 		: MCTSigner<CRSASignature*>(aClient->Token())
    45 	{
    46 	iClient = aClient;
    47 	iHandle.iTokenHandle = aClient->Token().Handle();
    48 	iHandle.iObjectId = 0;
    49 	}
    50 
    51 CRSARepudiableSigner::~CRSARepudiableSigner()
    52 	{
    53 	delete iDigest;
    54 	}
    55 
    56 void CRSARepudiableSigner::Release()
    57 	{
    58 	MCTTokenObject::Release();
    59 	}
    60 
    61 const TDesC& CRSARepudiableSigner::Label() const
    62 	{
    63 	return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
    64 	}
    65 
    66 MCTToken& CRSARepudiableSigner::Token() const
    67 	{
    68 	return iClient->Token();
    69 	}
    70 
    71 TUid CRSARepudiableSigner::Type() const
    72 	{
    73 	return KRSARepudiableSignerUID;
    74 	}
    75 
    76 TCTTokenObjectHandle CRSARepudiableSigner::Handle() const
    77 	{
    78 	return iHandle;
    79 	}
    80 
    81 void CRSARepudiableSigner::SignMessage(const TDesC8& aPlaintext, 
    82   				CRSASignature*& aSignature, 
    83   				TRequestStatus& aStatus)
    84 	{
    85 	// Hash the data on the client side
    86 	TRAPD(err, iDigest = CSHA1::NewL());
    87 	if (err != KErrNone)
    88 		{
    89 		TRequestStatus* status = &aStatus;
    90 		User::RequestComplete(status, err);
    91 		}
    92     else
    93         {
    94         iDigest->Update(aPlaintext);	
    95         Sign(iDigest->Final(), aSignature, aStatus);
    96         }
    97 	}
    98 
    99 void CRSARepudiableSigner::Sign(const TDesC8& aPlaintext, 
   100   				CRSASignature*& aSignature, 
   101   				TRequestStatus& aStatus)
   102 	{
   103 	iClient->RepudiableRSASign(Handle(),aPlaintext, aSignature, aStatus);
   104 	}
   105 
   106 void CRSARepudiableSigner::CancelSign()
   107 	{
   108 	iClient->CancelRepudiableRSASign();
   109 	}
   110 
   111 // CDSARepudiableSigner ////////////////////////////////////////////////////////
   112 
   113 CDSARepudiableSigner* CDSARepudiableSigner::New(CFSKeyStoreClient* aClient)
   114 	{
   115 	return new CDSARepudiableSigner(aClient);
   116 	}
   117 
   118 CDSARepudiableSigner::CDSARepudiableSigner(CFSKeyStoreClient* aClient)
   119 		: MCTSigner<CDSASignature*>(aClient->Token())
   120 	{
   121 	iClient = aClient;
   122 	iHandle.iTokenHandle = aClient->Token().Handle();
   123 	iHandle.iObjectId = 0;
   124 	}
   125 
   126 
   127 CDSARepudiableSigner::~CDSARepudiableSigner()
   128 	{
   129 	delete iDigest;
   130 	}
   131 
   132 void CDSARepudiableSigner::Release()
   133 	{
   134 	MCTTokenObject::Release();
   135 	}
   136 
   137 const TDesC& CDSARepudiableSigner::Label() const
   138 	{
   139 	return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
   140 	}
   141 
   142 MCTToken& CDSARepudiableSigner::Token() const
   143 	{
   144 	return iClient->Token();
   145 	}
   146 
   147 TUid CDSARepudiableSigner::Type() const
   148 	{
   149 	return KDSARepudiableSignerUID;
   150 	}
   151 
   152 TCTTokenObjectHandle CDSARepudiableSigner::Handle() const
   153 	{
   154 	return iHandle;
   155 	}
   156 
   157 void CDSARepudiableSigner::SignMessage(const TDesC8& aPlaintext, 
   158   				CDSASignature*& aSignature, 
   159  				TRequestStatus& aStatus)
   160 	{
   161 	// Hash the data on the client side
   162 	TRAPD(err, iDigest = CSHA1::NewL());
   163 	if (err != KErrNone)
   164 		{
   165 		TRequestStatus* status = &aStatus;
   166 		User::RequestComplete(status, err);
   167 		}
   168     else
   169         {
   170         iDigest->Update(aPlaintext);
   171         Sign(iDigest->Final(), aSignature, aStatus);
   172         }
   173 	}
   174 
   175 void CDSARepudiableSigner::Sign(const TDesC8& aPlaintext, 
   176   				CDSASignature*& aSignature, 
   177  				TRequestStatus& aStatus)
   178 	{
   179 	iClient->RepudiableDSASign(Handle(),aPlaintext, aSignature, aStatus);
   180 	}
   181 
   182 void CDSARepudiableSigner::CancelSign()
   183 	{
   184 	iClient->CancelRepudiableDSASign();
   185 	}
   186 
   187 // CFSRSADecryptor /////////////////////////////////////////////////////////////
   188 
   189 CFSRSADecryptor* CFSRSADecryptor::New(CFSKeyStoreClient* aClient)
   190 	{
   191 	return new CFSRSADecryptor(aClient);
   192 	}
   193 
   194 CFSRSADecryptor::CFSRSADecryptor(CFSKeyStoreClient* aClient)
   195 		: MCTDecryptor(aClient->Token())
   196 	{
   197 	iClient = aClient;
   198 	iHandle.iTokenHandle = aClient->Token().Handle();
   199 	iHandle.iObjectId = 0;
   200 	}
   201 
   202 CFSRSADecryptor::~CFSRSADecryptor()
   203 	{
   204 	}
   205 
   206 void CFSRSADecryptor::Release()
   207 	{
   208 	MCTTokenObject::Release();
   209 	}
   210 
   211 const TDesC& CFSRSADecryptor::Label() const
   212 	{
   213 	return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
   214 	}
   215 
   216 MCTToken& CFSRSADecryptor::Token() const
   217 	{
   218 	return iClient->Token();
   219 	}
   220 
   221 TUid CFSRSADecryptor::Type() const
   222 	{
   223 	return KPrivateDecryptorUID;
   224 	}
   225 
   226 TCTTokenObjectHandle CFSRSADecryptor::Handle() const
   227 	{
   228 	return iHandle;
   229 	}
   230 
   231 void CFSRSADecryptor::Decrypt(const TDesC8& aCiphertext,
   232 			TDes8& aPlaintext, 
   233 			TRequestStatus& aStatus
   234 	)
   235 	{
   236 	iClient->Decrypt(Handle(),aCiphertext,aPlaintext, aStatus);
   237 	}
   238 
   239 void CFSRSADecryptor::CancelDecrypt()
   240 	{
   241 	iClient->CancelDecrypt();
   242 	}
   243 
   244 // CDHAgreement ////////////////////////////////////////////////////////////////
   245 
   246 CDHAgreement* CDHAgreement::New(CFSKeyStoreClient* aClient)
   247 	{
   248 	return new CDHAgreement(aClient);
   249 	}
   250 
   251 CDHAgreement::CDHAgreement(CFSKeyStoreClient* aClient)
   252 	: MCTDH(aClient->Token())
   253 	{
   254 	iClient = aClient;
   255 	iHandle.iTokenHandle = aClient->Token().Handle();
   256 	iHandle.iObjectId = 0;
   257 	}
   258 
   259 CDHAgreement::~CDHAgreement()
   260 	{
   261 	}
   262 
   263 void CDHAgreement::Release()
   264 	{
   265 	MCTTokenObject::Release();
   266 	}
   267 
   268 const TDesC& CDHAgreement::Label() const
   269 	{
   270 	return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
   271 	}
   272 
   273 MCTToken& CDHAgreement::Token() const
   274 	{
   275 	return iClient->Token();
   276 	}
   277 
   278 TUid CDHAgreement::Type() const
   279 	{
   280 	return KKeyAgreementUID;
   281 	}
   282 
   283 TCTTokenObjectHandle CDHAgreement::Handle() const
   284 	{
   285 	return iHandle;
   286 	}
   287 
   288 /** Returns the public key ('Big X') for the supplied set of parameters */
   289 void CDHAgreement::PublicKey(const TInteger& aN, const TInteger& aG, 
   290 							 CDHPublicKey*& aX, TRequestStatus& aStatus)
   291 	{
   292 	iClient->DHPublicKey(Handle(), aN, aG, aX, aStatus);
   293 	}
   294 
   295 /** Agrees a session key given the public key of the other party */
   296 void CDHAgreement::Agree(const CDHPublicKey& iY, HBufC8*& aAgreedKey,
   297 						 TRequestStatus& aStatus)
   298 	{
   299 	iClient->DHAgree(Handle(), iY, aAgreedKey, aStatus);
   300 	}
   301 
   302 /** Cancels either a PublicKey or Agree operation */
   303 void CDHAgreement::CancelAgreement()
   304 	{
   305 	iClient->CancelDH();
   306 	}