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.

SecurityClient.cxx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2010 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 <assert.h>
  23. #include <rfb/CSecurityNone.h>
  24. #include <rfb/CSecurityStack.h>
  25. #include <rfb/CSecurityVeNCrypt.h>
  26. #include <rfb/CSecurityVncAuth.h>
  27. #include <rfb/CSecurityPlain.h>
  28. #include <rdr/Exception.h>
  29. #include <rfb/Security.h>
  30. #ifdef HAVE_GNUTLS
  31. #include <rfb/CSecurityTLS.h>
  32. #endif
  33. #ifdef HAVE_NETTLE
  34. #include <rfb/CSecurityRSAAES.h>
  35. #endif
  36. using namespace rdr;
  37. using namespace rfb;
  38. UserPasswdGetter *CSecurity::upg = NULL;
  39. #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
  40. UserMsgBox *CSecurity::msg = NULL;
  41. #endif
  42. StringParameter SecurityClient::secTypes
  43. ("SecurityTypes",
  44. "Specify which security scheme to use (None, VncAuth, Plain"
  45. #ifdef HAVE_GNUTLS
  46. ", TLSNone, TLSVnc, TLSPlain, X509None, X509Vnc, X509Plain"
  47. #endif
  48. #ifdef HAVE_NETTLE
  49. ", RA2, RA2ne, RA2_256, RA2ne_256"
  50. #endif
  51. ")",
  52. #ifdef HAVE_GNUTLS
  53. "X509Plain,TLSPlain,X509Vnc,TLSVnc,X509None,TLSNone,"
  54. #endif
  55. #ifdef HAVE_NETTLE
  56. "RA2,RA2_256,RA2ne,RA2ne_256,"
  57. #endif
  58. "VncAuth,None",
  59. ConfViewer);
  60. CSecurity* SecurityClient::GetCSecurity(CConnection* cc, U32 secType)
  61. {
  62. assert (CSecurity::upg != NULL); /* (upg == NULL) means bug in the viewer */
  63. #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE)
  64. assert (CSecurity::msg != NULL);
  65. #endif
  66. if (!IsSupported(secType))
  67. goto bail;
  68. switch (secType) {
  69. case secTypeNone: return new CSecurityNone(cc);
  70. case secTypeVncAuth: return new CSecurityVncAuth(cc);
  71. case secTypeVeNCrypt: return new CSecurityVeNCrypt(cc, this);
  72. case secTypePlain: return new CSecurityPlain(cc);
  73. #ifdef HAVE_GNUTLS
  74. case secTypeTLSNone:
  75. return new CSecurityStack(cc, secTypeTLSNone,
  76. new CSecurityTLS(cc, true));
  77. case secTypeTLSVnc:
  78. return new CSecurityStack(cc, secTypeTLSVnc,
  79. new CSecurityTLS(cc, true),
  80. new CSecurityVncAuth(cc));
  81. case secTypeTLSPlain:
  82. return new CSecurityStack(cc, secTypeTLSPlain,
  83. new CSecurityTLS(cc, true),
  84. new CSecurityPlain(cc));
  85. case secTypeX509None:
  86. return new CSecurityStack(cc, secTypeX509None,
  87. new CSecurityTLS(cc, false));
  88. case secTypeX509Vnc:
  89. return new CSecurityStack(cc, secTypeX509Vnc,
  90. new CSecurityTLS(cc, false),
  91. new CSecurityVncAuth(cc));
  92. case secTypeX509Plain:
  93. return new CSecurityStack(cc, secTypeX509Plain,
  94. new CSecurityTLS(cc, false),
  95. new CSecurityPlain(cc));
  96. #endif
  97. #ifdef HAVE_NETTLE
  98. case secTypeRA2:
  99. return new CSecurityRSAAES(cc, secTypeRA2, 128, true);
  100. case secTypeRA2ne:
  101. return new CSecurityRSAAES(cc, secTypeRA2ne, 128, false);
  102. case secTypeRA256:
  103. return new CSecurityRSAAES(cc, secTypeRA256, 256, true);
  104. case secTypeRAne256:
  105. return new CSecurityRSAAES(cc, secTypeRAne256, 256, false);
  106. #endif
  107. }
  108. bail:
  109. throw Exception("Security type not supported");
  110. }