1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/x509keys.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,809 @@
1.4 +/*
1.5 +* Copyright (c) 1998-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 +* X.509 key classes and utility classes for key encoding/decoding.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +
1.24 +
1.25 +/**
1.26 + @file
1.27 + @internalTechnology
1.28 +*/
1.29 +
1.30 +#if !defined (__X509KEYS_H__)
1.31 +#define __X509KEYS_H__
1.32 +
1.33 +#include <e32base.h>
1.34 +#include <e32std.h>
1.35 +#include <asymmetrickeys.h>
1.36 +#include <asymmetric.h>
1.37 +#include <hash.h>
1.38 +#include <bigint.h>
1.39 +#include <signed.h>
1.40 +
1.41 +// Forward declarations
1.42 +class CASN1EncBase;
1.43 +class CASN1EncContainer;
1.44 +class CASN1EncSequence;
1.45 +class CASN1EncBitString;
1.46 +
1.47 +class CX509RSAPublicKey : public CRSAPublicKey
1.48 +/** Adds the capability to decode DER-encoded RSA public keys.
1.49 +*
1.50 +* Adds a commitment to a specific encoding scheme allowing X.509 RSA public key
1.51 +* superclasses to remain encoding-independent.
1.52 +*
1.53 +* @publishedAll
1.54 +* @released
1.55 +*
1.56 +* @since v6.0
1.57 +*/
1.58 + {
1.59 +public:
1.60 + /** Creates a new RSA Public key object from the specified buffer containing the
1.61 + * encoded binary representation.
1.62 + *
1.63 + * Initialises the object from its encoded binary form into an internal representation.
1.64 + *
1.65 + * @param aBinaryData The encoded binary representation.
1.66 + * @return A pointer to the new CX509RSAPublicKey object. */
1.67 + IMPORT_C static CX509RSAPublicKey* NewL(const TDesC8& aBinaryData);
1.68 +
1.69 + /** Creates a new RSA Public Key object from the specified buffer containing the
1.70 + * encoded binary representation, and puts a pointer to it onto the cleanup stack.
1.71 + *
1.72 + * @param aBinaryData The encoded binary representation.
1.73 + * @return A pointer to the new CX509RSAPublicKey object. */
1.74 + IMPORT_C static CX509RSAPublicKey* NewLC(const TDesC8& aBinaryData);
1.75 +
1.76 + /** Creates a new RSA Public key object from the specified buffer containing the
1.77 + * encoded binary representation, starting at the specified offset.
1.78 + *
1.79 + * @param aBinaryData The encoded binary representation.
1.80 + * @param aPos The offset position from which to start decoding.
1.81 + * @return A pointer to the new CX509RSAPublicKey object. */
1.82 + IMPORT_C static CX509RSAPublicKey* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.83 +
1.84 + /** Creates a new RSA Public key object from the specified buffer containing the
1.85 + * encoded binary representation, starting at the specified offset, and puts
1.86 + * a pointer to it onto the cleanup stack.
1.87 + *
1.88 + * @param aBinaryData The encoded binary representation.
1.89 + * @param aPos The offset position from which to start decoding.
1.90 + * @return A pointer to the new CX509RSAPublicKey object. */
1.91 + IMPORT_C static CX509RSAPublicKey* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.92 +private:
1.93 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.94 + CX509RSAPublicKey();
1.95 + };
1.96 +
1.97 +class TASN1EncRSAPublicKey
1.98 +/**
1.99 + * Class for encoding RSA public keys to ASN.1 encoding.
1.100 + *
1.101 + * @publishedAll
1.102 + * @released
1.103 + * @since v8.0
1.104 + */
1.105 + {
1.106 +public:
1.107 + /**
1.108 + * Encodes the supplied public key into buffer in DER format ASN.1:
1.109 + * @code
1.110 + * SEQUENCE-OF
1.111 + * INTEGER modulus
1.112 + * INTEGER exponent
1.113 + * @endcode
1.114 + *
1.115 + * @param aKey Key to encode.
1.116 + * @return Allocated buffer containing DER encoding of
1.117 + * the supplied key aKey.
1.118 + */
1.119 + IMPORT_C HBufC8* EncodeDERL(const CRSAPublicKey& aKey) const;
1.120 + };
1.121 +
1.122 +class TASN1DecRSAPublicKey
1.123 +/**
1.124 + * Class for decoding RSA public keys from ASN.1 DER encoding.
1.125 + *
1.126 + * @publishedAll
1.127 + * @released
1.128 + * @since v8.0
1.129 + */
1.130 + {
1.131 +public:
1.132 + /**
1.133 + * Decodes an RSA key from the supplied buffer starting at the
1.134 + * specified position.
1.135 + *
1.136 + * @param aDER Buffer containing DER ASN.1 encoding of the key.
1.137 + * @param aPos Starting position in the buffer (updated on exit).
1.138 + * @return A pointer to the new CRSAPublicKey object.
1.139 + */
1.140 + IMPORT_C CRSAPublicKey* DecodeDERL(const TDesC8& aDER, TInt& aPos) const;
1.141 + };
1.142 +
1.143 +class TASN1DecRSAKeyPair
1.144 +/**
1.145 + * Class for decoding RSA key pairs from ASN.1 DER encoding.
1.146 + *
1.147 + * @publishedAll
1.148 + * @released
1.149 + * @since v8.0
1.150 + */
1.151 + {
1.152 +public:
1.153 + /**
1.154 + * Decodes an RSA key pair from buffer containing ASN.1
1.155 + * DER-encoded private key. The encoding of a private key
1.156 + * contains public key components as well.
1.157 + *
1.158 + * @param aDER DER-encoded private key.
1.159 + * @param aPos Position in the buffer to start decoding
1.160 + * (updated on exit).
1.161 + * @param aPublicKey On return, the RSA public key object
1.162 + * @param aPrivateKey On return, the RSA private key object
1.163 + * @param aKeyType Key type, default is @c EStandardCRT
1.164 + */
1.165 + IMPORT_C void DecodeDERL(const TDesC8& aDER, TInt& aPos,
1.166 + CRSAPublicKey*& aPublicKey,
1.167 + CRSAPrivateKey*& aPrivateKey,
1.168 + TRSAPrivateKeyType aKeyType = EStandardCRT);
1.169 + };
1.170 +
1.171 +class CX509DSAPublicKey : public CDSAPublicKey
1.172 +/** Encapsulates the X.509 DSA public key.
1.173 +*
1.174 +* Adds a commitment to a specific encoding scheme allowing superclasses to remain
1.175 +* encoding-independent.
1.176 +*
1.177 +* @publishedAll
1.178 +* @released
1.179 +* @since v6.0
1.180 +*/
1.181 +// DSA public key, params, signature.
1.182 + {
1.183 +public:
1.184 + /** Creates a new X.509 DSA public key object.
1.185 + *
1.186 + * @param aParamsData A non-modifiable descriptor representing the entire encoding.
1.187 + * @param aBinaryData The encoded binary representation.
1.188 + * @return A pointer to the new CX509DSAPublicKey object. */
1.189 + IMPORT_C static CX509DSAPublicKey* NewL(const TDesC8& aParamsData, const TDesC8& aBinaryData);
1.190 +
1.191 + /** Creates a new X.509 DSA public key object, and puts a pointer to it onto the cleanup stack.
1.192 + *
1.193 + * @param aParamsData A non-modifiable descriptor representing the entire encoding.
1.194 + * @param aBinaryData The encoded binary representation.
1.195 + * @return A pointer to the new CX509DSAPublicKey object. */
1.196 + IMPORT_C static CX509DSAPublicKey* NewLC(const TDesC8& aParamsData, const TDesC8& aBinaryData);
1.197 +
1.198 + /** Creates a new X.509 DSA public key object.
1.199 + *
1.200 + * @param aParams The DSA parameters.
1.201 + * @param aBinaryData The encoded binary representation.
1.202 + * @return A pointer to the new CX509DSAPublicKey object. */
1.203 + IMPORT_C static CX509DSAPublicKey* NewL(const CDSAParameters& aParams, const TDesC8& aBinaryData);
1.204 +
1.205 + /** Creates a new X.509 DSA public key object, and puts a pointer to it onto the cleanup stack.
1.206 + *
1.207 + * @param aParams The DSA parameters.
1.208 + * @param aBinaryData The encoded binary representation.
1.209 + * @return A pointer to the new CX509DSAPublicKey object. */
1.210 + IMPORT_C static CX509DSAPublicKey* NewLC(const CDSAParameters& aParams, const TDesC8& aBinaryData);
1.211 +
1.212 + /** Creates a new X.509 DSA public key object.
1.213 + *
1.214 + * @param aParamsData A non-modifiable descriptor representing the entire encoding.
1.215 + * @param aBinaryData The encoded binary representation.
1.216 + * @param aPos The position from which to start decoding.
1.217 + * @return A pointer to the new CX509DSAPublicKey object. */
1.218 + IMPORT_C static CX509DSAPublicKey* NewL(const TDesC8& aParamsData, const TDesC8& aBinaryData,TInt& aPos);
1.219 +
1.220 + /** Creates a new X.509 DSA public key object, and puts a pointer to it onto the cleanup stack.
1.221 + *
1.222 + * @param aParamsData A non-modifiable descriptor representing the entire encoding.
1.223 + * @param aBinaryData The encoded binary representation.
1.224 + * @param aPos The position from which to start decoding.
1.225 + * @return A pointer to the new CX509DSAPublicKey object. */
1.226 + IMPORT_C static CX509DSAPublicKey* NewLC(const TDesC8& aParamsData, const TDesC8& aBinaryData, TInt& aPos);
1.227 +
1.228 + /** Creates a new X.509 DSA public key object.
1.229 + *
1.230 + * @param aParams The DSA parameters.
1.231 + * @param aBinaryData The encoded binary representation.
1.232 + * @param aPos The position from which to start decoding.
1.233 + * @return A pointer to the new CX509DSAPublicKey object. */
1.234 + IMPORT_C static CX509DSAPublicKey* NewL(const CDSAParameters& aParams, const TDesC8& aBinaryData, TInt& aPos);
1.235 +
1.236 + /** Creates a new X.509 DSA public key object, and puts a pointer to it onto the cleanup stack.
1.237 + *
1.238 + * @param aParams The DSA parameters.
1.239 + * @param aBinaryData The encoded binary representation.
1.240 + * @param aPos The position from which to start decoding.
1.241 + * @return A pointer to the new CX509DSAPublicKey object. */
1.242 + IMPORT_C static CX509DSAPublicKey* NewLC(const CDSAParameters& aParams, const TDesC8& aBinaryData, TInt& aPos);
1.243 +public:
1.244 + /** Gets the DSA parameters from the encoding key.
1.245 + *
1.246 + * @param aParamsData A non-modifiable descriptor representing the entire encoding.
1.247 + * @return The DSA parameters. */
1.248 + IMPORT_C static CDSAParameters* DSAParametersL(const TDesC8& aParamsData);
1.249 +protected:
1.250 + /** @internalComponent */
1.251 + void ConstructL(const TDesC8& aParamsData, const TDesC8& aBinaryData, TInt& aPos);
1.252 + /** @internalComponent */
1.253 + void ConstructL(const CDSAParameters& aParams, const TDesC8& aBinaryData, TInt& aPos);
1.254 + /** @internalComponent */
1.255 + CX509DSAPublicKey();
1.256 + };
1.257 +
1.258 +class TASN1DecDSAKeyPair
1.259 +/**
1.260 + * Class for decoding DSA key pairs from ASN.1 DER encoding.
1.261 + *
1.262 + * @publishedAll
1.263 + * @released
1.264 + * @since v8.0
1.265 + */
1.266 + {
1.267 +public:
1.268 + /**
1.269 + * Decodes a DSA key pair from a buffer containing an ASN.1
1.270 + * DER-encoded private key.
1.271 + *
1.272 + * The encoding of the private key contains public key components as well.
1.273 + *
1.274 + * The DER encoding has the following format:
1.275 + * @verbatim
1.276 + * SEQUENCE-OF
1.277 + * INTEGER version (==0, ignored)
1.278 + * INTEGER p (public prime)
1.279 + * INTEGER q (160-bit public subprime, q | p-1)
1.280 + * INTEGER g (public generator of subgroup)
1.281 + * INTEGER x (private key)
1.282 + * INTEGER y (public key y=g^x)
1.283 + * @endverbatim
1.284 + *
1.285 + * @param aDER DER-encoded private key.
1.286 + * @param aPos Position in the buffer to start decoding
1.287 + * (updated on exit).
1.288 + * @param aPublicKey On return, the DSA public key object
1.289 + * @param aPrivateKey On return, the DSA private key object
1.290 + */
1.291 + IMPORT_C void DecodeDERL(const TDesC8& aDER, TInt& aPos,
1.292 + CDSAPublicKey*& aPublicKey, CDSAPrivateKey*& aPrivateKey);
1.293 + };
1.294 +
1.295 +/**
1.296 + * Class for encoding DSA public keys to ASN.1 encoding.
1.297 + *
1.298 + * @publishedAll
1.299 + * @released
1.300 + * @since v8.0
1.301 + */
1.302 +class TASN1EncDSAPublicKey
1.303 + {
1.304 +public:
1.305 + /**
1.306 + * Encodes the supplied public key into a buffer in DER format.
1.307 + *
1.308 + * Note that the encoding has the following format:
1.309 + * @code
1.310 + * SEQUENCE-OF
1.311 + * SEQUENCE-OF
1.312 + * INTEGER p
1.313 + * INTEGER q
1.314 + * INTEGER g
1.315 + * BIT STRING (encoded INTEGER public value)
1.316 + * @endcode
1.317 + *
1.318 + * @param aKey Key to encode.
1.319 + * @return Sequence containing public key information.
1.320 + */
1.321 + IMPORT_C CASN1EncSequence* EncodeDERL(const CDSAPublicKey& aKey) const;
1.322 +
1.323 + /**
1.324 + * Encodes DSA parameters into an ASN.1 encoding structure suitable for
1.325 + * inclusion into other objects, like a PKCS#10 certificate request.
1.326 + *
1.327 + * Note that the encoding has the following form:
1.328 + * @code
1.329 + * SEQUENCE-OF
1.330 + * INTEGER p
1.331 + * INTEGER q
1.332 + * INTEGER g
1.333 + * @endcode
1.334 + *
1.335 + * @param aKey DSA public key.
1.336 + * @return ASN.1 encoding structure on the cleanup stack.
1.337 + */
1.338 + IMPORT_C CASN1EncSequence* EncodeParamsLC(const CDSAPublicKey& aKey) const;
1.339 +
1.340 + /**
1.341 + * Encodes a public key as a bit string.
1.342 + *
1.343 + * @param aKey DSA public key.
1.344 + * @return ASN.1 bit string (public key). This is left on the cleanup stack.
1.345 + */
1.346 +
1.347 + IMPORT_C CASN1EncBitString* EncodePublicValueLC(const CDSAPublicKey& aKey) const;
1.348 + };
1.349 +
1.350 +class CX509DSASignature : public CDSASignature
1.351 +/** Encapsulates the X.509 DSA signature.
1.352 +*
1.353 +* Adds a commitment to a specific encoding scheme allowing superclasses to remain
1.354 +* encoding-independent.
1.355 +*
1.356 +* @publishedAll
1.357 +* @released
1.358 +* @since v6.0 */
1.359 + {
1.360 +public:
1.361 + /** Creates a new DSA Signature object from the specified buffer containing the
1.362 + * encoded binary representation.
1.363 + *
1.364 + * @param aBinaryData The encoded binary representation.
1.365 + * @return A pointer to the new CX509DSASignature object. */
1.366 + IMPORT_C static CX509DSASignature* NewL(const TDesC8& aBinaryData);
1.367 +
1.368 + /** Creates a new DSA Signature object from the specified buffer containing the
1.369 + * encoded binary representation, and puts a pointer to it onto the cleanup stack.
1.370 + *
1.371 + * @param aBinaryData The encoded binary representation.
1.372 + * @return A pointer to the new CX509DSASignature object. */
1.373 + IMPORT_C static CX509DSASignature* NewLC(const TDesC8& aBinaryData);
1.374 +
1.375 + /** Creates a new DSA Signature object from the specified buffer containing the
1.376 + * encoded binary representation, starting at the specified offset.
1.377 + *
1.378 + * @param aBinaryData The encoded binary representation.
1.379 + * @param aPos The offset position from which to start decoding.
1.380 + * @return A pointer to the new CX509DSASignature object. */
1.381 + IMPORT_C static CX509DSASignature* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.382 +
1.383 + /** Creates a new DSA Signature object from the specified buffer containing the
1.384 + * encoded binary representation, starting at the specified offset, and puts
1.385 + * a pointer to it onto the cleanup stack.
1.386 + *
1.387 + * @param aBinaryData The encoded binary representation.
1.388 + * @param aPos The offset position from which to start decoding.
1.389 + * @return A pointer to the new CX509DSASignature object. */
1.390 + IMPORT_C static CX509DSASignature* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.391 +private:
1.392 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.393 + CX509DSASignature();
1.394 + };
1.395 +
1.396 +class CX509DHPublicKey : public CDHPublicKey
1.397 +/** Provides clients with the information they need for Diffie-Hellman key exchange
1.398 +* within a protocol.
1.399 +*
1.400 +* @publishedAll
1.401 +* @released
1.402 +* @since v6.0 */
1.403 + {
1.404 +public:
1.405 + /** Creates a new CX509DHPublicKey object from the specified buffer containing the encoded
1.406 + * binary representation.
1.407 + *
1.408 + * @param aParamsData A non-modifiable descriptor representing the entire encoding.
1.409 + * @param aKeyData
1.410 + * @return A pointer to the new CX509DHPublicKey object.*/
1.411 + IMPORT_C static CX509DHPublicKey* NewL(const TDesC8& aParamsData, const TDesC8& aKeyData);
1.412 +
1.413 + /** Creates a new CX509DHPublicKey object from the specified buffer containing the encoded
1.414 + * binary representation, and puts a pointer to it onto the cleanup stack.
1.415 + *
1.416 + * @param aParamsData A non-modifiable descriptor representing the entire encoding.
1.417 + * @param aKeyData
1.418 + * @return A pointer to the new CX509DHPublicKey object.*/
1.419 + IMPORT_C static CX509DHPublicKey* NewLC(const TDesC8& aParamsData, const TDesC8& aKeyData);
1.420 +public:
1.421 + /** Destructor.
1.422 + *
1.423 + * Frees all resources owned by the object, prior to its destruction. */
1.424 + IMPORT_C virtual ~CX509DHPublicKey();
1.425 +protected:
1.426 + /** @internalComponent */
1.427 + CX509DHPublicKey();
1.428 + /** @internalComponent */
1.429 + void ConstructL(const TDesC8& aParamsData, const TDesC8& aKeyData);
1.430 + };
1.431 +
1.432 +class CX509DHKeyPair : public CDHKeyPair
1.433 +/** This class represents the Diffie-Hellman Key Pair.
1.434 +*
1.435 +* @publishedAll
1.436 +* @released
1.437 +* @since v8.0 */
1.438 +{
1.439 +public:
1.440 + /** Creates a new DH key pair object from the specified buffer containing
1.441 + * the encoded binary representation .
1.442 + *
1.443 + * @param aParamsData A non-modifiable descriptor representing the entire encoding.
1.444 + * @return A pointer to the new CX509DHKeyPair object.
1.445 + */
1.446 + IMPORT_C static CX509DHKeyPair* NewL(const TDesC8& aParamsData);
1.447 +
1.448 + /** Creates a new DH Key Pair object from the specified buffer containing the encoded binary
1.449 + * representation, and puts a pointer to it onto the cleanup stack.
1.450 + *
1.451 + * @param aParamsData A non-modifiable descriptor representing the entire encoding.
1.452 + * @return A pointer to the new CX509DHKeyPair object.
1.453 + */
1.454 + IMPORT_C static CX509DHKeyPair* NewLC(const TDesC8& aParamsData);
1.455 +public:
1.456 +
1.457 + /** Virtual Destructor.
1.458 + * Frees all resources owned by the object, prior to its destruction.
1.459 + *
1.460 + */
1.461 + IMPORT_C virtual ~CX509DHKeyPair();
1.462 +protected:
1.463 + /** @internalComponent */
1.464 + CX509DHKeyPair();
1.465 + /** @internalComponent */
1.466 + void ConstructL(const TDesC8& aParamsData);
1.467 +};
1.468 +
1.469 +class CX509DHValidationParams : public CBase
1.470 +/** Validates Diffie-Hellman (DH) Domain parameters.
1.471 +*
1.472 +* Provides access to the DH Validation Parameters, which are used to determine
1.473 +* if the DH Public Key has been generated in conformance with the algorithm
1.474 +* specified in ESDH (see RFC 2631).
1.475 +*
1.476 +* @publishedAll
1.477 +* @released
1.478 +* @since v6.0 */
1.479 + {
1.480 +public:
1.481 + /** Creates a new DH Validation parameters object from the specified buffer containing
1.482 + * the encoded binary representation.
1.483 + *
1.484 + * @param aBinaryData The encoded binary representation.
1.485 + * @return A pointer to the new CX509DHValidationParams object. */
1.486 + IMPORT_C static CX509DHValidationParams* NewL(const TDesC8& aBinaryData);
1.487 +
1.488 + /** Creates a new DH Validation parameters object from the specified buffer containing
1.489 + * the encoded binary representation, and puts a pointer to it onto the cleanup stack.
1.490 + *
1.491 + * @param aBinaryData The encoded binary representation.
1.492 + * @return A pointer to the new CX509DHValidationParams object. */
1.493 + IMPORT_C static CX509DHValidationParams* NewLC(const TDesC8& aBinaryData);
1.494 +
1.495 + /** Creates a new DH Validation parameters object from the specified buffer containing
1.496 + * the encoded binary representation, starting at the specified offset.
1.497 + *
1.498 + * @param aBinaryData The encoded binary representation.
1.499 + * @param aPos The offset position from which to start decoding.
1.500 + * @return A pointer to the new CX509DHValidationParams object. */
1.501 + IMPORT_C static CX509DHValidationParams* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.502 +
1.503 + /** Creates a new DH Validation parameters object from the specified buffer containing
1.504 + * the encoded binary representation, starting at the specified offset, and puts
1.505 + * a pointer to it onto the cleanup stack.
1.506 + *
1.507 + * @param aBinaryData The encoded binary representation.
1.508 + * @param aPos The offset position from which to start decoding.
1.509 + * @return A pointer to the new CX509DHValidationParams object. */
1.510 + IMPORT_C static CX509DHValidationParams* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.511 +
1.512 + /** Gets a DSA prime generation seed.
1.513 + *
1.514 + * @return The bit string parameter used as the seed. */
1.515 + IMPORT_C const TPtrC8 Seed() const;
1.516 +
1.517 + /** Gets the output from a DSA prime generation counter.
1.518 + *
1.519 + * @return The integer value output. */
1.520 + IMPORT_C const TInteger& PGenCounter() const;
1.521 +
1.522 + /** Destructor.
1.523 + *
1.524 + * Frees all resources owned by the object, prior to its destruction. */
1.525 + virtual ~CX509DHValidationParams();
1.526 +protected:
1.527 + /** @internalComponent */
1.528 + CX509DHValidationParams();
1.529 + /** @internalComponent */
1.530 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.531 + HBufC8* iSeed;
1.532 + RInteger iPGenCounter;
1.533 + };
1.534 +
1.535 +class CX509DHDomainParams : public CBase
1.536 +/** Encapsulates the compulsory Diffie-Hellman domain parameter values P and G
1.537 +* (See RFC 2459).
1.538 +*
1.539 +* @publishedAll
1.540 +* @released
1.541 +* @since v6.0 */
1.542 + {
1.543 +public:
1.544 + /** Creates a new DH Domain parameters object from the specified buffer containing
1.545 + * the encoded binary representation.
1.546 + *
1.547 + * @param aBinaryData The encoded binary representation.
1.548 + * @return A pointer to the new CX509DHDomainParams object. */
1.549 + IMPORT_C static CX509DHDomainParams* NewL(const TDesC8& aBinaryData);
1.550 +
1.551 + /** Creates a new DH Domain parameters object from the specified buffer containing
1.552 + * the encoded binary representation, and puts a pointer to it onto the cleanup stack.
1.553 + *
1.554 + * @param aBinaryData The encoded binary representation.
1.555 + * @return A pointer to the new CX509DHDomainParams object. */
1.556 + IMPORT_C static CX509DHDomainParams* NewLC(const TDesC8& aBinaryData);
1.557 +
1.558 + /** Creates a new DH Domain parameters object from the specified buffer containing
1.559 + * the encoded binary representation, starting at the specified offset.
1.560 + *
1.561 + * @param aBinaryData The encoded binary representation.
1.562 + * @param aPos The offset position from which to start decoding.
1.563 + * @return A pointer to the new CX509DHDomainParams object. */
1.564 + IMPORT_C static CX509DHDomainParams* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.565 +
1.566 + /** Creates a new DH Domain parameters object from the specified buffer containing
1.567 + * the encoded binary representation, starting at the specified offset, and puts
1.568 + * a pointer to it onto the cleanup stack.
1.569 + *
1.570 + * @param aBinaryData The encoded binary representation.
1.571 + * @param aPos The offset position from which to start decoding.
1.572 + * @return A pointer to the new CX509DHDomainParams object. */
1.573 + IMPORT_C static CX509DHDomainParams* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.574 +
1.575 + /** Gets the compulsory parameter value P.
1.576 + *
1.577 + * @return The compulsory parameter value P. */
1.578 + IMPORT_C const TInteger& P() const;
1.579 +
1.580 + /** Gets the compulsory parameter value G.
1.581 + *
1.582 + * @return The compulsory parameter value G. */
1.583 + IMPORT_C const TInteger& G() const;
1.584 +
1.585 +//the next 3 members are optional, in which case NULL is returned
1.586 +//the returned objects remain the property of this object
1.587 +
1.588 +//N.B. according to RFC 2459 the Q member is *not* optional,
1.589 +//however it is not essential for doing DH, and empirical studies
1.590 +//suggest it doesn't get included much, so I'm relaxing the spec here
1.591 +//to permit DomainParams objects which contain no Q.
1.592 +
1.593 + /** Gets the optional value Q.
1.594 + *
1.595 + * @return The optional value Q. */
1.596 + IMPORT_C const TInteger& Q() const;
1.597 +
1.598 + /** Gets the optional value J.
1.599 + *
1.600 + * @return The optional value J. */
1.601 + IMPORT_C const TInteger& J() const;
1.602 +
1.603 + /** Gets the optional validation parameters.
1.604 + *
1.605 + * @return The optional validation parameters. */
1.606 + IMPORT_C const CX509DHValidationParams* ValidationParams() const;
1.607 +
1.608 + /** Destructor.
1.609 + *
1.610 + * Frees all resources owned by the object, prior to its destruction. */
1.611 + virtual ~CX509DHDomainParams();
1.612 +protected:
1.613 + /** @internalComponent */
1.614 + CX509DHDomainParams();
1.615 + /** @internalComponent */
1.616 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.617 + RInteger iP;
1.618 + RInteger iG;
1.619 + RInteger iQ;
1.620 + RInteger iJ;
1.621 + CX509DHValidationParams* iValidationParams;
1.622 + };
1.623 +
1.624 +class TX509KeyEncoder
1.625 +/**
1.626 + * Abstract class that is the base class for RSA and DSA key encoder classes.
1.627 + * These classes are used to encode the X509 ASN.1 types AlgorithmIdentifier and
1.628 + * SubjectPublicKeyInfo.
1.629 + *
1.630 + * This class is part of the pkcs10 API, and will be changed or removed in a
1.631 + * future release. You should not use it.
1.632 + *
1.633 + * @internalTechnology
1.634 + */
1.635 + {
1.636 +public:
1.637 + /**
1.638 + * Constructor that takes an algorithm identifier and saves it into the
1.639 + * corresponding member variable. It is then used in the
1.640 + * EncodeSignatureAlgorithm() function.
1.641 + *
1.642 + * @param aDigestAlg Digest algorithm to use. Currently the following
1.643 + * algorithms are supported: MD2, MD5, and SHA-1.
1.644 + */
1.645 + IMPORT_C TX509KeyEncoder(TAlgorithmId aDigestAlg);
1.646 +
1.647 + /**
1.648 + * Produces the SubjectPublicKeyInfo encoding.
1.649 + *
1.650 + * The encoding has the following ASN.1 format:
1.651 + * @code
1.652 + * SubjectPublicKeyInfo {ALGORITHM : IOSet} ::= SEQUENCE {
1.653 + * algorithm AlgorithmIdentifier {{IOSet}},
1.654 + * subjectPublicKey BIT STRING
1.655 + * }
1.656 + * @endcode
1.657 + */
1.658 + IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const = 0;
1.659 +
1.660 + /**
1.661 + * Produces the AlgorithmIdentifier encoding.
1.662 + *
1.663 + * @return ASN.1 sequence containing signature algorithm
1.664 + */
1.665 + IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const = 0;
1.666 +
1.667 + /**
1.668 + * Produces the DigestAlgorithmIdentifier encoder.
1.669 + *
1.670 + * The encoding has the following ASN.1 format
1.671 + * @code
1.672 + * DigestAlgorithmIdentifier ::= SEQUENCE {
1.673 + * algorithm AlgorithmIdentifier,
1.674 + * parameters ANY DEFINED BY algorithm OPTIONAL }
1.675 + *
1.676 + * AlgorithmIdentifier ::= OBJECT IDENTIFIER
1.677 + * @endcode
1.678 + *
1.679 + * @return Appropriate ASN.1 sequence of type <code>DigestAlgorithmIdentifier</code>
1.680 + */
1.681 + IMPORT_C virtual CASN1EncSequence* EncodeDigestAlgorithmLC() const;
1.682 +
1.683 +protected:
1.684 + /** Digest algorithm to use. */
1.685 + TAlgorithmId iDigestAlg;
1.686 + };
1.687 +
1.688 +class TX509RSAKeyEncoder : public TX509KeyEncoder
1.689 +/**
1.690 + * Subclasses TC509KeyEncoder to provides key encoding capability for RSA public keys.
1.691 + *
1.692 + * This class is part of the pkcs10 API, and will be changed or removed in a
1.693 + * future release. You should not use it.
1.694 + *
1.695 + * @internalTechnology
1.696 + */
1.697 + {
1.698 +public:
1.699 + /**
1.700 + * Constructs a RSA key pair encoder, saving reference to the passed
1.701 + * key pair in the member variable.
1.702 + *
1.703 + * @param aPublicKey RSA public key to use for encoding.
1.704 + * @param aDigestAlg Digest algorithm to use.
1.705 + */
1.706 + IMPORT_C TX509RSAKeyEncoder(const CRSAPublicKey& aPublicKey, TAlgorithmId aDigestAlg);
1.707 +
1.708 + /**
1.709 + * Produces the SubjectPublicKeyInfo encoding.
1.710 + *
1.711 + * The resulting encoding has the following form:
1.712 + * @code
1.713 + * SEQUENCE-OF
1.714 + * SEQUENCE-OF
1.715 + * OID of the encryption algorithm (KRSA)
1.716 + * NULL
1.717 + * BIT STRING encoded public key.
1.718 + * @endcode
1.719 + *
1.720 + * @return DER-encoded public key information, placed on the cleanup stack.
1.721 + */
1.722 + IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const;
1.723 +
1.724 + /**
1.725 + * Produces the AlgorithmIdentifier encoding.
1.726 + *
1.727 + * This has the following form:
1.728 + * @code
1.729 + * SEQUENCE-OF
1.730 + * OID signature-algorithm
1.731 + * NULL
1.732 + * @endcode
1.733 + *
1.734 + * @return ASN.1 sequence containing signature algorithm encoding,
1.735 + * placed on the cleanup stack.
1.736 + */
1.737 + IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const;
1.738 +
1.739 +private:
1.740 + /**
1.741 + * Saved reference to the RSA public key to be used for encoding.
1.742 + */
1.743 + const CRSAPublicKey& iPublicKey;
1.744 + };
1.745 +
1.746 +class TX509DSAKeyEncoder : public TX509KeyEncoder
1.747 +/**
1.748 + * Provides key encoding and signing capability using a DSA public key.
1.749 + *
1.750 + * This class is part of the pkcs10 API, and will be changed or removed in a
1.751 + * future release. You should not use it.
1.752 + *
1.753 + * @internalTechnology
1.754 + */
1.755 + {
1.756 +public:
1.757 + /**
1.758 + * Constructs a DSA key pair encoder, saving reference to the passed
1.759 + * public key in the member variable.
1.760 + *
1.761 + * @param aKeyPublic DSA public key to use for encoding.
1.762 + * @param aDigestAlg Digest algorithm to use.
1.763 + */
1.764 + IMPORT_C TX509DSAKeyEncoder(const CDSAPublicKey& aKeyPublic,
1.765 + TAlgorithmId aDigestAlg);
1.766 +
1.767 + /**
1.768 + * Produces the SubjectPublicKeyInfo encoding.
1.769 + *
1.770 + * The ASN.1 encoding of a DSA key has the following form:
1.771 + * @code
1.772 + * SEQUENCE-OF
1.773 + * SEQUENCE-OF
1.774 + * OID dsa (1.2.840.10040.4.1)
1.775 + * SEQUENCE-OF
1.776 + * INTEGER p
1.777 + * INTEGER q
1.778 + * INTEGER g
1.779 + * BIT STRING
1.780 + * INTEGER public value (y)
1.781 + * @endcode
1.782 + *
1.783 + * @return DER-encoded public key information, placed on the cleanup stack.
1.784 + */
1.785 + IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const;
1.786 +
1.787 + /**
1.788 + * Produces the AlgorithmIdentifier encoding.
1.789 + *
1.790 + * This has the following form:
1.791 + * @code
1.792 + * SEQUENCE-OF
1.793 + * OID dsa-signature-oid
1.794 + * SEQUENCE-OF dsa-params
1.795 + * INTEGER p
1.796 + * INTEGER q
1.797 + * INTEGER g
1.798 + * @endcode
1.799 + *
1.800 + * @return ASN.1 sequence containing signature algorithm encoding,
1.801 + * placed on the cleanup stack.
1.802 + */
1.803 + IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const;
1.804 +
1.805 +private:
1.806 + /**
1.807 + * Saved reference to the DSA public key to be used for encoding.
1.808 + */
1.809 + const CDSAPublicKey& iPublicKey;
1.810 + };
1.811 +
1.812 +#endif