]> source.dussan.org Git - tigervnc.git/commitdiff
[Development] Add new rfb_win32::SecurityPage class
authorAdam Tkac <atkac@redhat.com>
Tue, 1 Feb 2011 14:35:39 +0000 (14:35 +0000)
committerAdam Tkac <atkac@redhat.com>
Tue, 1 Feb 2011 14:35:39 +0000 (14:35 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4246 3789f03b-4d11-0410-bbf8-ca57d06f2519

win/rfb_win32/CMakeLists.txt
win/rfb_win32/Makefile.am
win/rfb_win32/SecurityPage.cxx [new file with mode: 0644]
win/rfb_win32/SecurityPage.h [new file with mode: 0644]
win/rfb_win32/resource.h [new file with mode: 0644]

index 60af6db5bb4fb4291ca5b24454db71d1552e4135..83d7f1c62a1bdb932b1159ed228f0a8db7a07744 100644 (file)
@@ -20,6 +20,7 @@ set(RFB_WIN32_SOURCES
   RegConfig.cxx
   Registry.cxx
   ScaledDIBSectionBuffer.cxx
+  SecurityPage.cxx
   SDisplayCorePolling.cxx
   SDisplayCoreWMHooks.cxx
   SDisplay.cxx
index 80d9286fa4f1a20b9fc25eea660abb2411e01d81..c6ae74e4a5f659afaa0ff09fb1d9f2aa61f50c3b 100644 (file)
@@ -32,7 +32,9 @@ HDRS = \
   ProgressControl.h \
   RegConfig.h \
   Registry.h \
+  resource.h \
   ScaledDIBSectionBuffer.h \
+  SecurityPage.h \
   SDisplayCoreDriver.h \
   SDisplayCorePolling.h \
   SDisplayCoreWMHooks.h \
@@ -76,6 +78,7 @@ librfb_win32_la_SOURCES = $(HDRS) \
   RegConfig.cxx \
   Registry.cxx \
   ScaledDIBSectionBuffer.cxx \
+  SecurityPage.cxx \
   SDisplayCorePolling.cxx \
   SDisplayCoreWMHooks.cxx \
   SDisplay.cxx \
diff --git a/win/rfb_win32/SecurityPage.cxx b/win/rfb_win32/SecurityPage.cxx
new file mode 100644 (file)
index 0000000..1515727
--- /dev/null
@@ -0,0 +1,237 @@
+/* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
+ * Copyright (C) 2011 TigerVNC Team
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <rdr/Exception.h>
+
+#include <rfb/LogWriter.h>
+#include <rfb/Security.h>
+
+#include <rfb_win32/resource.h>
+#include <rfb_win32/SecurityPage.h>
+
+#include <list>
+
+using namespace rdr;
+using namespace rfb;
+using namespace rfb::win32;
+using namespace std;
+
+static LogWriter vlog("AuthDialog");
+
+/* XXX: This class contains bunch of similar code to unix/vncviewer/CConn.cxx */
+SecurityPage::SecurityPage(Security *security_)
+  : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_SECURITY)),
+    security(security_) {
+}
+
+void
+SecurityPage::initDialog()
+{
+  list<U8> secTypes;
+  list<U8>::iterator i;
+
+  enableVeNCryptFeatures(false);
+
+  secTypes = security->GetEnabledSecTypes();
+
+  /* Process non-VeNCrypt sectypes */
+  for (i = secTypes.begin(); i != secTypes.end(); i++) {
+    switch (*i) {
+    case secTypeVeNCrypt:
+      enableVeNCryptFeatures(true);
+      setItemChecked(IDC_VENCRYPT, true);
+      break;
+    case secTypeNone:
+      enableAuthMethod(IDC_ENC_NONE, IDC_AUTH_NONE);
+      break;
+    case secTypeVncAuth:
+      enableAuthMethod(IDC_ENC_NONE, IDC_AUTH_VNC);
+      break;
+    }
+  }
+
+  list<U32> secTypesExt;
+  list<U32>::iterator iext;
+
+  secTypesExt = security->GetEnabledExtSecTypes();
+
+  /* Process VeNCrypt subtypes */
+  if (isItemChecked(IDC_VENCRYPT)) {
+    for (iext = secTypesExt.begin(); iext != secTypesExt.end(); iext++) {
+      switch (*iext) {
+      case secTypePlain:
+       enableAuthMethod(IDC_ENC_NONE, IDC_AUTH_PLAIN);
+       break;
+      case secTypeTLSNone:
+       enableAuthMethod(IDC_ENC_TLS, IDC_AUTH_NONE);
+       break;
+      case secTypeTLSVnc:
+       enableAuthMethod(IDC_ENC_TLS, IDC_AUTH_VNC);
+       break;
+      case secTypeTLSPlain:
+       enableAuthMethod(IDC_ENC_TLS, IDC_AUTH_PLAIN);
+       break;
+      case secTypeX509None:
+       enableAuthMethod(IDC_ENC_X509, IDC_AUTH_NONE);
+        enableX509Dialogs();
+       break;
+      case secTypeX509Vnc:
+       enableAuthMethod(IDC_ENC_X509, IDC_AUTH_VNC);
+        enableX509Dialogs();
+       break;
+      case secTypeX509Plain:
+       enableAuthMethod(IDC_ENC_X509, IDC_AUTH_PLAIN);
+        enableX509Dialogs();
+       break;
+      }
+    }
+  }
+}
+
+bool
+SecurityPage::onCommand(int id, int cmd)
+{
+  if (id == IDC_VENCRYPT) {
+    enableVeNCryptFeatures(isItemChecked(IDC_VENCRYPT));
+  } else if (id == IDC_ENC_X509) {
+    if (isItemChecked(IDC_ENC_X509))
+      enableX509Dialogs();
+    else
+      disableX509Dialogs();
+  }
+
+  return true;
+}
+
+bool
+SecurityPage::onOk() {
+  bool x509_loaded = false;
+  bool vnc_loaded = false;
+  list<U32> secTypes;
+
+  /* Keep same priorities as in common/rfb/SecurityClient::secTypes */
+  if (isItemChecked(IDC_VENCRYPT)) {
+    secTypes.push_back(secTypeVeNCrypt);
+
+#ifdef HAVE_GNUTLS
+    /* X509Plain */
+    if (authMethodEnabled(IDC_ENC_X509, IDC_AUTH_PLAIN)) {
+      loadX509Certs(x509_loaded);
+      secTypes.push_back(secTypeX509Plain);
+    }
+
+    /* TLSPlain */
+    if (authMethodEnabled(IDC_ENC_TLS, IDC_AUTH_PLAIN))
+      secTypes.push_back(secTypeTLSPlain);
+
+    /* X509Vnc */
+    if (authMethodEnabled(IDC_ENC_X509, IDC_AUTH_VNC)) {
+      loadX509Certs(x509_loaded);
+      loadVncPasswd(vnc_loaded);
+      secTypes.push_back(secTypeX509Vnc);
+    }
+
+    /* TLSVnc */
+    if (authMethodEnabled(IDC_ENC_TLS, IDC_AUTH_VNC)) {
+      loadVncPasswd(vnc_loaded);
+      secTypes.push_back(secTypeTLSVnc);
+    }
+
+    /* X509None */
+    if (authMethodEnabled(IDC_ENC_X509, IDC_AUTH_NONE)) {
+      loadX509Certs(x509_loaded);
+      secTypes.push_back(secTypeX509None);
+    }
+
+    /* TLSNone */
+    if (authMethodEnabled(IDC_ENC_TLS, IDC_AUTH_NONE))
+      secTypes.push_back(secTypeTLSNone);
+#endif
+  }
+
+  /* VncAuth */
+  if (authMethodEnabled(IDC_ENC_NONE, IDC_AUTH_VNC)) {
+    loadVncPasswd(vnc_loaded);
+    secTypes.push_back(secTypeVncAuth);
+  }
+
+  /* None */
+  if (authMethodEnabled(IDC_ENC_NONE, IDC_AUTH_NONE))
+    secTypes.push_back(secTypeNone);
+
+  security->SetSecTypes(secTypes);
+
+  return true;
+}
+
+inline void
+SecurityPage::enableVeNCryptFeatures(bool enable)
+{
+  if (enable) {
+    enableItem(IDC_ENC_TLS, true);
+    enableItem(IDC_ENC_X509, true);
+    enableItem(IDC_AUTH_PLAIN, true);
+  } else {
+    disableFeature(IDC_ENC_TLS);
+    disableFeature(IDC_ENC_X509);
+    disableFeature(IDC_AUTH_PLAIN);
+    disableX509Dialogs();
+  }
+}
+
+inline void
+SecurityPage::disableFeature(int id)
+{
+  enableItem(id, false);
+  setItemChecked(id, false);
+}
+
+inline void
+SecurityPage::enableAuthMethod(int encid, int authid)
+{
+  setItemChecked(encid, true);
+  setItemChecked(authid, true);
+}
+
+inline bool
+SecurityPage::authMethodEnabled(int encid, int authid)
+{
+  return isItemChecked(encid) && isItemChecked(authid);
+}
+
+inline void
+SecurityPage::loadX509Certs(bool &loaded)
+{
+  if (!loaded)
+    loadX509Certs();
+  loaded = true;
+}
+
+inline void
+SecurityPage::loadVncPasswd(bool &loaded)
+{
+  if (!loaded)
+    loadVncPasswd();
+  loaded = true;
+}
+
diff --git a/win/rfb_win32/SecurityPage.h b/win/rfb_win32/SecurityPage.h
new file mode 100644 (file)
index 0000000..b43c2a3
--- /dev/null
@@ -0,0 +1,62 @@
+/* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
+ * Copyright (C) 2011 TigerVNC Team
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+
+#ifndef __RFB_WIN32_SECURITYPAGE_H__
+#define __RFB_WIN32_SECURITYPAGE_H__
+
+#include <rdr/types.h>
+
+#include <rfb/Security.h>
+#include <rfb_win32/Dialog.h>
+
+#include <list>
+
+namespace rfb {
+namespace win32 {
+
+class SecurityPage: public PropSheetPage
+{
+public:
+  SecurityPage(Security *security_);
+
+  virtual void loadX509Certs(void) = 0;
+  virtual void enableX509Dialogs(void) = 0;
+  virtual void disableX509Dialogs(void) = 0;
+  virtual void loadVncPasswd(void) = 0;
+
+  virtual void initDialog();
+  virtual bool onCommand(int id, int cmd);
+  virtual bool onOk();
+
+protected:
+  Security *security;
+
+private:
+  inline void enableVeNCryptFeatures(bool enable);
+  inline void disableFeature(int id);
+  inline void enableAuthMethod(int encid, int authid);
+  inline bool authMethodEnabled(int encid, int authid);
+  inline void loadX509Certs(bool &loaded);
+  inline void loadVncPasswd(bool &loaded);
+};
+    
+};
+};
+
+#endif
diff --git a/win/rfb_win32/resource.h b/win/rfb_win32/resource.h
new file mode 100644 (file)
index 0000000..aedfbda
--- /dev/null
@@ -0,0 +1,38 @@
+/* Copyright (C) 2011 TigerVNC Team
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+
+/*
+ * This file contains resource IDs shared between various Windows binaries.
+ * If you are adding new resource ID ensure it doesn't conflict with per-binary
+ * resource IDs.
+ */
+
+#ifndef __RFB_WIN32_RESOURCE_H__
+#define __RFB_WIN32_RESOURCE_H__
+
+#define IDD_SECURITY           117
+
+#define IDC_VENCRYPT           1200
+#define IDC_ENC_NONE           1201
+#define IDC_ENC_TLS            1202
+#define IDC_ENC_X509           1203
+#define IDC_AUTH_NONE          1206
+#define IDC_AUTH_VNC           1207
+#define IDC_AUTH_PLAIN         1208
+
+#endif