12 static char version33[VerLen+1] = "RFB 003.003\n";
13 static char version38[VerLen+1] = "RFB 003.008\n";
14 static int srvversion;
17 vncsrvhandshake(Vnc *v)
21 strecpy(msg, msg+sizeof msg, version33);
23 fprint(2, "server version: %s\n", msg);
24 vncwrbytes(v, msg, VerLen);
27 vncrdbytes(v, msg, VerLen);
29 fprint(2, "client version: %s\n", msg);
39 vncrdbytes(v, msg, VerLen);
40 if(strncmp(msg, "RFB 003.", 8) != 0 ||
41 strncmp(msg, "RFB 003.007\n", VerLen) == 0){
42 werrstr("bad rfb version \"%s\"", msg);
45 if(strncmp(msg, "RFB 003.008\n", VerLen) == 0)
51 fprint(2, "server version: %s\n", msg);
52 strcpy(msg, version38);
53 vncwrbytes(v, msg, VerLen);
64 ntypes = vncrdchar(v);
66 werrstr("no security types from server");
70 /* choose the "most secure" security type */
72 for(i = 0; i < ntypes; i++){
75 fprint(2, "auth type %s\n",
76 type == AFailed ? "Invalid" :
77 type == ANoAuth ? "None" :
78 type == AVncAuth ? "VNC" : "Unknown");
80 if(type > auth && type <= AVncAuth)
87 vncauth(Vnc *v, char *keypattern)
90 uchar chal[VncChalLen];
96 auth = srvversion == 38 ? sectype38(v) : vncrdlong(v);
100 werrstr("unknown auth type 0x%lux", auth);
102 fprint(2, "unknown auth type 0x%lux\n", auth);
107 reason = vncrdstring(v);
108 werrstr("%s", reason);
110 fprint(2, "auth failed: %s\n", reason);
114 if(srvversion == 38){
119 fprint(2, "no auth needed\n");
123 if(srvversion == 38){
128 vncrdbytes(v, chal, VncChalLen);
129 if(auth_respond(chal, VncChalLen, nil, 0, chal, VncChalLen, auth_getkey,
130 "proto=vnc role=client server=%s %s", serveraddr, keypattern) != VncChalLen){
133 vncwrbytes(v, chal, VncChalLen);
138 /* in version 3.8 the auth status is always sent, in 3.3 only in AVncAuth */
139 if(srvversion == 38 || auth == AVncAuth){
140 auth = vncrdlong(v); /* auth status */
143 werrstr("unknown server response 0x%lux", auth);
146 if (srvversion == 38)
149 werrstr("server says authentication failed");
152 werrstr("server says too many tries");
167 if((c = auth_challenge("proto=vnc role=server user=%q", getuser()))==nil)
168 sysfatal("vncchal: %r");
169 if(c->nchal != VncChalLen)
170 sysfatal("vncchal got %d bytes wanted %d", c->nchal, VncChalLen);
171 vncwrlong(v, AVncAuth);
172 vncwrbytes(v, c->chal, VncChalLen);
175 vncrdbytes(v, c->chal, VncChalLen);
177 c->nresp = VncChalLen;
178 ai = auth_response(c);
181 fprint(2, "vnc auth failed: server factotum: %r\n");
182 vncwrlong(v, VncAuthFailed);
187 vncwrlong(v, VncAuthOK);