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