os/security/cryptoservices/filebasedcertificateandkeystores/source/keystore/Client/ClientOpenedKeys.cpp
Update contrib.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 #include <mctkeystore.h>
22 #include "ClientOpenedKeys.h"
23 #include "cfskeystoreclient.h"
25 #include <mctkeystoreuids.h>
28 // COpenedKey //////////////////////////////////////////////////////////////////
30 COpenedKey::~COpenedKey()
32 iClient->ReleaseObject(iHandle);
36 // CRSARepudiableSigner ////////////////////////////////////////////////////////
38 CRSARepudiableSigner* CRSARepudiableSigner::New(CFSKeyStoreClient* aClient)
40 return new CRSARepudiableSigner(aClient);
43 CRSARepudiableSigner::CRSARepudiableSigner(CFSKeyStoreClient* aClient)
44 : MCTSigner<CRSASignature*>(aClient->Token())
47 iHandle.iTokenHandle = aClient->Token().Handle();
48 iHandle.iObjectId = 0;
51 CRSARepudiableSigner::~CRSARepudiableSigner()
56 void CRSARepudiableSigner::Release()
58 MCTTokenObject::Release();
61 const TDesC& CRSARepudiableSigner::Label() const
63 return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
66 MCTToken& CRSARepudiableSigner::Token() const
68 return iClient->Token();
71 TUid CRSARepudiableSigner::Type() const
73 return KRSARepudiableSignerUID;
76 TCTTokenObjectHandle CRSARepudiableSigner::Handle() const
81 void CRSARepudiableSigner::SignMessage(const TDesC8& aPlaintext,
82 CRSASignature*& aSignature,
83 TRequestStatus& aStatus)
85 // Hash the data on the client side
86 TRAPD(err, iDigest = CSHA1::NewL());
89 TRequestStatus* status = &aStatus;
90 User::RequestComplete(status, err);
94 iDigest->Update(aPlaintext);
95 Sign(iDigest->Final(), aSignature, aStatus);
99 void CRSARepudiableSigner::Sign(const TDesC8& aPlaintext,
100 CRSASignature*& aSignature,
101 TRequestStatus& aStatus)
103 iClient->RepudiableRSASign(Handle(),aPlaintext, aSignature, aStatus);
106 void CRSARepudiableSigner::CancelSign()
108 iClient->CancelRepudiableRSASign();
111 // CDSARepudiableSigner ////////////////////////////////////////////////////////
113 CDSARepudiableSigner* CDSARepudiableSigner::New(CFSKeyStoreClient* aClient)
115 return new CDSARepudiableSigner(aClient);
118 CDSARepudiableSigner::CDSARepudiableSigner(CFSKeyStoreClient* aClient)
119 : MCTSigner<CDSASignature*>(aClient->Token())
122 iHandle.iTokenHandle = aClient->Token().Handle();
123 iHandle.iObjectId = 0;
127 CDSARepudiableSigner::~CDSARepudiableSigner()
132 void CDSARepudiableSigner::Release()
134 MCTTokenObject::Release();
137 const TDesC& CDSARepudiableSigner::Label() const
139 return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
142 MCTToken& CDSARepudiableSigner::Token() const
144 return iClient->Token();
147 TUid CDSARepudiableSigner::Type() const
149 return KDSARepudiableSignerUID;
152 TCTTokenObjectHandle CDSARepudiableSigner::Handle() const
157 void CDSARepudiableSigner::SignMessage(const TDesC8& aPlaintext,
158 CDSASignature*& aSignature,
159 TRequestStatus& aStatus)
161 // Hash the data on the client side
162 TRAPD(err, iDigest = CSHA1::NewL());
165 TRequestStatus* status = &aStatus;
166 User::RequestComplete(status, err);
170 iDigest->Update(aPlaintext);
171 Sign(iDigest->Final(), aSignature, aStatus);
175 void CDSARepudiableSigner::Sign(const TDesC8& aPlaintext,
176 CDSASignature*& aSignature,
177 TRequestStatus& aStatus)
179 iClient->RepudiableDSASign(Handle(),aPlaintext, aSignature, aStatus);
182 void CDSARepudiableSigner::CancelSign()
184 iClient->CancelRepudiableDSASign();
187 // CFSRSADecryptor /////////////////////////////////////////////////////////////
189 CFSRSADecryptor* CFSRSADecryptor::New(CFSKeyStoreClient* aClient)
191 return new CFSRSADecryptor(aClient);
194 CFSRSADecryptor::CFSRSADecryptor(CFSKeyStoreClient* aClient)
195 : MCTDecryptor(aClient->Token())
198 iHandle.iTokenHandle = aClient->Token().Handle();
199 iHandle.iObjectId = 0;
202 CFSRSADecryptor::~CFSRSADecryptor()
206 void CFSRSADecryptor::Release()
208 MCTTokenObject::Release();
211 const TDesC& CFSRSADecryptor::Label() const
213 return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
216 MCTToken& CFSRSADecryptor::Token() const
218 return iClient->Token();
221 TUid CFSRSADecryptor::Type() const
223 return KPrivateDecryptorUID;
226 TCTTokenObjectHandle CFSRSADecryptor::Handle() const
231 void CFSRSADecryptor::Decrypt(const TDesC8& aCiphertext,
233 TRequestStatus& aStatus
236 iClient->Decrypt(Handle(),aCiphertext,aPlaintext, aStatus);
239 void CFSRSADecryptor::CancelDecrypt()
241 iClient->CancelDecrypt();
244 // CDHAgreement ////////////////////////////////////////////////////////////////
246 CDHAgreement* CDHAgreement::New(CFSKeyStoreClient* aClient)
248 return new CDHAgreement(aClient);
251 CDHAgreement::CDHAgreement(CFSKeyStoreClient* aClient)
252 : MCTDH(aClient->Token())
255 iHandle.iTokenHandle = aClient->Token().Handle();
256 iHandle.iObjectId = 0;
259 CDHAgreement::~CDHAgreement()
263 void CDHAgreement::Release()
265 MCTTokenObject::Release();
268 const TDesC& CDHAgreement::Label() const
270 return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC);
273 MCTToken& CDHAgreement::Token() const
275 return iClient->Token();
278 TUid CDHAgreement::Type() const
280 return KKeyAgreementUID;
283 TCTTokenObjectHandle CDHAgreement::Handle() const
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)
292 iClient->DHPublicKey(Handle(), aN, aG, aX, aStatus);
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)
299 iClient->DHAgree(Handle(), iY, aAgreedKey, aStatus);
302 /** Cancels either a PublicKey or Agree operation */
303 void CDHAgreement::CancelAgreement()