sl@0: /* sl@0: * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "cctcertinfo.h" sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS sl@0: sl@0: /** Mask constants used for serializing iDeletable and iFormat attributes sl@0: */ sl@0: const TUint KReadOnlyFlagMask = 128; sl@0: const TUint KFormatMask = 127; sl@0: sl@0: /** The UID of a CertInfo MCTTokenObject. */ sl@0: const TInt KCTObjectCertInfo = 0x101F50E6; sl@0: sl@0: #endif sl@0: sl@0: // MCertInfo /////////////////////////////////////////////////////////////////// sl@0: sl@0: EXPORT_C MCertInfo::MCertInfo() : sl@0: iDeletable(ETrue) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C MCertInfo::MCertInfo(const TDesC& aLabel, sl@0: TCertificateFormat aFormat, sl@0: TCertificateOwnerType aCertificateOwnerType, sl@0: TInt aSize, sl@0: const TKeyIdentifier* aSubjectKeyId, sl@0: const TKeyIdentifier* aIssuerKeyId, sl@0: TInt aCertificateId, sl@0: TBool aDeletable) : sl@0: iLabel(aLabel), iCertificateId(aCertificateId), sl@0: iFormat(aFormat), iCertificateOwnerType(aCertificateOwnerType), sl@0: iSize(aSize), iDeletable(aDeletable) sl@0: { sl@0: if (aSubjectKeyId) sl@0: { sl@0: iSubjectKeyId = *aSubjectKeyId; sl@0: } sl@0: else sl@0: { sl@0: iSubjectKeyId = KNullDesC8; sl@0: } sl@0: if (aIssuerKeyId) sl@0: { sl@0: iIssuerKeyId = *aIssuerKeyId; sl@0: } sl@0: else sl@0: { sl@0: iIssuerKeyId = KNullDesC8; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C MCertInfo::MCertInfo(const MCertInfo& aOther) : sl@0: iLabel(aOther.iLabel), sl@0: iCertificateId(aOther.iCertificateId), sl@0: iFormat(aOther.iFormat), sl@0: iCertificateOwnerType(aOther.iCertificateOwnerType), sl@0: iSize(aOther.iSize), sl@0: iSubjectKeyId(aOther.iSubjectKeyId), sl@0: iIssuerKeyId(aOther.iIssuerKeyId), sl@0: iDeletable(aOther.iDeletable) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C MCertInfo::~MCertInfo() sl@0: { sl@0: delete iIssuerHash; sl@0: } sl@0: sl@0: const TDesC8* MCertInfo::IssuerHash() const sl@0: { sl@0: return iIssuerHash; sl@0: } sl@0: sl@0: EXPORT_C void MCertInfo::ConstructL(const TDesC8* aIssuerHash) sl@0: { sl@0: delete iIssuerHash; sl@0: iIssuerHash = NULL; sl@0: if (aIssuerHash) sl@0: { sl@0: iIssuerHash = aIssuerHash->AllocL(); sl@0: } sl@0: sl@0: if (!Valid()) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: } sl@0: sl@0: TBool MCertInfo::Valid() const sl@0: { sl@0: if (iLabel.Length() == 0) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: if (iCertificateId < 0) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: if (iFormat != EX509Certificate && iFormat != EWTLSCertificate && sl@0: iFormat != EX968Certificate && iFormat != EX509CertificateUrl && sl@0: iFormat != EWTLSCertificateUrl && iFormat != EX968CertificateUrl) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: if (iCertificateOwnerType != ECACertificate && sl@0: iCertificateOwnerType != EUserCertificate && sl@0: iCertificateOwnerType != EPeerCertificate) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: if (iSize <= 0) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: if (iIssuerHash && *iIssuerHash == KNullDesC8) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: EXPORT_C void MCertInfo::ExternalizeL(RWriteStream& aStream) const sl@0: sl@0: This method externalizes the MCertInfo object to the given stream. sl@0: The iDeletable boolean attribute is combined with the iFormat attribute sl@0: for certstore backward compatibility sl@0: */ sl@0: EXPORT_C void MCertInfo::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: // insert iDeletable flag as most significant digit of iFormat in order sl@0: // store the flag without changing the externalized record format sl@0: // The value is OPPOSITE for backward compatibility sl@0: TUint8 tmpValue = static_cast (iFormat | (iDeletable ? 0 : KReadOnlyFlagMask)); sl@0: sl@0: aStream.WriteUint8L(tmpValue); sl@0: aStream.WriteInt32L(iSize); sl@0: aStream << iLabel; sl@0: aStream.WriteInt32L(iCertificateId); sl@0: aStream.WriteUint8L(iCertificateOwnerType); sl@0: aStream << iSubjectKeyId; sl@0: aStream << iIssuerKeyId; sl@0: } sl@0: sl@0: /** sl@0: EXPORT_C void MCertInfo::InternalizeL(RReadStream& aStream) sl@0: sl@0: This method internalizes a MCertInfo object from the given stream. sl@0: The iDeletable boolean and iFormat attributes are both extracted sl@0: from the stored iFormat value using for certstore backward compatibility sl@0: */ sl@0: EXPORT_C void MCertInfo::InternalizeL(RReadStream& aStream) sl@0: { sl@0: // get first byte from stream containing iDeletable flag and iFormat value sl@0: TUint8 tmpValue = aStream.ReadUint8L(); sl@0: sl@0: // extract iDeletable flag from most significant digit of iFormat sl@0: // set iDeletable to the OPPOSITE of the 8th bit value sl@0: iDeletable = !(tmpValue & KReadOnlyFlagMask); sl@0: sl@0: // extract iFormat = the value of the 7 least significant bits sl@0: iFormat = static_cast (tmpValue & KFormatMask); sl@0: sl@0: iSize = aStream.ReadInt32L(); sl@0: aStream >> iLabel; sl@0: iCertificateId = aStream.ReadInt32L(); sl@0: iCertificateOwnerType = static_cast(aStream.ReadUint8L()); sl@0: aStream >> iSubjectKeyId; sl@0: aStream >> iIssuerKeyId; sl@0: sl@0: if (!Valid()) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: } sl@0: sl@0: // CCTCertInfo ///////////////////////////////////////////////////////////////// sl@0: sl@0: EXPORT_C CCTCertInfo* CCTCertInfo::NewL(RReadStream& aStream, MCTToken& aToken) sl@0: { sl@0: CCTCertInfo* self = CCTCertInfo::NewLC(aStream, aToken); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(RReadStream& aStream, MCTToken& aToken) sl@0: { sl@0: CCTCertInfo* self = new(ELeave) CCTCertInfo(aToken); sl@0: CleanupReleasePushL(*self); sl@0: self->ConstructL(aStream); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const TDesC& aLabel, sl@0: TCertificateFormat aFormat, sl@0: TCertificateOwnerType aCertificateOwnerType, sl@0: TInt aSize, sl@0: const TKeyIdentifier* aSubjectKeyId, sl@0: const TKeyIdentifier* aIssuerKeyId, sl@0: MCTToken& aToken, sl@0: TInt aCertificateId) sl@0: { sl@0: CCTCertInfo* self = CCTCertInfo::NewLC(aLabel, sl@0: aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, aToken, sl@0: aCertificateId, ETrue); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const TDesC& aLabel, sl@0: TCertificateFormat aFormat, sl@0: TCertificateOwnerType aCertificateOwnerType, sl@0: TInt aSize, sl@0: const TKeyIdentifier* aSubjectKeyId, sl@0: const TKeyIdentifier* aIssuerKeyId, sl@0: MCTToken& aToken, sl@0: TInt aCertificateId, sl@0: TBool aIsDeletable, sl@0: const TDesC8* aIssuerHash) sl@0: { sl@0: CCTCertInfo* self = CCTCertInfo::NewLC(aLabel, sl@0: aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, aToken, sl@0: aCertificateId, aIsDeletable, aIssuerHash); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const TDesC& aLabel, sl@0: TCertificateFormat aFormat, sl@0: TCertificateOwnerType aCertificateOwnerType, sl@0: TInt aSize, sl@0: const TKeyIdentifier* aSubjectKeyId, sl@0: const TKeyIdentifier* aIssuerKeyId, sl@0: MCTToken& aToken, sl@0: TInt aCertificateId) sl@0: { sl@0: return CCTCertInfo::NewLC(aLabel, sl@0: aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, sl@0: aToken, aCertificateId, ETrue); sl@0: } sl@0: sl@0: EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const TDesC& aLabel, sl@0: TCertificateFormat aFormat, sl@0: TCertificateOwnerType aCertificateOwnerType, sl@0: TInt aSize, sl@0: const TKeyIdentifier* aSubjectKeyId, sl@0: const TKeyIdentifier* aIssuerKeyId, sl@0: MCTToken& aToken, sl@0: TInt aCertificateId, sl@0: TBool aIsDeletable, sl@0: const TDesC8* aIssuerHash) sl@0: { sl@0: CCTCertInfo* self = new(ELeave) CCTCertInfo(aLabel, sl@0: aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, sl@0: aIssuerKeyId, aToken, aCertificateId, aIsDeletable); sl@0: CleanupReleasePushL(*self); sl@0: self->ConstructL(aIssuerHash); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const CCTCertInfo& aCertInfo) sl@0: { sl@0: CCTCertInfo* self = CCTCertInfo::NewLC(aCertInfo); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const CCTCertInfo& aCertInfo) sl@0: { sl@0: CCTCertInfo* self = new(ELeave) CCTCertInfo(aCertInfo); sl@0: CleanupReleasePushL(*self); sl@0: self->ConstructL(aCertInfo.IssuerHash()); sl@0: return self; sl@0: } sl@0: sl@0: CCTCertInfo::CCTCertInfo(MCTToken& aToken) sl@0: : MCTTokenObject(aToken), iToken(aToken) sl@0: { sl@0: } sl@0: sl@0: CCTCertInfo::CCTCertInfo(const TDesC& aLabel, sl@0: TCertificateFormat aFormat, sl@0: TCertificateOwnerType aCertificateOwnerType, sl@0: TInt aSize, sl@0: const TKeyIdentifier* aSubjectKeyId, sl@0: const TKeyIdentifier* aIssuerKeyId, sl@0: MCTToken& aToken, sl@0: TInt aCertificateId, sl@0: TBool aIsDeletable) sl@0: : MCTTokenObject(aToken), sl@0: MCertInfo(aLabel, aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, sl@0: aIssuerKeyId, aCertificateId, aIsDeletable), sl@0: iToken(aToken) sl@0: { sl@0: } sl@0: sl@0: CCTCertInfo::CCTCertInfo(const CCTCertInfo& aOther) sl@0: : MCTTokenObject(aOther.iToken), MCertInfo(aOther), iToken(aOther.iToken) sl@0: { sl@0: } sl@0: sl@0: void CCTCertInfo::ConstructL(RReadStream& aStream) sl@0: { sl@0: InternalizeL(aStream); sl@0: } sl@0: sl@0: void CCTCertInfo::ConstructL(const TDesC8* aIssuerHash) sl@0: { sl@0: MCertInfo::ConstructL(aIssuerHash); sl@0: } sl@0: sl@0: EXPORT_C CCTCertInfo::~CCTCertInfo() sl@0: { sl@0: } sl@0: sl@0: const TDesC& CCTCertInfo::Label() const sl@0: { sl@0: return iLabel; sl@0: } sl@0: sl@0: TUid CCTCertInfo::Type() const sl@0: { sl@0: TUid uid = { KCTObjectCertInfo }; sl@0: return uid; sl@0: } sl@0: sl@0: EXPORT_C const TKeyIdentifier& CCTCertInfo::SubjectKeyId() const sl@0: { sl@0: return iSubjectKeyId; sl@0: } sl@0: sl@0: EXPORT_C const TKeyIdentifier& CCTCertInfo::IssuerKeyId() const sl@0: { sl@0: return iIssuerKeyId; sl@0: } sl@0: sl@0: EXPORT_C TCertificateFormat CCTCertInfo::CertificateFormat() const sl@0: { sl@0: return iFormat; sl@0: } sl@0: sl@0: EXPORT_C TCertificateOwnerType CCTCertInfo::CertificateOwnerType() const sl@0: { sl@0: return iCertificateOwnerType; sl@0: } sl@0: sl@0: EXPORT_C TInt CCTCertInfo::Size() const sl@0: { sl@0: return iSize; sl@0: } sl@0: sl@0: MCTToken& CCTCertInfo::Token() const sl@0: { sl@0: return iToken; sl@0: } sl@0: sl@0: EXPORT_C TCTTokenObjectHandle CCTCertInfo::Handle() const sl@0: { sl@0: return TCTTokenObjectHandle(iToken.Handle(), iCertificateId); sl@0: } sl@0: sl@0: EXPORT_C TBool CCTCertInfo::IsDeletable() const sl@0: { sl@0: return iDeletable; sl@0: } sl@0: sl@0: EXPORT_C const TDesC8* CCTCertInfo::IssuerHash() const sl@0: { sl@0: return MCertInfo::IssuerHash(); sl@0: } sl@0: sl@0: EXPORT_C TBool CCTCertInfo::operator==(const CCTCertInfo& aCertInfo) const sl@0: { sl@0: return aCertInfo.iLabel == iLabel; sl@0: } sl@0: sl@0: EXPORT_C void CCTCertInfo::SetCertificateId(TInt aCertId) sl@0: { sl@0: iCertificateId = aCertId; sl@0: }