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