|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // SSL3.0 and TLS1.0 Handshake message items source file. |
|
15 // This file contains definitions for SSL3.0 and TLS1.0 handshake items |
|
16 // (i.e., handshake protocol types, headers, message structures, etc). |
|
17 // |
|
18 // |
|
19 |
|
20 /** |
|
21 @file |
|
22 */ |
|
23 |
|
24 #include "tlshandshakeitem.h" |
|
25 #include <signed.h> |
|
26 #include <hash.h> |
|
27 #include <tlstypedef.h> |
|
28 |
|
29 void CServerKeyExchMsg::ComputeDigest( CMessageDigest* pDigest, const TDesC8& aClientRandom, const TDesC8& aServerRandom, TPtrC8& aDigestParams, TDes8& aDigest ) const |
|
30 { |
|
31 pDigest->Update(aClientRandom); |
|
32 pDigest->Update(aServerRandom); |
|
33 aDigest.Copy( pDigest->Final(aDigestParams) ); |
|
34 } |
|
35 |
|
36 void CServerKeyExchMsg::ComputeDSADigestL( const TDesC8& aClientRandom, const TDesC8& aServerRandom, TPtrC8& aDigestParams, TDes8& aDigest ) const |
|
37 { |
|
38 CMessageDigest* pDigest = CSHA1::NewL(); |
|
39 ComputeDigest( pDigest, aClientRandom, aServerRandom, aDigestParams, aDigest ); |
|
40 delete pDigest; |
|
41 } |
|
42 |
|
43 void CServerKeyExchMsg::ComputeRSADigestL( const TDesC8& aClientRandom, const TDesC8& aServerRandom, TPtrC8& aDigestParams, TDes8& aDigest ) const |
|
44 { |
|
45 CMessageDigest* pDigest = CMD5::NewL(); |
|
46 ComputeDigest( pDigest, aClientRandom, aServerRandom, aDigestParams, aDigest ); |
|
47 delete pDigest; |
|
48 //append DSA digest (SHA1 hash) |
|
49 TInt nMax = aDigest.MaxLength() - aDigest.Length(); |
|
50 TPtr8 digest( const_cast<TUint8*>(aDigest.Ptr()) + aDigest.Length(), 0, nMax ); |
|
51 ComputeDSADigestL( aClientRandom, aServerRandom, aDigestParams, digest ); |
|
52 aDigest.SetLength( digest.Length() + aDigest.Length() ); |
|
53 } |
|
54 |
|
55 //RSA key exchange |
|
56 void CRsaAnonServerKeyExchMsg::CopyParamsL( CTlsCryptoAttributes *aAttrs ) |
|
57 { |
|
58 iRsaParams.iRsaModulus.CopyBodyToL( aAttrs->iPublicKeyParams->iValue1); |
|
59 iRsaParams.iRsaExponent.CopyBodyToL( aAttrs->iPublicKeyParams->iValue2); |
|
60 } |
|
61 |
|
62 TPtr8 CRsaDsaServerKeyExchMsg::Signature() |
|
63 { |
|
64 return iDsaSignature.iSha.GetBodyDes(); |
|
65 } |
|
66 |
|
67 void CRsaDsaServerKeyExchMsg::ComputeDigestL( const TDesC8& aClientRandom, const TDesC8& aServerRandom, TDes8& aDigest ) |
|
68 { |
|
69 TPtrC8 ptrParams( GetDigestParamsPtr(), GetDigestParamsLength() ); |
|
70 ComputeDSADigestL( aClientRandom, aServerRandom, ptrParams, aDigest ); |
|
71 } |
|
72 |
|
73 TPtr8 CRsaRsaServerKeyExchMsg::Signature() |
|
74 { |
|
75 return iRsaSignature.iMd5Sha.GetBodyDes(); |
|
76 } |
|
77 |
|
78 void CRsaRsaServerKeyExchMsg::ComputeDigestL( const TDesC8& aClientRandom, const TDesC8& aServerRandom, TDes8& aDigest ) |
|
79 { |
|
80 TPtrC8 ptrParams( GetDigestParamsPtr(), GetDigestParamsLength() ); |
|
81 ComputeRSADigestL( aClientRandom, aServerRandom, ptrParams, aDigest ); |
|
82 } |
|
83 |
|
84 //DH key exchange |
|
85 void CDhAnonServerKeyExchMsg::CopyParamsL( CTlsCryptoAttributes *aAttrs ) |
|
86 { |
|
87 iDhParams.iDh_p.CopyBodyToL( aAttrs->iPublicKeyParams->iValue1); |
|
88 iDhParams.iDh_g.CopyBodyToL( aAttrs->iPublicKeyParams->iValue2); |
|
89 iDhParams.iDh_Ys.CopyBodyToL( aAttrs->iPublicKeyParams->iValue3); |
|
90 } |
|
91 |
|
92 TPtr8 CDhDsaServerKeyExchMsg::Signature() |
|
93 { |
|
94 return iDsaSignature.iSha.GetBodyDes(); |
|
95 } |
|
96 |
|
97 void CDhDsaServerKeyExchMsg::ComputeDigestL( const TDesC8& aClientRandom, const TDesC8& aServerRandom, TDes8& aDigest ) |
|
98 { |
|
99 TPtrC8 ptrParams( GetDigestParamsPtr(), GetDigestParamsLength() ); |
|
100 ComputeDSADigestL( aClientRandom, aServerRandom, ptrParams, aDigest ); |
|
101 } |
|
102 |
|
103 TPtr8 CDhRsaServerKeyExchMsg::Signature() |
|
104 { |
|
105 return iRsaSignature.iMd5Sha.GetBodyDes(); |
|
106 } |
|
107 |
|
108 void CDhRsaServerKeyExchMsg::ComputeDigestL( const TDesC8& aClientRandom, const TDesC8& aServerRandom, TDes8& aDigest ) |
|
109 { |
|
110 TPtrC8 ptrParams( GetDigestParamsPtr(), GetDigestParamsLength() ); |
|
111 ComputeRSADigestL( aClientRandom, aServerRandom, ptrParams, aDigest ); |
|
112 } |
|
113 |
|
114 //PSK key exchange |
|
115 void CPskServerKeyExchMsg::CopyParamsL( CTlsCryptoAttributes *aAttrs ) |
|
116 { |
|
117 iPskServerParams.iPskIdentityHint.CopyBodyToL( aAttrs->iPskIdentityHint ); |
|
118 } |
|
119 |
|
120 TPtr8 CPskServerKeyExchMsg::Signature() |
|
121 { |
|
122 // Not used |
|
123 return TPtr8(0,0); |
|
124 } |
|
125 |
|
126 void CPskServerKeyExchMsg::ComputeDigestL( const TDesC8& /*aClientRandom*/, const TDesC8& /*aServerRandom*/, TDes8& /*aDigest */) |
|
127 { |
|
128 // Not used |
|
129 } |
|
130 |
|
131 void CRsaCertificateVerifyMsg::SetSignature( TDesC8& aSign ) |
|
132 { |
|
133 iRsaSignature.iMd5Sha.SetBody( aSign ); |
|
134 } |
|
135 |
|
136 void CRsaCertificateVerifyMsg::SetSignatureLength( TDesC8& aSign ) |
|
137 { |
|
138 iRsaSignature.iMd5Sha.Header().SetInitialValue( aSign.Length() ); |
|
139 } |
|
140 |
|
141 void CDsaCertificateVerifyMsg::SetSignature( TDesC8& aSign ) |
|
142 { |
|
143 iDsaSignature.iSha.SetBody( aSign ); |
|
144 } |
|
145 |
|
146 void CDsaCertificateVerifyMsg::SetSignatureLength( TDesC8& aSign ) |
|
147 { |
|
148 iDsaSignature.iSha.Header().SetInitialValue( aSign.Length() ) ; |
|
149 } |
|
150 |
|
151 |
|
152 CGenericExtension* CGenericExtension::NewLC(TInt aInitialLength) |
|
153 { |
|
154 CGenericExtension* self = new(ELeave) CGenericExtension(aInitialLength); |
|
155 CleanupStack::PushL(self); |
|
156 return self; |
|
157 } |
|
158 |
|
159 CGenericExtension::CGenericExtension( TInt aInitialLength ) : |
|
160 CExtensionNode(&iOpaqueData), |
|
161 iOpaqueData(KTlsExtensionLength, NULL, aInitialLength) |
|
162 { |
|
163 } |
|
164 |
|
165 CGenericExtension::~CGenericExtension() |
|
166 { |
|
167 } |
|
168 |
|
169 TInt CGenericExtension::ExtensionLength() |
|
170 { |
|
171 return CExtensionNode::ExtensionLength() + iOpaqueData.GetItemLength(); |
|
172 } |
|
173 |
|
174 CClientServerNameEntry* CClientServerNameEntry::NewLC(TInt aInitialLength) |
|
175 { |
|
176 CClientServerNameEntry* self = new(ELeave) CClientServerNameEntry(aInitialLength); |
|
177 CleanupStack::PushL(self); |
|
178 return self; |
|
179 } |
|
180 |
|
181 CClientServerNameEntry::CClientServerNameEntry( TInt aInitialLength ) : |
|
182 CConstItem(&iName, KTlsExtensionNameTypeLength), |
|
183 iName(KTlsExtensionLength, NULL, aInitialLength) |
|
184 { |
|
185 } |
|
186 |
|
187 CClientServerNameExtension* CClientServerNameExtension::NewLC() |
|
188 { |
|
189 CClientServerNameExtension* self = new(ELeave) CClientServerNameExtension(); |
|
190 self->ConstructOpaqueDataWrapperL(&self->iServerNames); |
|
191 CleanupStack::PushL(self); |
|
192 return self; |
|
193 } |
|
194 |
|
195 void CClientServerNameExtension::AddServerNameEntryL(CClientServerNameEntry *aServerNameEntry) |
|
196 /** |
|
197 Add server name entry to the list of server names and take ownership of it. |
|
198 */ |
|
199 { |
|
200 iServerNames.AddNodeL(aServerNameEntry); |
|
201 } |
|
202 |
|
203 CClientServerNameEntry* CClientServerNameExtension::Node(TInt aIndex) |
|
204 { |
|
205 return static_cast<CClientServerNameEntry*>(iServerNames.Node(aIndex)); |
|
206 } |
|
207 |
|
208 CClientServerNameExtension::CClientServerNameExtension() : |
|
209 CKnownExtensionNode(), |
|
210 iServerNames(NULL, KTlsExtensionLength) |
|
211 { |
|
212 } |
|
213 |