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