sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #ifndef __PKCS12RECOG_H__ sl@0: sl@0: #include sl@0: sl@0: /** sl@0: A recogniser that recognises the following MIME types: sl@0: application/x-pkcs12 sl@0: */ sl@0: class CPkcs12Recognizer : public CApaDataRecognizerType sl@0: { sl@0: /** PKCS#12 recognizer panic codes */ sl@0: enum TPkcs12RecogPanic sl@0: { sl@0: /** Data type index does not correspond to a mime-type */ sl@0: EPanicInvalidDataType sl@0: }; sl@0: sl@0: public: sl@0: /** sl@0: Constructor sl@0: */ sl@0: CPkcs12Recognizer(); sl@0: sl@0: public: sl@0: /** sl@0: Returns the preferred buffer size for PKCS#12 recognition sl@0: @return preferred buffer size in bytes sl@0: */ sl@0: TUint PreferredBufSize(); sl@0: sl@0: /** sl@0: Allows a client to enumerate the supported mime-types. sl@0: @param aIndex index of the mimetype to return sl@0: @return mime-type corresponding to aIndex sl@0: */ sl@0: TDataType SupportedDataTypeL(TInt aIndex) const; sl@0: sl@0: static CApaDataRecognizerType* CreateRecognizerL(); sl@0: sl@0: private: sl@0: // Implementation CApaDataRecognizerType::DoRecognizeL sl@0: void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer); sl@0: sl@0: /** sl@0: Checks whether the file name has a known PKCS#12 extension sl@0: @param aName the file name to examine sl@0: @return ETrue if the file extension looks is .pfx or .p12; sl@0: otherwise, EFalse is returned. sl@0: */ sl@0: TBool HasPkcs12Extension(const TDesC& aName); sl@0: sl@0: /** sl@0: Checks whether the buffer contains a valid PKCS#12 header. sl@0: aBuffer buffer to recognise sl@0: sl@0: Expected ASN.1 sequence sl@0: SEQ sl@0: INTEGER // Version = 3 sl@0: SEQ // authSafe - PKCS#7 ContentInfo sl@0: OID // ContentType (data or signed data) sl@0: sl@0: It is not practical to check further than this because the content sl@0: field within the ContentInfo objects is optional and could be absent. sl@0: @param aBuffer the buffer to check sl@0: @return ETrue if the buffer contains a PKCS#12 header; sl@0: otherwise, EFalse is returned. sl@0: */ sl@0: TBool DoRecognizeBufferL(const TDesC8& aBuffer); sl@0: sl@0: // There is no need to validate the lengths because the recogniser sl@0: // checks the buffer size is at least as large as the minimum header sl@0: // size sl@0: sl@0: /** sl@0: Checks that the data at the specified offset is a DER sequence tag sl@0: and advances past the tag and it's length. sl@0: sl@0: @param aBuffer the buffer containing the DER sequence to validate sl@0: @param aOffset the offset of the current byte within the buffer. This sl@0: is undefined if an error occurs. sl@0: @return ETrue if a valid sequence tag & length is encountered; sl@0: otherwise, EFalse is returned. sl@0: */ sl@0: TBool ConsumeSequenceL(const TDesC8& aBuffer, TUint& aOffset) const; sl@0: sl@0: /** sl@0: Decodes a DER encoded integer at the specified offset and advances sl@0: to the next element. sl@0: Signed integers greater than 32 bits in length are not supported. sl@0: sl@0: @param aBuffer the buffer containing the DER intger to decode sl@0: @param aOffset the offset of the current byte within the buffer. This sl@0: is undefined if an error occurs. sl@0: @param aIntVal the decoded integer value. This is undefined if an error occurs. sl@0: @return ETrue if a valid integer is encountered; sl@0: otherwise, EFalse is returned. sl@0: */ sl@0: TBool ConsumeIntegerL(const TDesC8& aBuffer, TUint& aOffset, TInt& aIntVal) const; sl@0: sl@0: /** sl@0: Decodes a DER encoded length at the specified offset and advances sl@0: to the start of the value. sl@0: Lengths greater than 32 bits in length are not supported. sl@0: sl@0: @param aBuffer the buffer containing the length to decode. sl@0: @param aOffset the offset of the current byte within the buffer. This sl@0: is undefined if an error occurs. sl@0: @param aLength the decoded length value in octets. This is undefined if an error occurs. sl@0: @return ETrue if the length is valid; otherwise, EFalse is returned. sl@0: */ sl@0: TBool ConsumeLengthL(const TDesC8& aBuffer, TUint& aOffset, TInt& aLengthOctets) const; sl@0: sl@0: /** sl@0: Decodes base256 encoded integer up to 4 bytes in length and advances sl@0: past the data. sl@0: Signed integers greater than 32 bits in length are not supported. sl@0: sl@0: @param aBuffer the buffer containing the octets to decode. sl@0: @param aOffset the offset of the current byte within the buffer. This sl@0: is undefined if an error occurs. sl@0: @param aLength the number of octets to decode (must be <= 4) sl@0: @param aIntVal the decoded integer. This is undefined if an error occurs. sl@0: */ sl@0: TBool ConsumeBase256L(const TDesC8& aBuffer, TUint& aOffset, TInt aLengthOctets, TInt& aIntVal) const; sl@0: sl@0: /** sl@0: Calls panic with PKCS#12 recognizer category with the supplied panic code. sl@0: @param aReason the panic code sl@0: */ sl@0: void Panic(TPkcs12RecogPanic aReason) const; sl@0: }; sl@0: sl@0: #endif