49 CKeyDetails* CKeyDetails::NewL( TInt aHandle, |
68 CKeyDetails* CKeyDetails::NewL( TInt aHandle, |
50 const TDesC& aLabel, |
69 const TDesC& aLabel, |
51 const TDesC8& aPrivateKey, |
70 const TDesC8& aPrivateKey, |
52 const TDesC8& aPublicKey ) |
71 const TDesC8& aPublicKey ) |
53 { |
72 { |
54 CKeyDetails* keyDetails = new (ELeave) CKeyDetails(); |
73 TKeyIdentifier keyID; |
|
74 keyID.FillZ(keyID.MaxSize()); |
|
75 TKeyUsagePKCS15 usage = EPKCS15UsageNone; |
|
76 TUint size = 0; |
|
77 TInt handle = aHandle; |
|
78 const TSecurityPolicy& usePolicy = TSecurityPolicy::EAlwaysPass; |
|
79 const TSecurityPolicy& managementPolicy = TSecurityPolicy::EAlwaysPass; |
|
80 EKeyAlgorithm algorithm = EECC; |
|
81 TInt accessType = CKeyInfoBase::ENeverExtractable; |
|
82 accessType |= CKeyInfoBase::ELocal; |
|
83 TBool native = ETrue; |
|
84 TTime startDate = 0; |
|
85 TTime endDate = 0; |
|
86 HBufC8* pkcs8AttributeSet = NULL; |
|
87 |
|
88 HBufC* label = HBufC::NewLC(aLabel.Length()); |
|
89 label->Des().Copy(aLabel); |
|
90 |
|
91 CKeyDetails* keyDetails = new (ELeave) CKeyDetails(keyID,usage,size,label,handle,usePolicy,managementPolicy,algorithm,accessType,native,startDate,endDate,pkcs8AttributeSet); |
|
92 |
|
93 CleanupStack::Pop(label); |
55 CleanupStack::PushL(keyDetails); |
94 CleanupStack::PushL(keyDetails); |
56 keyDetails->ConstructL(aHandle, aLabel, aPrivateKey, aPublicKey); |
95 keyDetails->ConstructL(aPrivateKey, aPublicKey); |
57 CleanupStack::Pop(keyDetails); |
96 CleanupStack::Pop(keyDetails); |
58 return keyDetails; |
97 return keyDetails; |
59 } |
98 } |
60 |
99 |
61 |
100 |
62 CKeyDetails* CKeyDetails::NewL(RStoreReadStream& aReadStream) |
101 CKeyDetails* CKeyDetails::NewL(RStoreReadStream& aReadStream) |
63 { |
102 { |
64 CKeyDetails* self = new (ELeave) CKeyDetails(); |
103 CKeyDetails* self = new (ELeave) CKeyDetails(); |
65 CleanupStack::PushL(self); |
104 CleanupStack::PushL(self); |
66 self->InternalizeL(aReadStream); |
105 self->ConstructL(aReadStream); |
67 CleanupStack::Pop(self); |
106 CleanupStack::Pop(self); |
68 return (self); |
107 return (self); |
69 } |
108 } |
70 |
109 |
71 void CKeyDetails::ConstructL( TInt aHandle, const TDesC& aLabel, |
110 void CKeyDetails::ConstructL( const TDesC8& aPrivateKey, const TDesC8& aPublicKey ) |
72 const TDesC8& aPrivateKey, const TDesC8& aPublicKey ) |
|
73 { |
111 { |
74 CKeyInfoBase::ConstructL(); |
|
75 iHandle = aHandle; |
|
76 iLabel = aLabel.AllocL(); |
|
77 iPrivateKey = aPrivateKey.AllocL(); |
112 iPrivateKey = aPrivateKey.AllocL(); |
78 iPublicKey = aPublicKey.AllocL(); |
113 iPublicKey = aPublicKey.AllocL(); |
79 |
114 } |
80 // set the access type to never extractable |
115 |
81 iAccessType |= CKeyInfoBase::ENeverExtractable; |
116 void CKeyDetails::ConstructL(RStoreReadStream& aReadStream) |
82 iAccessType |= CKeyInfoBase::ELocal; |
117 { |
83 // Policy set for keys in hardware depends on the vendor requirements |
118 CKeyInfoBase::ConstructL(aReadStream); |
84 // this reference implementation assumes that accessibility of keys |
119 InternalizeL(aReadStream); |
85 // does not need any restriction. Hence for the testing environment policy is set to always pass. |
|
86 TSecurityPolicy temp(TSecurityPolicy::EAlwaysPass); |
|
87 iUsePolicy = temp; |
|
88 } |
120 } |
89 |
121 |
90 void CKeyDetails::ExternalizeL(RWriteStream& aWriteStream) const |
122 void CKeyDetails::ExternalizeL(RWriteStream& aWriteStream) const |
91 { |
123 { |
92 aWriteStream.WriteInt32L(iHandle); |
124 CKeyInfoBase::ExternalizeL(aWriteStream); |
93 |
|
94 TInt stringLen = iLabel->Length(); |
|
95 aWriteStream.WriteInt32L(stringLen); |
|
96 TPtr stringPtr = iLabel->Des(); |
|
97 stringPtr.SetLength(stringLen); |
|
98 aWriteStream.WriteL(stringPtr); |
|
99 |
125 |
100 stringLen = iPrivateKey->Length(); |
126 TInt stringLen = iPrivateKey->Length(); |
101 aWriteStream.WriteInt32L(stringLen); |
127 aWriteStream.WriteInt32L(stringLen); |
102 TPtr8 keyPtr = iPrivateKey->Des(); |
128 TPtr8 keyPtr = iPrivateKey->Des(); |
103 keyPtr.SetLength(stringLen); |
129 keyPtr.SetLength(stringLen); |
104 aWriteStream.WriteL(keyPtr); |
130 aWriteStream.WriteL(keyPtr); |
105 |
131 |
106 stringLen = iPublicKey->Length(); |
132 stringLen = iPublicKey->Length(); |
107 aWriteStream.WriteInt32L(stringLen); |
133 aWriteStream.WriteInt32L(stringLen); |
108 keyPtr = iPublicKey->Des(); |
134 keyPtr = iPublicKey->Des(); |
109 keyPtr.SetLength(stringLen); |
135 keyPtr.SetLength(stringLen); |
110 aWriteStream.WriteL(keyPtr); |
136 aWriteStream.WriteL(keyPtr); |
|
137 |
111 } |
138 } |
112 |
139 |
113 void CKeyDetails::InternalizeL(RReadStream& aReadStream) |
140 void CKeyDetails::InternalizeL(RReadStream& aReadStream) |
114 { |
141 { |
115 iHandle = aReadStream.ReadInt32L(); |
|
116 |
|
117 TInt stringLen = aReadStream.ReadInt32L(); |
142 TInt stringLen = aReadStream.ReadInt32L(); |
118 iLabel = HBufC::NewMaxL(stringLen); |
|
119 TPtr labelPtr((TUint16*)iLabel->Ptr(), stringLen, stringLen); |
|
120 labelPtr.FillZ(stringLen); |
|
121 aReadStream.ReadL(labelPtr); |
|
122 |
|
123 stringLen = aReadStream.ReadInt32L(); |
|
124 iPrivateKey = HBufC8::NewMaxL(stringLen); |
143 iPrivateKey = HBufC8::NewMaxL(stringLen); |
125 TPtr8 privateKeyPtr((TUint8*)iPrivateKey->Ptr(), stringLen, stringLen); |
144 TPtr8 privateKeyPtr((TUint8*)iPrivateKey->Ptr(), stringLen, stringLen); |
126 privateKeyPtr.FillZ(stringLen); |
145 privateKeyPtr.FillZ(stringLen); |
127 aReadStream.ReadL(privateKeyPtr); |
146 aReadStream.ReadL(privateKeyPtr); |
128 |
147 |
129 stringLen = aReadStream.ReadInt32L(); |
148 stringLen = aReadStream.ReadInt32L(); |
130 iPublicKey = HBufC8::NewMaxL(stringLen); |
149 iPublicKey = HBufC8::NewMaxL(stringLen); |
131 TPtr8 publicKeyPtr((TUint8*)iPublicKey->Ptr(), stringLen, stringLen); |
150 TPtr8 publicKeyPtr((TUint8*)iPublicKey->Ptr(), stringLen, stringLen); |
132 publicKeyPtr.FillZ(stringLen); |
151 publicKeyPtr.FillZ(stringLen); |
133 aReadStream.ReadL(publicKeyPtr); |
152 aReadStream.ReadL(publicKeyPtr); |
134 // Policy set for keys in hardware depends on the vendor requirements |
153 |
135 // this reference implementation assumes that accessibility of keys |
|
136 // does not need any restriction. Hence for the testing environment policy is set to always pass. |
|
137 TSecurityPolicy temp(TSecurityPolicy::EAlwaysPass); |
|
138 iUsePolicy = temp; |
|
139 } |
154 } |