|
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 #include "tsrtpstreamoutstateuninit.h" |
|
21 #include "msrtpstreamoutcontext.h" |
|
22 #include "msrtpcryptohandlercontext.h" |
|
23 #include "msrtpcryptohandlercontextrtp.h" |
|
24 #include "msrtpcryptohandlercontextrtcp.h" |
|
25 #include "srtputils.h" |
|
26 |
|
27 // ---------------------------------------------------------------------------- |
|
28 // TSRTPStreamOutStateUninit::TSRTPStreamOutStateUninit |
|
29 // ---------------------------------------------------------------------------- |
|
30 // |
|
31 TSRTPStreamOutStateUninit::TSRTPStreamOutStateUninit( |
|
32 MSRTPStreamOutContext& aStreamContext, |
|
33 MSRTPCryptoHandlerContextRTP& aCryptoHandlerRTPContext, |
|
34 MSRTPCryptoHandlerContextRTCP& aCryptoHandlerRTCPContext) |
|
35 : TSRTPStreamOutStateBase(aStreamContext, |
|
36 aCryptoHandlerRTPContext, |
|
37 aCryptoHandlerRTCPContext) |
|
38 { |
|
39 } |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // TSRTPStreamOutStateUninit::DoProtectRtpL |
|
43 // ---------------------------------------------------------------------------- |
|
44 // |
|
45 HBufC8* TSRTPStreamOutStateUninit::DoProtectRtpL(const TDesC8& aPacket) |
|
46 { |
|
47 SRTP_DEBUG_DETAIL( "TSRTPStreamOutStateUninit::DoProtectRtpL entry" ); |
|
48 SRTP_DEBUG_TINT_VALUE( "PacketLength is", aPacket.Length()); |
|
49 |
|
50 // first initialize current RTP packet.. |
|
51 iCryptoHandlerRTPContext.InitializePlainPacketL(aPacket); |
|
52 |
|
53 // Step 2 (in RFC 3711, section 3.3): |
|
54 // count the packet index i |
|
55 iCryptoHandlerRTPContext.CountSenderPacketIndexL(); |
|
56 |
|
57 SRTP_DEBUG_DETAIL( "StreamOutStateUninit, Protect, DeriveSessionKeysL" ); |
|
58 |
|
59 // derive session keys.. |
|
60 iCryptoHandlerRTPContext.DeriveSessionKeysL(); |
|
61 SRTP_DEBUG_DETAIL( "StreamOutStateUninit, Protect, Encrypt" ); |
|
62 // encrypt.. |
|
63 HBufC8* protectedPacket = iCryptoHandlerRTPContext.EncryptL(); |
|
64 |
|
65 // finally, conditional update of roll-over counter.. |
|
66 iCryptoHandlerRTPContext.UpdateROC(); |
|
67 |
|
68 |
|
69 // first RTP packet successfully encrypted.. |
|
70 // session keys derived etc.. |
|
71 // we can go to normal state |
|
72 SRTP_DEBUG_DETAIL( "ESRTPStreamOutNormal" ); |
|
73 |
|
74 iStreamContext.ChangeRTPState(MSRTPStreamOutContext::ESRTPStreamOutNormal); |
|
75 |
|
76 |
|
77 SRTP_DEBUG_TINT_VALUE("length of protectPacket", protectedPacket->Length() ); |
|
78 SRTP_DEBUG_DETAIL( "TSRTPStreamOutStateUninit::DoProtectRtpL exit" ); |
|
79 |
|
80 // return encrypted RTP packet |
|
81 return protectedPacket; |
|
82 } |
|
83 |
|
84 // ---------------------------------------------------------------------------- |
|
85 // TSRTPStreamOutStateUninit::DoProtectRtcpL |
|
86 // ---------------------------------------------------------------------------- |
|
87 // |
|
88 HBufC8* TSRTPStreamOutStateUninit::DoProtectRtcpL(const TDesC8& aPacket) |
|
89 { |
|
90 // first initialize current RTP packet.. |
|
91 iCryptoHandlerRTCPContext.InitializePlainPacketL(aPacket); |
|
92 |
|
93 // Step 2 (in RFC 3711, section 3.4): |
|
94 //Srtcp packet index must be set to zero before the first srtcp packet is sent |
|
95 iCryptoHandlerRTCPContext.InitialPacketIndex(); |
|
96 |
|
97 // derive session keys.. |
|
98 iCryptoHandlerRTCPContext.DeriveSessionKeysL(); |
|
99 |
|
100 // encrypt.. |
|
101 HBufC8* protectedPacket = iCryptoHandlerRTCPContext.EncryptL(); |
|
102 |
|
103 |
|
104 // first RTP packet successfully encrypted.. |
|
105 // session keys derived etc.. |
|
106 // we can go to normal state |
|
107 iStreamContext.ChangeRTCPState(MSRTPStreamOutContext::ESRTPStreamOutNormal); |
|
108 |
|
109 SRTP_DEBUG_TINT_VALUE("length of protect RTCP Packet", protectedPacket->Length() ); |
|
110 |
|
111 // return encrypted RTP packet |
|
112 return protectedPacket; |
|
113 } |
|
114 |