securityanddataprivacytools/securitytools/certapp/encdec/x509utils.h
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     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 
       
    22 /**
       
    23  @file
       
    24  @internalComponent
       
    25 */
       
    26 enum TCertificateFormat
       
    27 	{
       
    28     EX509Certificate    = 0x00,
       
    29     EWTLSCertificate    = 0x01,
       
    30 	EX968Certificate    = 0x02,
       
    31 	EUnknownCertificate = 0x0f,
       
    32 	EX509CertificateUrl = 0x10,
       
    33 	EWTLSCertificateUrl = 0x11,
       
    34 	EX968CertificateUrl = 0x12
       
    35 	};
       
    36 
       
    37 const TInt KSHA1HashLengthInBytes = 20;
       
    38 typedef  TBuf8<KSHA1HashLengthInBytes> TSHA1Hash;
       
    39 typedef TSHA1Hash TKeyIdentifier;
       
    40 
       
    41 struct KeyIdentifierObject
       
    42 	{
       
    43 	bool iAutoKey; // iHash needs generating by us, or matched the value we would generate!
       
    44 	TKeyIdentifier iHash;
       
    45 	};
       
    46 
       
    47 void EncodeHuman(REncodeWriteStream& aStream,const KeyIdentifierObject &aKeyId);
       
    48 void DecodeHuman(RDecodeReadStream& aStream, KeyIdentifierObject &aKeyId);
       
    49 
       
    50 RWriteStream& operator<<(RWriteStream& aStream,const KeyIdentifierObject& aKeyId);
       
    51 RReadStream& operator>>(RReadStream& aStream, KeyIdentifierObject& aKeyId);
       
    52 
       
    53 
       
    54 enum EUseCertificateExtension
       
    55 {
       
    56 	KIgnoreCertificateExtension,
       
    57 	KUseCertificateExtension
       
    58 };
       
    59 
       
    60 
       
    61 /**
       
    62    Get the subject key id from the certificate extension or calculate
       
    63    it from the public key (as specified in rfc3280 4.2.1.2 method 1).
       
    64 
       
    65    The subject name and subject key id are returned.
       
    66 
       
    67    WARNING: This function is NOT valid for client certs. For client
       
    68    certs, the subject key id in the certificate store MUST match the id
       
    69    of the key in the keystore.
       
    70 
       
    71    If ok return true.
       
    72 
       
    73    If the certificate is invalid then exit the program with an error message!
       
    74  */
       
    75 bool X509SubjectKeyId(EUseCertificateExtension aUseExtension, bool aUseRfc3280Algorithm,
       
    76 					  const std::string &aCert, 
       
    77 					  std::string &aSubject, TKeyIdentifier &aSubjectKeyId);
       
    78 
       
    79 /**
       
    80    Get the issuer key id from the certificate authority key id extension.
       
    81 
       
    82    The issuer name and issuer key id are returned.
       
    83 
       
    84    If ok return true.
       
    85 
       
    86    If the certificate is invalid then exit the program with an error message!
       
    87  */
       
    88 bool X509IssuerKeyId(EUseCertificateExtension aUseExtension,
       
    89 					 const TUint8 *aCert, TUint32 aCertLength, 
       
    90 					 std::string &aIssuer,
       
    91 					 TKeyIdentifier &aIssuerKeyId);
       
    92 
       
    93 /**
       
    94    Convert the DER certificate into PEM form
       
    95 */
       
    96 void Der2Pem(const std::string &aDerCert, std::string &aPemCert);
       
    97 
       
    98 /**
       
    99    Convert the PEM certificate into DER form
       
   100    
       
   101    Returns true if conversion succeeds
       
   102 */
       
   103 bool Pem2Der(const std::string &aPemCert, std::string &aDerCert);
       
   104 #endif