secureswitools/swisistools/source/signsislib/certificateinfo.h
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2008-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  @publishedPartner
       
    22  @released
       
    23 */
       
    24 
       
    25 #ifndef __CERTIFICATEINFO_H__
       
    26 #define __CERTIFICATEINFO_H__
       
    27 
       
    28 #include <openssl/x509.h>
       
    29 #include "sisdatetime.h"
       
    30 
       
    31 // Forward declarations
       
    32 struct TConfValue
       
    33 	{
       
    34 	std::string	iName;
       
    35 	std::string	iValue;
       
    36 	};
       
    37 
       
    38 struct TExtension
       
    39 	{
       
    40 	std::string				iExtensionName;
       
    41 	bool					iIsCritical;
       
    42 	bool					iIsMultiLine;
       
    43 	std::string				iValue;
       
    44 	std::vector<TConfValue>	iValueList;
       
    45 	};
       
    46 
       
    47 enum TPublicKeyType
       
    48 	{
       
    49 	EUnknownKey,
       
    50 	EPubKeyDSA,
       
    51 	EPubKeyRSA
       
    52 	};
       
    53 
       
    54 /**
       
    55  * This class extracts certificate details from a X509 certificate.
       
    56  */
       
    57 class CCertificateInfo
       
    58 	{
       
    59 	friend class CCertificateChain;
       
    60 
       
    61 public:
       
    62 	/**
       
    63 	 * Constructor will take X509 class pointer. Then it will
       
    64 	 * extract certificate details from the class.
       
    65 	 */
       
    66 	explicit CCertificateInfo (X509* aCertificate);
       
    67 	/**
       
    68 	 * Free up owned resources
       
    69 	 */
       
    70 	~CCertificateInfo();
       
    71 	
       
    72 public:
       
    73 	/**
       
    74 	 * Get the instance of X509 certificate class.
       
    75 	 */
       
    76 	inline const X509* Certificate() const;
       
    77 	/**
       
    78 	 * Issuer Name - Issuer of the certificate.
       
    79 	 * @param aGetFullName If true it will return detail name else only
       
    80 	 * 			common name (CN) will be returned.
       
    81 	 * @return Issuer name
       
    82 	 */
       
    83 	std::wstring IssuerName(bool aGetFullName = false) const;
       
    84 	/**
       
    85 	 * Subject Name - Name of the entity to whom the certificate was issued.
       
    86 	 * @param aGetFullName If true it will return detail name else only
       
    87 	 * 			common name (CN) will be returned.
       
    88 	 * @return Subject name
       
    89 	 */
       
    90 	std::wstring SubjectName(bool aGetFullName = false) const;
       
    91 	/**
       
    92 	 * Get the time from which the certificate is valid.
       
    93 	 */
       
    94 	const CSISDateTime& ValidFrom() const;
       
    95 	/**
       
    96 	 * Get the time till which the certificate is valid.
       
    97 	 */
       
    98 	const CSISDateTime& ValidTo() const;
       
    99 	/**
       
   100 	 * Certificate version. Version number starts with 0.
       
   101 	 * Therefore certifcate having version 1 will return (0),
       
   102 	 * certificate with version 3 will return 2.
       
   103 	 * @return Certificate version.
       
   104 	 */
       
   105 	int Version() const;
       
   106 	/**
       
   107 	 * Serial number of the certificate
       
   108 	 */
       
   109 	std::string SerialNumber() const;
       
   110 	/**
       
   111 	 * Algorithm used to sign the certificate.
       
   112 	 */
       
   113 	std::string SignatureAlgo() const;
       
   114 	/**
       
   115 	 * Algorithm used for key generation
       
   116 	 */
       
   117 	std::string PublicKeyAlgo() const;
       
   118 	/**
       
   119 	 * Function to retrieve extensions present in the certificate.
       
   120 	 * @return vector of TExtension class. TExtension class provide detail information 
       
   121 	 * 			of extension. 
       
   122 	 */
       
   123 	const std::vector<TExtension>& Extensions() const;
       
   124 	/**
       
   125 	 * Return the public key type.
       
   126 	 */
       
   127 	inline TPublicKeyType PublicKeyType() const;
       
   128 	/**
       
   129 	 * This function will write the public key into the stream provided.
       
   130 	 * @param aStream where the public key information need to be written.
       
   131 	 * @param aIndent Indentation size.
       
   132 	 */
       
   133 	void PrintPublicKey(std::ostream& aStream, int aIndent = 0) const;
       
   134 	/**
       
   135 	 * This function will write the signature into the stream provided.
       
   136 	 * @param aStream where the signature need to be written.
       
   137 	 * @param aIndent Indentation size.
       
   138 	 */
       
   139 	void PrintSignature(std::ostream& aStream, int aIndent = 0) const;
       
   140 	/**
       
   141 	 * Write the certificate into a file.
       
   142 	 * @param aCertFileName Certificate file name
       
   143 	 */ 
       
   144 	void ExtractCertificate(std::string& aCertFileName) const;
       
   145 	/**
       
   146 	 * Check if a particular NID is present in the certificate.
       
   147 	 * @return true if the NID is present else false.
       
   148 	 */
       
   149 	bool IsNIDPresent(int aNID) const;
       
   150 	
       
   151 private: // Private Member Functions
       
   152 	void ConstructL();
       
   153 	int GetNameEntry(X509_NAME* aName, char *aKey, wchar_t** aNameEntry) const;
       
   154 	std::wstring GetDistinguishedName(X509_NAME *x509Name, bool aGetFullName) const;
       
   155 	void SetDateTime(CSISDateTime& dateTime, ASN1_TIME* aASNTime);
       
   156 	void ExtractExtensions();
       
   157 	void ExtractConfValues(STACK_OF(CONF_VALUE) *confList, TExtension& aExtInfo);
       
   158 	std::string Get_ASN1_STRING_Data(ASN1_STRING *aASN1String);
       
   159 	
       
   160 private:
       
   161 	X509*					iCertificate;
       
   162 	CSISDateTime			iValidFrom;
       
   163 	CSISDateTime			iValidTo;
       
   164 	TPublicKeyType			iPublicKeyType;	
       
   165 	std::vector<TExtension>	iExtensions;
       
   166 	};
       
   167 
       
   168 inline const X509* CCertificateInfo::Certificate() const
       
   169 	{
       
   170 	return iCertificate;
       
   171 	}
       
   172 
       
   173 inline TPublicKeyType CCertificateInfo::PublicKeyType() const
       
   174 	{
       
   175 	return iPublicKeyType;
       
   176 	}
       
   177 
       
   178 
       
   179 
       
   180 #endif // __CERTIFICATEINFO_H__
       
   181