omadrm/drmengine/roapstorage/src/responsecertinfo.cpp
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "certid.h"
       
    20 #include "RoapOcsp.h"
       
    21 #include "RoapDef.h"
       
    22 
       
    23 #include <asn1dec.h>
       
    24 
       
    25 const TUint KGoodTag = 0;
       
    26 const TUint KRevokedTag = 1;
       
    27 const TUint KUnknownTag = 2;
       
    28 
       
    29 const TUint KNextUpdateTag = 0;
       
    30 const TUint KSingleExtensionsTag = 1;
       
    31 
       
    32 COCSPResponseCertInfo* COCSPResponseCertInfo::NewLC(CArrayPtr<TASN1DecGeneric>& items)
       
    33 	{
       
    34 	COCSPResponseCertInfo* self = new (ELeave) COCSPResponseCertInfo;
       
    35 	CleanupStack::PushL(self);
       
    36 	self->ConstructL(items);
       
    37 	return self;
       
    38 	}
       
    39 
       
    40 
       
    41 COCSPResponseCertInfo::~COCSPResponseCertInfo()
       
    42 	{
       
    43 	delete iNextUpdate;
       
    44 	delete iRevocationTime;
       
    45 	delete iCertID;
       
    46 	}
       
    47 
       
    48 
       
    49 OCSP::TResult COCSPResponseCertInfo::Status() const
       
    50 	{
       
    51 	return iStatus;
       
    52 	}
       
    53 
       
    54 
       
    55 TTime COCSPResponseCertInfo::ThisUpdate() const
       
    56 	{
       
    57 	return iThisUpdate;
       
    58 	}
       
    59 
       
    60 
       
    61 const TTime* COCSPResponseCertInfo::NextUpdate() const
       
    62 	{
       
    63 	return iNextUpdate;
       
    64 	}
       
    65 
       
    66 
       
    67 const TTime* COCSPResponseCertInfo::RevocationTime() const
       
    68 	{
       
    69 	return iRevocationTime;
       
    70 	}
       
    71 
       
    72 
       
    73 COCSPCertID* COCSPResponseCertInfo::CertID() const
       
    74 	{
       
    75 	return iCertID;
       
    76 	}
       
    77 
       
    78 
       
    79 void COCSPResponseCertInfo::ConstructL(CArrayPtr<TASN1DecGeneric>& items)
       
    80 	{
       
    81 	// The CertID
       
    82 	iCertID = COCSPCertID::NewL(items.At(0)->Encoding());
       
    83 	
       
    84 	// The cert status - implicitly tagged
       
    85 	TASN1DecGeneric& statusDec = *items.At(1);
       
    86 	switch(statusDec.Tag())
       
    87 		{
       
    88 		case KGoodTag:
       
    89 			iStatus = OCSP::EGood;
       
    90 			break;
       
    91 		case KRevokedTag:
       
    92 			{
       
    93 			iStatus = OCSP::ERevoked;
       
    94 
       
    95 			// Get revocation time
       
    96 			TASN1DecSequence seqDec;
       
    97 			CArrayPtr<TASN1DecGeneric>* revokedInfo = seqDec.DecodeDERLC(statusDec, 1, 2);
       
    98 			if (revokedInfo)
       
    99 				{
       
   100 				TASN1DecGeneric& revocationTimeDec = *revokedInfo->At(0);
       
   101 				if (revocationTimeDec.Tag() != EASN1GeneralizedTime)
       
   102 					{
       
   103 					User::Leave(OCSP::EMalformedResponse);
       
   104 					}
       
   105 
       
   106 				TASN1DecGeneralizedTime decGT;
       
   107 				iRevocationTime = new (ELeave) TTime(decGT.DecodeDERL(revocationTimeDec));
       
   108 
       
   109 				CleanupStack::PopAndDestroy();  // revokedInfo
       
   110 				}
       
   111 			break;
       
   112 			}
       
   113 		case KUnknownTag:
       
   114 			iStatus = OCSP::EUnknown;
       
   115 			break;
       
   116 		default:
       
   117 			User::Leave(OCSP::EMalformedResponse);
       
   118 		}
       
   119 		
       
   120 	// Carry on with thisUpdate
       
   121 	TASN1DecGeneralizedTime decGT;
       
   122 	iThisUpdate = decGT.DecodeDERL(*items.At(2));
       
   123 
       
   124 	// Optional bits...
       
   125 	TInt numItems = items.Count();
       
   126 	if (numItems > 3)
       
   127 		{
       
   128 		TInt nextItem = 3;
       
   129 
       
   130 		// Maybe nextUpdate is there too
       
   131 		TASN1DecGeneric& item4 = *items.At(3);
       
   132 		if (item4.Tag() == KNextUpdateTag)
       
   133 			{
       
   134 			++nextItem;
       
   135 			TASN1DecGeneralizedTime decGT;
       
   136 			TInt pos = 0;
       
   137 			iNextUpdate = new (ELeave) TTime (decGT.DecodeDERL(item4.GetContentDER(), pos));
       
   138 			}
       
   139 
       
   140 		// Check for extensions - we don't support any, but we need to leave if there are any marked 'critical'
       
   141 		if (nextItem < numItems)
       
   142 			{
       
   143 			TASN1DecGeneric& extnList = *items.At(nextItem);
       
   144 			if (extnList.Tag() == KSingleExtensionsTag)
       
   145 				{
       
   146 				// OK, we've got extensions, with an explicit tag.  Loop through them...
       
   147 				TASN1DecSequence decSeq;
       
   148 				TInt pos = 0;
       
   149 				CArrayPtr<TASN1DecGeneric>* extns = decSeq.DecodeDERLC(extnList.GetContentDER(), pos);
       
   150 				TInt numExts = extns->Count();
       
   151 				for (TInt extIndex = 0; extIndex < numExts; ++extIndex)
       
   152 					{
       
   153 					TASN1DecGeneric& ext = *extns->At(extIndex);
       
   154 					CArrayPtr<TASN1DecGeneric>* terms = decSeq.DecodeDERLC(ext);
       
   155 
       
   156 					// Check critical flag (may be absent - default value false
       
   157 					if (terms->Count() == 3)
       
   158 						{
       
   159 						TASN1DecBoolean boolDec;
       
   160 						if (boolDec.DecodeDERL(*terms->At(1)))
       
   161 							{
       
   162 							User::Leave(OCSP::EUnknownCriticalExtension);
       
   163 							}
       
   164 						}
       
   165 					CleanupStack::PopAndDestroy(); // Clean up 'terms'
       
   166 					}
       
   167 				CleanupStack::PopAndDestroy(); // Clean up 'extns'
       
   168 				}
       
   169 			}
       
   170 		}
       
   171 	}