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