cryptoservices/certificateandkeymgmt/x500/x520ava.cpp
changeset 8 35751d3474b7
parent 0 2c201484c85f
child 19 ece3df019add
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
    19 #include <x520ava.h>
    19 #include <x520ava.h>
    20 #include "X500dec.h"
    20 #include "X500dec.h"
    21 #include <asn1enc.h>
    21 #include <asn1enc.h>
    22 #include <asn1dec.h>
    22 #include <asn1dec.h>
    23 
    23 
       
    24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    25 //these are the only attribute types we handle at present
       
    26 _LIT(KX520PostalCode,"2.5.4.17");
       
    27 _LIT(KRFC2247DomainComponent, "0.9.2342.19200300.100.1.25");
       
    28 _LIT(KRFC2256Street,"2.5.4.9");
       
    29 _LIT(KPKCS9UnstructuredName, "1.2.840.113549.1.9.2");
       
    30 
       
    31 //email address is deprecated but we support it anyway...
       
    32 _LIT(KPKCS9EmailAddress, "1.2.840.113549.1.9.1");
       
    33 
       
    34 /** The maximum length allowed for a country name. */
       
    35 const TInt KX520MaxCLength = 2;
       
    36 /** The maximum length allowed for an organization name. */
       
    37 const TInt KX520MaxOLength = 64;
       
    38 /** The maximum length allowed for an organizational unit name. */
       
    39 const TInt KX520MaxOULength = 64;
       
    40 /** The maximum length allowed for a locality name. */
       
    41 const TInt KX520MaxLLength = 128;
       
    42 /** The maximum length allowed for a state or province name. */
       
    43 const TInt KX520MaxSOPLength = 128;
       
    44 /** The maximum length allowed for an title. */
       
    45 const TInt KX520MaxTLength = 64;
       
    46 /** The maximum length allowed for a common name. */
       
    47 const TInt KX520MaxCNLength = 256;
       
    48 /** The maximum length allowed for a given name. */
       
    49 const TInt KX520MaxGNLength = 16;
       
    50 /** The maximum length allowed for a surname. */
       
    51 const TInt KX520MaxSLength = 40;
       
    52 /** The maximum length allowed for initials. */
       
    53 const TInt KX520MaxILength = 5;
       
    54 /** The maximum length allowed for a generation qualifier. */
       
    55 const TInt KX520MaxGQLength = 3;
       
    56 /** The maximum length allowed for a serial number. */
       
    57 const TInt KX520MaxSNLength = 64;
       
    58 /** The maximum length allowed for a postal code. */
       
    59 const TInt KX520MaxPostalCodeLength = 40;
       
    60 /** The maximum length allowed for an email address. */
       
    61 const TInt KPKCS9MaxEmailAddressLength = 256;
       
    62 /** The maximum length allowed for an unstructured name. */
       
    63 const TInt KPKCS9MaxUnstructuredNameLength = 256;
       
    64 // No maximum was specified in the standard - 128 should be sufficient
       
    65 /** The maximum length allowed for an RFC 2247 domain component. 
       
    66 * 
       
    67 * Each component of the domain name is a short string. */
       
    68 const TInt KRFC2247MaxDomainComponentLength = 128;
       
    69 /** The maximum length allowed a for street. */
       
    70 const TInt KRFC2256StreetLength = 128;
       
    71 
       
    72 #endif
       
    73 
    24 EXPORT_C CX520AttributeTypeAndValue* CX520AttributeTypeAndValue::NewL(const CX520AttributeTypeAndValue& aPair)
    74 EXPORT_C CX520AttributeTypeAndValue* CX520AttributeTypeAndValue::NewL(const CX520AttributeTypeAndValue& aPair)
    25 	{
    75 	{
    26 	CX520AttributeTypeAndValue* self = CX520AttributeTypeAndValue::NewLC(aPair);
    76 	CX520AttributeTypeAndValue* self = CX520AttributeTypeAndValue::NewLC(aPair);
    27 	CleanupStack::Pop();//self
    77 	CleanupStack::Pop();//self
    28 	return self;
    78 	return self;
   398 		}
   448 		}
   399 	if (maxLength == 0)
   449 	if (maxLength == 0)
   400 		{
   450 		{
   401 		User::Leave(KErrNotSupported);
   451 		User::Leave(KErrNotSupported);
   402 		}
   452 		}
   403 
       
   404 	TASN1DecX500DirectoryString encDString;
   453 	TASN1DecX500DirectoryString encDString;
   405 	TInt pos = 0;
   454 	TInt pos = 0;
   406 	HBufC* res = encDString.DecodeDERL(iValue->Des(), pos, maxLength);
   455 	HBufC* res = encDString.DecodeDERL(iValue->Des(), pos, maxLength);
   407 	return res;
   456 	return res;
   408 	}
   457 	}
   409 
   458 
   410 TBool CX520AttributeTypeAndValue::IsCaseInSensitive(const TDesC8& aSource) const
   459 TBool CX520AttributeTypeAndValue::IsCaseInSensitiveL(const TDesC8& aSource) const
   411 	{
   460 	{
   412 	TPtr attribute = iType->Des();
   461 	TPtr attribute = iType->Des();
   413 	TBool caseInsensitiveAttr = (attribute == KPKCS9EmailAddress || attribute == KPKCS9UnstructuredName);
   462 	TBool caseInsensitiveAttr = (attribute == KPKCS9EmailAddress || attribute == KPKCS9UnstructuredName);
   414 	TASN1DecGeneric gen(aSource);
   463 	TASN1DecGeneric gen(aSource);
   415 	gen.InitL();
   464 	gen.InitL();
   416 	return ((gen.Tag() == EASN1PrintableString) || caseInsensitiveAttr);
   465 	return ((gen.Tag() == EASN1PrintableString) || caseInsensitiveAttr);
   417 	}
   466 	}
       
   467 
   418 
   468 
   419 EXPORT_C CASN1EncSequence* CX520AttributeTypeAndValue::EncodeASN1LC() const
   469 EXPORT_C CASN1EncSequence* CX520AttributeTypeAndValue::EncodeASN1LC() const
   420 	{
   470 	{
   421 	CASN1EncSequence *seq = CASN1EncSequence::NewLC();
   471 	CASN1EncSequence *seq = CASN1EncSequence::NewLC();
   422 	CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC(Type());
   472 	CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC(Type());
   468 	TPtr plhs = lhs->Des();
   518 	TPtr plhs = lhs->Des();
   469 	TPtr prhs = rhs->Des();
   519 	TPtr prhs = rhs->Des();
   470 	plhs.TrimAll();
   520 	plhs.TrimAll();
   471 	prhs.TrimAll();
   521 	prhs.TrimAll();
   472 
   522 
   473 	// PDEF125098: Certificate name matching done in accordance to RFC3280
   523 
       
   524 	// DEF124902: Certificate name matching done in accordance to RFC3280
   474 	// RFC3280: Printable String and Email address(of value type 'IA5String') will 
   525 	// RFC3280: Printable String and Email address(of value type 'IA5String') will 
   475 	// be compared case-insensitively.  
   526  	// be compared case-insensitively.  
   476 	if (IsCaseInSensitive(iValue->Des()))
   527  	
   477 		{
   528     if (IsCaseInSensitiveL(iValue->Des()))
   478 		//case insensitive comparison for Printable String and IA5String (EmailAdress only).
   529  	    {
   479 		res = (plhs.CompareF(prhs) == 0);
   530  	     //case insensitive comparison for Printable String and IA5String (EmailAdress only).
   480 		}
   531  	     res = (plhs.CompareF(prhs) == 0);
   481 	else
   532  	    }
   482 		{
   533     else
   483 		// case-sensitive comparison for strings other than printable string 
   534 	    {
   484 		// Exception: This may include IA5Stings other than 'EmailAddress' attiribute types.
   535 	     // case-sensitive comparison for strings other than printable string 
   485 		res = (plhs.Compare(prhs) == 0);
   536 	     // Exception: This may include IA5Stings other than 'EmailAddress' attiribute types.
   486 		}
   537  	     res = (plhs.Compare(prhs) == 0);
       
   538 	    }
   487 	CleanupStack::PopAndDestroy();
   539 	CleanupStack::PopAndDestroy();
   488 	delete rhs;
   540 	delete rhs;
   489 	return res; 
   541 	return res; 
   490 	}
   542 	}
   491 
   543