Add files using upload-large-folder tool
Browse files- local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/about_page/about_phone.html +397 -0
- local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_about_page/about.html +410 -0
- local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar.html +49 -0
- local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar.html +49 -0
- local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar_phone.html +50 -0
- local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/help_page/touch_pointer_phone.html +30 -0
- local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable/separator_background.xml +19 -0
- local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/cpp/android_cliprdr.h +33 -0
- local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/cpp/android_event.h +75 -0
- local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/cpp/android_freerdp.c +1042 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/childsession.h +27 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/connection.c +2219 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/display.c +90 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/mcs.h +187 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/rdp.c +3100 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/rdstls.c +1046 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/settings.h +77 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/simd.h +40 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/transport.c +2114 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/CMakeLists.txt +13 -0
local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/about_page/about_phone.html
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
| 5 |
+
<title></title>
|
| 6 |
+
<meta name="" content=""/>
|
| 7 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
|
| 8 |
+
|
| 9 |
+
<link rel="stylesheet" type="text/css" href="../about.css">
|
| 10 |
+
</head>
|
| 11 |
+
<body lang="en-US" link="#0000ff" bgcolor="#e9ebf8" dir="ltr">
|
| 12 |
+
<div id="container" dir="ltr">
|
| 13 |
+
<h2 class="western"><br/>
|
| 14 |
+
<br/>
|
| 15 |
+
|
| 16 |
+
</h2>
|
| 17 |
+
<div id="introduction_headline" dir="ltr" style="background: #353639">
|
| 18 |
+
<h2 class="western"><font color="#ffffff">aFreeRDP <br/>
|
| 19 |
+
Remote
|
| 20 |
+
Desktop Client</font></h2>
|
| 21 |
+
</div>
|
| 22 |
+
<p><img src="../FreeRDP_Logo.png" name="Image1" align="bottom" width="25%" border="0"/>
|
| 23 |
+
|
| 24 |
+
</p>
|
| 25 |
+
<div id="introduction" dir="ltr" style="background: #ffffff">
|
| 26 |
+
<p><font color="#000000"><b>aFreeRDP</b> is an open source client
|
| 27 |
+
capable of natively using<br/>
|
| 28 |
+
Remote Desktop Protocol (RDP) in
|
| 29 |
+
order to remotely access your Windows desktop. </font>
|
| 30 |
+
</p>
|
| 31 |
+
</div>
|
| 32 |
+
<div id="article" dir="ltr" style="background: #ffffff">
|
| 33 |
+
<p style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 34 |
+
<br/>
|
| 35 |
+
<br/>
|
| 36 |
+
|
| 37 |
+
</p>
|
| 38 |
+
<div id="headline" dir="ltr" style="background: #353639">
|
| 39 |
+
<h3 class="western" align="center"
|
| 40 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 41 |
+
Version Information</h3>
|
| 42 |
+
</div>
|
| 43 |
+
<table cellpadding="3" cellspacing="1" align="center">
|
| 44 |
+
<tr>
|
| 45 |
+
<td style="border: none; padding: 0in">
|
| 46 |
+
<p><b>aFreeRDP</b> Version</p>
|
| 47 |
+
</td>
|
| 48 |
+
<td style="border: none; padding: 0in">
|
| 49 |
+
<p>%AFREERDP_VERSION%</p>
|
| 50 |
+
</td>
|
| 51 |
+
</tr>
|
| 52 |
+
<tr>
|
| 53 |
+
<td style="border: none; padding: 0in">
|
| 54 |
+
<p>System Version</p>
|
| 55 |
+
</td>
|
| 56 |
+
<td style="border: none; padding: 0in">
|
| 57 |
+
<p>%SYSTEM_VERSION%</p>
|
| 58 |
+
</td>
|
| 59 |
+
</tr>
|
| 60 |
+
<tr>
|
| 61 |
+
<td style="border: none; padding: 0in">
|
| 62 |
+
<p>Model</p>
|
| 63 |
+
</td>
|
| 64 |
+
<td style="border: none; padding: 0in">
|
| 65 |
+
<p>%DEVICE_MODEL%</p>
|
| 66 |
+
</td>
|
| 67 |
+
</tr>
|
| 68 |
+
</table>
|
| 69 |
+
<div id="Section1" dir="ltr" style="background: #353639">
|
| 70 |
+
<h3 class="western" align="center" style="margin-left: 0.1in; margin-right: 0.1in"><a
|
| 71 |
+
name="headline"></a>
|
| 72 |
+
Credits</h3>
|
| 73 |
+
</div>
|
| 74 |
+
<p style="margin-top: 0.1in; margin-bottom: 0.1in"><font
|
| 75 |
+
color="#000000"><b>aFreeRDP</b></font><font color="#000000">
|
| 76 |
+
is a part of <a href="http://www.freerdp.com/">FreeRDP</a> </font>
|
| 77 |
+
</p>
|
| 78 |
+
<div id="Section2" dir="ltr" style="background: #353639">
|
| 79 |
+
<h3 class="western" align="center"
|
| 80 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 81 |
+
<a name="headline1"></a>
|
| 82 |
+
Data protection</h3>
|
| 83 |
+
</div>
|
| 84 |
+
<p style="margin-top: 0.1in; margin-bottom: 0.1in"><font color="#000000">Details
|
| 85 |
+
about data collection and usage by <b>aFreeRDP</b> are available at</font></p>
|
| 86 |
+
<p><a href="http://www.freerdp.com/privacy">http://www.freerdp.com/privacy</a>
|
| 87 |
+
</p>
|
| 88 |
+
<div id="Section3" dir="ltr" style="background: #353639">
|
| 89 |
+
<h3 class="western" align="center"
|
| 90 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 91 |
+
<a name="headline2"></a>
|
| 92 |
+
Licenses</h3>
|
| 93 |
+
</div>
|
| 94 |
+
<div id="Section4" dir="ltr" style="background: #353639">
|
| 95 |
+
<h4 class="western" align="center"
|
| 96 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 97 |
+
<a name="headline3"></a>
|
| 98 |
+
<font color="#ffffff">aFreeRDP</font></h4>
|
| 99 |
+
</div>
|
| 100 |
+
<pre class="western">This program is free software;
|
| 101 |
+
|
| 102 |
+
you can redistribute it and/or modify it under the terms
|
| 103 |
+
|
| 104 |
+
of the Mozilla Public License, v. 2.0.
|
| 105 |
+
|
| 106 |
+
You can obtain an online version of the License from
|
| 107 |
+
|
| 108 |
+
<a href="http://mozilla.org/MPL/2.0/">http://mozilla.org/MPL/2.0/</a>.
|
| 109 |
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
| 110 |
+
|
| 111 |
+
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 112 |
+
A copy of the product's source code can be obtained from the FreeRDP GitHub repository at
|
| 113 |
+
|
| 114 |
+
<a href="https://github.com/FreeRDP/FreeRDP">https://github.com/FreeRDP/FreeRDP</a>.</pre>
|
| 115 |
+
<p style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 116 |
+
<br/>
|
| 117 |
+
<br/>
|
| 118 |
+
|
| 119 |
+
</p>
|
| 120 |
+
<div id="Section5" dir="ltr" style="background: #353639">
|
| 121 |
+
<h4 class="western" align="center"
|
| 122 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 123 |
+
<a name="headline4"></a>
|
| 124 |
+
FreeRDP</h4>
|
| 125 |
+
</div>
|
| 126 |
+
<pre class="western">Licensed under the Apache License, Version 2.0 (the "License");
|
| 127 |
+
|
| 128 |
+
you may not use this file except in compliance with the License.
|
| 129 |
+
|
| 130 |
+
You may obtain a copy of the License at
|
| 131 |
+
|
| 132 |
+
<a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>
|
| 133 |
+
Unless required by applicable law or agreed to in writing, software
|
| 134 |
+
|
| 135 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 136 |
+
|
| 137 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 138 |
+
|
| 139 |
+
See the License for the specific language governing permissions and
|
| 140 |
+
|
| 141 |
+
limitations under the License.
|
| 142 |
+
A copy of the product's source code can be obtained from the FreeRDP GitHub repository at
|
| 143 |
+
|
| 144 |
+
<a href="https://github.com/FreeRDP/FreeRDP">https://github.com/FreeRDP/FreeRDP</a>.</pre>
|
| 145 |
+
<div id="Section6" dir="ltr" style="background: #353639">
|
| 146 |
+
<h4 class="western" align="center"
|
| 147 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 148 |
+
<a name="headline5"></a>
|
| 149 |
+
OpenSSL</h4>
|
| 150 |
+
</div>
|
| 151 |
+
<pre class="western">LICENSE ISSUES
|
| 152 |
+
|
| 153 |
+
==============
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
The OpenSSL toolkit stays under a dual license, i.e. both the conditions of
|
| 157 |
+
|
| 158 |
+
the OpenSSL License and the original SSLeay license apply to the toolkit.
|
| 159 |
+
|
| 160 |
+
See below for the actual license texts.
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
OpenSSL License
|
| 164 |
+
|
| 165 |
+
---------------
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
/* ====================================================================
|
| 169 |
+
|
| 170 |
+
* Copyright (c) 1998-2016 The OpenSSL Project. All rights reserved.
|
| 171 |
+
|
| 172 |
+
*
|
| 173 |
+
|
| 174 |
+
* Redistribution and use in source and binary forms, with or without
|
| 175 |
+
|
| 176 |
+
* modification, are permitted provided that the following conditions
|
| 177 |
+
|
| 178 |
+
* are met:
|
| 179 |
+
|
| 180 |
+
*
|
| 181 |
+
|
| 182 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 183 |
+
|
| 184 |
+
* notice, this list of conditions and the following disclaimer.
|
| 185 |
+
|
| 186 |
+
*
|
| 187 |
+
|
| 188 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 189 |
+
|
| 190 |
+
* notice, this list of conditions and the following disclaimer in
|
| 191 |
+
|
| 192 |
+
* the documentation and/or other materials provided with the
|
| 193 |
+
|
| 194 |
+
* distribution.
|
| 195 |
+
|
| 196 |
+
*
|
| 197 |
+
|
| 198 |
+
* 3. All advertising materials mentioning features or use of this
|
| 199 |
+
|
| 200 |
+
* software must display the following acknowledgment:
|
| 201 |
+
|
| 202 |
+
* "This product includes software developed by the OpenSSL Project
|
| 203 |
+
|
| 204 |
+
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
| 205 |
+
|
| 206 |
+
*
|
| 207 |
+
|
| 208 |
+
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
| 209 |
+
|
| 210 |
+
* endorse or promote products derived from this software without
|
| 211 |
+
|
| 212 |
+
* prior written permission. For written permission, please contact
|
| 213 |
+
|
| 214 |
+
* [email protected].
|
| 215 |
+
|
| 216 |
+
*
|
| 217 |
+
|
| 218 |
+
* 5. Products derived from this software may not be called "OpenSSL"
|
| 219 |
+
|
| 220 |
+
* nor may "OpenSSL" appear in their names without prior written
|
| 221 |
+
|
| 222 |
+
* permission of the OpenSSL Project.
|
| 223 |
+
|
| 224 |
+
*
|
| 225 |
+
|
| 226 |
+
* 6. Redistributions of any form whatsoever must retain the following
|
| 227 |
+
|
| 228 |
+
* acknowledgment:
|
| 229 |
+
|
| 230 |
+
* "This product includes software developed by the OpenSSL Project
|
| 231 |
+
|
| 232 |
+
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
| 233 |
+
|
| 234 |
+
*
|
| 235 |
+
|
| 236 |
+
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
| 237 |
+
|
| 238 |
+
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 239 |
+
|
| 240 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 241 |
+
|
| 242 |
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
| 243 |
+
|
| 244 |
+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 245 |
+
|
| 246 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
| 247 |
+
|
| 248 |
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 249 |
+
|
| 250 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 251 |
+
|
| 252 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
| 253 |
+
|
| 254 |
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 255 |
+
|
| 256 |
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
| 257 |
+
|
| 258 |
+
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 259 |
+
|
| 260 |
+
* ====================================================================
|
| 261 |
+
|
| 262 |
+
*
|
| 263 |
+
|
| 264 |
+
* This product includes cryptographic software written by Eric Young
|
| 265 |
+
|
| 266 |
+
* ([email protected]). This product includes software written by Tim
|
| 267 |
+
|
| 268 |
+
* Hudson ([email protected]).
|
| 269 |
+
|
| 270 |
+
*
|
| 271 |
+
|
| 272 |
+
*/
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
Original SSLeay License
|
| 276 |
+
|
| 277 |
+
-----------------------
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
/* Copyright (C) 1995-1998 Eric Young ([email protected])
|
| 281 |
+
|
| 282 |
+
* All rights reserved.
|
| 283 |
+
|
| 284 |
+
*
|
| 285 |
+
|
| 286 |
+
* This package is an SSL implementation written
|
| 287 |
+
|
| 288 |
+
* by Eric Young ([email protected]).
|
| 289 |
+
|
| 290 |
+
* The implementation was written so as to conform with Netscapes SSL.
|
| 291 |
+
|
| 292 |
+
*
|
| 293 |
+
|
| 294 |
+
* This library is free for commercial and non-commercial use as long as
|
| 295 |
+
|
| 296 |
+
* the following conditions are adhered to. The following conditions
|
| 297 |
+
|
| 298 |
+
* apply to all code found in this distribution, be it the RC4, RSA,
|
| 299 |
+
|
| 300 |
+
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
| 301 |
+
|
| 302 |
+
* included with this distribution is covered by the same copyright terms
|
| 303 |
+
|
| 304 |
+
* except that the holder is Tim Hudson ([email protected]).
|
| 305 |
+
|
| 306 |
+
*
|
| 307 |
+
|
| 308 |
+
* Copyright remains Eric Young's, and as such any Copyright notices in
|
| 309 |
+
|
| 310 |
+
* the code are not to be removed.
|
| 311 |
+
|
| 312 |
+
* If this package is used in a product, Eric Young should be given attribution
|
| 313 |
+
|
| 314 |
+
* as the author of the parts of the library used.
|
| 315 |
+
|
| 316 |
+
* This can be in the form of a textual message at program startup or
|
| 317 |
+
|
| 318 |
+
* in documentation (online or textual) provided with the package.
|
| 319 |
+
|
| 320 |
+
*
|
| 321 |
+
|
| 322 |
+
* Redistribution and use in source and binary forms, with or without
|
| 323 |
+
|
| 324 |
+
* modification, are permitted provided that the following conditions
|
| 325 |
+
|
| 326 |
+
* are met:
|
| 327 |
+
|
| 328 |
+
* 1. Redistributions of source code must retain the copyright
|
| 329 |
+
|
| 330 |
+
* notice, this list of conditions and the following disclaimer.
|
| 331 |
+
|
| 332 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 333 |
+
|
| 334 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 335 |
+
|
| 336 |
+
* documentation and/or other materials provided with the distribution.
|
| 337 |
+
|
| 338 |
+
* 3. All advertising materials mentioning features or use of this software
|
| 339 |
+
|
| 340 |
+
* must display the following acknowledgement:
|
| 341 |
+
|
| 342 |
+
* "This product includes cryptographic software written by
|
| 343 |
+
|
| 344 |
+
* Eric Young ([email protected])"
|
| 345 |
+
|
| 346 |
+
* The word 'cryptographic' can be left out if the routines from the library
|
| 347 |
+
|
| 348 |
+
* being used are not cryptographic related :-).
|
| 349 |
+
|
| 350 |
+
* 4. If you include any Windows specific code (or a derivative thereof) from
|
| 351 |
+
|
| 352 |
+
* the apps directory (application code) you must include an acknowledgement:
|
| 353 |
+
|
| 354 |
+
* "This product includes software written by Tim Hudson ([email protected])"
|
| 355 |
+
|
| 356 |
+
*
|
| 357 |
+
|
| 358 |
+
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
| 359 |
+
|
| 360 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 361 |
+
|
| 362 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 363 |
+
|
| 364 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
| 365 |
+
|
| 366 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 367 |
+
|
| 368 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 369 |
+
|
| 370 |
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 371 |
+
|
| 372 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 373 |
+
|
| 374 |
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 375 |
+
|
| 376 |
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 377 |
+
|
| 378 |
+
* SUCH DAMAGE.
|
| 379 |
+
|
| 380 |
+
*
|
| 381 |
+
|
| 382 |
+
* The licence and distribution terms for any publicly available version or
|
| 383 |
+
|
| 384 |
+
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
| 385 |
+
|
| 386 |
+
* copied and put under another distribution licence
|
| 387 |
+
|
| 388 |
+
* [including the GNU Public Licence.]
|
| 389 |
+
|
| 390 |
+
*/
|
| 391 |
+
A copy of the product's source code can be obtained from the project page at
|
| 392 |
+
|
| 393 |
+
<a href="https://www.openssl.org/">https://www.openssl.org/</a>.</pre>
|
| 394 |
+
</div>
|
| 395 |
+
</div>
|
| 396 |
+
</body>
|
| 397 |
+
</html>
|
local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_about_page/about.html
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
| 5 |
+
<title></title>
|
| 6 |
+
<meta name="" content=""/>
|
| 7 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
|
| 8 |
+
|
| 9 |
+
<link rel="stylesheet" type="text/css" href="../about.css">
|
| 10 |
+
</head>
|
| 11 |
+
<body lang="de-AT" link="#0000ff" bgcolor="#e9ebf8" dir="ltr">
|
| 12 |
+
<div id="container" dir="ltr">
|
| 13 |
+
<p><br/>
|
| 14 |
+
<br/>
|
| 15 |
+
|
| 16 |
+
</p>
|
| 17 |
+
<div id="introduction_headline" dir="ltr" style="background: #353639">
|
| 18 |
+
<h2 class="western"><font color="#ffffff">aFreeRDP<br/>
|
| 19 |
+
Remote
|
| 20 |
+
Desktop Client</font>
|
| 21 |
+
</h2>
|
| 22 |
+
</div>
|
| 23 |
+
<div id="introduction" dir="ltr" style="background: #ffffff">
|
| 24 |
+
<p align="center"><font color="#000000"><img src="FreeRDP_Logo.png" name="FreeRDP-Logo"
|
| 25 |
+
align="top" hspace="6" vspace="6" width="10%"
|
| 26 |
+
border="0"/>
|
| 27 |
+
|
| 28 |
+
</font>
|
| 29 |
+
</p>
|
| 30 |
+
</div>
|
| 31 |
+
<div id="article" dir="ltr" style="background: #ffffff">
|
| 32 |
+
<p align="center"
|
| 33 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 34 |
+
<font color="#000000"><b>aFreeRDP</b> ist ein Open Source Programm
|
| 35 |
+
mit nativer Unterstützung des Remote Desktop Protocol (RDP)<br/>
|
| 36 |
+
um
|
| 37 |
+
einen entfernten Zugriff auf Windows Desktops zu ermöglichen. </font>
|
| 38 |
+
</p>
|
| 39 |
+
<div id="headline" dir="ltr" style="background: #353639">
|
| 40 |
+
<h3 class="western" align="center"
|
| 41 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 42 |
+
Versions Information</h3>
|
| 43 |
+
</div>
|
| 44 |
+
<table cellpadding="3" cellspacing="1" align="center">
|
| 45 |
+
<tr>
|
| 46 |
+
<td style="border: none; padding: 0in">
|
| 47 |
+
<p><b>aFreeRDP</b> Version</p>
|
| 48 |
+
</td>
|
| 49 |
+
<td style="border: none; padding: 0in">
|
| 50 |
+
<p>%AFREERDP_VERSION%</p>
|
| 51 |
+
</td>
|
| 52 |
+
</tr>
|
| 53 |
+
<tr>
|
| 54 |
+
<td style="border: none; padding: 0in">
|
| 55 |
+
<p>System Version</p>
|
| 56 |
+
</td>
|
| 57 |
+
<td style="border: none; padding: 0in">
|
| 58 |
+
<p>%SYSTEM_VERSION%</p>
|
| 59 |
+
</td>
|
| 60 |
+
</tr>
|
| 61 |
+
<tr>
|
| 62 |
+
<td style="border: none; padding: 0in">
|
| 63 |
+
<p>Model</p>
|
| 64 |
+
</td>
|
| 65 |
+
<td style="border: none; padding: 0in">
|
| 66 |
+
<p>%DEVICE_MODEL%</p>
|
| 67 |
+
</td>
|
| 68 |
+
</tr>
|
| 69 |
+
</table>
|
| 70 |
+
</div>
|
| 71 |
+
<div id="Section1" dir="ltr" style="background: #ffffff">
|
| 72 |
+
<p style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 73 |
+
<a name="article"></a>
|
| 74 |
+
<br/>
|
| 75 |
+
<br/>
|
| 76 |
+
|
| 77 |
+
</p>
|
| 78 |
+
<div id="Section2" dir="ltr" style="background: #353639">
|
| 79 |
+
<h3 class="western" align="center"
|
| 80 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 81 |
+
<a name="headline"></a>
|
| 82 |
+
Credits</h3>
|
| 83 |
+
</div>
|
| 84 |
+
<p style="margin-top: 0.1in; margin-bottom: 0.1in"><font
|
| 85 |
+
color="#000000"><b>aFreeRDP</b></font><font color="#000000">
|
| 86 |
+
ist ein Teil von <a href="http://www.freerdp.com/">FreeRDP</a> </font>
|
| 87 |
+
</p>
|
| 88 |
+
</div>
|
| 89 |
+
<div id="Section3" dir="ltr" style="background: #ffffff">
|
| 90 |
+
<p style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 91 |
+
<a name="article1"></a>
|
| 92 |
+
<br/>
|
| 93 |
+
<br/>
|
| 94 |
+
|
| 95 |
+
</p>
|
| 96 |
+
<div id="Section4" dir="ltr" style="background: #353639">
|
| 97 |
+
<h3 class="western" align="center"
|
| 98 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 99 |
+
<a name="headline1"></a>
|
| 100 |
+
Datenschutz</h3>
|
| 101 |
+
</div>
|
| 102 |
+
<p style="margin-top: 0.1in; margin-bottom: 0.1in"><font color="#000000">Details
|
| 103 |
+
zu den Daten die aFreeRDP sammelt und verarbeitet sind unter</font></p>
|
| 104 |
+
<p style="margin-top: 0.1in; margin-bottom: 0.1in"><font color="#000000"><a
|
| 105 |
+
href="http://www.freerdp.com/privacy">http://www.freerdp.com/privacy</a>
|
| 106 |
+
zu finden.</font></p>
|
| 107 |
+
<div id="Section5" dir="ltr" style="background: #353639">
|
| 108 |
+
<h3 class="western" align="center"
|
| 109 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 110 |
+
<a name="headline2"></a>
|
| 111 |
+
Lizenzen</h3>
|
| 112 |
+
</div>
|
| 113 |
+
<div id="Section6" dir="ltr" style="background: #353639">
|
| 114 |
+
<h4 class="western" align="center"
|
| 115 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 116 |
+
<a name="headline3"></a>
|
| 117 |
+
<font color="#000000">aFreeRDP</font></h4>
|
| 118 |
+
</div>
|
| 119 |
+
<pre class="western">This program is free software;
|
| 120 |
+
|
| 121 |
+
you can redistribute it and/or modify it under the terms
|
| 122 |
+
|
| 123 |
+
of the Mozilla Public License, v. 2.0.
|
| 124 |
+
|
| 125 |
+
You can obtain an online version of the License from
|
| 126 |
+
|
| 127 |
+
<a href="http://mozilla.org/MPL/2.0/">http://mozilla.org/MPL/2.0/</a>.
|
| 128 |
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
| 129 |
+
|
| 130 |
+
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 131 |
+
A copy of the product's source code can be obtained from the FreeRDP GitHub repository at
|
| 132 |
+
|
| 133 |
+
<a href="https://github.com/FreeRDP/FreeRDP">https://github.com/FreeRDP/FreeRDP</a>.</pre>
|
| 134 |
+
<div id="Section7" dir="ltr" style="background: #353639">
|
| 135 |
+
<h4 class="western" align="center"
|
| 136 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 137 |
+
<a name="headline4"></a>
|
| 138 |
+
FreeRDP</h4>
|
| 139 |
+
</div>
|
| 140 |
+
<pre class="western">Licensed under the Apache License, Version 2.0 (the "License");
|
| 141 |
+
|
| 142 |
+
you may not use this file except in compliance with the License.
|
| 143 |
+
|
| 144 |
+
You may obtain a copy of the License at
|
| 145 |
+
<a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>
|
| 146 |
+
Unless required by applicable law or agreed to in writing, software
|
| 147 |
+
|
| 148 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 149 |
+
|
| 150 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 151 |
+
|
| 152 |
+
See the License for the specific language governing permissions and
|
| 153 |
+
|
| 154 |
+
limitations under the License.
|
| 155 |
+
A copy of the product's source code can be obtained from the FreeRDP GitHub repository at
|
| 156 |
+
|
| 157 |
+
<a href="https://github.com/FreeRDP/FreeRDP">https://github.com/FreeRDP/FreeRDP</a>.</pre>
|
| 158 |
+
<div id="Section8" dir="ltr" style="background: #353639">
|
| 159 |
+
<h4 class="western" align="center"
|
| 160 |
+
style="margin-left: 0.1in; margin-right: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in">
|
| 161 |
+
<a name="headline5"></a>
|
| 162 |
+
OpenSSL</h4>
|
| 163 |
+
</div>
|
| 164 |
+
<pre class="western">LICENSE ISSUES
|
| 165 |
+
|
| 166 |
+
==============
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
The OpenSSL toolkit stays under a dual license, i.e. both the conditions of
|
| 170 |
+
|
| 171 |
+
the OpenSSL License and the original SSLeay license apply to the toolkit.
|
| 172 |
+
|
| 173 |
+
See below for the actual license texts.
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
OpenSSL License
|
| 177 |
+
|
| 178 |
+
---------------
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
/* ====================================================================
|
| 182 |
+
|
| 183 |
+
* Copyright (c) 1998-2016 The OpenSSL Project. All rights reserved.
|
| 184 |
+
|
| 185 |
+
*
|
| 186 |
+
|
| 187 |
+
* Redistribution and use in source and binary forms, with or without
|
| 188 |
+
|
| 189 |
+
* modification, are permitted provided that the following conditions
|
| 190 |
+
|
| 191 |
+
* are met:
|
| 192 |
+
|
| 193 |
+
*
|
| 194 |
+
|
| 195 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 196 |
+
|
| 197 |
+
* notice, this list of conditions and the following disclaimer.
|
| 198 |
+
|
| 199 |
+
*
|
| 200 |
+
|
| 201 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 202 |
+
|
| 203 |
+
* notice, this list of conditions and the following disclaimer in
|
| 204 |
+
|
| 205 |
+
* the documentation and/or other materials provided with the
|
| 206 |
+
|
| 207 |
+
* distribution.
|
| 208 |
+
|
| 209 |
+
*
|
| 210 |
+
|
| 211 |
+
* 3. All advertising materials mentioning features or use of this
|
| 212 |
+
|
| 213 |
+
* software must display the following acknowledgment:
|
| 214 |
+
|
| 215 |
+
* "This product includes software developed by the OpenSSL Project
|
| 216 |
+
|
| 217 |
+
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
| 218 |
+
|
| 219 |
+
*
|
| 220 |
+
|
| 221 |
+
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
| 222 |
+
|
| 223 |
+
* endorse or promote products derived from this software without
|
| 224 |
+
|
| 225 |
+
* prior written permission. For written permission, please contact
|
| 226 |
+
|
| 227 |
+
* [email protected].
|
| 228 |
+
|
| 229 |
+
*
|
| 230 |
+
|
| 231 |
+
* 5. Products derived from this software may not be called "OpenSSL"
|
| 232 |
+
|
| 233 |
+
* nor may "OpenSSL" appear in their names without prior written
|
| 234 |
+
|
| 235 |
+
* permission of the OpenSSL Project.
|
| 236 |
+
|
| 237 |
+
*
|
| 238 |
+
|
| 239 |
+
* 6. Redistributions of any form whatsoever must retain the following
|
| 240 |
+
|
| 241 |
+
* acknowledgment:
|
| 242 |
+
|
| 243 |
+
* "This product includes software developed by the OpenSSL Project
|
| 244 |
+
|
| 245 |
+
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
| 246 |
+
|
| 247 |
+
*
|
| 248 |
+
|
| 249 |
+
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
| 250 |
+
|
| 251 |
+
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 252 |
+
|
| 253 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 254 |
+
|
| 255 |
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
| 256 |
+
|
| 257 |
+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 258 |
+
|
| 259 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
| 260 |
+
|
| 261 |
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 262 |
+
|
| 263 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 264 |
+
|
| 265 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
| 266 |
+
|
| 267 |
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 268 |
+
|
| 269 |
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
| 270 |
+
|
| 271 |
+
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 272 |
+
|
| 273 |
+
* ====================================================================
|
| 274 |
+
|
| 275 |
+
*
|
| 276 |
+
|
| 277 |
+
* This product includes cryptographic software written by Eric Young
|
| 278 |
+
|
| 279 |
+
* ([email protected]). This product includes software written by Tim
|
| 280 |
+
|
| 281 |
+
* Hudson ([email protected]).
|
| 282 |
+
|
| 283 |
+
*
|
| 284 |
+
|
| 285 |
+
*/
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
Original SSLeay License
|
| 289 |
+
|
| 290 |
+
-----------------------
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
/* Copyright (C) 1995-1998 Eric Young ([email protected])
|
| 294 |
+
|
| 295 |
+
* All rights reserved.
|
| 296 |
+
|
| 297 |
+
*
|
| 298 |
+
|
| 299 |
+
* This package is an SSL implementation written
|
| 300 |
+
|
| 301 |
+
* by Eric Young ([email protected]).
|
| 302 |
+
|
| 303 |
+
* The implementation was written so as to conform with Netscapes SSL.
|
| 304 |
+
|
| 305 |
+
*
|
| 306 |
+
|
| 307 |
+
* This library is free for commercial and non-commercial use as long as
|
| 308 |
+
|
| 309 |
+
* the following conditions are aheared to. The following conditions
|
| 310 |
+
|
| 311 |
+
* apply to all code found in this distribution, be it the RC4, RSA,
|
| 312 |
+
|
| 313 |
+
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
| 314 |
+
|
| 315 |
+
* included with this distribution is covered by the same copyright terms
|
| 316 |
+
|
| 317 |
+
* except that the holder is Tim Hudson ([email protected]).
|
| 318 |
+
|
| 319 |
+
*
|
| 320 |
+
|
| 321 |
+
* Copyright remains Eric Young's, and as such any Copyright notices in
|
| 322 |
+
|
| 323 |
+
* the code are not to be removed.
|
| 324 |
+
|
| 325 |
+
* If this package is used in a product, Eric Young should be given attribution
|
| 326 |
+
|
| 327 |
+
* as the author of the parts of the library used.
|
| 328 |
+
|
| 329 |
+
* This can be in the form of a textual message at program startup or
|
| 330 |
+
|
| 331 |
+
* in documentation (online or textual) provided with the package.
|
| 332 |
+
|
| 333 |
+
*
|
| 334 |
+
|
| 335 |
+
* Redistribution and use in source and binary forms, with or without
|
| 336 |
+
|
| 337 |
+
* modification, are permitted provided that the following conditions
|
| 338 |
+
|
| 339 |
+
* are met:
|
| 340 |
+
|
| 341 |
+
* 1. Redistributions of source code must retain the copyright
|
| 342 |
+
|
| 343 |
+
* notice, this list of conditions and the following disclaimer.
|
| 344 |
+
|
| 345 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 346 |
+
|
| 347 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 348 |
+
|
| 349 |
+
* documentation and/or other materials provided with the distribution.
|
| 350 |
+
|
| 351 |
+
* 3. All advertising materials mentioning features or use of this software
|
| 352 |
+
|
| 353 |
+
* must display the following acknowledgement:
|
| 354 |
+
|
| 355 |
+
* "This product includes cryptographic software written by
|
| 356 |
+
|
| 357 |
+
* Eric Young ([email protected])"
|
| 358 |
+
|
| 359 |
+
* The word 'cryptographic' can be left out if the rouines from the library
|
| 360 |
+
|
| 361 |
+
* being used are not cryptographic related :-).
|
| 362 |
+
|
| 363 |
+
* 4. If you include any Windows specific code (or a derivative thereof) from
|
| 364 |
+
|
| 365 |
+
* the apps directory (application code) you must include an acknowledgement:
|
| 366 |
+
|
| 367 |
+
* "This product includes software written by Tim Hudson ([email protected])"
|
| 368 |
+
|
| 369 |
+
*
|
| 370 |
+
|
| 371 |
+
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
| 372 |
+
|
| 373 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 374 |
+
|
| 375 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 376 |
+
|
| 377 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
| 378 |
+
|
| 379 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 380 |
+
|
| 381 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 382 |
+
|
| 383 |
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 384 |
+
|
| 385 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 386 |
+
|
| 387 |
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 388 |
+
|
| 389 |
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 390 |
+
|
| 391 |
+
* SUCH DAMAGE.
|
| 392 |
+
|
| 393 |
+
*
|
| 394 |
+
|
| 395 |
+
* The licence and distribution terms for any publically available version or
|
| 396 |
+
|
| 397 |
+
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
| 398 |
+
|
| 399 |
+
* copied and put under another distribution licence
|
| 400 |
+
|
| 401 |
+
* [including the GNU Public Licence.]
|
| 402 |
+
|
| 403 |
+
*/
|
| 404 |
+
A copy of the product's source code can be obtained from the project page at
|
| 405 |
+
|
| 406 |
+
<a href="https://www.openssl.org/">https://www.openssl.org/</a>.</pre>
|
| 407 |
+
</div>
|
| 408 |
+
</div>
|
| 409 |
+
</body>
|
| 410 |
+
</html>
|
local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar.html
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
| 2 |
+
|
| 3 |
+
<html>
|
| 4 |
+
|
| 5 |
+
<head>
|
| 6 |
+
<meta charset="utf-8">
|
| 7 |
+
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
|
| 8 |
+
<title>Help</title>
|
| 9 |
+
|
| 10 |
+
<link rel="stylesheet" type="text/css" href="../help.css">
|
| 11 |
+
</head>
|
| 12 |
+
|
| 13 |
+
<body>
|
| 14 |
+
<div id="container">
|
| 15 |
+
<center>
|
| 16 |
+
<div id="header">
|
| 17 |
+
<a href="gestures.html"><img src="nav_gestures.png"></a>
|
| 18 |
+
<a href="toolbar.html"><img src="nav_toolbar.png"></a>
|
| 19 |
+
<a href="touch_pointer.html"><img src="nav_touch_pointer.png"></a>
|
| 20 |
+
</div>
|
| 21 |
+
|
| 22 |
+
<div id="content">
|
| 23 |
+
<h1>Toolbar</h1>
|
| 24 |
+
<p>
|
| 25 |
+
With the toolbar you'll be able to display and hide the main tools in your session.
|
| 26 |
+
This allows together with the touch pointer and the gestures an intuitiv workflow
|
| 27 |
+
for remote computing on touch sensitive screens.
|
| 28 |
+
</p>
|
| 29 |
+
<p><img src="toolbar.png"></p>
|
| 30 |
+
|
| 31 |
+
<div id="article">
|
| 32 |
+
<div id="headline">
|
| 33 |
+
<h3><span style="color:white">Tastatur</span></h3></div>
|
| 34 |
+
Zeige/verstecke die standard und die erweiterte Tastatur mit Funktionstasten
|
| 35 |
+
</div>
|
| 36 |
+
<div id="article">
|
| 37 |
+
<div id="headline"><h3><span style="color:white">Touch Zeiger</span></h3></div>
|
| 38 |
+
Zeige/verstecke den gesten gesteuerten Zeiger
|
| 39 |
+
</div>
|
| 40 |
+
<div id="article">
|
| 41 |
+
<div id="headline"><h3><span style="color:white">Beenden</span></h3></div>
|
| 42 |
+
Beende die aktuelle Sitzung. Seihen sie sich bewusst, dass das Beenden kein Logout
|
| 43 |
+
ist.
|
| 44 |
+
</div>
|
| 45 |
+
</div>
|
| 46 |
+
</center>
|
| 47 |
+
</div>
|
| 48 |
+
</body>
|
| 49 |
+
</html>
|
local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar.html
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
| 2 |
+
|
| 3 |
+
<html>
|
| 4 |
+
|
| 5 |
+
<head>
|
| 6 |
+
<meta charset="utf-8">
|
| 7 |
+
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
|
| 8 |
+
<title>Help</title>
|
| 9 |
+
|
| 10 |
+
<link rel="stylesheet" type="text/css" href="../help.css">
|
| 11 |
+
</head>
|
| 12 |
+
|
| 13 |
+
<body>
|
| 14 |
+
<div id="container">
|
| 15 |
+
<center>
|
| 16 |
+
<div id="header">
|
| 17 |
+
<a href="gestures.html"><img src="nav_gestures.png"></a>
|
| 18 |
+
<a href="toolbar.html"><img src="nav_toolbar.png"></a>
|
| 19 |
+
<a href="touch_pointer.html"><img src="nav_touch_pointer.png"></a>
|
| 20 |
+
</div>
|
| 21 |
+
|
| 22 |
+
<div id="content">
|
| 23 |
+
<h1>Toolbar</h1>
|
| 24 |
+
<p>
|
| 25 |
+
With the toolbar you'll be able to display and hide the main tools in your session.
|
| 26 |
+
This allows together with the touch pointer and the gestures an intuitiv workflow
|
| 27 |
+
for remote computing on touch sensitive screens.
|
| 28 |
+
</p>
|
| 29 |
+
<p><img src="toolbar.png"></p>
|
| 30 |
+
|
| 31 |
+
<div id="article">
|
| 32 |
+
<div id="headline">
|
| 33 |
+
<h3><span style="color:white">Keyboards</span></h3></div>
|
| 34 |
+
Display/hide the default keyboard as well as an extended keyboard with function keys
|
| 35 |
+
</div>
|
| 36 |
+
<div id="article">
|
| 37 |
+
<div id="headline"><h3><span style="color:white">Touch Pointer</span></h3></div>
|
| 38 |
+
Display/hide the gesture controlled cursor
|
| 39 |
+
</div>
|
| 40 |
+
<div id="article">
|
| 41 |
+
<div id="headline"><h3><span style="color:white">Disconnect</span></h3></div>
|
| 42 |
+
Disconnect your current session. Please be aware that a disconnect is not the same
|
| 43 |
+
as a log out.
|
| 44 |
+
</div>
|
| 45 |
+
</div>
|
| 46 |
+
</center>
|
| 47 |
+
</div>
|
| 48 |
+
</body>
|
| 49 |
+
</html>
|
local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar_phone.html
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
| 2 |
+
|
| 3 |
+
<html>
|
| 4 |
+
|
| 5 |
+
<head>
|
| 6 |
+
<meta charset="utf-8">
|
| 7 |
+
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
|
| 8 |
+
<title>Help</title>
|
| 9 |
+
|
| 10 |
+
<link rel="stylesheet" type="text/css" href="../help-phone.css">
|
| 11 |
+
</head>
|
| 12 |
+
|
| 13 |
+
<body>
|
| 14 |
+
<div id="container">
|
| 15 |
+
<center>
|
| 16 |
+
<div id="header">
|
| 17 |
+
<a href="gestures_phone.html"><img src="nav_gestures.png" height="90%"></a>
|
| 18 |
+
<a href="toolbar_phone.html"><img src="nav_toolbar.png" height="90%"></a>
|
| 19 |
+
<a href="touch_pointer_phone.html"><img src="nav_touch_pointer.png" height="90%""></a>
|
| 20 |
+
</div>
|
| 21 |
+
|
| 22 |
+
<div id="content">
|
| 23 |
+
<h2>Toolbar</h2>
|
| 24 |
+
<p>
|
| 25 |
+
With the toolbar you'll be able to display and hide the main tools in your session.
|
| 26 |
+
This allows together with the touch pointer and the gestures an intuitiv workflow
|
| 27 |
+
for remote computing on touch sensitive screens.
|
| 28 |
+
</p>
|
| 29 |
+
<p><img src="toolbar_phone.png"></p>
|
| 30 |
+
|
| 31 |
+
<div id="article">
|
| 32 |
+
<div id="headline">
|
| 33 |
+
<h4><span style="color:white">Keyboards</h4></span></div>
|
| 34 |
+
Display/hide the default keyboard as well as an extended keyboard with function keys
|
| 35 |
+
</div>
|
| 36 |
+
<div id="article">
|
| 37 |
+
<div id="headline"><h4><span style="color:white">Touch Pointer</h4></div>
|
| 38 |
+
Display/hide the gesture controlled cursor
|
| 39 |
+
</div>
|
| 40 |
+
</span>
|
| 41 |
+
<div id="article">
|
| 42 |
+
<div id="headline"><h4><span style="color:white">Disconnect</span></h4></div>
|
| 43 |
+
Disconnect your current session. Please be aware that a disconnect is not the same
|
| 44 |
+
as a log out.
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
</center>
|
| 48 |
+
</div>
|
| 49 |
+
</body>
|
| 50 |
+
</html>
|
local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/help_page/touch_pointer_phone.html
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
| 2 |
+
|
| 3 |
+
<html>
|
| 4 |
+
|
| 5 |
+
<head>
|
| 6 |
+
<meta charset="utf-8">
|
| 7 |
+
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
|
| 8 |
+
<title>Help</title>
|
| 9 |
+
|
| 10 |
+
<link rel="stylesheet" type="text/css" href="../help-phone.css">
|
| 11 |
+
</head>
|
| 12 |
+
|
| 13 |
+
<body>
|
| 14 |
+
<div id="container">
|
| 15 |
+
<center>
|
| 16 |
+
<div id="header">
|
| 17 |
+
<a href="gestures_phone.html"><img src="nav_gestures.png" height="90%"></a>
|
| 18 |
+
<a href="toolbar_phone.html"><img src="nav_toolbar.png" height="90%"></a>
|
| 19 |
+
<a href="touch_pointer_phone.html"><img src="nav_touch_pointer.png" height="90%""></a>
|
| 20 |
+
</div>
|
| 21 |
+
|
| 22 |
+
<div id="content">
|
| 23 |
+
<h2>Touch Pointer</h2>
|
| 24 |
+
<p><img src="touch_pointer_phone.png">
|
| 25 |
+
</p>
|
| 26 |
+
</div>
|
| 27 |
+
</center>
|
| 28 |
+
</div>
|
| 29 |
+
</body>
|
| 30 |
+
</html>
|
local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable/separator_background.xml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="utf-8"?>
|
| 2 |
+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
| 3 |
+
|
| 4 |
+
<solid android:color="@color/separator_background_color" />
|
| 5 |
+
<stroke
|
| 6 |
+
android:width="1dp"
|
| 7 |
+
android:color="@color/separator_frame_color" />
|
| 8 |
+
<padding
|
| 9 |
+
android:bottom="1dp"
|
| 10 |
+
android:left="1dp"
|
| 11 |
+
android:right="1dp"
|
| 12 |
+
android:top="1dp" />
|
| 13 |
+
<!--
|
| 14 |
+
<color xmlns:android="http://schemas.android.com/apk/res/android"
|
| 15 |
+
android:color="#C2D6E6"
|
| 16 |
+
/>
|
| 17 |
+
-->
|
| 18 |
+
|
| 19 |
+
</shape>
|
local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/cpp/android_cliprdr.h
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Android Clipboard Redirection
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2013 Felix Long
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_CLIENT_ANDROID_CLIPRDR_H
|
| 21 |
+
#define FREERDP_CLIENT_ANDROID_CLIPRDR_H
|
| 22 |
+
|
| 23 |
+
#include <freerdp/client/cliprdr.h>
|
| 24 |
+
#include <freerdp/api.h>
|
| 25 |
+
|
| 26 |
+
#include "android_freerdp.h"
|
| 27 |
+
|
| 28 |
+
FREERDP_LOCAL UINT android_cliprdr_send_client_format_list(CliprdrClientContext* cliprdr);
|
| 29 |
+
|
| 30 |
+
FREERDP_LOCAL BOOL android_cliprdr_init(androidContext* afc, CliprdrClientContext* cliprdr);
|
| 31 |
+
FREERDP_LOCAL BOOL android_cliprdr_uninit(androidContext* afc, CliprdrClientContext* cliprdr);
|
| 32 |
+
|
| 33 |
+
#endif /* FREERDP_CLIENT_ANDROID_CLIPRDR_H */
|
local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/cpp/android_event.h
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Android Event System
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2010-2012 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
| 8 |
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
| 9 |
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
#ifndef FREERDP_CLIENT_ANDROID_EVENT_H
|
| 13 |
+
#define FREERDP_CLIENT_ANDROID_EVENT_H
|
| 14 |
+
#include <freerdp/freerdp.h>
|
| 15 |
+
#include <freerdp/api.h>
|
| 16 |
+
|
| 17 |
+
#define EVENT_TYPE_KEY 1
|
| 18 |
+
#define EVENT_TYPE_CURSOR 2
|
| 19 |
+
#define EVENT_TYPE_DISCONNECT 3
|
| 20 |
+
#define EVENT_TYPE_KEY_UNICODE 4
|
| 21 |
+
#define EVENT_TYPE_CLIPBOARD 5
|
| 22 |
+
|
| 23 |
+
typedef struct
|
| 24 |
+
{
|
| 25 |
+
int type;
|
| 26 |
+
} ANDROID_EVENT;
|
| 27 |
+
|
| 28 |
+
typedef struct
|
| 29 |
+
{
|
| 30 |
+
int type;
|
| 31 |
+
int flags;
|
| 32 |
+
UINT16 scancode;
|
| 33 |
+
} ANDROID_EVENT_KEY;
|
| 34 |
+
|
| 35 |
+
typedef struct
|
| 36 |
+
{
|
| 37 |
+
int type;
|
| 38 |
+
UINT16 flags;
|
| 39 |
+
UINT16 x;
|
| 40 |
+
UINT16 y;
|
| 41 |
+
} ANDROID_EVENT_CURSOR;
|
| 42 |
+
|
| 43 |
+
typedef struct
|
| 44 |
+
{
|
| 45 |
+
int type;
|
| 46 |
+
void* data;
|
| 47 |
+
int data_length;
|
| 48 |
+
} ANDROID_EVENT_CLIPBOARD;
|
| 49 |
+
|
| 50 |
+
typedef struct
|
| 51 |
+
{
|
| 52 |
+
int size;
|
| 53 |
+
int count;
|
| 54 |
+
HANDLE isSet;
|
| 55 |
+
ANDROID_EVENT** events;
|
| 56 |
+
} ANDROID_EVENT_QUEUE;
|
| 57 |
+
|
| 58 |
+
FREERDP_LOCAL BOOL android_push_event(freerdp* inst, ANDROID_EVENT* event);
|
| 59 |
+
|
| 60 |
+
FREERDP_LOCAL HANDLE android_get_handle(freerdp* inst);
|
| 61 |
+
FREERDP_LOCAL BOOL android_check_handle(freerdp* inst);
|
| 62 |
+
|
| 63 |
+
FREERDP_LOCAL ANDROID_EVENT_KEY* android_event_key_new(int flags, UINT16 scancode);
|
| 64 |
+
FREERDP_LOCAL ANDROID_EVENT_KEY* android_event_unicodekey_new(UINT16 flags, UINT16 key);
|
| 65 |
+
FREERDP_LOCAL ANDROID_EVENT_CURSOR* android_event_cursor_new(UINT16 flags, UINT16 x, UINT16 y);
|
| 66 |
+
FREERDP_LOCAL ANDROID_EVENT* android_event_disconnect_new(void);
|
| 67 |
+
FREERDP_LOCAL ANDROID_EVENT_CLIPBOARD* android_event_clipboard_new(const void* data,
|
| 68 |
+
size_t data_length);
|
| 69 |
+
|
| 70 |
+
FREERDP_LOCAL void android_event_free(ANDROID_EVENT* event);
|
| 71 |
+
|
| 72 |
+
FREERDP_LOCAL BOOL android_event_queue_init(freerdp* inst);
|
| 73 |
+
FREERDP_LOCAL void android_event_queue_uninit(freerdp* inst);
|
| 74 |
+
|
| 75 |
+
#endif /* FREERDP_CLIENT_ANDROID_EVENT_H */
|
local-test-freerdp-delta-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/cpp/android_freerdp.c
ADDED
|
@@ -0,0 +1,1042 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Android JNI Client Layer
|
| 3 |
+
|
| 4 |
+
Copyright 2010-2012 Marc-Andre Moreau <[email protected]>
|
| 5 |
+
Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
|
| 6 |
+
Copyright 2013 Thincast Technologies GmbH, Author: Armin Novak
|
| 7 |
+
Copyright 2015 Bernhard Miklautz <[email protected]>
|
| 8 |
+
Copyright 2016 Thincast Technologies GmbH
|
| 9 |
+
Copyright 2016 Armin Novak <[email protected]>
|
| 10 |
+
|
| 11 |
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
| 12 |
+
If a copy of the MPL was not distributed with this file, You can obtain one at
|
| 13 |
+
http://mozilla.org/MPL/2.0/.
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
#include <freerdp/config.h>
|
| 17 |
+
|
| 18 |
+
#include <locale.h>
|
| 19 |
+
|
| 20 |
+
#include <jni.h>
|
| 21 |
+
#include <stdio.h>
|
| 22 |
+
#include <stdlib.h>
|
| 23 |
+
#include <errno.h>
|
| 24 |
+
|
| 25 |
+
#include <winpr/assert.h>
|
| 26 |
+
|
| 27 |
+
#include <freerdp/graphics.h>
|
| 28 |
+
#include <freerdp/codec/rfx.h>
|
| 29 |
+
#include <freerdp/gdi/gdi.h>
|
| 30 |
+
#include <freerdp/gdi/gfx.h>
|
| 31 |
+
#include <freerdp/client/rdpei.h>
|
| 32 |
+
#include <freerdp/client/rdpgfx.h>
|
| 33 |
+
#include <freerdp/client/cliprdr.h>
|
| 34 |
+
#include <freerdp/codec/h264.h>
|
| 35 |
+
#include <freerdp/channels/channels.h>
|
| 36 |
+
#include <freerdp/client/channels.h>
|
| 37 |
+
#include <freerdp/client/cmdline.h>
|
| 38 |
+
#include <freerdp/constants.h>
|
| 39 |
+
#include <freerdp/locale/keyboard.h>
|
| 40 |
+
#include <freerdp/primitives.h>
|
| 41 |
+
#include <freerdp/version.h>
|
| 42 |
+
#include <freerdp/settings.h>
|
| 43 |
+
#include <freerdp/utils/signal.h>
|
| 44 |
+
|
| 45 |
+
#include <android/bitmap.h>
|
| 46 |
+
|
| 47 |
+
#include "android_jni_callback.h"
|
| 48 |
+
#include "android_jni_utils.h"
|
| 49 |
+
#include "android_cliprdr.h"
|
| 50 |
+
#include "android_freerdp_jni.h"
|
| 51 |
+
|
| 52 |
+
#if defined(WITH_GPROF)
|
| 53 |
+
#include "jni/prof.h"
|
| 54 |
+
#endif
|
| 55 |
+
|
| 56 |
+
#define TAG CLIENT_TAG("android")
|
| 57 |
+
|
| 58 |
+
/* Defines the JNI version supported by this library. */
|
| 59 |
+
#define FREERDP_JNI_VERSION FREERDP_VERSION_FULL
|
| 60 |
+
static void android_OnChannelConnectedEventHandler(void* context,
|
| 61 |
+
const ChannelConnectedEventArgs* e)
|
| 62 |
+
{
|
| 63 |
+
rdpSettings* settings;
|
| 64 |
+
androidContext* afc;
|
| 65 |
+
|
| 66 |
+
if (!context || !e)
|
| 67 |
+
{
|
| 68 |
+
WLog_FATAL(TAG, "(context=%p, EventArgs=%p", context, (void*)e);
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
afc = (androidContext*)context;
|
| 73 |
+
settings = afc->common.context.settings;
|
| 74 |
+
|
| 75 |
+
if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
|
| 76 |
+
{
|
| 77 |
+
android_cliprdr_init(afc, (CliprdrClientContext*)e->pInterface);
|
| 78 |
+
}
|
| 79 |
+
else
|
| 80 |
+
freerdp_client_OnChannelConnectedEventHandler(context, e);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
static void android_OnChannelDisconnectedEventHandler(void* context,
|
| 84 |
+
const ChannelDisconnectedEventArgs* e)
|
| 85 |
+
{
|
| 86 |
+
rdpSettings* settings;
|
| 87 |
+
androidContext* afc;
|
| 88 |
+
|
| 89 |
+
if (!context || !e)
|
| 90 |
+
{
|
| 91 |
+
WLog_FATAL(TAG, "(context=%p, EventArgs=%p", context, (void*)e);
|
| 92 |
+
return;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
afc = (androidContext*)context;
|
| 96 |
+
settings = afc->common.context.settings;
|
| 97 |
+
|
| 98 |
+
if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
|
| 99 |
+
{
|
| 100 |
+
android_cliprdr_uninit(afc, (CliprdrClientContext*)e->pInterface);
|
| 101 |
+
}
|
| 102 |
+
else
|
| 103 |
+
freerdp_client_OnChannelDisconnectedEventHandler(context, e);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
static BOOL android_begin_paint(rdpContext* context)
|
| 107 |
+
{
|
| 108 |
+
return TRUE;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
static BOOL android_end_paint(rdpContext* context)
|
| 112 |
+
{
|
| 113 |
+
HGDI_WND hwnd;
|
| 114 |
+
int ninvalid;
|
| 115 |
+
rdpGdi* gdi;
|
| 116 |
+
HGDI_RGN cinvalid;
|
| 117 |
+
int x1, y1, x2, y2;
|
| 118 |
+
androidContext* ctx = (androidContext*)context;
|
| 119 |
+
rdpSettings* settings;
|
| 120 |
+
|
| 121 |
+
if (!ctx || !context->instance)
|
| 122 |
+
return FALSE;
|
| 123 |
+
|
| 124 |
+
settings = context->settings;
|
| 125 |
+
|
| 126 |
+
if (!settings)
|
| 127 |
+
return FALSE;
|
| 128 |
+
|
| 129 |
+
gdi = context->gdi;
|
| 130 |
+
|
| 131 |
+
if (!gdi || !gdi->primary || !gdi->primary->hdc)
|
| 132 |
+
return FALSE;
|
| 133 |
+
|
| 134 |
+
hwnd = ctx->common.context.gdi->primary->hdc->hwnd;
|
| 135 |
+
|
| 136 |
+
if (!hwnd)
|
| 137 |
+
return FALSE;
|
| 138 |
+
|
| 139 |
+
ninvalid = hwnd->ninvalid;
|
| 140 |
+
|
| 141 |
+
if (ninvalid < 1)
|
| 142 |
+
return TRUE;
|
| 143 |
+
|
| 144 |
+
cinvalid = hwnd->cinvalid;
|
| 145 |
+
|
| 146 |
+
if (!cinvalid)
|
| 147 |
+
return FALSE;
|
| 148 |
+
|
| 149 |
+
x1 = cinvalid[0].x;
|
| 150 |
+
y1 = cinvalid[0].y;
|
| 151 |
+
x2 = cinvalid[0].x + cinvalid[0].w;
|
| 152 |
+
y2 = cinvalid[0].y + cinvalid[0].h;
|
| 153 |
+
|
| 154 |
+
for (int i = 0; i < ninvalid; i++)
|
| 155 |
+
{
|
| 156 |
+
x1 = MIN(x1, cinvalid[i].x);
|
| 157 |
+
y1 = MIN(y1, cinvalid[i].y);
|
| 158 |
+
x2 = MAX(x2, cinvalid[i].x + cinvalid[i].w);
|
| 159 |
+
y2 = MAX(y2, cinvalid[i].y + cinvalid[i].h);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
freerdp_callback("OnGraphicsUpdate", "(JIIII)V", (jlong)context->instance, x1, y1, x2 - x1,
|
| 163 |
+
y2 - y1);
|
| 164 |
+
|
| 165 |
+
hwnd->invalid->null = TRUE;
|
| 166 |
+
hwnd->ninvalid = 0;
|
| 167 |
+
return TRUE;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
static BOOL android_desktop_resize(rdpContext* context)
|
| 171 |
+
{
|
| 172 |
+
WINPR_ASSERT(context);
|
| 173 |
+
WINPR_ASSERT(context->settings);
|
| 174 |
+
WINPR_ASSERT(context->instance);
|
| 175 |
+
|
| 176 |
+
freerdp_callback("OnGraphicsResize", "(JIII)V", (jlong)context->instance,
|
| 177 |
+
freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth),
|
| 178 |
+
freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopHeight),
|
| 179 |
+
freerdp_settings_get_uint32(context->settings, FreeRDP_ColorDepth));
|
| 180 |
+
return TRUE;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
static BOOL android_pre_connect(freerdp* instance)
|
| 184 |
+
{
|
| 185 |
+
int rc;
|
| 186 |
+
rdpSettings* settings;
|
| 187 |
+
|
| 188 |
+
WINPR_ASSERT(instance);
|
| 189 |
+
WINPR_ASSERT(instance->context);
|
| 190 |
+
|
| 191 |
+
settings = instance->context->settings;
|
| 192 |
+
|
| 193 |
+
if (!settings)
|
| 194 |
+
return FALSE;
|
| 195 |
+
|
| 196 |
+
rc = PubSub_SubscribeChannelConnected(instance->context->pubSub,
|
| 197 |
+
android_OnChannelConnectedEventHandler);
|
| 198 |
+
|
| 199 |
+
if (rc != CHANNEL_RC_OK)
|
| 200 |
+
{
|
| 201 |
+
WLog_ERR(TAG, "Could not subscribe to connect event handler [%l08X]", rc);
|
| 202 |
+
return FALSE;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
rc = PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
|
| 206 |
+
android_OnChannelDisconnectedEventHandler);
|
| 207 |
+
|
| 208 |
+
if (rc != CHANNEL_RC_OK)
|
| 209 |
+
{
|
| 210 |
+
WLog_ERR(TAG, "Could not subscribe to disconnect event handler [%l08X]", rc);
|
| 211 |
+
return FALSE;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
freerdp_callback("OnPreConnect", "(J)V", (jlong)instance);
|
| 215 |
+
return TRUE;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
static BOOL android_Pointer_New(rdpContext* context, rdpPointer* pointer)
|
| 219 |
+
{
|
| 220 |
+
WINPR_ASSERT(context);
|
| 221 |
+
WINPR_ASSERT(pointer);
|
| 222 |
+
WINPR_ASSERT(context->gdi);
|
| 223 |
+
|
| 224 |
+
return TRUE;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
static void android_Pointer_Free(rdpContext* context, rdpPointer* pointer)
|
| 228 |
+
{
|
| 229 |
+
WINPR_ASSERT(context);
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
static BOOL android_Pointer_Set(rdpContext* context, rdpPointer* pointer)
|
| 233 |
+
{
|
| 234 |
+
WINPR_ASSERT(context);
|
| 235 |
+
WINPR_ASSERT(pointer);
|
| 236 |
+
|
| 237 |
+
return TRUE;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
static BOOL android_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
|
| 241 |
+
{
|
| 242 |
+
WINPR_ASSERT(context);
|
| 243 |
+
|
| 244 |
+
return TRUE;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
static BOOL android_Pointer_SetNull(rdpContext* context)
|
| 248 |
+
{
|
| 249 |
+
WINPR_ASSERT(context);
|
| 250 |
+
|
| 251 |
+
return TRUE;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
static BOOL android_Pointer_SetDefault(rdpContext* context)
|
| 255 |
+
{
|
| 256 |
+
WINPR_ASSERT(context);
|
| 257 |
+
|
| 258 |
+
return TRUE;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
static BOOL android_register_pointer(rdpGraphics* graphics)
|
| 262 |
+
{
|
| 263 |
+
rdpPointer pointer = { 0 };
|
| 264 |
+
|
| 265 |
+
if (!graphics)
|
| 266 |
+
return FALSE;
|
| 267 |
+
|
| 268 |
+
pointer.size = sizeof(pointer);
|
| 269 |
+
pointer.New = android_Pointer_New;
|
| 270 |
+
pointer.Free = android_Pointer_Free;
|
| 271 |
+
pointer.Set = android_Pointer_Set;
|
| 272 |
+
pointer.SetNull = android_Pointer_SetNull;
|
| 273 |
+
pointer.SetDefault = android_Pointer_SetDefault;
|
| 274 |
+
pointer.SetPosition = android_Pointer_SetPosition;
|
| 275 |
+
graphics_register_pointer(graphics, &pointer);
|
| 276 |
+
return TRUE;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
static BOOL android_post_connect(freerdp* instance)
|
| 280 |
+
{
|
| 281 |
+
rdpSettings* settings;
|
| 282 |
+
rdpUpdate* update;
|
| 283 |
+
|
| 284 |
+
WINPR_ASSERT(instance);
|
| 285 |
+
WINPR_ASSERT(instance->context);
|
| 286 |
+
|
| 287 |
+
update = instance->context->update;
|
| 288 |
+
WINPR_ASSERT(update);
|
| 289 |
+
|
| 290 |
+
settings = instance->context->settings;
|
| 291 |
+
WINPR_ASSERT(settings);
|
| 292 |
+
|
| 293 |
+
if (!gdi_init(instance, PIXEL_FORMAT_RGBX32))
|
| 294 |
+
return FALSE;
|
| 295 |
+
|
| 296 |
+
if (!android_register_pointer(instance->context->graphics))
|
| 297 |
+
return FALSE;
|
| 298 |
+
|
| 299 |
+
update->BeginPaint = android_begin_paint;
|
| 300 |
+
update->EndPaint = android_end_paint;
|
| 301 |
+
update->DesktopResize = android_desktop_resize;
|
| 302 |
+
freerdp_callback("OnSettingsChanged", "(JIII)V", (jlong)instance,
|
| 303 |
+
freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
|
| 304 |
+
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight),
|
| 305 |
+
freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth));
|
| 306 |
+
freerdp_callback("OnConnectionSuccess", "(J)V", (jlong)instance);
|
| 307 |
+
return TRUE;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
static void android_post_disconnect(freerdp* instance)
|
| 311 |
+
{
|
| 312 |
+
freerdp_callback("OnDisconnecting", "(J)V", (jlong)instance);
|
| 313 |
+
gdi_free(instance);
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
static BOOL android_authenticate_int(freerdp* instance, char** username, char** password,
|
| 317 |
+
char** domain, const char* cb_name)
|
| 318 |
+
{
|
| 319 |
+
JNIEnv* env;
|
| 320 |
+
jboolean attached = jni_attach_thread(&env);
|
| 321 |
+
jobject jstr1 = create_string_builder(env, *username);
|
| 322 |
+
jobject jstr2 = create_string_builder(env, *domain);
|
| 323 |
+
jobject jstr3 = create_string_builder(env, *password);
|
| 324 |
+
jboolean res;
|
| 325 |
+
res = freerdp_callback_bool_result(cb_name,
|
| 326 |
+
"(JLjava/lang/StringBuilder;"
|
| 327 |
+
"Ljava/lang/StringBuilder;"
|
| 328 |
+
"Ljava/lang/StringBuilder;)Z",
|
| 329 |
+
(jlong)instance, jstr1, jstr2, jstr3);
|
| 330 |
+
|
| 331 |
+
if (res == JNI_TRUE)
|
| 332 |
+
{
|
| 333 |
+
// read back string values
|
| 334 |
+
free(*username);
|
| 335 |
+
*username = get_string_from_string_builder(env, jstr1);
|
| 336 |
+
free(*domain);
|
| 337 |
+
*domain = get_string_from_string_builder(env, jstr2);
|
| 338 |
+
free(*password);
|
| 339 |
+
*password = get_string_from_string_builder(env, jstr3);
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
if (attached == JNI_TRUE)
|
| 343 |
+
jni_detach_thread();
|
| 344 |
+
|
| 345 |
+
return ((res == JNI_TRUE) ? TRUE : FALSE);
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
static BOOL android_authenticate(freerdp* instance, char** username, char** password, char** domain)
|
| 349 |
+
{
|
| 350 |
+
return android_authenticate_int(instance, username, password, domain, "OnAuthenticate");
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
static BOOL android_gw_authenticate(freerdp* instance, char** username, char** password,
|
| 354 |
+
char** domain)
|
| 355 |
+
{
|
| 356 |
+
return android_authenticate_int(instance, username, password, domain, "OnGatewayAuthenticate");
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
static DWORD android_verify_certificate_ex(freerdp* instance, const char* host, UINT16 port,
|
| 360 |
+
const char* common_name, const char* subject,
|
| 361 |
+
const char* issuer, const char* fingerprint, DWORD flags)
|
| 362 |
+
{
|
| 363 |
+
WLog_DBG(TAG, "Certificate details [%s:%" PRIu16 ":", host, port);
|
| 364 |
+
WLog_DBG(TAG, "\tSubject: %s", subject);
|
| 365 |
+
WLog_DBG(TAG, "\tIssuer: %s", issuer);
|
| 366 |
+
WLog_DBG(TAG, "\tThumbprint: %s", fingerprint);
|
| 367 |
+
WLog_DBG(TAG,
|
| 368 |
+
"The above X.509 certificate could not be verified, possibly because you do not have "
|
| 369 |
+
"the CA certificate in your certificate store, or the certificate has expired."
|
| 370 |
+
"Please look at the OpenSSL documentation on how to add a private CA to the store.\n");
|
| 371 |
+
JNIEnv* env;
|
| 372 |
+
jboolean attached = jni_attach_thread(&env);
|
| 373 |
+
jstring jstr0 = (*env)->NewStringUTF(env, host);
|
| 374 |
+
jstring jstr1 = (*env)->NewStringUTF(env, common_name);
|
| 375 |
+
jstring jstr2 = (*env)->NewStringUTF(env, subject);
|
| 376 |
+
jstring jstr3 = (*env)->NewStringUTF(env, issuer);
|
| 377 |
+
jstring jstr4 = (*env)->NewStringUTF(env, fingerprint);
|
| 378 |
+
jint res = freerdp_callback_int_result("OnVerifyCertificateEx",
|
| 379 |
+
"(JLjava/lang/String;JLjava/lang/String;Ljava/lang/"
|
| 380 |
+
"String;Ljava/lang/String;Ljava/lang/String;J)I",
|
| 381 |
+
(jlong)instance, jstr0, (jlong)port, jstr1, jstr2, jstr3,
|
| 382 |
+
jstr4, (jlong)flags);
|
| 383 |
+
|
| 384 |
+
if (attached == JNI_TRUE)
|
| 385 |
+
jni_detach_thread();
|
| 386 |
+
|
| 387 |
+
return res;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
static DWORD android_verify_changed_certificate_ex(freerdp* instance, const char* host, UINT16 port,
|
| 391 |
+
const char* common_name, const char* subject,
|
| 392 |
+
const char* issuer, const char* new_fingerprint,
|
| 393 |
+
const char* old_subject, const char* old_issuer,
|
| 394 |
+
const char* old_fingerprint, DWORD flags)
|
| 395 |
+
{
|
| 396 |
+
JNIEnv* env;
|
| 397 |
+
jboolean attached = jni_attach_thread(&env);
|
| 398 |
+
jstring jhost = (*env)->NewStringUTF(env, host);
|
| 399 |
+
jstring jstr0 = (*env)->NewStringUTF(env, common_name);
|
| 400 |
+
jstring jstr1 = (*env)->NewStringUTF(env, subject);
|
| 401 |
+
jstring jstr2 = (*env)->NewStringUTF(env, issuer);
|
| 402 |
+
jstring jstr3 = (*env)->NewStringUTF(env, new_fingerprint);
|
| 403 |
+
jstring jstr4 = (*env)->NewStringUTF(env, old_subject);
|
| 404 |
+
jstring jstr5 = (*env)->NewStringUTF(env, old_issuer);
|
| 405 |
+
jstring jstr6 = (*env)->NewStringUTF(env, old_fingerprint);
|
| 406 |
+
jint res =
|
| 407 |
+
freerdp_callback_int_result("OnVerifyChangedCertificateEx",
|
| 408 |
+
"(JLjava/lang/String;JLjava/lang/String;Ljava/lang/"
|
| 409 |
+
"String;Ljava/lang/String;Ljava/lang/String;"
|
| 410 |
+
"Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)I",
|
| 411 |
+
(jlong)instance, jhost, (jlong)port, jstr0, jstr1, jstr2, jstr3,
|
| 412 |
+
jstr4, jstr5, jstr6, (jlong)flags);
|
| 413 |
+
|
| 414 |
+
if (attached == JNI_TRUE)
|
| 415 |
+
jni_detach_thread();
|
| 416 |
+
|
| 417 |
+
return res;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
static int android_freerdp_run(freerdp* instance)
|
| 421 |
+
{
|
| 422 |
+
DWORD count;
|
| 423 |
+
DWORD status = WAIT_FAILED;
|
| 424 |
+
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
|
| 425 |
+
HANDLE inputEvent = NULL;
|
| 426 |
+
const rdpSettings* settings = instance->context->settings;
|
| 427 |
+
rdpContext* context = instance->context;
|
| 428 |
+
|
| 429 |
+
inputEvent = android_get_handle(instance);
|
| 430 |
+
|
| 431 |
+
while (!freerdp_shall_disconnect_context(instance->context))
|
| 432 |
+
{
|
| 433 |
+
DWORD tmp;
|
| 434 |
+
count = 0;
|
| 435 |
+
|
| 436 |
+
handles[count++] = inputEvent;
|
| 437 |
+
|
| 438 |
+
tmp = freerdp_get_event_handles(context, &handles[count], 64 - count);
|
| 439 |
+
|
| 440 |
+
if (tmp == 0)
|
| 441 |
+
{
|
| 442 |
+
WLog_ERR(TAG, "freerdp_get_event_handles failed");
|
| 443 |
+
break;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
count += tmp;
|
| 447 |
+
status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
|
| 448 |
+
|
| 449 |
+
if (status == WAIT_FAILED)
|
| 450 |
+
{
|
| 451 |
+
WLog_ERR(TAG, "WaitForMultipleObjects failed with %" PRIu32 " [%08lX]", status,
|
| 452 |
+
GetLastError());
|
| 453 |
+
break;
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
if (!freerdp_check_event_handles(context))
|
| 457 |
+
{
|
| 458 |
+
/* TODO: Auto reconnect
|
| 459 |
+
if (xf_auto_reconnect(instance))
|
| 460 |
+
continue;
|
| 461 |
+
*/
|
| 462 |
+
WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
|
| 463 |
+
status = GetLastError();
|
| 464 |
+
break;
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
if (freerdp_shall_disconnect_context(instance->context))
|
| 468 |
+
break;
|
| 469 |
+
|
| 470 |
+
if (android_check_handle(instance) != TRUE)
|
| 471 |
+
{
|
| 472 |
+
WLog_ERR(TAG, "Failed to check android file descriptor");
|
| 473 |
+
status = GetLastError();
|
| 474 |
+
break;
|
| 475 |
+
}
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
disconnect:
|
| 479 |
+
WLog_INFO(TAG, "Prepare shutdown...");
|
| 480 |
+
|
| 481 |
+
return status;
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
static DWORD WINAPI android_thread_func(LPVOID param)
|
| 485 |
+
{
|
| 486 |
+
DWORD status = ERROR_BAD_ARGUMENTS;
|
| 487 |
+
freerdp* instance = param;
|
| 488 |
+
WLog_DBG(TAG, "Start...");
|
| 489 |
+
|
| 490 |
+
WINPR_ASSERT(instance);
|
| 491 |
+
WINPR_ASSERT(instance->context);
|
| 492 |
+
|
| 493 |
+
if (freerdp_client_start(instance->context) != CHANNEL_RC_OK)
|
| 494 |
+
goto fail;
|
| 495 |
+
|
| 496 |
+
WLog_DBG(TAG, "Connect...");
|
| 497 |
+
|
| 498 |
+
if (!freerdp_connect(instance))
|
| 499 |
+
status = GetLastError();
|
| 500 |
+
else
|
| 501 |
+
{
|
| 502 |
+
status = android_freerdp_run(instance);
|
| 503 |
+
WLog_DBG(TAG, "Disconnect...");
|
| 504 |
+
|
| 505 |
+
if (!freerdp_disconnect(instance))
|
| 506 |
+
status = GetLastError();
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
WLog_DBG(TAG, "Stop...");
|
| 510 |
+
|
| 511 |
+
if (freerdp_client_stop(instance->context) != CHANNEL_RC_OK)
|
| 512 |
+
goto fail;
|
| 513 |
+
|
| 514 |
+
fail:
|
| 515 |
+
WLog_DBG(TAG, "Session ended with %08" PRIX32 "", status);
|
| 516 |
+
|
| 517 |
+
if (status == CHANNEL_RC_OK)
|
| 518 |
+
freerdp_callback("OnDisconnected", "(J)V", (jlong)instance);
|
| 519 |
+
else
|
| 520 |
+
freerdp_callback("OnConnectionFailure", "(J)V", (jlong)instance);
|
| 521 |
+
|
| 522 |
+
WLog_DBG(TAG, "Quit.");
|
| 523 |
+
ExitThread(status);
|
| 524 |
+
return status;
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
static BOOL android_client_new(freerdp* instance, rdpContext* context)
|
| 528 |
+
{
|
| 529 |
+
WINPR_ASSERT(instance);
|
| 530 |
+
WINPR_ASSERT(context);
|
| 531 |
+
|
| 532 |
+
if (!android_event_queue_init(instance))
|
| 533 |
+
return FALSE;
|
| 534 |
+
|
| 535 |
+
instance->PreConnect = android_pre_connect;
|
| 536 |
+
instance->PostConnect = android_post_connect;
|
| 537 |
+
instance->PostDisconnect = android_post_disconnect;
|
| 538 |
+
instance->Authenticate = android_authenticate;
|
| 539 |
+
instance->GatewayAuthenticate = android_gw_authenticate;
|
| 540 |
+
instance->VerifyCertificateEx = android_verify_certificate_ex;
|
| 541 |
+
instance->VerifyChangedCertificateEx = android_verify_changed_certificate_ex;
|
| 542 |
+
instance->LogonErrorInfo = NULL;
|
| 543 |
+
return TRUE;
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
static void android_client_free(freerdp* instance, rdpContext* context)
|
| 547 |
+
{
|
| 548 |
+
if (!context)
|
| 549 |
+
return;
|
| 550 |
+
|
| 551 |
+
android_event_queue_uninit(instance);
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
|
| 555 |
+
{
|
| 556 |
+
WINPR_ASSERT(pEntryPoints);
|
| 557 |
+
|
| 558 |
+
ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS));
|
| 559 |
+
|
| 560 |
+
pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
|
| 561 |
+
pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
|
| 562 |
+
pEntryPoints->GlobalInit = NULL;
|
| 563 |
+
pEntryPoints->GlobalUninit = NULL;
|
| 564 |
+
pEntryPoints->ContextSize = sizeof(androidContext);
|
| 565 |
+
pEntryPoints->ClientNew = android_client_new;
|
| 566 |
+
pEntryPoints->ClientFree = android_client_free;
|
| 567 |
+
pEntryPoints->ClientStart = NULL;
|
| 568 |
+
pEntryPoints->ClientStop = NULL;
|
| 569 |
+
return 0;
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
JNIEXPORT jlong JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1new(
|
| 573 |
+
JNIEnv* env, jclass cls, jobject context)
|
| 574 |
+
{
|
| 575 |
+
jclass contextClass;
|
| 576 |
+
jclass fileClass;
|
| 577 |
+
jobject filesDirObj;
|
| 578 |
+
jmethodID getFilesDirID;
|
| 579 |
+
jmethodID getAbsolutePathID;
|
| 580 |
+
jstring path;
|
| 581 |
+
const char* raw;
|
| 582 |
+
char* envStr;
|
| 583 |
+
RDP_CLIENT_ENTRY_POINTS clientEntryPoints;
|
| 584 |
+
rdpContext* ctx;
|
| 585 |
+
#if defined(WITH_GPROF)
|
| 586 |
+
setenv("CPUPROFILE_FREQUENCY", "200", 1);
|
| 587 |
+
monstartup("libfreerdp-android.so");
|
| 588 |
+
#endif
|
| 589 |
+
contextClass = (*env)->FindClass(env, JAVA_CONTEXT_CLASS);
|
| 590 |
+
fileClass = (*env)->FindClass(env, JAVA_FILE_CLASS);
|
| 591 |
+
|
| 592 |
+
if (!contextClass || !fileClass)
|
| 593 |
+
{
|
| 594 |
+
WLog_FATAL(TAG, "Failed to load class references %s=%p, %s=%p", JAVA_CONTEXT_CLASS,
|
| 595 |
+
(void*)contextClass, JAVA_FILE_CLASS, (void*)fileClass);
|
| 596 |
+
return (jlong)NULL;
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
getFilesDirID =
|
| 600 |
+
(*env)->GetMethodID(env, contextClass, "getFilesDir", "()L" JAVA_FILE_CLASS ";");
|
| 601 |
+
|
| 602 |
+
if (!getFilesDirID)
|
| 603 |
+
{
|
| 604 |
+
WLog_FATAL(TAG, "Failed to find method ID getFilesDir ()L" JAVA_FILE_CLASS ";");
|
| 605 |
+
return (jlong)NULL;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
getAbsolutePathID =
|
| 609 |
+
(*env)->GetMethodID(env, fileClass, "getAbsolutePath", "()Ljava/lang/String;");
|
| 610 |
+
|
| 611 |
+
if (!getAbsolutePathID)
|
| 612 |
+
{
|
| 613 |
+
WLog_FATAL(TAG, "Failed to find method ID getAbsolutePath ()Ljava/lang/String;");
|
| 614 |
+
return (jlong)NULL;
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
filesDirObj = (*env)->CallObjectMethod(env, context, getFilesDirID);
|
| 618 |
+
|
| 619 |
+
if (!filesDirObj)
|
| 620 |
+
{
|
| 621 |
+
WLog_FATAL(TAG, "Failed to call getFilesDir");
|
| 622 |
+
return (jlong)NULL;
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
path = (*env)->CallObjectMethod(env, filesDirObj, getAbsolutePathID);
|
| 626 |
+
|
| 627 |
+
if (!path)
|
| 628 |
+
{
|
| 629 |
+
WLog_FATAL(TAG, "Failed to call getAbsolutePath");
|
| 630 |
+
return (jlong)NULL;
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
raw = (*env)->GetStringUTFChars(env, path, 0);
|
| 634 |
+
|
| 635 |
+
if (!raw)
|
| 636 |
+
{
|
| 637 |
+
WLog_FATAL(TAG, "Failed to get C string from java string");
|
| 638 |
+
return (jlong)NULL;
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
envStr = _strdup(raw);
|
| 642 |
+
(*env)->ReleaseStringUTFChars(env, path, raw);
|
| 643 |
+
|
| 644 |
+
if (!envStr)
|
| 645 |
+
{
|
| 646 |
+
WLog_FATAL(TAG, "_strdup(%s) failed", raw);
|
| 647 |
+
return (jlong)NULL;
|
| 648 |
+
}
|
| 649 |
+
|
| 650 |
+
if (setenv("HOME", _strdup(envStr), 1) != 0)
|
| 651 |
+
{
|
| 652 |
+
char ebuffer[256] = { 0 };
|
| 653 |
+
WLog_FATAL(TAG, "Failed to set environment HOME=%s %s [%d]", env,
|
| 654 |
+
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
| 655 |
+
return (jlong)NULL;
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
RdpClientEntry(&clientEntryPoints);
|
| 659 |
+
ctx = freerdp_client_context_new(&clientEntryPoints);
|
| 660 |
+
|
| 661 |
+
if (!ctx)
|
| 662 |
+
return (jlong)NULL;
|
| 663 |
+
|
| 664 |
+
return (jlong)ctx->instance;
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1free(
|
| 668 |
+
JNIEnv* env, jclass cls, jlong instance)
|
| 669 |
+
{
|
| 670 |
+
freerdp* inst = (freerdp*)instance;
|
| 671 |
+
|
| 672 |
+
if (inst)
|
| 673 |
+
freerdp_client_context_free(inst->context);
|
| 674 |
+
|
| 675 |
+
#if defined(WITH_GPROF)
|
| 676 |
+
moncleanup();
|
| 677 |
+
#endif
|
| 678 |
+
}
|
| 679 |
+
|
| 680 |
+
JNIEXPORT jstring JNICALL
|
| 681 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1get_1last_1error_1string(JNIEnv* env,
|
| 682 |
+
jclass cls,
|
| 683 |
+
jlong instance)
|
| 684 |
+
{
|
| 685 |
+
freerdp* inst = (freerdp*)instance;
|
| 686 |
+
|
| 687 |
+
if (!inst || !inst->context)
|
| 688 |
+
return (*env)->NewStringUTF(env, "");
|
| 689 |
+
|
| 690 |
+
return (*env)->NewStringUTF(
|
| 691 |
+
env, freerdp_get_last_error_string(freerdp_get_last_error(inst->context)));
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
JNIEXPORT jboolean JNICALL
|
| 695 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1parse_1arguments(JNIEnv* env, jclass cls,
|
| 696 |
+
jlong instance,
|
| 697 |
+
jobjectArray arguments)
|
| 698 |
+
{
|
| 699 |
+
freerdp* inst = (freerdp*)instance;
|
| 700 |
+
int count;
|
| 701 |
+
char** argv;
|
| 702 |
+
DWORD status;
|
| 703 |
+
|
| 704 |
+
if (!inst || !inst->context)
|
| 705 |
+
return JNI_FALSE;
|
| 706 |
+
|
| 707 |
+
count = (*env)->GetArrayLength(env, arguments);
|
| 708 |
+
argv = calloc(count, sizeof(char*));
|
| 709 |
+
|
| 710 |
+
if (!argv)
|
| 711 |
+
return JNI_TRUE;
|
| 712 |
+
|
| 713 |
+
for (int i = 0; i < count; i++)
|
| 714 |
+
{
|
| 715 |
+
jstring str = (jstring)(*env)->GetObjectArrayElement(env, arguments, i);
|
| 716 |
+
const char* raw = (*env)->GetStringUTFChars(env, str, 0);
|
| 717 |
+
argv[i] = _strdup(raw);
|
| 718 |
+
(*env)->ReleaseStringUTFChars(env, str, raw);
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
status =
|
| 722 |
+
freerdp_client_settings_parse_command_line(inst->context->settings, count, argv, FALSE);
|
| 723 |
+
|
| 724 |
+
for (int i = 0; i < count; i++)
|
| 725 |
+
free(argv[i]);
|
| 726 |
+
|
| 727 |
+
free(argv);
|
| 728 |
+
return (status == 0) ? JNI_TRUE : JNI_FALSE;
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1connect(
|
| 732 |
+
JNIEnv* env, jclass cls, jlong instance)
|
| 733 |
+
{
|
| 734 |
+
freerdp* inst = (freerdp*)instance;
|
| 735 |
+
androidContext* ctx;
|
| 736 |
+
|
| 737 |
+
if (!inst || !inst->context)
|
| 738 |
+
{
|
| 739 |
+
WLog_FATAL(TAG, "(env=%p, cls=%p, instance=%d", (void*)env, (void*)cls, instance);
|
| 740 |
+
return JNI_FALSE;
|
| 741 |
+
}
|
| 742 |
+
|
| 743 |
+
ctx = (androidContext*)inst->context;
|
| 744 |
+
|
| 745 |
+
if (!(ctx->thread = CreateThread(NULL, 0, android_thread_func, inst, 0, NULL)))
|
| 746 |
+
{
|
| 747 |
+
return JNI_FALSE;
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
return JNI_TRUE;
|
| 751 |
+
}
|
| 752 |
+
|
| 753 |
+
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1disconnect(
|
| 754 |
+
JNIEnv* env, jclass cls, jlong instance)
|
| 755 |
+
{
|
| 756 |
+
freerdp* inst = (freerdp*)instance;
|
| 757 |
+
androidContext* ctx;
|
| 758 |
+
ANDROID_EVENT* event;
|
| 759 |
+
|
| 760 |
+
if (!inst || !inst->context || !cls || !env)
|
| 761 |
+
{
|
| 762 |
+
WLog_FATAL(TAG, "(env=%p, cls=%p, instance=%d", (void*)env, (void*)cls, instance);
|
| 763 |
+
return JNI_FALSE;
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
ctx = (androidContext*)inst->context;
|
| 767 |
+
event = (ANDROID_EVENT*)android_event_disconnect_new();
|
| 768 |
+
|
| 769 |
+
if (!event)
|
| 770 |
+
return JNI_FALSE;
|
| 771 |
+
|
| 772 |
+
if (!android_push_event(inst, event))
|
| 773 |
+
{
|
| 774 |
+
android_event_free((ANDROID_EVENT*)event);
|
| 775 |
+
return JNI_FALSE;
|
| 776 |
+
}
|
| 777 |
+
|
| 778 |
+
if (!freerdp_abort_connect_context(inst->context))
|
| 779 |
+
return JNI_FALSE;
|
| 780 |
+
|
| 781 |
+
return JNI_TRUE;
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
JNIEXPORT jboolean JNICALL
|
| 785 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1update_1graphics(JNIEnv* env, jclass cls,
|
| 786 |
+
jlong instance,
|
| 787 |
+
jobject bitmap, jint x,
|
| 788 |
+
jint y, jint width,
|
| 789 |
+
jint height)
|
| 790 |
+
{
|
| 791 |
+
UINT32 DstFormat;
|
| 792 |
+
jboolean rc;
|
| 793 |
+
int ret;
|
| 794 |
+
void* pixels;
|
| 795 |
+
AndroidBitmapInfo info;
|
| 796 |
+
freerdp* inst = (freerdp*)instance;
|
| 797 |
+
rdpGdi* gdi;
|
| 798 |
+
|
| 799 |
+
if (!env || !cls || !inst)
|
| 800 |
+
{
|
| 801 |
+
WLog_FATAL(TAG, "(env=%p, cls=%p, instance=%d", (void*)env, (void*)cls, instance);
|
| 802 |
+
return JNI_FALSE;
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
gdi = inst->context->gdi;
|
| 806 |
+
|
| 807 |
+
if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0)
|
| 808 |
+
{
|
| 809 |
+
WLog_FATAL(TAG, "AndroidBitmap_getInfo() failed ! error=%d", ret);
|
| 810 |
+
return JNI_FALSE;
|
| 811 |
+
}
|
| 812 |
+
|
| 813 |
+
if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0)
|
| 814 |
+
{
|
| 815 |
+
WLog_FATAL(TAG, "AndroidBitmap_lockPixels() failed ! error=%d", ret);
|
| 816 |
+
return JNI_FALSE;
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
rc = JNI_TRUE;
|
| 820 |
+
|
| 821 |
+
switch (info.format)
|
| 822 |
+
{
|
| 823 |
+
case ANDROID_BITMAP_FORMAT_RGBA_8888:
|
| 824 |
+
DstFormat = PIXEL_FORMAT_RGBX32;
|
| 825 |
+
break;
|
| 826 |
+
|
| 827 |
+
case ANDROID_BITMAP_FORMAT_RGB_565:
|
| 828 |
+
DstFormat = PIXEL_FORMAT_RGB16;
|
| 829 |
+
break;
|
| 830 |
+
|
| 831 |
+
case ANDROID_BITMAP_FORMAT_RGBA_4444:
|
| 832 |
+
case ANDROID_BITMAP_FORMAT_A_8:
|
| 833 |
+
case ANDROID_BITMAP_FORMAT_NONE:
|
| 834 |
+
default:
|
| 835 |
+
rc = JNI_FALSE;
|
| 836 |
+
break;
|
| 837 |
+
}
|
| 838 |
+
|
| 839 |
+
if (rc)
|
| 840 |
+
{
|
| 841 |
+
rc = freerdp_image_copy(pixels, DstFormat, info.stride, x, y, width, height,
|
| 842 |
+
gdi->primary_buffer, gdi->dstFormat, gdi->stride, x, y,
|
| 843 |
+
&gdi->palette, FREERDP_FLIP_NONE);
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
if ((ret = AndroidBitmap_unlockPixels(env, bitmap)) < 0)
|
| 847 |
+
{
|
| 848 |
+
WLog_FATAL(TAG, "AndroidBitmap_unlockPixels() failed ! error=%d", ret);
|
| 849 |
+
return JNI_FALSE;
|
| 850 |
+
}
|
| 851 |
+
|
| 852 |
+
return rc;
|
| 853 |
+
}
|
| 854 |
+
|
| 855 |
+
JNIEXPORT jboolean JNICALL
|
| 856 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1key_1event(JNIEnv* env, jclass cls,
|
| 857 |
+
jlong instance,
|
| 858 |
+
jint keycode,
|
| 859 |
+
jboolean down)
|
| 860 |
+
{
|
| 861 |
+
DWORD scancode;
|
| 862 |
+
ANDROID_EVENT* event;
|
| 863 |
+
freerdp* inst = (freerdp*)instance;
|
| 864 |
+
scancode = GetVirtualScanCodeFromVirtualKeyCode(keycode, 4);
|
| 865 |
+
int flags = (down == JNI_TRUE) ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE;
|
| 866 |
+
flags |= (scancode & KBDEXT) ? KBD_FLAGS_EXTENDED : 0;
|
| 867 |
+
event = (ANDROID_EVENT*)android_event_key_new(flags, scancode & 0xFF);
|
| 868 |
+
|
| 869 |
+
if (!event)
|
| 870 |
+
return JNI_FALSE;
|
| 871 |
+
|
| 872 |
+
if (!android_push_event(inst, event))
|
| 873 |
+
{
|
| 874 |
+
android_event_free(event);
|
| 875 |
+
return JNI_FALSE;
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
WLog_DBG(TAG, "send_key_event: %" PRIu32 ", %d", scancode, flags);
|
| 879 |
+
return JNI_TRUE;
|
| 880 |
+
}
|
| 881 |
+
|
| 882 |
+
JNIEXPORT jboolean JNICALL
|
| 883 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1unicodekey_1event(
|
| 884 |
+
JNIEnv* env, jclass cls, jlong instance, jint keycode, jboolean down)
|
| 885 |
+
{
|
| 886 |
+
ANDROID_EVENT* event;
|
| 887 |
+
freerdp* inst = (freerdp*)instance;
|
| 888 |
+
UINT16 flags = (down == JNI_TRUE) ? 0 : KBD_FLAGS_RELEASE;
|
| 889 |
+
event = (ANDROID_EVENT*)android_event_unicodekey_new(flags, keycode);
|
| 890 |
+
|
| 891 |
+
if (!event)
|
| 892 |
+
return JNI_FALSE;
|
| 893 |
+
|
| 894 |
+
if (!android_push_event(inst, event))
|
| 895 |
+
{
|
| 896 |
+
android_event_free(event);
|
| 897 |
+
return JNI_FALSE;
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
WLog_DBG(TAG, "send_unicodekey_event: %d", keycode);
|
| 901 |
+
return JNI_TRUE;
|
| 902 |
+
}
|
| 903 |
+
|
| 904 |
+
JNIEXPORT jboolean JNICALL
|
| 905 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1cursor_1event(
|
| 906 |
+
JNIEnv* env, jclass cls, jlong instance, jint x, jint y, jint flags)
|
| 907 |
+
{
|
| 908 |
+
ANDROID_EVENT* event;
|
| 909 |
+
freerdp* inst = (freerdp*)instance;
|
| 910 |
+
event = (ANDROID_EVENT*)android_event_cursor_new(flags, x, y);
|
| 911 |
+
|
| 912 |
+
if (!event)
|
| 913 |
+
return JNI_FALSE;
|
| 914 |
+
|
| 915 |
+
if (!android_push_event(inst, event))
|
| 916 |
+
{
|
| 917 |
+
android_event_free(event);
|
| 918 |
+
return JNI_FALSE;
|
| 919 |
+
}
|
| 920 |
+
|
| 921 |
+
WLog_DBG(TAG, "send_cursor_event: (%d, %d), %d", x, y, flags);
|
| 922 |
+
return JNI_TRUE;
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
JNIEXPORT jboolean JNICALL
|
| 926 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1clipboard_1data(JNIEnv* env,
|
| 927 |
+
jclass cls,
|
| 928 |
+
jlong instance,
|
| 929 |
+
jstring jdata)
|
| 930 |
+
{
|
| 931 |
+
ANDROID_EVENT* event;
|
| 932 |
+
freerdp* inst = (freerdp*)instance;
|
| 933 |
+
const char* data = jdata != NULL ? (*env)->GetStringUTFChars(env, jdata, NULL) : NULL;
|
| 934 |
+
const size_t data_length = data ? (*env)->GetStringUTFLength(env, jdata) : 0;
|
| 935 |
+
jboolean ret = JNI_FALSE;
|
| 936 |
+
event = (ANDROID_EVENT*)android_event_clipboard_new((void*)data, data_length);
|
| 937 |
+
|
| 938 |
+
if (!event)
|
| 939 |
+
goto out_fail;
|
| 940 |
+
|
| 941 |
+
if (!android_push_event(inst, event))
|
| 942 |
+
{
|
| 943 |
+
android_event_free(event);
|
| 944 |
+
goto out_fail;
|
| 945 |
+
}
|
| 946 |
+
|
| 947 |
+
WLog_DBG(TAG, "send_clipboard_data: (%s)", data);
|
| 948 |
+
ret = JNI_TRUE;
|
| 949 |
+
out_fail:
|
| 950 |
+
|
| 951 |
+
if (data)
|
| 952 |
+
(*env)->ReleaseStringUTFChars(env, jdata, data);
|
| 953 |
+
|
| 954 |
+
return ret;
|
| 955 |
+
}
|
| 956 |
+
|
| 957 |
+
JNIEXPORT jstring JNICALL
|
| 958 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1get_1jni_1version(JNIEnv* env, jclass cls)
|
| 959 |
+
{
|
| 960 |
+
return (*env)->NewStringUTF(env, FREERDP_JNI_VERSION);
|
| 961 |
+
}
|
| 962 |
+
|
| 963 |
+
JNIEXPORT jboolean JNICALL
|
| 964 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1has_1h264(JNIEnv* env, jclass cls)
|
| 965 |
+
{
|
| 966 |
+
H264_CONTEXT* ctx = h264_context_new(FALSE);
|
| 967 |
+
if (!ctx)
|
| 968 |
+
return JNI_FALSE;
|
| 969 |
+
h264_context_free(ctx);
|
| 970 |
+
return JNI_TRUE;
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
JNIEXPORT jstring JNICALL
|
| 974 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1get_1version(JNIEnv* env, jclass cls)
|
| 975 |
+
{
|
| 976 |
+
return (*env)->NewStringUTF(env, freerdp_get_version_string());
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
JNIEXPORT jstring JNICALL
|
| 980 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1get_1build_1revision(JNIEnv* env,
|
| 981 |
+
jclass cls)
|
| 982 |
+
{
|
| 983 |
+
return (*env)->NewStringUTF(env, freerdp_get_build_revision());
|
| 984 |
+
}
|
| 985 |
+
|
| 986 |
+
JNIEXPORT jstring JNICALL
|
| 987 |
+
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1get_1build_1config(JNIEnv* env,
|
| 988 |
+
jclass cls)
|
| 989 |
+
{
|
| 990 |
+
return (*env)->NewStringUTF(env, freerdp_get_build_config());
|
| 991 |
+
}
|
| 992 |
+
|
| 993 |
+
static jclass gJavaActivityClass = NULL;
|
| 994 |
+
|
| 995 |
+
jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
| 996 |
+
{
|
| 997 |
+
JNIEnv* env;
|
| 998 |
+
setlocale(LC_ALL, "");
|
| 999 |
+
WLog_DBG(TAG, "Setting up JNI environment...");
|
| 1000 |
+
|
| 1001 |
+
/*
|
| 1002 |
+
if (freerdp_handle_signals() != 0)
|
| 1003 |
+
{
|
| 1004 |
+
WLog_FATAL(TAG, "Failed to register signal handler");
|
| 1005 |
+
return -1;
|
| 1006 |
+
}
|
| 1007 |
+
*/
|
| 1008 |
+
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK)
|
| 1009 |
+
{
|
| 1010 |
+
WLog_FATAL(TAG, "Failed to get the environment");
|
| 1011 |
+
return -1;
|
| 1012 |
+
}
|
| 1013 |
+
|
| 1014 |
+
// Get SBCEngine activity class
|
| 1015 |
+
jclass activityClass = (*env)->FindClass(env, JAVA_LIBFREERDP_CLASS);
|
| 1016 |
+
|
| 1017 |
+
if (!activityClass)
|
| 1018 |
+
{
|
| 1019 |
+
WLog_FATAL(TAG, "failed to get %s class reference", JAVA_LIBFREERDP_CLASS);
|
| 1020 |
+
return -1;
|
| 1021 |
+
}
|
| 1022 |
+
|
| 1023 |
+
/* create global reference for class */
|
| 1024 |
+
gJavaActivityClass = (*env)->NewGlobalRef(env, activityClass);
|
| 1025 |
+
g_JavaVm = vm;
|
| 1026 |
+
return init_callback_environment(vm, env);
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved)
|
| 1030 |
+
{
|
| 1031 |
+
JNIEnv* env;
|
| 1032 |
+
WLog_DBG(TAG, "Tearing down JNI environment...");
|
| 1033 |
+
|
| 1034 |
+
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK)
|
| 1035 |
+
{
|
| 1036 |
+
WLog_FATAL(TAG, "Failed to get the environment");
|
| 1037 |
+
return;
|
| 1038 |
+
}
|
| 1039 |
+
|
| 1040 |
+
if (gJavaActivityClass)
|
| 1041 |
+
(*env)->DeleteGlobalRef(env, gJavaActivityClass);
|
| 1042 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/childsession.h
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Connecting to windows child session
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2023 David Fort <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CORE_CHILDSESSION_H
|
| 21 |
+
#define FREERDP_LIB_CORE_CHILDSESSION_H
|
| 22 |
+
|
| 23 |
+
#include <openssl/bio.h>
|
| 24 |
+
|
| 25 |
+
FREERDP_LOCAL BIO* createChildSessionBio(void);
|
| 26 |
+
|
| 27 |
+
#endif /* FREERDP_LIB_CORE_CHILDSESSION_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/connection.c
ADDED
|
@@ -0,0 +1,2219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Connection Sequence
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
|
| 8 |
+
* Copyright 2023 Armin Novak <[email protected]>
|
| 9 |
+
* Copyright 2023 Thincast Technologies GmbH
|
| 10 |
+
*
|
| 11 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 12 |
+
* you may not use this file except in compliance with the License.
|
| 13 |
+
* You may obtain a copy of the License at
|
| 14 |
+
*
|
| 15 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 16 |
+
*
|
| 17 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 18 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 19 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 20 |
+
* See the License for the specific language governing permissions and
|
| 21 |
+
* limitations under the License.
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
#include <freerdp/config.h>
|
| 25 |
+
|
| 26 |
+
#include "settings.h"
|
| 27 |
+
|
| 28 |
+
#include "info.h"
|
| 29 |
+
#include "input.h"
|
| 30 |
+
#include "rdp.h"
|
| 31 |
+
#include "peer.h"
|
| 32 |
+
|
| 33 |
+
#include "connection.h"
|
| 34 |
+
#include "transport.h"
|
| 35 |
+
|
| 36 |
+
#include <winpr/crt.h>
|
| 37 |
+
#include <winpr/crypto.h>
|
| 38 |
+
#include <winpr/ssl.h>
|
| 39 |
+
|
| 40 |
+
#include <freerdp/log.h>
|
| 41 |
+
#include <freerdp/error.h>
|
| 42 |
+
#include <freerdp/listener.h>
|
| 43 |
+
|
| 44 |
+
#include "../cache/pointer.h"
|
| 45 |
+
#include "../crypto/crypto.h"
|
| 46 |
+
#include "../crypto/privatekey.h"
|
| 47 |
+
#include "../crypto/certificate.h"
|
| 48 |
+
#include "gateway/arm.h"
|
| 49 |
+
|
| 50 |
+
#include "utils.h"
|
| 51 |
+
|
| 52 |
+
#define TAG FREERDP_TAG("core.connection")
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Connection Sequence
|
| 56 |
+
* client server
|
| 57 |
+
* | |
|
| 58 |
+
* |-----------------------X.224 Connection Request PDU--------------------->|
|
| 59 |
+
* |<----------------------X.224 Connection Confirm PDU----------------------|
|
| 60 |
+
* |-------MCS Connect-Initial PDU with GCC Conference Create Request------->|
|
| 61 |
+
* |<-----MCS Connect-Response PDU with GCC Conference Create Response-------|
|
| 62 |
+
* |------------------------MCS Erect Domain Request PDU-------------------->|
|
| 63 |
+
* |------------------------MCS Attach User Request PDU--------------------->|
|
| 64 |
+
* |<-----------------------MCS Attach User Confirm PDU----------------------|
|
| 65 |
+
* |------------------------MCS Channel Join Request PDU-------------------->|
|
| 66 |
+
* |<-----------------------MCS Channel Join Confirm PDU---------------------|
|
| 67 |
+
* |----------------------------Security Exchange PDU----------------------->|
|
| 68 |
+
* |-------------------------------Client Info PDU-------------------------->|
|
| 69 |
+
* |<---------------------License Error PDU - Valid Client-------------------|
|
| 70 |
+
* |<-----------------------------Demand Active PDU--------------------------|
|
| 71 |
+
* |------------------------------Confirm Active PDU------------------------>|
|
| 72 |
+
* |-------------------------------Synchronize PDU-------------------------->|
|
| 73 |
+
* |---------------------------Control PDU - Cooperate---------------------->|
|
| 74 |
+
* |------------------------Control PDU - Request Control------------------->|
|
| 75 |
+
* |--------------------------Persistent Key List PDU(s)-------------------->|
|
| 76 |
+
* |--------------------------------Font List PDU--------------------------->|
|
| 77 |
+
* |<------------------------------Synchronize PDU---------------------------|
|
| 78 |
+
* |<--------------------------Control PDU - Cooperate-----------------------|
|
| 79 |
+
* |<-----------------------Control PDU - Granted Control--------------------|
|
| 80 |
+
* |<-------------------------------Font Map PDU-----------------------------|
|
| 81 |
+
*
|
| 82 |
+
*/
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
*
|
| 86 |
+
* Connection Sequence
|
| 87 |
+
*
|
| 88 |
+
* 1. Connection Initiation: The client initiates the connection by sending the server a
|
| 89 |
+
* Class 0 X.224 Connection Request PDU (section 2.2.1.1). The server responds with a
|
| 90 |
+
* Class 0 X.224 Connection Confirm PDU (section 2.2.1.2). From this point, all subsequent
|
| 91 |
+
* data sent between client and server is wrapped in an X.224 Data Protocol Data Unit (PDU).
|
| 92 |
+
*
|
| 93 |
+
* 2. Basic Settings Exchange: Basic settings are exchanged between the client and server by
|
| 94 |
+
* using the MCS Connect Initial PDU (section 2.2.1.3) and MCS Connect Response PDU
|
| 95 |
+
*(section 2.2.1.4). The Connect Initial PDU contains a Generic Conference Control (GCC) Conference
|
| 96 |
+
*Create Request, while the Connect Response PDU contains a GCC Conference Create Response. These
|
| 97 |
+
*two GCC packets contain concatenated blocks of settings data (such as core data, security data,
|
| 98 |
+
*and network data) which are read by client and server.
|
| 99 |
+
*
|
| 100 |
+
* 3. Channel Connection: The client sends an MCS Erect Domain Request PDU (section 2.2.1.5),
|
| 101 |
+
* followed by an MCS Attach User Request PDU (section 2.2.1.6) to attach the primary user identity
|
| 102 |
+
* to the MCS domain. The server responds with an MCS Attach User Confirm PDU (section 2.2.1.7)
|
| 103 |
+
* containing the User Channel ID. The client then proceeds to join the user channel, the
|
| 104 |
+
* input/output (I/O) channel, and all of the static virtual channels (the I/O and static virtual
|
| 105 |
+
* channel IDs are obtained from the data embedded in the GCC packets) by using multiple MCS
|
| 106 |
+
*Channel Join Request PDUs (section 2.2.1.8). The server confirms each channel with an MCS Channel
|
| 107 |
+
*Join Confirm PDU (section 2.2.1.9). (The client only sends a Channel Join Request after it has
|
| 108 |
+
*received the Channel Join Confirm for the previously sent request.)
|
| 109 |
+
*
|
| 110 |
+
* From this point, all subsequent data sent from the client to the server is wrapped in an MCS
|
| 111 |
+
*Send Data Request PDU, while data sent from the server to the client is wrapped in an MCS Send
|
| 112 |
+
*Data Indication PDU. This is in addition to the data being wrapped by an X.224 Data PDU.
|
| 113 |
+
*
|
| 114 |
+
* 4. RDP Security Commencement: If Standard RDP Security mechanisms (section 5.3) are being
|
| 115 |
+
*employed and encryption is in force (this is determined by examining the data embedded in the GCC
|
| 116 |
+
*Conference Create Response packet) then the client sends a Security Exchange PDU
|
| 117 |
+
*(section 2.2.1.10) containing an encrypted 32-byte random number to the server. This random number
|
| 118 |
+
*is encrypted with the public key of the server as described in section 5.3.4.1 (the server's
|
| 119 |
+
*public key, as well as a 32-byte server-generated random number, are both obtained from the data
|
| 120 |
+
*embedded in the GCC Conference Create Response packet). The client and server then utilize the two
|
| 121 |
+
*32-byte random numbers to generate session keys which are used to encrypt and validate the
|
| 122 |
+
*integrity of subsequent RDP traffic.
|
| 123 |
+
*
|
| 124 |
+
* From this point, all subsequent RDP traffic can be encrypted and a security header is included
|
| 125 |
+
*with the data if encryption is in force. (The Client Info PDU (section 2.2.1.11) and licensing
|
| 126 |
+
*PDUs ([MS-RDPELE] section 2.2.2) are an exception in that they always have a security header). The
|
| 127 |
+
*Security Header follows the X.224 and MCS Headers and indicates whether the attached data is
|
| 128 |
+
*encrypted. Even if encryption is in force, server-to-client traffic may not always be encrypted,
|
| 129 |
+
*while client-to-server traffic must always be encrypted (encryption of licensing PDUs is optional,
|
| 130 |
+
*however).
|
| 131 |
+
*
|
| 132 |
+
* 5. Secure Settings Exchange: Secure client data (such as the username, password, and
|
| 133 |
+
*auto-reconnect cookie) is sent to the server by using the Client Info PDU (section 2.2.1.11).
|
| 134 |
+
*
|
| 135 |
+
* 6. Optional Connect-Time Auto-Detection: During the optional connect-time auto-detect phase the
|
| 136 |
+
*goal is to determine characteristics of the network, such as the round-trip latency time and the
|
| 137 |
+
*bandwidth of the link between the server and client. This is accomplished by exchanging a
|
| 138 |
+
*collection of PDUs (specified in section 2.2.1.4) over a predetermined period of time with enough
|
| 139 |
+
*data to ensure that the results are statistically relevant.
|
| 140 |
+
*
|
| 141 |
+
* 7. Licensing: The goal of the licensing exchange is to transfer a license from the server to
|
| 142 |
+
*the client. The client stores this license and on subsequent connections sends the license to the
|
| 143 |
+
*server for validation. However, in some situations the client may not be issued a license to
|
| 144 |
+
*store. In effect, the packets exchanged during this phase of the protocol depend on the licensing
|
| 145 |
+
*mechanisms employed by the server. Within the context of this document, it is assumed that the
|
| 146 |
+
*client will not be issued a license to store. For details regarding more advanced licensing
|
| 147 |
+
*scenarios that take place during the Licensing Phase, see [MS-RDPELE] section 1.3.
|
| 148 |
+
*
|
| 149 |
+
* 8. Optional Multitransport Bootstrapping: After the connection has been secured and the
|
| 150 |
+
*Licensing Phase has run to completion, the server can choose to initiate multitransport
|
| 151 |
+
*connections ([MS-RDPEMT] section 1.3). The Initiate Multitransport Request PDU (section 2.2.15.1)
|
| 152 |
+
*is sent by the server to the client and results in the out-of-band creation of a multitransport
|
| 153 |
+
*connection using messages from the RDP-UDP, TLS, DTLS, and multitransport protocols ([MS-RDPEMT]
|
| 154 |
+
*section 1.3.1).
|
| 155 |
+
*
|
| 156 |
+
* 9. Capabilities Exchange: The server sends the set of capabilities it supports to the client in
|
| 157 |
+
*a Demand Active PDU (section 2.2.1.13.1). The client responds with its capabilities by sending a
|
| 158 |
+
*Confirm Active PDU (section 2.2.1.13.2).
|
| 159 |
+
*
|
| 160 |
+
* 10. Connection Finalization: The client and server exchange PDUs to finalize the connection
|
| 161 |
+
*details. The client-to-server PDUs sent during this phase have no dependencies on any of the
|
| 162 |
+
*server-to-client PDUs; they may be sent as a single batch, provided that sequencing is maintained.
|
| 163 |
+
*
|
| 164 |
+
* - The Client Synchronize PDU (section 2.2.1.14) is sent after transmitting the Confirm Active
|
| 165 |
+
*PDU.
|
| 166 |
+
* - The Client Control (Cooperate) PDU (section 2.2.1.15) is sent after transmitting the Client
|
| 167 |
+
*Synchronize PDU.
|
| 168 |
+
* - The Client Control (Request Control) PDU (section 2.2.1.16) is sent after transmitting the
|
| 169 |
+
*Client Control (Cooperate) PDU.
|
| 170 |
+
* - The optional Persistent Key List PDUs (section 2.2.1.17) are sent after transmitting the
|
| 171 |
+
*Client Control (Request Control) PDU.
|
| 172 |
+
* - The Font List PDU (section 2.2.1.18) is sent after transmitting the Persistent Key List PDUs
|
| 173 |
+
*or, if the Persistent Key List PDUs were not sent, it is sent after transmitting the Client
|
| 174 |
+
*Control (Request Control) PDU (section 2.2.1.16).
|
| 175 |
+
*
|
| 176 |
+
* The server-to-client PDUs sent during the Connection Finalization Phase have dependencies on the
|
| 177 |
+
*client-to-server PDUs.
|
| 178 |
+
*
|
| 179 |
+
* - The optional Monitor Layout PDU (section 2.2.12.1) has no dependency on any client-to-server
|
| 180 |
+
*PDUs and is sent after the Demand Active PDU.
|
| 181 |
+
* - The Server Synchronize PDU (section 2.2.1.19) is sent in response to the Confirm Active PDU.
|
| 182 |
+
* - The Server Control (Cooperate) PDU (section 2.2.1.20) is sent after transmitting the Server
|
| 183 |
+
*Synchronize PDU.
|
| 184 |
+
* - The Server Control (Granted Control) PDU (section 2.2.1.21) is sent in response to the Client
|
| 185 |
+
*Control (Request Control) PDU.
|
| 186 |
+
* - The Font Map PDU (section 2.2.1.22) is sent in response to the Font List PDU.
|
| 187 |
+
*
|
| 188 |
+
* Once the client has sent the Confirm Active PDU, it can start sending mouse and keyboard input
|
| 189 |
+
*to the server, and upon receipt of the Font List PDU the server can start sending graphics output
|
| 190 |
+
*to the client.
|
| 191 |
+
*
|
| 192 |
+
* Besides input and graphics data, other data that can be exchanged between client and server
|
| 193 |
+
*after the connection has been finalized includes connection management information and virtual
|
| 194 |
+
*channel messages (exchanged between client-side plug-ins and server-side applications).
|
| 195 |
+
*/
|
| 196 |
+
|
| 197 |
+
static BOOL rdp_set_state(rdpRdp* rdp, CONNECTION_STATE state);
|
| 198 |
+
|
| 199 |
+
static BOOL rdp_client_reset_codecs(rdpContext* context)
|
| 200 |
+
{
|
| 201 |
+
rdpSettings* settings = NULL;
|
| 202 |
+
|
| 203 |
+
if (!context || !context->settings)
|
| 204 |
+
return FALSE;
|
| 205 |
+
|
| 206 |
+
settings = context->settings;
|
| 207 |
+
|
| 208 |
+
if (!freerdp_settings_get_bool(settings, FreeRDP_DeactivateClientDecoding))
|
| 209 |
+
{
|
| 210 |
+
const UINT32 flags = freerdp_settings_get_uint32(settings, FreeRDP_ThreadingFlags);
|
| 211 |
+
freerdp_client_codecs_free(context->codecs);
|
| 212 |
+
context->codecs = freerdp_client_codecs_new(flags);
|
| 213 |
+
|
| 214 |
+
if (!context->codecs)
|
| 215 |
+
return FALSE;
|
| 216 |
+
|
| 217 |
+
if (!freerdp_client_codecs_prepare(context->codecs,
|
| 218 |
+
freerdp_settings_get_codecs_flags(settings),
|
| 219 |
+
settings->DesktopWidth, settings->DesktopHeight))
|
| 220 |
+
return FALSE;
|
| 221 |
+
|
| 222 |
+
/* Runtime H264 detection. (only available if dynamic backend loading is defined)
|
| 223 |
+
* If no backend is available disable it before the channel is loaded.
|
| 224 |
+
*/
|
| 225 |
+
#if defined(WITH_GFX_H264) && defined(WITH_OPENH264_LOADING)
|
| 226 |
+
if (!context->codecs->h264)
|
| 227 |
+
{
|
| 228 |
+
settings->GfxH264 = FALSE;
|
| 229 |
+
settings->GfxAVC444 = FALSE;
|
| 230 |
+
settings->GfxAVC444v2 = FALSE;
|
| 231 |
+
}
|
| 232 |
+
#endif
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
return TRUE;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
static BOOL rdp_client_wait_for_activation(rdpRdp* rdp)
|
| 239 |
+
{
|
| 240 |
+
BOOL timedout = FALSE;
|
| 241 |
+
WINPR_ASSERT(rdp);
|
| 242 |
+
|
| 243 |
+
const rdpSettings* settings = rdp->settings;
|
| 244 |
+
WINPR_ASSERT(settings);
|
| 245 |
+
|
| 246 |
+
UINT64 now = GetTickCount64();
|
| 247 |
+
UINT64 dueDate = now + freerdp_settings_get_uint32(settings, FreeRDP_TcpAckTimeout);
|
| 248 |
+
|
| 249 |
+
for (; (now < dueDate) && !timedout; now = GetTickCount64())
|
| 250 |
+
{
|
| 251 |
+
HANDLE events[MAXIMUM_WAIT_OBJECTS] = { 0 };
|
| 252 |
+
DWORD wstatus = 0;
|
| 253 |
+
DWORD nevents = freerdp_get_event_handles(rdp->context, events, ARRAYSIZE(events));
|
| 254 |
+
if (!nevents)
|
| 255 |
+
{
|
| 256 |
+
WLog_ERR(TAG, "error retrieving connection events");
|
| 257 |
+
return FALSE;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
const UINT64 timeout = (dueDate - now);
|
| 261 |
+
WINPR_ASSERT(timeout <= UINT32_MAX);
|
| 262 |
+
wstatus = WaitForMultipleObjectsEx(nevents, events, FALSE, (UINT32)timeout, TRUE);
|
| 263 |
+
switch (wstatus)
|
| 264 |
+
{
|
| 265 |
+
case WAIT_TIMEOUT:
|
| 266 |
+
/* will make us quit with a timeout */
|
| 267 |
+
timedout = TRUE;
|
| 268 |
+
break;
|
| 269 |
+
case WAIT_ABANDONED:
|
| 270 |
+
case WAIT_FAILED:
|
| 271 |
+
return FALSE;
|
| 272 |
+
case WAIT_IO_COMPLETION:
|
| 273 |
+
break;
|
| 274 |
+
case WAIT_OBJECT_0:
|
| 275 |
+
default:
|
| 276 |
+
/* handles all WAIT_OBJECT_0 + [0 .. MAXIMUM_WAIT_OBJECTS-1] cases */
|
| 277 |
+
if (rdp_check_fds(rdp) < 0)
|
| 278 |
+
{
|
| 279 |
+
freerdp_set_last_error_if_not(rdp->context,
|
| 280 |
+
FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
|
| 281 |
+
return FALSE;
|
| 282 |
+
}
|
| 283 |
+
break;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
if (rdp_is_active_state(rdp))
|
| 287 |
+
return TRUE;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
WLog_ERR(TAG, "Timeout waiting for activation");
|
| 291 |
+
freerdp_set_last_error_if_not(rdp->context, FREERDP_ERROR_CONNECT_ACTIVATION_TIMEOUT);
|
| 292 |
+
return FALSE;
|
| 293 |
+
}
|
| 294 |
+
/**
|
| 295 |
+
* Establish RDP Connection based on the settings given in the 'rdp' parameter.
|
| 296 |
+
* msdn{cc240452}
|
| 297 |
+
* @param rdp RDP module
|
| 298 |
+
* @return true if the connection succeeded. FALSE otherwise.
|
| 299 |
+
*/
|
| 300 |
+
|
| 301 |
+
BOOL rdp_client_connect(rdpRdp* rdp)
|
| 302 |
+
{
|
| 303 |
+
UINT32 SelectedProtocol = 0;
|
| 304 |
+
BOOL status = 0;
|
| 305 |
+
rdpSettings* settings = NULL;
|
| 306 |
+
/* make sure SSL is initialize for earlier enough for crypto, by taking advantage of winpr SSL
|
| 307 |
+
* FIPS flag for openssl initialization */
|
| 308 |
+
DWORD flags = WINPR_SSL_INIT_DEFAULT;
|
| 309 |
+
|
| 310 |
+
WINPR_ASSERT(rdp);
|
| 311 |
+
|
| 312 |
+
settings = rdp->settings;
|
| 313 |
+
WINPR_ASSERT(settings);
|
| 314 |
+
|
| 315 |
+
if (!rdp_client_reset_codecs(rdp->context))
|
| 316 |
+
return FALSE;
|
| 317 |
+
|
| 318 |
+
if (settings->FIPSMode)
|
| 319 |
+
flags |= WINPR_SSL_INIT_ENABLE_FIPS;
|
| 320 |
+
|
| 321 |
+
winpr_InitializeSSL(flags);
|
| 322 |
+
rdp_log_build_warnings(rdp);
|
| 323 |
+
|
| 324 |
+
/* FIPS Mode forces the following and overrides the following(by happening later */
|
| 325 |
+
/* in the command line processing): */
|
| 326 |
+
/* 1. Disables NLA Security since NLA in freerdp uses NTLM(no Kerberos support yet) which uses
|
| 327 |
+
* algorithms */
|
| 328 |
+
/* not allowed in FIPS for sensitive data. So, we disallow NLA when FIPS is required. */
|
| 329 |
+
/* 2. Forces the only supported RDP encryption method to be FIPS. */
|
| 330 |
+
if (settings->FIPSMode || winpr_FIPSMode())
|
| 331 |
+
{
|
| 332 |
+
settings->NlaSecurity = FALSE;
|
| 333 |
+
settings->EncryptionMethods = ENCRYPTION_METHOD_FIPS;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
UINT32 TcpConnectTimeout = freerdp_settings_get_uint32(settings, FreeRDP_TcpConnectTimeout);
|
| 337 |
+
if (settings->GatewayArmTransport)
|
| 338 |
+
{
|
| 339 |
+
if (!arm_resolve_endpoint(rdp->log, rdp->context, TcpConnectTimeout))
|
| 340 |
+
{
|
| 341 |
+
WLog_ERR(TAG, "error retrieving ARM configuration");
|
| 342 |
+
return FALSE;
|
| 343 |
+
}
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
const char* hostname = settings->ServerHostname;
|
| 347 |
+
if (!hostname)
|
| 348 |
+
{
|
| 349 |
+
WLog_ERR(TAG, "Missing hostname, can not connect to NULL target");
|
| 350 |
+
return FALSE;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
const UINT32 port = settings->ServerPort;
|
| 354 |
+
WINPR_ASSERT(port <= UINT32_MAX);
|
| 355 |
+
|
| 356 |
+
nego_init(rdp->nego);
|
| 357 |
+
nego_set_target(rdp->nego, hostname, (UINT16)port);
|
| 358 |
+
|
| 359 |
+
if (settings->GatewayEnabled)
|
| 360 |
+
{
|
| 361 |
+
char* user = NULL;
|
| 362 |
+
char* domain = NULL;
|
| 363 |
+
size_t user_length = 0;
|
| 364 |
+
|
| 365 |
+
if (settings->Username)
|
| 366 |
+
{
|
| 367 |
+
user = settings->Username;
|
| 368 |
+
user_length = strlen(settings->Username);
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
if (settings->Domain)
|
| 372 |
+
domain = settings->Domain;
|
| 373 |
+
else
|
| 374 |
+
domain = settings->ComputerName;
|
| 375 |
+
|
| 376 |
+
const size_t domain_length = strlen(domain);
|
| 377 |
+
const size_t cookie_length = domain_length + 1 + user_length;
|
| 378 |
+
char* cookie = malloc(cookie_length + 1);
|
| 379 |
+
|
| 380 |
+
if (!cookie)
|
| 381 |
+
return FALSE;
|
| 382 |
+
|
| 383 |
+
CopyMemory(cookie, domain, domain_length);
|
| 384 |
+
WINPR_ASSERT(domain_length <= UINT32_MAX);
|
| 385 |
+
CharUpperBuffA(cookie, (UINT32)domain_length);
|
| 386 |
+
cookie[domain_length] = '\\';
|
| 387 |
+
|
| 388 |
+
if (settings->Username)
|
| 389 |
+
CopyMemory(&cookie[domain_length + 1], user, user_length);
|
| 390 |
+
|
| 391 |
+
cookie[cookie_length] = '\0';
|
| 392 |
+
status = nego_set_cookie(rdp->nego, cookie);
|
| 393 |
+
free(cookie);
|
| 394 |
+
}
|
| 395 |
+
else
|
| 396 |
+
{
|
| 397 |
+
status = nego_set_cookie(rdp->nego, settings->Username);
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
if (!status)
|
| 401 |
+
return FALSE;
|
| 402 |
+
|
| 403 |
+
nego_set_childsession_enabled(rdp->nego, settings->ConnectChildSession);
|
| 404 |
+
nego_set_send_preconnection_pdu(rdp->nego, settings->SendPreconnectionPdu);
|
| 405 |
+
nego_set_preconnection_id(rdp->nego, settings->PreconnectionId);
|
| 406 |
+
nego_set_preconnection_blob(rdp->nego, settings->PreconnectionBlob);
|
| 407 |
+
nego_set_negotiation_enabled(rdp->nego, settings->NegotiateSecurityLayer);
|
| 408 |
+
nego_set_restricted_admin_mode_required(rdp->nego, settings->RestrictedAdminModeRequired);
|
| 409 |
+
nego_set_RCG_required(rdp->nego, settings->RemoteCredentialGuard);
|
| 410 |
+
nego_set_gateway_enabled(rdp->nego, settings->GatewayEnabled);
|
| 411 |
+
nego_set_gateway_bypass_local(rdp->nego, settings->GatewayBypassLocal);
|
| 412 |
+
nego_enable_rdp(rdp->nego, settings->RdpSecurity);
|
| 413 |
+
nego_enable_tls(rdp->nego, settings->TlsSecurity);
|
| 414 |
+
nego_enable_nla(rdp->nego, settings->NlaSecurity);
|
| 415 |
+
nego_enable_ext(rdp->nego, settings->ExtSecurity);
|
| 416 |
+
nego_enable_rdstls(rdp->nego, settings->RdstlsSecurity);
|
| 417 |
+
nego_enable_aad(rdp->nego, settings->AadSecurity);
|
| 418 |
+
|
| 419 |
+
if (settings->MstscCookieMode)
|
| 420 |
+
settings->CookieMaxLength = MSTSC_COOKIE_MAX_LENGTH;
|
| 421 |
+
|
| 422 |
+
nego_set_cookie_max_length(rdp->nego, settings->CookieMaxLength);
|
| 423 |
+
|
| 424 |
+
if (settings->LoadBalanceInfo && (settings->LoadBalanceInfoLength > 0))
|
| 425 |
+
{
|
| 426 |
+
if (!nego_set_routing_token(rdp->nego, settings->LoadBalanceInfo,
|
| 427 |
+
settings->LoadBalanceInfoLength))
|
| 428 |
+
return FALSE;
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
if (!freerdp_settings_get_bool(settings, FreeRDP_TransportDumpReplay))
|
| 432 |
+
{
|
| 433 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_NEGO))
|
| 434 |
+
return FALSE;
|
| 435 |
+
|
| 436 |
+
if (!nego_connect(rdp->nego))
|
| 437 |
+
{
|
| 438 |
+
if (!freerdp_get_last_error(rdp->context))
|
| 439 |
+
{
|
| 440 |
+
freerdp_set_last_error_log(rdp->context,
|
| 441 |
+
FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED);
|
| 442 |
+
WLog_ERR(TAG, "Error: protocol security negotiation or connection failure");
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
return FALSE;
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
SelectedProtocol = nego_get_selected_protocol(rdp->nego);
|
| 449 |
+
|
| 450 |
+
if ((SelectedProtocol & PROTOCOL_SSL) || (SelectedProtocol == PROTOCOL_RDP) ||
|
| 451 |
+
(SelectedProtocol == PROTOCOL_RDSTLS))
|
| 452 |
+
{
|
| 453 |
+
wStream s = { 0 };
|
| 454 |
+
|
| 455 |
+
if ((settings->Username != NULL) &&
|
| 456 |
+
((freerdp_settings_get_string(settings, FreeRDP_Password) != NULL) ||
|
| 457 |
+
(settings->RedirectionPassword != NULL &&
|
| 458 |
+
settings->RedirectionPasswordLength > 0)))
|
| 459 |
+
settings->AutoLogonEnabled = TRUE;
|
| 460 |
+
|
| 461 |
+
if (rdp_recv_callback(rdp->transport, &s, rdp) < 0)
|
| 462 |
+
return FALSE;
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
transport_set_blocking_mode(rdp->transport, FALSE);
|
| 466 |
+
}
|
| 467 |
+
else
|
| 468 |
+
{
|
| 469 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_MCS_CREATE_REQUEST))
|
| 470 |
+
return FALSE;
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
/* everything beyond this point is event-driven and non blocking */
|
| 474 |
+
if (!transport_set_recv_callbacks(rdp->transport, rdp_recv_callback, rdp))
|
| 475 |
+
return FALSE;
|
| 476 |
+
|
| 477 |
+
return rdp_client_wait_for_activation(rdp);
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
BOOL rdp_client_disconnect(rdpRdp* rdp)
|
| 481 |
+
{
|
| 482 |
+
rdpContext* context = NULL;
|
| 483 |
+
|
| 484 |
+
if (!rdp || !rdp->settings || !rdp->context)
|
| 485 |
+
return FALSE;
|
| 486 |
+
|
| 487 |
+
context = rdp->context;
|
| 488 |
+
|
| 489 |
+
if (rdp->nego)
|
| 490 |
+
{
|
| 491 |
+
if (!nego_disconnect(rdp->nego))
|
| 492 |
+
return FALSE;
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
if (!transport_disconnect(rdp->transport))
|
| 496 |
+
return FALSE;
|
| 497 |
+
|
| 498 |
+
if (!rdp_reset(rdp))
|
| 499 |
+
return FALSE;
|
| 500 |
+
|
| 501 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_INITIAL))
|
| 502 |
+
return FALSE;
|
| 503 |
+
|
| 504 |
+
if (freerdp_channels_disconnect(context->channels, context->instance) != CHANNEL_RC_OK)
|
| 505 |
+
return FALSE;
|
| 506 |
+
|
| 507 |
+
freerdp_client_codecs_free(context->codecs);
|
| 508 |
+
context->codecs = NULL;
|
| 509 |
+
return TRUE;
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
BOOL rdp_client_disconnect_and_clear(rdpRdp* rdp)
|
| 513 |
+
{
|
| 514 |
+
rdpContext* context = NULL;
|
| 515 |
+
|
| 516 |
+
if (!rdp_client_disconnect(rdp))
|
| 517 |
+
return FALSE;
|
| 518 |
+
|
| 519 |
+
WINPR_ASSERT(rdp);
|
| 520 |
+
|
| 521 |
+
context = rdp->context;
|
| 522 |
+
WINPR_ASSERT(context);
|
| 523 |
+
|
| 524 |
+
if (freerdp_get_last_error(context) == FREERDP_ERROR_CONNECT_CANCELLED)
|
| 525 |
+
return FALSE;
|
| 526 |
+
|
| 527 |
+
context->LastError = FREERDP_ERROR_SUCCESS;
|
| 528 |
+
clearChannelError(context);
|
| 529 |
+
return utils_reset_abort(rdp);
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
static BOOL rdp_client_reconnect_channels(rdpRdp* rdp, BOOL redirect)
|
| 533 |
+
{
|
| 534 |
+
BOOL status = FALSE;
|
| 535 |
+
rdpContext* context = NULL;
|
| 536 |
+
|
| 537 |
+
if (!rdp || !rdp->context || !rdp->context->channels)
|
| 538 |
+
return FALSE;
|
| 539 |
+
|
| 540 |
+
context = rdp->context;
|
| 541 |
+
|
| 542 |
+
if (context->instance->ConnectionCallbackState == CLIENT_STATE_INITIAL)
|
| 543 |
+
return FALSE;
|
| 544 |
+
|
| 545 |
+
if (context->instance->ConnectionCallbackState == CLIENT_STATE_PRECONNECT_PASSED)
|
| 546 |
+
{
|
| 547 |
+
if (redirect)
|
| 548 |
+
return TRUE;
|
| 549 |
+
|
| 550 |
+
pointer_cache_register_callbacks(context->update);
|
| 551 |
+
|
| 552 |
+
if (!IFCALLRESULT(FALSE, context->instance->PostConnect, context->instance))
|
| 553 |
+
return FALSE;
|
| 554 |
+
|
| 555 |
+
context->instance->ConnectionCallbackState = CLIENT_STATE_POSTCONNECT_PASSED;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
if (context->instance->ConnectionCallbackState == CLIENT_STATE_POSTCONNECT_PASSED)
|
| 559 |
+
status =
|
| 560 |
+
(freerdp_channels_post_connect(context->channels, context->instance) == CHANNEL_RC_OK);
|
| 561 |
+
|
| 562 |
+
return status;
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
static BOOL rdp_client_redirect_resolvable(const char* host)
|
| 566 |
+
{
|
| 567 |
+
struct addrinfo* result = freerdp_tcp_resolve_host(host, -1, 0);
|
| 568 |
+
|
| 569 |
+
if (!result)
|
| 570 |
+
return FALSE;
|
| 571 |
+
|
| 572 |
+
freeaddrinfo(result);
|
| 573 |
+
return TRUE;
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
static BOOL rdp_client_redirect_try_fqdn(rdpSettings* settings)
|
| 577 |
+
{
|
| 578 |
+
if (settings->RedirectionFlags & LB_TARGET_FQDN)
|
| 579 |
+
{
|
| 580 |
+
if (settings->GatewayEnabled ||
|
| 581 |
+
rdp_client_redirect_resolvable(settings->RedirectionTargetFQDN))
|
| 582 |
+
{
|
| 583 |
+
if (!freerdp_settings_set_string(settings, FreeRDP_ServerHostname,
|
| 584 |
+
settings->RedirectionTargetFQDN))
|
| 585 |
+
return FALSE;
|
| 586 |
+
|
| 587 |
+
return TRUE;
|
| 588 |
+
}
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
return FALSE;
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
static BOOL rdp_client_redirect_try_ip(rdpSettings* settings)
|
| 595 |
+
{
|
| 596 |
+
if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESS)
|
| 597 |
+
{
|
| 598 |
+
if (!freerdp_settings_set_string(settings, FreeRDP_ServerHostname,
|
| 599 |
+
settings->TargetNetAddress))
|
| 600 |
+
return FALSE;
|
| 601 |
+
|
| 602 |
+
return TRUE;
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
return FALSE;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
static BOOL rdp_client_redirect_try_netbios(rdpSettings* settings)
|
| 609 |
+
{
|
| 610 |
+
if (settings->RedirectionFlags & LB_TARGET_NETBIOS_NAME)
|
| 611 |
+
{
|
| 612 |
+
if (settings->GatewayEnabled ||
|
| 613 |
+
rdp_client_redirect_resolvable(settings->RedirectionTargetNetBiosName))
|
| 614 |
+
{
|
| 615 |
+
if (!freerdp_settings_set_string(settings, FreeRDP_ServerHostname,
|
| 616 |
+
settings->RedirectionTargetNetBiosName))
|
| 617 |
+
return FALSE;
|
| 618 |
+
|
| 619 |
+
return TRUE;
|
| 620 |
+
}
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
return FALSE;
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
BOOL rdp_client_redirect(rdpRdp* rdp)
|
| 627 |
+
{
|
| 628 |
+
BOOL status = 0;
|
| 629 |
+
rdpSettings* settings = NULL;
|
| 630 |
+
|
| 631 |
+
if (!rdp_client_disconnect_and_clear(rdp))
|
| 632 |
+
return FALSE;
|
| 633 |
+
|
| 634 |
+
/* Only disconnect & close the channels here.
|
| 635 |
+
* they will be discarded and recreated after the new settings have been applied. */
|
| 636 |
+
freerdp_channels_disconnect(rdp->context->channels, rdp->context->instance);
|
| 637 |
+
freerdp_channels_close(rdp->context->channels, rdp->context->instance);
|
| 638 |
+
|
| 639 |
+
if (rdp_redirection_apply_settings(rdp) != 0)
|
| 640 |
+
return FALSE;
|
| 641 |
+
|
| 642 |
+
WINPR_ASSERT(rdp);
|
| 643 |
+
|
| 644 |
+
settings = rdp->settings;
|
| 645 |
+
WINPR_ASSERT(settings);
|
| 646 |
+
|
| 647 |
+
if ((settings->RedirectionFlags & LB_LOAD_BALANCE_INFO) == 0)
|
| 648 |
+
{
|
| 649 |
+
BOOL haveRedirectAddress = FALSE;
|
| 650 |
+
UINT32 redirectionMask = settings->RedirectionPreferType;
|
| 651 |
+
|
| 652 |
+
do
|
| 653 |
+
{
|
| 654 |
+
const BOOL tryFQDN = (redirectionMask & 0x01) == 0;
|
| 655 |
+
const BOOL tryNetAddress = (redirectionMask & 0x02) == 0;
|
| 656 |
+
const BOOL tryNetbios = (redirectionMask & 0x04) == 0;
|
| 657 |
+
|
| 658 |
+
if (tryFQDN && !haveRedirectAddress)
|
| 659 |
+
haveRedirectAddress = rdp_client_redirect_try_fqdn(settings);
|
| 660 |
+
|
| 661 |
+
if (tryNetAddress && !haveRedirectAddress)
|
| 662 |
+
haveRedirectAddress = rdp_client_redirect_try_ip(settings);
|
| 663 |
+
|
| 664 |
+
if (tryNetbios && !haveRedirectAddress)
|
| 665 |
+
haveRedirectAddress = rdp_client_redirect_try_netbios(settings);
|
| 666 |
+
|
| 667 |
+
redirectionMask >>= 3;
|
| 668 |
+
} while (!haveRedirectAddress && (redirectionMask != 0));
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
if (settings->RedirectionFlags & LB_USERNAME)
|
| 672 |
+
{
|
| 673 |
+
if (!freerdp_settings_set_string(
|
| 674 |
+
settings, FreeRDP_Username,
|
| 675 |
+
freerdp_settings_get_string(settings, FreeRDP_RedirectionUsername)))
|
| 676 |
+
return FALSE;
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
if (settings->RedirectionFlags & LB_DOMAIN)
|
| 680 |
+
{
|
| 681 |
+
if (!freerdp_settings_set_string(
|
| 682 |
+
settings, FreeRDP_Domain,
|
| 683 |
+
freerdp_settings_get_string(settings, FreeRDP_RedirectionDomain)))
|
| 684 |
+
return FALSE;
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
settings->RdstlsSecurity =
|
| 688 |
+
(settings->RedirectionFlags & LB_PASSWORD_IS_PK_ENCRYPTED) != 0 ? TRUE : FALSE;
|
| 689 |
+
|
| 690 |
+
WINPR_ASSERT(rdp->context);
|
| 691 |
+
WINPR_ASSERT(rdp->context->instance);
|
| 692 |
+
if (!IFCALLRESULT(TRUE, rdp->context->instance->Redirect, rdp->context->instance))
|
| 693 |
+
return FALSE;
|
| 694 |
+
|
| 695 |
+
BOOL ok = utils_reload_channels(rdp->context);
|
| 696 |
+
if (!ok)
|
| 697 |
+
return FALSE;
|
| 698 |
+
|
| 699 |
+
status = rdp_client_connect(rdp);
|
| 700 |
+
|
| 701 |
+
if (status)
|
| 702 |
+
status = rdp_client_reconnect_channels(rdp, TRUE);
|
| 703 |
+
|
| 704 |
+
return status;
|
| 705 |
+
}
|
| 706 |
+
|
| 707 |
+
BOOL rdp_client_reconnect(rdpRdp* rdp)
|
| 708 |
+
{
|
| 709 |
+
BOOL status = 0;
|
| 710 |
+
|
| 711 |
+
if (!rdp_client_disconnect_and_clear(rdp))
|
| 712 |
+
return FALSE;
|
| 713 |
+
|
| 714 |
+
status = rdp_client_connect(rdp);
|
| 715 |
+
|
| 716 |
+
if (status)
|
| 717 |
+
status = rdp_client_reconnect_channels(rdp, FALSE);
|
| 718 |
+
|
| 719 |
+
return status;
|
| 720 |
+
}
|
| 721 |
+
|
| 722 |
+
static const BYTE fips_ivec[8] = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
|
| 723 |
+
|
| 724 |
+
static BOOL rdp_client_establish_keys(rdpRdp* rdp)
|
| 725 |
+
{
|
| 726 |
+
wStream* s = NULL;
|
| 727 |
+
int status = 0;
|
| 728 |
+
BOOL ret = FALSE;
|
| 729 |
+
|
| 730 |
+
WINPR_ASSERT(rdp);
|
| 731 |
+
rdpSettings* settings = rdp->settings;
|
| 732 |
+
BYTE* crypt_client_random = NULL;
|
| 733 |
+
|
| 734 |
+
WINPR_ASSERT(settings);
|
| 735 |
+
if (!settings->UseRdpSecurityLayer)
|
| 736 |
+
{
|
| 737 |
+
/* no RDP encryption */
|
| 738 |
+
return TRUE;
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT))
|
| 742 |
+
return FALSE;
|
| 743 |
+
|
| 744 |
+
/* encrypt client random */
|
| 745 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ClientRandom, NULL,
|
| 746 |
+
CLIENT_RANDOM_LENGTH))
|
| 747 |
+
return FALSE;
|
| 748 |
+
winpr_RAND(settings->ClientRandom, settings->ClientRandomLength);
|
| 749 |
+
|
| 750 |
+
const rdpCertInfo* info = freerdp_certificate_get_info(settings->RdpServerCertificate);
|
| 751 |
+
if (!info)
|
| 752 |
+
{
|
| 753 |
+
WLog_ERR(TAG, "Failed to get rdpCertInfo from RdpServerCertificate");
|
| 754 |
+
return FALSE;
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
/*
|
| 758 |
+
* client random must be (bitlen / 8) + 8 - see [MS-RDPBCGR] 5.3.4.1
|
| 759 |
+
* for details
|
| 760 |
+
*/
|
| 761 |
+
crypt_client_random = calloc(info->ModulusLength, 1);
|
| 762 |
+
|
| 763 |
+
if (!crypt_client_random)
|
| 764 |
+
return FALSE;
|
| 765 |
+
|
| 766 |
+
crypto_rsa_public_encrypt(settings->ClientRandom, settings->ClientRandomLength, info,
|
| 767 |
+
crypt_client_random, info->ModulusLength);
|
| 768 |
+
/* send crypt client random to server */
|
| 769 |
+
const size_t length = RDP_PACKET_HEADER_MAX_LENGTH + RDP_SECURITY_HEADER_LENGTH + 4ULL +
|
| 770 |
+
info->ModulusLength + 8ULL;
|
| 771 |
+
if (length > UINT16_MAX)
|
| 772 |
+
return FALSE;
|
| 773 |
+
|
| 774 |
+
s = Stream_New(NULL, length);
|
| 775 |
+
|
| 776 |
+
if (!s)
|
| 777 |
+
{
|
| 778 |
+
WLog_ERR(TAG, "Stream_New failed!");
|
| 779 |
+
goto end;
|
| 780 |
+
}
|
| 781 |
+
|
| 782 |
+
if (!rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID))
|
| 783 |
+
goto end;
|
| 784 |
+
if (!rdp_write_security_header(rdp, s, SEC_EXCHANGE_PKT | SEC_LICENSE_ENCRYPT_SC))
|
| 785 |
+
goto end;
|
| 786 |
+
|
| 787 |
+
Stream_Write_UINT32(s, info->ModulusLength + 8);
|
| 788 |
+
Stream_Write(s, crypt_client_random, info->ModulusLength);
|
| 789 |
+
Stream_Zero(s, 8);
|
| 790 |
+
Stream_SealLength(s);
|
| 791 |
+
status = transport_write(rdp->mcs->transport, s);
|
| 792 |
+
|
| 793 |
+
if (status < 0)
|
| 794 |
+
goto end;
|
| 795 |
+
|
| 796 |
+
rdp->do_crypt_license = TRUE;
|
| 797 |
+
|
| 798 |
+
/* now calculate encrypt / decrypt and update keys */
|
| 799 |
+
if (!security_establish_keys(rdp))
|
| 800 |
+
goto end;
|
| 801 |
+
|
| 802 |
+
rdp->do_crypt = TRUE;
|
| 803 |
+
|
| 804 |
+
if (settings->SaltedChecksum)
|
| 805 |
+
rdp->do_secure_checksum = TRUE;
|
| 806 |
+
|
| 807 |
+
if (settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
| 808 |
+
{
|
| 809 |
+
rdp->fips_encrypt =
|
| 810 |
+
winpr_Cipher_NewEx(WINPR_CIPHER_DES_EDE3_CBC, WINPR_ENCRYPT, rdp->fips_encrypt_key,
|
| 811 |
+
sizeof(rdp->fips_encrypt_key), fips_ivec, sizeof(fips_ivec));
|
| 812 |
+
|
| 813 |
+
if (!rdp->fips_encrypt)
|
| 814 |
+
{
|
| 815 |
+
WLog_ERR(TAG, "unable to allocate des3 encrypt key");
|
| 816 |
+
goto end;
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
rdp->fips_decrypt =
|
| 820 |
+
winpr_Cipher_NewEx(WINPR_CIPHER_DES_EDE3_CBC, WINPR_DECRYPT, rdp->fips_decrypt_key,
|
| 821 |
+
sizeof(rdp->fips_decrypt_key), fips_ivec, sizeof(fips_ivec));
|
| 822 |
+
|
| 823 |
+
if (!rdp->fips_decrypt)
|
| 824 |
+
{
|
| 825 |
+
WLog_ERR(TAG, "unable to allocate des3 decrypt key");
|
| 826 |
+
goto end;
|
| 827 |
+
}
|
| 828 |
+
|
| 829 |
+
ret = TRUE;
|
| 830 |
+
goto end;
|
| 831 |
+
}
|
| 832 |
+
|
| 833 |
+
if (!rdp_reset_rc4_encrypt_keys(rdp))
|
| 834 |
+
goto end;
|
| 835 |
+
if (!rdp_reset_rc4_decrypt_keys(rdp))
|
| 836 |
+
goto end;
|
| 837 |
+
|
| 838 |
+
ret = TRUE;
|
| 839 |
+
end:
|
| 840 |
+
Stream_Free(s, TRUE);
|
| 841 |
+
free(crypt_client_random);
|
| 842 |
+
|
| 843 |
+
if (!ret)
|
| 844 |
+
{
|
| 845 |
+
winpr_Cipher_Free(rdp->fips_decrypt);
|
| 846 |
+
winpr_Cipher_Free(rdp->fips_encrypt);
|
| 847 |
+
rdp->fips_decrypt = NULL;
|
| 848 |
+
rdp->fips_encrypt = NULL;
|
| 849 |
+
|
| 850 |
+
rdp_free_rc4_decrypt_keys(rdp);
|
| 851 |
+
rdp_free_rc4_encrypt_keys(rdp);
|
| 852 |
+
}
|
| 853 |
+
|
| 854 |
+
return ret;
|
| 855 |
+
}
|
| 856 |
+
|
| 857 |
+
static BOOL rdp_update_client_random(rdpSettings* settings, const BYTE* crypt_random,
|
| 858 |
+
size_t crypt_random_len)
|
| 859 |
+
{
|
| 860 |
+
const size_t length = 32;
|
| 861 |
+
WINPR_ASSERT(settings);
|
| 862 |
+
|
| 863 |
+
const rdpPrivateKey* rsa = freerdp_settings_get_pointer(settings, FreeRDP_RdpServerRsaKey);
|
| 864 |
+
WINPR_ASSERT(rsa);
|
| 865 |
+
|
| 866 |
+
const rdpCertInfo* cinfo = freerdp_key_get_info(rsa);
|
| 867 |
+
WINPR_ASSERT(cinfo);
|
| 868 |
+
|
| 869 |
+
if (crypt_random_len != cinfo->ModulusLength + 8)
|
| 870 |
+
{
|
| 871 |
+
WLog_ERR(TAG, "invalid encrypted client random length");
|
| 872 |
+
return FALSE;
|
| 873 |
+
}
|
| 874 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ClientRandom, NULL, length))
|
| 875 |
+
return FALSE;
|
| 876 |
+
|
| 877 |
+
BYTE* client_random = freerdp_settings_get_pointer_writable(settings, FreeRDP_ClientRandom);
|
| 878 |
+
WINPR_ASSERT(client_random);
|
| 879 |
+
return crypto_rsa_private_decrypt(crypt_random, crypt_random_len - 8, rsa, client_random,
|
| 880 |
+
length) > 0;
|
| 881 |
+
}
|
| 882 |
+
|
| 883 |
+
BOOL rdp_server_establish_keys(rdpRdp* rdp, wStream* s)
|
| 884 |
+
{
|
| 885 |
+
UINT32 rand_len = 0;
|
| 886 |
+
UINT16 channel_id = 0;
|
| 887 |
+
UINT16 length = 0;
|
| 888 |
+
UINT16 sec_flags = 0;
|
| 889 |
+
BOOL ret = FALSE;
|
| 890 |
+
|
| 891 |
+
WINPR_ASSERT(rdp);
|
| 892 |
+
|
| 893 |
+
if (!rdp->settings->UseRdpSecurityLayer)
|
| 894 |
+
{
|
| 895 |
+
/* No RDP Security. */
|
| 896 |
+
return TRUE;
|
| 897 |
+
}
|
| 898 |
+
|
| 899 |
+
if (!rdp_read_header(rdp, s, &length, &channel_id))
|
| 900 |
+
return FALSE;
|
| 901 |
+
|
| 902 |
+
if (!rdp_read_security_header(rdp, s, &sec_flags, NULL))
|
| 903 |
+
{
|
| 904 |
+
WLog_ERR(TAG, "invalid security header");
|
| 905 |
+
return FALSE;
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
if ((sec_flags & SEC_EXCHANGE_PKT) == 0)
|
| 909 |
+
{
|
| 910 |
+
WLog_ERR(TAG, "missing SEC_EXCHANGE_PKT in security header");
|
| 911 |
+
return FALSE;
|
| 912 |
+
}
|
| 913 |
+
|
| 914 |
+
rdp->do_crypt_license = (sec_flags & SEC_LICENSE_ENCRYPT_SC) != 0 ? TRUE : FALSE;
|
| 915 |
+
|
| 916 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 917 |
+
return FALSE;
|
| 918 |
+
|
| 919 |
+
Stream_Read_UINT32(s, rand_len);
|
| 920 |
+
|
| 921 |
+
/* rand_len already includes 8 bytes of padding */
|
| 922 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, rand_len))
|
| 923 |
+
return FALSE;
|
| 924 |
+
|
| 925 |
+
const BYTE* crypt_random = Stream_ConstPointer(s);
|
| 926 |
+
if (!Stream_SafeSeek(s, rand_len))
|
| 927 |
+
goto end;
|
| 928 |
+
if (!rdp_update_client_random(rdp->settings, crypt_random, rand_len))
|
| 929 |
+
goto end;
|
| 930 |
+
|
| 931 |
+
/* now calculate encrypt / decrypt and update keys */
|
| 932 |
+
if (!security_establish_keys(rdp))
|
| 933 |
+
goto end;
|
| 934 |
+
|
| 935 |
+
rdp->do_crypt = TRUE;
|
| 936 |
+
|
| 937 |
+
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
| 938 |
+
{
|
| 939 |
+
rdp->fips_encrypt =
|
| 940 |
+
winpr_Cipher_NewEx(WINPR_CIPHER_DES_EDE3_CBC, WINPR_ENCRYPT, rdp->fips_encrypt_key,
|
| 941 |
+
sizeof(rdp->fips_encrypt_key), fips_ivec, sizeof(fips_ivec));
|
| 942 |
+
|
| 943 |
+
if (!rdp->fips_encrypt)
|
| 944 |
+
{
|
| 945 |
+
WLog_ERR(TAG, "unable to allocate des3 encrypt key");
|
| 946 |
+
goto end;
|
| 947 |
+
}
|
| 948 |
+
|
| 949 |
+
rdp->fips_decrypt =
|
| 950 |
+
winpr_Cipher_NewEx(WINPR_CIPHER_DES_EDE3_CBC, WINPR_DECRYPT, rdp->fips_decrypt_key,
|
| 951 |
+
sizeof(rdp->fips_decrypt_key), fips_ivec, sizeof(fips_ivec));
|
| 952 |
+
|
| 953 |
+
if (!rdp->fips_decrypt)
|
| 954 |
+
{
|
| 955 |
+
WLog_ERR(TAG, "unable to allocate des3 decrypt key");
|
| 956 |
+
goto end;
|
| 957 |
+
}
|
| 958 |
+
|
| 959 |
+
ret = TRUE;
|
| 960 |
+
goto end;
|
| 961 |
+
}
|
| 962 |
+
|
| 963 |
+
if (!rdp_reset_rc4_encrypt_keys(rdp))
|
| 964 |
+
goto end;
|
| 965 |
+
|
| 966 |
+
if (!rdp_reset_rc4_decrypt_keys(rdp))
|
| 967 |
+
goto end;
|
| 968 |
+
|
| 969 |
+
ret = tpkt_ensure_stream_consumed(s, length);
|
| 970 |
+
end:
|
| 971 |
+
|
| 972 |
+
if (!ret)
|
| 973 |
+
{
|
| 974 |
+
winpr_Cipher_Free(rdp->fips_encrypt);
|
| 975 |
+
winpr_Cipher_Free(rdp->fips_decrypt);
|
| 976 |
+
rdp->fips_encrypt = NULL;
|
| 977 |
+
rdp->fips_decrypt = NULL;
|
| 978 |
+
|
| 979 |
+
rdp_free_rc4_encrypt_keys(rdp);
|
| 980 |
+
rdp_free_rc4_decrypt_keys(rdp);
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
return ret;
|
| 984 |
+
}
|
| 985 |
+
|
| 986 |
+
static BOOL rdp_client_send_client_info_and_change_state(rdpRdp* rdp)
|
| 987 |
+
{
|
| 988 |
+
WINPR_ASSERT(rdp);
|
| 989 |
+
if (!rdp_client_establish_keys(rdp))
|
| 990 |
+
return FALSE;
|
| 991 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE))
|
| 992 |
+
return FALSE;
|
| 993 |
+
if (!rdp_send_client_info(rdp))
|
| 994 |
+
return FALSE;
|
| 995 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_REQUEST))
|
| 996 |
+
return FALSE;
|
| 997 |
+
return TRUE;
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
BOOL rdp_client_skip_mcs_channel_join(rdpRdp* rdp)
|
| 1001 |
+
{
|
| 1002 |
+
WINPR_ASSERT(rdp);
|
| 1003 |
+
|
| 1004 |
+
rdpMcs* mcs = rdp->mcs;
|
| 1005 |
+
WINPR_ASSERT(mcs);
|
| 1006 |
+
|
| 1007 |
+
mcs->userChannelJoined = TRUE;
|
| 1008 |
+
mcs->globalChannelJoined = TRUE;
|
| 1009 |
+
mcs->messageChannelJoined = TRUE;
|
| 1010 |
+
|
| 1011 |
+
for (UINT32 i = 0; i < mcs->channelCount; i++)
|
| 1012 |
+
{
|
| 1013 |
+
rdpMcsChannel* cur = &mcs->channels[i];
|
| 1014 |
+
WLog_DBG(TAG, " %s [%" PRIu16 "]", cur->Name, cur->ChannelId);
|
| 1015 |
+
cur->joined = TRUE;
|
| 1016 |
+
}
|
| 1017 |
+
|
| 1018 |
+
return rdp_client_send_client_info_and_change_state(rdp);
|
| 1019 |
+
}
|
| 1020 |
+
|
| 1021 |
+
static BOOL rdp_client_join_channel(rdpRdp* rdp, UINT16 ChannelId)
|
| 1022 |
+
{
|
| 1023 |
+
WINPR_ASSERT(rdp);
|
| 1024 |
+
|
| 1025 |
+
rdpMcs* mcs = rdp->mcs;
|
| 1026 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_MCS_CHANNEL_JOIN_REQUEST))
|
| 1027 |
+
return FALSE;
|
| 1028 |
+
if (!mcs_send_channel_join_request(mcs, ChannelId))
|
| 1029 |
+
return FALSE;
|
| 1030 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_MCS_CHANNEL_JOIN_RESPONSE))
|
| 1031 |
+
return FALSE;
|
| 1032 |
+
return TRUE;
|
| 1033 |
+
}
|
| 1034 |
+
|
| 1035 |
+
BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
|
| 1036 |
+
{
|
| 1037 |
+
UINT16 channelId = 0;
|
| 1038 |
+
BOOL allJoined = TRUE;
|
| 1039 |
+
|
| 1040 |
+
WINPR_ASSERT(rdp);
|
| 1041 |
+
rdpMcs* mcs = rdp->mcs;
|
| 1042 |
+
|
| 1043 |
+
if (!mcs_recv_channel_join_confirm(mcs, s, &channelId))
|
| 1044 |
+
return FALSE;
|
| 1045 |
+
|
| 1046 |
+
if (!mcs->userChannelJoined)
|
| 1047 |
+
{
|
| 1048 |
+
if (channelId != mcs->userId)
|
| 1049 |
+
{
|
| 1050 |
+
WLog_ERR(TAG, "expected user channel id %" PRIu16 ", but received %" PRIu16,
|
| 1051 |
+
mcs->userId, channelId);
|
| 1052 |
+
return FALSE;
|
| 1053 |
+
}
|
| 1054 |
+
|
| 1055 |
+
mcs->userChannelJoined = TRUE;
|
| 1056 |
+
if (!rdp_client_join_channel(rdp, MCS_GLOBAL_CHANNEL_ID))
|
| 1057 |
+
return FALSE;
|
| 1058 |
+
}
|
| 1059 |
+
else if (!mcs->globalChannelJoined)
|
| 1060 |
+
{
|
| 1061 |
+
if (channelId != MCS_GLOBAL_CHANNEL_ID)
|
| 1062 |
+
{
|
| 1063 |
+
WLog_ERR(TAG, "expected uglobalser channel id %" PRIu16 ", but received %" PRIu16,
|
| 1064 |
+
MCS_GLOBAL_CHANNEL_ID, channelId);
|
| 1065 |
+
return FALSE;
|
| 1066 |
+
}
|
| 1067 |
+
mcs->globalChannelJoined = TRUE;
|
| 1068 |
+
|
| 1069 |
+
if (mcs->messageChannelId != 0)
|
| 1070 |
+
{
|
| 1071 |
+
if (!rdp_client_join_channel(rdp, mcs->messageChannelId))
|
| 1072 |
+
return FALSE;
|
| 1073 |
+
allJoined = FALSE;
|
| 1074 |
+
}
|
| 1075 |
+
else
|
| 1076 |
+
{
|
| 1077 |
+
if (mcs->channelCount > 0)
|
| 1078 |
+
{
|
| 1079 |
+
const rdpMcsChannel* cur = &mcs->channels[0];
|
| 1080 |
+
if (!rdp_client_join_channel(rdp, cur->ChannelId))
|
| 1081 |
+
return FALSE;
|
| 1082 |
+
allJoined = FALSE;
|
| 1083 |
+
}
|
| 1084 |
+
}
|
| 1085 |
+
}
|
| 1086 |
+
else if ((mcs->messageChannelId != 0) && !mcs->messageChannelJoined)
|
| 1087 |
+
{
|
| 1088 |
+
if (channelId != mcs->messageChannelId)
|
| 1089 |
+
{
|
| 1090 |
+
WLog_ERR(TAG, "expected messageChannelId=%" PRIu16 ", got %" PRIu16,
|
| 1091 |
+
mcs->messageChannelId, channelId);
|
| 1092 |
+
return FALSE;
|
| 1093 |
+
}
|
| 1094 |
+
|
| 1095 |
+
mcs->messageChannelJoined = TRUE;
|
| 1096 |
+
|
| 1097 |
+
if (mcs->channelCount > 0)
|
| 1098 |
+
{
|
| 1099 |
+
const rdpMcsChannel* cur = &mcs->channels[0];
|
| 1100 |
+
if (!rdp_client_join_channel(rdp, cur->ChannelId))
|
| 1101 |
+
return FALSE;
|
| 1102 |
+
allJoined = FALSE;
|
| 1103 |
+
}
|
| 1104 |
+
}
|
| 1105 |
+
else
|
| 1106 |
+
{
|
| 1107 |
+
UINT32 i = 0;
|
| 1108 |
+
for (; i < mcs->channelCount; i++)
|
| 1109 |
+
{
|
| 1110 |
+
rdpMcsChannel* cur = &mcs->channels[i];
|
| 1111 |
+
if (cur->joined)
|
| 1112 |
+
continue;
|
| 1113 |
+
|
| 1114 |
+
if (cur->ChannelId != channelId)
|
| 1115 |
+
{
|
| 1116 |
+
WLog_ERR(TAG, "expected channel id %" PRIu16 ", but received %" PRIu16,
|
| 1117 |
+
MCS_GLOBAL_CHANNEL_ID, channelId);
|
| 1118 |
+
return FALSE;
|
| 1119 |
+
}
|
| 1120 |
+
cur->joined = TRUE;
|
| 1121 |
+
break;
|
| 1122 |
+
}
|
| 1123 |
+
|
| 1124 |
+
if (i + 1 < mcs->channelCount)
|
| 1125 |
+
{
|
| 1126 |
+
const rdpMcsChannel* cur = &mcs->channels[i + 1];
|
| 1127 |
+
if (!rdp_client_join_channel(rdp, cur->ChannelId))
|
| 1128 |
+
return FALSE;
|
| 1129 |
+
allJoined = FALSE;
|
| 1130 |
+
}
|
| 1131 |
+
}
|
| 1132 |
+
|
| 1133 |
+
if (mcs->userChannelJoined && mcs->globalChannelJoined && allJoined)
|
| 1134 |
+
{
|
| 1135 |
+
if (!rdp_client_send_client_info_and_change_state(rdp))
|
| 1136 |
+
return FALSE;
|
| 1137 |
+
}
|
| 1138 |
+
|
| 1139 |
+
return TRUE;
|
| 1140 |
+
}
|
| 1141 |
+
|
| 1142 |
+
BOOL rdp_handle_message_channel(rdpRdp* rdp, wStream* s, UINT16 channelId, UINT16 length)
|
| 1143 |
+
{
|
| 1144 |
+
WINPR_ASSERT(rdp);
|
| 1145 |
+
WINPR_ASSERT(rdp->mcs);
|
| 1146 |
+
|
| 1147 |
+
if (!rdp->mcs->messageChannelJoined)
|
| 1148 |
+
{
|
| 1149 |
+
WLog_Print(rdp->log, WLOG_WARN, "MCS message channel not joined!");
|
| 1150 |
+
return FALSE;
|
| 1151 |
+
}
|
| 1152 |
+
const UINT16 messageChannelId = rdp->mcs->messageChannelId;
|
| 1153 |
+
if (messageChannelId == 0)
|
| 1154 |
+
{
|
| 1155 |
+
WLog_Print(rdp->log, WLOG_WARN, "MCS message channel id == 0");
|
| 1156 |
+
return FALSE;
|
| 1157 |
+
}
|
| 1158 |
+
|
| 1159 |
+
if (channelId != messageChannelId)
|
| 1160 |
+
{
|
| 1161 |
+
WLog_Print(rdp->log, WLOG_WARN, "MCS message channel expected id=%" PRIu16 ", got %" PRIu16,
|
| 1162 |
+
messageChannelId, channelId);
|
| 1163 |
+
return FALSE;
|
| 1164 |
+
}
|
| 1165 |
+
|
| 1166 |
+
UINT16 securityFlags = 0;
|
| 1167 |
+
if (!rdp_read_security_header(rdp, s, &securityFlags, &length))
|
| 1168 |
+
return FALSE;
|
| 1169 |
+
|
| 1170 |
+
if (securityFlags & SEC_ENCRYPT)
|
| 1171 |
+
{
|
| 1172 |
+
if (!rdp_decrypt(rdp, s, &length, securityFlags))
|
| 1173 |
+
return FALSE;
|
| 1174 |
+
}
|
| 1175 |
+
|
| 1176 |
+
if (rdp_recv_message_channel_pdu(rdp, s, securityFlags) != STATE_RUN_SUCCESS)
|
| 1177 |
+
return FALSE;
|
| 1178 |
+
|
| 1179 |
+
return tpkt_ensure_stream_consumed(s, length);
|
| 1180 |
+
}
|
| 1181 |
+
|
| 1182 |
+
BOOL rdp_client_connect_auto_detect(rdpRdp* rdp, wStream* s)
|
| 1183 |
+
{
|
| 1184 |
+
WINPR_ASSERT(rdp);
|
| 1185 |
+
WINPR_ASSERT(rdp->mcs);
|
| 1186 |
+
|
| 1187 |
+
const size_t pos = Stream_GetPosition(s);
|
| 1188 |
+
UINT16 length = 0;
|
| 1189 |
+
UINT16 channelId = 0;
|
| 1190 |
+
|
| 1191 |
+
if (rdp_read_header(rdp, s, &length, &channelId))
|
| 1192 |
+
{
|
| 1193 |
+
const UINT16 messageChannelId = rdp->mcs->messageChannelId;
|
| 1194 |
+
/* If the MCS message channel has been joined... */
|
| 1195 |
+
|
| 1196 |
+
/* Process any MCS message channel PDUs. */
|
| 1197 |
+
if (rdp->mcs->messageChannelJoined && (channelId == messageChannelId))
|
| 1198 |
+
{
|
| 1199 |
+
if (rdp_handle_message_channel(rdp, s, channelId, length))
|
| 1200 |
+
return TRUE;
|
| 1201 |
+
}
|
| 1202 |
+
else
|
| 1203 |
+
{
|
| 1204 |
+
WLog_WARN(TAG, "expected messageChannelId=%" PRIu16 ", got %" PRIu16, messageChannelId,
|
| 1205 |
+
channelId);
|
| 1206 |
+
}
|
| 1207 |
+
}
|
| 1208 |
+
|
| 1209 |
+
Stream_SetPosition(s, pos);
|
| 1210 |
+
return FALSE;
|
| 1211 |
+
}
|
| 1212 |
+
|
| 1213 |
+
state_run_t rdp_client_connect_license(rdpRdp* rdp, wStream* s)
|
| 1214 |
+
{
|
| 1215 |
+
state_run_t status = STATE_RUN_FAILED;
|
| 1216 |
+
LICENSE_STATE state = LICENSE_STATE_ABORTED;
|
| 1217 |
+
UINT16 length = 0;
|
| 1218 |
+
UINT16 channelId = 0;
|
| 1219 |
+
UINT16 securityFlags = 0;
|
| 1220 |
+
|
| 1221 |
+
WINPR_ASSERT(rdp);
|
| 1222 |
+
if (!rdp_read_header(rdp, s, &length, &channelId))
|
| 1223 |
+
return STATE_RUN_FAILED;
|
| 1224 |
+
|
| 1225 |
+
/* there might be autodetect messages mixed in between licensing messages.
|
| 1226 |
+
* that has been observed with 2k12 R2 and 2k19
|
| 1227 |
+
*/
|
| 1228 |
+
const UINT16 messageChannelId = rdp->mcs->messageChannelId;
|
| 1229 |
+
if (rdp->mcs->messageChannelJoined && (channelId == messageChannelId))
|
| 1230 |
+
{
|
| 1231 |
+
if (!rdp_handle_message_channel(rdp, s, channelId, length))
|
| 1232 |
+
return STATE_RUN_FAILED;
|
| 1233 |
+
return STATE_RUN_SUCCESS;
|
| 1234 |
+
}
|
| 1235 |
+
|
| 1236 |
+
if (!rdp_read_security_header(rdp, s, &securityFlags, &length))
|
| 1237 |
+
return STATE_RUN_FAILED;
|
| 1238 |
+
|
| 1239 |
+
if (securityFlags & SEC_ENCRYPT)
|
| 1240 |
+
{
|
| 1241 |
+
if (!rdp_decrypt(rdp, s, &length, securityFlags))
|
| 1242 |
+
return STATE_RUN_FAILED;
|
| 1243 |
+
}
|
| 1244 |
+
|
| 1245 |
+
if (channelId != MCS_GLOBAL_CHANNEL_ID)
|
| 1246 |
+
WLog_WARN(TAG, "unexpected message for channel %u, expected %u", channelId,
|
| 1247 |
+
MCS_GLOBAL_CHANNEL_ID);
|
| 1248 |
+
|
| 1249 |
+
if ((securityFlags & SEC_LICENSE_PKT) == 0)
|
| 1250 |
+
{
|
| 1251 |
+
char buffer[512] = { 0 };
|
| 1252 |
+
char lbuffer[32] = { 0 };
|
| 1253 |
+
WLog_ERR(TAG, "securityFlags=%s, missing required flag %s",
|
| 1254 |
+
rdp_security_flag_string(securityFlags, buffer, sizeof(buffer)),
|
| 1255 |
+
rdp_security_flag_string(SEC_LICENSE_PKT, lbuffer, sizeof(lbuffer)));
|
| 1256 |
+
return STATE_RUN_FAILED;
|
| 1257 |
+
}
|
| 1258 |
+
|
| 1259 |
+
status = license_recv(rdp->license, s);
|
| 1260 |
+
|
| 1261 |
+
if (state_run_failed(status))
|
| 1262 |
+
return status;
|
| 1263 |
+
|
| 1264 |
+
state = license_get_state(rdp->license);
|
| 1265 |
+
switch (state)
|
| 1266 |
+
{
|
| 1267 |
+
case LICENSE_STATE_ABORTED:
|
| 1268 |
+
WLog_ERR(TAG, "license connection sequence aborted.");
|
| 1269 |
+
return STATE_RUN_FAILED;
|
| 1270 |
+
case LICENSE_STATE_COMPLETED:
|
| 1271 |
+
if (rdp->settings->MultitransportFlags)
|
| 1272 |
+
{
|
| 1273 |
+
if (!rdp_client_transition_to_state(
|
| 1274 |
+
rdp, CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_REQUEST))
|
| 1275 |
+
return STATE_RUN_FAILED;
|
| 1276 |
+
}
|
| 1277 |
+
else
|
| 1278 |
+
{
|
| 1279 |
+
if (!rdp_client_transition_to_state(
|
| 1280 |
+
rdp, CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE))
|
| 1281 |
+
return STATE_RUN_FAILED;
|
| 1282 |
+
}
|
| 1283 |
+
return STATE_RUN_SUCCESS;
|
| 1284 |
+
default:
|
| 1285 |
+
return STATE_RUN_SUCCESS;
|
| 1286 |
+
}
|
| 1287 |
+
}
|
| 1288 |
+
|
| 1289 |
+
state_run_t rdp_client_connect_demand_active(rdpRdp* rdp, wStream* s)
|
| 1290 |
+
{
|
| 1291 |
+
UINT16 length = 0;
|
| 1292 |
+
UINT16 channelId = 0;
|
| 1293 |
+
UINT16 pduType = 0;
|
| 1294 |
+
UINT16 pduSource = 0;
|
| 1295 |
+
|
| 1296 |
+
WINPR_ASSERT(rdp);
|
| 1297 |
+
WINPR_ASSERT(s);
|
| 1298 |
+
WINPR_ASSERT(rdp->settings);
|
| 1299 |
+
|
| 1300 |
+
if (!rdp_recv_get_active_header(rdp, s, &channelId, &length))
|
| 1301 |
+
return STATE_RUN_FAILED;
|
| 1302 |
+
|
| 1303 |
+
if (freerdp_shall_disconnect_context(rdp->context))
|
| 1304 |
+
return STATE_RUN_QUIT_SESSION;
|
| 1305 |
+
|
| 1306 |
+
if (rdp->mcs->messageChannelId && (channelId == rdp->mcs->messageChannelId))
|
| 1307 |
+
{
|
| 1308 |
+
rdp->inPackets++;
|
| 1309 |
+
if (!rdp_handle_message_channel(rdp, s, channelId, length))
|
| 1310 |
+
return STATE_RUN_FAILED;
|
| 1311 |
+
return STATE_RUN_SUCCESS;
|
| 1312 |
+
}
|
| 1313 |
+
|
| 1314 |
+
if (!rdp_handle_optional_rdp_decryption(rdp, s, &length, NULL))
|
| 1315 |
+
return STATE_RUN_FAILED;
|
| 1316 |
+
|
| 1317 |
+
if (!rdp_read_share_control_header(rdp, s, NULL, NULL, &pduType, &pduSource))
|
| 1318 |
+
return STATE_RUN_FAILED;
|
| 1319 |
+
|
| 1320 |
+
switch (pduType)
|
| 1321 |
+
{
|
| 1322 |
+
case PDU_TYPE_DEMAND_ACTIVE:
|
| 1323 |
+
if (!rdp_recv_demand_active(rdp, s, pduSource, length))
|
| 1324 |
+
return STATE_RUN_FAILED;
|
| 1325 |
+
return STATE_RUN_ACTIVE;
|
| 1326 |
+
default:
|
| 1327 |
+
return rdp_recv_out_of_sequence_pdu(rdp, s, pduType, length);
|
| 1328 |
+
}
|
| 1329 |
+
}
|
| 1330 |
+
|
| 1331 |
+
state_run_t rdp_client_connect_finalize(rdpRdp* rdp)
|
| 1332 |
+
{
|
| 1333 |
+
WINPR_ASSERT(rdp);
|
| 1334 |
+
/**
|
| 1335 |
+
* [MS-RDPBCGR] 1.3.1.1 - 8.
|
| 1336 |
+
* The client-to-server PDUs sent during this phase have no dependencies on any of the
|
| 1337 |
+
* server-to- client PDUs; they may be sent as a single batch, provided that sequencing is
|
| 1338 |
+
* maintained.
|
| 1339 |
+
*/
|
| 1340 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_SYNC))
|
| 1341 |
+
return STATE_RUN_FAILED;
|
| 1342 |
+
|
| 1343 |
+
if (!rdp_send_client_synchronize_pdu(rdp))
|
| 1344 |
+
return STATE_RUN_FAILED;
|
| 1345 |
+
|
| 1346 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_COOPERATE))
|
| 1347 |
+
return STATE_RUN_FAILED;
|
| 1348 |
+
if (!rdp_send_client_control_pdu(rdp, CTRLACTION_COOPERATE))
|
| 1349 |
+
return STATE_RUN_FAILED;
|
| 1350 |
+
|
| 1351 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_REQUEST_CONTROL))
|
| 1352 |
+
return STATE_RUN_FAILED;
|
| 1353 |
+
if (!rdp_send_client_control_pdu(rdp, CTRLACTION_REQUEST_CONTROL))
|
| 1354 |
+
return STATE_RUN_FAILED;
|
| 1355 |
+
|
| 1356 |
+
/**
|
| 1357 |
+
* [MS-RDPBCGR] 2.2.1.17
|
| 1358 |
+
* Client persistent key list must be sent if a bitmap is
|
| 1359 |
+
* stored in persistent bitmap cache or the server has advertised support for bitmap
|
| 1360 |
+
* host cache and a deactivation reactivation sequence is *not* in progress.
|
| 1361 |
+
*/
|
| 1362 |
+
|
| 1363 |
+
if (!rdp_finalize_is_flag_set(rdp, FINALIZE_DEACTIVATE_REACTIVATE) &&
|
| 1364 |
+
freerdp_settings_get_bool(rdp->settings, FreeRDP_BitmapCachePersistEnabled))
|
| 1365 |
+
{
|
| 1366 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_PERSISTENT_KEY_LIST))
|
| 1367 |
+
return STATE_RUN_FAILED;
|
| 1368 |
+
if (!rdp_send_client_persistent_key_list_pdu(rdp))
|
| 1369 |
+
return STATE_RUN_FAILED;
|
| 1370 |
+
}
|
| 1371 |
+
|
| 1372 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_FONT_LIST))
|
| 1373 |
+
return STATE_RUN_FAILED;
|
| 1374 |
+
if (!rdp_send_client_font_list_pdu(rdp, FONTLIST_FIRST | FONTLIST_LAST))
|
| 1375 |
+
return STATE_RUN_FAILED;
|
| 1376 |
+
|
| 1377 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_CLIENT_SYNC))
|
| 1378 |
+
return STATE_RUN_FAILED;
|
| 1379 |
+
return STATE_RUN_SUCCESS;
|
| 1380 |
+
}
|
| 1381 |
+
|
| 1382 |
+
BOOL rdp_client_transition_to_state(rdpRdp* rdp, CONNECTION_STATE state)
|
| 1383 |
+
{
|
| 1384 |
+
const char* name = rdp_state_string(state);
|
| 1385 |
+
|
| 1386 |
+
WINPR_ASSERT(rdp);
|
| 1387 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "%s --> %s", rdp_get_state_string(rdp), name);
|
| 1388 |
+
|
| 1389 |
+
if (!rdp_set_state(rdp, state))
|
| 1390 |
+
return FALSE;
|
| 1391 |
+
|
| 1392 |
+
switch (state)
|
| 1393 |
+
{
|
| 1394 |
+
case CONNECTION_STATE_FINALIZATION_SYNC:
|
| 1395 |
+
case CONNECTION_STATE_FINALIZATION_COOPERATE:
|
| 1396 |
+
case CONNECTION_STATE_FINALIZATION_REQUEST_CONTROL:
|
| 1397 |
+
case CONNECTION_STATE_FINALIZATION_PERSISTENT_KEY_LIST:
|
| 1398 |
+
case CONNECTION_STATE_FINALIZATION_FONT_LIST:
|
| 1399 |
+
update_reset_state(rdp->update);
|
| 1400 |
+
break;
|
| 1401 |
+
|
| 1402 |
+
case CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE:
|
| 1403 |
+
{
|
| 1404 |
+
ActivatedEventArgs activatedEvent = { 0 };
|
| 1405 |
+
rdpContext* context = rdp->context;
|
| 1406 |
+
EventArgsInit(&activatedEvent, "libfreerdp");
|
| 1407 |
+
activatedEvent.firstActivation =
|
| 1408 |
+
!rdp_finalize_is_flag_set(rdp, FINALIZE_DEACTIVATE_REACTIVATE);
|
| 1409 |
+
PubSub_OnActivated(rdp->pubSub, context, &activatedEvent);
|
| 1410 |
+
}
|
| 1411 |
+
|
| 1412 |
+
break;
|
| 1413 |
+
|
| 1414 |
+
default:
|
| 1415 |
+
break;
|
| 1416 |
+
}
|
| 1417 |
+
|
| 1418 |
+
{
|
| 1419 |
+
ConnectionStateChangeEventArgs stateEvent = { 0 };
|
| 1420 |
+
rdpContext* context = rdp->context;
|
| 1421 |
+
EventArgsInit(&stateEvent, "libfreerdp");
|
| 1422 |
+
stateEvent.state = WINPR_ASSERTING_INT_CAST(int32_t, rdp_get_state(rdp));
|
| 1423 |
+
stateEvent.active = rdp_is_active_state(rdp);
|
| 1424 |
+
PubSub_OnConnectionStateChange(rdp->pubSub, context, &stateEvent);
|
| 1425 |
+
}
|
| 1426 |
+
|
| 1427 |
+
return TRUE;
|
| 1428 |
+
}
|
| 1429 |
+
|
| 1430 |
+
BOOL rdp_server_accept_nego(rdpRdp* rdp, wStream* s)
|
| 1431 |
+
{
|
| 1432 |
+
UINT32 SelectedProtocol = 0;
|
| 1433 |
+
UINT32 RequestedProtocols = 0;
|
| 1434 |
+
BOOL status = 0;
|
| 1435 |
+
rdpSettings* settings = NULL;
|
| 1436 |
+
rdpNego* nego = NULL;
|
| 1437 |
+
|
| 1438 |
+
WINPR_ASSERT(rdp);
|
| 1439 |
+
WINPR_ASSERT(s);
|
| 1440 |
+
|
| 1441 |
+
settings = rdp->settings;
|
| 1442 |
+
WINPR_ASSERT(settings);
|
| 1443 |
+
|
| 1444 |
+
nego = rdp->nego;
|
| 1445 |
+
WINPR_ASSERT(nego);
|
| 1446 |
+
|
| 1447 |
+
transport_set_blocking_mode(rdp->transport, TRUE);
|
| 1448 |
+
|
| 1449 |
+
if (!nego_read_request(nego, s))
|
| 1450 |
+
return FALSE;
|
| 1451 |
+
|
| 1452 |
+
RequestedProtocols = nego_get_requested_protocols(nego);
|
| 1453 |
+
WLog_DBG(TAG, "Client Security: RDSTLS:%d NLA:%d TLS:%d RDP:%d",
|
| 1454 |
+
(RequestedProtocols & PROTOCOL_RDSTLS) ? 1 : 0,
|
| 1455 |
+
(RequestedProtocols & PROTOCOL_HYBRID) ? 1 : 0,
|
| 1456 |
+
(RequestedProtocols & PROTOCOL_SSL) ? 1 : 0,
|
| 1457 |
+
(RequestedProtocols == PROTOCOL_RDP) ? 1 : 0);
|
| 1458 |
+
WLog_DBG(TAG,
|
| 1459 |
+
"Server Security: RDSTLS:%" PRId32 " NLA:%" PRId32 " TLS:%" PRId32 " RDP:%" PRId32 "",
|
| 1460 |
+
settings->RdstlsSecurity, settings->NlaSecurity, settings->TlsSecurity,
|
| 1461 |
+
settings->RdpSecurity);
|
| 1462 |
+
|
| 1463 |
+
if ((settings->RdstlsSecurity) && (RequestedProtocols & PROTOCOL_RDSTLS))
|
| 1464 |
+
{
|
| 1465 |
+
SelectedProtocol = PROTOCOL_RDSTLS;
|
| 1466 |
+
}
|
| 1467 |
+
else if ((settings->NlaSecurity) && (RequestedProtocols & PROTOCOL_HYBRID))
|
| 1468 |
+
{
|
| 1469 |
+
SelectedProtocol = PROTOCOL_HYBRID;
|
| 1470 |
+
}
|
| 1471 |
+
else if ((settings->TlsSecurity) && (RequestedProtocols & PROTOCOL_SSL))
|
| 1472 |
+
{
|
| 1473 |
+
SelectedProtocol = PROTOCOL_SSL;
|
| 1474 |
+
}
|
| 1475 |
+
else if ((settings->RdpSecurity) && (RequestedProtocols == PROTOCOL_RDP))
|
| 1476 |
+
{
|
| 1477 |
+
SelectedProtocol = PROTOCOL_RDP;
|
| 1478 |
+
}
|
| 1479 |
+
else
|
| 1480 |
+
{
|
| 1481 |
+
/*
|
| 1482 |
+
* when here client and server aren't compatible, we select the right
|
| 1483 |
+
* error message to return to the client in the nego failure packet
|
| 1484 |
+
*/
|
| 1485 |
+
SelectedProtocol = PROTOCOL_FAILED_NEGO;
|
| 1486 |
+
|
| 1487 |
+
if (settings->RdpSecurity)
|
| 1488 |
+
{
|
| 1489 |
+
WLog_ERR(TAG, "server supports only Standard RDP Security");
|
| 1490 |
+
SelectedProtocol |= SSL_NOT_ALLOWED_BY_SERVER;
|
| 1491 |
+
}
|
| 1492 |
+
else
|
| 1493 |
+
{
|
| 1494 |
+
if (settings->NlaSecurity && !settings->TlsSecurity)
|
| 1495 |
+
{
|
| 1496 |
+
WLog_WARN(TAG, "server supports only NLA Security");
|
| 1497 |
+
SelectedProtocol |= HYBRID_REQUIRED_BY_SERVER;
|
| 1498 |
+
}
|
| 1499 |
+
else
|
| 1500 |
+
{
|
| 1501 |
+
WLog_WARN(TAG, "server supports only a SSL based Security (TLS or NLA)");
|
| 1502 |
+
SelectedProtocol |= SSL_REQUIRED_BY_SERVER;
|
| 1503 |
+
}
|
| 1504 |
+
}
|
| 1505 |
+
|
| 1506 |
+
WLog_ERR(TAG, "Protocol security negotiation failure");
|
| 1507 |
+
}
|
| 1508 |
+
|
| 1509 |
+
if (!(SelectedProtocol & PROTOCOL_FAILED_NEGO))
|
| 1510 |
+
{
|
| 1511 |
+
WLog_DBG(TAG, "Negotiated Security: RDSTLS:%d NLA:%d TLS:%d RDP:%d",
|
| 1512 |
+
(SelectedProtocol & PROTOCOL_RDSTLS) ? 1 : 0,
|
| 1513 |
+
(SelectedProtocol & PROTOCOL_HYBRID) ? 1 : 0,
|
| 1514 |
+
(SelectedProtocol & PROTOCOL_SSL) ? 1 : 0,
|
| 1515 |
+
(SelectedProtocol == PROTOCOL_RDP) ? 1 : 0);
|
| 1516 |
+
}
|
| 1517 |
+
|
| 1518 |
+
if (!nego_set_selected_protocol(nego, SelectedProtocol))
|
| 1519 |
+
return FALSE;
|
| 1520 |
+
|
| 1521 |
+
if (!nego_send_negotiation_response(nego))
|
| 1522 |
+
return FALSE;
|
| 1523 |
+
|
| 1524 |
+
SelectedProtocol = nego_get_selected_protocol(nego);
|
| 1525 |
+
status = FALSE;
|
| 1526 |
+
|
| 1527 |
+
if (SelectedProtocol & PROTOCOL_RDSTLS)
|
| 1528 |
+
status = transport_accept_rdstls(rdp->transport);
|
| 1529 |
+
else if (SelectedProtocol & PROTOCOL_HYBRID)
|
| 1530 |
+
status = transport_accept_nla(rdp->transport);
|
| 1531 |
+
else if (SelectedProtocol & PROTOCOL_SSL)
|
| 1532 |
+
status = transport_accept_tls(rdp->transport);
|
| 1533 |
+
else if (SelectedProtocol == PROTOCOL_RDP) /* 0 */
|
| 1534 |
+
status = transport_accept_rdp(rdp->transport);
|
| 1535 |
+
|
| 1536 |
+
if (!status)
|
| 1537 |
+
return FALSE;
|
| 1538 |
+
|
| 1539 |
+
transport_set_blocking_mode(rdp->transport, FALSE);
|
| 1540 |
+
|
| 1541 |
+
return TRUE;
|
| 1542 |
+
}
|
| 1543 |
+
|
| 1544 |
+
static BOOL rdp_update_encryption_level(rdpSettings* settings)
|
| 1545 |
+
{
|
| 1546 |
+
WINPR_ASSERT(settings);
|
| 1547 |
+
|
| 1548 |
+
UINT32 EncryptionLevel = freerdp_settings_get_uint32(settings, FreeRDP_EncryptionLevel);
|
| 1549 |
+
UINT32 EncryptionMethods = freerdp_settings_get_uint32(settings, FreeRDP_EncryptionMethods);
|
| 1550 |
+
|
| 1551 |
+
/**
|
| 1552 |
+
* Re: settings->EncryptionLevel:
|
| 1553 |
+
* This is configured/set by the server implementation and serves the same
|
| 1554 |
+
* purpose as the "Encryption Level" setting in the RDP-Tcp configuration
|
| 1555 |
+
* dialog of Microsoft's Remote Desktop Session Host Configuration.
|
| 1556 |
+
* Re: settings->EncryptionMethods:
|
| 1557 |
+
* at this point this setting contains the client's supported encryption
|
| 1558 |
+
* methods we've received in gcc_read_client_security_data()
|
| 1559 |
+
*/
|
| 1560 |
+
|
| 1561 |
+
if (!settings->UseRdpSecurityLayer)
|
| 1562 |
+
{
|
| 1563 |
+
/* TLS/NLA is used: disable rdp style encryption */
|
| 1564 |
+
EncryptionLevel = ENCRYPTION_LEVEL_NONE;
|
| 1565 |
+
}
|
| 1566 |
+
else
|
| 1567 |
+
{
|
| 1568 |
+
/* verify server encryption level value */
|
| 1569 |
+
switch (EncryptionLevel)
|
| 1570 |
+
{
|
| 1571 |
+
case ENCRYPTION_LEVEL_NONE:
|
| 1572 |
+
WLog_INFO(TAG, "Active rdp encryption level: NONE");
|
| 1573 |
+
break;
|
| 1574 |
+
|
| 1575 |
+
case ENCRYPTION_LEVEL_FIPS:
|
| 1576 |
+
WLog_INFO(TAG, "Active rdp encryption level: FIPS Compliant");
|
| 1577 |
+
break;
|
| 1578 |
+
|
| 1579 |
+
case ENCRYPTION_LEVEL_HIGH:
|
| 1580 |
+
WLog_INFO(TAG, "Active rdp encryption level: HIGH");
|
| 1581 |
+
break;
|
| 1582 |
+
|
| 1583 |
+
case ENCRYPTION_LEVEL_LOW:
|
| 1584 |
+
WLog_INFO(TAG, "Active rdp encryption level: LOW");
|
| 1585 |
+
break;
|
| 1586 |
+
|
| 1587 |
+
case ENCRYPTION_LEVEL_CLIENT_COMPATIBLE:
|
| 1588 |
+
WLog_INFO(TAG, "Active rdp encryption level: CLIENT-COMPATIBLE");
|
| 1589 |
+
break;
|
| 1590 |
+
|
| 1591 |
+
default:
|
| 1592 |
+
WLog_ERR(TAG, "Invalid server encryption level 0x%08" PRIX32 "", EncryptionLevel);
|
| 1593 |
+
WLog_ERR(TAG, "Switching to encryption level CLIENT-COMPATIBLE");
|
| 1594 |
+
EncryptionLevel = ENCRYPTION_LEVEL_CLIENT_COMPATIBLE;
|
| 1595 |
+
}
|
| 1596 |
+
}
|
| 1597 |
+
|
| 1598 |
+
/* choose rdp encryption method based on server level and client methods */
|
| 1599 |
+
switch (EncryptionLevel)
|
| 1600 |
+
{
|
| 1601 |
+
case ENCRYPTION_LEVEL_NONE:
|
| 1602 |
+
/* The only valid method is NONE in this case */
|
| 1603 |
+
EncryptionMethods = ENCRYPTION_METHOD_NONE;
|
| 1604 |
+
break;
|
| 1605 |
+
|
| 1606 |
+
case ENCRYPTION_LEVEL_FIPS:
|
| 1607 |
+
|
| 1608 |
+
/* The only valid method is FIPS in this case */
|
| 1609 |
+
if (!(EncryptionMethods & ENCRYPTION_METHOD_FIPS))
|
| 1610 |
+
{
|
| 1611 |
+
WLog_WARN(TAG, "client does not support FIPS as required by server configuration");
|
| 1612 |
+
}
|
| 1613 |
+
|
| 1614 |
+
EncryptionMethods = ENCRYPTION_METHOD_FIPS;
|
| 1615 |
+
break;
|
| 1616 |
+
|
| 1617 |
+
case ENCRYPTION_LEVEL_HIGH:
|
| 1618 |
+
|
| 1619 |
+
/* Maximum key strength supported by the server must be used (128 bit)*/
|
| 1620 |
+
if (!(EncryptionMethods & ENCRYPTION_METHOD_128BIT))
|
| 1621 |
+
{
|
| 1622 |
+
WLog_WARN(TAG, "client does not support 128 bit encryption method as required by "
|
| 1623 |
+
"server configuration");
|
| 1624 |
+
}
|
| 1625 |
+
|
| 1626 |
+
EncryptionMethods = ENCRYPTION_METHOD_128BIT;
|
| 1627 |
+
break;
|
| 1628 |
+
|
| 1629 |
+
case ENCRYPTION_LEVEL_LOW:
|
| 1630 |
+
case ENCRYPTION_LEVEL_CLIENT_COMPATIBLE:
|
| 1631 |
+
|
| 1632 |
+
/* Maximum key strength supported by the client must be used */
|
| 1633 |
+
if (EncryptionMethods & ENCRYPTION_METHOD_128BIT)
|
| 1634 |
+
EncryptionMethods = ENCRYPTION_METHOD_128BIT;
|
| 1635 |
+
else if (EncryptionMethods & ENCRYPTION_METHOD_56BIT)
|
| 1636 |
+
EncryptionMethods = ENCRYPTION_METHOD_56BIT;
|
| 1637 |
+
else if (EncryptionMethods & ENCRYPTION_METHOD_40BIT)
|
| 1638 |
+
EncryptionMethods = ENCRYPTION_METHOD_40BIT;
|
| 1639 |
+
else if (EncryptionMethods & ENCRYPTION_METHOD_FIPS)
|
| 1640 |
+
EncryptionMethods = ENCRYPTION_METHOD_FIPS;
|
| 1641 |
+
else
|
| 1642 |
+
{
|
| 1643 |
+
WLog_WARN(TAG, "client has not announced any supported encryption methods");
|
| 1644 |
+
EncryptionMethods = ENCRYPTION_METHOD_128BIT;
|
| 1645 |
+
}
|
| 1646 |
+
|
| 1647 |
+
break;
|
| 1648 |
+
|
| 1649 |
+
default:
|
| 1650 |
+
WLog_ERR(TAG, "internal error: unknown encryption level");
|
| 1651 |
+
return FALSE;
|
| 1652 |
+
}
|
| 1653 |
+
|
| 1654 |
+
/* log selected encryption method */
|
| 1655 |
+
if (settings->UseRdpSecurityLayer)
|
| 1656 |
+
{
|
| 1657 |
+
switch (EncryptionMethods)
|
| 1658 |
+
{
|
| 1659 |
+
case ENCRYPTION_METHOD_NONE:
|
| 1660 |
+
WLog_INFO(TAG, "Selected rdp encryption method: NONE");
|
| 1661 |
+
break;
|
| 1662 |
+
|
| 1663 |
+
case ENCRYPTION_METHOD_40BIT:
|
| 1664 |
+
WLog_INFO(TAG, "Selected rdp encryption method: 40BIT");
|
| 1665 |
+
break;
|
| 1666 |
+
|
| 1667 |
+
case ENCRYPTION_METHOD_56BIT:
|
| 1668 |
+
WLog_INFO(TAG, "Selected rdp encryption method: 56BIT");
|
| 1669 |
+
break;
|
| 1670 |
+
|
| 1671 |
+
case ENCRYPTION_METHOD_128BIT:
|
| 1672 |
+
WLog_INFO(TAG, "Selected rdp encryption method: 128BIT");
|
| 1673 |
+
break;
|
| 1674 |
+
|
| 1675 |
+
case ENCRYPTION_METHOD_FIPS:
|
| 1676 |
+
WLog_INFO(TAG, "Selected rdp encryption method: FIPS");
|
| 1677 |
+
break;
|
| 1678 |
+
|
| 1679 |
+
default:
|
| 1680 |
+
WLog_ERR(TAG, "internal error: unknown encryption method");
|
| 1681 |
+
return FALSE;
|
| 1682 |
+
}
|
| 1683 |
+
}
|
| 1684 |
+
|
| 1685 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_EncryptionLevel, EncryptionLevel))
|
| 1686 |
+
return FALSE;
|
| 1687 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_EncryptionMethods, EncryptionMethods))
|
| 1688 |
+
return FALSE;
|
| 1689 |
+
return TRUE;
|
| 1690 |
+
}
|
| 1691 |
+
|
| 1692 |
+
BOOL rdp_server_accept_mcs_connect_initial(rdpRdp* rdp, wStream* s)
|
| 1693 |
+
{
|
| 1694 |
+
WINPR_ASSERT(rdp);
|
| 1695 |
+
WINPR_ASSERT(s);
|
| 1696 |
+
|
| 1697 |
+
rdpMcs* mcs = rdp->mcs;
|
| 1698 |
+
WINPR_ASSERT(mcs);
|
| 1699 |
+
|
| 1700 |
+
WINPR_ASSERT(rdp_get_state(rdp) == CONNECTION_STATE_MCS_CREATE_REQUEST);
|
| 1701 |
+
if (!mcs_recv_connect_initial(mcs, s))
|
| 1702 |
+
return FALSE;
|
| 1703 |
+
WINPR_ASSERT(rdp->settings);
|
| 1704 |
+
|
| 1705 |
+
if (!mcs_server_apply_to_settings(mcs, rdp->settings))
|
| 1706 |
+
return FALSE;
|
| 1707 |
+
|
| 1708 |
+
WLog_DBG(TAG, "Accepted client: %s", rdp->settings->ClientHostname);
|
| 1709 |
+
WLog_DBG(TAG, "Accepted channels:");
|
| 1710 |
+
|
| 1711 |
+
WINPR_ASSERT(mcs->channels || (mcs->channelCount == 0));
|
| 1712 |
+
for (UINT32 i = 0; i < mcs->channelCount; i++)
|
| 1713 |
+
{
|
| 1714 |
+
ADDIN_ARGV* arg = NULL;
|
| 1715 |
+
rdpMcsChannel* cur = &mcs->channels[i];
|
| 1716 |
+
const char* params[1] = { cur->Name };
|
| 1717 |
+
WLog_DBG(TAG, " %s [%" PRIu16 "]", cur->Name, cur->ChannelId);
|
| 1718 |
+
arg = freerdp_addin_argv_new(ARRAYSIZE(params), params);
|
| 1719 |
+
if (!arg)
|
| 1720 |
+
return FALSE;
|
| 1721 |
+
|
| 1722 |
+
if (!freerdp_static_channel_collection_add(rdp->settings, arg))
|
| 1723 |
+
{
|
| 1724 |
+
freerdp_addin_argv_free(arg);
|
| 1725 |
+
return FALSE;
|
| 1726 |
+
}
|
| 1727 |
+
}
|
| 1728 |
+
|
| 1729 |
+
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_MCS_CREATE_RESPONSE))
|
| 1730 |
+
return FALSE;
|
| 1731 |
+
if (!rdp_update_encryption_level(rdp->settings))
|
| 1732 |
+
return FALSE;
|
| 1733 |
+
if (!mcs_send_connect_response(mcs))
|
| 1734 |
+
return FALSE;
|
| 1735 |
+
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_MCS_ERECT_DOMAIN))
|
| 1736 |
+
return FALSE;
|
| 1737 |
+
|
| 1738 |
+
return TRUE;
|
| 1739 |
+
}
|
| 1740 |
+
|
| 1741 |
+
BOOL rdp_server_accept_mcs_erect_domain_request(rdpRdp* rdp, wStream* s)
|
| 1742 |
+
{
|
| 1743 |
+
WINPR_ASSERT(rdp);
|
| 1744 |
+
WINPR_ASSERT(s);
|
| 1745 |
+
WINPR_ASSERT(rdp_get_state(rdp) == CONNECTION_STATE_MCS_ERECT_DOMAIN);
|
| 1746 |
+
|
| 1747 |
+
if (!mcs_recv_erect_domain_request(rdp->mcs, s))
|
| 1748 |
+
return FALSE;
|
| 1749 |
+
|
| 1750 |
+
return rdp_server_transition_to_state(rdp, CONNECTION_STATE_MCS_ATTACH_USER);
|
| 1751 |
+
}
|
| 1752 |
+
|
| 1753 |
+
static BOOL rdp_server_skip_mcs_channel_join(rdpRdp* rdp)
|
| 1754 |
+
{
|
| 1755 |
+
WINPR_ASSERT(rdp);
|
| 1756 |
+
|
| 1757 |
+
rdpMcs* mcs = rdp->mcs;
|
| 1758 |
+
WINPR_ASSERT(mcs);
|
| 1759 |
+
|
| 1760 |
+
mcs->userChannelJoined = TRUE;
|
| 1761 |
+
mcs->globalChannelJoined = TRUE;
|
| 1762 |
+
mcs->messageChannelJoined = TRUE;
|
| 1763 |
+
|
| 1764 |
+
for (UINT32 i = 0; i < mcs->channelCount; i++)
|
| 1765 |
+
{
|
| 1766 |
+
rdpMcsChannel* cur = &mcs->channels[i];
|
| 1767 |
+
WLog_DBG(TAG, " %s [%" PRIu16 "]", cur->Name, cur->ChannelId);
|
| 1768 |
+
cur->joined = TRUE;
|
| 1769 |
+
}
|
| 1770 |
+
return rdp_server_transition_to_state(rdp, CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT);
|
| 1771 |
+
}
|
| 1772 |
+
|
| 1773 |
+
BOOL rdp_server_accept_mcs_attach_user_request(rdpRdp* rdp, wStream* s)
|
| 1774 |
+
{
|
| 1775 |
+
if (!mcs_recv_attach_user_request(rdp->mcs, s))
|
| 1776 |
+
return FALSE;
|
| 1777 |
+
|
| 1778 |
+
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_MCS_ATTACH_USER_CONFIRM))
|
| 1779 |
+
return FALSE;
|
| 1780 |
+
|
| 1781 |
+
if (!mcs_send_attach_user_confirm(rdp->mcs))
|
| 1782 |
+
return FALSE;
|
| 1783 |
+
|
| 1784 |
+
if (freerdp_settings_get_bool(rdp->settings, FreeRDP_SupportSkipChannelJoin))
|
| 1785 |
+
return rdp_server_skip_mcs_channel_join(rdp);
|
| 1786 |
+
return rdp_server_transition_to_state(rdp, CONNECTION_STATE_MCS_CHANNEL_JOIN_REQUEST);
|
| 1787 |
+
}
|
| 1788 |
+
|
| 1789 |
+
BOOL rdp_server_accept_mcs_channel_join_request(rdpRdp* rdp, wStream* s)
|
| 1790 |
+
{
|
| 1791 |
+
UINT16 channelId = 0;
|
| 1792 |
+
BOOL allJoined = TRUE;
|
| 1793 |
+
rdpMcs* mcs = NULL;
|
| 1794 |
+
|
| 1795 |
+
WINPR_ASSERT(rdp);
|
| 1796 |
+
WINPR_ASSERT(rdp->context);
|
| 1797 |
+
|
| 1798 |
+
mcs = rdp->mcs;
|
| 1799 |
+
WINPR_ASSERT(mcs);
|
| 1800 |
+
|
| 1801 |
+
WINPR_ASSERT(rdp_get_state(rdp) == CONNECTION_STATE_MCS_CHANNEL_JOIN_REQUEST);
|
| 1802 |
+
|
| 1803 |
+
if (!mcs_recv_channel_join_request(mcs, rdp->settings, s, &channelId))
|
| 1804 |
+
return FALSE;
|
| 1805 |
+
|
| 1806 |
+
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_MCS_CHANNEL_JOIN_RESPONSE))
|
| 1807 |
+
return FALSE;
|
| 1808 |
+
|
| 1809 |
+
if (!mcs_send_channel_join_confirm(mcs, channelId))
|
| 1810 |
+
return FALSE;
|
| 1811 |
+
|
| 1812 |
+
if (channelId == mcs->userId)
|
| 1813 |
+
mcs->userChannelJoined = TRUE;
|
| 1814 |
+
if (channelId == MCS_GLOBAL_CHANNEL_ID)
|
| 1815 |
+
mcs->globalChannelJoined = TRUE;
|
| 1816 |
+
if (channelId == mcs->messageChannelId)
|
| 1817 |
+
mcs->messageChannelJoined = TRUE;
|
| 1818 |
+
|
| 1819 |
+
for (UINT32 i = 0; i < mcs->channelCount; i++)
|
| 1820 |
+
{
|
| 1821 |
+
rdpMcsChannel* cur = &mcs->channels[i];
|
| 1822 |
+
WLog_DBG(TAG, " %s [%" PRIu16 "]", cur->Name, cur->ChannelId);
|
| 1823 |
+
if (cur->ChannelId == channelId)
|
| 1824 |
+
cur->joined = TRUE;
|
| 1825 |
+
|
| 1826 |
+
if (!cur->joined)
|
| 1827 |
+
allJoined = FALSE;
|
| 1828 |
+
}
|
| 1829 |
+
|
| 1830 |
+
CONNECTION_STATE rc = CONNECTION_STATE_INITIAL;
|
| 1831 |
+
if ((mcs->userChannelJoined) && (mcs->globalChannelJoined) &&
|
| 1832 |
+
(mcs->messageChannelId == 0 || mcs->messageChannelJoined) && allJoined)
|
| 1833 |
+
rc = CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT;
|
| 1834 |
+
else
|
| 1835 |
+
rc = CONNECTION_STATE_MCS_CHANNEL_JOIN_REQUEST;
|
| 1836 |
+
|
| 1837 |
+
return rdp_server_transition_to_state(rdp, rc);
|
| 1838 |
+
}
|
| 1839 |
+
|
| 1840 |
+
static BOOL rdp_server_send_sync(rdpRdp* rdp)
|
| 1841 |
+
{
|
| 1842 |
+
WINPR_ASSERT(rdp);
|
| 1843 |
+
|
| 1844 |
+
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_CLIENT_SYNC))
|
| 1845 |
+
return FALSE;
|
| 1846 |
+
if (!rdp_send_server_synchronize_pdu(rdp))
|
| 1847 |
+
return FALSE;
|
| 1848 |
+
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_CLIENT_COOPERATE))
|
| 1849 |
+
return FALSE;
|
| 1850 |
+
if (!rdp_send_server_control_cooperate_pdu(rdp))
|
| 1851 |
+
return FALSE;
|
| 1852 |
+
if (!rdp_finalize_reset_flags(rdp, FALSE))
|
| 1853 |
+
return FALSE;
|
| 1854 |
+
return rdp_server_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_SYNC);
|
| 1855 |
+
}
|
| 1856 |
+
|
| 1857 |
+
BOOL rdp_server_accept_confirm_active(rdpRdp* rdp, wStream* s, UINT16 pduLength)
|
| 1858 |
+
{
|
| 1859 |
+
WINPR_ASSERT(rdp);
|
| 1860 |
+
WINPR_ASSERT(rdp->context);
|
| 1861 |
+
WINPR_ASSERT(rdp->settings);
|
| 1862 |
+
WINPR_ASSERT(s);
|
| 1863 |
+
|
| 1864 |
+
freerdp_peer* peer = rdp->context->peer;
|
| 1865 |
+
WINPR_ASSERT(peer);
|
| 1866 |
+
|
| 1867 |
+
if (rdp_get_state(rdp) != CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE)
|
| 1868 |
+
{
|
| 1869 |
+
if (freerdp_settings_get_bool(rdp->settings, FreeRDP_TransportDumpReplay))
|
| 1870 |
+
rdp_finalize_set_flag(rdp, FINALIZE_DEACTIVATE_REACTIVATE);
|
| 1871 |
+
else
|
| 1872 |
+
{
|
| 1873 |
+
WLog_WARN(TAG, "Invalid state, got %s, expected %s", rdp_get_state_string(rdp),
|
| 1874 |
+
rdp_state_string(CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE));
|
| 1875 |
+
return FALSE;
|
| 1876 |
+
}
|
| 1877 |
+
}
|
| 1878 |
+
|
| 1879 |
+
if (!rdp_recv_confirm_active(rdp, s, pduLength))
|
| 1880 |
+
return FALSE;
|
| 1881 |
+
|
| 1882 |
+
if (peer->ClientCapabilities && !peer->ClientCapabilities(peer))
|
| 1883 |
+
{
|
| 1884 |
+
WLog_WARN(TAG, "peer->ClientCapabilities failed");
|
| 1885 |
+
return FALSE;
|
| 1886 |
+
}
|
| 1887 |
+
|
| 1888 |
+
if (rdp->settings->SaltedChecksum)
|
| 1889 |
+
rdp->do_secure_checksum = TRUE;
|
| 1890 |
+
|
| 1891 |
+
return rdp_server_send_sync(rdp);
|
| 1892 |
+
}
|
| 1893 |
+
|
| 1894 |
+
BOOL rdp_server_reactivate(rdpRdp* rdp)
|
| 1895 |
+
{
|
| 1896 |
+
freerdp_peer* client = NULL;
|
| 1897 |
+
|
| 1898 |
+
if (rdp->context && rdp->context->peer)
|
| 1899 |
+
client = rdp->context->peer;
|
| 1900 |
+
|
| 1901 |
+
if (client)
|
| 1902 |
+
client->activated = FALSE;
|
| 1903 |
+
|
| 1904 |
+
if (!rdp_send_deactivate_all(rdp))
|
| 1905 |
+
return FALSE;
|
| 1906 |
+
|
| 1907 |
+
rdp_finalize_set_flag(rdp, FINALIZE_DEACTIVATE_REACTIVATE);
|
| 1908 |
+
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE))
|
| 1909 |
+
return FALSE;
|
| 1910 |
+
|
| 1911 |
+
state_run_t rc = rdp_peer_handle_state_demand_active(client);
|
| 1912 |
+
return state_run_success(rc);
|
| 1913 |
+
}
|
| 1914 |
+
|
| 1915 |
+
static BOOL rdp_is_active_peer_state(CONNECTION_STATE state)
|
| 1916 |
+
{
|
| 1917 |
+
/* [MS-RDPBCGR] 1.3.1.1 Connection Sequence states:
|
| 1918 |
+
* 'upon receipt of the Font List PDU the server can start sending graphics
|
| 1919 |
+
* output to the client'
|
| 1920 |
+
*/
|
| 1921 |
+
switch (state)
|
| 1922 |
+
{
|
| 1923 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_SYNC:
|
| 1924 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_COOPERATE:
|
| 1925 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_GRANTED_CONTROL:
|
| 1926 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_FONT_MAP:
|
| 1927 |
+
case CONNECTION_STATE_ACTIVE:
|
| 1928 |
+
return TRUE;
|
| 1929 |
+
default:
|
| 1930 |
+
return FALSE;
|
| 1931 |
+
}
|
| 1932 |
+
}
|
| 1933 |
+
|
| 1934 |
+
static BOOL rdp_is_active_client_state(CONNECTION_STATE state)
|
| 1935 |
+
{
|
| 1936 |
+
/* [MS-RDPBCGR] 1.3.1.1 Connection Sequence states:
|
| 1937 |
+
* 'Once the client has sent the Confirm Active PDU, it can start sending
|
| 1938 |
+
* mouse and keyboard input to the server'
|
| 1939 |
+
*/
|
| 1940 |
+
switch (state)
|
| 1941 |
+
{
|
| 1942 |
+
case CONNECTION_STATE_FINALIZATION_SYNC:
|
| 1943 |
+
case CONNECTION_STATE_FINALIZATION_COOPERATE:
|
| 1944 |
+
case CONNECTION_STATE_FINALIZATION_REQUEST_CONTROL:
|
| 1945 |
+
case CONNECTION_STATE_FINALIZATION_PERSISTENT_KEY_LIST:
|
| 1946 |
+
case CONNECTION_STATE_FINALIZATION_FONT_LIST:
|
| 1947 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_SYNC:
|
| 1948 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_COOPERATE:
|
| 1949 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_GRANTED_CONTROL:
|
| 1950 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_FONT_MAP:
|
| 1951 |
+
case CONNECTION_STATE_ACTIVE:
|
| 1952 |
+
return TRUE;
|
| 1953 |
+
default:
|
| 1954 |
+
return FALSE;
|
| 1955 |
+
}
|
| 1956 |
+
}
|
| 1957 |
+
|
| 1958 |
+
BOOL rdp_is_active_state(const rdpRdp* rdp)
|
| 1959 |
+
{
|
| 1960 |
+
WINPR_ASSERT(rdp);
|
| 1961 |
+
WINPR_ASSERT(rdp->context);
|
| 1962 |
+
|
| 1963 |
+
const CONNECTION_STATE state = rdp_get_state(rdp);
|
| 1964 |
+
if (freerdp_settings_get_bool(rdp->context->settings, FreeRDP_ServerMode))
|
| 1965 |
+
return rdp_is_active_peer_state(state);
|
| 1966 |
+
else
|
| 1967 |
+
return rdp_is_active_client_state(state);
|
| 1968 |
+
}
|
| 1969 |
+
|
| 1970 |
+
BOOL rdp_server_transition_to_state(rdpRdp* rdp, CONNECTION_STATE state)
|
| 1971 |
+
{
|
| 1972 |
+
BOOL status = FALSE;
|
| 1973 |
+
freerdp_peer* client = NULL;
|
| 1974 |
+
const CONNECTION_STATE cstate = rdp_get_state(rdp);
|
| 1975 |
+
|
| 1976 |
+
if (cstate >= CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT)
|
| 1977 |
+
{
|
| 1978 |
+
WINPR_ASSERT(rdp->context);
|
| 1979 |
+
client = rdp->context->peer;
|
| 1980 |
+
}
|
| 1981 |
+
|
| 1982 |
+
if (!rdp_is_active_peer_state(cstate))
|
| 1983 |
+
{
|
| 1984 |
+
if (client)
|
| 1985 |
+
client->activated = FALSE;
|
| 1986 |
+
}
|
| 1987 |
+
|
| 1988 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "%s --> %s", rdp_get_state_string(rdp),
|
| 1989 |
+
rdp_state_string(state));
|
| 1990 |
+
if (!rdp_set_state(rdp, state))
|
| 1991 |
+
goto fail;
|
| 1992 |
+
|
| 1993 |
+
status = TRUE;
|
| 1994 |
+
fail:
|
| 1995 |
+
return status;
|
| 1996 |
+
}
|
| 1997 |
+
|
| 1998 |
+
const char* rdp_client_connection_state_string(UINT state)
|
| 1999 |
+
{
|
| 2000 |
+
switch (state)
|
| 2001 |
+
{
|
| 2002 |
+
case CLIENT_STATE_INITIAL:
|
| 2003 |
+
return "CLIENT_STATE_INITIAL";
|
| 2004 |
+
case CLIENT_STATE_PRECONNECT_PASSED:
|
| 2005 |
+
return "CLIENT_STATE_PRECONNECT_PASSED";
|
| 2006 |
+
case CLIENT_STATE_POSTCONNECT_PASSED:
|
| 2007 |
+
return "CLIENT_STATE_POSTCONNECT_PASSED";
|
| 2008 |
+
default:
|
| 2009 |
+
return "UNKNOWN";
|
| 2010 |
+
}
|
| 2011 |
+
}
|
| 2012 |
+
|
| 2013 |
+
const char* rdp_state_string(CONNECTION_STATE state)
|
| 2014 |
+
{
|
| 2015 |
+
switch (state)
|
| 2016 |
+
{
|
| 2017 |
+
case CONNECTION_STATE_INITIAL:
|
| 2018 |
+
return "CONNECTION_STATE_INITIAL";
|
| 2019 |
+
case CONNECTION_STATE_NEGO:
|
| 2020 |
+
return "CONNECTION_STATE_NEGO";
|
| 2021 |
+
case CONNECTION_STATE_NLA:
|
| 2022 |
+
return "CONNECTION_STATE_NLA";
|
| 2023 |
+
case CONNECTION_STATE_AAD:
|
| 2024 |
+
return "CONNECTION_STATE_AAD";
|
| 2025 |
+
case CONNECTION_STATE_MCS_CREATE_REQUEST:
|
| 2026 |
+
return "CONNECTION_STATE_MCS_CREATE_REQUEST";
|
| 2027 |
+
case CONNECTION_STATE_MCS_CREATE_RESPONSE:
|
| 2028 |
+
return "CONNECTION_STATE_MCS_CREATE_RESPONSE";
|
| 2029 |
+
case CONNECTION_STATE_MCS_ERECT_DOMAIN:
|
| 2030 |
+
return "CONNECTION_STATE_MCS_ERECT_DOMAIN";
|
| 2031 |
+
case CONNECTION_STATE_MCS_ATTACH_USER:
|
| 2032 |
+
return "CONNECTION_STATE_MCS_ATTACH_USER";
|
| 2033 |
+
case CONNECTION_STATE_MCS_ATTACH_USER_CONFIRM:
|
| 2034 |
+
return "CONNECTION_STATE_MCS_ATTACH_USER_CONFIRM";
|
| 2035 |
+
case CONNECTION_STATE_MCS_CHANNEL_JOIN_REQUEST:
|
| 2036 |
+
return "CONNECTION_STATE_MCS_CHANNEL_JOIN_REQUEST";
|
| 2037 |
+
case CONNECTION_STATE_MCS_CHANNEL_JOIN_RESPONSE:
|
| 2038 |
+
return "CONNECTION_STATE_MCS_CHANNEL_JOIN_RESPONSE";
|
| 2039 |
+
case CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT:
|
| 2040 |
+
return "CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT";
|
| 2041 |
+
case CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE:
|
| 2042 |
+
return "CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE";
|
| 2043 |
+
case CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_REQUEST:
|
| 2044 |
+
return "CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_REQUEST";
|
| 2045 |
+
case CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_RESPONSE:
|
| 2046 |
+
return "CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_RESPONSE";
|
| 2047 |
+
case CONNECTION_STATE_LICENSING:
|
| 2048 |
+
return "CONNECTION_STATE_LICENSING";
|
| 2049 |
+
case CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_REQUEST:
|
| 2050 |
+
return "CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_REQUEST";
|
| 2051 |
+
case CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_RESPONSE:
|
| 2052 |
+
return "CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_RESPONSE";
|
| 2053 |
+
case CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE:
|
| 2054 |
+
return "CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE";
|
| 2055 |
+
case CONNECTION_STATE_CAPABILITIES_EXCHANGE_MONITOR_LAYOUT:
|
| 2056 |
+
return "CONNECTION_STATE_CAPABILITIES_EXCHANGE_MONITOR_LAYOUT";
|
| 2057 |
+
case CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE:
|
| 2058 |
+
return "CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE";
|
| 2059 |
+
case CONNECTION_STATE_FINALIZATION_SYNC:
|
| 2060 |
+
return "CONNECTION_STATE_FINALIZATION_SYNC";
|
| 2061 |
+
case CONNECTION_STATE_FINALIZATION_COOPERATE:
|
| 2062 |
+
return "CONNECTION_STATE_FINALIZATION_COOPERATE";
|
| 2063 |
+
case CONNECTION_STATE_FINALIZATION_REQUEST_CONTROL:
|
| 2064 |
+
return "CONNECTION_STATE_FINALIZATION_REQUEST_CONTROL";
|
| 2065 |
+
case CONNECTION_STATE_FINALIZATION_PERSISTENT_KEY_LIST:
|
| 2066 |
+
return "CONNECTION_STATE_FINALIZATION_PERSISTENT_KEY_LIST";
|
| 2067 |
+
case CONNECTION_STATE_FINALIZATION_FONT_LIST:
|
| 2068 |
+
return "CONNECTION_STATE_FINALIZATION_FONT_LIST";
|
| 2069 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_SYNC:
|
| 2070 |
+
return "CONNECTION_STATE_FINALIZATION_CLIENT_SYNC";
|
| 2071 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_COOPERATE:
|
| 2072 |
+
return "CONNECTION_STATE_FINALIZATION_CLIENT_COOPERATE";
|
| 2073 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_GRANTED_CONTROL:
|
| 2074 |
+
return "CONNECTION_STATE_FINALIZATION_CLIENT_GRANTED_CONTROL";
|
| 2075 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_FONT_MAP:
|
| 2076 |
+
return "CONNECTION_STATE_FINALIZATION_CLIENT_FONT_MAP";
|
| 2077 |
+
case CONNECTION_STATE_ACTIVE:
|
| 2078 |
+
return "CONNECTION_STATE_ACTIVE";
|
| 2079 |
+
default:
|
| 2080 |
+
return "UNKNOWN";
|
| 2081 |
+
}
|
| 2082 |
+
}
|
| 2083 |
+
|
| 2084 |
+
CONNECTION_STATE rdp_get_state(const rdpRdp* rdp)
|
| 2085 |
+
{
|
| 2086 |
+
WINPR_ASSERT(rdp);
|
| 2087 |
+
return rdp->state;
|
| 2088 |
+
}
|
| 2089 |
+
|
| 2090 |
+
BOOL rdp_set_state(rdpRdp* rdp, CONNECTION_STATE state)
|
| 2091 |
+
{
|
| 2092 |
+
WINPR_ASSERT(rdp);
|
| 2093 |
+
rdp->state = state;
|
| 2094 |
+
return TRUE;
|
| 2095 |
+
}
|
| 2096 |
+
|
| 2097 |
+
const char* rdp_get_state_string(const rdpRdp* rdp)
|
| 2098 |
+
{
|
| 2099 |
+
CONNECTION_STATE state = rdp_get_state(rdp);
|
| 2100 |
+
return rdp_state_string(state);
|
| 2101 |
+
}
|
| 2102 |
+
|
| 2103 |
+
BOOL rdp_channels_from_mcs(rdpSettings* settings, const rdpRdp* rdp)
|
| 2104 |
+
{
|
| 2105 |
+
const rdpMcs* mcs = NULL;
|
| 2106 |
+
|
| 2107 |
+
WINPR_ASSERT(rdp);
|
| 2108 |
+
|
| 2109 |
+
mcs = rdp->mcs;
|
| 2110 |
+
WINPR_ASSERT(mcs);
|
| 2111 |
+
|
| 2112 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ChannelDefArray, NULL,
|
| 2113 |
+
CHANNEL_MAX_COUNT))
|
| 2114 |
+
return FALSE;
|
| 2115 |
+
|
| 2116 |
+
for (UINT32 x = 0; x < mcs->channelCount; x++)
|
| 2117 |
+
{
|
| 2118 |
+
const rdpMcsChannel* mchannel = &mcs->channels[x];
|
| 2119 |
+
CHANNEL_DEF cur = { 0 };
|
| 2120 |
+
|
| 2121 |
+
memcpy(cur.name, mchannel->Name, sizeof(cur.name));
|
| 2122 |
+
cur.options = mchannel->options;
|
| 2123 |
+
if (!freerdp_settings_set_pointer_array(settings, FreeRDP_ChannelDefArray, x, &cur))
|
| 2124 |
+
return FALSE;
|
| 2125 |
+
}
|
| 2126 |
+
|
| 2127 |
+
return freerdp_settings_set_uint32(settings, FreeRDP_ChannelCount, mcs->channelCount);
|
| 2128 |
+
}
|
| 2129 |
+
|
| 2130 |
+
/* Here we are in client state CONFIRM_ACTIVE.
|
| 2131 |
+
*
|
| 2132 |
+
* This means:
|
| 2133 |
+
* 1. send the CONFIRM_ACTIVE PDU to the server
|
| 2134 |
+
* 2. register callbacks, the server can now start sending stuff
|
| 2135 |
+
*/
|
| 2136 |
+
state_run_t rdp_client_connect_confirm_active(rdpRdp* rdp, wStream* s)
|
| 2137 |
+
{
|
| 2138 |
+
WINPR_ASSERT(rdp);
|
| 2139 |
+
WINPR_ASSERT(rdp->settings);
|
| 2140 |
+
WINPR_ASSERT(s);
|
| 2141 |
+
|
| 2142 |
+
const UINT32 width = rdp->settings->DesktopWidth;
|
| 2143 |
+
const UINT32 height = rdp->settings->DesktopHeight;
|
| 2144 |
+
|
| 2145 |
+
if (!rdp_send_confirm_active(rdp))
|
| 2146 |
+
return STATE_RUN_FAILED;
|
| 2147 |
+
|
| 2148 |
+
if (!input_register_client_callbacks(rdp->input))
|
| 2149 |
+
{
|
| 2150 |
+
WLog_ERR(TAG, "error registering client callbacks");
|
| 2151 |
+
return STATE_RUN_FAILED;
|
| 2152 |
+
}
|
| 2153 |
+
|
| 2154 |
+
/**
|
| 2155 |
+
* The server may request a different desktop size during Deactivation-Reactivation sequence.
|
| 2156 |
+
* In this case, the UI should be informed and do actual window resizing at this point.
|
| 2157 |
+
*/
|
| 2158 |
+
const BOOL deactivate_reactivate =
|
| 2159 |
+
rdp->was_deactivated && ((rdp->deactivated_width != rdp->settings->DesktopWidth) ||
|
| 2160 |
+
(rdp->deactivated_height != rdp->settings->DesktopHeight));
|
| 2161 |
+
const BOOL resolution_change =
|
| 2162 |
+
((width != rdp->settings->DesktopWidth) || (height != rdp->settings->DesktopHeight));
|
| 2163 |
+
if (deactivate_reactivate || resolution_change)
|
| 2164 |
+
{
|
| 2165 |
+
BOOL status = TRUE;
|
| 2166 |
+
IFCALLRET(rdp->update->DesktopResize, status, rdp->update->context);
|
| 2167 |
+
|
| 2168 |
+
if (!status)
|
| 2169 |
+
{
|
| 2170 |
+
WLog_ERR(TAG, "client desktop resize callback failed");
|
| 2171 |
+
return STATE_RUN_FAILED;
|
| 2172 |
+
}
|
| 2173 |
+
}
|
| 2174 |
+
|
| 2175 |
+
WINPR_ASSERT(rdp->context);
|
| 2176 |
+
if (freerdp_shall_disconnect_context(rdp->context))
|
| 2177 |
+
return STATE_RUN_SUCCESS;
|
| 2178 |
+
|
| 2179 |
+
state_run_t status = STATE_RUN_SUCCESS;
|
| 2180 |
+
if (!rdp->settings->SupportMonitorLayoutPdu)
|
| 2181 |
+
status = rdp_client_connect_finalize(rdp);
|
| 2182 |
+
else
|
| 2183 |
+
{
|
| 2184 |
+
if (!rdp_client_transition_to_state(rdp,
|
| 2185 |
+
CONNECTION_STATE_CAPABILITIES_EXCHANGE_MONITOR_LAYOUT))
|
| 2186 |
+
status = STATE_RUN_FAILED;
|
| 2187 |
+
}
|
| 2188 |
+
if (!rdp_finalize_reset_flags(rdp, FALSE))
|
| 2189 |
+
status = STATE_RUN_FAILED;
|
| 2190 |
+
return status;
|
| 2191 |
+
}
|
| 2192 |
+
|
| 2193 |
+
BOOL rdp_handle_optional_rdp_decryption(rdpRdp* rdp, wStream* s, UINT16* length,
|
| 2194 |
+
UINT16* pSecurityFlags)
|
| 2195 |
+
{
|
| 2196 |
+
BOOL rc = FALSE;
|
| 2197 |
+
WINPR_ASSERT(rdp);
|
| 2198 |
+
WINPR_ASSERT(rdp->settings);
|
| 2199 |
+
|
| 2200 |
+
UINT16 securityFlags = 0;
|
| 2201 |
+
if (rdp->settings->UseRdpSecurityLayer)
|
| 2202 |
+
{
|
| 2203 |
+
if (!rdp_read_security_header(rdp, s, &securityFlags, length))
|
| 2204 |
+
goto fail;
|
| 2205 |
+
|
| 2206 |
+
if (securityFlags & SEC_ENCRYPT)
|
| 2207 |
+
{
|
| 2208 |
+
if (!rdp_decrypt(rdp, s, length, securityFlags))
|
| 2209 |
+
goto fail;
|
| 2210 |
+
}
|
| 2211 |
+
}
|
| 2212 |
+
|
| 2213 |
+
rc = TRUE;
|
| 2214 |
+
|
| 2215 |
+
fail:
|
| 2216 |
+
if (pSecurityFlags)
|
| 2217 |
+
*pSecurityFlags = securityFlags;
|
| 2218 |
+
return rc;
|
| 2219 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/display.c
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Display update notifications
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2019 Kobi Mizrachi <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "display.h"
|
| 21 |
+
|
| 22 |
+
static BOOL display_write_monitor_layout_pdu(wStream* s, UINT32 monitorCount,
|
| 23 |
+
const MONITOR_DEF* monitorDefArray)
|
| 24 |
+
{
|
| 25 |
+
if (!Stream_EnsureRemainingCapacity(s, 4 + (monitorCount * 20)))
|
| 26 |
+
return FALSE;
|
| 27 |
+
|
| 28 |
+
Stream_Write_UINT32(s, monitorCount); /* monitorCount (4 bytes) */
|
| 29 |
+
|
| 30 |
+
for (UINT32 index = 0; index < monitorCount; index++)
|
| 31 |
+
{
|
| 32 |
+
const MONITOR_DEF* monitor = &monitorDefArray[index];
|
| 33 |
+
|
| 34 |
+
Stream_Write_INT32(s, monitor->left); /* left (4 bytes) */
|
| 35 |
+
Stream_Write_INT32(s, monitor->top); /* top (4 bytes) */
|
| 36 |
+
Stream_Write_INT32(s, monitor->right); /* right (4 bytes) */
|
| 37 |
+
Stream_Write_INT32(s, monitor->bottom); /* bottom (4 bytes) */
|
| 38 |
+
Stream_Write_UINT32(s, monitor->flags); /* flags (4 bytes) */
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
return TRUE;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
BOOL display_convert_rdp_monitor_to_monitor_def(UINT32 monitorCount,
|
| 45 |
+
const rdpMonitor* monitorDefArray,
|
| 46 |
+
MONITOR_DEF** result)
|
| 47 |
+
{
|
| 48 |
+
MONITOR_DEF* mdef = NULL;
|
| 49 |
+
|
| 50 |
+
if (!monitorDefArray || !result || (*result))
|
| 51 |
+
return FALSE;
|
| 52 |
+
|
| 53 |
+
mdef = (MONITOR_DEF*)calloc(monitorCount, sizeof(MONITOR_DEF));
|
| 54 |
+
|
| 55 |
+
if (!mdef)
|
| 56 |
+
return FALSE;
|
| 57 |
+
|
| 58 |
+
for (UINT32 index = 0; index < monitorCount; index++)
|
| 59 |
+
{
|
| 60 |
+
const rdpMonitor* monitor = &monitorDefArray[index];
|
| 61 |
+
MONITOR_DEF* current = &mdef[index];
|
| 62 |
+
|
| 63 |
+
current->left = monitor->x; /* left (4 bytes) */
|
| 64 |
+
current->top = monitor->y; /* top (4 bytes) */
|
| 65 |
+
current->right = monitor->x + monitor->width - 1; /* right (4 bytes) */
|
| 66 |
+
current->bottom = monitor->y + monitor->height - 1; /* bottom (4 bytes) */
|
| 67 |
+
current->flags = monitor->is_primary ? MONITOR_PRIMARY : 0x0; /* flags (4 bytes) */
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
*result = mdef;
|
| 71 |
+
return TRUE;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
BOOL freerdp_display_send_monitor_layout(rdpContext* context, UINT32 monitorCount,
|
| 75 |
+
const MONITOR_DEF* monitorDefArray)
|
| 76 |
+
{
|
| 77 |
+
rdpRdp* rdp = context->rdp;
|
| 78 |
+
wStream* st = rdp_data_pdu_init(rdp);
|
| 79 |
+
|
| 80 |
+
if (!st)
|
| 81 |
+
return FALSE;
|
| 82 |
+
|
| 83 |
+
if (!display_write_monitor_layout_pdu(st, monitorCount, monitorDefArray))
|
| 84 |
+
{
|
| 85 |
+
Stream_Release(st);
|
| 86 |
+
return FALSE;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
return rdp_send_data_pdu(rdp, st, DATA_PDU_TYPE_MONITOR_LAYOUT, 0);
|
| 90 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/mcs.h
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* T.125 Multipoint Communication Service (MCS) Protocol
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#ifndef FREERDP_LIB_CORE_MCS_H
|
| 23 |
+
#define FREERDP_LIB_CORE_MCS_H
|
| 24 |
+
|
| 25 |
+
typedef struct rdp_mcs rdpMcs;
|
| 26 |
+
|
| 27 |
+
#include "transport.h"
|
| 28 |
+
|
| 29 |
+
#include <freerdp/crypto/ber.h>
|
| 30 |
+
#include <freerdp/api.h>
|
| 31 |
+
#include <freerdp/types.h>
|
| 32 |
+
|
| 33 |
+
#include <winpr/stream.h>
|
| 34 |
+
#include <winpr/wtsapi.h>
|
| 35 |
+
|
| 36 |
+
enum MCS_Result
|
| 37 |
+
{
|
| 38 |
+
MCS_Result_successful = 0,
|
| 39 |
+
MCS_Result_domain_merging = 1,
|
| 40 |
+
MCS_Result_domain_not_hierarchical = 2,
|
| 41 |
+
MCS_Result_no_such_channel = 3,
|
| 42 |
+
MCS_Result_no_such_domain = 4,
|
| 43 |
+
MCS_Result_no_such_user = 5,
|
| 44 |
+
MCS_Result_not_admitted = 6,
|
| 45 |
+
MCS_Result_other_user_id = 7,
|
| 46 |
+
MCS_Result_parameters_unacceptable = 8,
|
| 47 |
+
MCS_Result_token_not_available = 9,
|
| 48 |
+
MCS_Result_token_not_possessed = 10,
|
| 49 |
+
MCS_Result_too_many_channels = 11,
|
| 50 |
+
MCS_Result_too_many_tokens = 12,
|
| 51 |
+
MCS_Result_too_many_users = 13,
|
| 52 |
+
MCS_Result_unspecified_failure = 14,
|
| 53 |
+
MCS_Result_user_rejected = 15,
|
| 54 |
+
MCS_Result_enum_length = 16
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
typedef enum
|
| 58 |
+
{
|
| 59 |
+
DomainMCSPDU_invalid = -1,
|
| 60 |
+
DomainMCSPDU_PlumbDomainIndication = 0,
|
| 61 |
+
DomainMCSPDU_ErectDomainRequest = 1,
|
| 62 |
+
DomainMCSPDU_MergeChannelsRequest = 2,
|
| 63 |
+
DomainMCSPDU_MergeChannelsConfirm = 3,
|
| 64 |
+
DomainMCSPDU_PurgeChannelsIndication = 4,
|
| 65 |
+
DomainMCSPDU_MergeTokensRequest = 5,
|
| 66 |
+
DomainMCSPDU_MergeTokensConfirm = 6,
|
| 67 |
+
DomainMCSPDU_PurgeTokensIndication = 7,
|
| 68 |
+
DomainMCSPDU_DisconnectProviderUltimatum = 8,
|
| 69 |
+
DomainMCSPDU_RejectMCSPDUUltimatum = 9,
|
| 70 |
+
DomainMCSPDU_AttachUserRequest = 10,
|
| 71 |
+
DomainMCSPDU_AttachUserConfirm = 11,
|
| 72 |
+
DomainMCSPDU_DetachUserRequest = 12,
|
| 73 |
+
DomainMCSPDU_DetachUserIndication = 13,
|
| 74 |
+
DomainMCSPDU_ChannelJoinRequest = 14,
|
| 75 |
+
DomainMCSPDU_ChannelJoinConfirm = 15,
|
| 76 |
+
DomainMCSPDU_ChannelLeaveRequest = 16,
|
| 77 |
+
DomainMCSPDU_ChannelConveneRequest = 17,
|
| 78 |
+
DomainMCSPDU_ChannelConveneConfirm = 18,
|
| 79 |
+
DomainMCSPDU_ChannelDisbandRequest = 19,
|
| 80 |
+
DomainMCSPDU_ChannelDisbandIndication = 20,
|
| 81 |
+
DomainMCSPDU_ChannelAdmitRequest = 21,
|
| 82 |
+
DomainMCSPDU_ChannelAdmitIndication = 22,
|
| 83 |
+
DomainMCSPDU_ChannelExpelRequest = 23,
|
| 84 |
+
DomainMCSPDU_ChannelExpelIndication = 24,
|
| 85 |
+
DomainMCSPDU_SendDataRequest = 25,
|
| 86 |
+
DomainMCSPDU_SendDataIndication = 26,
|
| 87 |
+
DomainMCSPDU_UniformSendDataRequest = 27,
|
| 88 |
+
DomainMCSPDU_UniformSendDataIndication = 28,
|
| 89 |
+
DomainMCSPDU_TokenGrabRequest = 29,
|
| 90 |
+
DomainMCSPDU_TokenGrabConfirm = 30,
|
| 91 |
+
DomainMCSPDU_TokenInhibitRequest = 31,
|
| 92 |
+
DomainMCSPDU_TokenInhibitConfirm = 32,
|
| 93 |
+
DomainMCSPDU_TokenGiveRequest = 33,
|
| 94 |
+
DomainMCSPDU_TokenGiveIndication = 34,
|
| 95 |
+
DomainMCSPDU_TokenGiveResponse = 35,
|
| 96 |
+
DomainMCSPDU_TokenGiveConfirm = 36,
|
| 97 |
+
DomainMCSPDU_TokenPleaseRequest = 37,
|
| 98 |
+
DomainMCSPDU_TokenPleaseConfirm = 38,
|
| 99 |
+
DomainMCSPDU_TokenReleaseRequest = 39,
|
| 100 |
+
DomainMCSPDU_TokenReleaseConfirm = 40,
|
| 101 |
+
DomainMCSPDU_TokenTestRequest = 41,
|
| 102 |
+
DomainMCSPDU_TokenTestConfirm = 42,
|
| 103 |
+
DomainMCSPDU_enum_length = 43
|
| 104 |
+
} DomainMCSPDU;
|
| 105 |
+
|
| 106 |
+
typedef struct
|
| 107 |
+
{
|
| 108 |
+
UINT32 maxChannelIds;
|
| 109 |
+
UINT32 maxUserIds;
|
| 110 |
+
UINT32 maxTokenIds;
|
| 111 |
+
UINT32 numPriorities;
|
| 112 |
+
UINT32 minThroughput;
|
| 113 |
+
UINT32 maxHeight;
|
| 114 |
+
UINT32 maxMCSPDUsize;
|
| 115 |
+
UINT32 protocolVersion;
|
| 116 |
+
} DomainParameters;
|
| 117 |
+
|
| 118 |
+
struct rdp_mcs_channel
|
| 119 |
+
{
|
| 120 |
+
char Name[CHANNEL_NAME_LEN + 1];
|
| 121 |
+
UINT32 options;
|
| 122 |
+
UINT16 ChannelId;
|
| 123 |
+
BOOL joined;
|
| 124 |
+
void* handle;
|
| 125 |
+
};
|
| 126 |
+
typedef struct rdp_mcs_channel rdpMcsChannel;
|
| 127 |
+
|
| 128 |
+
struct rdp_mcs
|
| 129 |
+
{
|
| 130 |
+
rdpTransport* transport;
|
| 131 |
+
|
| 132 |
+
UINT16 userId;
|
| 133 |
+
UINT16 baseChannelId;
|
| 134 |
+
UINT16 messageChannelId;
|
| 135 |
+
|
| 136 |
+
UINT32 flags;
|
| 137 |
+
|
| 138 |
+
DomainParameters domainParameters;
|
| 139 |
+
DomainParameters targetParameters;
|
| 140 |
+
DomainParameters minimumParameters;
|
| 141 |
+
DomainParameters maximumParameters;
|
| 142 |
+
|
| 143 |
+
BOOL userChannelJoined;
|
| 144 |
+
BOOL globalChannelJoined;
|
| 145 |
+
BOOL messageChannelJoined;
|
| 146 |
+
|
| 147 |
+
UINT32 channelCount;
|
| 148 |
+
UINT32 channelMaxCount;
|
| 149 |
+
rdpMcsChannel* channels;
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
#define MCS_SEND_DATA_HEADER_MAX_LENGTH 8
|
| 153 |
+
|
| 154 |
+
#define MCS_TYPE_CONNECT_INITIAL 0x65
|
| 155 |
+
#define MCS_TYPE_CONNECT_RESPONSE 0x66
|
| 156 |
+
|
| 157 |
+
const char* mcs_domain_pdu_string(DomainMCSPDU pdu);
|
| 158 |
+
BOOL mcs_server_apply_to_settings(const rdpMcs* mcs, rdpSettings* settings);
|
| 159 |
+
|
| 160 |
+
FREERDP_LOCAL BOOL mcs_recv_connect_initial(rdpMcs* mcs, wStream* s);
|
| 161 |
+
FREERDP_LOCAL BOOL mcs_recv_connect_response(rdpMcs* mcs, wStream* s);
|
| 162 |
+
FREERDP_LOCAL BOOL mcs_send_connect_response(rdpMcs* mcs);
|
| 163 |
+
FREERDP_LOCAL BOOL mcs_recv_erect_domain_request(rdpMcs* mcs, wStream* s);
|
| 164 |
+
FREERDP_LOCAL BOOL mcs_send_erect_domain_request(rdpMcs* mcs);
|
| 165 |
+
FREERDP_LOCAL BOOL mcs_recv_attach_user_request(rdpMcs* mcs, wStream* s);
|
| 166 |
+
FREERDP_LOCAL BOOL mcs_send_attach_user_request(rdpMcs* mcs);
|
| 167 |
+
FREERDP_LOCAL BOOL mcs_recv_attach_user_confirm(rdpMcs* mcs, wStream* s);
|
| 168 |
+
FREERDP_LOCAL BOOL mcs_send_attach_user_confirm(rdpMcs* mcs);
|
| 169 |
+
FREERDP_LOCAL BOOL mcs_recv_channel_join_request(rdpMcs* mcs, const rdpSettings* settings,
|
| 170 |
+
wStream* s, UINT16* channelId);
|
| 171 |
+
FREERDP_LOCAL BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channelId);
|
| 172 |
+
FREERDP_LOCAL BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s, UINT16* channelId);
|
| 173 |
+
FREERDP_LOCAL BOOL mcs_send_channel_join_confirm(rdpMcs* mcs, UINT16 channelId);
|
| 174 |
+
FREERDP_LOCAL BOOL mcs_recv_disconnect_provider_ultimatum(rdpMcs* mcs, wStream* s, int* reason);
|
| 175 |
+
FREERDP_LOCAL BOOL mcs_send_disconnect_provider_ultimatum(rdpMcs* mcs);
|
| 176 |
+
|
| 177 |
+
FREERDP_LOCAL BOOL mcs_write_domain_mcspdu_header(wStream* s, DomainMCSPDU domainMCSPDU,
|
| 178 |
+
UINT16 length, BYTE options);
|
| 179 |
+
|
| 180 |
+
FREERDP_LOCAL BOOL mcs_client_begin(rdpMcs* mcs);
|
| 181 |
+
|
| 182 |
+
FREERDP_LOCAL void mcs_free(rdpMcs* mcs);
|
| 183 |
+
|
| 184 |
+
WINPR_ATTR_MALLOC(mcs_free, 1)
|
| 185 |
+
FREERDP_LOCAL rdpMcs* mcs_new(rdpTransport* transport);
|
| 186 |
+
|
| 187 |
+
#endif /* FREERDP_LIB_CORE_MCS_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/rdp.c
ADDED
|
@@ -0,0 +1,3100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* RDP Core
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
* Copyright 2014 DI (FH) Martin Haimberger <[email protected]>
|
| 7 |
+
*
|
| 8 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
* you may not use this file except in compliance with the License.
|
| 10 |
+
* You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
* See the License for the specific language governing permissions and
|
| 18 |
+
* limitations under the License.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include <freerdp/config.h>
|
| 22 |
+
|
| 23 |
+
#include "settings.h"
|
| 24 |
+
|
| 25 |
+
#include <winpr/crt.h>
|
| 26 |
+
#include <winpr/string.h>
|
| 27 |
+
#include <winpr/synch.h>
|
| 28 |
+
#include <winpr/assert.h>
|
| 29 |
+
#include <winpr/cast.h>
|
| 30 |
+
#include <winpr/json.h>
|
| 31 |
+
|
| 32 |
+
#include "rdp.h"
|
| 33 |
+
|
| 34 |
+
#include "state.h"
|
| 35 |
+
#include "info.h"
|
| 36 |
+
#include "utils.h"
|
| 37 |
+
#include "mcs.h"
|
| 38 |
+
#include "redirection.h"
|
| 39 |
+
|
| 40 |
+
#include <freerdp/codec/bulk.h>
|
| 41 |
+
#include <freerdp/crypto/per.h>
|
| 42 |
+
#include <freerdp/log.h>
|
| 43 |
+
#include <freerdp/buildflags.h>
|
| 44 |
+
|
| 45 |
+
#define RDP_TAG FREERDP_TAG("core.rdp")
|
| 46 |
+
|
| 47 |
+
typedef struct
|
| 48 |
+
{
|
| 49 |
+
const char* file;
|
| 50 |
+
const char* fkt;
|
| 51 |
+
size_t line;
|
| 52 |
+
DWORD level;
|
| 53 |
+
} log_line_t;
|
| 54 |
+
|
| 55 |
+
static const char* DATA_PDU_TYPE_STRINGS[80] = {
|
| 56 |
+
"?",
|
| 57 |
+
"?", /* 0x00 - 0x01 */
|
| 58 |
+
"Update", /* 0x02 */
|
| 59 |
+
"?",
|
| 60 |
+
"?",
|
| 61 |
+
"?",
|
| 62 |
+
"?",
|
| 63 |
+
"?",
|
| 64 |
+
"?",
|
| 65 |
+
"?",
|
| 66 |
+
"?", /* 0x03 - 0x0A */
|
| 67 |
+
"?",
|
| 68 |
+
"?",
|
| 69 |
+
"?",
|
| 70 |
+
"?",
|
| 71 |
+
"?",
|
| 72 |
+
"?",
|
| 73 |
+
"?",
|
| 74 |
+
"?",
|
| 75 |
+
"?", /* 0x0B - 0x13 */
|
| 76 |
+
"Control", /* 0x14 */
|
| 77 |
+
"?",
|
| 78 |
+
"?",
|
| 79 |
+
"?",
|
| 80 |
+
"?",
|
| 81 |
+
"?",
|
| 82 |
+
"?", /* 0x15 - 0x1A */
|
| 83 |
+
"Pointer", /* 0x1B */
|
| 84 |
+
"Input", /* 0x1C */
|
| 85 |
+
"?",
|
| 86 |
+
"?", /* 0x1D - 0x1E */
|
| 87 |
+
"Synchronize", /* 0x1F */
|
| 88 |
+
"?", /* 0x20 */
|
| 89 |
+
"Refresh Rect", /* 0x21 */
|
| 90 |
+
"Play Sound", /* 0x22 */
|
| 91 |
+
"Suppress Output", /* 0x23 */
|
| 92 |
+
"Shutdown Request", /* 0x24 */
|
| 93 |
+
"Shutdown Denied", /* 0x25 */
|
| 94 |
+
"Save Session Info", /* 0x26 */
|
| 95 |
+
"Font List", /* 0x27 */
|
| 96 |
+
"Font Map", /* 0x28 */
|
| 97 |
+
"Set Keyboard Indicators", /* 0x29 */
|
| 98 |
+
"?", /* 0x2A */
|
| 99 |
+
"Bitmap Cache Persistent List", /* 0x2B */
|
| 100 |
+
"Bitmap Cache Error", /* 0x2C */
|
| 101 |
+
"Set Keyboard IME Status", /* 0x2D */
|
| 102 |
+
"Offscreen Cache Error", /* 0x2E */
|
| 103 |
+
"Set Error Info", /* 0x2F */
|
| 104 |
+
"Draw Nine Grid Error", /* 0x30 */
|
| 105 |
+
"Draw GDI+ Error", /* 0x31 */
|
| 106 |
+
"ARC Status", /* 0x32 */
|
| 107 |
+
"?",
|
| 108 |
+
"?",
|
| 109 |
+
"?", /* 0x33 - 0x35 */
|
| 110 |
+
"Status Info", /* 0x36 */
|
| 111 |
+
"Monitor Layout", /* 0x37 */
|
| 112 |
+
"FrameAcknowledge",
|
| 113 |
+
"?",
|
| 114 |
+
"?", /* 0x38 - 0x40 */
|
| 115 |
+
"?",
|
| 116 |
+
"?",
|
| 117 |
+
"?",
|
| 118 |
+
"?",
|
| 119 |
+
"?",
|
| 120 |
+
"?" /* 0x41 - 0x46 */
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
#define rdp_check_monitor_layout_pdu_state(rdp, expected) \
|
| 124 |
+
rdp_check_monitor_layout_pdu_state_(rdp, expected, __FILE__, __func__, __LINE__)
|
| 125 |
+
|
| 126 |
+
static BOOL rdp_check_monitor_layout_pdu_state_(const rdpRdp* rdp, BOOL expected, const char* file,
|
| 127 |
+
const char* fkt, size_t line)
|
| 128 |
+
{
|
| 129 |
+
WINPR_ASSERT(rdp);
|
| 130 |
+
if (expected != rdp->monitor_layout_pdu)
|
| 131 |
+
{
|
| 132 |
+
const DWORD log_level = WLOG_ERROR;
|
| 133 |
+
if (WLog_IsLevelActive(rdp->log, log_level))
|
| 134 |
+
{
|
| 135 |
+
WLog_PrintMessage(rdp->log, WLOG_MESSAGE_TEXT, log_level, line, file, fkt,
|
| 136 |
+
"Expected rdp->monitor_layout_pdu == %s",
|
| 137 |
+
expected ? "TRUE" : "FALSE");
|
| 138 |
+
}
|
| 139 |
+
return FALSE;
|
| 140 |
+
}
|
| 141 |
+
return TRUE;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
#define rdp_set_monitor_layout_pdu_state(rdp, expected) \
|
| 145 |
+
rdp_set_monitor_layout_pdu_state_(rdp, expected, __FILE__, __func__, __LINE__)
|
| 146 |
+
static BOOL rdp_set_monitor_layout_pdu_state_(rdpRdp* rdp, BOOL value, const char* file,
|
| 147 |
+
const char* fkt, size_t line)
|
| 148 |
+
{
|
| 149 |
+
|
| 150 |
+
WINPR_ASSERT(rdp);
|
| 151 |
+
if (value && (value == rdp->monitor_layout_pdu))
|
| 152 |
+
{
|
| 153 |
+
const DWORD log_level = WLOG_WARN;
|
| 154 |
+
if (WLog_IsLevelActive(rdp->log, log_level))
|
| 155 |
+
{
|
| 156 |
+
WLog_PrintMessage(rdp->log, WLOG_MESSAGE_TEXT, log_level, line, file, fkt,
|
| 157 |
+
"rdp->monitor_layout_pdu == %s, expected FALSE",
|
| 158 |
+
value ? "TRUE" : "FALSE");
|
| 159 |
+
}
|
| 160 |
+
return FALSE;
|
| 161 |
+
}
|
| 162 |
+
rdp->monitor_layout_pdu = value;
|
| 163 |
+
return TRUE;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
const char* data_pdu_type_to_string(UINT8 type)
|
| 167 |
+
{
|
| 168 |
+
if (type >= ARRAYSIZE(DATA_PDU_TYPE_STRINGS))
|
| 169 |
+
return "???";
|
| 170 |
+
return DATA_PDU_TYPE_STRINGS[type];
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
static BOOL rdp_read_flow_control_pdu(rdpRdp* rdp, wStream* s, UINT16* type, UINT16* channel_id);
|
| 174 |
+
static BOOL rdp_write_share_control_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 type,
|
| 175 |
+
UINT16 channel_id);
|
| 176 |
+
static BOOL rdp_write_share_data_header(rdpRdp* rdp, wStream* s, size_t length, BYTE type,
|
| 177 |
+
UINT32 share_id);
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* @brief Read RDP Security Header.
|
| 181 |
+
* msdn{cc240579}
|
| 182 |
+
*
|
| 183 |
+
* @param s stream
|
| 184 |
+
* @param flags security flags
|
| 185 |
+
*
|
| 186 |
+
* @return \b TRUE for success, \b FALSE otherwise
|
| 187 |
+
*/
|
| 188 |
+
|
| 189 |
+
BOOL rdp_read_security_header(rdpRdp* rdp, wStream* s, UINT16* flags, UINT16* length)
|
| 190 |
+
{
|
| 191 |
+
char buffer[256] = { 0 };
|
| 192 |
+
WINPR_ASSERT(s);
|
| 193 |
+
WINPR_ASSERT(flags);
|
| 194 |
+
WINPR_ASSERT(rdp);
|
| 195 |
+
|
| 196 |
+
/* Basic Security Header */
|
| 197 |
+
if ((length && (*length < 4)))
|
| 198 |
+
{
|
| 199 |
+
WLog_Print(rdp->log, WLOG_WARN,
|
| 200 |
+
"invalid security header length, have %" PRIu16 ", must be >= 4", *length);
|
| 201 |
+
return FALSE;
|
| 202 |
+
}
|
| 203 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 4))
|
| 204 |
+
return FALSE;
|
| 205 |
+
|
| 206 |
+
Stream_Read_UINT16(s, *flags); /* flags */
|
| 207 |
+
Stream_Seek(s, 2); /* flagsHi (unused) */
|
| 208 |
+
WLog_Print(rdp->log, WLOG_TRACE, "%s",
|
| 209 |
+
rdp_security_flag_string(*flags, buffer, sizeof(buffer)));
|
| 210 |
+
if (length)
|
| 211 |
+
*length -= 4;
|
| 212 |
+
|
| 213 |
+
return TRUE;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
/**
|
| 217 |
+
* Write RDP Security Header.
|
| 218 |
+
* msdn{cc240579}
|
| 219 |
+
* @param s stream
|
| 220 |
+
* @param flags security flags
|
| 221 |
+
*
|
| 222 |
+
* @return \b TRUE for success, \b FALSE otherwise
|
| 223 |
+
*/
|
| 224 |
+
|
| 225 |
+
BOOL rdp_write_security_header(rdpRdp* rdp, wStream* s, UINT16 flags)
|
| 226 |
+
{
|
| 227 |
+
char buffer[256] = { 0 };
|
| 228 |
+
WINPR_ASSERT(s);
|
| 229 |
+
WINPR_ASSERT(rdp);
|
| 230 |
+
|
| 231 |
+
if (!Stream_CheckAndLogRequiredCapacityWLog(rdp->log, (s), 4))
|
| 232 |
+
return FALSE;
|
| 233 |
+
|
| 234 |
+
WLog_Print(rdp->log, WLOG_TRACE, "%s", rdp_security_flag_string(flags, buffer, sizeof(buffer)));
|
| 235 |
+
/* Basic Security Header */
|
| 236 |
+
Stream_Write_UINT16(s, flags); /* flags */
|
| 237 |
+
Stream_Write_UINT16(s, 0); /* flagsHi (unused) */
|
| 238 |
+
return TRUE;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
BOOL rdp_read_share_control_header(rdpRdp* rdp, wStream* s, UINT16* tpktLength,
|
| 242 |
+
UINT16* remainingLength, UINT16* type, UINT16* channel_id)
|
| 243 |
+
{
|
| 244 |
+
UINT16 len = 0;
|
| 245 |
+
UINT16 tmp = 0;
|
| 246 |
+
|
| 247 |
+
WINPR_ASSERT(rdp);
|
| 248 |
+
WINPR_ASSERT(s);
|
| 249 |
+
WINPR_ASSERT(type);
|
| 250 |
+
WINPR_ASSERT(channel_id);
|
| 251 |
+
|
| 252 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 2))
|
| 253 |
+
return FALSE;
|
| 254 |
+
|
| 255 |
+
/* Share Control Header */
|
| 256 |
+
Stream_Read_UINT16(s, len); /* totalLength */
|
| 257 |
+
|
| 258 |
+
/* If length is 0x8000 then we actually got a flow control PDU that we should ignore
|
| 259 |
+
http://msdn.microsoft.com/en-us/library/cc240576.aspx */
|
| 260 |
+
if (len == 0x8000)
|
| 261 |
+
{
|
| 262 |
+
if (!rdp_read_flow_control_pdu(rdp, s, type, channel_id))
|
| 263 |
+
return FALSE;
|
| 264 |
+
*channel_id = 0;
|
| 265 |
+
if (tpktLength)
|
| 266 |
+
*tpktLength = 8; /* Flow control PDU is 8 bytes */
|
| 267 |
+
if (remainingLength)
|
| 268 |
+
*remainingLength = 0;
|
| 269 |
+
|
| 270 |
+
char buffer[128] = { 0 };
|
| 271 |
+
WLog_Print(rdp->log, WLOG_DEBUG,
|
| 272 |
+
"[Flow control PDU] type=%s, tpktLength=%" PRIuz ", remainingLength=%" PRIuz,
|
| 273 |
+
pdu_type_to_str(*type, buffer, sizeof(buffer)), tpktLength ? *tpktLength : 0,
|
| 274 |
+
remainingLength ? *remainingLength : 0);
|
| 275 |
+
return TRUE;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
if (len < 4U)
|
| 279 |
+
{
|
| 280 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 281 |
+
"Invalid share control header, length is %" PRIu16 ", must be >4", len);
|
| 282 |
+
return FALSE;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
if (tpktLength)
|
| 286 |
+
*tpktLength = len;
|
| 287 |
+
|
| 288 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 2))
|
| 289 |
+
return FALSE;
|
| 290 |
+
|
| 291 |
+
Stream_Read_UINT16(s, tmp); /* pduType */
|
| 292 |
+
*type = tmp & 0x0F; /* type is in the 4 least significant bits */
|
| 293 |
+
|
| 294 |
+
size_t remLen = len - 4;
|
| 295 |
+
if (len > 5)
|
| 296 |
+
{
|
| 297 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 2))
|
| 298 |
+
return FALSE;
|
| 299 |
+
|
| 300 |
+
Stream_Read_UINT16(s, *channel_id); /* pduSource */
|
| 301 |
+
remLen = len - 6;
|
| 302 |
+
}
|
| 303 |
+
else
|
| 304 |
+
*channel_id = 0; /* Windows XP can send such short DEACTIVATE_ALL PDUs. */
|
| 305 |
+
|
| 306 |
+
char buffer[128] = { 0 };
|
| 307 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "type=%s, tpktLength=%" PRIuz ", remainingLength=%" PRIuz,
|
| 308 |
+
pdu_type_to_str(*type, buffer, sizeof(buffer)), len, remLen);
|
| 309 |
+
if (remainingLength)
|
| 310 |
+
{
|
| 311 |
+
WINPR_ASSERT(remLen <= UINT16_MAX);
|
| 312 |
+
*remainingLength = (UINT16)remLen;
|
| 313 |
+
}
|
| 314 |
+
return Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, remLen);
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
BOOL rdp_write_share_control_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 type,
|
| 318 |
+
UINT16 channel_id)
|
| 319 |
+
{
|
| 320 |
+
WINPR_ASSERT(s);
|
| 321 |
+
WINPR_ASSERT(rdp);
|
| 322 |
+
if (length > UINT16_MAX)
|
| 323 |
+
return FALSE;
|
| 324 |
+
|
| 325 |
+
if (length < RDP_PACKET_HEADER_MAX_LENGTH)
|
| 326 |
+
return FALSE;
|
| 327 |
+
if (!Stream_CheckAndLogRequiredCapacityWLog(rdp->log, (s), 6))
|
| 328 |
+
return FALSE;
|
| 329 |
+
length -= RDP_PACKET_HEADER_MAX_LENGTH;
|
| 330 |
+
/* Share Control Header */
|
| 331 |
+
Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, length)); /* totalLength */
|
| 332 |
+
Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, type | 0x10)); /* pduType */
|
| 333 |
+
Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, channel_id)); /* pduSource */
|
| 334 |
+
return TRUE;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
BOOL rdp_read_share_data_header(rdpRdp* rdp, wStream* s, UINT16* length, BYTE* type,
|
| 338 |
+
UINT32* shareId, BYTE* compressedType, UINT16* compressedLength)
|
| 339 |
+
{
|
| 340 |
+
WINPR_ASSERT(s);
|
| 341 |
+
WINPR_ASSERT(rdp);
|
| 342 |
+
|
| 343 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 12))
|
| 344 |
+
return FALSE;
|
| 345 |
+
|
| 346 |
+
/* Share Data Header */
|
| 347 |
+
Stream_Read_UINT32(s, *shareId); /* shareId (4 bytes) */
|
| 348 |
+
Stream_Seek_UINT8(s); /* pad1 (1 byte) */
|
| 349 |
+
Stream_Seek_UINT8(s); /* streamId (1 byte) */
|
| 350 |
+
Stream_Read_UINT16(s, *length); /* uncompressedLength (2 bytes) */
|
| 351 |
+
Stream_Read_UINT8(s, *type); /* pduType2, Data PDU Type (1 byte) */
|
| 352 |
+
Stream_Read_UINT8(s, *compressedType); /* compressedType (1 byte) */
|
| 353 |
+
Stream_Read_UINT16(s, *compressedLength); /* compressedLength (2 bytes) */
|
| 354 |
+
return TRUE;
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
BOOL rdp_write_share_data_header(rdpRdp* rdp, wStream* s, size_t length, BYTE type, UINT32 share_id)
|
| 358 |
+
{
|
| 359 |
+
const size_t headerLen = RDP_PACKET_HEADER_MAX_LENGTH + RDP_SHARE_CONTROL_HEADER_LENGTH +
|
| 360 |
+
RDP_SHARE_DATA_HEADER_LENGTH;
|
| 361 |
+
|
| 362 |
+
WINPR_ASSERT(s);
|
| 363 |
+
WINPR_ASSERT(rdp);
|
| 364 |
+
if (length > UINT16_MAX)
|
| 365 |
+
return FALSE;
|
| 366 |
+
|
| 367 |
+
if (length < headerLen)
|
| 368 |
+
return FALSE;
|
| 369 |
+
length -= headerLen;
|
| 370 |
+
if (!Stream_CheckAndLogRequiredCapacityWLog(rdp->log, (s), 12))
|
| 371 |
+
return FALSE;
|
| 372 |
+
|
| 373 |
+
/* Share Data Header */
|
| 374 |
+
Stream_Write_UINT32(s, share_id); /* shareId (4 bytes) */
|
| 375 |
+
Stream_Write_UINT8(s, 0); /* pad1 (1 byte) */
|
| 376 |
+
Stream_Write_UINT8(s, STREAM_LOW); /* streamId (1 byte) */
|
| 377 |
+
Stream_Write_UINT16(
|
| 378 |
+
s, WINPR_ASSERTING_INT_CAST(uint16_t, length)); /* uncompressedLength (2 bytes) */
|
| 379 |
+
Stream_Write_UINT8(s, type); /* pduType2, Data PDU Type (1 byte) */
|
| 380 |
+
Stream_Write_UINT8(s, 0); /* compressedType (1 byte) */
|
| 381 |
+
Stream_Write_UINT16(s, 0); /* compressedLength (2 bytes) */
|
| 382 |
+
return TRUE;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
static BOOL rdp_security_stream_init(rdpRdp* rdp, wStream* s, BOOL sec_header)
|
| 386 |
+
{
|
| 387 |
+
WINPR_ASSERT(rdp);
|
| 388 |
+
WINPR_ASSERT(s);
|
| 389 |
+
|
| 390 |
+
if (rdp->do_crypt)
|
| 391 |
+
{
|
| 392 |
+
if (!Stream_SafeSeek(s, 12))
|
| 393 |
+
return FALSE;
|
| 394 |
+
|
| 395 |
+
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
| 396 |
+
{
|
| 397 |
+
if (!Stream_SafeSeek(s, 4))
|
| 398 |
+
return FALSE;
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
rdp->sec_flags |= SEC_ENCRYPT;
|
| 402 |
+
|
| 403 |
+
if (rdp->do_secure_checksum)
|
| 404 |
+
rdp->sec_flags |= SEC_SECURE_CHECKSUM;
|
| 405 |
+
}
|
| 406 |
+
else if (rdp->sec_flags != 0 || sec_header)
|
| 407 |
+
{
|
| 408 |
+
if (!Stream_SafeSeek(s, 4))
|
| 409 |
+
return FALSE;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
return TRUE;
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
wStream* rdp_send_stream_init(rdpRdp* rdp)
|
| 416 |
+
{
|
| 417 |
+
wStream* s = NULL;
|
| 418 |
+
|
| 419 |
+
WINPR_ASSERT(rdp);
|
| 420 |
+
WINPR_ASSERT(rdp->transport);
|
| 421 |
+
|
| 422 |
+
s = transport_send_stream_init(rdp->transport, 4096);
|
| 423 |
+
|
| 424 |
+
if (!s)
|
| 425 |
+
return NULL;
|
| 426 |
+
|
| 427 |
+
if (!Stream_SafeSeek(s, RDP_PACKET_HEADER_MAX_LENGTH))
|
| 428 |
+
goto fail;
|
| 429 |
+
|
| 430 |
+
if (!rdp_security_stream_init(rdp, s, FALSE))
|
| 431 |
+
goto fail;
|
| 432 |
+
|
| 433 |
+
return s;
|
| 434 |
+
fail:
|
| 435 |
+
Stream_Release(s);
|
| 436 |
+
return NULL;
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
wStream* rdp_send_stream_pdu_init(rdpRdp* rdp)
|
| 440 |
+
{
|
| 441 |
+
wStream* s = rdp_send_stream_init(rdp);
|
| 442 |
+
|
| 443 |
+
if (!s)
|
| 444 |
+
return NULL;
|
| 445 |
+
|
| 446 |
+
if (!Stream_SafeSeek(s, RDP_SHARE_CONTROL_HEADER_LENGTH))
|
| 447 |
+
goto fail;
|
| 448 |
+
|
| 449 |
+
return s;
|
| 450 |
+
fail:
|
| 451 |
+
Stream_Release(s);
|
| 452 |
+
return NULL;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
wStream* rdp_data_pdu_init(rdpRdp* rdp)
|
| 456 |
+
{
|
| 457 |
+
wStream* s = rdp_send_stream_pdu_init(rdp);
|
| 458 |
+
|
| 459 |
+
if (!s)
|
| 460 |
+
return NULL;
|
| 461 |
+
|
| 462 |
+
if (!Stream_SafeSeek(s, RDP_SHARE_DATA_HEADER_LENGTH))
|
| 463 |
+
goto fail;
|
| 464 |
+
|
| 465 |
+
return s;
|
| 466 |
+
fail:
|
| 467 |
+
Stream_Release(s);
|
| 468 |
+
return NULL;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
BOOL rdp_set_error_info(rdpRdp* rdp, UINT32 errorInfo)
|
| 472 |
+
{
|
| 473 |
+
WINPR_ASSERT(rdp);
|
| 474 |
+
|
| 475 |
+
rdp->errorInfo = errorInfo;
|
| 476 |
+
|
| 477 |
+
if (rdp->errorInfo != ERRINFO_SUCCESS)
|
| 478 |
+
{
|
| 479 |
+
rdpContext* context = rdp->context;
|
| 480 |
+
WINPR_ASSERT(context);
|
| 481 |
+
|
| 482 |
+
rdp_print_errinfo(rdp->errorInfo);
|
| 483 |
+
|
| 484 |
+
if (context)
|
| 485 |
+
{
|
| 486 |
+
freerdp_set_last_error_log(context, MAKE_FREERDP_ERROR(ERRINFO, errorInfo));
|
| 487 |
+
|
| 488 |
+
if (context->pubSub)
|
| 489 |
+
{
|
| 490 |
+
ErrorInfoEventArgs e = { 0 };
|
| 491 |
+
EventArgsInit(&e, "freerdp");
|
| 492 |
+
e.code = rdp->errorInfo;
|
| 493 |
+
PubSub_OnErrorInfo(context->pubSub, context, &e);
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
else
|
| 497 |
+
WLog_Print(rdp->log, WLOG_ERROR, "missing context=%p", context);
|
| 498 |
+
}
|
| 499 |
+
else
|
| 500 |
+
{
|
| 501 |
+
freerdp_set_last_error_log(rdp->context, FREERDP_ERROR_SUCCESS);
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
return TRUE;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
wStream* rdp_message_channel_pdu_init(rdpRdp* rdp)
|
| 508 |
+
{
|
| 509 |
+
wStream* s = NULL;
|
| 510 |
+
|
| 511 |
+
WINPR_ASSERT(rdp);
|
| 512 |
+
|
| 513 |
+
s = transport_send_stream_init(rdp->transport, 4096);
|
| 514 |
+
|
| 515 |
+
if (!s)
|
| 516 |
+
return NULL;
|
| 517 |
+
|
| 518 |
+
if (!Stream_SafeSeek(s, RDP_PACKET_HEADER_MAX_LENGTH))
|
| 519 |
+
goto fail;
|
| 520 |
+
|
| 521 |
+
if (!rdp_security_stream_init(rdp, s, TRUE))
|
| 522 |
+
goto fail;
|
| 523 |
+
|
| 524 |
+
return s;
|
| 525 |
+
fail:
|
| 526 |
+
Stream_Release(s);
|
| 527 |
+
return NULL;
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
/**
|
| 531 |
+
* Read an RDP packet header.
|
| 532 |
+
* @param rdp rdp module
|
| 533 |
+
* @param s stream
|
| 534 |
+
* @param length RDP packet length
|
| 535 |
+
* @param channelId channel id
|
| 536 |
+
*
|
| 537 |
+
* @return \b TRUE for success, \b FALSE otherwise
|
| 538 |
+
*/
|
| 539 |
+
|
| 540 |
+
BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channelId)
|
| 541 |
+
{
|
| 542 |
+
BYTE li = 0;
|
| 543 |
+
BYTE code = 0;
|
| 544 |
+
BYTE choice = 0;
|
| 545 |
+
UINT16 initiator = 0;
|
| 546 |
+
|
| 547 |
+
WINPR_ASSERT(rdp);
|
| 548 |
+
WINPR_ASSERT(rdp->settings);
|
| 549 |
+
WINPR_ASSERT(s);
|
| 550 |
+
DomainMCSPDU MCSPDU = (rdp->settings->ServerMode) ? DomainMCSPDU_SendDataRequest
|
| 551 |
+
: DomainMCSPDU_SendDataIndication;
|
| 552 |
+
|
| 553 |
+
*channelId = 0; /* Initialize in case of early abort */
|
| 554 |
+
if (!tpkt_read_header(s, length))
|
| 555 |
+
return FALSE;
|
| 556 |
+
|
| 557 |
+
if (!tpdu_read_header(s, &code, &li, *length))
|
| 558 |
+
return FALSE;
|
| 559 |
+
|
| 560 |
+
if (code != X224_TPDU_DATA)
|
| 561 |
+
{
|
| 562 |
+
if (code == X224_TPDU_DISCONNECT_REQUEST)
|
| 563 |
+
{
|
| 564 |
+
WLog_Print(rdp->log, WLOG_WARN, "Received X224_TPDU_DISCONNECT_REQUEST, terminating");
|
| 565 |
+
utils_abort_connect(rdp);
|
| 566 |
+
return TRUE;
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
WLog_Print(rdp->log, WLOG_WARN,
|
| 570 |
+
"Unexpected X224 TPDU type %s [%08" PRIx32 "] instead of %s",
|
| 571 |
+
tpdu_type_to_string(code), code, tpdu_type_to_string(X224_TPDU_DATA));
|
| 572 |
+
return FALSE;
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
if (!per_read_choice(s, &choice))
|
| 576 |
+
return FALSE;
|
| 577 |
+
|
| 578 |
+
const DomainMCSPDU domainMCSPDU = (DomainMCSPDU)(choice >> 2);
|
| 579 |
+
|
| 580 |
+
if (domainMCSPDU != MCSPDU)
|
| 581 |
+
{
|
| 582 |
+
if (domainMCSPDU != DomainMCSPDU_DisconnectProviderUltimatum)
|
| 583 |
+
{
|
| 584 |
+
WLog_Print(rdp->log, WLOG_WARN, "Received %s instead of %s",
|
| 585 |
+
mcs_domain_pdu_string(domainMCSPDU), mcs_domain_pdu_string(MCSPDU));
|
| 586 |
+
return FALSE;
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
MCSPDU = domainMCSPDU;
|
| 591 |
+
|
| 592 |
+
if (*length < 8U)
|
| 593 |
+
{
|
| 594 |
+
WLog_Print(rdp->log, WLOG_WARN, "TPDU invalid length, got %" PRIu16 ", expected at least 8",
|
| 595 |
+
*length);
|
| 596 |
+
return FALSE;
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, *length - 8))
|
| 600 |
+
return FALSE;
|
| 601 |
+
|
| 602 |
+
if (MCSPDU == DomainMCSPDU_DisconnectProviderUltimatum)
|
| 603 |
+
{
|
| 604 |
+
int reason = 0;
|
| 605 |
+
TerminateEventArgs e = { 0 };
|
| 606 |
+
|
| 607 |
+
if (!mcs_recv_disconnect_provider_ultimatum(rdp->mcs, s, &reason))
|
| 608 |
+
return FALSE;
|
| 609 |
+
|
| 610 |
+
rdpContext* context = rdp->context;
|
| 611 |
+
WINPR_ASSERT(context);
|
| 612 |
+
context->disconnectUltimatum = reason;
|
| 613 |
+
|
| 614 |
+
if (rdp->errorInfo == ERRINFO_SUCCESS)
|
| 615 |
+
{
|
| 616 |
+
/**
|
| 617 |
+
* Some servers like Windows Server 2008 R2 do not send the error info pdu
|
| 618 |
+
* when the user logs off like they should. Map DisconnectProviderUltimatum
|
| 619 |
+
* to a ERRINFO_LOGOFF_BY_USER when the errinfo code is ERRINFO_SUCCESS.
|
| 620 |
+
*/
|
| 621 |
+
UINT32 errorInfo = ERRINFO_RPC_INITIATED_DISCONNECT;
|
| 622 |
+
if (reason == Disconnect_Ultimatum_provider_initiated)
|
| 623 |
+
errorInfo = ERRINFO_RPC_INITIATED_DISCONNECT;
|
| 624 |
+
else if (reason == Disconnect_Ultimatum_user_requested)
|
| 625 |
+
errorInfo = ERRINFO_LOGOFF_BY_USER;
|
| 626 |
+
|
| 627 |
+
rdp_set_error_info(rdp, errorInfo);
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "DisconnectProviderUltimatum: reason: %d", reason);
|
| 631 |
+
utils_abort_connect(rdp);
|
| 632 |
+
EventArgsInit(&e, "freerdp");
|
| 633 |
+
e.code = 0;
|
| 634 |
+
PubSub_OnTerminate(rdp->pubSub, context, &e);
|
| 635 |
+
return TRUE;
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 5))
|
| 639 |
+
return FALSE;
|
| 640 |
+
|
| 641 |
+
if (!per_read_integer16(s, &initiator, MCS_BASE_CHANNEL_ID)) /* initiator (UserId) */
|
| 642 |
+
return FALSE;
|
| 643 |
+
|
| 644 |
+
if (!per_read_integer16(s, channelId, 0)) /* channelId */
|
| 645 |
+
return FALSE;
|
| 646 |
+
|
| 647 |
+
const uint8_t byte = Stream_Get_UINT8(s); /* dataPriority + Segmentation (0x70) */
|
| 648 |
+
|
| 649 |
+
if (!per_read_length(s, length)) /* userData (OCTET_STRING) */
|
| 650 |
+
return FALSE;
|
| 651 |
+
|
| 652 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, *length))
|
| 653 |
+
return FALSE;
|
| 654 |
+
|
| 655 |
+
return TRUE;
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
/**
|
| 659 |
+
* Write an RDP packet header.
|
| 660 |
+
* @param rdp rdp module
|
| 661 |
+
* @param s stream
|
| 662 |
+
* @param length RDP packet length
|
| 663 |
+
* @param channelId channel id
|
| 664 |
+
*
|
| 665 |
+
* @return \b TRUE for success, \b FALSE otherwise
|
| 666 |
+
*/
|
| 667 |
+
|
| 668 |
+
BOOL rdp_write_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 channelId)
|
| 669 |
+
{
|
| 670 |
+
WINPR_ASSERT(rdp);
|
| 671 |
+
WINPR_ASSERT(rdp->settings);
|
| 672 |
+
WINPR_ASSERT(s);
|
| 673 |
+
WINPR_ASSERT(length >= RDP_PACKET_HEADER_MAX_LENGTH);
|
| 674 |
+
if (length > UINT16_MAX)
|
| 675 |
+
return FALSE;
|
| 676 |
+
|
| 677 |
+
DomainMCSPDU MCSPDU = (rdp->settings->ServerMode) ? DomainMCSPDU_SendDataIndication
|
| 678 |
+
: DomainMCSPDU_SendDataRequest;
|
| 679 |
+
|
| 680 |
+
if ((rdp->sec_flags & SEC_ENCRYPT) &&
|
| 681 |
+
(rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS))
|
| 682 |
+
{
|
| 683 |
+
const UINT16 body_length = (UINT16)length - RDP_PACKET_HEADER_MAX_LENGTH;
|
| 684 |
+
const UINT16 pad = 8 - (body_length % 8);
|
| 685 |
+
|
| 686 |
+
if (pad != 8)
|
| 687 |
+
length += pad;
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
if (!mcs_write_domain_mcspdu_header(s, MCSPDU, (UINT16)length, 0))
|
| 691 |
+
return FALSE;
|
| 692 |
+
if (!per_write_integer16(s, rdp->mcs->userId, MCS_BASE_CHANNEL_ID)) /* initiator */
|
| 693 |
+
return FALSE;
|
| 694 |
+
if (!per_write_integer16(s, channelId, 0)) /* channelId */
|
| 695 |
+
return FALSE;
|
| 696 |
+
if (!Stream_EnsureRemainingCapacity(s, 3))
|
| 697 |
+
return FALSE;
|
| 698 |
+
Stream_Write_UINT8(s, 0x70); /* dataPriority + segmentation */
|
| 699 |
+
/*
|
| 700 |
+
* We always encode length in two bytes, even though we could use
|
| 701 |
+
* only one byte if length <= 0x7F. It is just easier that way,
|
| 702 |
+
* because we can leave room for fixed-length header, store all
|
| 703 |
+
* the data first and then store the header.
|
| 704 |
+
*/
|
| 705 |
+
length = (length - RDP_PACKET_HEADER_MAX_LENGTH) | 0x8000;
|
| 706 |
+
Stream_Write_UINT16_BE(
|
| 707 |
+
s, WINPR_ASSERTING_INT_CAST(uint16_t, length)); /* userData (OCTET_STRING) */
|
| 708 |
+
return TRUE;
|
| 709 |
+
}
|
| 710 |
+
|
| 711 |
+
static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, size_t length, UINT32 sec_flags,
|
| 712 |
+
UINT32* pad)
|
| 713 |
+
{
|
| 714 |
+
BOOL status = 0;
|
| 715 |
+
WINPR_ASSERT(rdp);
|
| 716 |
+
if (length > UINT16_MAX)
|
| 717 |
+
return FALSE;
|
| 718 |
+
|
| 719 |
+
sec_flags |= rdp->sec_flags;
|
| 720 |
+
*pad = 0;
|
| 721 |
+
|
| 722 |
+
if (sec_flags != 0)
|
| 723 |
+
{
|
| 724 |
+
WINPR_ASSERT(sec_flags <= UINT16_MAX);
|
| 725 |
+
if (!rdp_write_security_header(rdp, s, (UINT16)sec_flags))
|
| 726 |
+
return FALSE;
|
| 727 |
+
|
| 728 |
+
if (sec_flags & SEC_ENCRYPT)
|
| 729 |
+
{
|
| 730 |
+
BOOL res = FALSE;
|
| 731 |
+
if (!security_lock(rdp))
|
| 732 |
+
return FALSE;
|
| 733 |
+
|
| 734 |
+
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
| 735 |
+
{
|
| 736 |
+
BYTE* data = Stream_PointerAs(s, BYTE) + 12;
|
| 737 |
+
const size_t size = WINPR_ASSERTING_INT_CAST(size_t, (data - Stream_Buffer(s)));
|
| 738 |
+
if (size > length)
|
| 739 |
+
goto unlock;
|
| 740 |
+
|
| 741 |
+
length -= size;
|
| 742 |
+
|
| 743 |
+
Stream_Write_UINT16(s, 0x10); /* length */
|
| 744 |
+
Stream_Write_UINT8(s, 0x1); /* TSFIPS_VERSION 1*/
|
| 745 |
+
/* handle padding */
|
| 746 |
+
*pad = 8 - (length % 8);
|
| 747 |
+
|
| 748 |
+
if (*pad == 8)
|
| 749 |
+
*pad = 0;
|
| 750 |
+
|
| 751 |
+
if (*pad)
|
| 752 |
+
memset(data + length, 0, *pad);
|
| 753 |
+
|
| 754 |
+
Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, *pad));
|
| 755 |
+
|
| 756 |
+
if (!Stream_CheckAndLogRequiredCapacityWLog(rdp->log, s, 8))
|
| 757 |
+
goto unlock;
|
| 758 |
+
if (!security_hmac_signature(data, length, Stream_Pointer(s), 8, rdp))
|
| 759 |
+
goto unlock;
|
| 760 |
+
|
| 761 |
+
Stream_Seek(s, 8);
|
| 762 |
+
if (!security_fips_encrypt(data, length + *pad, rdp))
|
| 763 |
+
goto unlock;
|
| 764 |
+
}
|
| 765 |
+
else
|
| 766 |
+
{
|
| 767 |
+
const BYTE* data = Stream_PointerAs(s, const BYTE) + 8;
|
| 768 |
+
const size_t diff = Stream_GetPosition(s) + 8ULL;
|
| 769 |
+
if (diff > length)
|
| 770 |
+
goto unlock;
|
| 771 |
+
length -= diff;
|
| 772 |
+
|
| 773 |
+
if (!Stream_CheckAndLogRequiredCapacityWLog(rdp->log, s, 8))
|
| 774 |
+
goto unlock;
|
| 775 |
+
if (sec_flags & SEC_SECURE_CHECKSUM)
|
| 776 |
+
status = security_salted_mac_signature(rdp, data, (UINT32)length, TRUE,
|
| 777 |
+
Stream_Pointer(s), 8);
|
| 778 |
+
else
|
| 779 |
+
status = security_mac_signature(rdp, data, (UINT32)length,
|
| 780 |
+
Stream_PointerAs(s, BYTE), 8);
|
| 781 |
+
|
| 782 |
+
if (!status)
|
| 783 |
+
goto unlock;
|
| 784 |
+
|
| 785 |
+
Stream_Seek(s, 8);
|
| 786 |
+
|
| 787 |
+
if (!security_encrypt(Stream_Pointer(s), length, rdp))
|
| 788 |
+
goto unlock;
|
| 789 |
+
}
|
| 790 |
+
res = TRUE;
|
| 791 |
+
|
| 792 |
+
unlock:
|
| 793 |
+
|
| 794 |
+
if (!security_unlock(rdp))
|
| 795 |
+
return FALSE;
|
| 796 |
+
if (!res)
|
| 797 |
+
return FALSE;
|
| 798 |
+
}
|
| 799 |
+
|
| 800 |
+
rdp->sec_flags = 0;
|
| 801 |
+
}
|
| 802 |
+
|
| 803 |
+
return TRUE;
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
static UINT32 rdp_get_sec_bytes(rdpRdp* rdp, UINT16 sec_flags)
|
| 807 |
+
{
|
| 808 |
+
UINT32 sec_bytes = 0;
|
| 809 |
+
|
| 810 |
+
if (rdp->sec_flags & SEC_ENCRYPT)
|
| 811 |
+
{
|
| 812 |
+
sec_bytes = 12;
|
| 813 |
+
|
| 814 |
+
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
| 815 |
+
sec_bytes += 4;
|
| 816 |
+
}
|
| 817 |
+
else if (rdp->sec_flags != 0 || sec_flags != 0)
|
| 818 |
+
{
|
| 819 |
+
sec_bytes = 4;
|
| 820 |
+
}
|
| 821 |
+
else
|
| 822 |
+
{
|
| 823 |
+
sec_bytes = 0;
|
| 824 |
+
}
|
| 825 |
+
|
| 826 |
+
return sec_bytes;
|
| 827 |
+
}
|
| 828 |
+
|
| 829 |
+
/**
|
| 830 |
+
* Send an RDP packet.
|
| 831 |
+
* @param rdp RDP module
|
| 832 |
+
* @param s stream
|
| 833 |
+
* @param channel_id channel id
|
| 834 |
+
*/
|
| 835 |
+
|
| 836 |
+
BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id)
|
| 837 |
+
{
|
| 838 |
+
BOOL rc = FALSE;
|
| 839 |
+
UINT32 pad = 0;
|
| 840 |
+
|
| 841 |
+
if (!s)
|
| 842 |
+
return FALSE;
|
| 843 |
+
|
| 844 |
+
if (!rdp)
|
| 845 |
+
goto fail;
|
| 846 |
+
|
| 847 |
+
size_t length = Stream_GetPosition(s);
|
| 848 |
+
Stream_SetPosition(s, 0);
|
| 849 |
+
if (!rdp_write_header(rdp, s, length, channel_id))
|
| 850 |
+
goto fail;
|
| 851 |
+
|
| 852 |
+
if (!rdp_security_stream_out(rdp, s, length, 0, &pad))
|
| 853 |
+
goto fail;
|
| 854 |
+
|
| 855 |
+
length += pad;
|
| 856 |
+
Stream_SetPosition(s, length);
|
| 857 |
+
Stream_SealLength(s);
|
| 858 |
+
|
| 859 |
+
if (transport_write(rdp->transport, s) < 0)
|
| 860 |
+
goto fail;
|
| 861 |
+
|
| 862 |
+
rc = TRUE;
|
| 863 |
+
fail:
|
| 864 |
+
Stream_Release(s);
|
| 865 |
+
return rc;
|
| 866 |
+
}
|
| 867 |
+
|
| 868 |
+
BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id)
|
| 869 |
+
{
|
| 870 |
+
UINT32 sec_bytes = 0;
|
| 871 |
+
size_t sec_hold = 0;
|
| 872 |
+
UINT32 pad = 0;
|
| 873 |
+
|
| 874 |
+
if (!rdp || !s)
|
| 875 |
+
return FALSE;
|
| 876 |
+
|
| 877 |
+
size_t length = Stream_GetPosition(s);
|
| 878 |
+
Stream_SetPosition(s, 0);
|
| 879 |
+
if (!rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID))
|
| 880 |
+
return FALSE;
|
| 881 |
+
sec_bytes = rdp_get_sec_bytes(rdp, 0);
|
| 882 |
+
sec_hold = Stream_GetPosition(s);
|
| 883 |
+
Stream_Seek(s, sec_bytes);
|
| 884 |
+
if (!rdp_write_share_control_header(rdp, s, length - sec_bytes, type, channel_id))
|
| 885 |
+
return FALSE;
|
| 886 |
+
Stream_SetPosition(s, sec_hold);
|
| 887 |
+
|
| 888 |
+
if (!rdp_security_stream_out(rdp, s, length, 0, &pad))
|
| 889 |
+
return FALSE;
|
| 890 |
+
|
| 891 |
+
length += pad;
|
| 892 |
+
Stream_SetPosition(s, length);
|
| 893 |
+
Stream_SealLength(s);
|
| 894 |
+
|
| 895 |
+
if (transport_write(rdp->transport, s) < 0)
|
| 896 |
+
return FALSE;
|
| 897 |
+
|
| 898 |
+
return TRUE;
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id)
|
| 902 |
+
{
|
| 903 |
+
BOOL rc = FALSE;
|
| 904 |
+
UINT32 sec_bytes = 0;
|
| 905 |
+
size_t sec_hold = 0;
|
| 906 |
+
UINT32 pad = 0;
|
| 907 |
+
|
| 908 |
+
if (!s)
|
| 909 |
+
return FALSE;
|
| 910 |
+
|
| 911 |
+
if (!rdp)
|
| 912 |
+
goto fail;
|
| 913 |
+
|
| 914 |
+
size_t length = Stream_GetPosition(s);
|
| 915 |
+
Stream_SetPosition(s, 0);
|
| 916 |
+
if (!rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID))
|
| 917 |
+
goto fail;
|
| 918 |
+
sec_bytes = rdp_get_sec_bytes(rdp, 0);
|
| 919 |
+
sec_hold = Stream_GetPosition(s);
|
| 920 |
+
Stream_Seek(s, sec_bytes);
|
| 921 |
+
if (!rdp_write_share_control_header(rdp, s, length - sec_bytes, PDU_TYPE_DATA, channel_id))
|
| 922 |
+
goto fail;
|
| 923 |
+
if (!rdp_write_share_data_header(rdp, s, length - sec_bytes, type, rdp->settings->ShareId))
|
| 924 |
+
goto fail;
|
| 925 |
+
Stream_SetPosition(s, sec_hold);
|
| 926 |
+
|
| 927 |
+
if (!rdp_security_stream_out(rdp, s, length, 0, &pad))
|
| 928 |
+
goto fail;
|
| 929 |
+
|
| 930 |
+
length += pad;
|
| 931 |
+
Stream_SetPosition(s, length);
|
| 932 |
+
Stream_SealLength(s);
|
| 933 |
+
WLog_Print(rdp->log, WLOG_DEBUG,
|
| 934 |
+
"sending data (type=0x%x size=%" PRIuz " channelId=%" PRIu16 ")", type,
|
| 935 |
+
Stream_Length(s), channel_id);
|
| 936 |
+
|
| 937 |
+
rdp->outPackets++;
|
| 938 |
+
if (transport_write(rdp->transport, s) < 0)
|
| 939 |
+
goto fail;
|
| 940 |
+
|
| 941 |
+
rc = TRUE;
|
| 942 |
+
fail:
|
| 943 |
+
Stream_Release(s);
|
| 944 |
+
return rc;
|
| 945 |
+
}
|
| 946 |
+
|
| 947 |
+
BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags)
|
| 948 |
+
{
|
| 949 |
+
BOOL rc = FALSE;
|
| 950 |
+
UINT32 pad = 0;
|
| 951 |
+
|
| 952 |
+
WINPR_ASSERT(rdp);
|
| 953 |
+
WINPR_ASSERT(s);
|
| 954 |
+
|
| 955 |
+
size_t length = Stream_GetPosition(s);
|
| 956 |
+
Stream_SetPosition(s, 0);
|
| 957 |
+
if (!rdp_write_header(rdp, s, length, rdp->mcs->messageChannelId))
|
| 958 |
+
goto fail;
|
| 959 |
+
|
| 960 |
+
if (!rdp_security_stream_out(rdp, s, length, sec_flags, &pad))
|
| 961 |
+
goto fail;
|
| 962 |
+
|
| 963 |
+
length += pad;
|
| 964 |
+
Stream_SetPosition(s, length);
|
| 965 |
+
Stream_SealLength(s);
|
| 966 |
+
|
| 967 |
+
if (transport_write(rdp->transport, s) < 0)
|
| 968 |
+
goto fail;
|
| 969 |
+
|
| 970 |
+
rc = TRUE;
|
| 971 |
+
fail:
|
| 972 |
+
Stream_Release(s);
|
| 973 |
+
return rc;
|
| 974 |
+
}
|
| 975 |
+
|
| 976 |
+
static BOOL rdp_recv_server_shutdown_denied_pdu(rdpRdp* rdp, wStream* s)
|
| 977 |
+
{
|
| 978 |
+
return TRUE;
|
| 979 |
+
}
|
| 980 |
+
|
| 981 |
+
static BOOL rdp_recv_server_set_keyboard_indicators_pdu(rdpRdp* rdp, wStream* s)
|
| 982 |
+
{
|
| 983 |
+
WINPR_ASSERT(rdp);
|
| 984 |
+
WINPR_ASSERT(s);
|
| 985 |
+
|
| 986 |
+
rdpContext* context = rdp->context;
|
| 987 |
+
WINPR_ASSERT(context);
|
| 988 |
+
WINPR_ASSERT(context->update);
|
| 989 |
+
|
| 990 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 4))
|
| 991 |
+
return FALSE;
|
| 992 |
+
|
| 993 |
+
const uint16_t unitId = Stream_Get_UINT16(s); /* unitId (2 bytes) */
|
| 994 |
+
const UINT16 ledFlags = Stream_Get_UINT16(s); /* ledFlags (2 bytes) */
|
| 995 |
+
return IFCALLRESULT(TRUE, context->update->SetKeyboardIndicators, context, ledFlags);
|
| 996 |
+
}
|
| 997 |
+
|
| 998 |
+
static BOOL rdp_recv_server_set_keyboard_ime_status_pdu(rdpRdp* rdp, wStream* s)
|
| 999 |
+
{
|
| 1000 |
+
UINT16 unitId = 0;
|
| 1001 |
+
UINT32 imeState = 0;
|
| 1002 |
+
UINT32 imeConvMode = 0;
|
| 1003 |
+
|
| 1004 |
+
if (!rdp || !rdp->input)
|
| 1005 |
+
return FALSE;
|
| 1006 |
+
|
| 1007 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 10))
|
| 1008 |
+
return FALSE;
|
| 1009 |
+
|
| 1010 |
+
Stream_Read_UINT16(s, unitId); /* unitId (2 bytes) */
|
| 1011 |
+
Stream_Read_UINT32(s, imeState); /* imeState (4 bytes) */
|
| 1012 |
+
Stream_Read_UINT32(s, imeConvMode); /* imeConvMode (4 bytes) */
|
| 1013 |
+
IFCALL(rdp->update->SetKeyboardImeStatus, rdp->context, unitId, imeState, imeConvMode);
|
| 1014 |
+
return TRUE;
|
| 1015 |
+
}
|
| 1016 |
+
|
| 1017 |
+
static BOOL rdp_recv_set_error_info_data_pdu(rdpRdp* rdp, wStream* s)
|
| 1018 |
+
{
|
| 1019 |
+
UINT32 errorInfo = 0;
|
| 1020 |
+
|
| 1021 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 4))
|
| 1022 |
+
return FALSE;
|
| 1023 |
+
|
| 1024 |
+
Stream_Read_UINT32(s, errorInfo); /* errorInfo (4 bytes) */
|
| 1025 |
+
return rdp_set_error_info(rdp, errorInfo);
|
| 1026 |
+
}
|
| 1027 |
+
|
| 1028 |
+
static BOOL rdp_recv_server_auto_reconnect_status_pdu(rdpRdp* rdp, wStream* s)
|
| 1029 |
+
{
|
| 1030 |
+
UINT32 arcStatus = 0;
|
| 1031 |
+
|
| 1032 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 4))
|
| 1033 |
+
return FALSE;
|
| 1034 |
+
|
| 1035 |
+
Stream_Read_UINT32(s, arcStatus); /* arcStatus (4 bytes) */
|
| 1036 |
+
WLog_Print(rdp->log, WLOG_WARN, "AutoReconnectStatus: 0x%08" PRIX32 "", arcStatus);
|
| 1037 |
+
return TRUE;
|
| 1038 |
+
}
|
| 1039 |
+
|
| 1040 |
+
static BOOL rdp_recv_server_status_info_pdu(rdpRdp* rdp, wStream* s)
|
| 1041 |
+
{
|
| 1042 |
+
UINT32 statusCode = 0;
|
| 1043 |
+
|
| 1044 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 4))
|
| 1045 |
+
return FALSE;
|
| 1046 |
+
|
| 1047 |
+
Stream_Read_UINT32(s, statusCode); /* statusCode (4 bytes) */
|
| 1048 |
+
|
| 1049 |
+
if (rdp->update->ServerStatusInfo)
|
| 1050 |
+
return rdp->update->ServerStatusInfo(rdp->context, statusCode);
|
| 1051 |
+
|
| 1052 |
+
return TRUE;
|
| 1053 |
+
}
|
| 1054 |
+
|
| 1055 |
+
static BOOL rdp_recv_monitor_layout_pdu(rdpRdp* rdp, wStream* s)
|
| 1056 |
+
{
|
| 1057 |
+
UINT32 monitorCount = 0;
|
| 1058 |
+
MONITOR_DEF* monitorDefArray = NULL;
|
| 1059 |
+
BOOL ret = TRUE;
|
| 1060 |
+
|
| 1061 |
+
WINPR_ASSERT(rdp);
|
| 1062 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 4))
|
| 1063 |
+
return FALSE;
|
| 1064 |
+
|
| 1065 |
+
Stream_Read_UINT32(s, monitorCount); /* monitorCount (4 bytes) */
|
| 1066 |
+
|
| 1067 |
+
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(rdp->log, s, monitorCount, 20ull))
|
| 1068 |
+
return FALSE;
|
| 1069 |
+
|
| 1070 |
+
monitorDefArray = (MONITOR_DEF*)calloc(monitorCount, sizeof(MONITOR_DEF));
|
| 1071 |
+
|
| 1072 |
+
if (!monitorDefArray)
|
| 1073 |
+
return FALSE;
|
| 1074 |
+
|
| 1075 |
+
for (UINT32 index = 0; index < monitorCount; index++)
|
| 1076 |
+
{
|
| 1077 |
+
MONITOR_DEF* monitor = &monitorDefArray[index];
|
| 1078 |
+
Stream_Read_INT32(s, monitor->left); /* left (4 bytes) */
|
| 1079 |
+
Stream_Read_INT32(s, monitor->top); /* top (4 bytes) */
|
| 1080 |
+
Stream_Read_INT32(s, monitor->right); /* right (4 bytes) */
|
| 1081 |
+
Stream_Read_INT32(s, monitor->bottom); /* bottom (4 bytes) */
|
| 1082 |
+
Stream_Read_UINT32(s, monitor->flags); /* flags (4 bytes) */
|
| 1083 |
+
}
|
| 1084 |
+
|
| 1085 |
+
IFCALLRET(rdp->update->RemoteMonitors, ret, rdp->context, monitorCount, monitorDefArray);
|
| 1086 |
+
free(monitorDefArray);
|
| 1087 |
+
if (!ret)
|
| 1088 |
+
return FALSE;
|
| 1089 |
+
return rdp_set_monitor_layout_pdu_state(rdp, TRUE);
|
| 1090 |
+
}
|
| 1091 |
+
|
| 1092 |
+
state_run_t rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
|
| 1093 |
+
{
|
| 1094 |
+
BYTE type = 0;
|
| 1095 |
+
wStream* cs = NULL;
|
| 1096 |
+
UINT16 length = 0;
|
| 1097 |
+
UINT32 shareId = 0;
|
| 1098 |
+
BYTE compressedType = 0;
|
| 1099 |
+
UINT16 compressedLength = 0;
|
| 1100 |
+
|
| 1101 |
+
WINPR_ASSERT(rdp);
|
| 1102 |
+
if (!rdp_read_share_data_header(rdp, s, &length, &type, &shareId, &compressedType,
|
| 1103 |
+
&compressedLength))
|
| 1104 |
+
{
|
| 1105 |
+
WLog_Print(rdp->log, WLOG_ERROR, "rdp_read_share_data_header() failed");
|
| 1106 |
+
return STATE_RUN_FAILED;
|
| 1107 |
+
}
|
| 1108 |
+
|
| 1109 |
+
cs = s;
|
| 1110 |
+
|
| 1111 |
+
if (compressedType & PACKET_COMPRESSED)
|
| 1112 |
+
{
|
| 1113 |
+
if (compressedLength < 18)
|
| 1114 |
+
{
|
| 1115 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1116 |
+
"bulk_decompress: not enough bytes for compressedLength %" PRIu16 "",
|
| 1117 |
+
compressedLength);
|
| 1118 |
+
return STATE_RUN_FAILED;
|
| 1119 |
+
}
|
| 1120 |
+
|
| 1121 |
+
UINT32 DstSize = 0;
|
| 1122 |
+
const BYTE* pDstData = NULL;
|
| 1123 |
+
UINT16 SrcSize = compressedLength - 18;
|
| 1124 |
+
|
| 1125 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, SrcSize))
|
| 1126 |
+
{
|
| 1127 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1128 |
+
"bulk_decompress: not enough bytes for compressedLength %" PRIu16 "",
|
| 1129 |
+
compressedLength);
|
| 1130 |
+
return STATE_RUN_FAILED;
|
| 1131 |
+
}
|
| 1132 |
+
|
| 1133 |
+
if (bulk_decompress(rdp->bulk, Stream_ConstPointer(s), SrcSize, &pDstData, &DstSize,
|
| 1134 |
+
compressedType))
|
| 1135 |
+
{
|
| 1136 |
+
cs = transport_take_from_pool(rdp->transport, DstSize);
|
| 1137 |
+
if (!cs)
|
| 1138 |
+
{
|
| 1139 |
+
WLog_Print(rdp->log, WLOG_ERROR, "Couldn't take stream from pool");
|
| 1140 |
+
return STATE_RUN_FAILED;
|
| 1141 |
+
}
|
| 1142 |
+
|
| 1143 |
+
Stream_SetPosition(cs, 0);
|
| 1144 |
+
Stream_Write(cs, pDstData, DstSize);
|
| 1145 |
+
Stream_SealLength(cs);
|
| 1146 |
+
Stream_SetPosition(cs, 0);
|
| 1147 |
+
}
|
| 1148 |
+
else
|
| 1149 |
+
{
|
| 1150 |
+
WLog_Print(rdp->log, WLOG_ERROR, "bulk_decompress() failed");
|
| 1151 |
+
return STATE_RUN_FAILED;
|
| 1152 |
+
}
|
| 1153 |
+
|
| 1154 |
+
Stream_Seek(s, SrcSize);
|
| 1155 |
+
}
|
| 1156 |
+
|
| 1157 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "recv %s Data PDU (0x%02" PRIX8 "), length: %" PRIu16 "",
|
| 1158 |
+
data_pdu_type_to_string(type), type, length);
|
| 1159 |
+
|
| 1160 |
+
switch (type)
|
| 1161 |
+
{
|
| 1162 |
+
case DATA_PDU_TYPE_UPDATE:
|
| 1163 |
+
if (!update_recv(rdp->update, cs))
|
| 1164 |
+
{
|
| 1165 |
+
WLog_Print(rdp->log, WLOG_ERROR, "DATA_PDU_TYPE_UPDATE - update_recv() failed");
|
| 1166 |
+
goto out_fail;
|
| 1167 |
+
}
|
| 1168 |
+
|
| 1169 |
+
break;
|
| 1170 |
+
|
| 1171 |
+
case DATA_PDU_TYPE_CONTROL:
|
| 1172 |
+
if (!rdp_recv_server_control_pdu(rdp, cs))
|
| 1173 |
+
{
|
| 1174 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1175 |
+
"DATA_PDU_TYPE_CONTROL - rdp_recv_server_control_pdu() failed");
|
| 1176 |
+
goto out_fail;
|
| 1177 |
+
}
|
| 1178 |
+
|
| 1179 |
+
break;
|
| 1180 |
+
|
| 1181 |
+
case DATA_PDU_TYPE_POINTER:
|
| 1182 |
+
if (!update_recv_pointer(rdp->update, cs))
|
| 1183 |
+
{
|
| 1184 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1185 |
+
"DATA_PDU_TYPE_POINTER - update_recv_pointer() failed");
|
| 1186 |
+
goto out_fail;
|
| 1187 |
+
}
|
| 1188 |
+
|
| 1189 |
+
break;
|
| 1190 |
+
|
| 1191 |
+
case DATA_PDU_TYPE_SYNCHRONIZE:
|
| 1192 |
+
if (!rdp_recv_server_synchronize_pdu(rdp, cs))
|
| 1193 |
+
{
|
| 1194 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1195 |
+
"DATA_PDU_TYPE_SYNCHRONIZE - rdp_recv_synchronize_pdu() failed");
|
| 1196 |
+
goto out_fail;
|
| 1197 |
+
}
|
| 1198 |
+
|
| 1199 |
+
break;
|
| 1200 |
+
|
| 1201 |
+
case DATA_PDU_TYPE_PLAY_SOUND:
|
| 1202 |
+
if (!update_recv_play_sound(rdp->update, cs))
|
| 1203 |
+
{
|
| 1204 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1205 |
+
"DATA_PDU_TYPE_PLAY_SOUND - update_recv_play_sound() failed");
|
| 1206 |
+
goto out_fail;
|
| 1207 |
+
}
|
| 1208 |
+
|
| 1209 |
+
break;
|
| 1210 |
+
|
| 1211 |
+
case DATA_PDU_TYPE_SHUTDOWN_DENIED:
|
| 1212 |
+
if (!rdp_recv_server_shutdown_denied_pdu(rdp, cs))
|
| 1213 |
+
{
|
| 1214 |
+
WLog_Print(
|
| 1215 |
+
rdp->log, WLOG_ERROR,
|
| 1216 |
+
"DATA_PDU_TYPE_SHUTDOWN_DENIED - rdp_recv_server_shutdown_denied_pdu() failed");
|
| 1217 |
+
goto out_fail;
|
| 1218 |
+
}
|
| 1219 |
+
|
| 1220 |
+
break;
|
| 1221 |
+
|
| 1222 |
+
case DATA_PDU_TYPE_SAVE_SESSION_INFO:
|
| 1223 |
+
if (!rdp_recv_save_session_info(rdp, cs))
|
| 1224 |
+
{
|
| 1225 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1226 |
+
"DATA_PDU_TYPE_SAVE_SESSION_INFO - rdp_recv_save_session_info() failed");
|
| 1227 |
+
goto out_fail;
|
| 1228 |
+
}
|
| 1229 |
+
|
| 1230 |
+
break;
|
| 1231 |
+
|
| 1232 |
+
case DATA_PDU_TYPE_FONT_MAP:
|
| 1233 |
+
if (!rdp_recv_font_map_pdu(rdp, cs))
|
| 1234 |
+
{
|
| 1235 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1236 |
+
"DATA_PDU_TYPE_FONT_MAP - rdp_recv_font_map_pdu() failed");
|
| 1237 |
+
goto out_fail;
|
| 1238 |
+
}
|
| 1239 |
+
|
| 1240 |
+
break;
|
| 1241 |
+
|
| 1242 |
+
case DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS:
|
| 1243 |
+
if (!rdp_recv_server_set_keyboard_indicators_pdu(rdp, cs))
|
| 1244 |
+
{
|
| 1245 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1246 |
+
"DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS - "
|
| 1247 |
+
"rdp_recv_server_set_keyboard_indicators_pdu() failed");
|
| 1248 |
+
goto out_fail;
|
| 1249 |
+
}
|
| 1250 |
+
|
| 1251 |
+
break;
|
| 1252 |
+
|
| 1253 |
+
case DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS:
|
| 1254 |
+
if (!rdp_recv_server_set_keyboard_ime_status_pdu(rdp, cs))
|
| 1255 |
+
{
|
| 1256 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1257 |
+
"DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS - "
|
| 1258 |
+
"rdp_recv_server_set_keyboard_ime_status_pdu() failed");
|
| 1259 |
+
goto out_fail;
|
| 1260 |
+
}
|
| 1261 |
+
|
| 1262 |
+
break;
|
| 1263 |
+
|
| 1264 |
+
case DATA_PDU_TYPE_SET_ERROR_INFO:
|
| 1265 |
+
if (!rdp_recv_set_error_info_data_pdu(rdp, cs))
|
| 1266 |
+
{
|
| 1267 |
+
WLog_Print(
|
| 1268 |
+
rdp->log, WLOG_ERROR,
|
| 1269 |
+
"DATA_PDU_TYPE_SET_ERROR_INFO - rdp_recv_set_error_info_data_pdu() failed");
|
| 1270 |
+
goto out_fail;
|
| 1271 |
+
}
|
| 1272 |
+
|
| 1273 |
+
break;
|
| 1274 |
+
|
| 1275 |
+
case DATA_PDU_TYPE_ARC_STATUS:
|
| 1276 |
+
if (!rdp_recv_server_auto_reconnect_status_pdu(rdp, cs))
|
| 1277 |
+
{
|
| 1278 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1279 |
+
"DATA_PDU_TYPE_ARC_STATUS - "
|
| 1280 |
+
"rdp_recv_server_auto_reconnect_status_pdu() failed");
|
| 1281 |
+
goto out_fail;
|
| 1282 |
+
}
|
| 1283 |
+
|
| 1284 |
+
break;
|
| 1285 |
+
|
| 1286 |
+
case DATA_PDU_TYPE_STATUS_INFO:
|
| 1287 |
+
if (!rdp_recv_server_status_info_pdu(rdp, cs))
|
| 1288 |
+
{
|
| 1289 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1290 |
+
"DATA_PDU_TYPE_STATUS_INFO - rdp_recv_server_status_info_pdu() failed");
|
| 1291 |
+
goto out_fail;
|
| 1292 |
+
}
|
| 1293 |
+
|
| 1294 |
+
break;
|
| 1295 |
+
|
| 1296 |
+
case DATA_PDU_TYPE_MONITOR_LAYOUT:
|
| 1297 |
+
if (!rdp_recv_monitor_layout_pdu(rdp, cs))
|
| 1298 |
+
{
|
| 1299 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1300 |
+
"DATA_PDU_TYPE_MONITOR_LAYOUT - rdp_recv_monitor_layout_pdu() failed");
|
| 1301 |
+
goto out_fail;
|
| 1302 |
+
}
|
| 1303 |
+
|
| 1304 |
+
break;
|
| 1305 |
+
|
| 1306 |
+
default:
|
| 1307 |
+
WLog_Print(rdp->log, WLOG_WARN,
|
| 1308 |
+
"[UNHANDLED] %s Data PDU (0x%02" PRIX8 "), length: %" PRIu16 "",
|
| 1309 |
+
data_pdu_type_to_string(type), type, length);
|
| 1310 |
+
break;
|
| 1311 |
+
}
|
| 1312 |
+
|
| 1313 |
+
if (cs != s)
|
| 1314 |
+
Stream_Release(cs);
|
| 1315 |
+
|
| 1316 |
+
return STATE_RUN_SUCCESS;
|
| 1317 |
+
out_fail:
|
| 1318 |
+
|
| 1319 |
+
if (cs != s)
|
| 1320 |
+
Stream_Release(cs);
|
| 1321 |
+
|
| 1322 |
+
return STATE_RUN_FAILED;
|
| 1323 |
+
}
|
| 1324 |
+
|
| 1325 |
+
state_run_t rdp_recv_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 securityFlags)
|
| 1326 |
+
{
|
| 1327 |
+
WINPR_ASSERT(rdp);
|
| 1328 |
+
WINPR_ASSERT(s);
|
| 1329 |
+
|
| 1330 |
+
if (securityFlags & SEC_AUTODETECT_REQ)
|
| 1331 |
+
{
|
| 1332 |
+
/* Server Auto-Detect Request PDU */
|
| 1333 |
+
return autodetect_recv_request_packet(rdp->autodetect, RDP_TRANSPORT_TCP, s);
|
| 1334 |
+
}
|
| 1335 |
+
|
| 1336 |
+
if (securityFlags & SEC_AUTODETECT_RSP)
|
| 1337 |
+
{
|
| 1338 |
+
/* Client Auto-Detect Response PDU */
|
| 1339 |
+
return autodetect_recv_response_packet(rdp->autodetect, RDP_TRANSPORT_TCP, s);
|
| 1340 |
+
}
|
| 1341 |
+
|
| 1342 |
+
if (securityFlags & SEC_HEARTBEAT)
|
| 1343 |
+
{
|
| 1344 |
+
/* Heartbeat PDU */
|
| 1345 |
+
return rdp_recv_heartbeat_packet(rdp, s);
|
| 1346 |
+
}
|
| 1347 |
+
|
| 1348 |
+
if (securityFlags & SEC_TRANSPORT_REQ)
|
| 1349 |
+
{
|
| 1350 |
+
return multitransport_recv_request(rdp->multitransport, s);
|
| 1351 |
+
}
|
| 1352 |
+
|
| 1353 |
+
if (securityFlags & SEC_TRANSPORT_RSP)
|
| 1354 |
+
{
|
| 1355 |
+
return multitransport_recv_response(rdp->multitransport, s);
|
| 1356 |
+
}
|
| 1357 |
+
|
| 1358 |
+
if (securityFlags & SEC_LICENSE_PKT)
|
| 1359 |
+
{
|
| 1360 |
+
return license_recv(rdp->license, s);
|
| 1361 |
+
}
|
| 1362 |
+
|
| 1363 |
+
if (securityFlags & SEC_LICENSE_ENCRYPT_CS)
|
| 1364 |
+
{
|
| 1365 |
+
return license_recv(rdp->license, s);
|
| 1366 |
+
}
|
| 1367 |
+
|
| 1368 |
+
if (securityFlags & SEC_LICENSE_ENCRYPT_SC)
|
| 1369 |
+
{
|
| 1370 |
+
return license_recv(rdp->license, s);
|
| 1371 |
+
}
|
| 1372 |
+
|
| 1373 |
+
return STATE_RUN_SUCCESS;
|
| 1374 |
+
}
|
| 1375 |
+
|
| 1376 |
+
state_run_t rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s, UINT16 pduType, UINT16 length)
|
| 1377 |
+
{
|
| 1378 |
+
state_run_t rc = STATE_RUN_FAILED;
|
| 1379 |
+
WINPR_ASSERT(rdp);
|
| 1380 |
+
|
| 1381 |
+
switch (pduType)
|
| 1382 |
+
{
|
| 1383 |
+
case PDU_TYPE_DATA:
|
| 1384 |
+
rc = rdp_recv_data_pdu(rdp, s);
|
| 1385 |
+
break;
|
| 1386 |
+
case PDU_TYPE_SERVER_REDIRECTION:
|
| 1387 |
+
rc = rdp_recv_enhanced_security_redirection_packet(rdp, s);
|
| 1388 |
+
break;
|
| 1389 |
+
case PDU_TYPE_FLOW_RESPONSE:
|
| 1390 |
+
case PDU_TYPE_FLOW_STOP:
|
| 1391 |
+
case PDU_TYPE_FLOW_TEST:
|
| 1392 |
+
rc = STATE_RUN_SUCCESS;
|
| 1393 |
+
break;
|
| 1394 |
+
default:
|
| 1395 |
+
{
|
| 1396 |
+
char buffer1[256] = { 0 };
|
| 1397 |
+
char buffer2[256] = { 0 };
|
| 1398 |
+
|
| 1399 |
+
WLog_Print(rdp->log, WLOG_ERROR, "expected %s, got %s",
|
| 1400 |
+
pdu_type_to_str(PDU_TYPE_DEMAND_ACTIVE, buffer1, sizeof(buffer1)),
|
| 1401 |
+
pdu_type_to_str(pduType, buffer2, sizeof(buffer2)));
|
| 1402 |
+
rc = STATE_RUN_FAILED;
|
| 1403 |
+
}
|
| 1404 |
+
break;
|
| 1405 |
+
}
|
| 1406 |
+
|
| 1407 |
+
if (!tpkt_ensure_stream_consumed(s, length))
|
| 1408 |
+
return STATE_RUN_FAILED;
|
| 1409 |
+
return rc;
|
| 1410 |
+
}
|
| 1411 |
+
|
| 1412 |
+
BOOL rdp_read_flow_control_pdu(rdpRdp* rdp, wStream* s, UINT16* type, UINT16* channel_id)
|
| 1413 |
+
{
|
| 1414 |
+
/*
|
| 1415 |
+
* Read flow control PDU - documented in FlowPDU section in T.128
|
| 1416 |
+
* http://www.itu.int/rec/T-REC-T.128-199802-S/en
|
| 1417 |
+
* The specification for the PDU has pad8bits listed BEFORE pduTypeFlow.
|
| 1418 |
+
* However, so far pad8bits has always been observed to arrive AFTER pduTypeFlow.
|
| 1419 |
+
* Switched the order of these two fields to match this observation.
|
| 1420 |
+
*/
|
| 1421 |
+
UINT8 pduType = 0;
|
| 1422 |
+
|
| 1423 |
+
WINPR_ASSERT(rdp);
|
| 1424 |
+
WINPR_ASSERT(s);
|
| 1425 |
+
WINPR_ASSERT(type);
|
| 1426 |
+
WINPR_ASSERT(channel_id);
|
| 1427 |
+
|
| 1428 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 6))
|
| 1429 |
+
return FALSE;
|
| 1430 |
+
Stream_Read_UINT8(s, pduType); /* pduTypeFlow */
|
| 1431 |
+
*type = pduType;
|
| 1432 |
+
Stream_Seek_UINT8(s); /* pad8bits */
|
| 1433 |
+
Stream_Seek_UINT8(s); /* flowIdentifier */
|
| 1434 |
+
Stream_Seek_UINT8(s); /* flowNumber */
|
| 1435 |
+
Stream_Read_UINT16(s, *channel_id); /* pduSource */
|
| 1436 |
+
return TRUE;
|
| 1437 |
+
}
|
| 1438 |
+
|
| 1439 |
+
/**
|
| 1440 |
+
* Decrypt an RDP packet.
|
| 1441 |
+
*
|
| 1442 |
+
* @param rdp RDP module
|
| 1443 |
+
* @param s stream
|
| 1444 |
+
* @param pLength A pointer to the result variable, must not be NULL
|
| 1445 |
+
* @param securityFlags the security flags to apply
|
| 1446 |
+
*
|
| 1447 |
+
* @return \b TRUE for success, \b FALSE otherwise
|
| 1448 |
+
*/
|
| 1449 |
+
|
| 1450 |
+
BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, UINT16* pLength, UINT16 securityFlags)
|
| 1451 |
+
{
|
| 1452 |
+
BOOL res = FALSE;
|
| 1453 |
+
BYTE cmac[8] = { 0 };
|
| 1454 |
+
BYTE wmac[8] = { 0 };
|
| 1455 |
+
BOOL status = FALSE;
|
| 1456 |
+
|
| 1457 |
+
WINPR_ASSERT(rdp);
|
| 1458 |
+
WINPR_ASSERT(rdp->settings);
|
| 1459 |
+
WINPR_ASSERT(s);
|
| 1460 |
+
WINPR_ASSERT(pLength);
|
| 1461 |
+
|
| 1462 |
+
if (!security_lock(rdp))
|
| 1463 |
+
return FALSE;
|
| 1464 |
+
|
| 1465 |
+
INT32 length = *pLength;
|
| 1466 |
+
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_NONE)
|
| 1467 |
+
return TRUE;
|
| 1468 |
+
|
| 1469 |
+
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
| 1470 |
+
{
|
| 1471 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 12))
|
| 1472 |
+
goto unlock;
|
| 1473 |
+
|
| 1474 |
+
UINT16 len = 0;
|
| 1475 |
+
Stream_Read_UINT16(s, len); /* 0x10 */
|
| 1476 |
+
if (len != 0x10)
|
| 1477 |
+
WLog_Print(rdp->log, WLOG_WARN, "ENCRYPTION_METHOD_FIPS length %" PRIu16 " != 0x10",
|
| 1478 |
+
len);
|
| 1479 |
+
|
| 1480 |
+
UINT16 version = 0;
|
| 1481 |
+
Stream_Read_UINT8(s, version); /* 0x1 */
|
| 1482 |
+
if (version != 1)
|
| 1483 |
+
WLog_Print(rdp->log, WLOG_WARN, "ENCRYPTION_METHOD_FIPS version %" PRIu16 " != 1",
|
| 1484 |
+
version);
|
| 1485 |
+
|
| 1486 |
+
BYTE pad = 0;
|
| 1487 |
+
Stream_Read_UINT8(s, pad);
|
| 1488 |
+
const BYTE* sig = Stream_ConstPointer(s);
|
| 1489 |
+
Stream_Seek(s, 8); /* signature */
|
| 1490 |
+
length -= 12;
|
| 1491 |
+
const INT32 padLength = length - pad;
|
| 1492 |
+
|
| 1493 |
+
if ((length <= 0) || (padLength <= 0) || (padLength > UINT16_MAX))
|
| 1494 |
+
{
|
| 1495 |
+
WLog_Print(rdp->log, WLOG_ERROR, "FATAL: invalid pad length %" PRId32, padLength);
|
| 1496 |
+
goto unlock;
|
| 1497 |
+
}
|
| 1498 |
+
|
| 1499 |
+
if (!security_fips_decrypt(Stream_Pointer(s), (size_t)length, rdp))
|
| 1500 |
+
goto unlock;
|
| 1501 |
+
|
| 1502 |
+
if (!security_fips_check_signature(Stream_ConstPointer(s), (size_t)padLength, sig, 8, rdp))
|
| 1503 |
+
goto unlock;
|
| 1504 |
+
|
| 1505 |
+
Stream_SetLength(s, Stream_Length(s) - pad);
|
| 1506 |
+
*pLength = (UINT16)padLength;
|
| 1507 |
+
}
|
| 1508 |
+
else
|
| 1509 |
+
{
|
| 1510 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, sizeof(wmac)))
|
| 1511 |
+
goto unlock;
|
| 1512 |
+
|
| 1513 |
+
Stream_Read(s, wmac, sizeof(wmac));
|
| 1514 |
+
length -= sizeof(wmac);
|
| 1515 |
+
|
| 1516 |
+
if (length <= 0)
|
| 1517 |
+
{
|
| 1518 |
+
WLog_Print(rdp->log, WLOG_ERROR, "FATAL: invalid length field");
|
| 1519 |
+
goto unlock;
|
| 1520 |
+
}
|
| 1521 |
+
|
| 1522 |
+
if (!security_decrypt(Stream_PointerAs(s, BYTE), (size_t)length, rdp))
|
| 1523 |
+
goto unlock;
|
| 1524 |
+
|
| 1525 |
+
if (securityFlags & SEC_SECURE_CHECKSUM)
|
| 1526 |
+
status = security_salted_mac_signature(rdp, Stream_ConstPointer(s), (UINT32)length,
|
| 1527 |
+
FALSE, cmac, sizeof(cmac));
|
| 1528 |
+
else
|
| 1529 |
+
status = security_mac_signature(rdp, Stream_ConstPointer(s), (UINT32)length, cmac,
|
| 1530 |
+
sizeof(cmac));
|
| 1531 |
+
|
| 1532 |
+
if (!status)
|
| 1533 |
+
goto unlock;
|
| 1534 |
+
|
| 1535 |
+
if (memcmp(wmac, cmac, sizeof(wmac)) != 0)
|
| 1536 |
+
{
|
| 1537 |
+
WLog_Print(rdp->log, WLOG_ERROR, "WARNING: invalid packet signature");
|
| 1538 |
+
/*
|
| 1539 |
+
* Because Standard RDP Security is totally broken,
|
| 1540 |
+
* and cannot protect against MITM, don't treat signature
|
| 1541 |
+
* verification failure as critical. This at least enables
|
| 1542 |
+
* us to work with broken RDP clients and servers that
|
| 1543 |
+
* generate invalid signatures.
|
| 1544 |
+
*/
|
| 1545 |
+
// return FALSE;
|
| 1546 |
+
}
|
| 1547 |
+
|
| 1548 |
+
*pLength = (UINT16)length;
|
| 1549 |
+
}
|
| 1550 |
+
res = TRUE;
|
| 1551 |
+
unlock:
|
| 1552 |
+
if (!security_unlock(rdp))
|
| 1553 |
+
return FALSE;
|
| 1554 |
+
return res;
|
| 1555 |
+
}
|
| 1556 |
+
|
| 1557 |
+
const char* pdu_type_to_str(UINT16 pduType, char* buffer, size_t length)
|
| 1558 |
+
{
|
| 1559 |
+
const char* str = NULL;
|
| 1560 |
+
switch (pduType)
|
| 1561 |
+
{
|
| 1562 |
+
case PDU_TYPE_DEMAND_ACTIVE:
|
| 1563 |
+
str = "PDU_TYPE_DEMAND_ACTIVE";
|
| 1564 |
+
break;
|
| 1565 |
+
case PDU_TYPE_CONFIRM_ACTIVE:
|
| 1566 |
+
str = "PDU_TYPE_CONFIRM_ACTIVE";
|
| 1567 |
+
break;
|
| 1568 |
+
case PDU_TYPE_DEACTIVATE_ALL:
|
| 1569 |
+
str = "PDU_TYPE_DEACTIVATE_ALL";
|
| 1570 |
+
break;
|
| 1571 |
+
case PDU_TYPE_DATA:
|
| 1572 |
+
str = "PDU_TYPE_DATA";
|
| 1573 |
+
break;
|
| 1574 |
+
case PDU_TYPE_SERVER_REDIRECTION:
|
| 1575 |
+
str = "PDU_TYPE_SERVER_REDIRECTION";
|
| 1576 |
+
break;
|
| 1577 |
+
case PDU_TYPE_FLOW_TEST:
|
| 1578 |
+
str = "PDU_TYPE_FLOW_TEST";
|
| 1579 |
+
break;
|
| 1580 |
+
case PDU_TYPE_FLOW_RESPONSE:
|
| 1581 |
+
str = "PDU_TYPE_FLOW_RESPONSE";
|
| 1582 |
+
break;
|
| 1583 |
+
case PDU_TYPE_FLOW_STOP:
|
| 1584 |
+
str = "PDU_TYPE_FLOW_STOP";
|
| 1585 |
+
break;
|
| 1586 |
+
default:
|
| 1587 |
+
str = "PDU_TYPE_UNKNOWN";
|
| 1588 |
+
break;
|
| 1589 |
+
}
|
| 1590 |
+
|
| 1591 |
+
winpr_str_append(str, buffer, length, "");
|
| 1592 |
+
{
|
| 1593 |
+
char msg[32] = { 0 };
|
| 1594 |
+
(void)_snprintf(msg, sizeof(msg), "[0x%08" PRIx32 "]", pduType);
|
| 1595 |
+
winpr_str_append(msg, buffer, length, "");
|
| 1596 |
+
}
|
| 1597 |
+
return buffer;
|
| 1598 |
+
}
|
| 1599 |
+
|
| 1600 |
+
/**
|
| 1601 |
+
* Process an RDP packet.
|
| 1602 |
+
* @param rdp RDP module
|
| 1603 |
+
* @param s stream
|
| 1604 |
+
*/
|
| 1605 |
+
|
| 1606 |
+
static state_run_t rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
|
| 1607 |
+
{
|
| 1608 |
+
state_run_t rc = STATE_RUN_SUCCESS;
|
| 1609 |
+
UINT16 length = 0;
|
| 1610 |
+
UINT16 pduType = 0;
|
| 1611 |
+
UINT16 pduSource = 0;
|
| 1612 |
+
UINT16 channelId = 0;
|
| 1613 |
+
UINT16 securityFlags = 0;
|
| 1614 |
+
freerdp* instance = NULL;
|
| 1615 |
+
|
| 1616 |
+
WINPR_ASSERT(rdp);
|
| 1617 |
+
WINPR_ASSERT(rdp->context);
|
| 1618 |
+
WINPR_ASSERT(s);
|
| 1619 |
+
|
| 1620 |
+
instance = rdp->context->instance;
|
| 1621 |
+
WINPR_ASSERT(instance);
|
| 1622 |
+
|
| 1623 |
+
if (!rdp_read_header(rdp, s, &length, &channelId))
|
| 1624 |
+
return STATE_RUN_FAILED;
|
| 1625 |
+
|
| 1626 |
+
if (freerdp_shall_disconnect_context(rdp->context))
|
| 1627 |
+
return STATE_RUN_SUCCESS;
|
| 1628 |
+
|
| 1629 |
+
if (rdp->autodetect->bandwidthMeasureStarted)
|
| 1630 |
+
{
|
| 1631 |
+
rdp->autodetect->bandwidthMeasureByteCount += length;
|
| 1632 |
+
}
|
| 1633 |
+
|
| 1634 |
+
if (rdp->mcs->messageChannelId && (channelId == rdp->mcs->messageChannelId))
|
| 1635 |
+
{
|
| 1636 |
+
rdp->inPackets++;
|
| 1637 |
+
if (!rdp_handle_message_channel(rdp, s, channelId, length))
|
| 1638 |
+
return STATE_RUN_FAILED;
|
| 1639 |
+
return STATE_RUN_SUCCESS;
|
| 1640 |
+
}
|
| 1641 |
+
|
| 1642 |
+
if (rdp->settings->UseRdpSecurityLayer)
|
| 1643 |
+
{
|
| 1644 |
+
if (!rdp_read_security_header(rdp, s, &securityFlags, &length))
|
| 1645 |
+
return STATE_RUN_FAILED;
|
| 1646 |
+
|
| 1647 |
+
if (securityFlags & (SEC_ENCRYPT | SEC_REDIRECTION_PKT))
|
| 1648 |
+
{
|
| 1649 |
+
if (!rdp_decrypt(rdp, s, &length, securityFlags))
|
| 1650 |
+
return STATE_RUN_FAILED;
|
| 1651 |
+
}
|
| 1652 |
+
|
| 1653 |
+
if (securityFlags & SEC_REDIRECTION_PKT)
|
| 1654 |
+
{
|
| 1655 |
+
/*
|
| 1656 |
+
* [MS-RDPBCGR] 2.2.13.2.1
|
| 1657 |
+
* - no share control header, nor the 2 byte pad
|
| 1658 |
+
*/
|
| 1659 |
+
Stream_Rewind(s, 2);
|
| 1660 |
+
rdp->inPackets++;
|
| 1661 |
+
|
| 1662 |
+
rc = rdp_recv_enhanced_security_redirection_packet(rdp, s);
|
| 1663 |
+
goto out;
|
| 1664 |
+
}
|
| 1665 |
+
}
|
| 1666 |
+
|
| 1667 |
+
if (channelId == MCS_GLOBAL_CHANNEL_ID)
|
| 1668 |
+
{
|
| 1669 |
+
while (Stream_GetRemainingLength(s) > 3)
|
| 1670 |
+
{
|
| 1671 |
+
wStream subbuffer;
|
| 1672 |
+
wStream* sub = NULL;
|
| 1673 |
+
size_t diff = 0;
|
| 1674 |
+
UINT16 remain = 0;
|
| 1675 |
+
|
| 1676 |
+
if (!rdp_read_share_control_header(rdp, s, NULL, &remain, &pduType, &pduSource))
|
| 1677 |
+
return STATE_RUN_FAILED;
|
| 1678 |
+
|
| 1679 |
+
sub = Stream_StaticInit(&subbuffer, Stream_Pointer(s), remain);
|
| 1680 |
+
if (!Stream_SafeSeek(s, remain))
|
| 1681 |
+
return STATE_RUN_FAILED;
|
| 1682 |
+
|
| 1683 |
+
rdp->settings->PduSource = pduSource;
|
| 1684 |
+
rdp->inPackets++;
|
| 1685 |
+
|
| 1686 |
+
switch (pduType)
|
| 1687 |
+
{
|
| 1688 |
+
case PDU_TYPE_DATA:
|
| 1689 |
+
rc = rdp_recv_data_pdu(rdp, sub);
|
| 1690 |
+
if (state_run_failed(rc))
|
| 1691 |
+
return rc;
|
| 1692 |
+
break;
|
| 1693 |
+
|
| 1694 |
+
case PDU_TYPE_DEACTIVATE_ALL:
|
| 1695 |
+
if (!rdp_recv_deactivate_all(rdp, sub))
|
| 1696 |
+
{
|
| 1697 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 1698 |
+
"rdp_recv_tpkt_pdu: rdp_recv_deactivate_all() fail");
|
| 1699 |
+
return STATE_RUN_FAILED;
|
| 1700 |
+
}
|
| 1701 |
+
|
| 1702 |
+
break;
|
| 1703 |
+
|
| 1704 |
+
case PDU_TYPE_SERVER_REDIRECTION:
|
| 1705 |
+
return rdp_recv_enhanced_security_redirection_packet(rdp, sub);
|
| 1706 |
+
|
| 1707 |
+
case PDU_TYPE_FLOW_RESPONSE:
|
| 1708 |
+
case PDU_TYPE_FLOW_STOP:
|
| 1709 |
+
case PDU_TYPE_FLOW_TEST:
|
| 1710 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "flow message 0x%04" PRIX16 "", pduType);
|
| 1711 |
+
/* http://msdn.microsoft.com/en-us/library/cc240576.aspx */
|
| 1712 |
+
if (!Stream_SafeSeek(sub, remain))
|
| 1713 |
+
return STATE_RUN_FAILED;
|
| 1714 |
+
break;
|
| 1715 |
+
|
| 1716 |
+
default:
|
| 1717 |
+
{
|
| 1718 |
+
char buffer[256] = { 0 };
|
| 1719 |
+
WLog_Print(rdp->log, WLOG_ERROR, "incorrect PDU type: %s",
|
| 1720 |
+
pdu_type_to_str(pduType, buffer, sizeof(buffer)));
|
| 1721 |
+
}
|
| 1722 |
+
break;
|
| 1723 |
+
}
|
| 1724 |
+
|
| 1725 |
+
diff = Stream_GetRemainingLength(sub);
|
| 1726 |
+
if (diff > 0)
|
| 1727 |
+
{
|
| 1728 |
+
char buffer[256] = { 0 };
|
| 1729 |
+
WLog_Print(rdp->log, WLOG_WARN,
|
| 1730 |
+
"pduType %s not properly parsed, %" PRIdz
|
| 1731 |
+
" bytes remaining unhandled. Skipping.",
|
| 1732 |
+
pdu_type_to_str(pduType, buffer, sizeof(buffer)), diff);
|
| 1733 |
+
}
|
| 1734 |
+
}
|
| 1735 |
+
}
|
| 1736 |
+
else
|
| 1737 |
+
{
|
| 1738 |
+
rdp->inPackets++;
|
| 1739 |
+
|
| 1740 |
+
if (!freerdp_channel_process(instance, s, channelId, length))
|
| 1741 |
+
return STATE_RUN_FAILED;
|
| 1742 |
+
}
|
| 1743 |
+
|
| 1744 |
+
out:
|
| 1745 |
+
if (!tpkt_ensure_stream_consumed(s, length))
|
| 1746 |
+
return STATE_RUN_FAILED;
|
| 1747 |
+
return rc;
|
| 1748 |
+
}
|
| 1749 |
+
|
| 1750 |
+
static state_run_t rdp_recv_fastpath_pdu(rdpRdp* rdp, wStream* s)
|
| 1751 |
+
{
|
| 1752 |
+
UINT16 length = 0;
|
| 1753 |
+
|
| 1754 |
+
WINPR_ASSERT(rdp);
|
| 1755 |
+
rdpFastPath* fastpath = rdp->fastpath;
|
| 1756 |
+
|
| 1757 |
+
if (!fastpath_read_header_rdp(fastpath, s, &length))
|
| 1758 |
+
{
|
| 1759 |
+
WLog_Print(rdp->log, WLOG_ERROR, "rdp_recv_fastpath_pdu: fastpath_read_header_rdp() fail");
|
| 1760 |
+
return STATE_RUN_FAILED;
|
| 1761 |
+
}
|
| 1762 |
+
|
| 1763 |
+
if ((length == 0) || (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, length)))
|
| 1764 |
+
{
|
| 1765 |
+
WLog_Print(rdp->log, WLOG_ERROR, "incorrect FastPath PDU header length %" PRIu16 "",
|
| 1766 |
+
length);
|
| 1767 |
+
return STATE_RUN_FAILED;
|
| 1768 |
+
}
|
| 1769 |
+
|
| 1770 |
+
if (rdp->autodetect->bandwidthMeasureStarted)
|
| 1771 |
+
{
|
| 1772 |
+
rdp->autodetect->bandwidthMeasureByteCount += length;
|
| 1773 |
+
}
|
| 1774 |
+
|
| 1775 |
+
if (!fastpath_decrypt(fastpath, s, &length))
|
| 1776 |
+
return STATE_RUN_FAILED;
|
| 1777 |
+
|
| 1778 |
+
return fastpath_recv_updates(rdp->fastpath, s);
|
| 1779 |
+
}
|
| 1780 |
+
|
| 1781 |
+
static state_run_t rdp_recv_pdu(rdpRdp* rdp, wStream* s)
|
| 1782 |
+
{
|
| 1783 |
+
const int rc = tpkt_verify_header(s);
|
| 1784 |
+
if (rc > 0)
|
| 1785 |
+
return rdp_recv_tpkt_pdu(rdp, s);
|
| 1786 |
+
else if (rc == 0)
|
| 1787 |
+
return rdp_recv_fastpath_pdu(rdp, s);
|
| 1788 |
+
else
|
| 1789 |
+
return STATE_RUN_FAILED;
|
| 1790 |
+
}
|
| 1791 |
+
|
| 1792 |
+
static state_run_t rdp_handle_sc_flags(rdpRdp* rdp, wStream* s, UINT32 flag,
|
| 1793 |
+
CONNECTION_STATE nextState)
|
| 1794 |
+
{
|
| 1795 |
+
const UINT32 mask = FINALIZE_SC_SYNCHRONIZE_PDU | FINALIZE_SC_CONTROL_COOPERATE_PDU |
|
| 1796 |
+
FINALIZE_SC_CONTROL_GRANTED_PDU | FINALIZE_SC_FONT_MAP_PDU;
|
| 1797 |
+
WINPR_ASSERT(rdp);
|
| 1798 |
+
state_run_t status = rdp_recv_pdu(rdp, s);
|
| 1799 |
+
if (state_run_success(status))
|
| 1800 |
+
{
|
| 1801 |
+
const UINT32 flags = rdp->finalize_sc_pdus & mask;
|
| 1802 |
+
if ((flags & flag) == flag)
|
| 1803 |
+
{
|
| 1804 |
+
if (!rdp_client_transition_to_state(rdp, nextState))
|
| 1805 |
+
status = STATE_RUN_FAILED;
|
| 1806 |
+
else
|
| 1807 |
+
status = STATE_RUN_SUCCESS;
|
| 1808 |
+
}
|
| 1809 |
+
else
|
| 1810 |
+
{
|
| 1811 |
+
char flag_buffer[256] = { 0 };
|
| 1812 |
+
char mask_buffer[256] = { 0 };
|
| 1813 |
+
WLog_Print(rdp->log, WLOG_WARN,
|
| 1814 |
+
"[%s] unexpected server message, expected flag %s [have %s]",
|
| 1815 |
+
rdp_get_state_string(rdp),
|
| 1816 |
+
rdp_finalize_flags_to_str(flag, flag_buffer, sizeof(flag_buffer)),
|
| 1817 |
+
rdp_finalize_flags_to_str(flags, mask_buffer, sizeof(mask_buffer)));
|
| 1818 |
+
}
|
| 1819 |
+
}
|
| 1820 |
+
return status;
|
| 1821 |
+
}
|
| 1822 |
+
|
| 1823 |
+
static state_run_t rdp_client_exchange_monitor_layout(rdpRdp* rdp, wStream* s)
|
| 1824 |
+
{
|
| 1825 |
+
WINPR_ASSERT(rdp);
|
| 1826 |
+
|
| 1827 |
+
if (!rdp_check_monitor_layout_pdu_state(rdp, FALSE))
|
| 1828 |
+
return FALSE;
|
| 1829 |
+
|
| 1830 |
+
/* We might receive unrelated messages from the server (channel traffic),
|
| 1831 |
+
* so only proceed if some flag changed
|
| 1832 |
+
*/
|
| 1833 |
+
const UINT32 old = rdp->finalize_sc_pdus;
|
| 1834 |
+
state_run_t status = rdp_recv_pdu(rdp, s);
|
| 1835 |
+
const UINT32 now = rdp->finalize_sc_pdus;
|
| 1836 |
+
const BOOL changed = (old != now) || rdp->monitor_layout_pdu;
|
| 1837 |
+
|
| 1838 |
+
/* This PDU is optional, so if we received a finalize PDU continue there */
|
| 1839 |
+
if (state_run_success(status) && changed)
|
| 1840 |
+
{
|
| 1841 |
+
if (!rdp->monitor_layout_pdu)
|
| 1842 |
+
{
|
| 1843 |
+
if (!rdp_finalize_is_flag_set(rdp, FINALIZE_SC_SYNCHRONIZE_PDU))
|
| 1844 |
+
return STATE_RUN_FAILED;
|
| 1845 |
+
}
|
| 1846 |
+
|
| 1847 |
+
status = rdp_client_connect_finalize(rdp);
|
| 1848 |
+
if (state_run_success(status) && !rdp->monitor_layout_pdu)
|
| 1849 |
+
status = STATE_RUN_TRY_AGAIN;
|
| 1850 |
+
}
|
| 1851 |
+
return status;
|
| 1852 |
+
}
|
| 1853 |
+
|
| 1854 |
+
static state_run_t rdp_recv_callback_int(rdpTransport* transport, wStream* s, void* extra)
|
| 1855 |
+
{
|
| 1856 |
+
state_run_t status = STATE_RUN_SUCCESS;
|
| 1857 |
+
rdpRdp* rdp = (rdpRdp*)extra;
|
| 1858 |
+
|
| 1859 |
+
WINPR_ASSERT(transport);
|
| 1860 |
+
WINPR_ASSERT(rdp);
|
| 1861 |
+
WINPR_ASSERT(s);
|
| 1862 |
+
|
| 1863 |
+
switch (rdp_get_state(rdp))
|
| 1864 |
+
{
|
| 1865 |
+
case CONNECTION_STATE_NEGO:
|
| 1866 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_MCS_CREATE_REQUEST))
|
| 1867 |
+
status = STATE_RUN_FAILED;
|
| 1868 |
+
else
|
| 1869 |
+
status = STATE_RUN_CONTINUE;
|
| 1870 |
+
break;
|
| 1871 |
+
case CONNECTION_STATE_NLA:
|
| 1872 |
+
if (nla_get_state(rdp->nla) < NLA_STATE_AUTH_INFO)
|
| 1873 |
+
{
|
| 1874 |
+
if (nla_recv_pdu(rdp->nla, s) < 1)
|
| 1875 |
+
{
|
| 1876 |
+
WLog_Print(rdp->log, WLOG_ERROR, "%s - nla_recv_pdu() fail",
|
| 1877 |
+
rdp_get_state_string(rdp));
|
| 1878 |
+
status = STATE_RUN_FAILED;
|
| 1879 |
+
}
|
| 1880 |
+
}
|
| 1881 |
+
else if (nla_get_state(rdp->nla) == NLA_STATE_POST_NEGO)
|
| 1882 |
+
{
|
| 1883 |
+
nego_recv(rdp->transport, s, (void*)rdp->nego);
|
| 1884 |
+
|
| 1885 |
+
if (!nego_update_settings_from_state(rdp->nego, rdp->settings))
|
| 1886 |
+
return FALSE;
|
| 1887 |
+
|
| 1888 |
+
if (nego_get_state(rdp->nego) != NEGO_STATE_FINAL)
|
| 1889 |
+
{
|
| 1890 |
+
WLog_Print(rdp->log, WLOG_ERROR, "%s - nego_recv() fail",
|
| 1891 |
+
rdp_get_state_string(rdp));
|
| 1892 |
+
status = STATE_RUN_FAILED;
|
| 1893 |
+
}
|
| 1894 |
+
else if (!nla_set_state(rdp->nla, NLA_STATE_FINAL))
|
| 1895 |
+
status = STATE_RUN_FAILED;
|
| 1896 |
+
}
|
| 1897 |
+
|
| 1898 |
+
if (state_run_success(status))
|
| 1899 |
+
{
|
| 1900 |
+
if (nla_get_state(rdp->nla) == NLA_STATE_AUTH_INFO)
|
| 1901 |
+
{
|
| 1902 |
+
transport_set_nla_mode(rdp->transport, FALSE);
|
| 1903 |
+
|
| 1904 |
+
if (rdp->settings->VmConnectMode)
|
| 1905 |
+
{
|
| 1906 |
+
if (!nego_set_state(rdp->nego, NEGO_STATE_NLA))
|
| 1907 |
+
status = STATE_RUN_FAILED;
|
| 1908 |
+
else if (!nego_set_requested_protocols(rdp->nego,
|
| 1909 |
+
PROTOCOL_HYBRID | PROTOCOL_SSL))
|
| 1910 |
+
status = STATE_RUN_FAILED;
|
| 1911 |
+
else if (!nego_send_negotiation_request(rdp->nego))
|
| 1912 |
+
status = STATE_RUN_FAILED;
|
| 1913 |
+
else if (!nla_set_state(rdp->nla, NLA_STATE_POST_NEGO))
|
| 1914 |
+
status = STATE_RUN_FAILED;
|
| 1915 |
+
}
|
| 1916 |
+
else
|
| 1917 |
+
{
|
| 1918 |
+
if (!nla_set_state(rdp->nla, NLA_STATE_FINAL))
|
| 1919 |
+
status = STATE_RUN_FAILED;
|
| 1920 |
+
}
|
| 1921 |
+
}
|
| 1922 |
+
}
|
| 1923 |
+
if (state_run_success(status))
|
| 1924 |
+
{
|
| 1925 |
+
|
| 1926 |
+
if (nla_get_state(rdp->nla) == NLA_STATE_FINAL)
|
| 1927 |
+
{
|
| 1928 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_MCS_CREATE_REQUEST))
|
| 1929 |
+
status = STATE_RUN_FAILED;
|
| 1930 |
+
else
|
| 1931 |
+
status = STATE_RUN_CONTINUE;
|
| 1932 |
+
}
|
| 1933 |
+
}
|
| 1934 |
+
break;
|
| 1935 |
+
|
| 1936 |
+
case CONNECTION_STATE_AAD:
|
| 1937 |
+
if (aad_recv(rdp->aad, s) < 1)
|
| 1938 |
+
{
|
| 1939 |
+
WLog_Print(rdp->log, WLOG_ERROR, "%s - aad_recv() fail", rdp_get_state_string(rdp));
|
| 1940 |
+
status = STATE_RUN_FAILED;
|
| 1941 |
+
}
|
| 1942 |
+
if (state_run_success(status))
|
| 1943 |
+
{
|
| 1944 |
+
if (aad_get_state(rdp->aad) == AAD_STATE_FINAL)
|
| 1945 |
+
{
|
| 1946 |
+
transport_set_aad_mode(rdp->transport, FALSE);
|
| 1947 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_MCS_CREATE_REQUEST))
|
| 1948 |
+
status = STATE_RUN_FAILED;
|
| 1949 |
+
else
|
| 1950 |
+
status = STATE_RUN_CONTINUE;
|
| 1951 |
+
}
|
| 1952 |
+
}
|
| 1953 |
+
break;
|
| 1954 |
+
|
| 1955 |
+
case CONNECTION_STATE_MCS_CREATE_REQUEST:
|
| 1956 |
+
if (!mcs_client_begin(rdp->mcs))
|
| 1957 |
+
{
|
| 1958 |
+
WLog_Print(rdp->log, WLOG_ERROR, "%s - mcs_client_begin() fail",
|
| 1959 |
+
rdp_get_state_string(rdp));
|
| 1960 |
+
status = STATE_RUN_FAILED;
|
| 1961 |
+
}
|
| 1962 |
+
else if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_MCS_CREATE_RESPONSE))
|
| 1963 |
+
status = STATE_RUN_FAILED;
|
| 1964 |
+
else if (Stream_GetRemainingLength(s) > 0)
|
| 1965 |
+
status = STATE_RUN_CONTINUE;
|
| 1966 |
+
break;
|
| 1967 |
+
|
| 1968 |
+
case CONNECTION_STATE_MCS_CREATE_RESPONSE:
|
| 1969 |
+
if (!mcs_recv_connect_response(rdp->mcs, s))
|
| 1970 |
+
{
|
| 1971 |
+
WLog_Print(rdp->log, WLOG_ERROR, "mcs_recv_connect_response failure");
|
| 1972 |
+
status = STATE_RUN_FAILED;
|
| 1973 |
+
}
|
| 1974 |
+
else
|
| 1975 |
+
{
|
| 1976 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_MCS_ERECT_DOMAIN))
|
| 1977 |
+
status = STATE_RUN_FAILED;
|
| 1978 |
+
else if (!mcs_send_erect_domain_request(rdp->mcs))
|
| 1979 |
+
{
|
| 1980 |
+
WLog_Print(rdp->log, WLOG_ERROR, "mcs_send_erect_domain_request failure");
|
| 1981 |
+
status = STATE_RUN_FAILED;
|
| 1982 |
+
}
|
| 1983 |
+
else if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_MCS_ATTACH_USER))
|
| 1984 |
+
status = STATE_RUN_FAILED;
|
| 1985 |
+
else if (!mcs_send_attach_user_request(rdp->mcs))
|
| 1986 |
+
{
|
| 1987 |
+
WLog_Print(rdp->log, WLOG_ERROR, "mcs_send_attach_user_request failure");
|
| 1988 |
+
status = STATE_RUN_FAILED;
|
| 1989 |
+
}
|
| 1990 |
+
else if (!rdp_client_transition_to_state(rdp,
|
| 1991 |
+
CONNECTION_STATE_MCS_ATTACH_USER_CONFIRM))
|
| 1992 |
+
status = STATE_RUN_FAILED;
|
| 1993 |
+
}
|
| 1994 |
+
break;
|
| 1995 |
+
|
| 1996 |
+
case CONNECTION_STATE_MCS_ATTACH_USER_CONFIRM:
|
| 1997 |
+
if (!mcs_recv_attach_user_confirm(rdp->mcs, s))
|
| 1998 |
+
{
|
| 1999 |
+
WLog_Print(rdp->log, WLOG_ERROR, "mcs_recv_attach_user_confirm failure");
|
| 2000 |
+
status = STATE_RUN_FAILED;
|
| 2001 |
+
}
|
| 2002 |
+
else if (!freerdp_settings_get_bool(rdp->settings, FreeRDP_SupportSkipChannelJoin))
|
| 2003 |
+
{
|
| 2004 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_MCS_CHANNEL_JOIN_REQUEST))
|
| 2005 |
+
status = STATE_RUN_FAILED;
|
| 2006 |
+
else if (!mcs_send_channel_join_request(rdp->mcs, rdp->mcs->userId))
|
| 2007 |
+
{
|
| 2008 |
+
WLog_Print(rdp->log, WLOG_ERROR, "mcs_send_channel_join_request failure");
|
| 2009 |
+
status = STATE_RUN_FAILED;
|
| 2010 |
+
}
|
| 2011 |
+
else if (!rdp_client_transition_to_state(
|
| 2012 |
+
rdp, CONNECTION_STATE_MCS_CHANNEL_JOIN_RESPONSE))
|
| 2013 |
+
status = STATE_RUN_FAILED;
|
| 2014 |
+
}
|
| 2015 |
+
else
|
| 2016 |
+
{
|
| 2017 |
+
/* SKIP_CHANNELJOIN is active, consider channels to be joined */
|
| 2018 |
+
if (!rdp_client_skip_mcs_channel_join(rdp))
|
| 2019 |
+
status = STATE_RUN_FAILED;
|
| 2020 |
+
}
|
| 2021 |
+
break;
|
| 2022 |
+
|
| 2023 |
+
case CONNECTION_STATE_MCS_CHANNEL_JOIN_RESPONSE:
|
| 2024 |
+
if (!rdp_client_connect_mcs_channel_join_confirm(rdp, s))
|
| 2025 |
+
{
|
| 2026 |
+
WLog_Print(rdp->log, WLOG_ERROR,
|
| 2027 |
+
"%s - "
|
| 2028 |
+
"rdp_client_connect_mcs_channel_join_confirm() fail",
|
| 2029 |
+
rdp_get_state_string(rdp));
|
| 2030 |
+
status = STATE_RUN_FAILED;
|
| 2031 |
+
}
|
| 2032 |
+
|
| 2033 |
+
break;
|
| 2034 |
+
|
| 2035 |
+
case CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_REQUEST:
|
| 2036 |
+
if (!rdp_client_connect_auto_detect(rdp, s))
|
| 2037 |
+
{
|
| 2038 |
+
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_LICENSING))
|
| 2039 |
+
status = STATE_RUN_FAILED;
|
| 2040 |
+
else
|
| 2041 |
+
status = STATE_RUN_TRY_AGAIN;
|
| 2042 |
+
}
|
| 2043 |
+
break;
|
| 2044 |
+
|
| 2045 |
+
case CONNECTION_STATE_LICENSING:
|
| 2046 |
+
status = rdp_client_connect_license(rdp, s);
|
| 2047 |
+
|
| 2048 |
+
if (state_run_failed(status))
|
| 2049 |
+
{
|
| 2050 |
+
char buffer[64] = { 0 };
|
| 2051 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "%s - rdp_client_connect_license() - %s",
|
| 2052 |
+
rdp_get_state_string(rdp),
|
| 2053 |
+
state_run_result_string(status, buffer, ARRAYSIZE(buffer)));
|
| 2054 |
+
}
|
| 2055 |
+
|
| 2056 |
+
break;
|
| 2057 |
+
|
| 2058 |
+
case CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_REQUEST:
|
| 2059 |
+
if (!rdp_client_connect_auto_detect(rdp, s))
|
| 2060 |
+
{
|
| 2061 |
+
(void)rdp_client_transition_to_state(
|
| 2062 |
+
rdp, CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE);
|
| 2063 |
+
status = STATE_RUN_TRY_AGAIN;
|
| 2064 |
+
}
|
| 2065 |
+
break;
|
| 2066 |
+
|
| 2067 |
+
case CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE:
|
| 2068 |
+
status = rdp_client_connect_demand_active(rdp, s);
|
| 2069 |
+
|
| 2070 |
+
if (state_run_failed(status))
|
| 2071 |
+
{
|
| 2072 |
+
char buffer[64] = { 0 };
|
| 2073 |
+
WLog_Print(rdp->log, WLOG_DEBUG,
|
| 2074 |
+
"%s - "
|
| 2075 |
+
"rdp_client_connect_demand_active() - %s",
|
| 2076 |
+
rdp_get_state_string(rdp),
|
| 2077 |
+
state_run_result_string(status, buffer, ARRAYSIZE(buffer)));
|
| 2078 |
+
}
|
| 2079 |
+
else if (status == STATE_RUN_ACTIVE)
|
| 2080 |
+
{
|
| 2081 |
+
if (!rdp_client_transition_to_state(
|
| 2082 |
+
rdp, CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE))
|
| 2083 |
+
status = STATE_RUN_FAILED;
|
| 2084 |
+
else
|
| 2085 |
+
status = STATE_RUN_CONTINUE;
|
| 2086 |
+
}
|
| 2087 |
+
break;
|
| 2088 |
+
|
| 2089 |
+
case CONNECTION_STATE_CAPABILITIES_EXCHANGE_MONITOR_LAYOUT:
|
| 2090 |
+
status = rdp_client_exchange_monitor_layout(rdp, s);
|
| 2091 |
+
break;
|
| 2092 |
+
|
| 2093 |
+
case CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE:
|
| 2094 |
+
status = rdp_client_connect_confirm_active(rdp, s);
|
| 2095 |
+
break;
|
| 2096 |
+
|
| 2097 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_SYNC:
|
| 2098 |
+
status = rdp_handle_sc_flags(rdp, s, FINALIZE_SC_SYNCHRONIZE_PDU,
|
| 2099 |
+
CONNECTION_STATE_FINALIZATION_CLIENT_COOPERATE);
|
| 2100 |
+
break;
|
| 2101 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_COOPERATE:
|
| 2102 |
+
status = rdp_handle_sc_flags(rdp, s, FINALIZE_SC_CONTROL_COOPERATE_PDU,
|
| 2103 |
+
CONNECTION_STATE_FINALIZATION_CLIENT_GRANTED_CONTROL);
|
| 2104 |
+
break;
|
| 2105 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_GRANTED_CONTROL:
|
| 2106 |
+
status = rdp_handle_sc_flags(rdp, s, FINALIZE_SC_CONTROL_GRANTED_PDU,
|
| 2107 |
+
CONNECTION_STATE_FINALIZATION_CLIENT_FONT_MAP);
|
| 2108 |
+
break;
|
| 2109 |
+
case CONNECTION_STATE_FINALIZATION_CLIENT_FONT_MAP:
|
| 2110 |
+
status = rdp_handle_sc_flags(rdp, s, FINALIZE_SC_FONT_MAP_PDU, CONNECTION_STATE_ACTIVE);
|
| 2111 |
+
break;
|
| 2112 |
+
|
| 2113 |
+
case CONNECTION_STATE_ACTIVE:
|
| 2114 |
+
status = rdp_recv_pdu(rdp, s);
|
| 2115 |
+
|
| 2116 |
+
if (state_run_failed(status))
|
| 2117 |
+
{
|
| 2118 |
+
char buffer[64] = { 0 };
|
| 2119 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "%s - rdp_recv_pdu() - %s",
|
| 2120 |
+
rdp_get_state_string(rdp),
|
| 2121 |
+
state_run_result_string(status, buffer, ARRAYSIZE(buffer)));
|
| 2122 |
+
}
|
| 2123 |
+
break;
|
| 2124 |
+
|
| 2125 |
+
default:
|
| 2126 |
+
WLog_Print(rdp->log, WLOG_ERROR, "%s state %d", rdp_get_state_string(rdp),
|
| 2127 |
+
rdp_get_state(rdp));
|
| 2128 |
+
status = STATE_RUN_FAILED;
|
| 2129 |
+
break;
|
| 2130 |
+
}
|
| 2131 |
+
|
| 2132 |
+
if (state_run_failed(status))
|
| 2133 |
+
{
|
| 2134 |
+
char buffer[64] = { 0 };
|
| 2135 |
+
WLog_Print(rdp->log, WLOG_ERROR, "%s status %s", rdp_get_state_string(rdp),
|
| 2136 |
+
state_run_result_string(status, buffer, ARRAYSIZE(buffer)));
|
| 2137 |
+
}
|
| 2138 |
+
return status;
|
| 2139 |
+
}
|
| 2140 |
+
|
| 2141 |
+
state_run_t rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra)
|
| 2142 |
+
{
|
| 2143 |
+
char buffer[64] = { 0 };
|
| 2144 |
+
state_run_t rc = STATE_RUN_FAILED;
|
| 2145 |
+
const size_t start = Stream_GetPosition(s);
|
| 2146 |
+
const rdpContext* context = transport_get_context(transport);
|
| 2147 |
+
|
| 2148 |
+
WINPR_ASSERT(context);
|
| 2149 |
+
do
|
| 2150 |
+
{
|
| 2151 |
+
const rdpRdp* rdp = context->rdp;
|
| 2152 |
+
WINPR_ASSERT(rdp);
|
| 2153 |
+
|
| 2154 |
+
if (rc == STATE_RUN_TRY_AGAIN)
|
| 2155 |
+
Stream_SetPosition(s, start);
|
| 2156 |
+
|
| 2157 |
+
const char* old = rdp_get_state_string(rdp);
|
| 2158 |
+
const size_t orem = Stream_GetRemainingLength(s);
|
| 2159 |
+
rc = rdp_recv_callback_int(transport, s, extra);
|
| 2160 |
+
|
| 2161 |
+
const char* now = rdp_get_state_string(rdp);
|
| 2162 |
+
const size_t rem = Stream_GetRemainingLength(s);
|
| 2163 |
+
|
| 2164 |
+
WLog_Print(rdp->log, WLOG_TRACE,
|
| 2165 |
+
"(client)[%s -> %s] current return %s [feeding %" PRIuz " bytes, %" PRIuz
|
| 2166 |
+
" bytes not processed]",
|
| 2167 |
+
old, now, state_run_result_string(rc, buffer, sizeof(buffer)), orem, rem);
|
| 2168 |
+
} while ((rc == STATE_RUN_TRY_AGAIN) || (rc == STATE_RUN_CONTINUE));
|
| 2169 |
+
return rc;
|
| 2170 |
+
}
|
| 2171 |
+
|
| 2172 |
+
BOOL rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId, const BYTE* data, size_t size)
|
| 2173 |
+
{
|
| 2174 |
+
return freerdp_channel_send(rdp, channelId, data, size);
|
| 2175 |
+
}
|
| 2176 |
+
|
| 2177 |
+
BOOL rdp_channel_send_packet(rdpRdp* rdp, UINT16 channelId, size_t totalSize, UINT32 flags,
|
| 2178 |
+
const BYTE* data, size_t chunkSize)
|
| 2179 |
+
{
|
| 2180 |
+
return freerdp_channel_send_packet(rdp, channelId, totalSize, flags, data, chunkSize);
|
| 2181 |
+
}
|
| 2182 |
+
|
| 2183 |
+
BOOL rdp_send_error_info(rdpRdp* rdp)
|
| 2184 |
+
{
|
| 2185 |
+
wStream* s = NULL;
|
| 2186 |
+
BOOL status = 0;
|
| 2187 |
+
|
| 2188 |
+
if (rdp->errorInfo == ERRINFO_SUCCESS)
|
| 2189 |
+
return TRUE;
|
| 2190 |
+
|
| 2191 |
+
s = rdp_data_pdu_init(rdp);
|
| 2192 |
+
|
| 2193 |
+
if (!s)
|
| 2194 |
+
return FALSE;
|
| 2195 |
+
|
| 2196 |
+
Stream_Write_UINT32(s, rdp->errorInfo); /* error id (4 bytes) */
|
| 2197 |
+
status = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SET_ERROR_INFO, 0);
|
| 2198 |
+
return status;
|
| 2199 |
+
}
|
| 2200 |
+
|
| 2201 |
+
int rdp_check_fds(rdpRdp* rdp)
|
| 2202 |
+
{
|
| 2203 |
+
int status = 0;
|
| 2204 |
+
rdpTsg* tsg = NULL;
|
| 2205 |
+
rdpTransport* transport = NULL;
|
| 2206 |
+
|
| 2207 |
+
WINPR_ASSERT(rdp);
|
| 2208 |
+
transport = rdp->transport;
|
| 2209 |
+
|
| 2210 |
+
tsg = transport_get_tsg(transport);
|
| 2211 |
+
if (tsg)
|
| 2212 |
+
{
|
| 2213 |
+
if (!tsg_check_event_handles(tsg))
|
| 2214 |
+
{
|
| 2215 |
+
WLog_Print(rdp->log, WLOG_ERROR, "rdp_check_fds: tsg_check_event_handles()");
|
| 2216 |
+
return -1;
|
| 2217 |
+
}
|
| 2218 |
+
|
| 2219 |
+
if (tsg_get_state(tsg) != TSG_STATE_PIPE_CREATED)
|
| 2220 |
+
return 1;
|
| 2221 |
+
}
|
| 2222 |
+
|
| 2223 |
+
status = transport_check_fds(transport);
|
| 2224 |
+
|
| 2225 |
+
if (status == 1)
|
| 2226 |
+
{
|
| 2227 |
+
if (!rdp_client_redirect(rdp)) /* session redirection */
|
| 2228 |
+
return -1;
|
| 2229 |
+
}
|
| 2230 |
+
|
| 2231 |
+
if (status < 0)
|
| 2232 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "transport_check_fds() - %i", status);
|
| 2233 |
+
|
| 2234 |
+
return status;
|
| 2235 |
+
}
|
| 2236 |
+
|
| 2237 |
+
BOOL freerdp_get_stats(rdpRdp* rdp, UINT64* inBytes, UINT64* outBytes, UINT64* inPackets,
|
| 2238 |
+
UINT64* outPackets)
|
| 2239 |
+
{
|
| 2240 |
+
if (!rdp)
|
| 2241 |
+
return FALSE;
|
| 2242 |
+
|
| 2243 |
+
if (inBytes)
|
| 2244 |
+
*inBytes = rdp->inBytes;
|
| 2245 |
+
if (outBytes)
|
| 2246 |
+
*outBytes = rdp->outBytes;
|
| 2247 |
+
if (inPackets)
|
| 2248 |
+
*inPackets = rdp->inPackets;
|
| 2249 |
+
if (outPackets)
|
| 2250 |
+
*outPackets = rdp->outPackets;
|
| 2251 |
+
|
| 2252 |
+
return TRUE;
|
| 2253 |
+
}
|
| 2254 |
+
|
| 2255 |
+
/**
|
| 2256 |
+
* Instantiate new RDP module.
|
| 2257 |
+
* @return new RDP module
|
| 2258 |
+
*/
|
| 2259 |
+
|
| 2260 |
+
rdpRdp* rdp_new(rdpContext* context)
|
| 2261 |
+
{
|
| 2262 |
+
rdpRdp* rdp = NULL;
|
| 2263 |
+
DWORD flags = 0;
|
| 2264 |
+
rdp = (rdpRdp*)calloc(1, sizeof(rdpRdp));
|
| 2265 |
+
|
| 2266 |
+
if (!rdp)
|
| 2267 |
+
return NULL;
|
| 2268 |
+
|
| 2269 |
+
rdp->log = WLog_Get(RDP_TAG);
|
| 2270 |
+
WINPR_ASSERT(rdp->log);
|
| 2271 |
+
|
| 2272 |
+
(void)_snprintf(rdp->log_context, sizeof(rdp->log_context), "%p", (void*)context);
|
| 2273 |
+
WLog_SetContext(rdp->log, NULL, rdp->log_context);
|
| 2274 |
+
|
| 2275 |
+
InitializeCriticalSection(&rdp->critical);
|
| 2276 |
+
rdp->context = context;
|
| 2277 |
+
WINPR_ASSERT(rdp->context);
|
| 2278 |
+
|
| 2279 |
+
if (context->ServerMode)
|
| 2280 |
+
flags |= FREERDP_SETTINGS_SERVER_MODE;
|
| 2281 |
+
|
| 2282 |
+
if (!context->settings)
|
| 2283 |
+
{
|
| 2284 |
+
context->settings = rdp->settings = freerdp_settings_new(flags);
|
| 2285 |
+
|
| 2286 |
+
if (!rdp->settings)
|
| 2287 |
+
goto fail;
|
| 2288 |
+
}
|
| 2289 |
+
else
|
| 2290 |
+
rdp->settings = context->settings;
|
| 2291 |
+
|
| 2292 |
+
/* Keep a backup copy of settings for later comparisons */
|
| 2293 |
+
if (!rdp_set_backup_settings(rdp))
|
| 2294 |
+
goto fail;
|
| 2295 |
+
|
| 2296 |
+
rdp->settings->instance = context->instance;
|
| 2297 |
+
|
| 2298 |
+
context->settings = rdp->settings;
|
| 2299 |
+
if (context->instance)
|
| 2300 |
+
context->settings->instance = context->instance;
|
| 2301 |
+
else if (context->peer)
|
| 2302 |
+
{
|
| 2303 |
+
rdp->settings->instance = context->peer;
|
| 2304 |
+
|
| 2305 |
+
#if defined(WITH_FREERDP_DEPRECATED)
|
| 2306 |
+
context->peer->settings = rdp->settings;
|
| 2307 |
+
#endif
|
| 2308 |
+
}
|
| 2309 |
+
|
| 2310 |
+
rdp->transport = transport_new(context);
|
| 2311 |
+
|
| 2312 |
+
if (!rdp->transport)
|
| 2313 |
+
goto fail;
|
| 2314 |
+
|
| 2315 |
+
{
|
| 2316 |
+
const rdpTransportIo* io = transport_get_io_callbacks(rdp->transport);
|
| 2317 |
+
if (!io)
|
| 2318 |
+
goto fail;
|
| 2319 |
+
rdp->io = calloc(1, sizeof(rdpTransportIo));
|
| 2320 |
+
if (!rdp->io)
|
| 2321 |
+
goto fail;
|
| 2322 |
+
*rdp->io = *io;
|
| 2323 |
+
}
|
| 2324 |
+
|
| 2325 |
+
rdp->aad = aad_new(context, rdp->transport);
|
| 2326 |
+
if (!rdp->aad)
|
| 2327 |
+
goto fail;
|
| 2328 |
+
|
| 2329 |
+
rdp->license = license_new(rdp);
|
| 2330 |
+
|
| 2331 |
+
if (!rdp->license)
|
| 2332 |
+
goto fail;
|
| 2333 |
+
|
| 2334 |
+
rdp->input = input_new(rdp);
|
| 2335 |
+
|
| 2336 |
+
if (!rdp->input)
|
| 2337 |
+
goto fail;
|
| 2338 |
+
|
| 2339 |
+
rdp->update = update_new(rdp);
|
| 2340 |
+
|
| 2341 |
+
if (!rdp->update)
|
| 2342 |
+
goto fail;
|
| 2343 |
+
|
| 2344 |
+
rdp->fastpath = fastpath_new(rdp);
|
| 2345 |
+
|
| 2346 |
+
if (!rdp->fastpath)
|
| 2347 |
+
goto fail;
|
| 2348 |
+
|
| 2349 |
+
rdp->nego = nego_new(rdp->transport);
|
| 2350 |
+
|
| 2351 |
+
if (!rdp->nego)
|
| 2352 |
+
goto fail;
|
| 2353 |
+
|
| 2354 |
+
rdp->mcs = mcs_new(rdp->transport);
|
| 2355 |
+
|
| 2356 |
+
if (!rdp->mcs)
|
| 2357 |
+
goto fail;
|
| 2358 |
+
|
| 2359 |
+
rdp->redirection = redirection_new();
|
| 2360 |
+
|
| 2361 |
+
if (!rdp->redirection)
|
| 2362 |
+
goto fail;
|
| 2363 |
+
|
| 2364 |
+
rdp->autodetect = autodetect_new(rdp->context);
|
| 2365 |
+
|
| 2366 |
+
if (!rdp->autodetect)
|
| 2367 |
+
goto fail;
|
| 2368 |
+
|
| 2369 |
+
rdp->heartbeat = heartbeat_new();
|
| 2370 |
+
|
| 2371 |
+
if (!rdp->heartbeat)
|
| 2372 |
+
goto fail;
|
| 2373 |
+
|
| 2374 |
+
rdp->multitransport = multitransport_new(rdp, INITIATE_REQUEST_PROTOCOL_UDPFECL |
|
| 2375 |
+
INITIATE_REQUEST_PROTOCOL_UDPFECR);
|
| 2376 |
+
|
| 2377 |
+
if (!rdp->multitransport)
|
| 2378 |
+
goto fail;
|
| 2379 |
+
|
| 2380 |
+
rdp->bulk = bulk_new(context);
|
| 2381 |
+
|
| 2382 |
+
if (!rdp->bulk)
|
| 2383 |
+
goto fail;
|
| 2384 |
+
|
| 2385 |
+
rdp->pubSub = PubSub_New(TRUE);
|
| 2386 |
+
if (!rdp->pubSub)
|
| 2387 |
+
goto fail;
|
| 2388 |
+
|
| 2389 |
+
rdp->abortEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
| 2390 |
+
if (!rdp->abortEvent)
|
| 2391 |
+
goto fail;
|
| 2392 |
+
return rdp;
|
| 2393 |
+
|
| 2394 |
+
fail:
|
| 2395 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 2396 |
+
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
| 2397 |
+
rdp_free(rdp);
|
| 2398 |
+
WINPR_PRAGMA_DIAG_POP
|
| 2399 |
+
return NULL;
|
| 2400 |
+
}
|
| 2401 |
+
|
| 2402 |
+
static void rdp_reset_free(rdpRdp* rdp)
|
| 2403 |
+
{
|
| 2404 |
+
WINPR_ASSERT(rdp);
|
| 2405 |
+
|
| 2406 |
+
(void)security_lock(rdp);
|
| 2407 |
+
rdp_free_rc4_decrypt_keys(rdp);
|
| 2408 |
+
rdp_free_rc4_encrypt_keys(rdp);
|
| 2409 |
+
|
| 2410 |
+
winpr_Cipher_Free(rdp->fips_encrypt);
|
| 2411 |
+
winpr_Cipher_Free(rdp->fips_decrypt);
|
| 2412 |
+
rdp->fips_encrypt = NULL;
|
| 2413 |
+
rdp->fips_decrypt = NULL;
|
| 2414 |
+
(void)security_unlock(rdp);
|
| 2415 |
+
|
| 2416 |
+
mcs_free(rdp->mcs);
|
| 2417 |
+
nego_free(rdp->nego);
|
| 2418 |
+
license_free(rdp->license);
|
| 2419 |
+
transport_free(rdp->transport);
|
| 2420 |
+
fastpath_free(rdp->fastpath);
|
| 2421 |
+
|
| 2422 |
+
rdp->mcs = NULL;
|
| 2423 |
+
rdp->nego = NULL;
|
| 2424 |
+
rdp->license = NULL;
|
| 2425 |
+
rdp->transport = NULL;
|
| 2426 |
+
rdp->fastpath = NULL;
|
| 2427 |
+
}
|
| 2428 |
+
|
| 2429 |
+
BOOL rdp_reset(rdpRdp* rdp)
|
| 2430 |
+
{
|
| 2431 |
+
BOOL rc = TRUE;
|
| 2432 |
+
rdpContext* context = NULL;
|
| 2433 |
+
rdpSettings* settings = NULL;
|
| 2434 |
+
|
| 2435 |
+
WINPR_ASSERT(rdp);
|
| 2436 |
+
|
| 2437 |
+
context = rdp->context;
|
| 2438 |
+
WINPR_ASSERT(context);
|
| 2439 |
+
|
| 2440 |
+
settings = rdp->settings;
|
| 2441 |
+
WINPR_ASSERT(settings);
|
| 2442 |
+
|
| 2443 |
+
bulk_reset(rdp->bulk);
|
| 2444 |
+
|
| 2445 |
+
rdp_reset_free(rdp);
|
| 2446 |
+
|
| 2447 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ServerRandom, NULL, 0))
|
| 2448 |
+
rc = FALSE;
|
| 2449 |
+
|
| 2450 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ServerCertificate, NULL, 0))
|
| 2451 |
+
rc = FALSE;
|
| 2452 |
+
|
| 2453 |
+
if (!freerdp_settings_set_string(settings, FreeRDP_ClientAddress, NULL))
|
| 2454 |
+
rc = FALSE;
|
| 2455 |
+
|
| 2456 |
+
if (!rc)
|
| 2457 |
+
goto fail;
|
| 2458 |
+
|
| 2459 |
+
rc = FALSE;
|
| 2460 |
+
rdp->transport = transport_new(context);
|
| 2461 |
+
if (!rdp->transport)
|
| 2462 |
+
goto fail;
|
| 2463 |
+
|
| 2464 |
+
if (rdp->io)
|
| 2465 |
+
{
|
| 2466 |
+
if (!transport_set_io_callbacks(rdp->transport, rdp->io))
|
| 2467 |
+
goto fail;
|
| 2468 |
+
}
|
| 2469 |
+
|
| 2470 |
+
aad_free(rdp->aad);
|
| 2471 |
+
rdp->aad = aad_new(context, rdp->transport);
|
| 2472 |
+
if (!rdp->aad)
|
| 2473 |
+
goto fail;
|
| 2474 |
+
|
| 2475 |
+
rdp->nego = nego_new(rdp->transport);
|
| 2476 |
+
if (!rdp->nego)
|
| 2477 |
+
goto fail;
|
| 2478 |
+
|
| 2479 |
+
rdp->mcs = mcs_new(rdp->transport);
|
| 2480 |
+
if (!rdp->mcs)
|
| 2481 |
+
goto fail;
|
| 2482 |
+
|
| 2483 |
+
if (!transport_set_layer(rdp->transport, TRANSPORT_LAYER_TCP))
|
| 2484 |
+
goto fail;
|
| 2485 |
+
|
| 2486 |
+
rdp->license = license_new(rdp);
|
| 2487 |
+
if (!rdp->license)
|
| 2488 |
+
goto fail;
|
| 2489 |
+
|
| 2490 |
+
rdp->fastpath = fastpath_new(rdp);
|
| 2491 |
+
if (!rdp->fastpath)
|
| 2492 |
+
goto fail;
|
| 2493 |
+
|
| 2494 |
+
rdp->errorInfo = 0;
|
| 2495 |
+
rc = rdp_finalize_reset_flags(rdp, TRUE);
|
| 2496 |
+
|
| 2497 |
+
fail:
|
| 2498 |
+
return rc;
|
| 2499 |
+
}
|
| 2500 |
+
|
| 2501 |
+
/**
|
| 2502 |
+
* Free RDP module.
|
| 2503 |
+
* @param rdp RDP module to be freed
|
| 2504 |
+
*/
|
| 2505 |
+
|
| 2506 |
+
void rdp_free(rdpRdp* rdp)
|
| 2507 |
+
{
|
| 2508 |
+
if (rdp)
|
| 2509 |
+
{
|
| 2510 |
+
rdp_reset_free(rdp);
|
| 2511 |
+
|
| 2512 |
+
freerdp_settings_free(rdp->settings);
|
| 2513 |
+
freerdp_settings_free(rdp->originalSettings);
|
| 2514 |
+
freerdp_settings_free(rdp->remoteSettings);
|
| 2515 |
+
|
| 2516 |
+
input_free(rdp->input);
|
| 2517 |
+
update_free(rdp->update);
|
| 2518 |
+
nla_free(rdp->nla);
|
| 2519 |
+
redirection_free(rdp->redirection);
|
| 2520 |
+
autodetect_free(rdp->autodetect);
|
| 2521 |
+
heartbeat_free(rdp->heartbeat);
|
| 2522 |
+
multitransport_free(rdp->multitransport);
|
| 2523 |
+
bulk_free(rdp->bulk);
|
| 2524 |
+
free(rdp->io);
|
| 2525 |
+
PubSub_Free(rdp->pubSub);
|
| 2526 |
+
if (rdp->abortEvent)
|
| 2527 |
+
(void)CloseHandle(rdp->abortEvent);
|
| 2528 |
+
aad_free(rdp->aad);
|
| 2529 |
+
WINPR_JSON_Delete(rdp->wellknown);
|
| 2530 |
+
DeleteCriticalSection(&rdp->critical);
|
| 2531 |
+
free(rdp);
|
| 2532 |
+
}
|
| 2533 |
+
}
|
| 2534 |
+
|
| 2535 |
+
BOOL rdp_io_callback_set_event(rdpRdp* rdp, BOOL set)
|
| 2536 |
+
{
|
| 2537 |
+
if (!rdp)
|
| 2538 |
+
return FALSE;
|
| 2539 |
+
return transport_io_callback_set_event(rdp->transport, set);
|
| 2540 |
+
}
|
| 2541 |
+
|
| 2542 |
+
const rdpTransportIo* rdp_get_io_callbacks(rdpRdp* rdp)
|
| 2543 |
+
{
|
| 2544 |
+
if (!rdp)
|
| 2545 |
+
return NULL;
|
| 2546 |
+
return rdp->io;
|
| 2547 |
+
}
|
| 2548 |
+
|
| 2549 |
+
BOOL rdp_set_io_callbacks(rdpRdp* rdp, const rdpTransportIo* io_callbacks)
|
| 2550 |
+
{
|
| 2551 |
+
if (!rdp)
|
| 2552 |
+
return FALSE;
|
| 2553 |
+
free(rdp->io);
|
| 2554 |
+
rdp->io = NULL;
|
| 2555 |
+
if (io_callbacks)
|
| 2556 |
+
{
|
| 2557 |
+
rdp->io = malloc(sizeof(rdpTransportIo));
|
| 2558 |
+
if (!rdp->io)
|
| 2559 |
+
return FALSE;
|
| 2560 |
+
*rdp->io = *io_callbacks;
|
| 2561 |
+
return transport_set_io_callbacks(rdp->transport, rdp->io);
|
| 2562 |
+
}
|
| 2563 |
+
return TRUE;
|
| 2564 |
+
}
|
| 2565 |
+
|
| 2566 |
+
BOOL rdp_set_io_callback_context(rdpRdp* rdp, void* usercontext)
|
| 2567 |
+
{
|
| 2568 |
+
WINPR_ASSERT(rdp);
|
| 2569 |
+
rdp->ioContext = usercontext;
|
| 2570 |
+
return TRUE;
|
| 2571 |
+
}
|
| 2572 |
+
|
| 2573 |
+
void* rdp_get_io_callback_context(rdpRdp* rdp)
|
| 2574 |
+
{
|
| 2575 |
+
WINPR_ASSERT(rdp);
|
| 2576 |
+
return rdp->ioContext;
|
| 2577 |
+
}
|
| 2578 |
+
|
| 2579 |
+
const char* rdp_finalize_flags_to_str(UINT32 flags, char* buffer, size_t size)
|
| 2580 |
+
{
|
| 2581 |
+
char number[32] = { 0 };
|
| 2582 |
+
const UINT32 mask =
|
| 2583 |
+
(uint32_t)~(FINALIZE_SC_SYNCHRONIZE_PDU | FINALIZE_SC_CONTROL_COOPERATE_PDU |
|
| 2584 |
+
FINALIZE_SC_CONTROL_GRANTED_PDU | FINALIZE_SC_FONT_MAP_PDU |
|
| 2585 |
+
FINALIZE_CS_SYNCHRONIZE_PDU | FINALIZE_CS_CONTROL_COOPERATE_PDU |
|
| 2586 |
+
FINALIZE_CS_CONTROL_REQUEST_PDU | FINALIZE_CS_PERSISTENT_KEY_LIST_PDU |
|
| 2587 |
+
FINALIZE_CS_FONT_LIST_PDU | FINALIZE_DEACTIVATE_REACTIVATE);
|
| 2588 |
+
|
| 2589 |
+
if (flags & FINALIZE_SC_SYNCHRONIZE_PDU)
|
| 2590 |
+
winpr_str_append("FINALIZE_SC_SYNCHRONIZE_PDU", buffer, size, "|");
|
| 2591 |
+
if (flags & FINALIZE_SC_CONTROL_COOPERATE_PDU)
|
| 2592 |
+
winpr_str_append("FINALIZE_SC_CONTROL_COOPERATE_PDU", buffer, size, "|");
|
| 2593 |
+
if (flags & FINALIZE_SC_CONTROL_GRANTED_PDU)
|
| 2594 |
+
winpr_str_append("FINALIZE_SC_CONTROL_GRANTED_PDU", buffer, size, "|");
|
| 2595 |
+
if (flags & FINALIZE_SC_FONT_MAP_PDU)
|
| 2596 |
+
winpr_str_append("FINALIZE_SC_FONT_MAP_PDU", buffer, size, "|");
|
| 2597 |
+
if (flags & FINALIZE_CS_SYNCHRONIZE_PDU)
|
| 2598 |
+
winpr_str_append("FINALIZE_CS_SYNCHRONIZE_PDU", buffer, size, "|");
|
| 2599 |
+
if (flags & FINALIZE_CS_CONTROL_COOPERATE_PDU)
|
| 2600 |
+
winpr_str_append("FINALIZE_CS_CONTROL_COOPERATE_PDU", buffer, size, "|");
|
| 2601 |
+
if (flags & FINALIZE_CS_CONTROL_REQUEST_PDU)
|
| 2602 |
+
winpr_str_append("FINALIZE_CS_CONTROL_REQUEST_PDU", buffer, size, "|");
|
| 2603 |
+
if (flags & FINALIZE_CS_PERSISTENT_KEY_LIST_PDU)
|
| 2604 |
+
winpr_str_append("FINALIZE_CS_PERSISTENT_KEY_LIST_PDU", buffer, size, "|");
|
| 2605 |
+
if (flags & FINALIZE_CS_FONT_LIST_PDU)
|
| 2606 |
+
winpr_str_append("FINALIZE_CS_FONT_LIST_PDU", buffer, size, "|");
|
| 2607 |
+
if (flags & FINALIZE_DEACTIVATE_REACTIVATE)
|
| 2608 |
+
winpr_str_append("FINALIZE_DEACTIVATE_REACTIVATE", buffer, size, "|");
|
| 2609 |
+
if (flags & mask)
|
| 2610 |
+
winpr_str_append("UNKNOWN_FLAG", buffer, size, "|");
|
| 2611 |
+
if (flags == 0)
|
| 2612 |
+
winpr_str_append("NO_FLAG_SET", buffer, size, "|");
|
| 2613 |
+
(void)_snprintf(number, sizeof(number), " [0x%08" PRIx32 "]", flags);
|
| 2614 |
+
winpr_str_append(number, buffer, size, "");
|
| 2615 |
+
return buffer;
|
| 2616 |
+
}
|
| 2617 |
+
|
| 2618 |
+
BOOL rdp_finalize_reset_flags(rdpRdp* rdp, BOOL clearAll)
|
| 2619 |
+
{
|
| 2620 |
+
WINPR_ASSERT(rdp);
|
| 2621 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "[%s] reset finalize_sc_pdus", rdp_get_state_string(rdp));
|
| 2622 |
+
if (clearAll)
|
| 2623 |
+
rdp->finalize_sc_pdus = 0;
|
| 2624 |
+
else
|
| 2625 |
+
rdp->finalize_sc_pdus &= FINALIZE_DEACTIVATE_REACTIVATE;
|
| 2626 |
+
|
| 2627 |
+
return rdp_set_monitor_layout_pdu_state(rdp, FALSE);
|
| 2628 |
+
}
|
| 2629 |
+
|
| 2630 |
+
BOOL rdp_finalize_set_flag(rdpRdp* rdp, UINT32 flag)
|
| 2631 |
+
{
|
| 2632 |
+
char buffer[1024] = { 0 };
|
| 2633 |
+
|
| 2634 |
+
WINPR_ASSERT(rdp);
|
| 2635 |
+
|
| 2636 |
+
WLog_Print(rdp->log, WLOG_DEBUG, "[%s] received flag %s", rdp_get_state_string(rdp),
|
| 2637 |
+
rdp_finalize_flags_to_str(flag, buffer, sizeof(buffer)));
|
| 2638 |
+
rdp->finalize_sc_pdus |= flag;
|
| 2639 |
+
return TRUE;
|
| 2640 |
+
}
|
| 2641 |
+
|
| 2642 |
+
BOOL rdp_finalize_is_flag_set(rdpRdp* rdp, UINT32 flag)
|
| 2643 |
+
{
|
| 2644 |
+
WINPR_ASSERT(rdp);
|
| 2645 |
+
return (rdp->finalize_sc_pdus & flag) == flag;
|
| 2646 |
+
}
|
| 2647 |
+
|
| 2648 |
+
BOOL rdp_reset_rc4_encrypt_keys(rdpRdp* rdp)
|
| 2649 |
+
{
|
| 2650 |
+
WINPR_ASSERT(rdp);
|
| 2651 |
+
rdp_free_rc4_encrypt_keys(rdp);
|
| 2652 |
+
rdp->rc4_encrypt_key = winpr_RC4_New(rdp->encrypt_key, rdp->rc4_key_len);
|
| 2653 |
+
|
| 2654 |
+
rdp->encrypt_use_count = 0;
|
| 2655 |
+
return rdp->rc4_encrypt_key != NULL;
|
| 2656 |
+
}
|
| 2657 |
+
|
| 2658 |
+
void rdp_free_rc4_encrypt_keys(rdpRdp* rdp)
|
| 2659 |
+
{
|
| 2660 |
+
WINPR_ASSERT(rdp);
|
| 2661 |
+
winpr_RC4_Free(rdp->rc4_encrypt_key);
|
| 2662 |
+
rdp->rc4_encrypt_key = NULL;
|
| 2663 |
+
}
|
| 2664 |
+
|
| 2665 |
+
void rdp_free_rc4_decrypt_keys(rdpRdp* rdp)
|
| 2666 |
+
{
|
| 2667 |
+
WINPR_ASSERT(rdp);
|
| 2668 |
+
winpr_RC4_Free(rdp->rc4_decrypt_key);
|
| 2669 |
+
rdp->rc4_decrypt_key = NULL;
|
| 2670 |
+
}
|
| 2671 |
+
|
| 2672 |
+
BOOL rdp_reset_rc4_decrypt_keys(rdpRdp* rdp)
|
| 2673 |
+
{
|
| 2674 |
+
WINPR_ASSERT(rdp);
|
| 2675 |
+
rdp_free_rc4_decrypt_keys(rdp);
|
| 2676 |
+
rdp->rc4_decrypt_key = winpr_RC4_New(rdp->decrypt_key, rdp->rc4_key_len);
|
| 2677 |
+
|
| 2678 |
+
rdp->decrypt_use_count = 0;
|
| 2679 |
+
return rdp->rc4_decrypt_key != NULL;
|
| 2680 |
+
}
|
| 2681 |
+
|
| 2682 |
+
const char* rdp_security_flag_string(UINT32 securityFlags, char* buffer, size_t size)
|
| 2683 |
+
{
|
| 2684 |
+
if (securityFlags & SEC_EXCHANGE_PKT)
|
| 2685 |
+
winpr_str_append("SEC_EXCHANGE_PKT", buffer, size, "|");
|
| 2686 |
+
if (securityFlags & SEC_TRANSPORT_REQ)
|
| 2687 |
+
winpr_str_append("SEC_TRANSPORT_REQ", buffer, size, "|");
|
| 2688 |
+
if (securityFlags & SEC_TRANSPORT_RSP)
|
| 2689 |
+
winpr_str_append("SEC_TRANSPORT_RSP", buffer, size, "|");
|
| 2690 |
+
if (securityFlags & SEC_ENCRYPT)
|
| 2691 |
+
winpr_str_append("SEC_ENCRYPT", buffer, size, "|");
|
| 2692 |
+
if (securityFlags & SEC_RESET_SEQNO)
|
| 2693 |
+
winpr_str_append("SEC_RESET_SEQNO", buffer, size, "|");
|
| 2694 |
+
if (securityFlags & SEC_IGNORE_SEQNO)
|
| 2695 |
+
winpr_str_append("SEC_IGNORE_SEQNO", buffer, size, "|");
|
| 2696 |
+
if (securityFlags & SEC_INFO_PKT)
|
| 2697 |
+
winpr_str_append("SEC_INFO_PKT", buffer, size, "|");
|
| 2698 |
+
if (securityFlags & SEC_LICENSE_PKT)
|
| 2699 |
+
winpr_str_append("SEC_LICENSE_PKT", buffer, size, "|");
|
| 2700 |
+
if (securityFlags & SEC_LICENSE_ENCRYPT_CS)
|
| 2701 |
+
winpr_str_append("SEC_LICENSE_ENCRYPT_CS", buffer, size, "|");
|
| 2702 |
+
if (securityFlags & SEC_LICENSE_ENCRYPT_SC)
|
| 2703 |
+
winpr_str_append("SEC_LICENSE_ENCRYPT_SC", buffer, size, "|");
|
| 2704 |
+
if (securityFlags & SEC_REDIRECTION_PKT)
|
| 2705 |
+
winpr_str_append("SEC_REDIRECTION_PKT", buffer, size, "|");
|
| 2706 |
+
if (securityFlags & SEC_SECURE_CHECKSUM)
|
| 2707 |
+
winpr_str_append("SEC_SECURE_CHECKSUM", buffer, size, "|");
|
| 2708 |
+
if (securityFlags & SEC_AUTODETECT_REQ)
|
| 2709 |
+
winpr_str_append("SEC_AUTODETECT_REQ", buffer, size, "|");
|
| 2710 |
+
if (securityFlags & SEC_AUTODETECT_RSP)
|
| 2711 |
+
winpr_str_append("SEC_AUTODETECT_RSP", buffer, size, "|");
|
| 2712 |
+
if (securityFlags & SEC_HEARTBEAT)
|
| 2713 |
+
winpr_str_append("SEC_HEARTBEAT", buffer, size, "|");
|
| 2714 |
+
if (securityFlags & SEC_FLAGSHI_VALID)
|
| 2715 |
+
winpr_str_append("SEC_FLAGSHI_VALID", buffer, size, "|");
|
| 2716 |
+
{
|
| 2717 |
+
char msg[32] = { 0 };
|
| 2718 |
+
|
| 2719 |
+
(void)_snprintf(msg, sizeof(msg), "[0x%08" PRIx32 "]", securityFlags);
|
| 2720 |
+
winpr_str_append(msg, buffer, size, "");
|
| 2721 |
+
}
|
| 2722 |
+
return buffer;
|
| 2723 |
+
}
|
| 2724 |
+
|
| 2725 |
+
static BOOL rdp_reset_remote_settings(rdpRdp* rdp)
|
| 2726 |
+
{
|
| 2727 |
+
UINT32 flags = FREERDP_SETTINGS_REMOTE_MODE;
|
| 2728 |
+
WINPR_ASSERT(rdp);
|
| 2729 |
+
freerdp_settings_free(rdp->remoteSettings);
|
| 2730 |
+
|
| 2731 |
+
if (!freerdp_settings_get_bool(rdp->settings, FreeRDP_ServerMode))
|
| 2732 |
+
flags |= FREERDP_SETTINGS_SERVER_MODE;
|
| 2733 |
+
rdp->remoteSettings = freerdp_settings_new(flags);
|
| 2734 |
+
return rdp->remoteSettings != NULL;
|
| 2735 |
+
}
|
| 2736 |
+
|
| 2737 |
+
BOOL rdp_set_backup_settings(rdpRdp* rdp)
|
| 2738 |
+
{
|
| 2739 |
+
WINPR_ASSERT(rdp);
|
| 2740 |
+
freerdp_settings_free(rdp->originalSettings);
|
| 2741 |
+
rdp->originalSettings = freerdp_settings_clone(rdp->settings);
|
| 2742 |
+
if (!rdp->originalSettings)
|
| 2743 |
+
return FALSE;
|
| 2744 |
+
return rdp_reset_remote_settings(rdp);
|
| 2745 |
+
}
|
| 2746 |
+
|
| 2747 |
+
BOOL rdp_reset_runtime_settings(rdpRdp* rdp)
|
| 2748 |
+
{
|
| 2749 |
+
WINPR_ASSERT(rdp);
|
| 2750 |
+
WINPR_ASSERT(rdp->context);
|
| 2751 |
+
|
| 2752 |
+
freerdp_settings_free(rdp->settings);
|
| 2753 |
+
rdp->context->settings = rdp->settings = freerdp_settings_clone(rdp->originalSettings);
|
| 2754 |
+
|
| 2755 |
+
if (!rdp->settings)
|
| 2756 |
+
return FALSE;
|
| 2757 |
+
return rdp_reset_remote_settings(rdp);
|
| 2758 |
+
}
|
| 2759 |
+
|
| 2760 |
+
static BOOL starts_with(const char* tok, const char* val)
|
| 2761 |
+
{
|
| 2762 |
+
const size_t len = strlen(val);
|
| 2763 |
+
if (strncmp(tok, val, len) != 0)
|
| 2764 |
+
return FALSE;
|
| 2765 |
+
if (tok[len] != '=')
|
| 2766 |
+
return FALSE;
|
| 2767 |
+
return TRUE;
|
| 2768 |
+
}
|
| 2769 |
+
|
| 2770 |
+
static BOOL option_equals(const char* what, const char* val)
|
| 2771 |
+
{
|
| 2772 |
+
return _stricmp(what, val) == 0;
|
| 2773 |
+
}
|
| 2774 |
+
|
| 2775 |
+
static BOOL parse_on_off_option(const char* value)
|
| 2776 |
+
{
|
| 2777 |
+
WINPR_ASSERT(value);
|
| 2778 |
+
const char* sep = strchr(value, '=');
|
| 2779 |
+
if (!sep)
|
| 2780 |
+
return TRUE;
|
| 2781 |
+
if (option_equals("on", &sep[1]))
|
| 2782 |
+
return TRUE;
|
| 2783 |
+
if (option_equals("true", &sep[1]))
|
| 2784 |
+
return TRUE;
|
| 2785 |
+
if (option_equals("off", &sep[1]))
|
| 2786 |
+
return FALSE;
|
| 2787 |
+
if (option_equals("false", &sep[1]))
|
| 2788 |
+
return FALSE;
|
| 2789 |
+
|
| 2790 |
+
errno = 0;
|
| 2791 |
+
long val = strtol(value, NULL, 0);
|
| 2792 |
+
if (errno == 0)
|
| 2793 |
+
return val == 0 ? FALSE : TRUE;
|
| 2794 |
+
|
| 2795 |
+
return FALSE;
|
| 2796 |
+
}
|
| 2797 |
+
|
| 2798 |
+
#define STR(x) #x
|
| 2799 |
+
|
| 2800 |
+
static BOOL option_is_runtime_checks(wLog* log, const char* tok)
|
| 2801 |
+
{
|
| 2802 |
+
const char* experimental[] = { STR(WITH_VERBOSE_WINPR_ASSERT) };
|
| 2803 |
+
for (size_t x = 0; x < ARRAYSIZE(experimental); x++)
|
| 2804 |
+
{
|
| 2805 |
+
const char* opt = experimental[x];
|
| 2806 |
+
if (starts_with(tok, opt))
|
| 2807 |
+
{
|
| 2808 |
+
return parse_on_off_option(tok);
|
| 2809 |
+
}
|
| 2810 |
+
}
|
| 2811 |
+
return FALSE;
|
| 2812 |
+
}
|
| 2813 |
+
|
| 2814 |
+
static BOOL option_is_experimental(wLog* log, const char* tok)
|
| 2815 |
+
{
|
| 2816 |
+
const char* experimental[] = { STR(WITH_DSP_EXPERIMENTAL), STR(WITH_VAAPI) };
|
| 2817 |
+
for (size_t x = 0; x < ARRAYSIZE(experimental); x++)
|
| 2818 |
+
{
|
| 2819 |
+
const char* opt = experimental[x];
|
| 2820 |
+
if (starts_with(tok, opt))
|
| 2821 |
+
{
|
| 2822 |
+
return parse_on_off_option(tok);
|
| 2823 |
+
}
|
| 2824 |
+
}
|
| 2825 |
+
return FALSE;
|
| 2826 |
+
}
|
| 2827 |
+
|
| 2828 |
+
static BOOL option_is_debug(wLog* log, const char* tok)
|
| 2829 |
+
{
|
| 2830 |
+
WINPR_ASSERT(log);
|
| 2831 |
+
const char* debug[] = { STR(WITH_DEBUG_ALL),
|
| 2832 |
+
STR(WITH_DEBUG_CERTIFICATE),
|
| 2833 |
+
STR(WITH_DEBUG_CAPABILITIES),
|
| 2834 |
+
STR(WITH_DEBUG_CHANNELS),
|
| 2835 |
+
STR(WITH_DEBUG_CLIPRDR),
|
| 2836 |
+
STR(WITH_DEBUG_CODECS),
|
| 2837 |
+
STR(WITH_DEBUG_RDPGFX),
|
| 2838 |
+
STR(WITH_DEBUG_DVC),
|
| 2839 |
+
STR(WITH_DEBUG_TSMF),
|
| 2840 |
+
STR(WITH_DEBUG_KBD),
|
| 2841 |
+
STR(WITH_DEBUG_LICENSE),
|
| 2842 |
+
STR(WITH_DEBUG_NEGO),
|
| 2843 |
+
STR(WITH_DEBUG_NLA),
|
| 2844 |
+
STR(WITH_DEBUG_TSG),
|
| 2845 |
+
STR(WITH_DEBUG_RAIL),
|
| 2846 |
+
STR(WITH_DEBUG_RDP),
|
| 2847 |
+
STR(WITH_DEBUG_RDPEI),
|
| 2848 |
+
STR(WITH_DEBUG_REDIR),
|
| 2849 |
+
STR(WITH_DEBUG_RDPDR),
|
| 2850 |
+
STR(WITH_DEBUG_RFX),
|
| 2851 |
+
STR(WITH_DEBUG_SCARD),
|
| 2852 |
+
STR(WITH_DEBUG_SND),
|
| 2853 |
+
STR(WITH_DEBUG_SVC),
|
| 2854 |
+
STR(WITH_DEBUG_TRANSPORT),
|
| 2855 |
+
STR(WITH_DEBUG_TIMEZONE),
|
| 2856 |
+
STR(WITH_DEBUG_WND),
|
| 2857 |
+
STR(WITH_DEBUG_X11_CLIPRDR),
|
| 2858 |
+
STR(WITH_DEBUG_X11_LOCAL_MOVESIZE),
|
| 2859 |
+
STR(WITH_DEBUG_X11),
|
| 2860 |
+
STR(WITH_DEBUG_XV),
|
| 2861 |
+
STR(WITH_DEBUG_RINGBUFFER),
|
| 2862 |
+
STR(WITH_DEBUG_SYMBOLS),
|
| 2863 |
+
STR(WITH_DEBUG_EVENTS),
|
| 2864 |
+
STR(WITH_DEBUG_MUTEX),
|
| 2865 |
+
STR(WITH_DEBUG_NTLM),
|
| 2866 |
+
STR(WITH_DEBUG_SDL_EVENTS),
|
| 2867 |
+
STR(WITH_DEBUG_SDL_KBD_EVENTS),
|
| 2868 |
+
STR(WITH_DEBUG_THREADS),
|
| 2869 |
+
STR(WITH_DEBUG_URBDRC) };
|
| 2870 |
+
|
| 2871 |
+
for (size_t x = 0; x < ARRAYSIZE(debug); x++)
|
| 2872 |
+
{
|
| 2873 |
+
const char* opt = debug[x];
|
| 2874 |
+
if (starts_with(tok, opt))
|
| 2875 |
+
return parse_on_off_option(tok);
|
| 2876 |
+
}
|
| 2877 |
+
|
| 2878 |
+
if (starts_with(tok, "WITH_DEBUG"))
|
| 2879 |
+
{
|
| 2880 |
+
WLog_Print(log, WLOG_WARN, "[BUG] Unmapped Debug-Build option '%s'.", tok);
|
| 2881 |
+
return parse_on_off_option(tok);
|
| 2882 |
+
}
|
| 2883 |
+
|
| 2884 |
+
return FALSE;
|
| 2885 |
+
}
|
| 2886 |
+
|
| 2887 |
+
static void log_build_warn(rdpRdp* rdp, const char* what, const char* msg,
|
| 2888 |
+
BOOL (*cmp)(wLog* log, const char* tok))
|
| 2889 |
+
{
|
| 2890 |
+
WINPR_ASSERT(rdp);
|
| 2891 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 2892 |
+
WINPR_PRAGMA_DIAG_IGNORED_OVERLENGTH_STRINGS
|
| 2893 |
+
|
| 2894 |
+
size_t len = sizeof(FREERDP_BUILD_CONFIG);
|
| 2895 |
+
char* list = calloc(len, sizeof(char));
|
| 2896 |
+
char* config = _strdup(FREERDP_BUILD_CONFIG);
|
| 2897 |
+
WINPR_PRAGMA_DIAG_POP
|
| 2898 |
+
|
| 2899 |
+
if (config && list)
|
| 2900 |
+
{
|
| 2901 |
+
char* saveptr = NULL;
|
| 2902 |
+
char* tok = strtok_s(config, " ", &saveptr);
|
| 2903 |
+
while (tok)
|
| 2904 |
+
{
|
| 2905 |
+
if (cmp(rdp->log, tok))
|
| 2906 |
+
winpr_str_append(tok, list, len, " ");
|
| 2907 |
+
|
| 2908 |
+
tok = strtok_s(NULL, " ", &saveptr);
|
| 2909 |
+
}
|
| 2910 |
+
}
|
| 2911 |
+
free(config);
|
| 2912 |
+
|
| 2913 |
+
if (list)
|
| 2914 |
+
{
|
| 2915 |
+
if (strlen(list) > 0)
|
| 2916 |
+
{
|
| 2917 |
+
WLog_Print(rdp->log, WLOG_WARN, "*************************************************");
|
| 2918 |
+
WLog_Print(rdp->log, WLOG_WARN, "This build is using [%s] build options:", what);
|
| 2919 |
+
|
| 2920 |
+
char* saveptr = NULL;
|
| 2921 |
+
char* tok = strtok_s(list, " ", &saveptr);
|
| 2922 |
+
while (tok)
|
| 2923 |
+
{
|
| 2924 |
+
WLog_Print(rdp->log, WLOG_WARN, "* '%s'", tok);
|
| 2925 |
+
tok = strtok_s(NULL, " ", &saveptr);
|
| 2926 |
+
}
|
| 2927 |
+
WLog_Print(rdp->log, WLOG_WARN, "");
|
| 2928 |
+
WLog_Print(rdp->log, WLOG_WARN, "[%s] build options %s", what, msg);
|
| 2929 |
+
WLog_Print(rdp->log, WLOG_WARN, "*************************************************");
|
| 2930 |
+
}
|
| 2931 |
+
}
|
| 2932 |
+
free(list);
|
| 2933 |
+
}
|
| 2934 |
+
|
| 2935 |
+
#define print_first_line(log, firstLine, what) \
|
| 2936 |
+
print_first_line_int((log), (firstLine), (what), __FILE__, __func__, __LINE__)
|
| 2937 |
+
static void print_first_line_int(wLog* log, log_line_t* firstLine, const char* what,
|
| 2938 |
+
const char* file, const char* fkt, size_t line)
|
| 2939 |
+
{
|
| 2940 |
+
WINPR_ASSERT(firstLine);
|
| 2941 |
+
if (!firstLine->fkt)
|
| 2942 |
+
{
|
| 2943 |
+
const DWORD level = WLOG_WARN;
|
| 2944 |
+
if (WLog_IsLevelActive(log, level))
|
| 2945 |
+
{
|
| 2946 |
+
WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, fkt,
|
| 2947 |
+
"*************************************************");
|
| 2948 |
+
WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, fkt,
|
| 2949 |
+
"[SSL] {%s} build or configuration missing:", what);
|
| 2950 |
+
}
|
| 2951 |
+
firstLine->line = line;
|
| 2952 |
+
firstLine->file = file;
|
| 2953 |
+
firstLine->fkt = fkt;
|
| 2954 |
+
firstLine->level = level;
|
| 2955 |
+
}
|
| 2956 |
+
}
|
| 2957 |
+
|
| 2958 |
+
static void print_last_line(wLog* log, const log_line_t* firstLine)
|
| 2959 |
+
{
|
| 2960 |
+
WINPR_ASSERT(firstLine);
|
| 2961 |
+
if (firstLine->fkt)
|
| 2962 |
+
{
|
| 2963 |
+
if (WLog_IsLevelActive(log, firstLine->level))
|
| 2964 |
+
WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, firstLine->level, firstLine->line,
|
| 2965 |
+
firstLine->file, firstLine->fkt,
|
| 2966 |
+
"*************************************************");
|
| 2967 |
+
}
|
| 2968 |
+
}
|
| 2969 |
+
|
| 2970 |
+
static void log_build_warn_cipher(rdpRdp* rdp, log_line_t* firstLine, WINPR_CIPHER_TYPE md,
|
| 2971 |
+
const char* what)
|
| 2972 |
+
{
|
| 2973 |
+
BOOL haveCipher = FALSE;
|
| 2974 |
+
|
| 2975 |
+
char key[WINPR_CIPHER_MAX_KEY_LENGTH] = { 0 };
|
| 2976 |
+
char iv[WINPR_CIPHER_MAX_IV_LENGTH] = { 0 };
|
| 2977 |
+
|
| 2978 |
+
/* RC4 only exists in the compatibility functions winpr_RC4_*
|
| 2979 |
+
* winpr_Cipher_* does not support that. */
|
| 2980 |
+
if (md == WINPR_CIPHER_ARC4_128)
|
| 2981 |
+
{
|
| 2982 |
+
WINPR_RC4_CTX* enc = winpr_RC4_New(key, sizeof(key));
|
| 2983 |
+
haveCipher = enc != NULL;
|
| 2984 |
+
winpr_RC4_Free(enc);
|
| 2985 |
+
}
|
| 2986 |
+
else
|
| 2987 |
+
{
|
| 2988 |
+
WINPR_CIPHER_CTX* enc =
|
| 2989 |
+
winpr_Cipher_NewEx(md, WINPR_ENCRYPT, key, sizeof(key), iv, sizeof(iv));
|
| 2990 |
+
WINPR_CIPHER_CTX* dec =
|
| 2991 |
+
winpr_Cipher_NewEx(md, WINPR_DECRYPT, key, sizeof(key), iv, sizeof(iv));
|
| 2992 |
+
if (enc && dec)
|
| 2993 |
+
haveCipher = TRUE;
|
| 2994 |
+
|
| 2995 |
+
winpr_Cipher_Free(enc);
|
| 2996 |
+
winpr_Cipher_Free(dec);
|
| 2997 |
+
}
|
| 2998 |
+
|
| 2999 |
+
if (!haveCipher)
|
| 3000 |
+
{
|
| 3001 |
+
print_first_line(rdp->log, firstLine, "Cipher");
|
| 3002 |
+
WLog_Print(rdp->log, WLOG_WARN, "* %s: %s", winpr_cipher_type_to_string(md), what);
|
| 3003 |
+
}
|
| 3004 |
+
}
|
| 3005 |
+
|
| 3006 |
+
static void log_build_warn_hmac(rdpRdp* rdp, log_line_t* firstLine, WINPR_MD_TYPE md,
|
| 3007 |
+
const char* what)
|
| 3008 |
+
{
|
| 3009 |
+
BOOL haveHmacX = FALSE;
|
| 3010 |
+
WINPR_HMAC_CTX* hmac = winpr_HMAC_New();
|
| 3011 |
+
if (hmac)
|
| 3012 |
+
{
|
| 3013 |
+
/* We need some key length, but there is no real limit here.
|
| 3014 |
+
* just take the cipher maximum key length as we already have that available.
|
| 3015 |
+
*/
|
| 3016 |
+
char key[WINPR_CIPHER_MAX_KEY_LENGTH] = { 0 };
|
| 3017 |
+
haveHmacX = winpr_HMAC_Init(hmac, md, key, sizeof(key));
|
| 3018 |
+
}
|
| 3019 |
+
winpr_HMAC_Free(hmac);
|
| 3020 |
+
|
| 3021 |
+
if (!haveHmacX)
|
| 3022 |
+
{
|
| 3023 |
+
print_first_line(rdp->log, firstLine, "HMAC");
|
| 3024 |
+
WLog_Print(rdp->log, WLOG_WARN, " * %s: %s", winpr_md_type_to_string(md), what);
|
| 3025 |
+
}
|
| 3026 |
+
}
|
| 3027 |
+
|
| 3028 |
+
static void log_build_warn_hash(rdpRdp* rdp, log_line_t* firstLine, WINPR_MD_TYPE md,
|
| 3029 |
+
const char* what)
|
| 3030 |
+
{
|
| 3031 |
+
BOOL haveDigestX = FALSE;
|
| 3032 |
+
|
| 3033 |
+
WINPR_DIGEST_CTX* digest = winpr_Digest_New();
|
| 3034 |
+
if (digest)
|
| 3035 |
+
haveDigestX = winpr_Digest_Init(digest, md);
|
| 3036 |
+
winpr_Digest_Free(digest);
|
| 3037 |
+
|
| 3038 |
+
if (!haveDigestX)
|
| 3039 |
+
{
|
| 3040 |
+
print_first_line(rdp->log, firstLine, "Digest");
|
| 3041 |
+
WLog_Print(rdp->log, WLOG_WARN, " * %s: %s", winpr_md_type_to_string(md), what);
|
| 3042 |
+
}
|
| 3043 |
+
}
|
| 3044 |
+
|
| 3045 |
+
static void log_build_warn_ssl(rdpRdp* rdp)
|
| 3046 |
+
{
|
| 3047 |
+
WINPR_ASSERT(rdp);
|
| 3048 |
+
|
| 3049 |
+
log_line_t firstHashLine = { 0 };
|
| 3050 |
+
log_build_warn_hash(rdp, &firstHashLine, WINPR_MD_MD4, "NTLM support not available");
|
| 3051 |
+
log_build_warn_hash(rdp, &firstHashLine, WINPR_MD_MD5,
|
| 3052 |
+
"NTLM, assistance files with encrypted passwords, autoreconnect cookies, "
|
| 3053 |
+
"licensing and RDP security will not work");
|
| 3054 |
+
log_build_warn_hash(rdp, &firstHashLine, WINPR_MD_SHA1,
|
| 3055 |
+
"assistance files with encrypted passwords, Kerberos, Smartcard Logon, RDP "
|
| 3056 |
+
"security support not available");
|
| 3057 |
+
log_build_warn_hash(
|
| 3058 |
+
rdp, &firstHashLine, WINPR_MD_SHA256,
|
| 3059 |
+
"file clipboard, AAD gateway, NLA security and certificates might not work");
|
| 3060 |
+
print_last_line(rdp->log, &firstHashLine);
|
| 3061 |
+
|
| 3062 |
+
log_line_t firstHmacLine = { 0 };
|
| 3063 |
+
log_build_warn_hmac(rdp, &firstHmacLine, WINPR_MD_MD5, "Autoreconnect cookie not supported");
|
| 3064 |
+
log_build_warn_hmac(rdp, &firstHmacLine, WINPR_MD_SHA1, "RDP security not supported");
|
| 3065 |
+
print_last_line(rdp->log, &firstHmacLine);
|
| 3066 |
+
|
| 3067 |
+
log_line_t firstCipherLine = { 0 };
|
| 3068 |
+
log_build_warn_cipher(rdp, &firstCipherLine, WINPR_CIPHER_ARC4_128,
|
| 3069 |
+
"assistance files with encrypted passwords, NTLM, RDP licensing and RDP "
|
| 3070 |
+
"security will not work");
|
| 3071 |
+
log_build_warn_cipher(rdp, &firstCipherLine, WINPR_CIPHER_DES_EDE3_CBC,
|
| 3072 |
+
"RDP security FIPS mode will not work");
|
| 3073 |
+
log_build_warn_cipher(
|
| 3074 |
+
rdp, &firstCipherLine, WINPR_CIPHER_AES_128_CBC,
|
| 3075 |
+
"assistance file encrypted LHTicket will not work and ARM gateway might not");
|
| 3076 |
+
log_build_warn_cipher(rdp, &firstCipherLine, WINPR_CIPHER_AES_192_CBC,
|
| 3077 |
+
"ARM gateway might not work");
|
| 3078 |
+
log_build_warn_cipher(rdp, &firstCipherLine, WINPR_CIPHER_AES_256_CBC,
|
| 3079 |
+
"ARM gateway might not work");
|
| 3080 |
+
print_last_line(rdp->log, &firstCipherLine);
|
| 3081 |
+
}
|
| 3082 |
+
|
| 3083 |
+
void rdp_log_build_warnings(rdpRdp* rdp)
|
| 3084 |
+
{
|
| 3085 |
+
static unsigned count = 0;
|
| 3086 |
+
|
| 3087 |
+
WINPR_ASSERT(rdp);
|
| 3088 |
+
/* Since this function is called in context creation routines stop logging
|
| 3089 |
+
* this issue repeatedly. This is required for proxy, which would otherwise
|
| 3090 |
+
* spam the log with these. */
|
| 3091 |
+
if (count > 0)
|
| 3092 |
+
return;
|
| 3093 |
+
count++;
|
| 3094 |
+
log_build_warn(rdp, "experimental", "might crash the application", option_is_experimental);
|
| 3095 |
+
log_build_warn(rdp, "debug", "might leak sensitive information (credentials, ...)",
|
| 3096 |
+
option_is_debug);
|
| 3097 |
+
log_build_warn(rdp, "runtime-check", "might slow down the application",
|
| 3098 |
+
option_is_runtime_checks);
|
| 3099 |
+
log_build_warn_ssl(rdp);
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* RDSTLS Security protocol
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2023 Joan Torres <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include "settings.h"
|
| 23 |
+
|
| 24 |
+
#include <freerdp/log.h>
|
| 25 |
+
#include <freerdp/error.h>
|
| 26 |
+
#include <freerdp/settings.h>
|
| 27 |
+
|
| 28 |
+
#include <winpr/assert.h>
|
| 29 |
+
#include <winpr/stream.h>
|
| 30 |
+
#include <winpr/wlog.h>
|
| 31 |
+
|
| 32 |
+
#include "rdstls.h"
|
| 33 |
+
#include "transport.h"
|
| 34 |
+
#include "utils.h"
|
| 35 |
+
|
| 36 |
+
#define RDSTLS_VERSION_1 0x01
|
| 37 |
+
|
| 38 |
+
#define RDSTLS_TYPE_CAPABILITIES 0x01
|
| 39 |
+
#define RDSTLS_TYPE_AUTHREQ 0x02
|
| 40 |
+
#define RDSTLS_TYPE_AUTHRSP 0x04
|
| 41 |
+
|
| 42 |
+
#define RDSTLS_DATA_CAPABILITIES 0x01
|
| 43 |
+
#define RDSTLS_DATA_PASSWORD_CREDS 0x01
|
| 44 |
+
#define RDSTLS_DATA_AUTORECONNECT_COOKIE 0x02
|
| 45 |
+
#define RDSTLS_DATA_RESULT_CODE 0x01
|
| 46 |
+
|
| 47 |
+
typedef enum
|
| 48 |
+
{
|
| 49 |
+
RDSTLS_STATE_INITIAL,
|
| 50 |
+
RDSTLS_STATE_CAPABILITIES,
|
| 51 |
+
RDSTLS_STATE_AUTH_REQ,
|
| 52 |
+
RDSTLS_STATE_AUTH_RSP,
|
| 53 |
+
RDSTLS_STATE_FINAL,
|
| 54 |
+
} RDSTLS_STATE;
|
| 55 |
+
|
| 56 |
+
typedef enum
|
| 57 |
+
{
|
| 58 |
+
|
| 59 |
+
RDSTLS_RESULT_SUCCESS = 0x00000000,
|
| 60 |
+
RDSTLS_RESULT_ACCESS_DENIED = 0x00000005,
|
| 61 |
+
RDSTLS_RESULT_LOGON_FAILURE = 0x0000052e,
|
| 62 |
+
RDSTLS_RESULT_INVALID_LOGON_HOURS = 0x00000530,
|
| 63 |
+
RDSTLS_RESULT_PASSWORD_EXPIRED = 0x00000532,
|
| 64 |
+
RDSTLS_RESULT_ACCOUNT_DISABLED = 0x00000533,
|
| 65 |
+
RDSTLS_RESULT_PASSWORD_MUST_CHANGE = 0x00000773,
|
| 66 |
+
RDSTLS_RESULT_ACCOUNT_LOCKED_OUT = 0x00000775
|
| 67 |
+
} RDSTLS_RESULT_CODE;
|
| 68 |
+
|
| 69 |
+
struct rdp_rdstls
|
| 70 |
+
{
|
| 71 |
+
BOOL server;
|
| 72 |
+
RDSTLS_STATE state;
|
| 73 |
+
rdpContext* context;
|
| 74 |
+
rdpTransport* transport;
|
| 75 |
+
|
| 76 |
+
RDSTLS_RESULT_CODE resultCode;
|
| 77 |
+
wLog* log;
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
static const char* rdstls_result_code_str(UINT32 resultCode)
|
| 81 |
+
{
|
| 82 |
+
switch (resultCode)
|
| 83 |
+
{
|
| 84 |
+
case RDSTLS_RESULT_SUCCESS:
|
| 85 |
+
return "RDSTLS_RESULT_SUCCESS";
|
| 86 |
+
case RDSTLS_RESULT_ACCESS_DENIED:
|
| 87 |
+
return "RDSTLS_RESULT_ACCESS_DENIED";
|
| 88 |
+
case RDSTLS_RESULT_LOGON_FAILURE:
|
| 89 |
+
return "RDSTLS_RESULT_LOGON_FAILURE";
|
| 90 |
+
case RDSTLS_RESULT_INVALID_LOGON_HOURS:
|
| 91 |
+
return "RDSTLS_RESULT_INVALID_LOGON_HOURS";
|
| 92 |
+
case RDSTLS_RESULT_PASSWORD_EXPIRED:
|
| 93 |
+
return "RDSTLS_RESULT_PASSWORD_EXPIRED";
|
| 94 |
+
case RDSTLS_RESULT_ACCOUNT_DISABLED:
|
| 95 |
+
return "RDSTLS_RESULT_ACCOUNT_DISABLED";
|
| 96 |
+
case RDSTLS_RESULT_PASSWORD_MUST_CHANGE:
|
| 97 |
+
return "RDSTLS_RESULT_PASSWORD_MUST_CHANGE";
|
| 98 |
+
case RDSTLS_RESULT_ACCOUNT_LOCKED_OUT:
|
| 99 |
+
return "RDSTLS_RESULT_ACCOUNT_LOCKED_OUT";
|
| 100 |
+
default:
|
| 101 |
+
return "RDSTLS_RESULT_UNKNOWN";
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
/**
|
| 105 |
+
* Create new RDSTLS state machine.
|
| 106 |
+
*
|
| 107 |
+
* @param context A pointer to the rdp context to use
|
| 108 |
+
*
|
| 109 |
+
* @return new RDSTLS state machine.
|
| 110 |
+
*/
|
| 111 |
+
|
| 112 |
+
rdpRdstls* rdstls_new(rdpContext* context, rdpTransport* transport)
|
| 113 |
+
{
|
| 114 |
+
WINPR_ASSERT(context);
|
| 115 |
+
WINPR_ASSERT(transport);
|
| 116 |
+
|
| 117 |
+
rdpSettings* settings = context->settings;
|
| 118 |
+
WINPR_ASSERT(settings);
|
| 119 |
+
|
| 120 |
+
rdpRdstls* rdstls = (rdpRdstls*)calloc(1, sizeof(rdpRdstls));
|
| 121 |
+
|
| 122 |
+
if (!rdstls)
|
| 123 |
+
return NULL;
|
| 124 |
+
rdstls->log = WLog_Get(FREERDP_TAG("core.rdstls"));
|
| 125 |
+
rdstls->context = context;
|
| 126 |
+
rdstls->transport = transport;
|
| 127 |
+
rdstls->server = settings->ServerMode;
|
| 128 |
+
|
| 129 |
+
rdstls->state = RDSTLS_STATE_INITIAL;
|
| 130 |
+
|
| 131 |
+
return rdstls;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Free RDSTLS state machine.
|
| 136 |
+
* @param rdstls The RDSTLS instance to free
|
| 137 |
+
*/
|
| 138 |
+
|
| 139 |
+
void rdstls_free(rdpRdstls* rdstls)
|
| 140 |
+
{
|
| 141 |
+
free(rdstls);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
static const char* rdstls_get_state_str(RDSTLS_STATE state)
|
| 145 |
+
{
|
| 146 |
+
switch (state)
|
| 147 |
+
{
|
| 148 |
+
case RDSTLS_STATE_INITIAL:
|
| 149 |
+
return "RDSTLS_STATE_INITIAL";
|
| 150 |
+
case RDSTLS_STATE_CAPABILITIES:
|
| 151 |
+
return "RDSTLS_STATE_CAPABILITIES";
|
| 152 |
+
case RDSTLS_STATE_AUTH_REQ:
|
| 153 |
+
return "RDSTLS_STATE_AUTH_REQ";
|
| 154 |
+
case RDSTLS_STATE_AUTH_RSP:
|
| 155 |
+
return "RDSTLS_STATE_AUTH_RSP";
|
| 156 |
+
case RDSTLS_STATE_FINAL:
|
| 157 |
+
return "RDSTLS_STATE_FINAL";
|
| 158 |
+
default:
|
| 159 |
+
return "UNKNOWN";
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
static RDSTLS_STATE rdstls_get_state(rdpRdstls* rdstls)
|
| 164 |
+
{
|
| 165 |
+
WINPR_ASSERT(rdstls);
|
| 166 |
+
return rdstls->state;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
static BOOL check_transition(wLog* log, RDSTLS_STATE current, RDSTLS_STATE expected,
|
| 170 |
+
RDSTLS_STATE requested)
|
| 171 |
+
{
|
| 172 |
+
if (requested != expected)
|
| 173 |
+
{
|
| 174 |
+
WLog_Print(log, WLOG_ERROR,
|
| 175 |
+
"Unexpected rdstls state transition from %s [%d] to %s [%d], expected %s [%d]",
|
| 176 |
+
rdstls_get_state_str(current), current, rdstls_get_state_str(requested),
|
| 177 |
+
requested, rdstls_get_state_str(expected), expected);
|
| 178 |
+
return FALSE;
|
| 179 |
+
}
|
| 180 |
+
return TRUE;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
static BOOL rdstls_set_state(rdpRdstls* rdstls, RDSTLS_STATE state)
|
| 184 |
+
{
|
| 185 |
+
BOOL rc = FALSE;
|
| 186 |
+
WINPR_ASSERT(rdstls);
|
| 187 |
+
|
| 188 |
+
WLog_Print(rdstls->log, WLOG_DEBUG, "-- %s\t--> %s", rdstls_get_state_str(rdstls->state),
|
| 189 |
+
rdstls_get_state_str(state));
|
| 190 |
+
|
| 191 |
+
switch (rdstls->state)
|
| 192 |
+
{
|
| 193 |
+
case RDSTLS_STATE_INITIAL:
|
| 194 |
+
rc = check_transition(rdstls->log, rdstls->state, RDSTLS_STATE_CAPABILITIES, state);
|
| 195 |
+
break;
|
| 196 |
+
case RDSTLS_STATE_CAPABILITIES:
|
| 197 |
+
rc = check_transition(rdstls->log, rdstls->state, RDSTLS_STATE_AUTH_REQ, state);
|
| 198 |
+
break;
|
| 199 |
+
case RDSTLS_STATE_AUTH_REQ:
|
| 200 |
+
rc = check_transition(rdstls->log, rdstls->state, RDSTLS_STATE_AUTH_RSP, state);
|
| 201 |
+
break;
|
| 202 |
+
case RDSTLS_STATE_AUTH_RSP:
|
| 203 |
+
rc = check_transition(rdstls->log, rdstls->state, RDSTLS_STATE_FINAL, state);
|
| 204 |
+
break;
|
| 205 |
+
case RDSTLS_STATE_FINAL:
|
| 206 |
+
rc = check_transition(rdstls->log, rdstls->state, RDSTLS_STATE_CAPABILITIES, state);
|
| 207 |
+
break;
|
| 208 |
+
default:
|
| 209 |
+
WLog_Print(rdstls->log, WLOG_ERROR,
|
| 210 |
+
"Invalid rdstls state %s [%d], requested transition to %s [%d]",
|
| 211 |
+
rdstls_get_state_str(rdstls->state), rdstls->state,
|
| 212 |
+
rdstls_get_state_str(state), state);
|
| 213 |
+
break;
|
| 214 |
+
}
|
| 215 |
+
if (rc)
|
| 216 |
+
rdstls->state = state;
|
| 217 |
+
|
| 218 |
+
return rc;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
static BOOL rdstls_write_capabilities(rdpRdstls* rdstls, wStream* s)
|
| 222 |
+
{
|
| 223 |
+
if (!Stream_EnsureRemainingCapacity(s, 6))
|
| 224 |
+
return FALSE;
|
| 225 |
+
|
| 226 |
+
Stream_Write_UINT16(s, RDSTLS_TYPE_CAPABILITIES);
|
| 227 |
+
Stream_Write_UINT16(s, RDSTLS_DATA_CAPABILITIES);
|
| 228 |
+
Stream_Write_UINT16(s, RDSTLS_VERSION_1);
|
| 229 |
+
|
| 230 |
+
return TRUE;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
static SSIZE_T rdstls_write_string(wStream* s, const char* str)
|
| 234 |
+
{
|
| 235 |
+
const size_t pos = Stream_GetPosition(s);
|
| 236 |
+
|
| 237 |
+
if (!Stream_EnsureRemainingCapacity(s, 2))
|
| 238 |
+
return -1;
|
| 239 |
+
|
| 240 |
+
if (!str)
|
| 241 |
+
{
|
| 242 |
+
/* Write unicode null */
|
| 243 |
+
Stream_Write_UINT16(s, 2);
|
| 244 |
+
if (!Stream_EnsureRemainingCapacity(s, 2))
|
| 245 |
+
return -1;
|
| 246 |
+
|
| 247 |
+
Stream_Write_UINT16(s, 0);
|
| 248 |
+
return (SSIZE_T)(Stream_GetPosition(s) - pos);
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
const size_t length = (strlen(str) + 1);
|
| 252 |
+
|
| 253 |
+
Stream_Write_UINT16(s, (UINT16)length * sizeof(WCHAR));
|
| 254 |
+
|
| 255 |
+
if (!Stream_EnsureRemainingCapacity(s, length * sizeof(WCHAR)))
|
| 256 |
+
return -1;
|
| 257 |
+
|
| 258 |
+
if (Stream_Write_UTF16_String_From_UTF8(s, length, str, length, TRUE) < 0)
|
| 259 |
+
return -1;
|
| 260 |
+
|
| 261 |
+
return (SSIZE_T)(Stream_GetPosition(s) - pos);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
static BOOL rdstls_write_data(wStream* s, UINT32 length, const BYTE* data)
|
| 265 |
+
{
|
| 266 |
+
WINPR_ASSERT(data || (length == 0));
|
| 267 |
+
|
| 268 |
+
if (!Stream_EnsureRemainingCapacity(s, 2) || (length > UINT16_MAX))
|
| 269 |
+
return FALSE;
|
| 270 |
+
|
| 271 |
+
Stream_Write_UINT16(s, (UINT16)length);
|
| 272 |
+
|
| 273 |
+
if (!Stream_EnsureRemainingCapacity(s, length))
|
| 274 |
+
return FALSE;
|
| 275 |
+
|
| 276 |
+
Stream_Write(s, data, length);
|
| 277 |
+
|
| 278 |
+
return TRUE;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
static BOOL rdstls_write_authentication_request_with_password(rdpRdstls* rdstls, wStream* s)
|
| 282 |
+
{
|
| 283 |
+
rdpSettings* settings = rdstls->context->settings;
|
| 284 |
+
WINPR_ASSERT(settings);
|
| 285 |
+
|
| 286 |
+
if (!Stream_EnsureRemainingCapacity(s, 4))
|
| 287 |
+
return FALSE;
|
| 288 |
+
|
| 289 |
+
Stream_Write_UINT16(s, RDSTLS_TYPE_AUTHREQ);
|
| 290 |
+
Stream_Write_UINT16(s, RDSTLS_DATA_PASSWORD_CREDS);
|
| 291 |
+
|
| 292 |
+
if (!rdstls_write_data(s, settings->RedirectionGuidLength, settings->RedirectionGuid))
|
| 293 |
+
return FALSE;
|
| 294 |
+
|
| 295 |
+
if (rdstls_write_string(s, settings->Username) < 0)
|
| 296 |
+
return FALSE;
|
| 297 |
+
|
| 298 |
+
if (rdstls_write_string(s, settings->Domain) < 0)
|
| 299 |
+
return FALSE;
|
| 300 |
+
|
| 301 |
+
if (!rdstls_write_data(s, settings->RedirectionPasswordLength, settings->RedirectionPassword))
|
| 302 |
+
return FALSE;
|
| 303 |
+
|
| 304 |
+
return TRUE;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
static BOOL rdstls_write_authentication_request_with_cookie(rdpRdstls* rdstls, wStream* s)
|
| 308 |
+
{
|
| 309 |
+
// TODO
|
| 310 |
+
return FALSE;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
static BOOL rdstls_write_authentication_response(rdpRdstls* rdstls, wStream* s)
|
| 314 |
+
{
|
| 315 |
+
if (!Stream_EnsureRemainingCapacity(s, 8))
|
| 316 |
+
return FALSE;
|
| 317 |
+
|
| 318 |
+
Stream_Write_UINT16(s, RDSTLS_TYPE_AUTHRSP);
|
| 319 |
+
Stream_Write_UINT16(s, RDSTLS_DATA_RESULT_CODE);
|
| 320 |
+
Stream_Write_UINT32(s, rdstls->resultCode);
|
| 321 |
+
|
| 322 |
+
return TRUE;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
static BOOL rdstls_process_capabilities(rdpRdstls* rdstls, wStream* s)
|
| 326 |
+
{
|
| 327 |
+
UINT16 dataType = 0;
|
| 328 |
+
UINT16 supportedVersions = 0;
|
| 329 |
+
|
| 330 |
+
if (Stream_GetRemainingLength(s) < 4)
|
| 331 |
+
return FALSE;
|
| 332 |
+
|
| 333 |
+
Stream_Read_UINT16(s, dataType);
|
| 334 |
+
if (dataType != RDSTLS_DATA_CAPABILITIES)
|
| 335 |
+
{
|
| 336 |
+
WLog_Print(rdstls->log, WLOG_ERROR,
|
| 337 |
+
"received invalid DataType=0x%04" PRIX16 ", expected 0x%04" PRIX16, dataType,
|
| 338 |
+
RDSTLS_DATA_CAPABILITIES);
|
| 339 |
+
return FALSE;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
Stream_Read_UINT16(s, supportedVersions);
|
| 343 |
+
if ((supportedVersions & RDSTLS_VERSION_1) == 0)
|
| 344 |
+
{
|
| 345 |
+
WLog_Print(rdstls->log, WLOG_ERROR,
|
| 346 |
+
"received invalid supportedVersions=0x%04" PRIX16 ", expected 0x%04" PRIX16,
|
| 347 |
+
supportedVersions, RDSTLS_VERSION_1);
|
| 348 |
+
return FALSE;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
return TRUE;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
static BOOL rdstls_read_unicode_string(wLog* log, wStream* s, char** str)
|
| 355 |
+
{
|
| 356 |
+
UINT16 length = 0;
|
| 357 |
+
|
| 358 |
+
WINPR_ASSERT(str);
|
| 359 |
+
|
| 360 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 361 |
+
return FALSE;
|
| 362 |
+
|
| 363 |
+
Stream_Read_UINT16(s, length);
|
| 364 |
+
|
| 365 |
+
if (Stream_GetRemainingLength(s) < length)
|
| 366 |
+
return FALSE;
|
| 367 |
+
|
| 368 |
+
if (length <= 2)
|
| 369 |
+
{
|
| 370 |
+
Stream_Seek(s, length);
|
| 371 |
+
return TRUE;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
*str = Stream_Read_UTF16_String_As_UTF8(s, length / sizeof(WCHAR), NULL);
|
| 375 |
+
if (!*str)
|
| 376 |
+
return FALSE;
|
| 377 |
+
|
| 378 |
+
return TRUE;
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
static BOOL rdstls_read_data(wLog* log, wStream* s, UINT16* pLength, const BYTE** pData)
|
| 382 |
+
{
|
| 383 |
+
UINT16 length = 0;
|
| 384 |
+
|
| 385 |
+
WINPR_ASSERT(pLength);
|
| 386 |
+
WINPR_ASSERT(pData);
|
| 387 |
+
|
| 388 |
+
*pData = NULL;
|
| 389 |
+
*pLength = 0;
|
| 390 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 391 |
+
return FALSE;
|
| 392 |
+
|
| 393 |
+
Stream_Read_UINT16(s, length);
|
| 394 |
+
|
| 395 |
+
if (Stream_GetRemainingLength(s) < length)
|
| 396 |
+
return FALSE;
|
| 397 |
+
|
| 398 |
+
if (length <= 2)
|
| 399 |
+
{
|
| 400 |
+
Stream_Seek(s, length);
|
| 401 |
+
return TRUE;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
*pData = Stream_ConstPointer(s);
|
| 405 |
+
*pLength = length;
|
| 406 |
+
Stream_Seek(s, length);
|
| 407 |
+
return TRUE;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
static BOOL rdstls_cmp_data(wLog* log, const char* field, const BYTE* serverData,
|
| 411 |
+
const UINT32 serverDataLength, const BYTE* clientData,
|
| 412 |
+
const UINT16 clientDataLength)
|
| 413 |
+
{
|
| 414 |
+
if (serverDataLength > 0)
|
| 415 |
+
{
|
| 416 |
+
if (clientDataLength == 0)
|
| 417 |
+
{
|
| 418 |
+
WLog_Print(log, WLOG_ERROR, "expected %s", field);
|
| 419 |
+
return FALSE;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
if (serverDataLength > UINT16_MAX || serverDataLength != clientDataLength ||
|
| 423 |
+
memcmp(serverData, clientData, serverDataLength) != 0)
|
| 424 |
+
{
|
| 425 |
+
WLog_Print(log, WLOG_ERROR, "%s verification failed", field);
|
| 426 |
+
return FALSE;
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
return TRUE;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
static BOOL rdstls_cmp_str(wLog* log, const char* field, const char* serverStr,
|
| 434 |
+
const char* clientStr)
|
| 435 |
+
{
|
| 436 |
+
if (!utils_str_is_empty(serverStr))
|
| 437 |
+
{
|
| 438 |
+
if (utils_str_is_empty(clientStr))
|
| 439 |
+
{
|
| 440 |
+
WLog_Print(log, WLOG_ERROR, "expected %s", field);
|
| 441 |
+
return FALSE;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
WINPR_ASSERT(serverStr);
|
| 445 |
+
WINPR_ASSERT(clientStr);
|
| 446 |
+
if (strcmp(serverStr, clientStr) != 0)
|
| 447 |
+
{
|
| 448 |
+
WLog_Print(log, WLOG_ERROR, "%s verification failed", field);
|
| 449 |
+
return FALSE;
|
| 450 |
+
}
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
return TRUE;
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
static BOOL rdstls_process_authentication_request_with_password(rdpRdstls* rdstls, wStream* s)
|
| 457 |
+
{
|
| 458 |
+
BOOL rc = FALSE;
|
| 459 |
+
|
| 460 |
+
const BYTE* clientRedirectionGuid = NULL;
|
| 461 |
+
UINT16 clientRedirectionGuidLength = 0;
|
| 462 |
+
char* clientPassword = NULL;
|
| 463 |
+
char* clientUsername = NULL;
|
| 464 |
+
char* clientDomain = NULL;
|
| 465 |
+
|
| 466 |
+
const BYTE* serverRedirectionGuid = NULL;
|
| 467 |
+
const char* serverPassword = NULL;
|
| 468 |
+
const char* serverUsername = NULL;
|
| 469 |
+
const char* serverDomain = NULL;
|
| 470 |
+
|
| 471 |
+
rdpSettings* settings = rdstls->context->settings;
|
| 472 |
+
WINPR_ASSERT(settings);
|
| 473 |
+
|
| 474 |
+
if (!rdstls_read_data(rdstls->log, s, &clientRedirectionGuidLength, &clientRedirectionGuid))
|
| 475 |
+
goto fail;
|
| 476 |
+
|
| 477 |
+
if (!rdstls_read_unicode_string(rdstls->log, s, &clientUsername))
|
| 478 |
+
goto fail;
|
| 479 |
+
|
| 480 |
+
if (!rdstls_read_unicode_string(rdstls->log, s, &clientDomain))
|
| 481 |
+
goto fail;
|
| 482 |
+
|
| 483 |
+
if (!rdstls_read_unicode_string(rdstls->log, s, &clientPassword))
|
| 484 |
+
goto fail;
|
| 485 |
+
|
| 486 |
+
serverRedirectionGuid = freerdp_settings_get_pointer(settings, FreeRDP_RedirectionGuid);
|
| 487 |
+
const UINT32 serverRedirectionGuidLength =
|
| 488 |
+
freerdp_settings_get_uint32(settings, FreeRDP_RedirectionGuidLength);
|
| 489 |
+
serverUsername = freerdp_settings_get_string(settings, FreeRDP_Username);
|
| 490 |
+
serverDomain = freerdp_settings_get_string(settings, FreeRDP_Domain);
|
| 491 |
+
serverPassword = freerdp_settings_get_string(settings, FreeRDP_Password);
|
| 492 |
+
|
| 493 |
+
rdstls->resultCode = RDSTLS_RESULT_SUCCESS;
|
| 494 |
+
|
| 495 |
+
if (!rdstls_cmp_data(rdstls->log, "RedirectionGuid", serverRedirectionGuid,
|
| 496 |
+
serverRedirectionGuidLength, clientRedirectionGuid,
|
| 497 |
+
clientRedirectionGuidLength))
|
| 498 |
+
rdstls->resultCode = RDSTLS_RESULT_ACCESS_DENIED;
|
| 499 |
+
|
| 500 |
+
if (!rdstls_cmp_str(rdstls->log, "UserName", serverUsername, clientUsername))
|
| 501 |
+
rdstls->resultCode = RDSTLS_RESULT_LOGON_FAILURE;
|
| 502 |
+
|
| 503 |
+
if (!rdstls_cmp_str(rdstls->log, "Domain", serverDomain, clientDomain))
|
| 504 |
+
rdstls->resultCode = RDSTLS_RESULT_LOGON_FAILURE;
|
| 505 |
+
|
| 506 |
+
if (!rdstls_cmp_str(rdstls->log, "Password", serverPassword, clientPassword))
|
| 507 |
+
rdstls->resultCode = RDSTLS_RESULT_LOGON_FAILURE;
|
| 508 |
+
|
| 509 |
+
rc = TRUE;
|
| 510 |
+
fail:
|
| 511 |
+
return rc;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
static BOOL rdstls_process_authentication_request_with_cookie(rdpRdstls* rdstls, wStream* s)
|
| 515 |
+
{
|
| 516 |
+
// TODO
|
| 517 |
+
return FALSE;
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
static BOOL rdstls_process_authentication_request(rdpRdstls* rdstls, wStream* s)
|
| 521 |
+
{
|
| 522 |
+
UINT16 dataType = 0;
|
| 523 |
+
|
| 524 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 525 |
+
return FALSE;
|
| 526 |
+
|
| 527 |
+
Stream_Read_UINT16(s, dataType);
|
| 528 |
+
switch (dataType)
|
| 529 |
+
{
|
| 530 |
+
case RDSTLS_DATA_PASSWORD_CREDS:
|
| 531 |
+
if (!rdstls_process_authentication_request_with_password(rdstls, s))
|
| 532 |
+
return FALSE;
|
| 533 |
+
break;
|
| 534 |
+
case RDSTLS_DATA_AUTORECONNECT_COOKIE:
|
| 535 |
+
if (!rdstls_process_authentication_request_with_cookie(rdstls, s))
|
| 536 |
+
return FALSE;
|
| 537 |
+
break;
|
| 538 |
+
default:
|
| 539 |
+
WLog_Print(rdstls->log, WLOG_ERROR,
|
| 540 |
+
"received invalid DataType=0x%04" PRIX16 ", expected 0x%04" PRIX16
|
| 541 |
+
" or 0x%04" PRIX16,
|
| 542 |
+
dataType, RDSTLS_DATA_PASSWORD_CREDS, RDSTLS_DATA_AUTORECONNECT_COOKIE);
|
| 543 |
+
return FALSE;
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
return TRUE;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
static BOOL rdstls_process_authentication_response(rdpRdstls* rdstls, wStream* s)
|
| 550 |
+
{
|
| 551 |
+
UINT16 dataType = 0;
|
| 552 |
+
UINT32 resultCode = 0;
|
| 553 |
+
|
| 554 |
+
if (Stream_GetRemainingLength(s) < 6)
|
| 555 |
+
return FALSE;
|
| 556 |
+
|
| 557 |
+
Stream_Read_UINT16(s, dataType);
|
| 558 |
+
if (dataType != RDSTLS_DATA_RESULT_CODE)
|
| 559 |
+
{
|
| 560 |
+
WLog_Print(rdstls->log, WLOG_ERROR,
|
| 561 |
+
"received invalid DataType=0x%04" PRIX16 ", expected 0x%04" PRIX16, dataType,
|
| 562 |
+
RDSTLS_DATA_RESULT_CODE);
|
| 563 |
+
return FALSE;
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
Stream_Read_UINT32(s, resultCode);
|
| 567 |
+
if (resultCode != RDSTLS_RESULT_SUCCESS)
|
| 568 |
+
{
|
| 569 |
+
WLog_Print(rdstls->log, WLOG_ERROR, "resultCode: %s [0x%08" PRIX32 "]",
|
| 570 |
+
rdstls_result_code_str(resultCode), resultCode);
|
| 571 |
+
|
| 572 |
+
UINT32 error = ERROR_INTERNAL_ERROR;
|
| 573 |
+
switch (resultCode)
|
| 574 |
+
{
|
| 575 |
+
case RDSTLS_RESULT_ACCESS_DENIED:
|
| 576 |
+
error = FREERDP_ERROR_CONNECT_ACCESS_DENIED;
|
| 577 |
+
break;
|
| 578 |
+
case RDSTLS_RESULT_ACCOUNT_DISABLED:
|
| 579 |
+
error = FREERDP_ERROR_CONNECT_ACCOUNT_DISABLED;
|
| 580 |
+
break;
|
| 581 |
+
case RDSTLS_RESULT_ACCOUNT_LOCKED_OUT:
|
| 582 |
+
error = FREERDP_ERROR_CONNECT_ACCOUNT_LOCKED_OUT;
|
| 583 |
+
break;
|
| 584 |
+
case RDSTLS_RESULT_LOGON_FAILURE:
|
| 585 |
+
error = FREERDP_ERROR_CONNECT_LOGON_FAILURE;
|
| 586 |
+
break;
|
| 587 |
+
case RDSTLS_RESULT_INVALID_LOGON_HOURS:
|
| 588 |
+
error = FREERDP_ERROR_CONNECT_ACCOUNT_RESTRICTION;
|
| 589 |
+
break;
|
| 590 |
+
case RDSTLS_RESULT_PASSWORD_EXPIRED:
|
| 591 |
+
error = FREERDP_ERROR_CONNECT_PASSWORD_EXPIRED;
|
| 592 |
+
break;
|
| 593 |
+
case RDSTLS_RESULT_PASSWORD_MUST_CHANGE:
|
| 594 |
+
error = FREERDP_ERROR_CONNECT_PASSWORD_MUST_CHANGE;
|
| 595 |
+
break;
|
| 596 |
+
default:
|
| 597 |
+
error = ERROR_INVALID_PARAMETER;
|
| 598 |
+
break;
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
freerdp_set_last_error_if_not(rdstls->context, error);
|
| 602 |
+
return FALSE;
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
return TRUE;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
static BOOL rdstls_send(rdpTransport* transport, wStream* s, void* extra)
|
| 609 |
+
{
|
| 610 |
+
rdpRdstls* rdstls = (rdpRdstls*)extra;
|
| 611 |
+
rdpSettings* settings = NULL;
|
| 612 |
+
|
| 613 |
+
WINPR_ASSERT(transport);
|
| 614 |
+
WINPR_ASSERT(s);
|
| 615 |
+
WINPR_ASSERT(rdstls);
|
| 616 |
+
|
| 617 |
+
settings = rdstls->context->settings;
|
| 618 |
+
WINPR_ASSERT(settings);
|
| 619 |
+
|
| 620 |
+
if (!Stream_EnsureRemainingCapacity(s, 2))
|
| 621 |
+
return FALSE;
|
| 622 |
+
|
| 623 |
+
Stream_Write_UINT16(s, RDSTLS_VERSION_1);
|
| 624 |
+
|
| 625 |
+
const RDSTLS_STATE state = rdstls_get_state(rdstls);
|
| 626 |
+
switch (state)
|
| 627 |
+
{
|
| 628 |
+
case RDSTLS_STATE_CAPABILITIES:
|
| 629 |
+
if (!rdstls_write_capabilities(rdstls, s))
|
| 630 |
+
return FALSE;
|
| 631 |
+
break;
|
| 632 |
+
case RDSTLS_STATE_AUTH_REQ:
|
| 633 |
+
if (settings->RedirectionFlags & LB_PASSWORD_IS_PK_ENCRYPTED)
|
| 634 |
+
{
|
| 635 |
+
if (!rdstls_write_authentication_request_with_password(rdstls, s))
|
| 636 |
+
return FALSE;
|
| 637 |
+
}
|
| 638 |
+
else if (settings->ServerAutoReconnectCookie != NULL)
|
| 639 |
+
{
|
| 640 |
+
if (!rdstls_write_authentication_request_with_cookie(rdstls, s))
|
| 641 |
+
return FALSE;
|
| 642 |
+
}
|
| 643 |
+
else
|
| 644 |
+
{
|
| 645 |
+
WLog_Print(rdstls->log, WLOG_ERROR,
|
| 646 |
+
"cannot authenticate with password or auto-reconnect cookie");
|
| 647 |
+
return FALSE;
|
| 648 |
+
}
|
| 649 |
+
break;
|
| 650 |
+
case RDSTLS_STATE_AUTH_RSP:
|
| 651 |
+
if (!rdstls_write_authentication_response(rdstls, s))
|
| 652 |
+
return FALSE;
|
| 653 |
+
break;
|
| 654 |
+
default:
|
| 655 |
+
WLog_Print(rdstls->log, WLOG_ERROR, "Invalid rdstls state %s [%d]",
|
| 656 |
+
rdstls_get_state_str(state), state);
|
| 657 |
+
return FALSE;
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
if (transport_write(rdstls->transport, s) < 0)
|
| 661 |
+
return FALSE;
|
| 662 |
+
|
| 663 |
+
return TRUE;
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
static int rdstls_recv(rdpTransport* transport, wStream* s, void* extra)
|
| 667 |
+
{
|
| 668 |
+
UINT16 version = 0;
|
| 669 |
+
UINT16 pduType = 0;
|
| 670 |
+
rdpRdstls* rdstls = (rdpRdstls*)extra;
|
| 671 |
+
|
| 672 |
+
WINPR_ASSERT(transport);
|
| 673 |
+
WINPR_ASSERT(s);
|
| 674 |
+
WINPR_ASSERT(rdstls);
|
| 675 |
+
|
| 676 |
+
if (Stream_GetRemainingLength(s) < 4)
|
| 677 |
+
return FALSE;
|
| 678 |
+
|
| 679 |
+
Stream_Read_UINT16(s, version);
|
| 680 |
+
if (version != RDSTLS_VERSION_1)
|
| 681 |
+
{
|
| 682 |
+
WLog_Print(rdstls->log, WLOG_ERROR,
|
| 683 |
+
"received invalid RDSTLS Version=0x%04" PRIX16 ", expected 0x%04" PRIX16,
|
| 684 |
+
version, RDSTLS_VERSION_1);
|
| 685 |
+
return -1;
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
Stream_Read_UINT16(s, pduType);
|
| 689 |
+
switch (pduType)
|
| 690 |
+
{
|
| 691 |
+
case RDSTLS_TYPE_CAPABILITIES:
|
| 692 |
+
if (!rdstls_process_capabilities(rdstls, s))
|
| 693 |
+
return -1;
|
| 694 |
+
break;
|
| 695 |
+
case RDSTLS_TYPE_AUTHREQ:
|
| 696 |
+
if (!rdstls_process_authentication_request(rdstls, s))
|
| 697 |
+
return -1;
|
| 698 |
+
break;
|
| 699 |
+
case RDSTLS_TYPE_AUTHRSP:
|
| 700 |
+
if (!rdstls_process_authentication_response(rdstls, s))
|
| 701 |
+
return -1;
|
| 702 |
+
break;
|
| 703 |
+
default:
|
| 704 |
+
WLog_Print(rdstls->log, WLOG_ERROR, "unknown RDSTLS PDU type [0x%04" PRIx16 "]",
|
| 705 |
+
pduType);
|
| 706 |
+
return -1;
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
return 1;
|
| 710 |
+
}
|
| 711 |
+
|
| 712 |
+
#define rdstls_check_state_requirements(rdstls, expected) \
|
| 713 |
+
rdstls_check_state_requirements_((rdstls), (expected), __FILE__, __func__, __LINE__)
|
| 714 |
+
static BOOL rdstls_check_state_requirements_(rdpRdstls* rdstls, RDSTLS_STATE expected,
|
| 715 |
+
const char* file, const char* fkt, size_t line)
|
| 716 |
+
{
|
| 717 |
+
const RDSTLS_STATE current = rdstls_get_state(rdstls);
|
| 718 |
+
if (current == expected)
|
| 719 |
+
return TRUE;
|
| 720 |
+
|
| 721 |
+
const DWORD log_level = WLOG_ERROR;
|
| 722 |
+
if (WLog_IsLevelActive(rdstls->log, log_level))
|
| 723 |
+
WLog_PrintMessage(rdstls->log, WLOG_MESSAGE_TEXT, log_level, line, file, fkt,
|
| 724 |
+
"Unexpected rdstls state %s [%d], expected %s [%d]",
|
| 725 |
+
rdstls_get_state_str(current), current, rdstls_get_state_str(expected),
|
| 726 |
+
expected);
|
| 727 |
+
|
| 728 |
+
return FALSE;
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
static BOOL rdstls_send_capabilities(rdpRdstls* rdstls)
|
| 732 |
+
{
|
| 733 |
+
BOOL rc = FALSE;
|
| 734 |
+
wStream* s = NULL;
|
| 735 |
+
|
| 736 |
+
if (!rdstls_check_state_requirements(rdstls, RDSTLS_STATE_CAPABILITIES))
|
| 737 |
+
goto fail;
|
| 738 |
+
|
| 739 |
+
s = Stream_New(NULL, 512);
|
| 740 |
+
if (!s)
|
| 741 |
+
goto fail;
|
| 742 |
+
|
| 743 |
+
if (!rdstls_send(rdstls->transport, s, rdstls))
|
| 744 |
+
goto fail;
|
| 745 |
+
|
| 746 |
+
rc = rdstls_set_state(rdstls, RDSTLS_STATE_AUTH_REQ);
|
| 747 |
+
fail:
|
| 748 |
+
Stream_Free(s, TRUE);
|
| 749 |
+
return rc;
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
static BOOL rdstls_recv_authentication_request(rdpRdstls* rdstls)
|
| 753 |
+
{
|
| 754 |
+
BOOL rc = FALSE;
|
| 755 |
+
int status = 0;
|
| 756 |
+
wStream* s = NULL;
|
| 757 |
+
|
| 758 |
+
if (!rdstls_check_state_requirements(rdstls, RDSTLS_STATE_AUTH_REQ))
|
| 759 |
+
goto fail;
|
| 760 |
+
|
| 761 |
+
s = Stream_New(NULL, 4096);
|
| 762 |
+
if (!s)
|
| 763 |
+
goto fail;
|
| 764 |
+
|
| 765 |
+
status = transport_read_pdu(rdstls->transport, s);
|
| 766 |
+
|
| 767 |
+
if (status < 0)
|
| 768 |
+
goto fail;
|
| 769 |
+
|
| 770 |
+
status = rdstls_recv(rdstls->transport, s, rdstls);
|
| 771 |
+
|
| 772 |
+
if (status < 0)
|
| 773 |
+
goto fail;
|
| 774 |
+
|
| 775 |
+
rc = rdstls_set_state(rdstls, RDSTLS_STATE_AUTH_RSP);
|
| 776 |
+
fail:
|
| 777 |
+
Stream_Free(s, TRUE);
|
| 778 |
+
return rc;
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
static BOOL rdstls_send_authentication_response(rdpRdstls* rdstls)
|
| 782 |
+
{
|
| 783 |
+
BOOL rc = FALSE;
|
| 784 |
+
wStream* s = NULL;
|
| 785 |
+
|
| 786 |
+
if (!rdstls_check_state_requirements(rdstls, RDSTLS_STATE_AUTH_RSP))
|
| 787 |
+
goto fail;
|
| 788 |
+
|
| 789 |
+
s = Stream_New(NULL, 512);
|
| 790 |
+
if (!s)
|
| 791 |
+
goto fail;
|
| 792 |
+
|
| 793 |
+
if (!rdstls_send(rdstls->transport, s, rdstls))
|
| 794 |
+
goto fail;
|
| 795 |
+
|
| 796 |
+
rc = rdstls_set_state(rdstls, RDSTLS_STATE_FINAL);
|
| 797 |
+
fail:
|
| 798 |
+
Stream_Free(s, TRUE);
|
| 799 |
+
return rc;
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
static BOOL rdstls_recv_capabilities(rdpRdstls* rdstls)
|
| 803 |
+
{
|
| 804 |
+
BOOL rc = FALSE;
|
| 805 |
+
int status = 0;
|
| 806 |
+
wStream* s = NULL;
|
| 807 |
+
|
| 808 |
+
if (!rdstls_check_state_requirements(rdstls, RDSTLS_STATE_CAPABILITIES))
|
| 809 |
+
goto fail;
|
| 810 |
+
|
| 811 |
+
s = Stream_New(NULL, 512);
|
| 812 |
+
if (!s)
|
| 813 |
+
goto fail;
|
| 814 |
+
|
| 815 |
+
status = transport_read_pdu(rdstls->transport, s);
|
| 816 |
+
|
| 817 |
+
if (status < 0)
|
| 818 |
+
goto fail;
|
| 819 |
+
|
| 820 |
+
status = rdstls_recv(rdstls->transport, s, rdstls);
|
| 821 |
+
|
| 822 |
+
if (status < 0)
|
| 823 |
+
goto fail;
|
| 824 |
+
|
| 825 |
+
rc = rdstls_set_state(rdstls, RDSTLS_STATE_AUTH_REQ);
|
| 826 |
+
fail:
|
| 827 |
+
Stream_Free(s, TRUE);
|
| 828 |
+
return rc;
|
| 829 |
+
}
|
| 830 |
+
|
| 831 |
+
static BOOL rdstls_send_authentication_request(rdpRdstls* rdstls)
|
| 832 |
+
{
|
| 833 |
+
BOOL rc = FALSE;
|
| 834 |
+
wStream* s = NULL;
|
| 835 |
+
|
| 836 |
+
if (!rdstls_check_state_requirements(rdstls, RDSTLS_STATE_AUTH_REQ))
|
| 837 |
+
goto fail;
|
| 838 |
+
|
| 839 |
+
s = Stream_New(NULL, 4096);
|
| 840 |
+
if (!s)
|
| 841 |
+
goto fail;
|
| 842 |
+
|
| 843 |
+
if (!rdstls_send(rdstls->transport, s, rdstls))
|
| 844 |
+
goto fail;
|
| 845 |
+
|
| 846 |
+
rc = rdstls_set_state(rdstls, RDSTLS_STATE_AUTH_RSP);
|
| 847 |
+
fail:
|
| 848 |
+
Stream_Free(s, TRUE);
|
| 849 |
+
return rc;
|
| 850 |
+
}
|
| 851 |
+
|
| 852 |
+
static BOOL rdstls_recv_authentication_response(rdpRdstls* rdstls)
|
| 853 |
+
{
|
| 854 |
+
BOOL rc = FALSE;
|
| 855 |
+
int status = 0;
|
| 856 |
+
wStream* s = NULL;
|
| 857 |
+
|
| 858 |
+
WINPR_ASSERT(rdstls);
|
| 859 |
+
|
| 860 |
+
if (!rdstls_check_state_requirements(rdstls, RDSTLS_STATE_AUTH_RSP))
|
| 861 |
+
goto fail;
|
| 862 |
+
|
| 863 |
+
s = Stream_New(NULL, 512);
|
| 864 |
+
if (!s)
|
| 865 |
+
goto fail;
|
| 866 |
+
|
| 867 |
+
status = transport_read_pdu(rdstls->transport, s);
|
| 868 |
+
|
| 869 |
+
if (status < 0)
|
| 870 |
+
goto fail;
|
| 871 |
+
|
| 872 |
+
status = rdstls_recv(rdstls->transport, s, rdstls);
|
| 873 |
+
|
| 874 |
+
if (status < 0)
|
| 875 |
+
goto fail;
|
| 876 |
+
|
| 877 |
+
rc = rdstls_set_state(rdstls, RDSTLS_STATE_FINAL);
|
| 878 |
+
fail:
|
| 879 |
+
Stream_Free(s, TRUE);
|
| 880 |
+
return rc;
|
| 881 |
+
}
|
| 882 |
+
|
| 883 |
+
static int rdstls_server_authenticate(rdpRdstls* rdstls)
|
| 884 |
+
{
|
| 885 |
+
if (!rdstls_set_state(rdstls, RDSTLS_STATE_CAPABILITIES))
|
| 886 |
+
return -1;
|
| 887 |
+
|
| 888 |
+
if (!rdstls_send_capabilities(rdstls))
|
| 889 |
+
return -1;
|
| 890 |
+
|
| 891 |
+
if (!rdstls_recv_authentication_request(rdstls))
|
| 892 |
+
return -1;
|
| 893 |
+
|
| 894 |
+
if (!rdstls_send_authentication_response(rdstls))
|
| 895 |
+
return -1;
|
| 896 |
+
|
| 897 |
+
if (rdstls->resultCode != RDSTLS_RESULT_SUCCESS)
|
| 898 |
+
return -1;
|
| 899 |
+
|
| 900 |
+
return 1;
|
| 901 |
+
}
|
| 902 |
+
|
| 903 |
+
static int rdstls_client_authenticate(rdpRdstls* rdstls)
|
| 904 |
+
{
|
| 905 |
+
if (!rdstls_set_state(rdstls, RDSTLS_STATE_CAPABILITIES))
|
| 906 |
+
return -1;
|
| 907 |
+
|
| 908 |
+
if (!rdstls_recv_capabilities(rdstls))
|
| 909 |
+
return -1;
|
| 910 |
+
|
| 911 |
+
if (!rdstls_send_authentication_request(rdstls))
|
| 912 |
+
return -1;
|
| 913 |
+
|
| 914 |
+
if (!rdstls_recv_authentication_response(rdstls))
|
| 915 |
+
return -1;
|
| 916 |
+
|
| 917 |
+
return 1;
|
| 918 |
+
}
|
| 919 |
+
|
| 920 |
+
/**
|
| 921 |
+
* Authenticate using RDSTLS.
|
| 922 |
+
* @param rdstls The RDSTLS instance to use
|
| 923 |
+
*
|
| 924 |
+
* @return 1 if authentication is successful
|
| 925 |
+
*/
|
| 926 |
+
|
| 927 |
+
int rdstls_authenticate(rdpRdstls* rdstls)
|
| 928 |
+
{
|
| 929 |
+
WINPR_ASSERT(rdstls);
|
| 930 |
+
|
| 931 |
+
if (rdstls->server)
|
| 932 |
+
return rdstls_server_authenticate(rdstls);
|
| 933 |
+
else
|
| 934 |
+
return rdstls_client_authenticate(rdstls);
|
| 935 |
+
}
|
| 936 |
+
|
| 937 |
+
static SSIZE_T rdstls_parse_pdu_data_type(wLog* log, UINT16 dataType, wStream* s)
|
| 938 |
+
{
|
| 939 |
+
size_t pduLength = 0;
|
| 940 |
+
|
| 941 |
+
switch (dataType)
|
| 942 |
+
{
|
| 943 |
+
case RDSTLS_DATA_PASSWORD_CREDS:
|
| 944 |
+
{
|
| 945 |
+
UINT16 redirGuidLength = 0;
|
| 946 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 947 |
+
return 0;
|
| 948 |
+
Stream_Read_UINT16(s, redirGuidLength);
|
| 949 |
+
|
| 950 |
+
if (Stream_GetRemainingLength(s) < redirGuidLength)
|
| 951 |
+
return 0;
|
| 952 |
+
Stream_Seek(s, redirGuidLength);
|
| 953 |
+
|
| 954 |
+
UINT16 usernameLength = 0;
|
| 955 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 956 |
+
return 0;
|
| 957 |
+
Stream_Read_UINT16(s, usernameLength);
|
| 958 |
+
|
| 959 |
+
if (Stream_GetRemainingLength(s) < usernameLength)
|
| 960 |
+
return 0;
|
| 961 |
+
Stream_Seek(s, usernameLength);
|
| 962 |
+
|
| 963 |
+
UINT16 domainLength = 0;
|
| 964 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 965 |
+
return 0;
|
| 966 |
+
Stream_Read_UINT16(s, domainLength);
|
| 967 |
+
|
| 968 |
+
if (Stream_GetRemainingLength(s) < domainLength)
|
| 969 |
+
return 0;
|
| 970 |
+
Stream_Seek(s, domainLength);
|
| 971 |
+
|
| 972 |
+
UINT16 passwordLength = 0;
|
| 973 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 974 |
+
return 0;
|
| 975 |
+
Stream_Read_UINT16(s, passwordLength);
|
| 976 |
+
|
| 977 |
+
pduLength = Stream_GetPosition(s) + passwordLength;
|
| 978 |
+
}
|
| 979 |
+
break;
|
| 980 |
+
case RDSTLS_DATA_AUTORECONNECT_COOKIE:
|
| 981 |
+
{
|
| 982 |
+
if (Stream_GetRemainingLength(s) < 4)
|
| 983 |
+
return 0;
|
| 984 |
+
Stream_Seek(s, 4);
|
| 985 |
+
|
| 986 |
+
UINT16 cookieLength = 0;
|
| 987 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 988 |
+
return 0;
|
| 989 |
+
Stream_Read_UINT16(s, cookieLength);
|
| 990 |
+
|
| 991 |
+
pduLength = Stream_GetPosition(s) + cookieLength;
|
| 992 |
+
}
|
| 993 |
+
break;
|
| 994 |
+
default:
|
| 995 |
+
WLog_Print(log, WLOG_ERROR, "invalid RDSLTS dataType");
|
| 996 |
+
return -1;
|
| 997 |
+
}
|
| 998 |
+
|
| 999 |
+
if (pduLength > SSIZE_MAX)
|
| 1000 |
+
return 0;
|
| 1001 |
+
return (SSIZE_T)pduLength;
|
| 1002 |
+
}
|
| 1003 |
+
|
| 1004 |
+
SSIZE_T rdstls_parse_pdu(wLog* log, wStream* stream)
|
| 1005 |
+
{
|
| 1006 |
+
SSIZE_T pduLength = -1;
|
| 1007 |
+
wStream sbuffer = { 0 };
|
| 1008 |
+
wStream* s = Stream_StaticConstInit(&sbuffer, Stream_Buffer(stream), Stream_Length(stream));
|
| 1009 |
+
|
| 1010 |
+
UINT16 version = 0;
|
| 1011 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 1012 |
+
return 0;
|
| 1013 |
+
Stream_Read_UINT16(s, version);
|
| 1014 |
+
if (version != RDSTLS_VERSION_1)
|
| 1015 |
+
{
|
| 1016 |
+
WLog_Print(log, WLOG_ERROR, "invalid RDSTLS version");
|
| 1017 |
+
return -1;
|
| 1018 |
+
}
|
| 1019 |
+
|
| 1020 |
+
UINT16 pduType = 0;
|
| 1021 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 1022 |
+
return 0;
|
| 1023 |
+
Stream_Read_UINT16(s, pduType);
|
| 1024 |
+
switch (pduType)
|
| 1025 |
+
{
|
| 1026 |
+
case RDSTLS_TYPE_CAPABILITIES:
|
| 1027 |
+
pduLength = 8;
|
| 1028 |
+
break;
|
| 1029 |
+
case RDSTLS_TYPE_AUTHREQ:
|
| 1030 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 1031 |
+
return 0;
|
| 1032 |
+
UINT16 dataType = 0;
|
| 1033 |
+
Stream_Read_UINT16(s, dataType);
|
| 1034 |
+
pduLength = rdstls_parse_pdu_data_type(log, dataType, s);
|
| 1035 |
+
|
| 1036 |
+
break;
|
| 1037 |
+
case RDSTLS_TYPE_AUTHRSP:
|
| 1038 |
+
pduLength = 10;
|
| 1039 |
+
break;
|
| 1040 |
+
default:
|
| 1041 |
+
WLog_Print(log, WLOG_ERROR, "invalid RDSTLS PDU type");
|
| 1042 |
+
return -1;
|
| 1043 |
+
}
|
| 1044 |
+
|
| 1045 |
+
return pduLength;
|
| 1046 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/settings.h
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Internal settings header for functions not exported
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2018 Armin Novak <[email protected]>
|
| 6 |
+
* Copyright 2018 Thincast Technologies GmbH
|
| 7 |
+
*
|
| 8 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
* you may not use this file except in compliance with the License.
|
| 10 |
+
* You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
* See the License for the specific language governing permissions and
|
| 18 |
+
* limitations under the License.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#ifndef FREERDP_LIB_CORE_SETTINGS_H
|
| 22 |
+
#define FREERDP_LIB_CORE_SETTINGS_H
|
| 23 |
+
|
| 24 |
+
#include <winpr/string.h>
|
| 25 |
+
#include <winpr/sspi.h>
|
| 26 |
+
|
| 27 |
+
#include <freerdp/config.h>
|
| 28 |
+
|
| 29 |
+
#define FREERDP_SETTINGS_INTERNAL_USE
|
| 30 |
+
#include <freerdp/settings_types_private.h>
|
| 31 |
+
|
| 32 |
+
#include <freerdp/types.h>
|
| 33 |
+
#include <freerdp/settings.h>
|
| 34 |
+
#include <freerdp/api.h>
|
| 35 |
+
|
| 36 |
+
#include <string.h>
|
| 37 |
+
|
| 38 |
+
FREERDP_LOCAL BOOL freerdp_settings_enforce_monitor_exists(rdpSettings* settings);
|
| 39 |
+
FREERDP_LOCAL void freerdp_settings_print_warnings(const rdpSettings* settings);
|
| 40 |
+
FREERDP_LOCAL BOOL freerdp_settings_check_client_after_preconnect(const rdpSettings* settings);
|
| 41 |
+
FREERDP_LOCAL BOOL freerdp_settings_set_default_order_support(rdpSettings* settings);
|
| 42 |
+
FREERDP_LOCAL BOOL freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src);
|
| 43 |
+
FREERDP_LOCAL void freerdp_settings_free_keys(rdpSettings* dst, BOOL cleanup);
|
| 44 |
+
FREERDP_LOCAL BOOL freerdp_settings_set_string_(rdpSettings* settings,
|
| 45 |
+
FreeRDP_Settings_Keys_String id, const char* val,
|
| 46 |
+
size_t len);
|
| 47 |
+
FREERDP_LOCAL BOOL freerdp_settings_set_string_copy_(rdpSettings* settings,
|
| 48 |
+
FreeRDP_Settings_Keys_String id,
|
| 49 |
+
const char* val, size_t len, BOOL cleanup);
|
| 50 |
+
FREERDP_LOCAL BOOL freerdp_capability_buffer_allocate(rdpSettings* settings, UINT32 count);
|
| 51 |
+
|
| 52 |
+
FREERDP_LOCAL BOOL identity_set_from_settings_with_pwd(SEC_WINNT_AUTH_IDENTITY_W* identity,
|
| 53 |
+
const rdpSettings* settings,
|
| 54 |
+
FreeRDP_Settings_Keys_String UserId,
|
| 55 |
+
FreeRDP_Settings_Keys_String DomainId,
|
| 56 |
+
const WCHAR* Password, size_t pwdLen);
|
| 57 |
+
FREERDP_LOCAL BOOL identity_set_from_settings(SEC_WINNT_AUTH_IDENTITY_W* identity,
|
| 58 |
+
const rdpSettings* settings,
|
| 59 |
+
FreeRDP_Settings_Keys_String UserId,
|
| 60 |
+
FreeRDP_Settings_Keys_String DomainId,
|
| 61 |
+
FreeRDP_Settings_Keys_String PwdId);
|
| 62 |
+
FREERDP_LOCAL BOOL identity_set_from_smartcard_hash(SEC_WINNT_AUTH_IDENTITY_W* identity,
|
| 63 |
+
const rdpSettings* settings,
|
| 64 |
+
FreeRDP_Settings_Keys_String userId,
|
| 65 |
+
FreeRDP_Settings_Keys_String domainId,
|
| 66 |
+
FreeRDP_Settings_Keys_String pwdId,
|
| 67 |
+
const BYTE* certSha1, size_t sha1len);
|
| 68 |
+
FREERDP_LOCAL const char* freerdp_settings_glyph_level_string(UINT32 level, char* buffer,
|
| 69 |
+
size_t size);
|
| 70 |
+
|
| 71 |
+
FREERDP_LOCAL BOOL freerdp_settings_set_pointer_len_(rdpSettings* settings,
|
| 72 |
+
FreeRDP_Settings_Keys_Pointer id,
|
| 73 |
+
FreeRDP_Settings_Keys_UInt32 lenId,
|
| 74 |
+
const void* data, size_t len, size_t size);
|
| 75 |
+
FREERDP_LOCAL BOOL freerdp_target_net_adresses_reset(rdpSettings* settings, size_t size);
|
| 76 |
+
|
| 77 |
+
#endif /* FREERDP_LIB_CORE_SETTINGS_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/simd.h
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* SIMD support detection header
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2024 Armin Novak <[email protected]>
|
| 6 |
+
* Copyright 2024 Thincast Technologies GmbH
|
| 7 |
+
*
|
| 8 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
* you may not use this file except in compliance with the License.
|
| 10 |
+
* You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
* See the License for the specific language governing permissions and
|
| 18 |
+
* limitations under the License.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#pragma once
|
| 22 |
+
|
| 23 |
+
#include <freerdp/config.h>
|
| 24 |
+
|
| 25 |
+
/* https://sourceforge.net/p/predef/wiki/Architectures/
|
| 26 |
+
*
|
| 27 |
+
* contains a list of defined symbols for each compiler
|
| 28 |
+
*/
|
| 29 |
+
#if defined(WITH_SIMD)
|
| 30 |
+
#if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined(_M_IX86_AMD64) || \
|
| 31 |
+
defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || \
|
| 32 |
+
defined(__i686__) || defined(__ia64__)
|
| 33 |
+
#define SSE_AVX_INTRINSICS_ENABLED
|
| 34 |
+
#endif
|
| 35 |
+
|
| 36 |
+
// Inspired by llvm arm_neon.h header checks
|
| 37 |
+
#if defined(__ARM_NEON) && defined(__ARM_FP)
|
| 38 |
+
#define NEON_INTRINSICS_ENABLED
|
| 39 |
+
#endif
|
| 40 |
+
#endif
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/transport.c
ADDED
|
@@ -0,0 +1,2114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include "settings.h"
|
| 23 |
+
|
| 24 |
+
#include <winpr/assert.h>
|
| 25 |
+
|
| 26 |
+
#include <winpr/crt.h>
|
| 27 |
+
#include <winpr/synch.h>
|
| 28 |
+
#include <winpr/print.h>
|
| 29 |
+
#include <winpr/stream.h>
|
| 30 |
+
#include <winpr/winsock.h>
|
| 31 |
+
#include <winpr/crypto.h>
|
| 32 |
+
|
| 33 |
+
#include <freerdp/log.h>
|
| 34 |
+
#include <freerdp/error.h>
|
| 35 |
+
#include <freerdp/utils/ringbuffer.h>
|
| 36 |
+
|
| 37 |
+
#include <openssl/bio.h>
|
| 38 |
+
#include <time.h>
|
| 39 |
+
#include <errno.h>
|
| 40 |
+
#include <fcntl.h>
|
| 41 |
+
|
| 42 |
+
#ifndef _WIN32
|
| 43 |
+
#include <netdb.h>
|
| 44 |
+
#include <sys/socket.h>
|
| 45 |
+
#endif /* _WIN32 */
|
| 46 |
+
|
| 47 |
+
#ifdef FREERDP_HAVE_VALGRIND_MEMCHECK_H
|
| 48 |
+
#include <valgrind/memcheck.h>
|
| 49 |
+
#endif
|
| 50 |
+
|
| 51 |
+
#include "tpkt.h"
|
| 52 |
+
#include "fastpath.h"
|
| 53 |
+
#include "transport.h"
|
| 54 |
+
#include "rdp.h"
|
| 55 |
+
#include "proxy.h"
|
| 56 |
+
#include "utils.h"
|
| 57 |
+
#include "state.h"
|
| 58 |
+
#include "childsession.h"
|
| 59 |
+
|
| 60 |
+
#include "gateway/rdg.h"
|
| 61 |
+
#include "gateway/wst.h"
|
| 62 |
+
#include "gateway/arm.h"
|
| 63 |
+
|
| 64 |
+
#define TAG FREERDP_TAG("core.transport")
|
| 65 |
+
|
| 66 |
+
#define BUFFER_SIZE 16384
|
| 67 |
+
|
| 68 |
+
struct rdp_transport
|
| 69 |
+
{
|
| 70 |
+
TRANSPORT_LAYER layer;
|
| 71 |
+
BIO* frontBio;
|
| 72 |
+
rdpRdg* rdg;
|
| 73 |
+
rdpTsg* tsg;
|
| 74 |
+
rdpWst* wst;
|
| 75 |
+
rdpTls* tls;
|
| 76 |
+
rdpContext* context;
|
| 77 |
+
rdpNla* nla;
|
| 78 |
+
void* ReceiveExtra;
|
| 79 |
+
wStream* ReceiveBuffer;
|
| 80 |
+
TransportRecv ReceiveCallback;
|
| 81 |
+
wStreamPool* ReceivePool;
|
| 82 |
+
HANDLE connectedEvent;
|
| 83 |
+
BOOL NlaMode;
|
| 84 |
+
BOOL RdstlsMode;
|
| 85 |
+
BOOL AadMode;
|
| 86 |
+
BOOL blocking;
|
| 87 |
+
BOOL GatewayEnabled;
|
| 88 |
+
CRITICAL_SECTION ReadLock;
|
| 89 |
+
CRITICAL_SECTION WriteLock;
|
| 90 |
+
ULONG written;
|
| 91 |
+
HANDLE rereadEvent;
|
| 92 |
+
BOOL haveMoreBytesToRead;
|
| 93 |
+
wLog* log;
|
| 94 |
+
rdpTransportIo io;
|
| 95 |
+
HANDLE ioEvent;
|
| 96 |
+
BOOL useIoEvent;
|
| 97 |
+
BOOL earlyUserAuth;
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
static void transport_ssl_cb(const SSL* ssl, int where, int ret)
|
| 101 |
+
{
|
| 102 |
+
if (where & SSL_CB_ALERT)
|
| 103 |
+
{
|
| 104 |
+
rdpTransport* transport = (rdpTransport*)SSL_get_app_data(ssl);
|
| 105 |
+
WINPR_ASSERT(transport);
|
| 106 |
+
|
| 107 |
+
switch (ret)
|
| 108 |
+
{
|
| 109 |
+
case (SSL3_AL_FATAL << 8) | SSL_AD_ACCESS_DENIED:
|
| 110 |
+
{
|
| 111 |
+
if (!freerdp_get_last_error(transport_get_context(transport)))
|
| 112 |
+
{
|
| 113 |
+
WLog_Print(transport->log, WLOG_ERROR, "ACCESS DENIED");
|
| 114 |
+
freerdp_set_last_error_log(transport_get_context(transport),
|
| 115 |
+
FREERDP_ERROR_AUTHENTICATION_FAILED);
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
break;
|
| 119 |
+
|
| 120 |
+
case (SSL3_AL_FATAL << 8) | SSL_AD_INTERNAL_ERROR:
|
| 121 |
+
{
|
| 122 |
+
if (transport->NlaMode)
|
| 123 |
+
{
|
| 124 |
+
if (!freerdp_get_last_error(transport_get_context(transport)))
|
| 125 |
+
{
|
| 126 |
+
UINT32 kret = 0;
|
| 127 |
+
if (transport->nla)
|
| 128 |
+
kret = nla_get_error(transport->nla);
|
| 129 |
+
if (kret == 0)
|
| 130 |
+
kret = FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED;
|
| 131 |
+
freerdp_set_last_error_log(transport_get_context(transport), kret);
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
break;
|
| 136 |
+
|
| 137 |
+
case (SSL3_AL_WARNING << 8) | SSL3_AD_CLOSE_NOTIFY:
|
| 138 |
+
break;
|
| 139 |
+
|
| 140 |
+
default:
|
| 141 |
+
WLog_Print(transport->log, WLOG_WARN,
|
| 142 |
+
"Unhandled SSL error (where=%d, ret=%d [%s, %s])", where, ret,
|
| 143 |
+
SSL_alert_type_string_long(ret), SSL_alert_desc_string_long(ret));
|
| 144 |
+
break;
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
wStream* transport_send_stream_init(rdpTransport* transport, size_t size)
|
| 151 |
+
{
|
| 152 |
+
WINPR_ASSERT(transport);
|
| 153 |
+
|
| 154 |
+
wStream* s = StreamPool_Take(transport->ReceivePool, size);
|
| 155 |
+
if (!s)
|
| 156 |
+
return NULL;
|
| 157 |
+
|
| 158 |
+
if (!Stream_EnsureCapacity(s, size))
|
| 159 |
+
{
|
| 160 |
+
Stream_Release(s);
|
| 161 |
+
return NULL;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
Stream_SetPosition(s, 0);
|
| 165 |
+
return s;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
BOOL transport_attach(rdpTransport* transport, int sockfd)
|
| 169 |
+
{
|
| 170 |
+
if (!transport)
|
| 171 |
+
return FALSE;
|
| 172 |
+
return IFCALLRESULT(FALSE, transport->io.TransportAttach, transport, sockfd);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
static BOOL transport_default_attach(rdpTransport* transport, int sockfd)
|
| 176 |
+
{
|
| 177 |
+
BIO* socketBio = NULL;
|
| 178 |
+
BIO* bufferedBio = NULL;
|
| 179 |
+
const rdpSettings* settings = NULL;
|
| 180 |
+
rdpContext* context = transport_get_context(transport);
|
| 181 |
+
|
| 182 |
+
if (sockfd < 0)
|
| 183 |
+
{
|
| 184 |
+
WLog_WARN(TAG, "Running peer without socket (sockfd=%d)", sockfd);
|
| 185 |
+
return TRUE;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
settings = context->settings;
|
| 189 |
+
WINPR_ASSERT(settings);
|
| 190 |
+
|
| 191 |
+
if (sockfd >= 0)
|
| 192 |
+
{
|
| 193 |
+
if (!freerdp_tcp_set_keep_alive_mode(settings, sockfd))
|
| 194 |
+
goto fail;
|
| 195 |
+
|
| 196 |
+
socketBio = BIO_new(BIO_s_simple_socket());
|
| 197 |
+
|
| 198 |
+
if (!socketBio)
|
| 199 |
+
goto fail;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
bufferedBio = BIO_new(BIO_s_buffered_socket());
|
| 203 |
+
if (!bufferedBio)
|
| 204 |
+
goto fail;
|
| 205 |
+
|
| 206 |
+
if (socketBio)
|
| 207 |
+
{
|
| 208 |
+
bufferedBio = BIO_push(bufferedBio, socketBio);
|
| 209 |
+
if (!bufferedBio)
|
| 210 |
+
goto fail;
|
| 211 |
+
|
| 212 |
+
/* Attach the socket only when this function can no longer fail.
|
| 213 |
+
* This ensures solid ownership:
|
| 214 |
+
* - if this function fails, the caller is responsible to clean up
|
| 215 |
+
* - if this function is successful, the caller MUST NOT close the socket any more.
|
| 216 |
+
*/
|
| 217 |
+
BIO_set_fd(socketBio, sockfd, BIO_CLOSE);
|
| 218 |
+
}
|
| 219 |
+
EnterCriticalSection(&(transport->ReadLock));
|
| 220 |
+
EnterCriticalSection(&(transport->WriteLock));
|
| 221 |
+
transport->frontBio = bufferedBio;
|
| 222 |
+
LeaveCriticalSection(&(transport->WriteLock));
|
| 223 |
+
LeaveCriticalSection(&(transport->ReadLock));
|
| 224 |
+
|
| 225 |
+
return TRUE;
|
| 226 |
+
fail:
|
| 227 |
+
|
| 228 |
+
if (socketBio)
|
| 229 |
+
BIO_free_all(socketBio);
|
| 230 |
+
else
|
| 231 |
+
closesocket((SOCKET)sockfd);
|
| 232 |
+
|
| 233 |
+
return FALSE;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
BOOL transport_connect_rdp(rdpTransport* transport)
|
| 237 |
+
{
|
| 238 |
+
if (!transport)
|
| 239 |
+
return FALSE;
|
| 240 |
+
|
| 241 |
+
switch (utils_authenticate(transport_get_context(transport)->instance, AUTH_RDP, FALSE))
|
| 242 |
+
{
|
| 243 |
+
case AUTH_SKIP:
|
| 244 |
+
case AUTH_SUCCESS:
|
| 245 |
+
case AUTH_NO_CREDENTIALS:
|
| 246 |
+
return TRUE;
|
| 247 |
+
case AUTH_CANCELLED:
|
| 248 |
+
freerdp_set_last_error_if_not(transport_get_context(transport),
|
| 249 |
+
FREERDP_ERROR_CONNECT_CANCELLED);
|
| 250 |
+
return FALSE;
|
| 251 |
+
default:
|
| 252 |
+
return FALSE;
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
BOOL transport_connect_tls(rdpTransport* transport)
|
| 257 |
+
{
|
| 258 |
+
const rdpSettings* settings = NULL;
|
| 259 |
+
rdpContext* context = transport_get_context(transport);
|
| 260 |
+
|
| 261 |
+
settings = context->settings;
|
| 262 |
+
WINPR_ASSERT(settings);
|
| 263 |
+
|
| 264 |
+
/* Only prompt for password if we use TLS (NLA also calls this function) */
|
| 265 |
+
if (settings->SelectedProtocol == PROTOCOL_SSL)
|
| 266 |
+
{
|
| 267 |
+
switch (utils_authenticate(context->instance, AUTH_TLS, FALSE))
|
| 268 |
+
{
|
| 269 |
+
case AUTH_SKIP:
|
| 270 |
+
case AUTH_SUCCESS:
|
| 271 |
+
case AUTH_NO_CREDENTIALS:
|
| 272 |
+
break;
|
| 273 |
+
case AUTH_CANCELLED:
|
| 274 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_CANCELLED);
|
| 275 |
+
return FALSE;
|
| 276 |
+
default:
|
| 277 |
+
return FALSE;
|
| 278 |
+
}
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
return IFCALLRESULT(FALSE, transport->io.TLSConnect, transport);
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
static BOOL transport_default_connect_tls(rdpTransport* transport)
|
| 285 |
+
{
|
| 286 |
+
int tlsStatus = 0;
|
| 287 |
+
rdpTls* tls = NULL;
|
| 288 |
+
rdpContext* context = NULL;
|
| 289 |
+
rdpSettings* settings = NULL;
|
| 290 |
+
|
| 291 |
+
WINPR_ASSERT(transport);
|
| 292 |
+
|
| 293 |
+
context = transport_get_context(transport);
|
| 294 |
+
WINPR_ASSERT(context);
|
| 295 |
+
|
| 296 |
+
settings = context->settings;
|
| 297 |
+
WINPR_ASSERT(settings);
|
| 298 |
+
|
| 299 |
+
if (!(tls = freerdp_tls_new(context)))
|
| 300 |
+
return FALSE;
|
| 301 |
+
|
| 302 |
+
transport->tls = tls;
|
| 303 |
+
|
| 304 |
+
if (transport->GatewayEnabled)
|
| 305 |
+
transport->layer = TRANSPORT_LAYER_TSG_TLS;
|
| 306 |
+
else
|
| 307 |
+
transport->layer = TRANSPORT_LAYER_TLS;
|
| 308 |
+
|
| 309 |
+
tls->hostname = settings->ServerHostname;
|
| 310 |
+
tls->serverName = settings->UserSpecifiedServerName;
|
| 311 |
+
tls->port = WINPR_ASSERTING_INT_CAST(int32_t, MIN(UINT16_MAX, settings->ServerPort));
|
| 312 |
+
|
| 313 |
+
if (tls->port == 0)
|
| 314 |
+
tls->port = 3389;
|
| 315 |
+
|
| 316 |
+
tls->isGatewayTransport = FALSE;
|
| 317 |
+
tlsStatus = freerdp_tls_connect(tls, transport->frontBio);
|
| 318 |
+
|
| 319 |
+
if (tlsStatus < 1)
|
| 320 |
+
{
|
| 321 |
+
if (tlsStatus < 0)
|
| 322 |
+
{
|
| 323 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_TLS_CONNECT_FAILED);
|
| 324 |
+
}
|
| 325 |
+
else
|
| 326 |
+
{
|
| 327 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_CANCELLED);
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
return FALSE;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
transport->frontBio = tls->bio;
|
| 334 |
+
|
| 335 |
+
/* See libfreerdp/crypto/tls.c transport_default_connect_tls
|
| 336 |
+
*
|
| 337 |
+
* we are wrapping a SSL object in the BIO and actually want to set
|
| 338 |
+
*
|
| 339 |
+
* SSL_set_info_callback there. So ensure our callback is of appropriate
|
| 340 |
+
* type for that instead of what the function prototype suggests.
|
| 341 |
+
*/
|
| 342 |
+
typedef void (*ssl_cb_t)(const SSL* ssl, int type, int val);
|
| 343 |
+
ssl_cb_t fkt = transport_ssl_cb;
|
| 344 |
+
|
| 345 |
+
BIO_info_cb* bfkt = WINPR_FUNC_PTR_CAST(fkt, BIO_info_cb*);
|
| 346 |
+
BIO_callback_ctrl(tls->bio, BIO_CTRL_SET_CALLBACK, bfkt);
|
| 347 |
+
SSL_set_app_data(tls->ssl, transport);
|
| 348 |
+
|
| 349 |
+
if (!transport->frontBio)
|
| 350 |
+
{
|
| 351 |
+
WLog_Print(transport->log, WLOG_ERROR, "unable to prepend a filtering TLS bio");
|
| 352 |
+
return FALSE;
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
return TRUE;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
BOOL transport_connect_nla(rdpTransport* transport, BOOL earlyUserAuth)
|
| 359 |
+
{
|
| 360 |
+
rdpContext* context = NULL;
|
| 361 |
+
rdpSettings* settings = NULL;
|
| 362 |
+
rdpRdp* rdp = NULL;
|
| 363 |
+
if (!transport)
|
| 364 |
+
return FALSE;
|
| 365 |
+
|
| 366 |
+
context = transport_get_context(transport);
|
| 367 |
+
WINPR_ASSERT(context);
|
| 368 |
+
|
| 369 |
+
settings = context->settings;
|
| 370 |
+
WINPR_ASSERT(settings);
|
| 371 |
+
|
| 372 |
+
rdp = context->rdp;
|
| 373 |
+
WINPR_ASSERT(rdp);
|
| 374 |
+
|
| 375 |
+
if (!transport_connect_tls(transport))
|
| 376 |
+
return FALSE;
|
| 377 |
+
|
| 378 |
+
if (!settings->Authentication)
|
| 379 |
+
return TRUE;
|
| 380 |
+
|
| 381 |
+
nla_free(rdp->nla);
|
| 382 |
+
rdp->nla = nla_new(context, transport);
|
| 383 |
+
|
| 384 |
+
if (!rdp->nla)
|
| 385 |
+
return FALSE;
|
| 386 |
+
|
| 387 |
+
nla_set_early_user_auth(rdp->nla, earlyUserAuth);
|
| 388 |
+
|
| 389 |
+
transport_set_nla_mode(transport, TRUE);
|
| 390 |
+
|
| 391 |
+
if (settings->AuthenticationServiceClass)
|
| 392 |
+
{
|
| 393 |
+
if (!nla_set_service_principal(rdp->nla, settings->AuthenticationServiceClass,
|
| 394 |
+
freerdp_settings_get_server_name(settings)))
|
| 395 |
+
return FALSE;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
if (nla_client_begin(rdp->nla) < 0)
|
| 399 |
+
{
|
| 400 |
+
WLog_Print(transport->log, WLOG_ERROR, "NLA begin failed");
|
| 401 |
+
|
| 402 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_AUTHENTICATION_FAILED);
|
| 403 |
+
|
| 404 |
+
transport_set_nla_mode(transport, FALSE);
|
| 405 |
+
return FALSE;
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
return rdp_client_transition_to_state(rdp, CONNECTION_STATE_NLA);
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
BOOL transport_connect_rdstls(rdpTransport* transport)
|
| 412 |
+
{
|
| 413 |
+
BOOL rc = FALSE;
|
| 414 |
+
rdpRdstls* rdstls = NULL;
|
| 415 |
+
rdpContext* context = NULL;
|
| 416 |
+
|
| 417 |
+
WINPR_ASSERT(transport);
|
| 418 |
+
|
| 419 |
+
context = transport_get_context(transport);
|
| 420 |
+
WINPR_ASSERT(context);
|
| 421 |
+
|
| 422 |
+
if (!transport_connect_tls(transport))
|
| 423 |
+
goto fail;
|
| 424 |
+
|
| 425 |
+
rdstls = rdstls_new(context, transport);
|
| 426 |
+
if (!rdstls)
|
| 427 |
+
goto fail;
|
| 428 |
+
|
| 429 |
+
transport_set_rdstls_mode(transport, TRUE);
|
| 430 |
+
|
| 431 |
+
if (rdstls_authenticate(rdstls) < 0)
|
| 432 |
+
{
|
| 433 |
+
WLog_Print(transport->log, WLOG_ERROR, "RDSTLS authentication failed");
|
| 434 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_AUTHENTICATION_FAILED);
|
| 435 |
+
goto fail;
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
transport_set_rdstls_mode(transport, FALSE);
|
| 439 |
+
rc = TRUE;
|
| 440 |
+
fail:
|
| 441 |
+
rdstls_free(rdstls);
|
| 442 |
+
return rc;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
BOOL transport_connect_aad(rdpTransport* transport)
|
| 446 |
+
{
|
| 447 |
+
rdpContext* context = NULL;
|
| 448 |
+
rdpSettings* settings = NULL;
|
| 449 |
+
rdpRdp* rdp = NULL;
|
| 450 |
+
if (!transport)
|
| 451 |
+
return FALSE;
|
| 452 |
+
|
| 453 |
+
context = transport_get_context(transport);
|
| 454 |
+
WINPR_ASSERT(context);
|
| 455 |
+
|
| 456 |
+
settings = context->settings;
|
| 457 |
+
WINPR_ASSERT(settings);
|
| 458 |
+
|
| 459 |
+
rdp = context->rdp;
|
| 460 |
+
WINPR_ASSERT(rdp);
|
| 461 |
+
|
| 462 |
+
if (!transport_connect_tls(transport))
|
| 463 |
+
return FALSE;
|
| 464 |
+
|
| 465 |
+
if (!settings->Authentication)
|
| 466 |
+
return TRUE;
|
| 467 |
+
|
| 468 |
+
if (!rdp->aad)
|
| 469 |
+
return FALSE;
|
| 470 |
+
|
| 471 |
+
transport_set_aad_mode(transport, TRUE);
|
| 472 |
+
|
| 473 |
+
if (aad_client_begin(rdp->aad) < 0)
|
| 474 |
+
{
|
| 475 |
+
WLog_Print(transport->log, WLOG_ERROR, "AAD begin failed");
|
| 476 |
+
|
| 477 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_AUTHENTICATION_FAILED);
|
| 478 |
+
|
| 479 |
+
transport_set_aad_mode(transport, FALSE);
|
| 480 |
+
return FALSE;
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
return rdp_client_transition_to_state(rdp, CONNECTION_STATE_AAD);
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port, DWORD timeout)
|
| 487 |
+
{
|
| 488 |
+
BOOL status = FALSE;
|
| 489 |
+
rdpSettings* settings = NULL;
|
| 490 |
+
rdpContext* context = transport_get_context(transport);
|
| 491 |
+
BOOL rpcFallback = 0;
|
| 492 |
+
|
| 493 |
+
WINPR_ASSERT(context);
|
| 494 |
+
WINPR_ASSERT(hostname);
|
| 495 |
+
|
| 496 |
+
settings = context->settings;
|
| 497 |
+
WINPR_ASSERT(settings);
|
| 498 |
+
|
| 499 |
+
rpcFallback = !settings->GatewayHttpTransport;
|
| 500 |
+
|
| 501 |
+
if (transport->GatewayEnabled)
|
| 502 |
+
{
|
| 503 |
+
if (settings->GatewayUrl)
|
| 504 |
+
{
|
| 505 |
+
WINPR_ASSERT(!transport->wst);
|
| 506 |
+
transport->wst = wst_new(context);
|
| 507 |
+
|
| 508 |
+
if (!transport->wst)
|
| 509 |
+
return FALSE;
|
| 510 |
+
|
| 511 |
+
status = wst_connect(transport->wst, timeout);
|
| 512 |
+
|
| 513 |
+
if (status)
|
| 514 |
+
{
|
| 515 |
+
transport->frontBio = wst_get_front_bio_and_take_ownership(transport->wst);
|
| 516 |
+
WINPR_ASSERT(transport->frontBio);
|
| 517 |
+
BIO_set_nonblock(transport->frontBio, 0);
|
| 518 |
+
transport->layer = TRANSPORT_LAYER_TSG;
|
| 519 |
+
status = TRUE;
|
| 520 |
+
}
|
| 521 |
+
else
|
| 522 |
+
{
|
| 523 |
+
wst_free(transport->wst);
|
| 524 |
+
transport->wst = NULL;
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
if (!status && settings->GatewayHttpTransport)
|
| 528 |
+
{
|
| 529 |
+
WINPR_ASSERT(!transport->rdg);
|
| 530 |
+
transport->rdg = rdg_new(context);
|
| 531 |
+
|
| 532 |
+
if (!transport->rdg)
|
| 533 |
+
return FALSE;
|
| 534 |
+
|
| 535 |
+
status = rdg_connect(transport->rdg, timeout, &rpcFallback);
|
| 536 |
+
|
| 537 |
+
if (status)
|
| 538 |
+
{
|
| 539 |
+
transport->frontBio = rdg_get_front_bio_and_take_ownership(transport->rdg);
|
| 540 |
+
WINPR_ASSERT(transport->frontBio);
|
| 541 |
+
BIO_set_nonblock(transport->frontBio, 0);
|
| 542 |
+
transport->layer = TRANSPORT_LAYER_TSG;
|
| 543 |
+
status = TRUE;
|
| 544 |
+
}
|
| 545 |
+
else
|
| 546 |
+
{
|
| 547 |
+
rdg_free(transport->rdg);
|
| 548 |
+
transport->rdg = NULL;
|
| 549 |
+
}
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
if (!status && settings->GatewayRpcTransport && rpcFallback)
|
| 553 |
+
{
|
| 554 |
+
WINPR_ASSERT(!transport->tsg);
|
| 555 |
+
transport->tsg = tsg_new(transport);
|
| 556 |
+
|
| 557 |
+
if (!transport->tsg)
|
| 558 |
+
return FALSE;
|
| 559 |
+
|
| 560 |
+
/* Reset error condition from RDG */
|
| 561 |
+
freerdp_set_last_error_log(context, FREERDP_ERROR_SUCCESS);
|
| 562 |
+
status = tsg_connect(transport->tsg, hostname, port, timeout);
|
| 563 |
+
|
| 564 |
+
if (status)
|
| 565 |
+
{
|
| 566 |
+
transport->frontBio = tsg_get_bio(transport->tsg);
|
| 567 |
+
transport->layer = TRANSPORT_LAYER_TSG;
|
| 568 |
+
status = TRUE;
|
| 569 |
+
}
|
| 570 |
+
else
|
| 571 |
+
{
|
| 572 |
+
tsg_free(transport->tsg);
|
| 573 |
+
transport->tsg = NULL;
|
| 574 |
+
}
|
| 575 |
+
}
|
| 576 |
+
}
|
| 577 |
+
else
|
| 578 |
+
{
|
| 579 |
+
UINT16 peerPort = 0;
|
| 580 |
+
const char* proxyHostname = NULL;
|
| 581 |
+
const char* proxyUsername = NULL;
|
| 582 |
+
const char* proxyPassword = NULL;
|
| 583 |
+
BOOL isProxyConnection =
|
| 584 |
+
proxy_prepare(settings, &proxyHostname, &peerPort, &proxyUsername, &proxyPassword);
|
| 585 |
+
|
| 586 |
+
rdpTransportLayer* layer = NULL;
|
| 587 |
+
if (isProxyConnection)
|
| 588 |
+
layer = transport_connect_layer(transport, proxyHostname, peerPort, timeout);
|
| 589 |
+
else
|
| 590 |
+
layer = transport_connect_layer(transport, hostname, port, timeout);
|
| 591 |
+
|
| 592 |
+
if (!layer)
|
| 593 |
+
return FALSE;
|
| 594 |
+
|
| 595 |
+
if (!transport_attach_layer(transport, layer))
|
| 596 |
+
{
|
| 597 |
+
transport_layer_free(layer);
|
| 598 |
+
return FALSE;
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
if (isProxyConnection)
|
| 602 |
+
{
|
| 603 |
+
if (!proxy_connect(context, transport->frontBio, proxyUsername, proxyPassword, hostname,
|
| 604 |
+
port))
|
| 605 |
+
return FALSE;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
status = TRUE;
|
| 609 |
+
}
|
| 610 |
+
|
| 611 |
+
return status;
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
BOOL transport_connect_childsession(rdpTransport* transport)
|
| 615 |
+
{
|
| 616 |
+
WINPR_ASSERT(transport);
|
| 617 |
+
|
| 618 |
+
transport->frontBio = createChildSessionBio();
|
| 619 |
+
if (!transport->frontBio)
|
| 620 |
+
return FALSE;
|
| 621 |
+
|
| 622 |
+
transport->layer = TRANSPORT_LAYER_TSG;
|
| 623 |
+
return TRUE;
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
BOOL transport_accept_rdp(rdpTransport* transport)
|
| 627 |
+
{
|
| 628 |
+
if (!transport)
|
| 629 |
+
return FALSE;
|
| 630 |
+
/* RDP encryption */
|
| 631 |
+
return TRUE;
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
BOOL transport_accept_tls(rdpTransport* transport)
|
| 635 |
+
{
|
| 636 |
+
if (!transport)
|
| 637 |
+
return FALSE;
|
| 638 |
+
return IFCALLRESULT(FALSE, transport->io.TLSAccept, transport);
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
static BOOL transport_default_accept_tls(rdpTransport* transport)
|
| 642 |
+
{
|
| 643 |
+
rdpContext* context = transport_get_context(transport);
|
| 644 |
+
rdpSettings* settings = NULL;
|
| 645 |
+
|
| 646 |
+
WINPR_ASSERT(context);
|
| 647 |
+
|
| 648 |
+
settings = context->settings;
|
| 649 |
+
WINPR_ASSERT(settings);
|
| 650 |
+
|
| 651 |
+
if (!transport->tls)
|
| 652 |
+
transport->tls = freerdp_tls_new(context);
|
| 653 |
+
|
| 654 |
+
transport->layer = TRANSPORT_LAYER_TLS;
|
| 655 |
+
|
| 656 |
+
if (!freerdp_tls_accept(transport->tls, transport->frontBio, settings))
|
| 657 |
+
return FALSE;
|
| 658 |
+
|
| 659 |
+
transport->frontBio = transport->tls->bio;
|
| 660 |
+
return TRUE;
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
BOOL transport_accept_nla(rdpTransport* transport)
|
| 664 |
+
{
|
| 665 |
+
rdpContext* context = transport_get_context(transport);
|
| 666 |
+
rdpSettings* settings = NULL;
|
| 667 |
+
|
| 668 |
+
WINPR_ASSERT(context);
|
| 669 |
+
|
| 670 |
+
settings = context->settings;
|
| 671 |
+
WINPR_ASSERT(settings);
|
| 672 |
+
|
| 673 |
+
if (!IFCALLRESULT(FALSE, transport->io.TLSAccept, transport))
|
| 674 |
+
return FALSE;
|
| 675 |
+
|
| 676 |
+
/* Network Level Authentication */
|
| 677 |
+
|
| 678 |
+
if (!settings->Authentication)
|
| 679 |
+
return TRUE;
|
| 680 |
+
|
| 681 |
+
if (!transport->nla)
|
| 682 |
+
{
|
| 683 |
+
transport->nla = nla_new(context, transport);
|
| 684 |
+
transport_set_nla_mode(transport, TRUE);
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
if (nla_authenticate(transport->nla) < 0)
|
| 688 |
+
{
|
| 689 |
+
WLog_Print(transport->log, WLOG_ERROR, "client authentication failure");
|
| 690 |
+
transport_set_nla_mode(transport, FALSE);
|
| 691 |
+
nla_free(transport->nla);
|
| 692 |
+
transport->nla = NULL;
|
| 693 |
+
freerdp_tls_set_alert_code(transport->tls, TLS_ALERT_LEVEL_FATAL,
|
| 694 |
+
TLS_ALERT_DESCRIPTION_ACCESS_DENIED);
|
| 695 |
+
freerdp_tls_send_alert(transport->tls);
|
| 696 |
+
return FALSE;
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
/* don't free nla module yet, we need to copy the credentials from it first */
|
| 700 |
+
transport_set_nla_mode(transport, FALSE);
|
| 701 |
+
return TRUE;
|
| 702 |
+
}
|
| 703 |
+
|
| 704 |
+
BOOL transport_accept_rdstls(rdpTransport* transport)
|
| 705 |
+
{
|
| 706 |
+
BOOL rc = FALSE;
|
| 707 |
+
rdpRdstls* rdstls = NULL;
|
| 708 |
+
rdpContext* context = NULL;
|
| 709 |
+
|
| 710 |
+
WINPR_ASSERT(transport);
|
| 711 |
+
|
| 712 |
+
context = transport_get_context(transport);
|
| 713 |
+
WINPR_ASSERT(context);
|
| 714 |
+
|
| 715 |
+
if (!IFCALLRESULT(FALSE, transport->io.TLSAccept, transport))
|
| 716 |
+
goto fail;
|
| 717 |
+
|
| 718 |
+
rdstls = rdstls_new(context, transport);
|
| 719 |
+
if (!rdstls)
|
| 720 |
+
goto fail;
|
| 721 |
+
|
| 722 |
+
transport_set_rdstls_mode(transport, TRUE);
|
| 723 |
+
|
| 724 |
+
if (rdstls_authenticate(rdstls) < 0)
|
| 725 |
+
{
|
| 726 |
+
WLog_Print(transport->log, WLOG_ERROR, "client authentication failure");
|
| 727 |
+
freerdp_tls_set_alert_code(transport->tls, TLS_ALERT_LEVEL_FATAL,
|
| 728 |
+
TLS_ALERT_DESCRIPTION_ACCESS_DENIED);
|
| 729 |
+
freerdp_tls_send_alert(transport->tls);
|
| 730 |
+
goto fail;
|
| 731 |
+
}
|
| 732 |
+
|
| 733 |
+
transport_set_rdstls_mode(transport, FALSE);
|
| 734 |
+
rc = TRUE;
|
| 735 |
+
fail:
|
| 736 |
+
rdstls_free(rdstls);
|
| 737 |
+
return rc;
|
| 738 |
+
}
|
| 739 |
+
|
| 740 |
+
#define WLog_ERR_BIO(transport, biofunc, bio) \
|
| 741 |
+
transport_bio_error_log(transport, biofunc, bio, __FILE__, __func__, __LINE__)
|
| 742 |
+
|
| 743 |
+
static void transport_bio_error_log(rdpTransport* transport, LPCSTR biofunc, BIO* bio, LPCSTR file,
|
| 744 |
+
LPCSTR func, DWORD line)
|
| 745 |
+
{
|
| 746 |
+
unsigned long sslerr = 0;
|
| 747 |
+
int saveerrno = 0;
|
| 748 |
+
DWORD level = 0;
|
| 749 |
+
|
| 750 |
+
WINPR_ASSERT(transport);
|
| 751 |
+
|
| 752 |
+
saveerrno = errno;
|
| 753 |
+
level = WLOG_ERROR;
|
| 754 |
+
|
| 755 |
+
if (level < WLog_GetLogLevel(transport->log))
|
| 756 |
+
return;
|
| 757 |
+
|
| 758 |
+
if (ERR_peek_error() == 0)
|
| 759 |
+
{
|
| 760 |
+
char ebuffer[256] = { 0 };
|
| 761 |
+
const char* fmt = "%s returned a system error %d: %s";
|
| 762 |
+
if (saveerrno == 0)
|
| 763 |
+
fmt = "%s retries exceeded";
|
| 764 |
+
WLog_PrintMessage(transport->log, WLOG_MESSAGE_TEXT, level, line, file, func, fmt, biofunc,
|
| 765 |
+
saveerrno, winpr_strerror(saveerrno, ebuffer, sizeof(ebuffer)));
|
| 766 |
+
return;
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
while ((sslerr = ERR_get_error()))
|
| 770 |
+
{
|
| 771 |
+
char buf[120] = { 0 };
|
| 772 |
+
const char* fmt = "%s returned an error: %s";
|
| 773 |
+
|
| 774 |
+
ERR_error_string_n(sslerr, buf, 120);
|
| 775 |
+
WLog_PrintMessage(transport->log, WLOG_MESSAGE_TEXT, level, line, file, func, fmt, biofunc,
|
| 776 |
+
buf);
|
| 777 |
+
}
|
| 778 |
+
}
|
| 779 |
+
|
| 780 |
+
static SSIZE_T transport_read_layer(rdpTransport* transport, BYTE* data, size_t bytes)
|
| 781 |
+
{
|
| 782 |
+
SSIZE_T read = 0;
|
| 783 |
+
rdpRdp* rdp = NULL;
|
| 784 |
+
rdpContext* context = NULL;
|
| 785 |
+
|
| 786 |
+
WINPR_ASSERT(transport);
|
| 787 |
+
|
| 788 |
+
context = transport_get_context(transport);
|
| 789 |
+
WINPR_ASSERT(context);
|
| 790 |
+
|
| 791 |
+
rdp = context->rdp;
|
| 792 |
+
WINPR_ASSERT(rdp);
|
| 793 |
+
|
| 794 |
+
if (!transport->frontBio || (bytes > SSIZE_MAX))
|
| 795 |
+
{
|
| 796 |
+
transport->layer = TRANSPORT_LAYER_CLOSED;
|
| 797 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
|
| 798 |
+
return -1;
|
| 799 |
+
}
|
| 800 |
+
|
| 801 |
+
while (read < (SSIZE_T)bytes)
|
| 802 |
+
{
|
| 803 |
+
const SSIZE_T tr = (SSIZE_T)bytes - read;
|
| 804 |
+
int r = (int)((tr > INT_MAX) ? INT_MAX : tr);
|
| 805 |
+
ERR_clear_error();
|
| 806 |
+
int status = BIO_read(transport->frontBio, data + read, r);
|
| 807 |
+
|
| 808 |
+
if (freerdp_shall_disconnect_context(context))
|
| 809 |
+
return -1;
|
| 810 |
+
|
| 811 |
+
if (status <= 0)
|
| 812 |
+
{
|
| 813 |
+
if (!transport->frontBio || !BIO_should_retry(transport->frontBio))
|
| 814 |
+
{
|
| 815 |
+
/* something unexpected happened, let's close */
|
| 816 |
+
if (!transport->frontBio)
|
| 817 |
+
{
|
| 818 |
+
WLog_Print(transport->log, WLOG_ERROR, "BIO_read: transport->frontBio null");
|
| 819 |
+
return -1;
|
| 820 |
+
}
|
| 821 |
+
|
| 822 |
+
WLog_ERR_BIO(transport, "BIO_read", transport->frontBio);
|
| 823 |
+
transport->layer = TRANSPORT_LAYER_CLOSED;
|
| 824 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
|
| 825 |
+
return -1;
|
| 826 |
+
}
|
| 827 |
+
|
| 828 |
+
/* non blocking will survive a partial read */
|
| 829 |
+
if (!transport->blocking)
|
| 830 |
+
return read;
|
| 831 |
+
|
| 832 |
+
/* blocking means that we can't continue until we have read the number of requested
|
| 833 |
+
* bytes */
|
| 834 |
+
if (BIO_wait_read(transport->frontBio, 100) < 0)
|
| 835 |
+
{
|
| 836 |
+
WLog_ERR_BIO(transport, "BIO_wait_read", transport->frontBio);
|
| 837 |
+
return -1;
|
| 838 |
+
}
|
| 839 |
+
|
| 840 |
+
continue;
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
#ifdef FREERDP_HAVE_VALGRIND_MEMCHECK_H
|
| 844 |
+
VALGRIND_MAKE_MEM_DEFINED(data + read, bytes - read);
|
| 845 |
+
#endif
|
| 846 |
+
read += status;
|
| 847 |
+
rdp->inBytes += WINPR_ASSERTING_INT_CAST(uint64_t, status);
|
| 848 |
+
}
|
| 849 |
+
|
| 850 |
+
return read;
|
| 851 |
+
}
|
| 852 |
+
|
| 853 |
+
/**
|
| 854 |
+
* @brief Tries to read toRead bytes from the specified transport
|
| 855 |
+
*
|
| 856 |
+
* Try to read toRead bytes from the transport to the stream.
|
| 857 |
+
* In case it was not possible to read toRead bytes 0 is returned. The stream is always advanced by
|
| 858 |
+
* the number of bytes read.
|
| 859 |
+
*
|
| 860 |
+
* The function assumes that the stream has enough capacity to hold the data.
|
| 861 |
+
*
|
| 862 |
+
* @param[in] transport rdpTransport
|
| 863 |
+
* @param[in] s wStream
|
| 864 |
+
* @param[in] toRead number of bytes to read
|
| 865 |
+
* @return < 0 on error; 0 if not enough data is available (non blocking mode); 1 toRead bytes read
|
| 866 |
+
*/
|
| 867 |
+
static SSIZE_T transport_read_layer_bytes(rdpTransport* transport, wStream* s, size_t toRead)
|
| 868 |
+
{
|
| 869 |
+
SSIZE_T status = 0;
|
| 870 |
+
if (!transport)
|
| 871 |
+
return -1;
|
| 872 |
+
|
| 873 |
+
if (toRead > SSIZE_MAX)
|
| 874 |
+
return 0;
|
| 875 |
+
|
| 876 |
+
status = IFCALLRESULT(-1, transport->io.ReadBytes, transport, Stream_Pointer(s), toRead);
|
| 877 |
+
|
| 878 |
+
if (status <= 0)
|
| 879 |
+
return status;
|
| 880 |
+
|
| 881 |
+
Stream_Seek(s, (size_t)status);
|
| 882 |
+
return status == (SSIZE_T)toRead ? 1 : 0;
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
/**
|
| 886 |
+
* @brief Try to read a complete PDU (NLA, fast-path or tpkt) from the underlying transport.
|
| 887 |
+
*
|
| 888 |
+
* If possible a complete PDU is read, in case of non blocking transport this might not succeed.
|
| 889 |
+
* Except in case of an error the passed stream will point to the last byte read (correct
|
| 890 |
+
* position). When the pdu read is completed the stream is sealed and the pointer set to 0
|
| 891 |
+
*
|
| 892 |
+
* @param[in] transport rdpTransport
|
| 893 |
+
* @param[in] s wStream
|
| 894 |
+
* @return < 0 on error; 0 if not enough data is available (non blocking mode); > 0 number of
|
| 895 |
+
* bytes of the *complete* pdu read
|
| 896 |
+
*/
|
| 897 |
+
int transport_read_pdu(rdpTransport* transport, wStream* s)
|
| 898 |
+
{
|
| 899 |
+
if (!transport)
|
| 900 |
+
return -1;
|
| 901 |
+
return IFCALLRESULT(-1, transport->io.ReadPdu, transport, s);
|
| 902 |
+
}
|
| 903 |
+
|
| 904 |
+
static SSIZE_T parse_nla_mode_pdu(rdpTransport* transport, wStream* stream)
|
| 905 |
+
{
|
| 906 |
+
SSIZE_T pduLength = 0;
|
| 907 |
+
wStream sbuffer = { 0 };
|
| 908 |
+
wStream* s = Stream_StaticConstInit(&sbuffer, Stream_Buffer(stream), Stream_Length(stream));
|
| 909 |
+
/*
|
| 910 |
+
* In case NlaMode is set TSRequest package(s) are expected
|
| 911 |
+
* 0x30 = DER encoded data with these bits set:
|
| 912 |
+
* bit 6 P/C constructed
|
| 913 |
+
* bit 5 tag number - sequence
|
| 914 |
+
*/
|
| 915 |
+
UINT8 typeEncoding = 0;
|
| 916 |
+
if (Stream_GetRemainingLength(s) < 1)
|
| 917 |
+
return 0;
|
| 918 |
+
Stream_Read_UINT8(s, typeEncoding);
|
| 919 |
+
if (typeEncoding == 0x30)
|
| 920 |
+
{
|
| 921 |
+
/* TSRequest (NLA) */
|
| 922 |
+
UINT8 lengthEncoding = 0;
|
| 923 |
+
if (Stream_GetRemainingLength(s) < 1)
|
| 924 |
+
return 0;
|
| 925 |
+
Stream_Read_UINT8(s, lengthEncoding);
|
| 926 |
+
if (lengthEncoding & 0x80)
|
| 927 |
+
{
|
| 928 |
+
if ((lengthEncoding & ~(0x80)) == 1)
|
| 929 |
+
{
|
| 930 |
+
UINT8 length = 0;
|
| 931 |
+
if (Stream_GetRemainingLength(s) < 1)
|
| 932 |
+
return 0;
|
| 933 |
+
Stream_Read_UINT8(s, length);
|
| 934 |
+
pduLength = length;
|
| 935 |
+
pduLength += 3;
|
| 936 |
+
}
|
| 937 |
+
else if ((lengthEncoding & ~(0x80)) == 2)
|
| 938 |
+
{
|
| 939 |
+
/* check for header bytes already read in previous calls */
|
| 940 |
+
UINT16 length = 0;
|
| 941 |
+
if (Stream_GetRemainingLength(s) < 2)
|
| 942 |
+
return 0;
|
| 943 |
+
Stream_Read_UINT16_BE(s, length);
|
| 944 |
+
pduLength = length;
|
| 945 |
+
pduLength += 4;
|
| 946 |
+
}
|
| 947 |
+
else
|
| 948 |
+
{
|
| 949 |
+
WLog_Print(transport->log, WLOG_ERROR, "Error reading TSRequest!");
|
| 950 |
+
return -1;
|
| 951 |
+
}
|
| 952 |
+
}
|
| 953 |
+
else
|
| 954 |
+
{
|
| 955 |
+
pduLength = lengthEncoding;
|
| 956 |
+
pduLength += 2;
|
| 957 |
+
}
|
| 958 |
+
}
|
| 959 |
+
|
| 960 |
+
return pduLength;
|
| 961 |
+
}
|
| 962 |
+
|
| 963 |
+
static SSIZE_T parse_default_mode_pdu(rdpTransport* transport, wStream* stream)
|
| 964 |
+
{
|
| 965 |
+
SSIZE_T pduLength = 0;
|
| 966 |
+
wStream sbuffer = { 0 };
|
| 967 |
+
wStream* s = Stream_StaticConstInit(&sbuffer, Stream_Buffer(stream), Stream_Length(stream));
|
| 968 |
+
|
| 969 |
+
UINT8 version = 0;
|
| 970 |
+
if (Stream_GetRemainingLength(s) < 1)
|
| 971 |
+
return 0;
|
| 972 |
+
Stream_Read_UINT8(s, version);
|
| 973 |
+
if (version == 0x03)
|
| 974 |
+
{
|
| 975 |
+
/* TPKT header */
|
| 976 |
+
UINT16 length = 0;
|
| 977 |
+
if (Stream_GetRemainingLength(s) < 3)
|
| 978 |
+
return 0;
|
| 979 |
+
Stream_Seek(s, 1);
|
| 980 |
+
Stream_Read_UINT16_BE(s, length);
|
| 981 |
+
pduLength = length;
|
| 982 |
+
|
| 983 |
+
/* min and max values according to ITU-T Rec. T.123 (01/2007) section 8 */
|
| 984 |
+
if ((pduLength < 7) || (pduLength > 0xFFFF))
|
| 985 |
+
{
|
| 986 |
+
WLog_Print(transport->log, WLOG_ERROR, "tpkt - invalid pduLength: %" PRIdz, pduLength);
|
| 987 |
+
return -1;
|
| 988 |
+
}
|
| 989 |
+
}
|
| 990 |
+
else
|
| 991 |
+
{
|
| 992 |
+
/* Fast-Path Header */
|
| 993 |
+
UINT8 length1 = 0;
|
| 994 |
+
if (Stream_GetRemainingLength(s) < 1)
|
| 995 |
+
return 0;
|
| 996 |
+
Stream_Read_UINT8(s, length1);
|
| 997 |
+
if (length1 & 0x80)
|
| 998 |
+
{
|
| 999 |
+
UINT8 length2 = 0;
|
| 1000 |
+
if (Stream_GetRemainingLength(s) < 1)
|
| 1001 |
+
return 0;
|
| 1002 |
+
Stream_Read_UINT8(s, length2);
|
| 1003 |
+
pduLength = ((length1 & 0x7F) << 8) | length2;
|
| 1004 |
+
}
|
| 1005 |
+
else
|
| 1006 |
+
pduLength = length1;
|
| 1007 |
+
|
| 1008 |
+
/*
|
| 1009 |
+
* fast-path has 7 bits for length so the maximum size, including headers is 0x8000
|
| 1010 |
+
* The theoretical minimum fast-path PDU consists only of two header bytes plus one
|
| 1011 |
+
* byte for data (e.g. fast-path input synchronize pdu)
|
| 1012 |
+
*/
|
| 1013 |
+
if (pduLength < 3 || pduLength > 0x8000)
|
| 1014 |
+
{
|
| 1015 |
+
WLog_Print(transport->log, WLOG_ERROR, "fast path - invalid pduLength: %" PRIdz,
|
| 1016 |
+
pduLength);
|
| 1017 |
+
return -1;
|
| 1018 |
+
}
|
| 1019 |
+
}
|
| 1020 |
+
|
| 1021 |
+
return pduLength;
|
| 1022 |
+
}
|
| 1023 |
+
|
| 1024 |
+
SSIZE_T transport_parse_pdu(rdpTransport* transport, wStream* s, BOOL* incomplete)
|
| 1025 |
+
{
|
| 1026 |
+
SSIZE_T pduLength = 0;
|
| 1027 |
+
|
| 1028 |
+
if (!transport)
|
| 1029 |
+
return -1;
|
| 1030 |
+
|
| 1031 |
+
if (!s)
|
| 1032 |
+
return -1;
|
| 1033 |
+
|
| 1034 |
+
if (incomplete)
|
| 1035 |
+
*incomplete = TRUE;
|
| 1036 |
+
|
| 1037 |
+
Stream_SealLength(s);
|
| 1038 |
+
if (transport->NlaMode)
|
| 1039 |
+
pduLength = parse_nla_mode_pdu(transport, s);
|
| 1040 |
+
else if (transport->RdstlsMode)
|
| 1041 |
+
pduLength = rdstls_parse_pdu(transport->log, s);
|
| 1042 |
+
else
|
| 1043 |
+
pduLength = parse_default_mode_pdu(transport, s);
|
| 1044 |
+
|
| 1045 |
+
if (pduLength <= 0)
|
| 1046 |
+
return pduLength;
|
| 1047 |
+
|
| 1048 |
+
const size_t len = Stream_Length(s);
|
| 1049 |
+
if (len > WINPR_ASSERTING_INT_CAST(size_t, pduLength))
|
| 1050 |
+
return -1;
|
| 1051 |
+
|
| 1052 |
+
if (incomplete)
|
| 1053 |
+
*incomplete = len < WINPR_ASSERTING_INT_CAST(size_t, pduLength);
|
| 1054 |
+
|
| 1055 |
+
return pduLength;
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
static int transport_default_read_pdu(rdpTransport* transport, wStream* s)
|
| 1059 |
+
{
|
| 1060 |
+
BOOL incomplete = 0;
|
| 1061 |
+
SSIZE_T status = 0;
|
| 1062 |
+
size_t pduLength = 0;
|
| 1063 |
+
size_t position = 0;
|
| 1064 |
+
|
| 1065 |
+
WINPR_ASSERT(transport);
|
| 1066 |
+
WINPR_ASSERT(s);
|
| 1067 |
+
|
| 1068 |
+
/* RDS AAD Auth PDUs have no length indicator. We need to determine the end of the PDU by
|
| 1069 |
+
* reading in one byte at a time until we encounter the terminating null byte */
|
| 1070 |
+
if (transport->AadMode)
|
| 1071 |
+
{
|
| 1072 |
+
BYTE c = '\0';
|
| 1073 |
+
do
|
| 1074 |
+
{
|
| 1075 |
+
const SSIZE_T rc = transport_read_layer(transport, &c, 1);
|
| 1076 |
+
if (rc != 1)
|
| 1077 |
+
return (rc == 0) ? 0 : -1;
|
| 1078 |
+
if (!Stream_EnsureRemainingCapacity(s, 1))
|
| 1079 |
+
return -1;
|
| 1080 |
+
Stream_Write_UINT8(s, c);
|
| 1081 |
+
} while (c != '\0');
|
| 1082 |
+
}
|
| 1083 |
+
else if (transport->earlyUserAuth)
|
| 1084 |
+
{
|
| 1085 |
+
if (!Stream_EnsureCapacity(s, 4))
|
| 1086 |
+
return -1;
|
| 1087 |
+
const SSIZE_T rc = transport_read_layer_bytes(transport, s, 4);
|
| 1088 |
+
if (rc != 1)
|
| 1089 |
+
return (rc == 0) ? 0 : -1;
|
| 1090 |
+
}
|
| 1091 |
+
else
|
| 1092 |
+
{
|
| 1093 |
+
/* Read in pdu length */
|
| 1094 |
+
status = transport_parse_pdu(transport, s, &incomplete);
|
| 1095 |
+
while ((status == 0) && incomplete)
|
| 1096 |
+
{
|
| 1097 |
+
if (!Stream_EnsureRemainingCapacity(s, 1))
|
| 1098 |
+
return -1;
|
| 1099 |
+
SSIZE_T rc = transport_read_layer_bytes(transport, s, 1);
|
| 1100 |
+
if (rc > INT32_MAX)
|
| 1101 |
+
return INT32_MAX;
|
| 1102 |
+
if (rc != 1)
|
| 1103 |
+
return (int)rc;
|
| 1104 |
+
status = transport_parse_pdu(transport, s, &incomplete);
|
| 1105 |
+
}
|
| 1106 |
+
|
| 1107 |
+
if (status < 0)
|
| 1108 |
+
return -1;
|
| 1109 |
+
|
| 1110 |
+
pduLength = (size_t)status;
|
| 1111 |
+
|
| 1112 |
+
/* Read in rest of the PDU */
|
| 1113 |
+
if (!Stream_EnsureCapacity(s, pduLength))
|
| 1114 |
+
return -1;
|
| 1115 |
+
|
| 1116 |
+
position = Stream_GetPosition(s);
|
| 1117 |
+
if (position > pduLength)
|
| 1118 |
+
return -1;
|
| 1119 |
+
else if (position < pduLength)
|
| 1120 |
+
{
|
| 1121 |
+
status = transport_read_layer_bytes(transport, s, pduLength - position);
|
| 1122 |
+
if (status != 1)
|
| 1123 |
+
{
|
| 1124 |
+
if ((status < INT32_MIN) || (status > INT32_MAX))
|
| 1125 |
+
return -1;
|
| 1126 |
+
return (int)status;
|
| 1127 |
+
}
|
| 1128 |
+
}
|
| 1129 |
+
|
| 1130 |
+
if (Stream_GetPosition(s) >= pduLength)
|
| 1131 |
+
WLog_Packet(transport->log, WLOG_TRACE, Stream_Buffer(s), pduLength,
|
| 1132 |
+
WLOG_PACKET_INBOUND);
|
| 1133 |
+
}
|
| 1134 |
+
|
| 1135 |
+
Stream_SealLength(s);
|
| 1136 |
+
Stream_SetPosition(s, 0);
|
| 1137 |
+
const size_t len = Stream_Length(s);
|
| 1138 |
+
if (len > INT32_MAX)
|
| 1139 |
+
return -1;
|
| 1140 |
+
return (int)len;
|
| 1141 |
+
}
|
| 1142 |
+
|
| 1143 |
+
int transport_write(rdpTransport* transport, wStream* s)
|
| 1144 |
+
{
|
| 1145 |
+
if (!transport)
|
| 1146 |
+
return -1;
|
| 1147 |
+
|
| 1148 |
+
return IFCALLRESULT(-1, transport->io.WritePdu, transport, s);
|
| 1149 |
+
}
|
| 1150 |
+
|
| 1151 |
+
static int transport_default_write(rdpTransport* transport, wStream* s)
|
| 1152 |
+
{
|
| 1153 |
+
int status = -1;
|
| 1154 |
+
rdpContext* context = transport_get_context(transport);
|
| 1155 |
+
|
| 1156 |
+
WINPR_ASSERT(transport);
|
| 1157 |
+
WINPR_ASSERT(context);
|
| 1158 |
+
|
| 1159 |
+
if (!s)
|
| 1160 |
+
return -1;
|
| 1161 |
+
|
| 1162 |
+
Stream_AddRef(s);
|
| 1163 |
+
|
| 1164 |
+
rdpRdp* rdp = context->rdp;
|
| 1165 |
+
if (!rdp)
|
| 1166 |
+
goto fail;
|
| 1167 |
+
|
| 1168 |
+
EnterCriticalSection(&(transport->WriteLock));
|
| 1169 |
+
if (!transport->frontBio)
|
| 1170 |
+
goto out_cleanup;
|
| 1171 |
+
|
| 1172 |
+
size_t length = Stream_GetPosition(s);
|
| 1173 |
+
size_t writtenlength = length;
|
| 1174 |
+
Stream_SetPosition(s, 0);
|
| 1175 |
+
|
| 1176 |
+
if (length > 0)
|
| 1177 |
+
{
|
| 1178 |
+
rdp->outBytes += length;
|
| 1179 |
+
WLog_Packet(transport->log, WLOG_TRACE, Stream_Buffer(s), length, WLOG_PACKET_OUTBOUND);
|
| 1180 |
+
}
|
| 1181 |
+
|
| 1182 |
+
while (length > 0)
|
| 1183 |
+
{
|
| 1184 |
+
ERR_clear_error();
|
| 1185 |
+
const int towrite = (length > INT32_MAX) ? INT32_MAX : (int)length;
|
| 1186 |
+
status = BIO_write(transport->frontBio, Stream_ConstPointer(s), towrite);
|
| 1187 |
+
|
| 1188 |
+
if (status <= 0)
|
| 1189 |
+
{
|
| 1190 |
+
/* the buffered BIO that is at the end of the chain always says OK for writing,
|
| 1191 |
+
* so a retry means that for any reason we need to read. The most probable
|
| 1192 |
+
* is a SSL or TSG BIO in the chain.
|
| 1193 |
+
*/
|
| 1194 |
+
if (!BIO_should_retry(transport->frontBio))
|
| 1195 |
+
{
|
| 1196 |
+
WLog_ERR_BIO(transport, "BIO_should_retry", transport->frontBio);
|
| 1197 |
+
goto out_cleanup;
|
| 1198 |
+
}
|
| 1199 |
+
|
| 1200 |
+
/* non-blocking can live with blocked IOs */
|
| 1201 |
+
if (!transport->blocking)
|
| 1202 |
+
{
|
| 1203 |
+
WLog_ERR_BIO(transport, "BIO_write", transport->frontBio);
|
| 1204 |
+
goto out_cleanup;
|
| 1205 |
+
}
|
| 1206 |
+
|
| 1207 |
+
if (BIO_wait_write(transport->frontBio, 100) < 0)
|
| 1208 |
+
{
|
| 1209 |
+
WLog_ERR_BIO(transport, "BIO_wait_write", transport->frontBio);
|
| 1210 |
+
status = -1;
|
| 1211 |
+
goto out_cleanup;
|
| 1212 |
+
}
|
| 1213 |
+
|
| 1214 |
+
continue;
|
| 1215 |
+
}
|
| 1216 |
+
|
| 1217 |
+
WINPR_ASSERT(context->settings);
|
| 1218 |
+
if (transport->blocking || context->settings->WaitForOutputBufferFlush)
|
| 1219 |
+
{
|
| 1220 |
+
while (BIO_write_blocked(transport->frontBio))
|
| 1221 |
+
{
|
| 1222 |
+
if (BIO_wait_write(transport->frontBio, 100) < 0)
|
| 1223 |
+
{
|
| 1224 |
+
WLog_Print(transport->log, WLOG_ERROR, "error when selecting for write");
|
| 1225 |
+
status = -1;
|
| 1226 |
+
goto out_cleanup;
|
| 1227 |
+
}
|
| 1228 |
+
|
| 1229 |
+
if (BIO_flush(transport->frontBio) < 1)
|
| 1230 |
+
{
|
| 1231 |
+
WLog_Print(transport->log, WLOG_ERROR, "error when flushing outputBuffer");
|
| 1232 |
+
status = -1;
|
| 1233 |
+
goto out_cleanup;
|
| 1234 |
+
}
|
| 1235 |
+
}
|
| 1236 |
+
}
|
| 1237 |
+
|
| 1238 |
+
length -= (size_t)status;
|
| 1239 |
+
Stream_Seek(s, (size_t)status);
|
| 1240 |
+
}
|
| 1241 |
+
|
| 1242 |
+
transport->written += writtenlength;
|
| 1243 |
+
out_cleanup:
|
| 1244 |
+
|
| 1245 |
+
if (status < 0)
|
| 1246 |
+
{
|
| 1247 |
+
/* A write error indicates that the peer has dropped the connection */
|
| 1248 |
+
transport->layer = TRANSPORT_LAYER_CLOSED;
|
| 1249 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
|
| 1250 |
+
}
|
| 1251 |
+
|
| 1252 |
+
LeaveCriticalSection(&(transport->WriteLock));
|
| 1253 |
+
fail:
|
| 1254 |
+
Stream_Release(s);
|
| 1255 |
+
return status;
|
| 1256 |
+
}
|
| 1257 |
+
|
| 1258 |
+
BOOL transport_get_public_key(rdpTransport* transport, const BYTE** data, DWORD* length)
|
| 1259 |
+
{
|
| 1260 |
+
return IFCALLRESULT(FALSE, transport->io.GetPublicKey, transport, data, length);
|
| 1261 |
+
}
|
| 1262 |
+
|
| 1263 |
+
static BOOL transport_default_get_public_key(rdpTransport* transport, const BYTE** data,
|
| 1264 |
+
DWORD* length)
|
| 1265 |
+
{
|
| 1266 |
+
rdpTls* tls = transport_get_tls(transport);
|
| 1267 |
+
if (!tls)
|
| 1268 |
+
return FALSE;
|
| 1269 |
+
|
| 1270 |
+
*data = tls->PublicKey;
|
| 1271 |
+
*length = tls->PublicKeyLength;
|
| 1272 |
+
|
| 1273 |
+
return TRUE;
|
| 1274 |
+
}
|
| 1275 |
+
|
| 1276 |
+
DWORD transport_get_event_handles(rdpTransport* transport, HANDLE* events, DWORD count)
|
| 1277 |
+
{
|
| 1278 |
+
DWORD nCount = 0; /* always the reread Event */
|
| 1279 |
+
|
| 1280 |
+
WINPR_ASSERT(transport);
|
| 1281 |
+
WINPR_ASSERT(events);
|
| 1282 |
+
WINPR_ASSERT(count > 0);
|
| 1283 |
+
|
| 1284 |
+
if (events)
|
| 1285 |
+
{
|
| 1286 |
+
if (count < 1)
|
| 1287 |
+
{
|
| 1288 |
+
WLog_Print(transport->log, WLOG_ERROR, "provided handles array is too small");
|
| 1289 |
+
return 0;
|
| 1290 |
+
}
|
| 1291 |
+
|
| 1292 |
+
events[nCount++] = transport->rereadEvent;
|
| 1293 |
+
|
| 1294 |
+
if (transport->useIoEvent)
|
| 1295 |
+
{
|
| 1296 |
+
if (count < 2)
|
| 1297 |
+
return 0;
|
| 1298 |
+
events[nCount++] = transport->ioEvent;
|
| 1299 |
+
}
|
| 1300 |
+
}
|
| 1301 |
+
|
| 1302 |
+
if (!transport->GatewayEnabled)
|
| 1303 |
+
{
|
| 1304 |
+
if (events)
|
| 1305 |
+
{
|
| 1306 |
+
if (nCount >= count)
|
| 1307 |
+
{
|
| 1308 |
+
WLog_Print(transport->log, WLOG_ERROR,
|
| 1309 |
+
"provided handles array is too small (count=%" PRIu32 " nCount=%" PRIu32
|
| 1310 |
+
")",
|
| 1311 |
+
count, nCount);
|
| 1312 |
+
return 0;
|
| 1313 |
+
}
|
| 1314 |
+
|
| 1315 |
+
if (transport->frontBio)
|
| 1316 |
+
{
|
| 1317 |
+
if (BIO_get_event(transport->frontBio, &events[nCount]) != 1)
|
| 1318 |
+
{
|
| 1319 |
+
WLog_Print(transport->log, WLOG_ERROR, "error getting the frontBio handle");
|
| 1320 |
+
return 0;
|
| 1321 |
+
}
|
| 1322 |
+
nCount++;
|
| 1323 |
+
}
|
| 1324 |
+
}
|
| 1325 |
+
}
|
| 1326 |
+
else
|
| 1327 |
+
{
|
| 1328 |
+
if (transport->rdg)
|
| 1329 |
+
{
|
| 1330 |
+
const DWORD tmp =
|
| 1331 |
+
rdg_get_event_handles(transport->rdg, &events[nCount], count - nCount);
|
| 1332 |
+
|
| 1333 |
+
if (tmp == 0)
|
| 1334 |
+
return 0;
|
| 1335 |
+
|
| 1336 |
+
nCount += tmp;
|
| 1337 |
+
}
|
| 1338 |
+
else if (transport->tsg)
|
| 1339 |
+
{
|
| 1340 |
+
const DWORD tmp =
|
| 1341 |
+
tsg_get_event_handles(transport->tsg, &events[nCount], count - nCount);
|
| 1342 |
+
|
| 1343 |
+
if (tmp == 0)
|
| 1344 |
+
return 0;
|
| 1345 |
+
|
| 1346 |
+
nCount += tmp;
|
| 1347 |
+
}
|
| 1348 |
+
else if (transport->wst)
|
| 1349 |
+
{
|
| 1350 |
+
const DWORD tmp =
|
| 1351 |
+
wst_get_event_handles(transport->wst, &events[nCount], count - nCount);
|
| 1352 |
+
|
| 1353 |
+
if (tmp == 0)
|
| 1354 |
+
return 0;
|
| 1355 |
+
|
| 1356 |
+
nCount += tmp;
|
| 1357 |
+
}
|
| 1358 |
+
}
|
| 1359 |
+
|
| 1360 |
+
return nCount;
|
| 1361 |
+
}
|
| 1362 |
+
|
| 1363 |
+
#if defined(WITH_FREERDP_DEPRECATED)
|
| 1364 |
+
void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount)
|
| 1365 |
+
{
|
| 1366 |
+
DWORD nCount = 0;
|
| 1367 |
+
HANDLE events[MAXIMUM_WAIT_OBJECTS] = { 0 };
|
| 1368 |
+
|
| 1369 |
+
WINPR_ASSERT(transport);
|
| 1370 |
+
WINPR_ASSERT(rfds);
|
| 1371 |
+
WINPR_ASSERT(rcount);
|
| 1372 |
+
|
| 1373 |
+
nCount = transport_get_event_handles(transport, events, ARRAYSIZE(events));
|
| 1374 |
+
*rcount = nCount + 1;
|
| 1375 |
+
|
| 1376 |
+
for (DWORD index = 0; index < nCount; index++)
|
| 1377 |
+
{
|
| 1378 |
+
rfds[index] = GetEventWaitObject(events[index]);
|
| 1379 |
+
}
|
| 1380 |
+
|
| 1381 |
+
rfds[nCount] = GetEventWaitObject(transport->rereadEvent);
|
| 1382 |
+
}
|
| 1383 |
+
#endif
|
| 1384 |
+
|
| 1385 |
+
BOOL transport_is_write_blocked(rdpTransport* transport)
|
| 1386 |
+
{
|
| 1387 |
+
WINPR_ASSERT(transport);
|
| 1388 |
+
WINPR_ASSERT(transport->frontBio);
|
| 1389 |
+
return BIO_write_blocked(transport->frontBio) != 0;
|
| 1390 |
+
}
|
| 1391 |
+
|
| 1392 |
+
int transport_drain_output_buffer(rdpTransport* transport)
|
| 1393 |
+
{
|
| 1394 |
+
BOOL status = FALSE;
|
| 1395 |
+
|
| 1396 |
+
WINPR_ASSERT(transport);
|
| 1397 |
+
WINPR_ASSERT(transport->frontBio);
|
| 1398 |
+
if (BIO_write_blocked(transport->frontBio))
|
| 1399 |
+
{
|
| 1400 |
+
if (BIO_flush(transport->frontBio) < 1)
|
| 1401 |
+
return -1;
|
| 1402 |
+
|
| 1403 |
+
const long rc = BIO_write_blocked(transport->frontBio);
|
| 1404 |
+
status = (rc != 0);
|
| 1405 |
+
}
|
| 1406 |
+
|
| 1407 |
+
return status;
|
| 1408 |
+
}
|
| 1409 |
+
|
| 1410 |
+
int transport_check_fds(rdpTransport* transport)
|
| 1411 |
+
{
|
| 1412 |
+
int status = 0;
|
| 1413 |
+
state_run_t recv_status = STATE_RUN_FAILED;
|
| 1414 |
+
wStream* received = NULL;
|
| 1415 |
+
rdpContext* context = transport_get_context(transport);
|
| 1416 |
+
|
| 1417 |
+
WINPR_ASSERT(context);
|
| 1418 |
+
|
| 1419 |
+
if (transport->layer == TRANSPORT_LAYER_CLOSED)
|
| 1420 |
+
{
|
| 1421 |
+
WLog_Print(transport->log, WLOG_DEBUG, "transport_check_fds: transport layer closed");
|
| 1422 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
|
| 1423 |
+
return -1;
|
| 1424 |
+
}
|
| 1425 |
+
|
| 1426 |
+
/**
|
| 1427 |
+
* Note: transport_read_pdu tries to read one PDU from
|
| 1428 |
+
* the transport layer.
|
| 1429 |
+
* The ReceiveBuffer might have a position > 0 in case of a non blocking
|
| 1430 |
+
* transport. If transport_read_pdu returns 0 the pdu couldn't be read at
|
| 1431 |
+
* this point.
|
| 1432 |
+
* Note that transport->ReceiveBuffer is replaced after each iteration
|
| 1433 |
+
* of this loop with a fresh stream instance from a pool.
|
| 1434 |
+
*/
|
| 1435 |
+
if ((status = transport_read_pdu(transport, transport->ReceiveBuffer)) <= 0)
|
| 1436 |
+
{
|
| 1437 |
+
if (status < 0)
|
| 1438 |
+
WLog_Print(transport->log, WLOG_DEBUG, "transport_check_fds: transport_read_pdu() - %i",
|
| 1439 |
+
status);
|
| 1440 |
+
if (transport->haveMoreBytesToRead)
|
| 1441 |
+
{
|
| 1442 |
+
transport->haveMoreBytesToRead = FALSE;
|
| 1443 |
+
(void)ResetEvent(transport->rereadEvent);
|
| 1444 |
+
}
|
| 1445 |
+
return status;
|
| 1446 |
+
}
|
| 1447 |
+
|
| 1448 |
+
received = transport->ReceiveBuffer;
|
| 1449 |
+
|
| 1450 |
+
if (!(transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0)))
|
| 1451 |
+
return -1;
|
| 1452 |
+
|
| 1453 |
+
/**
|
| 1454 |
+
* status:
|
| 1455 |
+
* -1: error
|
| 1456 |
+
* 0: success
|
| 1457 |
+
* 1: redirection
|
| 1458 |
+
*/
|
| 1459 |
+
WINPR_ASSERT(transport->ReceiveCallback);
|
| 1460 |
+
recv_status = transport->ReceiveCallback(transport, received, transport->ReceiveExtra);
|
| 1461 |
+
Stream_Release(received);
|
| 1462 |
+
|
| 1463 |
+
if (state_run_failed(recv_status))
|
| 1464 |
+
{
|
| 1465 |
+
char buffer[64] = { 0 };
|
| 1466 |
+
WLog_Print(transport->log, WLOG_ERROR,
|
| 1467 |
+
"transport_check_fds: transport->ReceiveCallback() - %s",
|
| 1468 |
+
state_run_result_string(recv_status, buffer, ARRAYSIZE(buffer)));
|
| 1469 |
+
return -1;
|
| 1470 |
+
}
|
| 1471 |
+
|
| 1472 |
+
/* Run this again to be sure we consumed all input data.
|
| 1473 |
+
* This will be repeated until a (not fully) received packet is in buffer
|
| 1474 |
+
*/
|
| 1475 |
+
if (!transport->haveMoreBytesToRead)
|
| 1476 |
+
{
|
| 1477 |
+
transport->haveMoreBytesToRead = TRUE;
|
| 1478 |
+
(void)SetEvent(transport->rereadEvent);
|
| 1479 |
+
}
|
| 1480 |
+
return recv_status;
|
| 1481 |
+
}
|
| 1482 |
+
|
| 1483 |
+
BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking)
|
| 1484 |
+
{
|
| 1485 |
+
WINPR_ASSERT(transport);
|
| 1486 |
+
|
| 1487 |
+
return IFCALLRESULT(FALSE, transport->io.SetBlockingMode, transport, blocking);
|
| 1488 |
+
}
|
| 1489 |
+
|
| 1490 |
+
static BOOL transport_default_set_blocking_mode(rdpTransport* transport, BOOL blocking)
|
| 1491 |
+
{
|
| 1492 |
+
WINPR_ASSERT(transport);
|
| 1493 |
+
|
| 1494 |
+
transport->blocking = blocking;
|
| 1495 |
+
|
| 1496 |
+
if (transport->frontBio)
|
| 1497 |
+
{
|
| 1498 |
+
if (!BIO_set_nonblock(transport->frontBio, blocking ? FALSE : TRUE))
|
| 1499 |
+
return FALSE;
|
| 1500 |
+
}
|
| 1501 |
+
|
| 1502 |
+
return TRUE;
|
| 1503 |
+
}
|
| 1504 |
+
|
| 1505 |
+
rdpTransportLayer* transport_connect_layer(rdpTransport* transport, const char* hostname, int port,
|
| 1506 |
+
DWORD timeout)
|
| 1507 |
+
{
|
| 1508 |
+
WINPR_ASSERT(transport);
|
| 1509 |
+
|
| 1510 |
+
return IFCALLRESULT(NULL, transport->io.ConnectLayer, transport, hostname, port, timeout);
|
| 1511 |
+
}
|
| 1512 |
+
|
| 1513 |
+
static rdpTransportLayer* transport_default_connect_layer(rdpTransport* transport,
|
| 1514 |
+
const char* hostname, int port,
|
| 1515 |
+
DWORD timeout)
|
| 1516 |
+
{
|
| 1517 |
+
rdpContext* context = transport_get_context(transport);
|
| 1518 |
+
WINPR_ASSERT(context);
|
| 1519 |
+
|
| 1520 |
+
return freerdp_tcp_connect_layer(context, hostname, port, timeout);
|
| 1521 |
+
}
|
| 1522 |
+
|
| 1523 |
+
BOOL transport_attach_layer(rdpTransport* transport, rdpTransportLayer* layer)
|
| 1524 |
+
{
|
| 1525 |
+
WINPR_ASSERT(transport);
|
| 1526 |
+
WINPR_ASSERT(layer);
|
| 1527 |
+
|
| 1528 |
+
return IFCALLRESULT(FALSE, transport->io.AttachLayer, transport, layer);
|
| 1529 |
+
}
|
| 1530 |
+
|
| 1531 |
+
static BOOL transport_default_attach_layer(rdpTransport* transport, rdpTransportLayer* layer)
|
| 1532 |
+
{
|
| 1533 |
+
BIO* layerBio = BIO_new(BIO_s_transport_layer());
|
| 1534 |
+
if (!layerBio)
|
| 1535 |
+
goto fail;
|
| 1536 |
+
|
| 1537 |
+
BIO* bufferedBio = BIO_new(BIO_s_buffered_socket());
|
| 1538 |
+
if (!bufferedBio)
|
| 1539 |
+
goto fail;
|
| 1540 |
+
|
| 1541 |
+
bufferedBio = BIO_push(bufferedBio, layerBio);
|
| 1542 |
+
if (!bufferedBio)
|
| 1543 |
+
goto fail;
|
| 1544 |
+
|
| 1545 |
+
/* BIO takes over the layer reference at this point. */
|
| 1546 |
+
BIO_set_data(layerBio, layer);
|
| 1547 |
+
|
| 1548 |
+
transport->frontBio = bufferedBio;
|
| 1549 |
+
|
| 1550 |
+
return TRUE;
|
| 1551 |
+
|
| 1552 |
+
fail:
|
| 1553 |
+
if (layerBio)
|
| 1554 |
+
BIO_free_all(layerBio);
|
| 1555 |
+
|
| 1556 |
+
return FALSE;
|
| 1557 |
+
}
|
| 1558 |
+
|
| 1559 |
+
void transport_set_gateway_enabled(rdpTransport* transport, BOOL GatewayEnabled)
|
| 1560 |
+
{
|
| 1561 |
+
WINPR_ASSERT(transport);
|
| 1562 |
+
transport->GatewayEnabled = GatewayEnabled;
|
| 1563 |
+
}
|
| 1564 |
+
|
| 1565 |
+
void transport_set_nla_mode(rdpTransport* transport, BOOL NlaMode)
|
| 1566 |
+
{
|
| 1567 |
+
WINPR_ASSERT(transport);
|
| 1568 |
+
transport->NlaMode = NlaMode;
|
| 1569 |
+
}
|
| 1570 |
+
|
| 1571 |
+
void transport_set_rdstls_mode(rdpTransport* transport, BOOL RdstlsMode)
|
| 1572 |
+
{
|
| 1573 |
+
WINPR_ASSERT(transport);
|
| 1574 |
+
transport->RdstlsMode = RdstlsMode;
|
| 1575 |
+
}
|
| 1576 |
+
|
| 1577 |
+
void transport_set_aad_mode(rdpTransport* transport, BOOL AadMode)
|
| 1578 |
+
{
|
| 1579 |
+
WINPR_ASSERT(transport);
|
| 1580 |
+
transport->AadMode = AadMode;
|
| 1581 |
+
}
|
| 1582 |
+
|
| 1583 |
+
BOOL transport_disconnect(rdpTransport* transport)
|
| 1584 |
+
{
|
| 1585 |
+
if (!transport)
|
| 1586 |
+
return FALSE;
|
| 1587 |
+
return IFCALLRESULT(FALSE, transport->io.TransportDisconnect, transport);
|
| 1588 |
+
}
|
| 1589 |
+
|
| 1590 |
+
static BOOL transport_default_disconnect(rdpTransport* transport)
|
| 1591 |
+
{
|
| 1592 |
+
BOOL status = TRUE;
|
| 1593 |
+
|
| 1594 |
+
if (!transport)
|
| 1595 |
+
return FALSE;
|
| 1596 |
+
|
| 1597 |
+
EnterCriticalSection(&(transport->ReadLock));
|
| 1598 |
+
EnterCriticalSection(&(transport->WriteLock));
|
| 1599 |
+
if (transport->tls)
|
| 1600 |
+
{
|
| 1601 |
+
freerdp_tls_free(transport->tls);
|
| 1602 |
+
transport->tls = NULL;
|
| 1603 |
+
}
|
| 1604 |
+
else
|
| 1605 |
+
{
|
| 1606 |
+
if (transport->frontBio)
|
| 1607 |
+
BIO_free_all(transport->frontBio);
|
| 1608 |
+
}
|
| 1609 |
+
|
| 1610 |
+
if (transport->tsg)
|
| 1611 |
+
{
|
| 1612 |
+
tsg_free(transport->tsg);
|
| 1613 |
+
transport->tsg = NULL;
|
| 1614 |
+
}
|
| 1615 |
+
|
| 1616 |
+
if (transport->rdg)
|
| 1617 |
+
{
|
| 1618 |
+
rdg_free(transport->rdg);
|
| 1619 |
+
transport->rdg = NULL;
|
| 1620 |
+
}
|
| 1621 |
+
|
| 1622 |
+
if (transport->wst)
|
| 1623 |
+
{
|
| 1624 |
+
wst_free(transport->wst);
|
| 1625 |
+
transport->wst = NULL;
|
| 1626 |
+
}
|
| 1627 |
+
|
| 1628 |
+
transport->frontBio = NULL;
|
| 1629 |
+
transport->layer = TRANSPORT_LAYER_TCP;
|
| 1630 |
+
transport->earlyUserAuth = FALSE;
|
| 1631 |
+
LeaveCriticalSection(&(transport->WriteLock));
|
| 1632 |
+
LeaveCriticalSection(&(transport->ReadLock));
|
| 1633 |
+
return status;
|
| 1634 |
+
}
|
| 1635 |
+
|
| 1636 |
+
rdpTransport* transport_new(rdpContext* context)
|
| 1637 |
+
{
|
| 1638 |
+
rdpTransport* transport = (rdpTransport*)calloc(1, sizeof(rdpTransport));
|
| 1639 |
+
|
| 1640 |
+
WINPR_ASSERT(context);
|
| 1641 |
+
if (!transport)
|
| 1642 |
+
return NULL;
|
| 1643 |
+
|
| 1644 |
+
transport->log = WLog_Get(TAG);
|
| 1645 |
+
|
| 1646 |
+
if (!transport->log)
|
| 1647 |
+
goto fail;
|
| 1648 |
+
|
| 1649 |
+
// transport->io.DataHandler = transport_data_handler;
|
| 1650 |
+
transport->io.TCPConnect = freerdp_tcp_default_connect;
|
| 1651 |
+
transport->io.TLSConnect = transport_default_connect_tls;
|
| 1652 |
+
transport->io.TLSAccept = transport_default_accept_tls;
|
| 1653 |
+
transport->io.TransportAttach = transport_default_attach;
|
| 1654 |
+
transport->io.TransportDisconnect = transport_default_disconnect;
|
| 1655 |
+
transport->io.ReadPdu = transport_default_read_pdu;
|
| 1656 |
+
transport->io.WritePdu = transport_default_write;
|
| 1657 |
+
transport->io.ReadBytes = transport_read_layer;
|
| 1658 |
+
transport->io.GetPublicKey = transport_default_get_public_key;
|
| 1659 |
+
transport->io.SetBlockingMode = transport_default_set_blocking_mode;
|
| 1660 |
+
transport->io.ConnectLayer = transport_default_connect_layer;
|
| 1661 |
+
transport->io.AttachLayer = transport_default_attach_layer;
|
| 1662 |
+
|
| 1663 |
+
transport->context = context;
|
| 1664 |
+
transport->ReceivePool = StreamPool_New(TRUE, BUFFER_SIZE);
|
| 1665 |
+
|
| 1666 |
+
if (!transport->ReceivePool)
|
| 1667 |
+
goto fail;
|
| 1668 |
+
|
| 1669 |
+
/* receive buffer for non-blocking read. */
|
| 1670 |
+
transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0);
|
| 1671 |
+
|
| 1672 |
+
if (!transport->ReceiveBuffer)
|
| 1673 |
+
goto fail;
|
| 1674 |
+
|
| 1675 |
+
transport->connectedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
| 1676 |
+
|
| 1677 |
+
if (!transport->connectedEvent || transport->connectedEvent == INVALID_HANDLE_VALUE)
|
| 1678 |
+
goto fail;
|
| 1679 |
+
|
| 1680 |
+
transport->rereadEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
| 1681 |
+
|
| 1682 |
+
if (!transport->rereadEvent || transport->rereadEvent == INVALID_HANDLE_VALUE)
|
| 1683 |
+
goto fail;
|
| 1684 |
+
|
| 1685 |
+
transport->ioEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
| 1686 |
+
|
| 1687 |
+
if (!transport->ioEvent || transport->ioEvent == INVALID_HANDLE_VALUE)
|
| 1688 |
+
goto fail;
|
| 1689 |
+
|
| 1690 |
+
transport->haveMoreBytesToRead = FALSE;
|
| 1691 |
+
transport->blocking = TRUE;
|
| 1692 |
+
transport->GatewayEnabled = FALSE;
|
| 1693 |
+
transport->layer = TRANSPORT_LAYER_TCP;
|
| 1694 |
+
|
| 1695 |
+
if (!InitializeCriticalSectionAndSpinCount(&(transport->ReadLock), 4000))
|
| 1696 |
+
goto fail;
|
| 1697 |
+
|
| 1698 |
+
if (!InitializeCriticalSectionAndSpinCount(&(transport->WriteLock), 4000))
|
| 1699 |
+
goto fail;
|
| 1700 |
+
|
| 1701 |
+
return transport;
|
| 1702 |
+
fail:
|
| 1703 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 1704 |
+
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
| 1705 |
+
transport_free(transport);
|
| 1706 |
+
WINPR_PRAGMA_DIAG_POP
|
| 1707 |
+
return NULL;
|
| 1708 |
+
}
|
| 1709 |
+
|
| 1710 |
+
void transport_free(rdpTransport* transport)
|
| 1711 |
+
{
|
| 1712 |
+
if (!transport)
|
| 1713 |
+
return;
|
| 1714 |
+
|
| 1715 |
+
transport_disconnect(transport);
|
| 1716 |
+
|
| 1717 |
+
EnterCriticalSection(&(transport->ReadLock));
|
| 1718 |
+
if (transport->ReceiveBuffer)
|
| 1719 |
+
Stream_Release(transport->ReceiveBuffer);
|
| 1720 |
+
LeaveCriticalSection(&(transport->ReadLock));
|
| 1721 |
+
|
| 1722 |
+
(void)StreamPool_WaitForReturn(transport->ReceivePool, INFINITE);
|
| 1723 |
+
|
| 1724 |
+
EnterCriticalSection(&(transport->ReadLock));
|
| 1725 |
+
EnterCriticalSection(&(transport->WriteLock));
|
| 1726 |
+
|
| 1727 |
+
nla_free(transport->nla);
|
| 1728 |
+
StreamPool_Free(transport->ReceivePool);
|
| 1729 |
+
(void)CloseHandle(transport->connectedEvent);
|
| 1730 |
+
(void)CloseHandle(transport->rereadEvent);
|
| 1731 |
+
(void)CloseHandle(transport->ioEvent);
|
| 1732 |
+
|
| 1733 |
+
LeaveCriticalSection(&(transport->ReadLock));
|
| 1734 |
+
DeleteCriticalSection(&(transport->ReadLock));
|
| 1735 |
+
|
| 1736 |
+
LeaveCriticalSection(&(transport->WriteLock));
|
| 1737 |
+
DeleteCriticalSection(&(transport->WriteLock));
|
| 1738 |
+
free(transport);
|
| 1739 |
+
}
|
| 1740 |
+
|
| 1741 |
+
BOOL transport_set_io_callbacks(rdpTransport* transport, const rdpTransportIo* io_callbacks)
|
| 1742 |
+
{
|
| 1743 |
+
if (!transport || !io_callbacks)
|
| 1744 |
+
return FALSE;
|
| 1745 |
+
|
| 1746 |
+
transport->io = *io_callbacks;
|
| 1747 |
+
return TRUE;
|
| 1748 |
+
}
|
| 1749 |
+
|
| 1750 |
+
const rdpTransportIo* transport_get_io_callbacks(rdpTransport* transport)
|
| 1751 |
+
{
|
| 1752 |
+
if (!transport)
|
| 1753 |
+
return NULL;
|
| 1754 |
+
return &transport->io;
|
| 1755 |
+
}
|
| 1756 |
+
|
| 1757 |
+
rdpContext* transport_get_context(rdpTransport* transport)
|
| 1758 |
+
{
|
| 1759 |
+
WINPR_ASSERT(transport);
|
| 1760 |
+
return transport->context;
|
| 1761 |
+
}
|
| 1762 |
+
|
| 1763 |
+
rdpTransport* freerdp_get_transport(rdpContext* context)
|
| 1764 |
+
{
|
| 1765 |
+
WINPR_ASSERT(context);
|
| 1766 |
+
WINPR_ASSERT(context->rdp);
|
| 1767 |
+
return context->rdp->transport;
|
| 1768 |
+
}
|
| 1769 |
+
|
| 1770 |
+
BOOL transport_set_nla(rdpTransport* transport, rdpNla* nla)
|
| 1771 |
+
{
|
| 1772 |
+
WINPR_ASSERT(transport);
|
| 1773 |
+
nla_free(transport->nla);
|
| 1774 |
+
transport->nla = nla;
|
| 1775 |
+
return TRUE;
|
| 1776 |
+
}
|
| 1777 |
+
|
| 1778 |
+
rdpNla* transport_get_nla(rdpTransport* transport)
|
| 1779 |
+
{
|
| 1780 |
+
WINPR_ASSERT(transport);
|
| 1781 |
+
return transport->nla;
|
| 1782 |
+
}
|
| 1783 |
+
|
| 1784 |
+
BOOL transport_set_tls(rdpTransport* transport, rdpTls* tls)
|
| 1785 |
+
{
|
| 1786 |
+
WINPR_ASSERT(transport);
|
| 1787 |
+
freerdp_tls_free(transport->tls);
|
| 1788 |
+
transport->tls = tls;
|
| 1789 |
+
return TRUE;
|
| 1790 |
+
}
|
| 1791 |
+
|
| 1792 |
+
rdpTls* transport_get_tls(rdpTransport* transport)
|
| 1793 |
+
{
|
| 1794 |
+
WINPR_ASSERT(transport);
|
| 1795 |
+
return transport->tls;
|
| 1796 |
+
}
|
| 1797 |
+
|
| 1798 |
+
BOOL transport_set_tsg(rdpTransport* transport, rdpTsg* tsg)
|
| 1799 |
+
{
|
| 1800 |
+
WINPR_ASSERT(transport);
|
| 1801 |
+
tsg_free(transport->tsg);
|
| 1802 |
+
transport->tsg = tsg;
|
| 1803 |
+
return TRUE;
|
| 1804 |
+
}
|
| 1805 |
+
|
| 1806 |
+
rdpTsg* transport_get_tsg(rdpTransport* transport)
|
| 1807 |
+
{
|
| 1808 |
+
WINPR_ASSERT(transport);
|
| 1809 |
+
return transport->tsg;
|
| 1810 |
+
}
|
| 1811 |
+
|
| 1812 |
+
wStream* transport_take_from_pool(rdpTransport* transport, size_t size)
|
| 1813 |
+
{
|
| 1814 |
+
WINPR_ASSERT(transport);
|
| 1815 |
+
if (!transport->frontBio)
|
| 1816 |
+
return NULL;
|
| 1817 |
+
return StreamPool_Take(transport->ReceivePool, size);
|
| 1818 |
+
}
|
| 1819 |
+
|
| 1820 |
+
ULONG transport_get_bytes_sent(rdpTransport* transport, BOOL resetCount)
|
| 1821 |
+
{
|
| 1822 |
+
ULONG rc = 0;
|
| 1823 |
+
WINPR_ASSERT(transport);
|
| 1824 |
+
rc = transport->written;
|
| 1825 |
+
if (resetCount)
|
| 1826 |
+
transport->written = 0;
|
| 1827 |
+
return rc;
|
| 1828 |
+
}
|
| 1829 |
+
|
| 1830 |
+
TRANSPORT_LAYER transport_get_layer(rdpTransport* transport)
|
| 1831 |
+
{
|
| 1832 |
+
WINPR_ASSERT(transport);
|
| 1833 |
+
return transport->layer;
|
| 1834 |
+
}
|
| 1835 |
+
|
| 1836 |
+
BOOL transport_set_layer(rdpTransport* transport, TRANSPORT_LAYER layer)
|
| 1837 |
+
{
|
| 1838 |
+
WINPR_ASSERT(transport);
|
| 1839 |
+
transport->layer = layer;
|
| 1840 |
+
return TRUE;
|
| 1841 |
+
}
|
| 1842 |
+
|
| 1843 |
+
BOOL transport_set_connected_event(rdpTransport* transport)
|
| 1844 |
+
{
|
| 1845 |
+
WINPR_ASSERT(transport);
|
| 1846 |
+
return SetEvent(transport->connectedEvent);
|
| 1847 |
+
}
|
| 1848 |
+
|
| 1849 |
+
BOOL transport_set_recv_callbacks(rdpTransport* transport, TransportRecv recv, void* extra)
|
| 1850 |
+
{
|
| 1851 |
+
WINPR_ASSERT(transport);
|
| 1852 |
+
transport->ReceiveCallback = recv;
|
| 1853 |
+
transport->ReceiveExtra = extra;
|
| 1854 |
+
return TRUE;
|
| 1855 |
+
}
|
| 1856 |
+
|
| 1857 |
+
BOOL transport_get_blocking(rdpTransport* transport)
|
| 1858 |
+
{
|
| 1859 |
+
WINPR_ASSERT(transport);
|
| 1860 |
+
return transport->blocking;
|
| 1861 |
+
}
|
| 1862 |
+
|
| 1863 |
+
BOOL transport_set_blocking(rdpTransport* transport, BOOL blocking)
|
| 1864 |
+
{
|
| 1865 |
+
WINPR_ASSERT(transport);
|
| 1866 |
+
transport->blocking = blocking;
|
| 1867 |
+
return TRUE;
|
| 1868 |
+
}
|
| 1869 |
+
|
| 1870 |
+
BOOL transport_have_more_bytes_to_read(rdpTransport* transport)
|
| 1871 |
+
{
|
| 1872 |
+
WINPR_ASSERT(transport);
|
| 1873 |
+
return transport->haveMoreBytesToRead;
|
| 1874 |
+
}
|
| 1875 |
+
|
| 1876 |
+
int transport_tcp_connect(rdpTransport* transport, const char* hostname, int port, DWORD timeout)
|
| 1877 |
+
{
|
| 1878 |
+
rdpContext* context = transport_get_context(transport);
|
| 1879 |
+
WINPR_ASSERT(context);
|
| 1880 |
+
WINPR_ASSERT(context->settings);
|
| 1881 |
+
return IFCALLRESULT(-1, transport->io.TCPConnect, context, context->settings, hostname, port,
|
| 1882 |
+
timeout);
|
| 1883 |
+
}
|
| 1884 |
+
|
| 1885 |
+
HANDLE transport_get_front_bio(rdpTransport* transport)
|
| 1886 |
+
{
|
| 1887 |
+
HANDLE hEvent = NULL;
|
| 1888 |
+
WINPR_ASSERT(transport);
|
| 1889 |
+
WINPR_ASSERT(transport->frontBio);
|
| 1890 |
+
|
| 1891 |
+
BIO_get_event(transport->frontBio, &hEvent);
|
| 1892 |
+
return hEvent;
|
| 1893 |
+
}
|
| 1894 |
+
|
| 1895 |
+
BOOL transport_io_callback_set_event(rdpTransport* transport, BOOL set)
|
| 1896 |
+
{
|
| 1897 |
+
WINPR_ASSERT(transport);
|
| 1898 |
+
transport->useIoEvent = TRUE;
|
| 1899 |
+
if (!set)
|
| 1900 |
+
return ResetEvent(transport->ioEvent);
|
| 1901 |
+
return SetEvent(transport->ioEvent);
|
| 1902 |
+
}
|
| 1903 |
+
|
| 1904 |
+
void transport_set_early_user_auth_mode(rdpTransport* transport, BOOL EUAMode)
|
| 1905 |
+
{
|
| 1906 |
+
WINPR_ASSERT(transport);
|
| 1907 |
+
transport->earlyUserAuth = EUAMode;
|
| 1908 |
+
WLog_Print(transport->log, WLOG_DEBUG, "Early User Auth Mode: %s", EUAMode ? "on" : "off");
|
| 1909 |
+
}
|
| 1910 |
+
|
| 1911 |
+
rdpTransportLayer* transport_layer_new(rdpTransport* transport, size_t contextSize)
|
| 1912 |
+
{
|
| 1913 |
+
rdpTransportLayer* layer = (rdpTransportLayer*)calloc(1, sizeof(rdpTransportLayer));
|
| 1914 |
+
if (!layer)
|
| 1915 |
+
return NULL;
|
| 1916 |
+
|
| 1917 |
+
if (contextSize)
|
| 1918 |
+
{
|
| 1919 |
+
layer->userContext = calloc(1, contextSize);
|
| 1920 |
+
if (!layer->userContext)
|
| 1921 |
+
{
|
| 1922 |
+
free(layer);
|
| 1923 |
+
return NULL;
|
| 1924 |
+
}
|
| 1925 |
+
}
|
| 1926 |
+
|
| 1927 |
+
return layer;
|
| 1928 |
+
}
|
| 1929 |
+
|
| 1930 |
+
void transport_layer_free(rdpTransportLayer* layer)
|
| 1931 |
+
{
|
| 1932 |
+
if (!layer)
|
| 1933 |
+
return;
|
| 1934 |
+
|
| 1935 |
+
IFCALL(layer->Close, layer->userContext);
|
| 1936 |
+
free(layer->userContext);
|
| 1937 |
+
free(layer);
|
| 1938 |
+
}
|
| 1939 |
+
|
| 1940 |
+
static int transport_layer_bio_write(BIO* bio, const char* buf, int size)
|
| 1941 |
+
{
|
| 1942 |
+
if (!buf || !size)
|
| 1943 |
+
return 0;
|
| 1944 |
+
if (size < 0)
|
| 1945 |
+
return -1;
|
| 1946 |
+
|
| 1947 |
+
WINPR_ASSERT(bio);
|
| 1948 |
+
|
| 1949 |
+
rdpTransportLayer* layer = (rdpTransportLayer*)BIO_get_data(bio);
|
| 1950 |
+
if (!layer)
|
| 1951 |
+
return -1;
|
| 1952 |
+
|
| 1953 |
+
BIO_clear_flags(bio, BIO_FLAGS_WRITE | BIO_FLAGS_SHOULD_RETRY);
|
| 1954 |
+
|
| 1955 |
+
int status = IFCALLRESULT(-1, layer->Write, layer->userContext, buf, size);
|
| 1956 |
+
|
| 1957 |
+
if (status >= 0 && status < size)
|
| 1958 |
+
BIO_set_flags(bio, (BIO_FLAGS_WRITE | BIO_FLAGS_SHOULD_RETRY));
|
| 1959 |
+
|
| 1960 |
+
return status;
|
| 1961 |
+
}
|
| 1962 |
+
|
| 1963 |
+
static int transport_layer_bio_read(BIO* bio, char* buf, int size)
|
| 1964 |
+
{
|
| 1965 |
+
if (!buf || !size)
|
| 1966 |
+
return 0;
|
| 1967 |
+
if (size < 0)
|
| 1968 |
+
return -1;
|
| 1969 |
+
|
| 1970 |
+
WINPR_ASSERT(bio);
|
| 1971 |
+
|
| 1972 |
+
rdpTransportLayer* layer = (rdpTransportLayer*)BIO_get_data(bio);
|
| 1973 |
+
if (!layer)
|
| 1974 |
+
return -1;
|
| 1975 |
+
|
| 1976 |
+
BIO_clear_flags(bio, BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY);
|
| 1977 |
+
|
| 1978 |
+
int status = IFCALLRESULT(-1, layer->Read, layer->userContext, buf, size);
|
| 1979 |
+
|
| 1980 |
+
if (status == 0)
|
| 1981 |
+
BIO_set_flags(bio, (BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY));
|
| 1982 |
+
|
| 1983 |
+
return status;
|
| 1984 |
+
}
|
| 1985 |
+
|
| 1986 |
+
static int transport_layer_bio_puts(BIO* bio, const char* str)
|
| 1987 |
+
{
|
| 1988 |
+
return 1;
|
| 1989 |
+
}
|
| 1990 |
+
|
| 1991 |
+
static int transport_layer_bio_gets(BIO* bio, char* str, int size)
|
| 1992 |
+
{
|
| 1993 |
+
return 1;
|
| 1994 |
+
}
|
| 1995 |
+
|
| 1996 |
+
static long transport_layer_bio_ctrl(BIO* bio, int cmd, long arg1, void* arg2)
|
| 1997 |
+
{
|
| 1998 |
+
WINPR_ASSERT(bio);
|
| 1999 |
+
|
| 2000 |
+
rdpTransportLayer* layer = (rdpTransportLayer*)BIO_get_data(bio);
|
| 2001 |
+
if (!layer)
|
| 2002 |
+
return -1;
|
| 2003 |
+
|
| 2004 |
+
int status = -1;
|
| 2005 |
+
switch (cmd)
|
| 2006 |
+
{
|
| 2007 |
+
case BIO_C_GET_EVENT:
|
| 2008 |
+
*((HANDLE*)arg2) = IFCALLRESULT(NULL, layer->GetEvent, layer->userContext);
|
| 2009 |
+
status = 1;
|
| 2010 |
+
break;
|
| 2011 |
+
|
| 2012 |
+
case BIO_C_SET_NONBLOCK:
|
| 2013 |
+
status = 1;
|
| 2014 |
+
break;
|
| 2015 |
+
|
| 2016 |
+
case BIO_C_WAIT_READ:
|
| 2017 |
+
{
|
| 2018 |
+
int timeout = (int)arg1;
|
| 2019 |
+
BOOL r = IFCALLRESULT(FALSE, layer->Wait, layer->userContext, FALSE,
|
| 2020 |
+
WINPR_ASSERTING_INT_CAST(uint32_t, timeout));
|
| 2021 |
+
/* Convert timeout to error return */
|
| 2022 |
+
if (!r)
|
| 2023 |
+
{
|
| 2024 |
+
errno = ETIMEDOUT;
|
| 2025 |
+
status = 0;
|
| 2026 |
+
}
|
| 2027 |
+
else
|
| 2028 |
+
status = 1;
|
| 2029 |
+
break;
|
| 2030 |
+
}
|
| 2031 |
+
|
| 2032 |
+
case BIO_C_WAIT_WRITE:
|
| 2033 |
+
{
|
| 2034 |
+
int timeout = (int)arg1;
|
| 2035 |
+
BOOL r = IFCALLRESULT(FALSE, layer->Wait, layer->userContext, TRUE,
|
| 2036 |
+
WINPR_ASSERTING_INT_CAST(uint32_t, timeout));
|
| 2037 |
+
/* Convert timeout to error return */
|
| 2038 |
+
if (!r)
|
| 2039 |
+
{
|
| 2040 |
+
errno = ETIMEDOUT;
|
| 2041 |
+
status = 0;
|
| 2042 |
+
}
|
| 2043 |
+
else
|
| 2044 |
+
status = 1;
|
| 2045 |
+
break;
|
| 2046 |
+
}
|
| 2047 |
+
|
| 2048 |
+
case BIO_CTRL_GET_CLOSE:
|
| 2049 |
+
status = BIO_get_shutdown(bio);
|
| 2050 |
+
break;
|
| 2051 |
+
|
| 2052 |
+
case BIO_CTRL_SET_CLOSE:
|
| 2053 |
+
BIO_set_shutdown(bio, (int)arg1);
|
| 2054 |
+
status = 1;
|
| 2055 |
+
break;
|
| 2056 |
+
|
| 2057 |
+
case BIO_CTRL_FLUSH:
|
| 2058 |
+
case BIO_CTRL_DUP:
|
| 2059 |
+
status = 1;
|
| 2060 |
+
break;
|
| 2061 |
+
|
| 2062 |
+
default:
|
| 2063 |
+
status = 0;
|
| 2064 |
+
break;
|
| 2065 |
+
}
|
| 2066 |
+
|
| 2067 |
+
return status;
|
| 2068 |
+
}
|
| 2069 |
+
|
| 2070 |
+
static int transport_layer_bio_new(BIO* bio)
|
| 2071 |
+
{
|
| 2072 |
+
WINPR_ASSERT(bio);
|
| 2073 |
+
|
| 2074 |
+
BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 2075 |
+
BIO_set_init(bio, 1);
|
| 2076 |
+
return 1;
|
| 2077 |
+
}
|
| 2078 |
+
|
| 2079 |
+
static int transport_layer_bio_free(BIO* bio)
|
| 2080 |
+
{
|
| 2081 |
+
if (!bio)
|
| 2082 |
+
return 0;
|
| 2083 |
+
|
| 2084 |
+
rdpTransportLayer* layer = (rdpTransportLayer*)BIO_get_data(bio);
|
| 2085 |
+
if (layer)
|
| 2086 |
+
transport_layer_free(layer);
|
| 2087 |
+
|
| 2088 |
+
BIO_set_data(bio, NULL);
|
| 2089 |
+
BIO_set_init(bio, 0);
|
| 2090 |
+
BIO_set_flags(bio, 0);
|
| 2091 |
+
|
| 2092 |
+
return 1;
|
| 2093 |
+
}
|
| 2094 |
+
|
| 2095 |
+
BIO_METHOD* BIO_s_transport_layer(void)
|
| 2096 |
+
{
|
| 2097 |
+
static BIO_METHOD* bio_methods = NULL;
|
| 2098 |
+
|
| 2099 |
+
if (bio_methods == NULL)
|
| 2100 |
+
{
|
| 2101 |
+
if (!(bio_methods = BIO_meth_new(BIO_TYPE_SIMPLE, "TransportLayer")))
|
| 2102 |
+
return NULL;
|
| 2103 |
+
|
| 2104 |
+
BIO_meth_set_write(bio_methods, transport_layer_bio_write);
|
| 2105 |
+
BIO_meth_set_read(bio_methods, transport_layer_bio_read);
|
| 2106 |
+
BIO_meth_set_puts(bio_methods, transport_layer_bio_puts);
|
| 2107 |
+
BIO_meth_set_gets(bio_methods, transport_layer_bio_gets);
|
| 2108 |
+
BIO_meth_set_ctrl(bio_methods, transport_layer_bio_ctrl);
|
| 2109 |
+
BIO_meth_set_create(bio_methods, transport_layer_bio_new);
|
| 2110 |
+
BIO_meth_set_destroy(bio_methods, transport_layer_bio_free);
|
| 2111 |
+
}
|
| 2112 |
+
|
| 2113 |
+
return bio_methods;
|
| 2114 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/CMakeLists.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
if(WITH_SMARTCARD_EMULATE)
|
| 2 |
+
list(
|
| 3 |
+
APPEND
|
| 4 |
+
EMULATE_SRCS
|
| 5 |
+
scard/smartcard_emulate.c
|
| 6 |
+
scard/FreeRDP.ico.h
|
| 7 |
+
scard/FreeRDP.ico.c
|
| 8 |
+
scard/smartcard_virtual_gids.h
|
| 9 |
+
scard/smartcard_virtual_gids.c
|
| 10 |
+
)
|
| 11 |
+
freerdp_module_add(${EMULATE_SRCS})
|
| 12 |
+
freerdp_library_add(ZLIB::ZLIB)
|
| 13 |
+
endif()
|