/[winpt]/trunk/Src/wptKeyserver.cpp
ViewVC logotype

Diff of /trunk/Src/wptKeyserver.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 214 by twoaday, Sun May 14 18:40:36 2006 UTC revision 271 by twoaday, Sun Nov 5 08:57:45 2006 UTC
# Line 29  Line 29 
29  #include <sys/stat.h>  #include <sys/stat.h>
30  #include <ctype.h>  #include <ctype.h>
31    
32    #include "wptGPG.h"
33  #include "wptKeyserver.h"  #include "wptKeyserver.h"
34  #include "wptErrors.h"  #include "wptErrors.h"
35  #include "wptTypes.h"  #include "wptTypes.h"
36  #include "wptNLS.h"  #include "wptNLS.h"
37  #include "wptW32API.h"  #include "wptW32API.h"
 #include "wptGPG.h"  
38  #include "wptRegistry.h"  #include "wptRegistry.h"
39    #include "wptUTF8.h"
40    
41  /* Map net_errno to a winsock error. */  /* Map net_errno to a winsock error. */
42  #define net_errno ((int)WSAGetLastError ())  #define net_errno ((int)WSAGetLastError ())
# Line 44  Line 45 
45  keyserver server[MAX_KEYSERVERS] = {0};  keyserver server[MAX_KEYSERVERS] = {0};
46  keyserver_proxy_s proxy = {0};  keyserver_proxy_s proxy = {0};
47  static const char *server_list[] = {  static const char *server_list[] = {
     "hkp://gnv.us.ks.cryptnet.net",  
     "hkp://keyserver.kjsl.com",  
48      "hkp://sks.keyserver.penguin.de",      "hkp://sks.keyserver.penguin.de",
49      "hkp://subkeys.pgp.net",      "hkp://subkeys.pgp.net",
50      "ldap://keyserver.pgp.com",      "ldap://keyserver.pgp.com",
# Line 84  base64_encode (const char *inbuf, char * Line 83  base64_encode (const char *inbuf, char *
83      char base64code[] =      char base64code[] =
84          "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";          "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
85      int index = 0, temp = 0, res = 0;      int index = 0, temp = 0, res = 0;
86      int i = 0, inputlen = 0, len = 0;      int i, inputlen, len = 0;
87            
88      inputlen = strlen (inbuf);      inputlen = strlen (inbuf);
89      for (i = 0; i < inputlen; i++) {      for (i = 0; i < inputlen; i++) {
# Line 122  base64_encode (const char *inbuf, char * Line 121  base64_encode (const char *inbuf, char *
121  }  }
122    
123    
124    /* Check that the given buffer contains a valid keyserver URL
125       and return the prefix length, 0 in case of an error. */
126    static int
127    check_URL (const char *buf)
128    {
129        const char *proto[] = {
130            "ldap://",
131            "http://",
132            "finger://",
133            "hkp://",
134            NULL};
135        int i;
136    
137        if (strlen (buf) < 7)
138            return 0;
139    
140        for (i=0; proto[i] != NULL; i++) {
141            if (strstr (buf, proto[i]))
142                return strlen (proto[i]);
143        }
144        return 0;
145    }
146    
147    
148  /* Skip the URL schema and return only the host part of it. */  /* Skip the URL schema and return only the host part of it. */
149  static const char*  static const char*
150  skip_type_prefix (const char *hostname)  skip_type_prefix (const char *hostname)
151  {  {
152      if (hostname && !strncmp (hostname, "http://", 7))      int pos;
153          hostname += 7;  
154      else if (hostname && !strncmp (hostname, "hkp://", 6))      if (!hostname)
155          hostname += 6;          return hostname;
156      else if (hostname && !strncmp (hostname, "finger://", 9))  
157          hostname += 9;      pos = check_URL (hostname);
158      else if (hostname && !strncmp (hostname, "ldap://", 7))      if (pos > 0)
159          hostname += 7;          hostname += pos;
160      return hostname;      return hostname;
161  }  }
162    
163    /* Parse the keyserver response and extract the human
164       readable text passages. */
165    static int
166    parse_keyserver_error (const char *resp, char *txt, size_t txtlen)
167    {
168        char *p, *p2;
169    
170        /* If we find no 'Error' substring, we assume a success. */
171        if (!stristr (resp, "Error"))
172            return -1;
173    
174        memset (txt, 0, txtlen);
175        p = strstr (resp, "\r\n\r\n");
176        if (!p)
177            return -1;
178        resp += (p-resp);
179        p = strstr (resp, "<h1>");
180        if (!p)
181            return -1;
182        resp += (p-resp)+strlen ("<h1>");
183        p = strstr (resp, "</h1>");
184        if (!p)
185            return -1;
186        resp += (p-resp)+strlen ("</h1>");
187        p2 = strstr (resp, "</body>");
188        if (p2 != NULL)
189            memcpy (txt, resp, (p2-resp));
190        else {
191            if (!strnicmp (resp, "<p>", 3))
192                resp += 3;
193            while (resp && *resp == '\r' || *resp == '\n')
194                resp++;
195            memcpy (txt, resp, strlen (resp));
196        }
197        return 0;
198    }
199    
200    
201  /* Check that the keyserver response indicates an OK.  /* Check that the keyserver response indicates an OK.
202     Return 0 on success. */     Return 0 on success. */
203  static int  static int
204  check_hkp_response (const char *resp, int recv)  check_hkp_response (const char *resp, int recv)
205  {      {
206      char *p, *end;      int ec;
     int ec, len;  
207    
208        log_debug ("check_hkp_response: '%s'\r\n", resp);
209      ec = recv ? WPTERR_WINSOCK_RECVKEY : WPTERR_WINSOCK_SENDKEY;      ec = recv ? WPTERR_WINSOCK_RECVKEY : WPTERR_WINSOCK_SENDKEY;
210      if (!strstr (resp, "HTTP/1.0 200 OK") &&      if (!strstr (resp, "HTTP/1.0 200 OK") &&
211          !strstr (resp, "HTTP/1.1 200 OK")) /* http error */          !strstr (resp, "HTTP/1.1 200 OK") &&
212          return ec;          !strstr (resp, "HTTP/1.0 500 OK") &&
213      if (strstr (resp, "Public Key Server -- Error")          !strstr (resp, "HTTP/1.1 500 OK"))
214          || strstr (resp, "Public Key Server -- Error")          return ec; /* http error */
215          || strstr (resp, "No matching keys in database")) {  
216          p = strstr (resp, "<p>");      if (!parse_keyserver_error (resp, hkp_errmsg, DIM (hkp_errmsg)-2)) {
217          if (p && strlen (p) < sizeof (hkp_errmsg)) {          if (!strlen (hkp_errmsg))
218              end = strstr (p, "</p>");              _snprintf (hkp_errmsg, DIM (hkp_errmsg)-1,
219              len = end? (end - p + 1) : strlen (p);                          "Unknown keyserver error");
220              memset (hkp_errmsg, 0, sizeof (hkp_errmsg));          hkp_err = 1;
             strncpy (hkp_errmsg, p, len);  
             hkp_err = 1;  
         }  
221          return ec;          return ec;
222      }      }
223      return 0;      return 0;
# Line 295  sock_read_ext (int fd, char **buffer, in Line 352  sock_read_ext (int fd, char **buffer, in
352          else if (!rc)          else if (!rc)
353              n++;              n++;
354          else {          else {
355              nread = recv (fd, buf, sizeof (buf), 0);              nread = recv (fd, buf, DIM (buf), 0);
356              if (nread == SOCKET_ERROR)              if (nread == SOCKET_ERROR)
357                  return SOCKET_ERROR;                  return SOCKET_ERROR;
358              else if (!nread)              else if (!nread)
# Line 351  wsock_end (void) Line 408  wsock_end (void)
408      char *p;      char *p;
409      int i;      int i;
410    
411    #ifdef WINPT_MOBILE
412        p = m_strdup ("keyserver.conf");
413    #else
414      p = make_special_filename (CSIDL_APPDATA, "winpt\\keyserver.conf", NULL);      p = make_special_filename (CSIDL_APPDATA, "winpt\\keyserver.conf", NULL);
415    #endif
416      kserver_save_conf (p);      kserver_save_conf (p);
417      free_if_alloc (p);      free_if_alloc (p);
418      free_if_alloc (default_keyserver);      free_if_alloc (default_keyserver);
# Line 361  wsock_end (void) Line 422  wsock_end (void)
422      }      }
423      kserver_proxy_release (&proxy);      kserver_proxy_release (&proxy);
424      WSACleanup ();      WSACleanup ();
425        log_debug ("wsock_end: cleanup finished.\r\n");
426  }  }
427    
428    
# Line 408  wsock_strerror (void) Line 470  wsock_strerror (void)
470  void  void
471  kserver_set_socket_timeout (int nsec)  kserver_set_socket_timeout (int nsec)
472  {  {
473      if (nsec < 0)      if (nsec < 0 || nsec > 3600)
474          nsec = 0;          nsec = 0;
475      default_socket_timeout = nsec;      default_socket_timeout = nsec;
476  }  }
# Line 434  kserver_get_hostname (int idx, int type, Line 496  kserver_get_hostname (int idx, int type,
496          return default_keyserver;          return default_keyserver;
497      }      }
498      else if (!type && idx < DIM (server_list)) {      else if (!type && idx < DIM (server_list)) {
499            /* XXX: handle non HKP servers. */
500          *port = HKP_PORT;          *port = HKP_PORT;
501          return server_list[idx];          return server_list[idx];
502      }      }
# Line 452  kserver_check_inet_connection (void) Line 515  kserver_check_inet_connection (void)
515          closesocket (fd);          closesocket (fd);
516          return 0;          return 0;
517      }      }
518        log_debug ("kserver_check_inet_connection: no inet connection.\r\n");
519      return -1;      return -1;
520  }  }
521    
# Line 463  kserver_check_inet_connection (void) Line 527  kserver_check_inet_connection (void)
527  const char*  const char*
528  kserver_check_keyid (const char *keyid)  kserver_check_keyid (const char *keyid)
529  {        {      
530      static char id[21];      static char id[22];
531    
532      if (strstr (keyid, "@"))      if (strstr (keyid, "@"))
533          return keyid; /* email address */          return keyid; /* email address */
534      if (strncmp (keyid, "0x", 2)) {      if (strncmp (keyid, "0x", 2)) {
535          memset (&id, 0, sizeof (id));          memset (&id, 0, sizeof (id));
536          _snprintf (id, sizeof (id)-1, "0x%s", keyid);          _snprintf (id, DIM (id)-1, "0x%s", keyid);
537          return id;          return id;
538      }      }
539      return keyid;      return keyid;
# Line 486  update_proxy_user (const char *proxy_use Line 550  update_proxy_user (const char *proxy_use
550      n = 4*strlen (proxy_user) / 3 + 32 + strlen (proxy_pass) + 2;      n = 4*strlen (proxy_user) / 3 + 32 + strlen (proxy_pass) + 2;
551      free_if_alloc (proxy.base64_user);      free_if_alloc (proxy.base64_user);
552      proxy.base64_user = safe_alloc (n+1);      proxy.base64_user = safe_alloc (n+1);
553      _snprintf (t, sizeof (t)-1, "%s:%s", proxy_user, proxy_pass);      _snprintf (t, DIM (t)-1, "%s:%s", proxy_user, proxy_pass);
554      base64_encode (t, proxy.base64_user);      base64_encode (t, proxy.base64_user);
555      free_if_alloc (proxy.user);      free_if_alloc (proxy.user);
556      free_if_alloc (proxy.pass);      free_if_alloc (proxy.pass);
557      proxy.user = m_strdup (proxy_user);      proxy.user = m_strdup (proxy_user);
558      proxy.pass = m_strdup (proxy_pass);      proxy.pass = m_strdup (proxy_pass);
559  }  }
   
   
 /* Check that the given buffer contains a valid keyserver URL. */  
 static int  
 check_URL (const char * buf)  
 {  
     if (strlen (buf) < 7)  
         return -1;  
     if (!strstr (buf, "ldap://")  
         && !strstr (buf, "http://")  
         && !strstr (buf, "finger://")  
         && !strstr (buf, "hkp://"))  
         return -1;  
     return 0;  
 }  
560            
561    
562  /* Get the port number from the given protocol. */  /* Get the port number from the given protocol. */
# Line 515  static int Line 564  static int
564  port_from_proto (int proto)  port_from_proto (int proto)
565  {  {
566      switch (proto) {      switch (proto) {
567      case KSPROTO_LDAP:   return 0;      case KSPROTO_LDAP:   return LDAP_PORT;
568      case KSPROTO_FINGER: return FINGER_PORT;      case KSPROTO_FINGER: return FINGER_PORT;
569      case KSPROTO_HTTP:   return HKP_PORT;      case KSPROTO_HTTP:   return HKP_PORT;
570      }      }
# Line 529  proto_from_URL (const char *buf) Line 578  proto_from_URL (const char *buf)
578  {  {
579      if (strstr (buf, "ldap"))      if (strstr (buf, "ldap"))
580          return KSPROTO_LDAP;          return KSPROTO_LDAP;
581      else if (strstr( buf, "finger"))      else if (strstr (buf, "finger"))
582          return KSPROTO_FINGER;          return KSPROTO_FINGER;
583      return KSPROTO_HKP;      return KSPROTO_HKP;
584  }  }
585    
586    
587    /* Set the default keyserver.
588       If @hostname is NULL, use the predefined keyserver. */
589  void  void
590  keyserver_set_default (const char *hostname, WORD port)  keyserver_set_default (const char *hostname, WORD port)
591  {  {
592        if (!port)
593            port = HKP_PORT;
594      if (hostname != NULL) {      if (hostname != NULL) {
595          free_if_alloc (default_keyserver);          free_if_alloc (default_keyserver);
596          default_keyserver = m_strdup (hostname);          default_keyserver = m_strdup (hostname);
597          default_keyserver_port = port;          default_keyserver_port = port;
598      }      }
599      if (!port)      if (!default_keyserver) {
         port = HKP_PORT;  
     if (!default_keyserver)  
600          default_keyserver = m_strdup (DEF_HKP_KEYSERVER);          default_keyserver = m_strdup (DEF_HKP_KEYSERVER);
601            default_keyserver_port = HKP_PORT;
602        }
603      server[0].name =  m_strdup (default_keyserver);      server[0].name =  m_strdup (default_keyserver);
604      server[0].used = 1;      server[0].used = 1;
605      server[0].port = port;      server[0].port = port;
# Line 598  kserver_save_conf (const char *conf) Line 651  kserver_save_conf (const char *conf)
651  }  }
652    
653    
654    /* Return the specified keyserver config setting @key as an integer. */
655    static int
656    get_conf_kserver_int (const char *key)
657    {
658        char *p;
659        int val = 0;
660    
661        p = get_reg_entry_keyserver (key);
662        if (p && *p)
663            val = atoi (p);
664        free_if_alloc (p);
665        return val;
666    }
667    
668    
669    /* Read the proxy configuration and store it into @prox. */
670    static void
671    read_proxy_config (keyserver_proxy_t prox)
672    {
673        char *proto;
674    
675        if (!prox)
676            return;
677        
678        proto = get_reg_entry_keyserver("Proto");
679        if (proto != NULL && strlen (proto) > 0)
680            prox->proto = atoi (proto);
681        else
682            prox->proto = PROXY_PROTO_NONE;
683        free_if_alloc (proto);
684        free_if_alloc (prox->host);
685        prox->host = get_reg_entry_keyserver ("Host");
686        free_if_alloc (prox->user);
687        prox->user = get_reg_entry_keyserver ("User");
688        free_if_alloc (prox->pass);
689        prox->pass = get_reg_entry_keyserver ("Pass");
690        prox->port = get_conf_kserver_int ("Port");
691    }
692    
693    
694  /* Load the keyserver config file @conf. */  /* Load the keyserver config file @conf. */
695  int  int
696  kserver_load_conf (const char *conf)  kserver_load_conf (const char *conf)
# Line 622  kserver_load_conf (const char *conf) Line 715  kserver_load_conf (const char *conf)
715          }          }
716          no_config=1;          no_config=1;
717      }      }
718      get_reg_proxy_prefs (&proxy);      read_proxy_config (&proxy);
719      if (user && pass)      if (user && pass)
720          update_proxy_user (user, pass);          update_proxy_user (user, pass);
721      else if (user && !pass || !user && pass) {      else if (user && !pass || !user && pass) {
722          msg_box (NULL, _("Invalid proxy configuration."          msg_box (NULL, _("Invalid proxy configuration. "
723                           "You need to set a user and a password"                           "You need to set a user and a password "
724                           "to use proxy authentication!"),                           "to use proxy authentication!"),
725                           _("Proxy Error"), MB_ERR);                           _("Proxy Error"), MB_ERR);
726      }      }
# Line 642  kserver_load_conf (const char *conf) Line 735  kserver_load_conf (const char *conf)
735            
736      pos = 0;      pos = 0;
737      while (fp && !feof (fp)) {      while (fp && !feof (fp)) {
738          s = fgets (buf, sizeof (buf)-1, fp);          s = fgets (buf, DIM (buf)-1, fp);
739          if (!s)          if (!s)
740              break;              break;
741          if (strstr (buf, "\r\n"))          if (strstr (buf, "\r\n"))
# Line 652  kserver_load_conf (const char *conf) Line 745  kserver_load_conf (const char *conf)
745          s = (char *)skip_whitespace (buf);          s = (char *)skip_whitespace (buf);
746          if (*s == '#' || strlen (s) < 7)          if (*s == '#' || strlen (s) < 7)
747              continue;              continue;
748          if (check_URL (s)) {          chk_pos = check_URL (s);
749            if (!chk_pos) {
750              msg_box (NULL, _("All entries of this file must have a valid prefix.\n"              msg_box (NULL, _("All entries of this file must have a valid prefix.\n"
751                               "Currently HKP/HTTP, LDAP and FINGER are supported.\n"),                               "Currently HKP/HTTP, LDAP and FINGER are supported.\n"),
752                               _("Keyserver Error"), MB_ERR);                               _("Keyserver Error"), MB_ERR);
753              continue;              continue;
754          }          }
         chk_pos = 6;  
         if (strstr (s, "finger"))  
             chk_pos = 10;  
755          p = strchr (s+chk_pos, ':');          p = strchr (s+chk_pos, ':');
756          server[pos].used = 1;          server[pos].used = 1;
757          server[pos].proto = proto_from_URL (s);          server[pos].proto = proto_from_URL (s);
# Line 705  kserver_connect (const char *hostname, W Line 796  kserver_connect (const char *hostname, W
796      struct sockaddr_in sock;      struct sockaddr_in sock;
797      char host[128] = {0};      char host[128] = {0};
798      DWORD iaddr;      DWORD iaddr;
799        bool use_proxy = proxy.host != NULL;
800      int rc, fd;      int rc, fd;
801    
     log_debug ("kserver_connect: %s:%d\r\n", hostname, port);  
   
802      if (!port)      if (!port)
803          port = HKP_PORT;          port = HKP_PORT;
804      if (conn_fd)      if (conn_fd)
805          *conn_fd = 0;          *conn_fd = 0;
806      hostname = skip_type_prefix (hostname);      hostname = skip_type_prefix (hostname);
807        log_debug ("kserver_connect: %s:%d\r\n", hostname, port);
808            
809      if (proxy.host && proxy.proto == PROXY_PROTO_HTTP)      if (use_proxy && proxy.proto == PROXY_PROTO_HTTP)
810          port = proxy.port;          port = proxy.port;
811      memset (&sock, 0, sizeof (sock));      memset (&sock, 0, sizeof (sock));
812      sock.sin_family = AF_INET;      sock.sin_family = AF_INET;
813      sock.sin_port = htons (port);      sock.sin_port = htons (port);
814      if (proxy.host)      if (use_proxy)
815          strncpy (host, proxy.host, 127);          strncpy (host, proxy.host, DIM (host)-1);
816      else      else
817          strncpy (host, hostname, 127);          strncpy (host, hostname, DIM (host)-1);
818    
819      if ((iaddr = inet_addr (host)) != INADDR_NONE)      if ((iaddr = inet_addr (host)) != INADDR_NONE)
820          memcpy (&sock.sin_addr, &iaddr, sizeof (iaddr));          memcpy (&sock.sin_addr, &iaddr, sizeof (iaddr));
# Line 736  kserver_connect (const char *hostname, W Line 827  kserver_connect (const char *hostname, W
827      }      }
828      else {      else {
829          log_debug ("gethostbyname: failed ec=%d.\r\n", net_errno);          log_debug ("gethostbyname: failed ec=%d.\r\n", net_errno);
830          return WPTERR_WINSOCK_RESOLVE;          return use_proxy? WPTERR_WINSOCK_PROXY : WPTERR_WINSOCK_RESOLVE;
831      }      }
832      fd = socket (AF_INET, SOCK_STREAM, 0);      fd = socket (AF_INET, SOCK_STREAM, 0);
833      if (fd == INVALID_SOCKET)        if (fd == INVALID_SOCKET)  
# Line 745  kserver_connect (const char *hostname, W Line 836  kserver_connect (const char *hostname, W
836      if (rc == SOCKET_ERROR) {      if (rc == SOCKET_ERROR) {
837          log_debug ("connect: failed ec=%d.\r\n", net_errno);          log_debug ("connect: failed ec=%d.\r\n", net_errno);
838          closesocket (fd);          closesocket (fd);
839          return WPTERR_WINSOCK_CONNECT;          return use_proxy? WPTERR_WINSOCK_PROXY : WPTERR_WINSOCK_CONNECT;
840      }      }
841    
842      if (proxy.proto == PROXY_PROTO_SOCKS5) {      if (proxy.proto == PROXY_PROTO_SOCKS5) {
843            /* XXX: finish code and provide errors constants. */
844          rc = socks_handshake (&proxy, fd, hostname, port);          rc = socks_handshake (&proxy, fd, hostname, port);
845          if (rc) {          if (rc) {
846              closesocket (fd);              closesocket (fd);
847              return WPTERR_GENERAL; /* XXX: use better code. */              return WPTERR_GENERAL;
848          }          }
849      }      }
850    
# Line 763  kserver_connect (const char *hostname, W Line 855  kserver_connect (const char *hostname, W
855  }  }
856    
857    
858    /* Check if the URL needs to be encoded or not. */
859  static bool  static bool
860  URL_must_encoded (const char *url)  URL_must_encoded (const char *url)
861  {  {
# Line 854  kserver_send_request (const char *hostna Line 947  kserver_send_request (const char *hostna
947      }      }
948    
949      free_if_alloc (enc_pubkey);      free_if_alloc (enc_pubkey);
950      log_debug ("%s\r\n", request);      log_debug ("request:\r\n%s\r\n", request);
951      return request;      return request;
952  }  }
953    
# Line 899  kserver_recvkey (const char *hostname, W Line 992  kserver_recvkey (const char *hostname, W
992          _snprintf (request, reqlen, fmt, keyid);          _snprintf (request, reqlen, fmt, keyid);
993      }      }
994    
995      log_debug ("%s\r\n", request);      log_debug ("request:\r\n%s\r\n", request);
996            
997      rc = sock_write (conn_fd, request, strlen (request));      rc = sock_write (conn_fd, request, strlen (request));
998      if (rc == SOCKET_ERROR) {      if (rc == SOCKET_ERROR) {
# Line 913  kserver_recvkey (const char *hostname, W Line 1006  kserver_recvkey (const char *hostname, W
1006          goto leave;          goto leave;
1007      }      }
1008    
1009      log_debug ("%s\r\n", *r_key);      log_debug ("response:\r\n%s\r\n", *r_key);
1010      rc = check_hkp_response (*r_key, 1);      rc = check_hkp_response (*r_key, 1);
1011      if (rc)      if (rc)
1012          goto leave;          goto leave;
# Line 953  kserver_sendkey (const char *hostname, W Line 1046  kserver_sendkey (const char *hostname, W
1046          goto leave;              goto leave;    
1047      }      }
1048            
1049      rc = sock_read (conn_fd, log, sizeof (log)-1, &n);      rc = sock_read (conn_fd, log, DIM (log)-1, &n);
1050      if (rc == SOCKET_ERROR) {      if (rc == SOCKET_ERROR) {
1051          rc = WPTERR_WINSOCK_SENDKEY;          rc = WPTERR_WINSOCK_SENDKEY;
1052          goto leave;          goto leave;
# Line 981  kserver_search_chkresp (int fd) Line 1074  kserver_search_chkresp (int fd)
1074      int n=0;      int n=0;
1075            
1076      /* parse response 'HTTP/1.0 500 OK' */      /* parse response 'HTTP/1.0 500 OK' */
1077      if (sock_getline (fd, buf, sizeof (buf)-1, &n))      if (sock_getline (fd, buf, DIM (buf)-1, &n))
1078          return WPTERR_KEYSERVER_NOTFOUND;          return WPTERR_KEYSERVER_NOTFOUND;
1079    
1080      log_debug ("kserver_search_chkpresp: %s\r\n", buf);      log_debug ("kserver_search_chkpresp: %s\r\n", buf);
# Line 1086  kserver_search_begin (const char *hostna Line 1179  kserver_search_begin (const char *hostna
1179    
1180      /* Skip all lines until we reach the "info:" record. */      /* Skip all lines until we reach the "info:" record. */
1181      for (;;) {      for (;;) {
1182          if (sock_getline (sock_fd, status, sizeof (status)-1, &reqlen)) {                if (sock_getline (sock_fd, status, DIM (status)-1, &reqlen)) {  
1183              log_debug ("kserver_search_begin: retrieving status line failed.\r\n");              log_debug ("kserver_search_begin: retrieving status line failed.\r\n");
1184              closesocket (sock_fd);              closesocket (sock_fd);
1185              sock_fd = 0;              sock_fd = 0;
# Line 1115  parse_pub_record (keyserver_key_s *key, Line 1208  parse_pub_record (keyserver_key_s *key,
1208      enum pub_rec_t {ID=1, KEYID, ALGO, SIZE, CREATE, EXPIRE};      enum pub_rec_t {ID=1, KEYID, ALGO, SIZE, CREATE, EXPIRE};
1209      char *p;      char *p;
1210      int recno = 0;      int recno = 0;
1211        int off = 0;
1212    
1213      /* pub:BF3DF9B4:17:1024:925411133:: */      /* pub:BF3DF9B4:17:1024:925411133:: */
1214      p = strtok (buf, ":");      p = strtok (buf, ":");
# Line 1124  parse_pub_record (keyserver_key_s *key, Line 1218  parse_pub_record (keyserver_key_s *key,
1218          case ID:          case ID:
1219              break;              break;
1220    
1221          case KEYID:          case KEYID:
1222                /* If for any reason the returned record actually contains
1223                   a fingerprint instead of a key ID, we truncate the fpr. */
1224                off = strlen (p) == 40? 32 : 0;
1225              free_if_alloc (key->keyid);              free_if_alloc (key->keyid);
1226              key->keyid = m_strdup (p);              key->keyid = m_strdup (p+off);
1227              break;              break;
1228    
1229          case ALGO:          case ALGO:
# Line 1147  parse_pub_record (keyserver_key_s *key, Line 1244  parse_pub_record (keyserver_key_s *key,
1244          }          }
1245          p = strtok (NULL, ":");          p = strtok (NULL, ":");
1246      }      }
       
1247  }  }
1248    
1249    
# Line 1157  parse_uid_record (keyserver_key_s *key, Line 1253  parse_uid_record (keyserver_key_s *key,
1253  {  {
1254      enum uid_rec_t {ID=1, UID, CREATE, EXPIRE};      enum uid_rec_t {ID=1, UID, CREATE, EXPIRE};
1255      keyserver_uid_s *u, *n;      keyserver_uid_s *u, *n;
1256      char *p;      char *p, *raw;
1257      int recno = 0;      int recno = 0;
1258    
1259      /* uid:Timo Schulz <[email protected]>:1138440360:: */      /* uid:Timo Schulz <[email protected]>:1138440360:: */
# Line 1173  parse_uid_record (keyserver_key_s *key, Line 1269  parse_uid_record (keyserver_key_s *key,
1269              break;              break;
1270    
1271          case UID:          case UID:
1272              /* XXX: search for %3A and decode it back to ':' */              unhexify_buffer (p, &raw);
1273              u->uid = m_strdup (p);              u->uid = utf8_to_native (raw);
1274                free_if_alloc (raw);
1275              break;              break;
1276    
1277          case CREATE:          case CREATE:
# Line 1230  kserver_search_next (int fd, keyserver_k Line 1327  kserver_search_next (int fd, keyserver_k
1327      key = new keyserver_key_s;      key = new keyserver_key_s;
1328      memset (key, 0, sizeof *key);      memset (key, 0, sizeof *key);
1329      for (;;) {      for (;;) {
1330          if (sock_getline (fd, buf, sizeof (buf)-1, &n))          if (sock_getline (fd, buf, DIM (buf)-1, &n))
1331              break;              break;
1332            /*log_debug ("record: '%s'\r\n", buf); */
1333          if (!strncmp (buf, "pub", 3))          if (!strncmp (buf, "pub", 3))
1334              parse_pub_record (key, buf);              parse_pub_record (key, buf);
1335          else          else
# Line 1336  do_spawn_ldap_helper (const char *host, Line 1434  do_spawn_ldap_helper (const char *host,
1434          fp = NULL;          fp = NULL;
1435          goto leave;          goto leave;
1436      }      }
1437      get_temp_name (outf, sizeof (outf)-1, keyid);      get_temp_name (outf, DIM (outf)-1, keyid);
1438      get_temp_name (inf, sizeof (inf)-1, NULL);      get_temp_name (inf, DIM (inf)-1, NULL);
1439      fp = fopen (inf, "w+b");      fp = fopen (inf, "w+b");
1440      if (!fp) {      if (!fp) {
1441          log_box ("LDAP Keyserver Plugin", MB_ERR, "%s: %s", inf,          log_box ("LDAP Keyserver Plugin", MB_ERR, "%s: %s", inf,
# Line 1394  ldap_recvkey (const char *host, const ch Line 1492  ldap_recvkey (const char *host, const ch
1492      if (gpgme_data_new (&raw))      if (gpgme_data_new (&raw))
1493          BUG (0);          BUG (0);
1494      while (!feof (fp)) {      while (!feof (fp)) {
1495          s = fgets (buf, sizeof (buf)-1, fp);          s = fgets (buf, DIM (buf)-1, fp);
1496          if (!s)          if (!s)
1497              break;              break;
1498          if (strstr (s, "KEY") && strstr (s, "FAILED")) {          if (strstr (s, "KEY") && strstr (s, "FAILED")) {
# Line 1427  finger_recvkey (const char *host, const Line 1525  finger_recvkey (const char *host, const
1525                  char **r_key, int *r_keylen)                  char **r_key, int *r_keylen)
1526  {  {
1527      gpgme_data_t raw;      gpgme_data_t raw;
1528      char buf[256];      char buf[256+1];
1529      int fd, nread;      int fd, nread;
1530      int start_key = 0;      int start_key = 0;
1531      int rc=0;      int rc=0;
# Line 1443  finger_recvkey (const char *host, const Line 1541  finger_recvkey (const char *host, const
1541          BUG (0);          BUG (0);
1542    
1543      for (;;) {      for (;;) {
1544          if (sock_getline (fd, buf, sizeof (buf), &nread))          if (sock_getline (fd, buf, DIM (buf)-1, &nread))
1545              break;              break;
1546          strcat (buf, "\n");          strcat (buf, "\n");
1547          if (strstr (buf, "BEGIN PGP PUBLIC KEY BLOCK")) {          if (strstr (buf, "BEGIN PGP PUBLIC KEY BLOCK")) {
# Line 1491  parse_keyserver_url (char **r_keyserver, Line 1589  parse_keyserver_url (char **r_keyserver,
1589  {  {
1590      char *p;      char *p;
1591      char *url = *r_keyserver;      char *url = *r_keyserver;
1592        int off = 0;
1593    
1594      /* no port is given so use the default port. */      /* no port is given so use the default port. */
1595      p = strrchr (url, ':');      p = strrchr (url, ':');
# Line 1501  parse_keyserver_url (char **r_keyserver, Line 1600  parse_keyserver_url (char **r_keyserver,
1600          *r_port = port;          *r_port = port;
1601          return 0;          return 0;
1602      }      }
1603      /* XXX: remove / in .de/:11371 */  
1604      *r_keyserver = substr (url, 0, (p-url));          if (url[(p-url)-1] == '/') /* remove / in .de/:11371 */
1605            off = 1;
1606    
1607        *r_keyserver = substr (url, 0, (p-url)-off);
1608      *r_port = atoi (url+(p-url)+1);      *r_port = atoi (url+(p-url)+1);
1609      safe_free (url);      free_if_alloc (url);
1610      return 0;      return 0;
1611  }  }

Legend:
Removed from v.214  
changed lines
  Added in v.271

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26