pkiutilities/DeviceToken/Src/Certstore/server/DevandTruSrvCertStoreServer.cpp
changeset 17 8957df7b0072
parent 0 164170e6151a
equal deleted inserted replaced
15:318c4eab2439 17:8957df7b0072
     1 /*
     1 /*
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   329 //
   329 //
   330 void CDevandTruSrvCertStoreServer::AddL(const TDevTokenAddCertDataStruct& aInfo,
   330 void CDevandTruSrvCertStoreServer::AddL(const TDevTokenAddCertDataStruct& aInfo,
   331                 const TDesC8& aCert,
   331                 const TDesC8& aCert,
   332                 const RMessage2& aMessage, TBool aFromTruSiteSrv )
   332                 const RMessage2& aMessage, TBool aFromTruSiteSrv )
   333     {
   333     {
   334     // Check if a certificate with this name already exists
       
   335     if (iEntryList->LabelExists(aInfo.iLabel))
       
   336         {
       
   337         User::Leave(KErrBadName);
       
   338         }
       
   339 
       
   340     // Check subject key id and cert data are supplied, issuer key id is optional
   334     // Check subject key id and cert data are supplied, issuer key id is optional
   341     if (aInfo.iSubjectKeyId == KNullDesC8 || aCert == KNullDesC8)
   335     if (aInfo.iSubjectKeyId == KNullDesC8 || aCert == KNullDesC8)
   342         {
   336         {
   343         User::Leave(KErrArgument);
   337         User::Leave(KErrArgument);
   344         }
   338         }
   401     TRAPD(err, UpdateStoreL());
   395     TRAPD(err, UpdateStoreL());
   402     if ( (err == KErrNone) && (aCertInfo.CertificateOwnerType() == EPeerCertificate ))
   396     if ( (err == KErrNone) && (aCertInfo.CertificateOwnerType() == EPeerCertificate ))
   403         {
   397         {
   404         CX509Certificate* cert = CX509Certificate::NewLC( aCertData );
   398         CX509Certificate* cert = CX509Certificate::NewLC( aCertData );
   405         TBuf8<KSHA1Length> certHash;
   399         TBuf8<KSHA1Length> certHash;
   406         certHash.Copy(cert->Fingerprint()); 
   400         certHash.Copy(cert->Fingerprint());
   407          
   401 
   408           
       
   409         const CX500DistinguishedName& dName = cert->SubjectName();
   402         const CX500DistinguishedName& dName = cert->SubjectName();
   410         // Retrieve CN
   403         // Retrieve CN
   411         HBufC* cn = dName.ExtractFieldL( KX520CommonName );  
   404         HBufC* cn = dName.ExtractFieldL( KX520CommonName );
   412         CleanupStack::PushL(cn);  
   405         if( cn )
   413         iTrustedSitesServer->AddL( certHash, *cn );
   406             {
   414 
   407             CleanupStack::PushL( cn );
   415         CleanupStack::PopAndDestroy( 2 );//cert, cn	
   408             iTrustedSitesServer->AddL( certHash, *cn );
       
   409             CleanupStack::PopAndDestroy( cn );
       
   410             }
       
   411 
       
   412         CleanupStack::PopAndDestroy( cert );
   416         }
   413         }
   417     if (err != KErrNone)
   414     if (err != KErrNone)
   418         {
   415         {
   419         iEntryList->Remove(index);
   416         iEntryList->Remove(index);
   420         delete entry;
   417         delete entry;