vpnengine/pkiservice/src/pkimapper.cpp
branchRCL_3
changeset 44 735de8341ce4
parent 41 e06095241a65
child 49 5960d2d03390
equal deleted inserted replaced
41:e06095241a65 44:735de8341ce4
     1 /*
     1 /*
     2 * Copyright (c) 2006-2009 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".
   144 TInt CPKIMapper::GetCertDetailsL(TSecurityObjectDescriptor& aSecDesc, 
   144 TInt CPKIMapper::GetCertDetailsL(TSecurityObjectDescriptor& aSecDesc, 
   145                                  TPkiServiceStoreType aStoreType, 
   145                                  TPkiServiceStoreType aStoreType, 
   146                                  TBool aInfoOnly,
   146                                  TBool aInfoOnly,
   147                                  TCertificateListEntry& aResultCertInfo)
   147                                  TCertificateListEntry& aResultCertInfo)
   148     {
   148     {
       
   149     LOG(Log::Printf(_L("CPKIMapper::GetCertDetailsL\n")));
       
   150     
   149     TInt index;
   151     TInt index;
   150     TInt err = KErrNone;
   152     TInt err = KErrNone;
   151     
   153     
   152     TRAPD(leave, err = ResolveCertMappingL(aSecDesc, iObjectName, 
   154     TRAPD(leave, err = ResolveCertMappingL(aSecDesc, iObjectName, 
   153                                            index, aInfoOnly, 
   155                                            index, aInfoOnly, 
   157         return leave; 
   159         return leave; 
   158         }
   160         }
   159     
   161     
   160     if (err == KErrNone)
   162     if (err == KErrNone)
   161         {        
   163         {        
   162         const CMapDescriptor* mapping = (*iMapping)[index];        
   164         const CMapDescriptor* mapping = (*iMapping)[index];
   163         aResultCertInfo.iObjectName = mapping->Label();
   165         CopyCertDataL( *mapping, aResultCertInfo );  
   164         aResultCertInfo.iOwnerType = mapping->OwnerType();
   166         }
   165         aResultCertInfo.iTrustedAuthority = mapping->TrustedAuthority();
   167 
   166         aResultCertInfo.iIdentitySubjectName = mapping->IdentitySubjectName();
       
   167         aResultCertInfo.iSerialNumber = mapping->SerialNumber();
       
   168         aResultCertInfo.iSubjectKeyId = mapping->CertificateKeyId();
       
   169         aResultCertInfo.iKeySize = mapping->KeySize();                 
       
   170         aResultCertInfo.iKeyAlgorithm = mapping->KeyAlgorithm();       
       
   171         aResultCertInfo.iIsDeletable = mapping->Deletable();           
       
   172         }
       
   173     return err;    
   168     return err;    
   174     }
   169     }
   175 
   170 
   176 
   171 
   177 TInt CPKIMapper::GetCertListL(const RMessage2 &aMessage, TBool aInfoOnly)
   172 TInt CPKIMapper::GetCertListL(const RMessage2 &aMessage, TBool aInfoOnly)
   178 {
   173 {
       
   174     LOG(Log::Printf(_L("CPKIMapper::GetCertListL\n")));
       
   175 
   179     TInt pos = 0;
   176     TInt pos = 0;
   180     TInt iLast = 0;
   177     TInt iLast = 0;
   181     TInt iFirst = 0;
   178     TInt iFirst = 0;
   182     
   179     
   183     iLast = iMapping->Count();
   180     iLast = iMapping->Count();
   184     CBufFlat* list = CBufFlat::NewL(sizeof(TCertificateListEntry));
   181     CBufFlat* list = CBufFlat::NewL(sizeof(TCertificateListEntry));
   185     CleanupStack::PushL(list);
   182     CleanupStack::PushL(list);
   186     list->ResizeL(iCount * sizeof(TCertificateListEntry));
   183     list->ResizeL(iCount * sizeof(TCertificateListEntry));
   187     TCertificateListEntry certInfo;
   184     
       
   185     TCertificateListEntry* certInfo = new (ELeave) TCertificateListEntry();
       
   186     CleanupStack::PushL( certInfo );
   188     
   187     
   189     for(TInt i = iFirst; i < iLast; i++)
   188     for(TInt i = iFirst; i < iLast; i++)
   190         {
   189         {
   191         CMapDescriptor* mapping = (*iMapping)[i];
   190         CMapDescriptor* mapping = (*iMapping)[i];
   192         if(aInfoOnly || mapping->CertValidity() != CMapDescriptor::EExpired)
   191         if(aInfoOnly || mapping->CertValidity() != CMapDescriptor::EExpired)
   193             {
   192             {
   194             certInfo.iObjectName = mapping->Label();
   193             CopyCertDataL( *mapping, *certInfo );
   195             certInfo.iOwnerType = mapping->OwnerType();
       
   196             certInfo.iTrustedAuthority = mapping->TrustedAuthority();
       
   197             certInfo.iIdentitySubjectName = mapping->IdentitySubjectName();
       
   198             certInfo.iSerialNumber = mapping->SerialNumber();
       
   199             certInfo.iSubjectKeyId = mapping->CertificateKeyId();
       
   200             certInfo.iKeySize = mapping->KeySize();                   // Key size
       
   201             certInfo.iKeyAlgorithm = mapping->KeyAlgorithm();         // RSA, DSA
       
   202             certInfo.iIsDeletable = mapping->Deletable();           // IsDeletable
       
   203 
   194 
   204             list->Write(pos * sizeof(TCertificateListEntry),
   195             list->Write(pos * sizeof(TCertificateListEntry),
   205                         (TAny*)&certInfo,
   196                         (TAny*)certInfo,
   206                         sizeof(TCertificateListEntry));
   197                         sizeof(TCertificateListEntry));
   207             pos++;
   198             pos++;
   208             if(pos >= iCount)
   199             if(pos >= iCount)
   209                 {
   200                 {
   210                 break;
   201                 break;
   212             }            
   203             }            
   213         }
   204         }
   214     TPtr8 ptrList = list->Ptr(0);
   205     TPtr8 ptrList = list->Ptr(0);
   215     aMessage.WriteL(0, ptrList);
   206     aMessage.WriteL(0, ptrList);
   216 
   207 
   217     CleanupStack::PopAndDestroy(1); // list
   208     CleanupStack::PopAndDestroy(  2 );  // list, certInfo
   218     return KErrNone;
   209     return KErrNone;
   219 }
   210 }
   220 
   211 
   221 
   212 
   222 void CPKIMapper::GetApplicableCertListL(const RMessage2& aMessage, const RArray<TUid>& aUidArray)
   213 void CPKIMapper::GetApplicableCertListL(const RMessage2& aMessage, const RArray<TUid>& aUidArray)
   223 {
   214 {
       
   215     LOG(Log::Printf(_L("CPKIMapper::GetApplicableCertListL\n")));
       
   216     
   224     TInt pos = 0;
   217     TInt pos = 0;
   225     
   218     
   226     CBufFlat* list = CBufFlat::NewL(sizeof(TCertificateListEntry));
   219     CBufFlat* list = CBufFlat::NewL(sizeof(TCertificateListEntry));
   227     CleanupStack::PushL(list);
   220     CleanupStack::PushL(list);
   228     list->ResizeL(iCount * sizeof(TCertificateListEntry));
   221     list->ResizeL(iCount * sizeof(TCertificateListEntry));
   229     TCertificateListEntry certInfo;
   222 
       
   223     TCertificateListEntry* certInfo = new (ELeave) TCertificateListEntry();
       
   224     CleanupStack::PushL( certInfo );
   230 
   225 
   231     for(TInt i = 0; (i < iMapping->Count()) && (pos < iCount); i++)
   226     for(TInt i = 0; (i < iMapping->Count()) && (pos < iCount); i++)
   232         {
   227         {
   233         CMapDescriptor* mapping = (*iMapping)[i];
   228         CMapDescriptor* mapping = (*iMapping)[i];
   234         if(mapping->OwnerType() == EPKICACertificate)
   229         if(mapping->OwnerType() == EPKICACertificate)
   237                 {
   232                 {
   238                 for(TInt j = 0; j < aUidArray.Count(); j++)
   233                 for(TInt j = 0; j < aUidArray.Count(); j++)
   239                     {
   234                     {
   240                     if(mapping->IsApplicable(aUidArray[j]))
   235                     if(mapping->IsApplicable(aUidArray[j]))
   241                         {
   236                         {
   242                         certInfo.iObjectName = mapping->Label();
   237                         CopyCertDataL( *mapping, *certInfo );
   243                         certInfo.iOwnerType = mapping->OwnerType();
       
   244                         certInfo.iTrustedAuthority = mapping->TrustedAuthority();
       
   245                         certInfo.iIdentitySubjectName = mapping->IdentitySubjectName();
       
   246                         certInfo.iSerialNumber = mapping->SerialNumber();
       
   247                         certInfo.iSubjectKeyId = mapping->CertificateKeyId();
       
   248                         certInfo.iKeySize = mapping->KeySize();                   // Key size
       
   249                         certInfo.iKeyAlgorithm = mapping->KeyAlgorithm();         // RSA, DSA
       
   250                         certInfo.iIsDeletable = mapping->Deletable();           // IsDeletable
       
   251 
   238 
   252                         list->Write(pos * sizeof(TCertificateListEntry),
   239                         list->Write(pos * sizeof(TCertificateListEntry),
   253                                     (TAny*)&certInfo,
   240                                     (TAny*)certInfo,
   254                                     sizeof(TCertificateListEntry));
   241                                     sizeof(TCertificateListEntry));
   255                         pos++;
   242                         pos++;
   256                         break;
   243                         break;
   257                         }
   244                         }
   258                     }
   245                     }
   260             }
   247             }
   261         }
   248         }
   262     TPtr8 ptrList = list->Ptr(0);
   249     TPtr8 ptrList = list->Ptr(0);
   263     aMessage.WriteL(0, ptrList);
   250     aMessage.WriteL(0, ptrList);
   264 
   251 
   265     CleanupStack::PopAndDestroy(1); // list
   252     CleanupStack::PopAndDestroy( 2 );  // list, certInfo
   266 }
   253 }
   267 
   254 
   268 
   255 
   269 
   256 
   270 CMapDescriptor& CPKIMapper::GetMapDescriptorAtIndex(TInt aIndex)
   257 CMapDescriptor& CPKIMapper::GetMapDescriptorAtIndex(TInt aIndex)
   488     }    
   475     }    
   489   
   476   
   490 
   477 
   491 void CPKIMapper::LogSearchArguments(TSecurityObjectDescriptor &aDescriptor) const
   478 void CPKIMapper::LogSearchArguments(TSecurityObjectDescriptor &aDescriptor) const
   492     {
   479     {
   493     TBuf<256> temp;
       
   494     LOG(Log::Printf(_L("====Object Search arguments====\n")));
   480     LOG(Log::Printf(_L("====Object Search arguments====\n")));
   495     if(aDescriptor.iTrustedAuthorityUsed)
   481     if(aDescriptor.iTrustedAuthorityUsed)
   496         {
   482         {
   497         temp.Copy(aDescriptor.iTrustedAuthority);
   483         LOG(Log::Printf(_L("Trusted authority:")));
   498         if((aDescriptor.iTrustedAuthority[0] != 0x30)
   484         LOG(Log::HexDump(NULL, NULL, aDescriptor.iTrustedAuthority.Ptr(), aDescriptor.iTrustedAuthority.Length()));
   499            || ((aDescriptor.iTrustedAuthority[1] != 0x81)
       
   500                && (aDescriptor.iTrustedAuthority[1] != 0x82)
       
   501                && ((aDescriptor.iTrustedAuthority[1] + 2) != aDescriptor.iTrustedAuthority.Length())))
       
   502             {
       
   503             LOG(Log::Printf(_L("Trusted authority: %S\n"), &temp));
       
   504             }
       
   505         else
       
   506             {
       
   507             LOG(Log::Printf(_L("Trusted authority:")));
       
   508             LOG(Log::HexDump(NULL, NULL, aDescriptor.iTrustedAuthority.Ptr(), aDescriptor.iTrustedAuthority.Length()));
       
   509             }
       
   510         }
   485         }
   511     if(aDescriptor.iIdentitySubjectNameUsed)
   486     if(aDescriptor.iIdentitySubjectNameUsed)
   512         {
   487         {
   513         temp.Copy(aDescriptor.iIdentitySubjectName);
   488         LOG(Log::Printf(_L("SubjectName:")));
   514         if((aDescriptor.iIdentitySubjectName[0] != 0x30)
   489         LOG(Log::HexDump(NULL, NULL, aDescriptor.iIdentitySubjectName.Ptr(), aDescriptor.iIdentitySubjectName.Length()));
   515            || ((aDescriptor.iIdentitySubjectName[1] != 0x81)
       
   516                && (aDescriptor.iIdentitySubjectName[1] != 0x82)
       
   517                && ((aDescriptor.iIdentitySubjectName[1] + 2) != aDescriptor.iIdentitySubjectName.Length())))
       
   518             {
       
   519             LOG(Log::Printf(_L("SubjectName: %S\n"), &temp));
       
   520             }
       
   521         else
       
   522             {
       
   523             LOG(Log::Printf(_L("SubjectName:")));
       
   524             LOG(Log::HexDump(NULL, NULL, aDescriptor.iIdentitySubjectName.Ptr(), aDescriptor.iIdentitySubjectName.Length()));
       
   525             }
       
   526         }
   490         }
   527     if(aDescriptor.iIdentityRfc822NameUsed)
   491     if(aDescriptor.iIdentityRfc822NameUsed)
   528         {
   492         {
   529         temp.Copy(aDescriptor.iIdentityRfc822Name);
   493         LOG(Log::Printf(_L("Rfc822Name: %S\n"), &aDescriptor.iIdentityRfc822Name));
   530         LOG(Log::Printf(_L("Rfc822Name: %S\n"), &temp));
       
   531         }
   494         }
   532     if(aDescriptor.iSerialNumberUsed)
   495     if(aDescriptor.iSerialNumberUsed)
   533         {
   496         {
   534         LOG(Log::Printf(_L("SerialNumber:")));
   497         LOG(Log::Printf(_L("SerialNumber:")));
   535         LOG(Log::HexDump(NULL, NULL, aDescriptor.iSerialNumber.Ptr(), aDescriptor.iSerialNumber.Length()));
   498         LOG(Log::HexDump(NULL, NULL, aDescriptor.iSerialNumber.Ptr(), aDescriptor.iSerialNumber.Length()));
   556         {
   519         {
   557         LOG(Log::Printf(_L("KeyAlgorithm: %d\n"), aDescriptor.iKeyAlgorithm));
   520         LOG(Log::Printf(_L("KeyAlgorithm: %d\n"), aDescriptor.iKeyAlgorithm));
   558         }
   521         }
   559     }   
   522     }   
   560 
   523 
       
   524 
       
   525 void CPKIMapper::CopyCertDataL(
       
   526     const CMapDescriptor& aMapping, TCertificateListEntry& aCertInfo ) const
       
   527     {
       
   528     LOG(Log::Printf(_L("CPKIMapper::CopyCertDataL\n")));
       
   529 
       
   530     TInt len = 0;
       
   531 
       
   532     aCertInfo.iObjectName = aMapping.Label();
       
   533     aCertInfo.iOwnerType  = aMapping.OwnerType();
       
   534 
       
   535     TPtrC8 ta = aMapping.TrustedAuthority();
       
   536     len = ta.Length();
       
   537 
       
   538     if( KMaxX500DN >= len )
       
   539         {
       
   540         aCertInfo.iTrustedAuthority = ta;
       
   541         }
       
   542     else
       
   543         {
       
   544         LOG(Log::Printf(_L("Trusted authority length: %d\n"), len ));
       
   545         User::Leave( KErrArgument );
       
   546         }
       
   547 
       
   548     TPtrC8 isn = aMapping.IdentitySubjectName();       
       
   549     len = isn.Length();
       
   550     
       
   551     if( KMaxX500DN >= len )
       
   552         {
       
   553         aCertInfo.iIdentitySubjectName = isn;
       
   554         }
       
   555     else{
       
   556         LOG(Log::Printf(_L("Subject name length: %d\n"), len ));
       
   557         User::Leave( KErrArgument );
       
   558         }    
       
   559     
       
   560     TPtrC8 sn = aMapping.SerialNumber();
       
   561     len = sn.Length();
       
   562             
       
   563     if( KMaxSerial >= len )
       
   564         {
       
   565         aCertInfo.iSerialNumber = sn;
       
   566         }
       
   567     else
       
   568         {
       
   569         LOG(Log::Printf(_L("Serial number length: %d\n"), len ));
       
   570         User::Leave( KErrArgument );
       
   571         }
       
   572 
       
   573     aCertInfo.iSubjectKeyId = aMapping.CertificateKeyId();
       
   574     aCertInfo.iKeySize      = aMapping.KeySize();
       
   575     aCertInfo.iKeyAlgorithm = aMapping.KeyAlgorithm();  // RSA, DSA
       
   576     aCertInfo.iIsDeletable  = aMapping.Deletable();
       
   577     }
       
   578