|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "tsrtpstreaminstatenormal.h" |
|
22 #include "msrtpstreamincontext.h" |
|
23 #include "msrtpcryptohandlercontext.h" |
|
24 #include "msrtpcryptohandlercontextrtp.h" |
|
25 #include "msrtpcryptohandlercontextrtcp.h" |
|
26 #include "srtputils.h" |
|
27 |
|
28 // ---------------------------------------------------------------------------- |
|
29 // TSRTPStreamInStateNormal::TSRTPStreamInStateNormal |
|
30 // ---------------------------------------------------------------------------- |
|
31 // |
|
32 TSRTPStreamInStateNormal::TSRTPStreamInStateNormal( |
|
33 MSRTPStreamInContext& aStreamContext, |
|
34 MSRTPCryptoHandlerContextRTP& aCryptoHandlerRTPContext, |
|
35 MSRTPCryptoHandlerContextRTCP& aCryptoHandlerRTCPContext) |
|
36 : TSRTPStreamInStateBase(aStreamContext, |
|
37 aCryptoHandlerRTPContext, |
|
38 aCryptoHandlerRTCPContext) |
|
39 { |
|
40 } |
|
41 |
|
42 // ---------------------------------------------------------------------------- |
|
43 // TSRTPStreamInStateNormal::DoUnprotectSrtpL |
|
44 // ---------------------------------------------------------------------------- |
|
45 // |
|
46 HBufC8* TSRTPStreamInStateNormal::DoUnprotectSrtpL(const TDesC8& aPacket) |
|
47 { |
|
48 SRTP_DEBUG_DETAIL( "TSRTPStreamInStateNormal::DoUnprotectSrtpL ENTRY" ); |
|
49 SRTP_DEBUG_TINT_VALUE( "Encrypted PacketLength is", aPacket.Length() ); |
|
50 |
|
51 // first initialize current encrypted RTP packet.. |
|
52 iCryptoHandlerRTPContext.InitializeEncryptedPacketL(aPacket); |
|
53 |
|
54 // Step 2 (in RFC 3711, section 3.3): |
|
55 // count the packet index i |
|
56 iCryptoHandlerRTPContext.CountReceiverPacketIndexL(); |
|
57 |
|
58 // check MKI if it is used |
|
59 iCryptoHandlerRTPContext.CheckMasterKeyIdentifierL(); |
|
60 |
|
61 // derive session keys.. |
|
62 if (iCryptoHandlerRTPContext.MasterKeysUpdated()) |
|
63 { |
|
64 iCryptoHandlerRTPContext.DeriveSessionKeysL(); |
|
65 } |
|
66 |
|
67 // do the replay protection |
|
68 iCryptoHandlerRTPContext.ReplayProtectionL(); |
|
69 |
|
70 // do the authentication (integrity check) |
|
71 iCryptoHandlerRTPContext.AuthenticateL(); |
|
72 |
|
73 // decrypt.. |
|
74 HBufC8* decryptedPacket = iCryptoHandlerRTPContext.DecryptL(); |
|
75 |
|
76 // Step 7, conditional update s_l and ROC values.. |
|
77 // (in RFC 3711, section 3.3): |
|
78 iCryptoHandlerRTPContext.Update_s_l_and_RocL(); |
|
79 iCryptoHandlerRTPContext.AddReplayIndex(); |
|
80 ///Should check the next Packet Index and decide if need to be re-key |
|
81 |
|
82 SRTP_DEBUG_TINT_VALUE( "the decrypted packet Length is", decryptedPacket->Length()); |
|
83 SRTP_DEBUG_DETAIL( "TSRTPStreamInStateNormal::DoUnprotectSrtpL EXIT" ); |
|
84 |
|
85 return decryptedPacket; |
|
86 |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // TSRTPStreamInStateNormal::DoUnprotectSrtcpL |
|
91 // ---------------------------------------------------------------------------- |
|
92 // |
|
93 HBufC8* TSRTPStreamInStateNormal::DoUnprotectSrtcpL(const TDesC8& aPacket) |
|
94 { |
|
95 |
|
96 // first initialize current encrypted RTP packet.. |
|
97 iCryptoHandlerRTCPContext.InitializeEncryptedPacketL(aPacket); |
|
98 |
|
99 //(in RFC 3711, section 3.4): |
|
100 // count the packet index i |
|
101 iCryptoHandlerRTCPContext.ReceiverPacketIndexL(); |
|
102 |
|
103 // check MKI if it is used |
|
104 iCryptoHandlerRTCPContext.CheckMasterKeyIdentifierL(); |
|
105 |
|
106 // derive session keys.. |
|
107 if (iCryptoHandlerRTCPContext.MasterKeysUpdated()) |
|
108 { |
|
109 iCryptoHandlerRTCPContext.DeriveSessionKeysL(); |
|
110 } |
|
111 |
|
112 // do the replay protection |
|
113 iCryptoHandlerRTCPContext.ReplayProtectionL(); |
|
114 |
|
115 // do the authentication (integrity check) |
|
116 iCryptoHandlerRTCPContext.AuthenticateL(); |
|
117 |
|
118 // decrypt.. |
|
119 HBufC8* decryptedPacket = iCryptoHandlerRTCPContext.DecryptL(); |
|
120 iCryptoHandlerRTCPContext.AddReplayIndex(); |
|
121 ///Should check the next Packet Index and decide if need to be re-key |
|
122 //Set updateKey needed and then lateron compared the key if the key is the same then ignore packet |
|
123 //implemented later |
|
124 // return decrypted RTCP packet |
|
125 return decryptedPacket; |
|
126 |
|
127 } |