public void S1_Connection_Initialization_NegativeTest_InitialLossyConnection_RDPEncryption() { CheckPlatformCompatibility(TransportMode.Lossy); Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection, used RDP encryption"); StartRDPConnection(true); this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", TransportMode.Lossy); this.EstablishUDPConnection(TransportMode.Lossy, waitTime); this.TestSite.Log.Add(LogEntryKind.Comment, "Start DTLS handshake."); String certFile; PtfPropUtility.GetPtfPropertyValue(Site, "CertificatePath", out certFile); String certPwd; PtfPropUtility.GetPtfPropertyValue(Site, "CertificatePassword", out certPwd); X509Certificate2 cert = new X509Certificate2(certFile, certPwd); RdpeudpDTLSChannel sChannel = new RdpeudpDTLSChannel(rdpeudpSocketL); sChannel.AuthenticateAsServer(cert); this.TestSite.Log.Add(LogEntryKind.Comment, "Expect for Client Initiate Multitransport Error PDU to indicate Client drop RDP-UDP connection"); this.rdpbcgrAdapter.WaitForPacket <Client_Initiate_Multitransport_Response_PDU>(waitTime); if (requestIdList.Count == 1) { VerifyClientInitiateMultitransportResponsePDU(rdpbcgrAdapter.SessionContext.ClientInitiateMultitransportResponsePDU, requestIdList[0]); } }
/// <summary> /// Get the First valid UDP Source Packet. /// </summary> /// <param name="udpTransportMode"></param> /// <returns></returns> private RdpeudpPacket GetFirstValidUdpPacket(TransportMode udpTransportMode) { byte[] dataToSent = null; RdpeudpPacket firstPacket = null; String certFile; PtfPropUtility.GetPtfPropertyValue(Site, "CertificatePath", out certFile); String certPwd; PtfPropUtility.GetPtfPropertyValue(Site, "CertificatePassword", out certPwd); X509Certificate2 cert = new X509Certificate2(certFile, certPwd); if (udpTransportMode == TransportMode.Reliable) { RdpeudpTLSChannel secChannel = new RdpeudpTLSChannel(rdpeudpSocketR); secChannel.AuthenticateAsServer(cert); RdpeudpPacket packet = rdpeudpSocketR.ExpectPacket(waitTime); if (packet.payload != null) { rdpeudpSocketR.ProcessSourceData(packet); // Process Source Data to make sure ACK Vector created next is correct secChannel.ReceiveBytes(packet.payload); } dataToSent = secChannel.GetDataToSent(waitTime); // Make sure this test packet does not exceed upstream MTU. int maxPayloadsize = GetMaxiumPayloadSizeForSourcePacket(rdpeudpSocketR.UUpStreamMtu); dataToSent = dataToSent.Take(maxPayloadsize).ToArray(); firstPacket = rdpeudpSocketR.CreateSourcePacket(dataToSent); } else { RdpeudpDTLSChannel secChannel = new RdpeudpDTLSChannel(rdpeudpSocketL); secChannel.AuthenticateAsServer(cert); RdpeudpPacket packet = rdpeudpSocketL.ExpectPacket(waitTime); if (packet.payload != null) { rdpeudpSocketL.ProcessSourceData(packet); // Process Source Data to make sure ACK Vector created next is correct secChannel.ReceiveBytes(packet.payload); } dataToSent = secChannel.GetDataToSent(waitTime); // Make sure this test packet does not exceed upstream MTU. int maxPayloadsize = GetMaxiumPayloadSizeForSourcePacket(rdpeudpSocketL.UUpStreamMtu); dataToSent = dataToSent.Take(maxPayloadsize).ToArray(); firstPacket = rdpeudpSocketL.CreateSourcePacket(dataToSent); } return(firstPacket); }
/// <summary> /// Get the next valid rdpeudp packet. /// </summary> /// <param name="udpTransportMode">Transport mode: reliable or Lossy.</param> /// <returns>The next valid rdpeudp packet.</returns> private RdpeudpPacket GetNextValidUdpPacket(TransportMode udpTransportMode, byte[] data = null) { /*This function is used to get a valid rdpeudp packet. * Using rdpeudpSocket.LossPacket flag to control whether the socket send the packet. * First set rdpeudpSocket.LossPacket to true and send a tunnal Data, the socket will store the next packet(RDPEUDP socket which contains the encrypted tunnel data) and doesn't send it. * Then get the stored packet and return it. */ RdpemtServer rdpemtServer = rdpemtServerR; RdpeudpSocket rdpeudpSocket = rdpeudpSocketR; if (udpTransportMode == TransportMode.Lossy) { rdpemtServer = rdpemtServerL; rdpeudpSocket = rdpeudpSocketL; } if (data == null) { data = new byte[1000]; } RDP_TUNNEL_DATA tunnelData = rdpemtServer.CreateTunnelDataPdu(data, null); byte[] unEncryptData = PduMarshaler.Marshal(tunnelData); byte[] encryptData = null; if (udpTransportMode == TransportMode.Reliable) { RdpeudpTLSChannel secChannel = rdpemtServer.SecureChannel as RdpeudpTLSChannel; encryptData = secChannel.Encrypt(unEncryptData); } else { RdpeudpDTLSChannel secChannel = rdpemtServer.SecureChannel as RdpeudpDTLSChannel; List <byte[]> encryptDataList = secChannel.Encrypt(unEncryptData); if (encryptDataList != null && encryptDataList.Count > 0) { encryptData = encryptDataList[0]; } } RdpeudpPacket packet = rdpeudpSocket.CreateSourcePacket(encryptData); return(packet); }
/// <summary> /// Get the First valid UDP Source Packet. /// </summary> /// <param name="udpTransportMode"></param> /// <returns></returns> private RdpeudpPacket GetFirstValidUdpPacket(TransportMode udpTransportMode) { byte[] dataToSent = null; RdpeudpPacket firstPacket = null; String certFile = this.Site.Properties["CertificatePath"]; String certPwd = this.Site.Properties["CertificatePassword"]; X509Certificate2 cert = new X509Certificate2(certFile, certPwd); if (udpTransportMode == TransportMode.Reliable) { RdpeudpTLSChannel secChannel = new RdpeudpTLSChannel(rdpeudpSocketR); secChannel.AuthenticateAsServer(cert); RdpeudpPacket packet = rdpeudpSocketR.ExpectPacket(waitTime); if (packet.payload != null) { rdpeudpSocketR.ProcessSourceData(packet); // Process Source Data to makesure ACK Vector created next is correct secChannel.ReceiveBytes(packet.payload); } dataToSent = secChannel.GetDataToSent(waitTime); firstPacket = rdpeudpSocketR.CreateSourcePacket(dataToSent); } else { RdpeudpDTLSChannel secChannel = new RdpeudpDTLSChannel(rdpeudpSocketL); secChannel.AuthenticateAsServer(cert); RdpeudpPacket packet = rdpeudpSocketL.ExpectPacket(waitTime); if (packet.payload != null) { rdpeudpSocketL.ProcessSourceData(packet); // Process Source Data to makesure ACK Vector created next is correct secChannel.ReceiveBytes(packet.payload); } dataToSent = secChannel.GetDataToSent(waitTime); firstPacket = rdpeudpSocketL.CreateSourcePacket(dataToSent); } return(firstPacket); }