1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/pkcs12recog/pkcs12recog.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,156 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @internalTechnology
1.25 +*/
1.26 +
1.27 +#ifndef __PKCS12RECOG_H__
1.28 +
1.29 +#include <apmrec.h>
1.30 +
1.31 +/**
1.32 + A recogniser that recognises the following MIME types:
1.33 + application/x-pkcs12
1.34 + */
1.35 +class CPkcs12Recognizer : public CApaDataRecognizerType
1.36 + {
1.37 + /** PKCS#12 recognizer panic codes */
1.38 + enum TPkcs12RecogPanic
1.39 + {
1.40 + /** Data type index does not correspond to a mime-type */
1.41 + EPanicInvalidDataType
1.42 + };
1.43 +
1.44 +public:
1.45 + /**
1.46 + Constructor
1.47 + */
1.48 + CPkcs12Recognizer();
1.49 +
1.50 +public:
1.51 + /**
1.52 + Returns the preferred buffer size for PKCS#12 recognition
1.53 + @return preferred buffer size in bytes
1.54 + */
1.55 + TUint PreferredBufSize();
1.56 +
1.57 + /**
1.58 + Allows a client to enumerate the supported mime-types.
1.59 + @param aIndex index of the mimetype to return
1.60 + @return mime-type corresponding to aIndex
1.61 + */
1.62 + TDataType SupportedDataTypeL(TInt aIndex) const;
1.63 +
1.64 + static CApaDataRecognizerType* CreateRecognizerL();
1.65 +
1.66 +private:
1.67 + // Implementation CApaDataRecognizerType::DoRecognizeL
1.68 + void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
1.69 +
1.70 + /**
1.71 + Checks whether the file name has a known PKCS#12 extension
1.72 + @param aName the file name to examine
1.73 + @return ETrue if the file extension looks is .pfx or .p12;
1.74 + otherwise, EFalse is returned.
1.75 + */
1.76 + TBool HasPkcs12Extension(const TDesC& aName);
1.77 +
1.78 + /**
1.79 + Checks whether the buffer contains a valid PKCS#12 header.
1.80 + aBuffer buffer to recognise
1.81 +
1.82 + Expected ASN.1 sequence
1.83 + SEQ
1.84 + INTEGER // Version = 3
1.85 + SEQ // authSafe - PKCS#7 ContentInfo
1.86 + OID // ContentType (data or signed data)
1.87 +
1.88 + It is not practical to check further than this because the content
1.89 + field within the ContentInfo objects is optional and could be absent.
1.90 + @param aBuffer the buffer to check
1.91 + @return ETrue if the buffer contains a PKCS#12 header;
1.92 + otherwise, EFalse is returned.
1.93 + */
1.94 + TBool DoRecognizeBufferL(const TDesC8& aBuffer);
1.95 +
1.96 + // There is no need to validate the lengths because the recogniser
1.97 + // checks the buffer size is at least as large as the minimum header
1.98 + // size
1.99 +
1.100 + /**
1.101 + Checks that the data at the specified offset is a DER sequence tag
1.102 + and advances past the tag and it's length.
1.103 +
1.104 + @param aBuffer the buffer containing the DER sequence to validate
1.105 + @param aOffset the offset of the current byte within the buffer. This
1.106 + is undefined if an error occurs.
1.107 + @return ETrue if a valid sequence tag & length is encountered;
1.108 + otherwise, EFalse is returned.
1.109 + */
1.110 + TBool ConsumeSequenceL(const TDesC8& aBuffer, TUint& aOffset) const;
1.111 +
1.112 + /**
1.113 + Decodes a DER encoded integer at the specified offset and advances
1.114 + to the next element.
1.115 + Signed integers greater than 32 bits in length are not supported.
1.116 +
1.117 + @param aBuffer the buffer containing the DER intger to decode
1.118 + @param aOffset the offset of the current byte within the buffer. This
1.119 + is undefined if an error occurs.
1.120 + @param aIntVal the decoded integer value. This is undefined if an error occurs.
1.121 + @return ETrue if a valid integer is encountered;
1.122 + otherwise, EFalse is returned.
1.123 + */
1.124 + TBool ConsumeIntegerL(const TDesC8& aBuffer, TUint& aOffset, TInt& aIntVal) const;
1.125 +
1.126 + /**
1.127 + Decodes a DER encoded length at the specified offset and advances
1.128 + to the start of the value.
1.129 + Lengths greater than 32 bits in length are not supported.
1.130 +
1.131 + @param aBuffer the buffer containing the length to decode.
1.132 + @param aOffset the offset of the current byte within the buffer. This
1.133 + is undefined if an error occurs.
1.134 + @param aLength the decoded length value in octets. This is undefined if an error occurs.
1.135 + @return ETrue if the length is valid; otherwise, EFalse is returned.
1.136 + */
1.137 + TBool ConsumeLengthL(const TDesC8& aBuffer, TUint& aOffset, TInt& aLengthOctets) const;
1.138 +
1.139 + /**
1.140 + Decodes base256 encoded integer up to 4 bytes in length and advances
1.141 + past the data.
1.142 + Signed integers greater than 32 bits in length are not supported.
1.143 +
1.144 + @param aBuffer the buffer containing the octets to decode.
1.145 + @param aOffset the offset of the current byte within the buffer. This
1.146 + is undefined if an error occurs.
1.147 + @param aLength the number of octets to decode (must be <= 4)
1.148 + @param aIntVal the decoded integer. This is undefined if an error occurs.
1.149 + */
1.150 + TBool ConsumeBase256L(const TDesC8& aBuffer, TUint& aOffset, TInt aLengthOctets, TInt& aIntVal) const;
1.151 +
1.152 + /**
1.153 + Calls panic with PKCS#12 recognizer category with the supplied panic code.
1.154 + @param aReason the panic code
1.155 + */
1.156 + void Panic(TPkcs12RecogPanic aReason) const;
1.157 + };
1.158 +
1.159 +#endif