pkiutilities/ocsp/src/request.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Object encapsulating the OCSP request - uses ASN1 encoding
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "ocsp.h"
       
    19 #include "panic.h"
       
    20 #include "oids.h"
       
    21 #include "certid.h"
       
    22 
       
    23 #include <bigint.h>
       
    24 #include <x509cert.h>
       
    25 #include <x509certchain.h>
       
    26 #include <random.h>
       
    27 #include "ocsprequestandresponse.h"
       
    28 
       
    29 // COCSPRequest methods
       
    30 COCSPRequest* COCSPRequest::NewLC(TBool aUseNonce)
       
    31 	{
       
    32 	COCSPRequest* self = new (ELeave) COCSPRequest;
       
    33 	CleanupStack::PushL(self);
       
    34 	self->ConstructL(aUseNonce);
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 COCSPRequest* COCSPRequest::NewL(TBool aUseNonce)
       
    39 	{
       
    40 	COCSPRequest* self = COCSPRequest::NewLC(aUseNonce);
       
    41 	CleanupStack::Pop(self);
       
    42 	return self;
       
    43 	}
       
    44 
       
    45 COCSPRequest::COCSPRequest()
       
    46 	{}
       
    47 
       
    48 void COCSPRequest::ConstructL(TBool aUseNonce)
       
    49 	{
       
    50 	if (aUseNonce)
       
    51 		{
       
    52 		// Make nonce data
       
    53 		iNonce = HBufC8::NewL(KOCSPNonceBytes);
       
    54 		TPtr8 des = iNonce->Des();
       
    55 		des.SetLength(KOCSPNonceBytes);
       
    56 		TRandom::RandomL(des);
       
    57 		}
       
    58 	}
       
    59 
       
    60 
       
    61 COCSPRequest::~COCSPRequest()
       
    62 	{
       
    63 	iCertInfos.ResetAndDestroy();
       
    64 	delete iNonce;
       
    65 	}
       
    66 
       
    67 
       
    68 void COCSPRequest::AddCertificateL(const CX509Certificate& aSubject,
       
    69 								   const CX509Certificate& aIssuer)
       
    70 	{
       
    71 	COCSPRequestCertInfo* certInfo = COCSPRequestCertInfo::NewLC(aSubject, aIssuer);
       
    72 	User::LeaveIfError(iCertInfos.Append(certInfo));
       
    73 	CleanupStack::Pop(certInfo);
       
    74 	}
       
    75 
       
    76 
       
    77 EXPORT_C const TDesC8* COCSPRequest::Nonce() const
       
    78 	{
       
    79 	return iNonce;
       
    80 	}
       
    81 
       
    82 
       
    83 EXPORT_C TInt COCSPRequest::CertCount() const
       
    84 	{
       
    85 	return iCertInfos.Count();
       
    86 	}
       
    87 
       
    88 
       
    89 EXPORT_C const COCSPRequestCertInfo& COCSPRequest::CertInfo(TUint aIndex) const
       
    90 	{
       
    91 	return *iCertInfos[aIndex];
       
    92 	}
       
    93 
       
    94 
       
    95 // COCSPRequestCertInfo methods
       
    96 
       
    97 
       
    98 COCSPRequestCertInfo* COCSPRequestCertInfo::NewLC(const CX509Certificate& aSubject,
       
    99 												  const CX509Certificate& aIssuer)
       
   100 	{
       
   101 	COCSPRequestCertInfo* self = new (ELeave) COCSPRequestCertInfo(aSubject, aIssuer);
       
   102 	CleanupStack::PushL(self);
       
   103 	self->ConstructL();
       
   104 	return self;
       
   105 	}
       
   106 
       
   107 
       
   108 COCSPRequestCertInfo::COCSPRequestCertInfo(const CX509Certificate& aSubject, const CX509Certificate& aIssuer) :
       
   109 	iSubject(aSubject),
       
   110 	iIssuer(aIssuer)
       
   111 	{
       
   112 	}
       
   113 
       
   114 
       
   115 void COCSPRequestCertInfo::ConstructL()
       
   116 	{
       
   117 	iCertID = COCSPCertID::NewL(iSubject, iIssuer);
       
   118 	}
       
   119 
       
   120 
       
   121 COCSPRequestCertInfo::~COCSPRequestCertInfo()
       
   122 	{
       
   123 	delete iCertID;
       
   124 	}
       
   125 
       
   126 
       
   127 EXPORT_C const CX509Certificate& COCSPRequestCertInfo::Subject() const
       
   128 	{
       
   129 	return iSubject;
       
   130 	}
       
   131 
       
   132 
       
   133 EXPORT_C const CX509Certificate& COCSPRequestCertInfo::Issuer() const
       
   134 	{
       
   135 	return iIssuer;
       
   136 	}
       
   137 
       
   138 
       
   139 const COCSPCertID& COCSPRequestCertInfo::CertID() const
       
   140 	{
       
   141 	return *iCertID;
       
   142 	}