First public contribution.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Implementation for testing object identifier decoding with invalid data
20 #include "testinvalidoid.h"
21 #include "tasn1normaltest.h"
28 const TInt KNumberOftests = 2;
30 CTestInvalidOID* CTestInvalidOID::NewL(CASN1NormalTest &aASN1Action)
32 CTestInvalidOID* test = new (ELeave) CTestInvalidOID(aASN1Action);
36 CTestInvalidOID::CTestInvalidOID(CASN1NormalTest &aASN1Action) : CTestBase(aASN1Action)
41 void CTestInvalidOID::GetName(TDes& aBuf)
43 aBuf.Copy(_L("Test Invalid Object Identifier"));
47 void CTestInvalidOID::FillParameterArray(void)
49 iParameters->Append(CTestParameter::EString);
52 TBool CTestInvalidOID::PerformTestsL(CConsoleBase& aConsole)
54 TASN1DecObjectIdentifier decoder;
56 HBufC* decodedData= NULL;
60 // test some hardcoded examples of badly formed ASN1
62 /* check decoding of overflow example "1.2.826.0.1.1796587.1.1.1.72057594037927942"
63 from DEF099095: OID parsing error can cause X509.v3 extensions to be eclipsed */
64 _LIT8(KASN1overflow, "\x06\x14\x2A\x86\x3A\x00\x01\xED\xD3\x6B\x01\x01\x01\x81\x80\x80\x80\x80\x80\x80\x80\x06");
65 TRAP( err, decodedData = decoder.DecodeDERL(KASN1overflow, readLength));
66 if ((err == KErrOverflow ) && ( decodedData == NULL ))
68 iASN1Action.ReportProgressL(KErrNone, testNumber, KNumberOftests);
72 aConsole.Write(_L("ERROR!\nShould NOT be able to decode \n"));
73 iASN1Action.ReportProgressL(KErrASN1EncodingError, testNumber, KNumberOftests);
78 // check 30 bit value is ok 0x20000006 = 536870918
79 _LIT8(KASN130bit, "\x06\x10\x2A\x86\x3A\x00\x01\xED\xD3\x6B\x01\x01\x01\x82\x80\x80\x80\x06");
80 _LIT16(KASN130bitResult, "1.2.826.0.1.1796587.1.1.1.536870918");
82 TRAP( err, decodedData = decoder.DecodeDERL(KASN130bit, readLength));
83 TPtr pData = decodedData->Des();
84 if ((err == KErrNone ) && ( pData.Compare( KASN130bitResult ) ==0 ) )
86 iASN1Action.ReportProgressL(KErrNone, testNumber, KNumberOftests);
91 aConsole.Write(_L("ERROR!\nShould NOT be able to decode \n"));
92 iASN1Action.ReportProgressL(KErrASN1EncodingError, testNumber, KNumberOftests);
97 // check 31 bit value is ok 0x40000006 = 1073741830
98 _LIT8(KASN131bit, "\x06\x10\x2A\x86\x3A\x00\x01\xED\xD3\x6B\x01\x01\x01\x84\x80\x80\x80\x06");
99 _LIT16(KASN131bitResult, "1.2.826.0.1.1796587.1.1.1.1073741830");
102 TRAP( err, decodedData = decoder.DecodeDERL(KASN131bit, readLength));
103 pData = decodedData->Des();
104 if ((err == KErrNone ) && ( pData.Compare( KASN131bitResult ) ==0 ))
106 iASN1Action.ReportProgressL(KErrNone, testNumber, KNumberOftests);
112 aConsole.Write(_L("ERROR!\nShould NOT be able to decode \n"));
113 iASN1Action.ReportProgressL(KErrASN1EncodingError, testNumber, KNumberOftests);
118 // check 32 bit value does NOT decode 0x80000006 = 2147483654
119 _LIT8(KASN132bit, "\x06\x10\x2A\x86\x3A\x00\x01\xED\xD3\x6B\x01\x01\x01\x88\x80\x80\x80\x06");
122 TRAP( err, decodedData = decoder.DecodeDERL(KASN132bit, readLength));
123 if ((err == KErrOverflow ) && ( decodedData == NULL ))
125 iASN1Action.ReportProgressL(KErrNone, testNumber, KNumberOftests);
129 aConsole.Write(_L("ERROR!\nShould NOT be able to decode \n"));
130 iASN1Action.ReportProgressL(KErrASN1EncodingError, testNumber, KNumberOftests);
135 // check that too many ids causes KErrOverflow, "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1"
136 _LIT8(KASN1ToManyIds, "\x06\x13\x2A\x86\x3A\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01");
139 TRAP( err, decodedData = decoder.DecodeDERL(KASN1ToManyIds, readLength));
140 if ((err == KErrOverflow ) && ( decodedData == NULL ))
142 iASN1Action.ReportProgressL(KErrNone, testNumber, KNumberOftests);
146 aConsole.Write(_L("ERROR!\nShould NOT be able to decode \n"));
147 iASN1Action.ReportProgressL(KErrASN1EncodingError, testNumber, KNumberOftests);
150 /* some more examples of Bad ASN encoding can be added here */