~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to debian/patches/vnc-4.0b5-vncviewer-tls.diff

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
--- vnc-4.0b5-unixsrc/x0vncserver/Makefile.in.tls       2004-06-11 16:36:08.113307745 +0100
2
 
+++ vnc-4.0b5-unixsrc/x0vncserver/Makefile.in   2004-06-11 16:36:46.864918325 +0100
3
 
@@ -7,9 +7,9 @@
4
 
 
5
 
 DEP_LIBS = ../rfb/librfb.a ../network/libnetwork.a ../rdr/librdr.a
6
 
 
7
 
-EXTRA_LIBS = @ZLIB_LIB@ @X_PRE_LIBS@ @X_LIBS@ -lXtst -lXext -lX11 @X_EXTRA_LIBS@
8
 
+EXTRA_LIBS = @ZLIB_LIB@ @X_PRE_LIBS@ @X_LIBS@ -lXtst -lXext -lX11 @X_EXTRA_LIBS@ @LIBGNUTLS_LIBS@
9
 
 
10
 
-DIR_CPPFLAGS = -I$(top_srcdir) @X_CFLAGS@ # X_CFLAGS are really CPPFLAGS
11
 
+DIR_CPPFLAGS = -I$(top_srcdir) @X_CFLAGS@ @LIBGNUTLS_CFLAGS@ # X_CFLAGS are really CPPFLAGS
12
 
 
13
 
 all:: $(program)
14
 
 
15
 
--- vnc-4.0b5-unixsrc/configure.in.tls  2004-06-11 16:36:08.147303017 +0100
16
 
+++ vnc-4.0b5-unixsrc/configure.in      2004-06-11 16:36:46.865918186 +0100
17
 
@@ -63,6 +63,14 @@
18
 
 AC_SUBST(ZLIB_INCLUDE)
19
 
 AC_SUBST(ZLIB_LIB)
20
 
 
21
 
+AC_ARG_ENABLE(gnutls, [  --enable-gnutls         build with gnutls support])
22
 
+if test "x$enable_gnutls" = "xyes"; then
23
 
+   AC_LANG_PUSH(C)
24
 
+   AM_PATH_LIBGNUTLS(1.0.0, [AC_DEFINE(HAVE_GNUTLS)], AC_MSG_ERROR([Unable to find GNUTLS]))
25
 
+   LIBGNUTLS_CFLAGS="-DHAVE_GNUTLS $LIBGNUTLS_CFLAGS"
26
 
+   AC_LANG_PUSH(C)
27
 
+fi
28
 
+
29
 
 AC_CHECK_FUNC(vsnprintf,VSNPRINTF_DEFINE='-DHAVE_VSNPRINTF',VSNPRINTF_DEFINE=)
30
 
 AC_SUBST(VSNPRINTF_DEFINE)
31
 
 
32
 
--- vnc-4.0b5-unixsrc/rfb/CSecurity.h.tls       2004-06-11 16:36:08.167300236 +0100
33
 
+++ vnc-4.0b5-unixsrc/rfb/CSecurity.h   2004-06-11 16:36:46.867917908 +0100
34
 
@@ -38,8 +38,14 @@
35
 
   class CConnection;
36
 
   class CSecurity {
37
 
   public:
38
 
+    enum statusEnum {
39
 
+      RFB_SECURITY_ERROR,
40
 
+      RFB_SECURITY_COMPLETED,
41
 
+      RFB_SECURITY_DEFER,
42
 
+      RFB_SECURITY_AUTH_TYPES
43
 
+    };
44
 
     virtual ~CSecurity() {}
45
 
-    virtual bool processMsg(CConnection* cc, bool* done)=0;
46
 
+    virtual statusEnum processMsg(CConnection* cc)=0;
47
 
     virtual void destroy() { delete this; }
48
 
     virtual int getType() const = 0;
49
 
     virtual const char* description() const = 0;
50
 
--- vnc-4.0b5-unixsrc/rfb/CSecurityTLS.cxx.tls  2004-06-11 16:36:36.557351881 +0100
51
 
+++ vnc-4.0b5-unixsrc/rfb/CSecurityTLS.cxx      2004-06-11 16:36:46.868917769 +0100
52
 
@@ -0,0 +1,122 @@
53
 
+/* 
54
 
+ * Copyright (C) 2004 Red Hat Inc.
55
 
+ *    
56
 
+ * This is free software; you can redistribute it and/or modify
57
 
+ * it under the terms of the GNU General Public License as published by
58
 
+ * the Free Software Foundation; either version 2 of the License, or
59
 
+ * (at your option) any later version.
60
 
+ * 
61
 
+ * This software is distributed in the hope that it will be useful,
62
 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
63
 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
64
 
+ * GNU General Public License for more details.
65
 
+ * 
66
 
+ * You should have received a copy of the GNU General Public License
67
 
+ * along with this software; if not, write to the Free Software
68
 
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
69
 
+ * USA.
70
 
+ */
71
 
+
72
 
+#ifdef HAVE_GNUTLS
73
 
+
74
 
+#include <rfb/CSecurityTLS.h>
75
 
+#include <rfb/CConnection.h>
76
 
+#include <rfb/LogWriter.h>
77
 
+#include <rdr/FdInStream.h>
78
 
+#include <rdr/FdOutStream.h>
79
 
+
80
 
+#undef TLS_DEBUG
81
 
+
82
 
+using namespace rfb;
83
 
+
84
 
+static LogWriter vlog("TLS");
85
 
+
86
 
+#ifdef TLS_DEBUG
87
 
+static void debug_log(int level, const char* str)
88
 
+{
89
 
+  vlog.debug(str);
90
 
+}
91
 
+#endif
92
 
+
93
 
+void CSecurityTLS::initGlobal()
94
 
+{
95
 
+  static bool globalInitDone = false;
96
 
+
97
 
+  if (!globalInitDone) {
98
 
+    gnutls_global_init();
99
 
+
100
 
+#ifdef TLS_DEBUG
101
 
+    gnutls_global_set_log_level(10);
102
 
+    gnutls_global_set_log_function(debug_log);
103
 
+#endif
104
 
+
105
 
+    globalInitDone = true;
106
 
+  }
107
 
+}
108
 
+
109
 
+CSecurityTLS::CSecurityTLS() : session(0), anon_cred(0)
110
 
+{
111
 
+}
112
 
+
113
 
+CSecurityTLS::~CSecurityTLS()
114
 
+{
115
 
+  if (session) {
116
 
+    gnutls_bye(session, GNUTLS_SHUT_RDWR);
117
 
+    gnutls_anon_free_client_credentials (anon_cred);
118
 
+    gnutls_deinit (session);
119
 
+  }
120
 
+
121
 
+  /* FIXME: should be doing gnutls_global_deinit() at some point */
122
 
+}
123
 
+
124
 
+CSecurityTLS::statusEnum CSecurityTLS::processMsg(CConnection* cc)
125
 
+{
126
 
+  rdr::FdInStream* is;
127
 
+  rdr::FdOutStream* os;
128
 
+
129
 
+  if ((is = dynamic_cast<rdr::FdInStream*>(cc->getInStream())) == 0) {
130
 
+    vlog.error("Cannot use TLS security type with anything other than FdInStream");
131
 
+    return RFB_SECURITY_ERROR;
132
 
+  }
133
 
+
134
 
+  if ((os = dynamic_cast<rdr::FdOutStream*>(cc->getOutStream())) == 0) {
135
 
+    vlog.error("Cannot use TLS security type with anything other than FdOutStream");
136
 
+    return RFB_SECURITY_ERROR;
137
 
+  }
138
 
+
139
 
+  initGlobal();
140
 
+
141
 
+  gnutls_init(&session, GNUTLS_CLIENT);
142
 
+  gnutls_set_default_priority(session);
143
 
+
144
 
+  int kx_priority[] = { GNUTLS_KX_ANON_DH, 0 };
145
 
+  gnutls_kx_set_priority(session, kx_priority);
146
 
+
147
 
+  gnutls_anon_allocate_client_credentials(&anon_cred);
148
 
+  gnutls_credentials_set(session, GNUTLS_CRD_ANON, anon_cred);
149
 
+
150
 
+  gnutls_transport_set_ptr2(session,
151
 
+                           (gnutls_transport_ptr)is->getFd(),
152
 
+                           (gnutls_transport_ptr)os->getFd());
153
 
+
154
 
+  int err;
155
 
+  do {
156
 
+    err = gnutls_handshake(session);
157
 
+  } while (err != GNUTLS_E_SUCCESS && !gnutls_error_is_fatal(err));
158
 
+
159
 
+  if (err != GNUTLS_E_SUCCESS) {
160
 
+    vlog.error("TLS Handshake failed: %s\n", gnutls_strerror (err));
161
 
+    gnutls_bye(session, GNUTLS_SHUT_RDWR);
162
 
+    gnutls_anon_free_client_credentials(anon_cred);
163
 
+    gnutls_deinit(session);
164
 
+    session = 0;
165
 
+    return RFB_SECURITY_ERROR;
166
 
+  }
167
 
+
168
 
+  is->useTLS(session);
169
 
+  os->useTLS(session);
170
 
+
171
 
+  return RFB_SECURITY_AUTH_TYPES;
172
 
+}
173
 
+
174
 
+#endif /* HAVE_GNUTLS */
175
 
--- vnc-4.0b5-unixsrc/rfb/CConnection.h.tls     2004-06-11 16:36:08.248288973 +0100
176
 
+++ vnc-4.0b5-unixsrc/rfb/CConnection.h 2004-06-11 16:36:46.869917630 +0100
177
 
@@ -59,6 +59,11 @@
178
 
     // first one is most preferred.
179
 
     void addSecType(rdr::U8 secType);
180
 
 
181
 
+    // addAuthType() should be called once for each authentication type which
182
 
+    // the client supports.  The order in which they're added is such that the
183
 
+    // first one is most preferred.
184
 
+    void addAuthType(rdr::U8 authType);
185
 
+
186
 
     // setClientSecTypeOrder() determines whether the client should obey
187
 
     // the server's security type preference, by picking the first server security
188
 
     // type that the client supports, or whether it should pick the first type
189
 
@@ -150,6 +155,7 @@
190
 
   private:
191
 
     void processVersionMsg();
192
 
     void processSecurityTypesMsg();
193
 
+    void processAuthTypesMsg();
194
 
     void processSecurityMsg();
195
 
     void processSecurityResultMsg();
196
 
     void processInitMsg();
197
 
@@ -164,9 +170,11 @@
198
 
     bool deleteStreamsWhenDone;
199
 
     bool shared;
200
 
     CSecurity* security;
201
 
-    enum { maxSecTypes = 8 };
202
 
+    enum { maxSecTypes = 8, maxAuthTypes = 8 };
203
 
     int nSecTypes;
204
 
     rdr::U8 secTypes[maxSecTypes];
205
 
+    int nAuthTypes;
206
 
+    rdr::U8 authTypes[maxAuthTypes];
207
 
     bool clientSecTypeOrder;
208
 
     stateEnum state_;
209
 
 
210
 
--- vnc-4.0b5-unixsrc/rfb/Makefile.in.tls       2004-06-11 16:36:08.250288695 +0100
211
 
+++ vnc-4.0b5-unixsrc/rfb/Makefile.in   2004-06-11 16:36:46.869917630 +0100
212
 
@@ -8,6 +8,7 @@
213
 
   CMsgWriter.cxx \
214
 
   CMsgWriterV3.cxx \
215
 
   CSecurityVncAuth.cxx \
216
 
+  CSecurityTLS.cxx \
217
 
   ComparingUpdateTracker.cxx \
218
 
   Configuration.cxx \
219
 
   ConnParams.cxx \
220
 
@@ -52,7 +53,7 @@
221
 
 
222
 
 OBJS = d3des.o $(CXXSRCS:.cxx=.o)
223
 
 
224
 
-DIR_CPPFLAGS = -I$(top_srcdir) @VSNPRINTF_DEFINE@
225
 
+DIR_CPPFLAGS = -I$(top_srcdir) @VSNPRINTF_DEFINE@ @LIBGNUTLS_CFLAGS@
226
 
 
227
 
 library = librfb.a
228
 
 
229
 
@@ -63,4 +64,6 @@
230
 
        $(AR) $(library) $(OBJS)
231
 
        $(RANLIB) $(library)
232
 
 
233
 
+DIR_CFLAGS = -DPIC -fPIC
234
 
+DIR_CXXFLAGS = -DPIC -fPIC
235
 
 # followed by boilerplate.mk
236
 
--- vnc-4.0b5-unixsrc/rfb/CSecurityVncAuth.cxx.tls      2004-06-11 16:36:08.252288416 +0100
237
 
+++ vnc-4.0b5-unixsrc/rfb/CSecurityVncAuth.cxx  2004-06-11 16:36:46.869917630 +0100
238
 
@@ -41,9 +41,8 @@
239
 
 {
240
 
 }
241
 
 
242
 
-bool CSecurityVncAuth::processMsg(CConnection* cc, bool* done)
243
 
+CSecurity::statusEnum CSecurityVncAuth::processMsg(CConnection* cc)
244
 
 {
245
 
-  *done = false;
246
 
   rdr::InStream* is = cc->getInStream();
247
 
   rdr::OutStream* os = cc->getOutStream();
248
 
 
249
 
@@ -52,12 +51,11 @@
250
 
   CharArray passwd;
251
 
   if (!upg->getUserPasswd(0, &passwd.buf)) {
252
 
     vlog.error("Getting password failed");
253
 
-    return false;
254
 
+    return RFB_SECURITY_ERROR;
255
 
   }
256
 
   vncAuthEncryptChallenge(challenge, passwd.buf);
257
 
   memset(passwd.buf, 0, strlen(passwd.buf));
258
 
   os->writeBytes(challenge, vncAuthChallengeSize);
259
 
   os->flush();
260
 
-  *done = true;
261
 
-  return true;
262
 
+  return RFB_SECURITY_COMPLETED;
263
 
 }
264
 
--- vnc-4.0b5-unixsrc/rfb/secTypes.cxx.tls      2004-06-11 16:36:08.254288138 +0100
265
 
+++ vnc-4.0b5-unixsrc/rfb/secTypes.cxx  2004-06-11 16:36:46.870917491 +0100
266
 
@@ -28,6 +28,7 @@
267
 
   if (strcasecmp(name, "VncAuth") == 0)    return secTypeVncAuth;
268
 
   if (strcasecmp(name, "RA2") == 0)        return secTypeRA2;
269
 
   if (strcasecmp(name, "RA2ne") == 0)      return secTypeRA2ne;
270
 
+  if (strcasecmp(name, "TLS") == 0)        return secTypeTLS;
271
 
   return secTypeInvalid;
272
 
 }
273
 
 
274
 
@@ -38,6 +39,7 @@
275
 
   case secTypeVncAuth:    return "VncAuth";
276
 
   case secTypeRA2:        return "RA2";
277
 
   case secTypeRA2ne:      return "RA2ne";
278
 
+  case secTypeTLS:        return "TLS";
279
 
   default:                return "[unknown secType]";
280
 
   }
281
 
 }
282
 
@@ -46,6 +48,7 @@
283
 
 {
284
 
   switch (num) {
285
 
   case secTypeRA2:        return true;
286
 
+  case secTypeTLS:        return true;
287
 
   default:                return false;
288
 
   }
289
 
 }
290
 
--- vnc-4.0b5-unixsrc/rfb/CSecurityTLS.h.tls    2004-06-11 16:36:31.135105991 +0100
291
 
+++ vnc-4.0b5-unixsrc/rfb/CSecurityTLS.h        2004-06-11 16:36:46.870917491 +0100
292
 
@@ -0,0 +1,48 @@
293
 
+/* 
294
 
+ * Copyright (C) 2004 Red Hat Inc.
295
 
+ *    
296
 
+ * This is free software; you can redistribute it and/or modify
297
 
+ * it under the terms of the GNU General Public License as published by
298
 
+ * the Free Software Foundation; either version 2 of the License, or
299
 
+ * (at your option) any later version.
300
 
+ * 
301
 
+ * This software is distributed in the hope that it will be useful,
302
 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
303
 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
304
 
+ * GNU General Public License for more details.
305
 
+ * 
306
 
+ * You should have received a copy of the GNU General Public License
307
 
+ * along with this software; if not, write to the Free Software
308
 
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
309
 
+ * USA.
310
 
+ */
311
 
+
312
 
+#ifndef __C_SECURITY_TLS_H__
313
 
+#define __C_SECURITY_TLS_H__
314
 
+
315
 
+#ifdef HAVE_GNUTLS
316
 
+
317
 
+#include <rfb/CSecurity.h>
318
 
+#include <rfb/secTypes.h>
319
 
+#include <gnutls/gnutls.h>
320
 
+
321
 
+namespace rfb {
322
 
+  class CSecurityTLS : public CSecurity {
323
 
+  public:
324
 
+    CSecurityTLS();
325
 
+    virtual ~CSecurityTLS();
326
 
+    virtual statusEnum processMsg(CConnection* cc);
327
 
+    virtual int getType() const { return secTypeTLS; };
328
 
+    virtual const char* description() const { return "TLS Encryption"; }
329
 
+
330
 
+  private:
331
 
+    static void initGlobal();
332
 
+
333
 
+    gnutls_session session;
334
 
+    gnutls_anon_server_credentials anon_cred;
335
 
+  };
336
 
+}
337
 
+
338
 
+#endif /* HAVE_GNUTLS */
339
 
+
340
 
+#endif /* __C_SECURITY_TLS_H__ */
341
 
--- vnc-4.0b5-unixsrc/rfb/CSecurityNone.h.tls   2004-06-11 16:36:08.312280073 +0100
342
 
+++ vnc-4.0b5-unixsrc/rfb/CSecurityNone.h       2004-06-11 16:36:46.871917352 +0100
343
 
@@ -28,8 +28,8 @@
344
 
 
345
 
   class CSecurityNone : public CSecurity {
346
 
   public:
347
 
-    virtual bool processMsg(CConnection* cc, bool* done) {
348
 
-      *done = true; return true;
349
 
+    virtual statusEnum processMsg(CConnection* cc) {
350
 
+      return RFB_SECURITY_COMPLETED;
351
 
     }
352
 
     virtual int getType() const {return secTypeNone;}
353
 
     virtual const char* description() const {return "No Encryption";}
354
 
--- vnc-4.0b5-unixsrc/rfb/CConnection.cxx.tls   2004-06-11 16:36:08.315279656 +0100
355
 
+++ vnc-4.0b5-unixsrc/rfb/CConnection.cxx       2004-06-11 16:36:46.980902194 +0100
356
 
@@ -33,7 +33,8 @@
357
 
 
358
 
 CConnection::CConnection()
359
 
   : is(0), os(0), reader_(0), writer_(0),
360
 
-    shared(false), security(0), nSecTypes(0), clientSecTypeOrder(false),
361
 
+    shared(false), security(0),
362
 
+    nSecTypes(0), nAuthTypes(0), clientSecTypeOrder(false),
363
 
     state_(RFBSTATE_UNINITIALISED), useProtocol3_3(false)
364
 
 {
365
 
 }
366
 
@@ -64,11 +65,19 @@
367
 
 
368
 
 void CConnection::addSecType(rdr::U8 secType)
369
 
 {
370
 
+  vlog.debug("adding %d", secType);
371
 
   if (nSecTypes == maxSecTypes)
372
 
     throw Exception("too many security types");
373
 
   secTypes[nSecTypes++] = secType;
374
 
 }
375
 
 
376
 
+void CConnection::addAuthType(rdr::U8 authType)
377
 
+{
378
 
+  if (nAuthTypes == maxAuthTypes)
379
 
+    throw Exception("too many authentication types");
380
 
+  authTypes[nAuthTypes++] = authType;
381
 
+}
382
 
+
383
 
 void CConnection::setClientSecTypeOrder(bool clientOrder) {
384
 
   clientSecTypeOrder = clientOrder;
385
 
 }
386
 
@@ -204,15 +213,72 @@
387
 
   processSecurityMsg();
388
 
 }
389
 
 
390
 
+void CConnection::processAuthTypesMsg()
391
 
+{
392
 
+  vlog.debug("processing authentication types message");
393
 
+
394
 
+  int authType = secTypeInvalid;
395
 
+
396
 
+  int nServerAuthTypes = is->readU8();
397
 
+  if (nServerAuthTypes == 0)
398
 
+    throwConnFailedException();
399
 
+
400
 
+  int authTypePos = nAuthTypes;
401
 
+  for (int i = 0; i < nServerAuthTypes; i++) {
402
 
+    rdr::U8 serverAuthType = is->readU8();
403
 
+    vlog.debug("Server offers security type %s(%d)",
404
 
+              secTypeName(serverAuthType),serverAuthType);
405
 
+
406
 
+    // If we haven't already chosen a authType, try this one
407
 
+    // If we are using the client's preference for types,
408
 
+    // we keep trying types, to find the one that matches and
409
 
+    // which appears first in the client's list of supported types.
410
 
+    if (authType == secTypeInvalid || clientSecTypeOrder) {
411
 
+      for (int j = 0; j < nAuthTypes; j++) {
412
 
+       if (authTypes[j] == serverAuthType && j < authTypePos) {
413
 
+         authType = authTypes[j];
414
 
+         authTypePos = j;
415
 
+         break;
416
 
+       }
417
 
+      }
418
 
+      // NB: Continue reading the remaining server authTypes, but ignore them
419
 
+    }
420
 
+  }
421
 
+
422
 
+  // Inform the server of our decision
423
 
+  if (authType != secTypeInvalid) {
424
 
+    os->writeU8(authType);
425
 
+    os->flush();
426
 
+    vlog.debug("Choosing authentication type %s(%d)",secTypeName(authType),authType);
427
 
+  }
428
 
+
429
 
+  if (authType == secTypeInvalid) {
430
 
+    state_ = RFBSTATE_INVALID;
431
 
+    vlog.error("No matching authentication types");
432
 
+    throw Exception("No matching authentication types");
433
 
+  }
434
 
+
435
 
+  security = getCSecurity(authType);
436
 
+  processSecurityMsg();
437
 
+}
438
 
+
439
 
 void CConnection::processSecurityMsg()
440
 
 {
441
 
   vlog.debug("processing security message");
442
 
-  bool done;
443
 
-  if (!security->processMsg(this, &done))
444
 
+  switch (security->processMsg(this)) {
445
 
+  case CSecurity::RFB_SECURITY_ERROR:
446
 
     throwAuthFailureException();
447
 
-  if (done) {
448
 
+  case CSecurity::RFB_SECURITY_COMPLETED:
449
 
     state_ = RFBSTATE_SECURITY_RESULT;
450
 
     processSecurityResultMsg();
451
 
+    break;
452
 
+  case CSecurity::RFB_SECURITY_DEFER:
453
 
+    break;
454
 
+  case CSecurity::RFB_SECURITY_AUTH_TYPES:
455
 
+    processAuthTypesMsg();
456
 
+    break;
457
 
+  default:
458
 
+    throw Exception("CConnection::processSecurityMsg: invalid security status");
459
 
   }
460
 
 }
461
 
 
462
 
--- vnc-4.0b5-unixsrc/rfb/CSecurityVncAuth.h.tls        2004-06-11 16:36:08.317279378 +0100
463
 
+++ vnc-4.0b5-unixsrc/rfb/CSecurityVncAuth.h    2004-06-11 16:36:46.980902194 +0100
464
 
@@ -30,7 +30,7 @@
465
 
   public:
466
 
     CSecurityVncAuth(UserPasswdGetter* pg);
467
 
     virtual ~CSecurityVncAuth();
468
 
-    virtual bool processMsg(CConnection* cc, bool* done);
469
 
+    virtual statusEnum processMsg(CConnection* cc);
470
 
     virtual int getType() const {return secTypeVncAuth;};
471
 
     virtual const char* description() const {return "No Encryption";}
472
 
   private:
473
 
--- vnc-4.0b5-unixsrc/network/Makefile.in.tls   2004-06-11 16:36:08.319279100 +0100
474
 
+++ vnc-4.0b5-unixsrc/network/Makefile.in       2004-06-11 16:36:46.981902055 +0100
475
 
@@ -3,7 +3,7 @@
476
 
 
477
 
 OBJS = $(SRCS:.cxx=.o)
478
 
 
479
 
-DIR_CPPFLAGS = -I$(top_srcdir) @SOCKLEN_T_DEFINE@
480
 
+DIR_CPPFLAGS = -I$(top_srcdir) @SOCKLEN_T_DEFINE@ @LIBGNUTLS_CFLAGS@
481
 
 
482
 
 library = libnetwork.a
483
 
 
484
 
@@ -14,4 +14,5 @@
485
 
        $(AR) $(library) $(OBJS)
486
 
        $(RANLIB) $(library)
487
 
 
488
 
+DIR_CXXFLAGS = -DPIC -fPIC
489
 
 # followed by boilerplate.mk
490
 
--- vnc-4.0b5-unixsrc/vncconfig/Makefile.in.tls 2004-06-11 16:36:08.322278683 +0100
491
 
+++ vnc-4.0b5-unixsrc/vncconfig/Makefile.in     2004-06-11 16:36:47.034894685 +0100
492
 
@@ -8,9 +8,9 @@
493
 
 DEP_LIBS = ../tx/libtx.a ../rfb/librfb.a ../network/libnetwork.a \
494
 
            ../rdr/librdr.a
495
 
 
496
 
-EXTRA_LIBS = @X_PRE_LIBS@ @X_LIBS@ -lX11 -lXext @X_EXTRA_LIBS@
497
 
+EXTRA_LIBS = @X_PRE_LIBS@ @X_LIBS@ -lX11 -lXext @X_EXTRA_LIBS@ @LIBGNUTLS_LIBS@
498
 
 
499
 
-DIR_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/tx @X_CFLAGS@ # X_CFLAGS are really CPPFLAGS
500
 
+DIR_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/tx @X_CFLAGS@ @LIBGNUTLS_CFLAGS@ # X_CFLAGS are really CPPFLAGS
501
 
 
502
 
 all:: $(program)
503
 
 
504
 
--- vnc-4.0b5-unixsrc/rdr/FdInStream.h.tls      2004-06-11 16:36:08.324278405 +0100
505
 
+++ vnc-4.0b5-unixsrc/rdr/FdInStream.h  2004-06-11 16:36:47.035894546 +0100
506
 
@@ -25,6 +25,10 @@
507
 
 
508
 
 #include <rdr/InStream.h>
509
 
 
510
 
+#ifdef HAVE_GNUTLS
511
 
+#include <gnutls/gnutls.h>
512
 
+#endif
513
 
+
514
 
 namespace rdr {
515
 
 
516
 
   class FdInStreamBlockCallback {
517
 
@@ -47,6 +51,10 @@
518
 
     int pos();
519
 
     void readBytes(void* data, int length);
520
 
 
521
 
+#ifdef HAVE_GNUTLS
522
 
+    void useTLS(gnutls_session session);
523
 
+#endif
524
 
+
525
 
     void startTiming();
526
 
     void stopTiming();
527
 
     unsigned int kbitsPerSecond();
528
 
@@ -63,6 +71,10 @@
529
 
     int timeoutms;
530
 
     FdInStreamBlockCallback* blockCallback;
531
 
 
532
 
+#ifdef HAVE_GNUTLS
533
 
+    gnutls_session tlsSession;
534
 
+#endif
535
 
+
536
 
     bool timing;
537
 
     unsigned int timeWaitedIn100us;
538
 
     unsigned int timedKbits;
539
 
--- vnc-4.0b5-unixsrc/rdr/FdOutStream.cxx.tls   2004-06-11 16:36:08.327277987 +0100
540
 
+++ vnc-4.0b5-unixsrc/rdr/FdOutStream.cxx       2004-06-11 16:36:47.035894546 +0100
541
 
@@ -45,6 +45,9 @@
542
 
 FdOutStream::FdOutStream(int fd_, int timeoutms_, int bufSize_)
543
 
   : fd(fd_), timeoutms(timeoutms_),
544
 
     bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
545
 
+#ifdef HAVE_GNUTLS
546
 
+    ,tlsSession(0)
547
 
+#endif
548
 
 {
549
 
   ptr = start = new U8[bufSize];
550
 
   end = start + bufSize;
551
 
@@ -113,6 +116,13 @@
552
 
   return nItems;
553
 
 }
554
 
 
555
 
+#ifdef HAVE_GNUTLS
556
 
+void FdOutStream::useTLS(gnutls_session session)
557
 
+{
558
 
+  tlsSession = session;
559
 
+}
560
 
+#endif
561
 
+
562
 
 //
563
 
 // writeWithTimeout() writes up to the given length in bytes from the given
564
 
 // buffer to the file descriptor.  If there is a timeout set and that timeout
565
 
@@ -127,7 +137,9 @@
566
 
 {
567
 
   int n;
568
 
 
569
 
+#ifndef HAVE_GNUTLS
570
 
   do {
571
 
+#endif
572
 
 
573
 
     do {
574
 
       fd_set fds;
575
 
@@ -159,15 +171,32 @@
576
 
 
577
 
     if (n == 0) throw TimedOut();
578
 
 
579
 
-    do {
580
 
-      n = ::write(fd, data, length);
581
 
-    } while (n < 0 && (errno == EINTR));
582
 
+#ifdef HAVE_GNUTLS
583
 
+    if (!tlsSession) {
584
 
+#endif
585
 
+
586
 
+      do {
587
 
+       n = ::write(fd, data, length);
588
 
+      } while (n < 0 && (errno == EINTR));
589
 
+
590
 
+#ifdef HAVE_GNUTLS
591
 
+    } else {
592
 
+
593
 
+      do {
594
 
+       n = gnutls_record_send(tlsSession, data, length);
595
 
+      } while (n == GNUTLS_E_INTERRUPTED);
596
 
+      
597
 
+      if (n < 0) throw TLSException("send",n);
598
 
+    }
599
 
+#else
600
 
       
601
 
     // NB: This outer loop simply fixes a broken Winsock2 EWOULDBLOCK
602
 
     // condition, found only under Win98 (first edition), with slow
603
 
     // network connections.  Should in fact never ever happen...
604
 
   } while (n < 0 && (errno == EWOULDBLOCK));
605
 
 
606
 
+#endif /* HAVE_GNUTLS */
607
 
+
608
 
   if (n < 0) throw SystemException("write",errno);
609
 
 
610
 
   return n;
611
 
--- vnc-4.0b5-unixsrc/rdr/FdOutStream.h.tls     2004-06-11 16:36:08.329277709 +0100
612
 
+++ vnc-4.0b5-unixsrc/rdr/FdOutStream.h 2004-06-11 16:36:47.088887176 +0100
613
 
@@ -25,6 +25,10 @@
614
 
 
615
 
 #include <rdr/OutStream.h>
616
 
 
617
 
+#ifdef HAVE_GNUTLS
618
 
+#include <gnutls/gnutls.h>
619
 
+#endif
620
 
+
621
 
 namespace rdr {
622
 
 
623
 
   class FdOutStream : public OutStream {
624
 
@@ -41,6 +45,10 @@
625
 
     int length();
626
 
     void writeBytes(const void* data, int length);
627
 
 
628
 
+#ifdef HAVE_GNUTLS
629
 
+    void useTLS(gnutls_session session);
630
 
+#endif
631
 
+
632
 
   private:
633
 
     int overrun(int itemSize, int nItems);
634
 
     int writeWithTimeout(const void* data, int length);
635
 
@@ -49,6 +57,10 @@
636
 
     int bufSize;
637
 
     int offset;
638
 
     U8* start;
639
 
+
640
 
+#ifdef HAVE_GNUTLS
641
 
+    gnutls_session tlsSession;
642
 
+#endif
643
 
   };
644
 
 
645
 
 }
646
 
--- vnc-4.0b5-unixsrc/rdr/Makefile.in.tls       2004-06-11 16:36:08.331277431 +0100
647
 
+++ vnc-4.0b5-unixsrc/rdr/Makefile.in   2004-06-11 16:36:47.089887037 +0100
648
 
@@ -5,7 +5,7 @@
649
 
 
650
 
 OBJS = $(SRCS:.cxx=.o)
651
 
 
652
 
-DIR_CPPFLAGS = -I$(top_srcdir) @ZLIB_INCLUDE@
653
 
+DIR_CPPFLAGS = -I$(top_srcdir) @ZLIB_INCLUDE@ @LIBGNUTLS_CFLAGS@
654
 
 
655
 
 library = librdr.a
656
 
 
657
 
--- vnc-4.0b5-unixsrc/rdr/Exception.cxx.tls     2004-06-11 16:36:08.333277153 +0100
658
 
+++ vnc-4.0b5-unixsrc/rdr/Exception.cxx 2004-06-11 16:36:47.089887037 +0100
659
 
@@ -62,3 +62,17 @@
660
 
   strncat(str_, buf, len-1-strlen(str_));
661
 
   strncat(str_, ")", len-1-strlen(str_));
662
 
 }
663
 
+
664
 
+#ifdef HAVE_GNUTLS
665
 
+TLSException::TLSException(const char* s, int err_)
666
 
+  : Exception(s, "rdr::TLSException"), err(err_)
667
 
+{
668
 
+  strncat(str_, ": ", len-1-strlen(str_));
669
 
+  strncat(str_, gnutls_strerror(err), len-1-strlen(str_));
670
 
+  strncat(str_, " (", len-1-strlen(str_));
671
 
+  char buf[20];
672
 
+  sprintf(buf,"%d",err);
673
 
+  strncat(str_, buf, len-1-strlen(str_));
674
 
+  strncat(str_, ")", len-1-strlen(str_));
675
 
+}
676
 
+#endif /* HAVE_GNUTLS */
677
 
--- vnc-4.0b5-unixsrc/rdr/FdInStream.cxx.tls    2004-06-11 16:36:08.335276875 +0100
678
 
+++ vnc-4.0b5-unixsrc/rdr/FdInStream.cxx        2004-06-11 16:36:47.142879667 +0100
679
 
@@ -53,6 +53,9 @@
680
 
                        bool closeWhenDone_)
681
 
   : fd(fd_), closeWhenDone(closeWhenDone_),
682
 
     timeoutms(timeoutms_), blockCallback(0),
683
 
+#ifdef HAVE_GNUTLS
684
 
+    tlsSession(0),
685
 
+#endif
686
 
     timing(false), timeWaitedIn100us(5), timedKbits(0),
687
 
     bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
688
 
 {
689
 
@@ -169,6 +172,13 @@
690
 
 }
691
 
 #endif
692
 
 
693
 
+#ifdef HAVE_GNUTLS
694
 
+void FdInStream::useTLS(gnutls_session session)
695
 
+{
696
 
+  tlsSession = session;
697
 
+}
698
 
+#endif
699
 
+
700
 
 //
701
 
 // readWithTimeoutOrCallback() reads up to the given length in bytes from the
702
 
 // file descriptor into a buffer.  If the wait argument is false, then zero is
703
 
@@ -217,12 +227,29 @@
704
 
     blockCallback->blockCallback();
705
 
   }
706
 
 
707
 
-  do {
708
 
-    n = ::read(fd, buf, len);
709
 
-  } while (n < 0 && errno == EINTR);
710
 
+#ifdef HAVE_GNUTLS
711
 
+  if (!tlsSession) {
712
 
+#endif
713
 
+
714
 
+    do {
715
 
+      n = ::read(fd, buf, len);
716
 
+    } while (n < 0 && errno == EINTR);
717
 
 
718
 
-  if (n < 0) throw SystemException("read",errno);
719
 
-  if (n == 0) throw EndOfStream();
720
 
+    if (n < 0) throw SystemException("read",errno);
721
 
+    if (n == 0) throw EndOfStream();
722
 
+
723
 
+#ifdef HAVE_GNUTLS
724
 
+  } else {
725
 
+
726
 
+    do {
727
 
+      n = gnutls_record_recv(tlsSession, buf, len);
728
 
+    } while (n == GNUTLS_E_INTERRUPTED);
729
 
+
730
 
+    if (n < 0) throw TLSException("recv",n);
731
 
+    if (n == 0) throw EndOfStream();
732
 
+
733
 
+  }
734
 
+#endif
735
 
 
736
 
   if (timing) {
737
 
     gettimeofday(&after, 0);
738
 
--- vnc-4.0b5-unixsrc/rdr/Exception.h.tls       2004-06-11 16:36:08.337276597 +0100
739
 
+++ vnc-4.0b5-unixsrc/rdr/Exception.h   2004-06-11 16:36:47.143879528 +0100
740
 
@@ -22,6 +22,10 @@
741
 
 #include <stdio.h>
742
 
 #include <string.h>
743
 
 
744
 
+#ifdef HAVE_GNUTLS
745
 
+#include <gnutls/gnutls.h>
746
 
+#endif
747
 
+
748
 
 namespace rdr {
749
 
 
750
 
   struct Exception {
751
 
@@ -44,7 +48,7 @@
752
 
   struct SystemException : public Exception {
753
 
     int err;
754
 
     SystemException(const char* s, int err_);
755
 
-  }; 
756
 
+  };
757
 
 
758
 
   struct TimedOut : public Exception {
759
 
     TimedOut(const char* s="Timed out") : Exception(s,"rdr::TimedOut") {}
760
 
@@ -54,6 +58,13 @@
761
 
     EndOfStream(const char* s="End of stream")
762
 
       : Exception(s,"rdr::EndOfStream") {}
763
 
   };
764
 
+
765
 
+#ifdef HAVE_GNUTLS
766
 
+  struct TLSException : public Exception {
767
 
+    int err;
768
 
+    TLSException(const char* s, int err_);
769
 
+  };
770
 
+#endif
771
 
 }
772
 
 
773
 
 #endif
774
 
--- vnc-4.0b5-unixsrc/vncviewer/Makefile.in.tls 2004-06-11 16:36:08.339276319 +0100
775
 
+++ vnc-4.0b5-unixsrc/vncviewer/Makefile.in     2004-06-11 16:36:47.144879388 +0100
776
 
@@ -8,9 +8,9 @@
777
 
 DEP_LIBS = ../tx/libtx.a ../rfb/librfb.a ../network/libnetwork.a \
778
 
            ../rdr/librdr.a
779
 
 
780
 
-EXTRA_LIBS = @ZLIB_LIB@ @X_PRE_LIBS@ @X_LIBS@ -lXext -lX11 @X_EXTRA_LIBS@
781
 
+EXTRA_LIBS = @ZLIB_LIB@ @X_PRE_LIBS@ @X_LIBS@ -lXext -lX11 @X_EXTRA_LIBS@ @LIBGNUTLS_LIBS@
782
 
 
783
 
-DIR_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/tx @X_CFLAGS@ # X_CFLAGS are really CPPFLAGS
784
 
+DIR_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/tx @X_CFLAGS@ @LIBGNUTLS_CFLAGS@ # X_CFLAGS are really CPPFLAGS
785
 
 
786
 
 all:: $(program)
787
 
 
788
 
--- vnc-4.0b5-unixsrc/vncviewer/CConn.cxx.tls   2004-06-11 16:36:08.341276041 +0100
789
 
+++ vnc-4.0b5-unixsrc/vncviewer/CConn.cxx       2004-06-11 16:36:47.201871462 +0100
790
 
@@ -26,6 +26,7 @@
791
 
 #include <rfb/secTypes.h>
792
 
 #include <rfb/CSecurityNone.h>
793
 
 #include <rfb/CSecurityVncAuth.h>
794
 
+#include <rfb/CSecurityTLS.h>
795
 
 #include <rfb/Hostname.h>
796
 
 #include <rfb/LogWriter.h>
797
 
 #include <rfb/util.h>
798
 
@@ -64,8 +65,16 @@
799
 
   menuKeysym = XStringToKeysym(menuKeyStr.buf);
800
 
 
801
 
   setShared(shared);
802
 
+
803
 
+#ifdef HAVE_GNUTLS
804
 
+  addSecType(secTypeTLS);
805
 
+#endif
806
 
   addSecType(secTypeNone);
807
 
   addSecType(secTypeVncAuth);
808
 
+
809
 
+  addAuthType(secTypeNone);
810
 
+  addAuthType(secTypeVncAuth);
811
 
+
812
 
   CharArray encStr(preferredEncoding.getData());
813
 
   int encNum = encodingNum(encStr.buf);
814
 
   if (encNum != -1) {
815
 
@@ -216,6 +225,10 @@
816
 
     return new CSecurityNone();
817
 
   case secTypeVncAuth:
818
 
     return new CSecurityVncAuth(this);
819
 
+#ifdef HAVE_GNUTLS
820
 
+  case secTypeTLS:
821
 
+    return new CSecurityTLS();
822
 
+#endif
823
 
   default:
824
 
     throw rfb::Exception("Unsupported secType?");
825
 
   }
826
 
--- vnc-4.0b5-unixsrc/tx/Makefile.in.tls        2004-06-11 16:36:08.392268949 +0100
827
 
+++ vnc-4.0b5-unixsrc/tx/Makefile.in    2004-06-11 16:36:47.202871323 +0100
828
 
@@ -4,7 +4,7 @@
829
 
 
830
 
 OBJS = $(SRCS:.cxx=.o)
831
 
 
832
 
-DIR_CPPFLAGS = -I$(top_srcdir) @X_CFLAGS@ # X_CFLAGS are really CPPFLAGS
833
 
+DIR_CPPFLAGS = -I$(top_srcdir) @X_CFLAGS@ @LIBGNUTLS_CFLAGS@ # X_CFLAGS are really CPPFLAGS
834
 
 
835
 
 library = libtx.a
836