cryptoservices/certificateandkeymgmt/pkcs12recog/pkcs12recog.h
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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 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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @internalTechnology 
       
    24 */
       
    25 
       
    26 #ifndef __PKCS12RECOG_H__
       
    27 
       
    28 #include <apmrec.h>
       
    29 
       
    30 /**
       
    31  A recogniser that recognises the following MIME types:
       
    32  application/x-pkcs12
       
    33  */
       
    34 class CPkcs12Recognizer : public CApaDataRecognizerType
       
    35 	{
       
    36 	/** PKCS#12 recognizer panic codes */
       
    37 	enum TPkcs12RecogPanic 
       
    38 		{
       
    39 		/** Data type index does not correspond to a mime-type */
       
    40 		EPanicInvalidDataType
       
    41 		};
       
    42 		
       
    43 public:
       
    44 	/**
       
    45 	Constructor
       
    46 	*/
       
    47 	CPkcs12Recognizer();
       
    48 
       
    49 public: 
       
    50 	/**
       
    51 	Returns the preferred buffer size for PKCS#12 recognition
       
    52 	@return preferred buffer size in bytes
       
    53 	*/
       
    54 	TUint PreferredBufSize();
       
    55 	
       
    56 	/**
       
    57 	Allows a client to enumerate the supported mime-types.
       
    58 	@param aIndex index of the mimetype to return
       
    59 	@return mime-type corresponding to aIndex
       
    60 	*/
       
    61 	TDataType SupportedDataTypeL(TInt aIndex) const;
       
    62 	
       
    63 	static CApaDataRecognizerType* CreateRecognizerL();
       
    64 
       
    65 private:
       
    66 	// Implementation CApaDataRecognizerType::DoRecognizeL
       
    67 	void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
       
    68 	
       
    69 	/**
       
    70 	Checks whether the file name has a known PKCS#12 extension
       
    71 	@param aName the file name to examine
       
    72 	@return ETrue if the file extension looks is .pfx or .p12;
       
    73 		    otherwise, EFalse is returned.
       
    74 	*/
       
    75 	TBool HasPkcs12Extension(const TDesC& aName);
       
    76 		
       
    77 	/**	
       
    78 	Checks whether the buffer contains a valid PKCS#12 header.
       
    79 	aBuffer buffer to recognise
       
    80 
       
    81 	Expected ASN.1 sequence
       
    82 	SEQ
       
    83 		INTEGER  	// Version = 3
       
    84 		SEQ		 	// authSafe - PKCS#7 ContentInfo
       
    85 			OID		// ContentType (data or signed data)
       
    86 
       
    87 	It is not practical to check further than this because the content
       
    88 	field within the ContentInfo objects is optional and could be absent.
       
    89 	@param aBuffer the buffer to check
       
    90 	@return ETrue if the buffer contains a PKCS#12 header; 
       
    91 			otherwise, EFalse is returned.	
       
    92 	*/
       
    93 	TBool DoRecognizeBufferL(const TDesC8& aBuffer);
       
    94 	
       
    95 	// There is no need to validate the lengths because the recogniser
       
    96 	// checks the buffer size is at least as large as the minimum header
       
    97 	// size	
       
    98 	
       
    99 	/**
       
   100 	Checks that the data at the specified offset is a DER sequence tag
       
   101 	and advances past the tag and it's length.
       
   102 	
       
   103 	@param aBuffer the buffer containing the DER sequence to validate
       
   104 	@param aOffset the offset of the current byte within the buffer. This
       
   105 	               is undefined if an error occurs.
       
   106 	@return ETrue if a valid sequence tag & length is encountered;
       
   107 			otherwise, EFalse is returned.
       
   108 	*/
       
   109 	TBool ConsumeSequenceL(const TDesC8& aBuffer, TUint& aOffset) const;
       
   110 
       
   111 	/**
       
   112 	Decodes a DER encoded integer at the specified offset and advances
       
   113 	to the next element.
       
   114 	Signed integers greater than 32 bits in length are not supported.	
       
   115 	
       
   116 	@param aBuffer the buffer containing the DER intger to decode
       
   117 	@param aOffset the offset of the current byte within the buffer. This
       
   118 	               is undefined if an error occurs.
       
   119 	@param aIntVal the decoded integer value. This is undefined if an error occurs.
       
   120 	@return ETrue if a valid integer is encountered; 
       
   121 			otherwise, EFalse is returned.
       
   122 	*/	
       
   123 	TBool ConsumeIntegerL(const TDesC8& aBuffer, TUint& aOffset, TInt& aIntVal) const;
       
   124 	
       
   125 	/**
       
   126 	Decodes a DER encoded length at the specified offset and advances
       
   127 	to the start of the value.
       
   128 	Lengths greater than 32 bits in length are not supported.
       
   129 	
       
   130 	@param aBuffer the buffer containing the length to decode.
       
   131 	@param aOffset the offset of the current byte within the buffer. This
       
   132 	               is undefined if an error occurs.
       
   133 	@param aLength the decoded length value in octets. This is undefined if an error occurs.
       
   134 	@return ETrue if the length is valid; otherwise, EFalse is returned.
       
   135 	*/			
       
   136 	TBool ConsumeLengthL(const TDesC8& aBuffer, TUint& aOffset, TInt& aLengthOctets) const;
       
   137 	
       
   138 	/**
       
   139 	Decodes base256 encoded integer up to 4 bytes in length and advances
       
   140 	past the data.
       
   141 	Signed integers greater than 32 bits in length are not supported.
       
   142 	
       
   143 	@param aBuffer the buffer containing the octets to decode.
       
   144 	@param aOffset the offset of the current byte within the buffer. This
       
   145 	               is undefined if an error occurs.
       
   146 	@param aLength the number of octets to decode (must be <= 4)
       
   147 	@param aIntVal the decoded integer. This is undefined if an error occurs.
       
   148 	*/		
       
   149 	TBool ConsumeBase256L(const TDesC8& aBuffer, TUint& aOffset, TInt aLengthOctets, TInt& aIntVal) const;
       
   150 	
       
   151 	/**
       
   152 	Calls panic with PKCS#12 recognizer category with the supplied panic code.
       
   153 	@param aReason the panic code
       
   154 	*/
       
   155 	void Panic(TPkcs12RecogPanic aReason) const;
       
   156 	};
       
   157 
       
   158 #endif