networksecurity/tlsprovider/source/tlsprovider/CTlsProvider.cpp
branchRCL_3
changeset 7 db85996de7c4
parent 0 af10295192d8
child 20 7e41d162e158
equal deleted inserted replaced
6:c64cefac6e99 7:db85996de7c4
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    16 //
    16 //
    17 
    17 
    18 #include <ecom/ecom.h>
    18 #include <ecom/ecom.h>
    19 #include <securitydefsconst.h>
    19 #include <securitydefsconst.h>
    20 #include <x520ava.h>
    20 #include <x520ava.h>
       
    21 #include <asn1dec.h>
    21 
    22 
    22 #include "tlsprovider.h"
    23 #include "tlsprovider.h"
    23 #include "cryptostrength.h"
    24 #include "cryptostrength.h"
    24 
    25 
    25 
    26 
   478 		}
   479 		}
   479 	
   480 	
   480 	return;
   481 	return;
   481 	}
   482 	}
   482 
   483 
       
   484 // This patch is to fix-up the Common Name component of the Subject field. 
       
   485 // This is due to a bug in TASN1DecBMPString::DecodeContentsL which is incorrectly decoding the BMP String contents. 
       
   486 // Since fixing TASN1DecBMPString would cause a major break in public API, this fix-up is being done here locally.
       
   487 // This patch is active only if the encoding is in BMP String. If TASN1DecBMPString::DecodeContentsL is ever fixed (which 
       
   488 // means CX500DistinguishedName::DisplayNameL is also automatically fixed) then this patch MUST to be removed.
       
   489 
       
   490 HBufC* CTlsProviderImpl::ExtractCertFieldL(const TDesC& aFieldName, const CX500DistinguishedName& aDistinguishedName)
       
   491     {
       
   492     TInt count = aDistinguishedName.Count();
       
   493     for (TInt i = 0; i < count; i++)
       
   494         {
       
   495         const CX520AttributeTypeAndValue& ava = aDistinguishedName.Element(i);
       
   496         if (ava.Type() == aFieldName)
       
   497             {
       
   498             HBufC* res = ava.ValueL();
       
   499             CleanupStack::PushL(res);
       
   500             TPtr pRes = res->Des();
       
   501             TUint8* data = const_cast<TUint8 *>(reinterpret_cast<const TUint8 *>(res->Ptr())); 
       
   502             TUint len = pRes.Length()*2;
       
   503             TASN1DecGeneric gen(ava.EncodedValue());
       
   504             gen.InitL();
       
   505             if (gen.Tag() == EASN1BMPString)
       
   506                 {
       
   507                 // Bmp String internally store them as little endian, as a string we want it big
       
   508                 // endian interchange least and most significent byte
       
   509                 for(TUint i=0; i<len; i+=2)
       
   510                      {
       
   511                      TUint8 temp = data[i];
       
   512                      data[i] = data[i+1];
       
   513                      data[i+1] = temp;       
       
   514                      }
       
   515                 }
       
   516             CleanupStack::Pop();
       
   517             return res;
       
   518             }
       
   519         }
       
   520     return NULL;
       
   521     }
   483 
   522 
   484 
   523 
   485 TBool CTlsProviderImpl::VerifySignatureL(
   524 TBool CTlsProviderImpl::VerifySignatureL(
   486 		const CSubjectPublicKeyInfo& aServerPublicKey, 
   525 		const CSubjectPublicKeyInfo& aServerPublicKey, 
   487 		const TDesC8& aDigest,const TDesC8& aSignature)
   526 		const TDesC8& aDigest,const TDesC8& aSignature)
  1524 		
  1563 		
  1525 	// if the certificate has an alternative name extension, with DNS entries, ignore the common name	
  1564 	// if the certificate has an alternative name extension, with DNS entries, ignore the common name	
  1526 	if(!hasAltNameExt)
  1565 	if(!hasAltNameExt)
  1527 		{
  1566 		{
  1528 		// no name yet lets try common name from Subject
  1567 		// no name yet lets try common name from Subject
  1529 		HBufC* commonName = aSource.SubjectName().ExtractFieldL(KX520CommonName);
  1568 		//HBufC* commonName = aSource.SubjectName().ExtractFieldL(KX520CommonName);
       
  1569 		HBufC* commonName  = ExtractCertFieldL(KX520CommonName, aSource.SubjectName());
  1530 		if(commonName)
  1570 		if(commonName)
  1531 			{
  1571 			{
  1532 			CleanupStack::PushL(commonName);
  1572 			CleanupStack::PushL(commonName);
  1533 			TPtr name = commonName->Des();
  1573 			TPtr name = commonName->Des();
  1534 			// check for wildcard, we consider it only if left-most name component (see RFC 2595)
  1574 			// check for wildcard, we consider it only if left-most name component (see RFC 2595)