os/security/securityanddataprivacytools/securitytools/certapp/encdec/x509utils.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 #ifndef __X509UTILS_H__
     2 #define __X509UTILS_H__/*
     3 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     4 * All rights reserved.
     5 * This component and the accompanying materials are made available
     6 * under the terms of the License "Eclipse Public License v1.0"
     7 * which accompanies this distribution, and is available
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     9 *
    10 * Initial Contributors:
    11 * Nokia Corporation - initial contribution.
    12 *
    13 * Contributors:
    14 *
    15 * Description: 
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22  @internalComponent
    23 */
    24 enum TCertificateFormat
    25 	{
    26     EX509Certificate    = 0x00,
    27     EWTLSCertificate    = 0x01,
    28 	EX968Certificate    = 0x02,
    29 	EUnknownCertificate = 0x0f,
    30 	EX509CertificateUrl = 0x10,
    31 	EWTLSCertificateUrl = 0x11,
    32 	EX968CertificateUrl = 0x12
    33 	};
    34 
    35 const TInt KSHA1HashLengthInBytes = 20;
    36 typedef  TBuf8<KSHA1HashLengthInBytes> TSHA1Hash;
    37 typedef TSHA1Hash TKeyIdentifier;
    38 
    39 struct KeyIdentifierObject
    40 	{
    41 	bool iAutoKey; // iHash needs generating by us, or matched the value we would generate!
    42 	TKeyIdentifier iHash;
    43 	};
    44 
    45 void EncodeHuman(REncodeWriteStream& aStream,const KeyIdentifierObject &aKeyId);
    46 void DecodeHuman(RDecodeReadStream& aStream, KeyIdentifierObject &aKeyId);
    47 
    48 RWriteStream& operator<<(RWriteStream& aStream,const KeyIdentifierObject& aKeyId);
    49 RReadStream& operator>>(RReadStream& aStream, KeyIdentifierObject& aKeyId);
    50 
    51 
    52 enum EUseCertificateExtension
    53 {
    54 	KIgnoreCertificateExtension,
    55 	KUseCertificateExtension
    56 };
    57 
    58 
    59 /**
    60    Get the subject key id from the certificate extension or calculate
    61    it from the public key (as specified in rfc3280 4.2.1.2 method 1).
    62 
    63    The subject name and subject key id are returned.
    64 
    65    WARNING: This function is NOT valid for client certs. For client
    66    certs, the subject key id in the certificate store MUST match the id
    67    of the key in the keystore.
    68 
    69    If ok return true.
    70 
    71    If the certificate is invalid then exit the program with an error message!
    72  */
    73 bool X509SubjectKeyId(EUseCertificateExtension aUseExtension, bool aUseRfc3280Algorithm,
    74 					  bool aIsCa, const std::string &aCert, 
    75 					  std::string &aSubject, TKeyIdentifier &aSubjectKeyId);
    76 
    77 /**
    78    Get the issuer key id from the certificate authority key id extension.
    79 
    80    The issuer name and issuer key id are returned.
    81 
    82    If ok return true.
    83 
    84    If the certificate is invalid then exit the program with an error message!
    85  */
    86 bool X509IssuerKeyId(EUseCertificateExtension aUseExtension,
    87 					 const TUint8 *aCert, TUint32 aCertLength, 
    88 					 std::string &aIssuer,
    89 					 TKeyIdentifier &aIssuerKeyId);
    90 
    91 /**
    92    Convert the DER certificate into PEM form
    93 */
    94 void Der2Pem(const std::string &aDerCert, std::string &aPemCert);
    95 
    96 /**
    97    Convert the PEM certificate into DER form
    98    
    99    Returns true if conversion succeeds
   100 */
   101 bool Pem2Der(const std::string &aPemCert, std::string &aDerCert);
   102 #endif