You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SecurityPage.cxx 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2011 TigerVNC Team
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22. #include <rdr/Exception.h>
  23. #include <rfb/LogWriter.h>
  24. #include <rfb/Security.h>
  25. #include <rfb_win32/resource.h>
  26. #include <rfb_win32/SecurityPage.h>
  27. #include <list>
  28. using namespace rdr;
  29. using namespace rfb;
  30. using namespace rfb::win32;
  31. using namespace std;
  32. static LogWriter vlog("AuthDialog");
  33. /* XXX: This class contains bunch of similar code to unix/vncviewer/CConn.cxx */
  34. SecurityPage::SecurityPage(Security *security_)
  35. : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_SECURITY)),
  36. security(security_) {
  37. }
  38. void
  39. SecurityPage::initDialog()
  40. {
  41. list<U8> secTypes;
  42. list<U8>::iterator i;
  43. if (isItemChecked(IDC_ENC_X509))
  44. enableX509Dialogs();
  45. else
  46. disableX509Dialogs();
  47. secTypes = security->GetEnabledSecTypes();
  48. /* Process non-VeNCrypt sectypes */
  49. for (i = secTypes.begin(); i != secTypes.end(); i++) {
  50. switch (*i) {
  51. case secTypeNone:
  52. enableAuthMethod(IDC_ENC_NONE, IDC_AUTH_NONE);
  53. break;
  54. case secTypeVncAuth:
  55. enableAuthMethod(IDC_ENC_NONE, IDC_AUTH_VNC);
  56. break;
  57. }
  58. }
  59. list<U32> secTypesExt;
  60. list<U32>::iterator iext;
  61. secTypesExt = security->GetEnabledExtSecTypes();
  62. /* Process VeNCrypt subtypes */
  63. for (iext = secTypesExt.begin(); iext != secTypesExt.end(); iext++) {
  64. switch (*iext) {
  65. case secTypePlain:
  66. enableAuthMethod(IDC_ENC_NONE, IDC_AUTH_PLAIN);
  67. break;
  68. case secTypeTLSNone:
  69. enableAuthMethod(IDC_ENC_TLS, IDC_AUTH_NONE);
  70. break;
  71. case secTypeTLSVnc:
  72. enableAuthMethod(IDC_ENC_TLS, IDC_AUTH_VNC);
  73. break;
  74. case secTypeTLSPlain:
  75. enableAuthMethod(IDC_ENC_TLS, IDC_AUTH_PLAIN);
  76. break;
  77. case secTypeX509None:
  78. enableAuthMethod(IDC_ENC_X509, IDC_AUTH_NONE);
  79. enableX509Dialogs();
  80. break;
  81. case secTypeX509Vnc:
  82. enableAuthMethod(IDC_ENC_X509, IDC_AUTH_VNC);
  83. enableX509Dialogs();
  84. break;
  85. case secTypeX509Plain:
  86. enableAuthMethod(IDC_ENC_X509, IDC_AUTH_PLAIN);
  87. enableX509Dialogs();
  88. break;
  89. }
  90. }
  91. }
  92. bool
  93. SecurityPage::onCommand(int id, int /*cmd*/)
  94. {
  95. if (id == IDC_ENC_X509) {
  96. if (isItemChecked(IDC_ENC_X509))
  97. enableX509Dialogs();
  98. else
  99. disableX509Dialogs();
  100. }
  101. return true;
  102. }
  103. bool
  104. SecurityPage::onOk() {
  105. #ifdef HAVE_GNUTLS
  106. bool x509_loaded = false;
  107. #endif
  108. bool vnc_loaded = false;
  109. list<U32> secTypes;
  110. /* Keep same priorities as in common/rfb/SecurityClient::secTypes */
  111. secTypes.push_back(secTypeVeNCrypt);
  112. #ifdef HAVE_GNUTLS
  113. /* X509Plain */
  114. if (authMethodEnabled(IDC_ENC_X509, IDC_AUTH_PLAIN)) {
  115. loadX509Certs(x509_loaded);
  116. secTypes.push_back(secTypeX509Plain);
  117. }
  118. /* TLSPlain */
  119. if (authMethodEnabled(IDC_ENC_TLS, IDC_AUTH_PLAIN))
  120. secTypes.push_back(secTypeTLSPlain);
  121. /* X509Vnc */
  122. if (authMethodEnabled(IDC_ENC_X509, IDC_AUTH_VNC)) {
  123. loadX509Certs(x509_loaded);
  124. loadVncPasswd(vnc_loaded);
  125. secTypes.push_back(secTypeX509Vnc);
  126. }
  127. /* TLSVnc */
  128. if (authMethodEnabled(IDC_ENC_TLS, IDC_AUTH_VNC)) {
  129. loadVncPasswd(vnc_loaded);
  130. secTypes.push_back(secTypeTLSVnc);
  131. }
  132. /* X509None */
  133. if (authMethodEnabled(IDC_ENC_X509, IDC_AUTH_NONE)) {
  134. loadX509Certs(x509_loaded);
  135. secTypes.push_back(secTypeX509None);
  136. }
  137. /* TLSNone */
  138. if (authMethodEnabled(IDC_ENC_TLS, IDC_AUTH_NONE))
  139. secTypes.push_back(secTypeTLSNone);
  140. #endif
  141. /* VncAuth */
  142. if (authMethodEnabled(IDC_ENC_NONE, IDC_AUTH_VNC)) {
  143. loadVncPasswd(vnc_loaded);
  144. secTypes.push_back(secTypeVncAuth);
  145. }
  146. /* None */
  147. if (authMethodEnabled(IDC_ENC_NONE, IDC_AUTH_NONE))
  148. secTypes.push_back(secTypeNone);
  149. security->SetSecTypes(secTypes);
  150. return true;
  151. }
  152. inline void
  153. SecurityPage::disableFeature(int id)
  154. {
  155. enableItem(id, false);
  156. setItemChecked(id, false);
  157. }
  158. inline void
  159. SecurityPage::enableAuthMethod(int encid, int authid)
  160. {
  161. setItemChecked(encid, true);
  162. setItemChecked(authid, true);
  163. }
  164. inline bool
  165. SecurityPage::authMethodEnabled(int encid, int authid)
  166. {
  167. return isItemChecked(encid) && isItemChecked(authid);
  168. }
  169. inline void
  170. SecurityPage::loadX509Certs(bool &loaded)
  171. {
  172. if (!loaded)
  173. loadX509Certs();
  174. loaded = true;
  175. }
  176. inline void
  177. SecurityPage::loadVncPasswd(bool &loaded)
  178. {
  179. if (!loaded)
  180. loadVncPasswd();
  181. loaded = true;
  182. }