cryptoservices/certificateandkeymgmt/inc/x509keyencoder.h
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 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 * X.509 key classes and utility classes for key encoding/decoding.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalTechnology 
       
    23 */
       
    24 
       
    25 #if !defined (X509KEYENCODER_H)
       
    26 #define X509KEYENCODER_H
       
    27 
       
    28 #include <e32base.h>
       
    29 #include <e32std.h>
       
    30 #include <asymmetrickeys.h>
       
    31 #include <asymmetric.h>
       
    32 #include <hash.h>
       
    33 #include <bigint.h>
       
    34 #include <signed.h>
       
    35 
       
    36 // Forward declarations
       
    37 class CASN1EncBase;
       
    38 class CASN1EncContainer;
       
    39 class CASN1EncSequence;
       
    40 class CASN1EncBitString;
       
    41 
       
    42 class TX509KeyEncoder
       
    43 /**
       
    44  * Abstract class that is the base class for RSA and DSA key encoder classes.
       
    45  * These classes are used to encode the X509 ASN.1 types AlgorithmIdentifier and
       
    46  * SubjectPublicKeyInfo.
       
    47  *
       
    48  * This class is part of the pkcs10 API, and will be changed or removed in a
       
    49  * future release.  You should not use it.
       
    50  * 
       
    51  */
       
    52 	{
       
    53 public:
       
    54 	/**
       
    55 	 * Constructor that takes an algorithm identifier and saves it into the 
       
    56 	 * corresponding member variable. It is then used in the
       
    57 	 * EncodeSignatureAlgorithm() function.
       
    58 	 * 
       
    59 	 * @param aDigestAlg	Digest algorithm to use. Currently the following 
       
    60 	 * 						algorithms are supported: MD2, MD5, and SHA-1.
       
    61 	 */
       
    62 	TX509KeyEncoder(TAlgorithmId aDigestAlg);
       
    63 
       
    64 	/**
       
    65 	 * Produces the SubjectPublicKeyInfo encoding. 
       
    66 	 * 
       
    67 	 * The encoding has the following ASN.1 format:
       
    68 	 * @code
       
    69 	 * SubjectPublicKeyInfo {ALGORITHM : IOSet} ::= SEQUENCE {
       
    70 	 *     algorithm        AlgorithmIdentifier {{IOSet}},
       
    71 	 *     subjectPublicKey BIT STRING
       
    72 	 *     }
       
    73 	 * @endcode
       
    74 	 */
       
    75 	IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const = 0;
       
    76 
       
    77 	/**
       
    78 	 * Produces the AlgorithmIdentifier encoding.
       
    79 	 * 
       
    80 	 * @return	ASN.1 sequence containing signature algorithm
       
    81 	 */
       
    82 	IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const = 0;
       
    83 
       
    84 	/**
       
    85 	 * Produces the DigestAlgorithmIdentifier encoder.
       
    86 	 *
       
    87 	 * The encoding has the following ASN.1 format
       
    88 	 * @code
       
    89      *   DigestAlgorithmIdentifier ::= SEQUENCE {
       
    90      *     algorithm AlgorithmIdentifier,
       
    91      *     parameters ANY DEFINED BY algorithm OPTIONAL }
       
    92      *
       
    93      *   AlgorithmIdentifier ::= OBJECT IDENTIFIER
       
    94 	 * @endcode
       
    95  	 *
       
    96 	 * @return Appropriate ASN.1 sequence of type <code>DigestAlgorithmIdentifier</code>
       
    97 	 */
       
    98 	IMPORT_C virtual CASN1EncSequence* EncodeDigestAlgorithmLC() const;
       
    99 
       
   100 protected:
       
   101 	/** Digest algorithm to use. */
       
   102 	TAlgorithmId iDigestAlg;
       
   103 	};
       
   104 
       
   105 class TX509RSAKeyEncoder : public TX509KeyEncoder
       
   106 /**
       
   107  * Subclasses TC509KeyEncoder to provides key encoding capability for RSA public keys.
       
   108  * 
       
   109  * This class is part of the pkcs10 API, and will be changed or removed in a
       
   110  * future release.  You should not use it.
       
   111  * 
       
   112  */
       
   113 	{
       
   114 public:
       
   115 	/**
       
   116 	 * Constructs a RSA key pair encoder, saving reference to the passed 
       
   117 	 * key pair in the member variable.
       
   118 	 * 
       
   119 	 * @param aPublicKey	RSA public key to use for encoding.
       
   120 	 * @param aDigestAlg	Digest algorithm to use.
       
   121 	 */
       
   122 	IMPORT_C TX509RSAKeyEncoder(const CRSAPublicKey& aPublicKey, TAlgorithmId aDigestAlg);
       
   123 
       
   124 	/**
       
   125 	 * Produces the SubjectPublicKeyInfo encoding. 
       
   126 	 * 
       
   127 	 * The resulting encoding has the following form:
       
   128 	 * @code
       
   129 	 *     SEQUENCE-OF
       
   130 	 *         SEQUENCE-OF
       
   131 	 *             OID of the encryption algorithm (KRSA)
       
   132 	 *             NULL
       
   133 	 *         BIT STRING encoded public key.
       
   134 	 * @endcode
       
   135 	 * 
       
   136 	 * @return	DER-encoded public key information, placed on the cleanup stack.
       
   137 	 */
       
   138 	IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const;
       
   139 
       
   140 	/**
       
   141 	 * Produces the AlgorithmIdentifier encoding.
       
   142   	 * 
       
   143 	 * This has the following form:
       
   144 	 * @code
       
   145 	 *     SEQUENCE-OF
       
   146 	 *         OID signature-algorithm
       
   147 	 *         NULL
       
   148 	 * @endcode
       
   149 	 * 
       
   150 	 * @return	ASN.1 sequence containing signature algorithm encoding, 
       
   151 	 * 			placed on the cleanup stack.
       
   152 	 */
       
   153 	IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const;
       
   154 
       
   155 private:
       
   156 	/**
       
   157 	 * Saved reference to the RSA public key to be used for encoding.
       
   158 	 */
       
   159 	const CRSAPublicKey& iPublicKey;
       
   160 	};
       
   161 
       
   162 class TX509DSAKeyEncoder : public TX509KeyEncoder
       
   163 /**
       
   164  * Provides key encoding and signing capability using a DSA public key.
       
   165  * 
       
   166  * This class is part of the pkcs10 API, and will be changed or removed in a
       
   167  * future release.  You should not use it.
       
   168  * 
       
   169  */
       
   170 	{
       
   171 public:
       
   172 	/**
       
   173 	 * Constructs a DSA key pair encoder, saving reference to the passed 
       
   174 	 * public key in the member variable.
       
   175 	 * 
       
   176 	 * @param aKeyPublic	DSA public key to use for encoding.
       
   177 	 * @param aDigestAlg	Digest algorithm to use.
       
   178 	 */
       
   179 	IMPORT_C TX509DSAKeyEncoder(const CDSAPublicKey& aKeyPublic, 
       
   180 								TAlgorithmId aDigestAlg);
       
   181 
       
   182 	/**
       
   183 	 * Produces the SubjectPublicKeyInfo encoding. 
       
   184   	 * 
       
   185 	 * The ASN.1 encoding of a DSA key has the following form:
       
   186 	 * @code
       
   187 	 * SEQUENCE-OF
       
   188 	 *     SEQUENCE-OF
       
   189 	 *         OID dsa (1.2.840.10040.4.1)
       
   190 	 *         SEQUENCE-OF
       
   191 	 *             INTEGER p
       
   192 	 *             INTEGER q
       
   193 	 *             INTEGER g
       
   194 	 *     BIT STRING
       
   195 	 *         INTEGER public value (y)
       
   196 	 * @endcode
       
   197 	 * 
       
   198 	 * @return DER-encoded public key information, placed on the cleanup stack.
       
   199 	 */
       
   200 	IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const;
       
   201 
       
   202 	/**
       
   203 	 * Produces the AlgorithmIdentifier encoding.
       
   204    	 * 
       
   205 	 * This has the following form:
       
   206 	 * @code
       
   207 	 * SEQUENCE-OF
       
   208 	 *     OID dsa-signature-oid
       
   209 	 *     SEQUENCE-OF dsa-params
       
   210 	 *         INTEGER p
       
   211 	 *         INTEGER q
       
   212 	 *         INTEGER g
       
   213 	 * @endcode
       
   214 	 * 
       
   215 	 * @return	ASN.1 sequence containing signature algorithm encoding, 
       
   216 	 *     		placed on the cleanup stack.
       
   217 	 */
       
   218 	IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const;
       
   219 
       
   220 private:
       
   221 	/**
       
   222 	 * Saved reference to the DSA public key to be used for encoding.
       
   223 	 */
       
   224 	const CDSAPublicKey& iPublicKey;
       
   225 	};
       
   226 
       
   227 #endif