source: trunk/server/common/patches/openssl-1.0.0n-ipv6-apps.patch @ 2558

Last change on this file since 2558 was 2558, checked in by andersk, 10 years ago
Update OpenSSL to 1.0.0n
File size: 13.0 KB
  • openssl-1.0.0b/apps/s_apps.h

    diff -up openssl-1.0.0b/apps/s_apps.h.ipv6-apps openssl-1.0.0b/apps/s_apps.h
    old new typedef fd_mask fd_set; 
    148148#define PORT_STR        "4433"
    149149#define PROTOCOL        "tcp"
    150150
    151 int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);
     151int do_server(char *port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);
    152152#ifdef HEADER_X509_H
    153153int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
    154154#endif
    int MS_CALLBACK verify_callback(int ok,  
    156156int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);
    157157int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key);
    158158#endif
    159 int init_client(int *sock, char *server, int port, int type);
     159int init_client(int *sock, char *server, char *port, int type);
    160160int should_retry(int i);
    161 int extract_port(char *str, short *port_ptr);
    162 int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);
     161int extract_host_port(char *str,char **host_ptr,char **port_ptr);
    163162
    164163long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
    165164                                   int argi, long argl, long ret);
  • openssl-1.0.0b/apps/s_client.c

    diff -up openssl-1.0.0b/apps/s_client.c.ipv6-apps openssl-1.0.0b/apps/s_client.c
    old new int MAIN(int argc, char **argv) 
    389389        int cbuf_len,cbuf_off;
    390390        int sbuf_len,sbuf_off;
    391391        fd_set readfds,writefds;
    392         short port=PORT;
     392        char *port_str = PORT_STR;
    393393        int full_log=1;
    394394        char *host=SSL_HOST_NAME;
    395395        char *cert_file=NULL,*key_file=NULL;
    int MAIN(int argc, char **argv) 
    488488                else if (strcmp(*argv,"-port") == 0)
    489489                        {
    490490                        if (--argc < 1) goto bad;
    491                         port=atoi(*(++argv));
    492                         if (port == 0) goto bad;
     491                        port_str= *(++argv);
    493492                        }
    494493                else if (strcmp(*argv,"-connect") == 0)
    495494                        {
    496495                        if (--argc < 1) goto bad;
    497                         if (!extract_host_port(*(++argv),&host,NULL,&port))
     496                        if (!extract_host_port(*(++argv),&host,&port_str))
    498497                                goto bad;
    499498                        }
    500499                else if (strcmp(*argv,"-verify") == 0)
    bad: 
    967966
    968967re_start:
    969968
    970         if (init_client(&s,host,port,socket_type) == 0)
     969        if (init_client(&s,host,port_str,socket_type) == 0)
    971970                {
    972971                BIO_printf(bio_err,"connect:errno=%d\n",get_last_socket_error());
    973972                SHUTDOWN(s);
  • openssl-1.0.0b/apps/s_server.c

    diff -up openssl-1.0.0b/apps/s_server.c.ipv6-apps openssl-1.0.0b/apps/s_server.c
    old new int MAIN(int argc, char *argv[]) 
    838838        {
    839839        X509_VERIFY_PARAM *vpm = NULL;
    840840        int badarg = 0;
    841         short port=PORT;
     841        char *port_str = PORT_STR;
    842842        char *CApath=NULL,*CAfile=NULL;
    843843        unsigned char *context = NULL;
    844844        char *dhfile = NULL;
    int MAIN(int argc, char *argv[]) 
    909909                         (strcmp(*argv,"-accept") == 0))
    910910                        {
    911911                        if (--argc < 1) goto bad;
    912                         if (!extract_port(*(++argv),&port))
    913                                 goto bad;
     912                        port_str= *(++argv);
    914913                        }
    915914                else if (strcmp(*argv,"-verify") == 0)
    916915                        {
    bad: 
    17001699        BIO_printf(bio_s_out,"ACCEPT\n");
    17011700        (void)BIO_flush(bio_s_out);
    17021701        if (www)
    1703                 do_server(port,socket_type,&accept_socket,www_body, context);
     1702                do_server(port_str,socket_type,&accept_socket,www_body, context);
    17041703        else
    1705                 do_server(port,socket_type,&accept_socket,sv_body, context);
     1704                do_server(port_str,socket_type,&accept_socket,sv_body, context);
    17061705        print_stats(bio_s_out,ctx);
    17071706        ret=0;
    17081707end:
  • openssl-1.0.0b/apps/s_socket.c

    diff -up openssl-1.0.0b/apps/s_socket.c.ipv6-apps openssl-1.0.0b/apps/s_socket.c
    old new static struct hostent *GetHostByName(cha 
    102102static void ssl_sock_cleanup(void);
    103103#endif
    104104static int ssl_sock_init(void);
    105 static int init_client_ip(int *sock,unsigned char ip[4], int port, int type);
    106 static int init_server(int *sock, int port, int type);
    107 static int init_server_long(int *sock, int port,char *ip, int type);
     105static int init_server(int *sock, char *port, int type);
    108106static int do_accept(int acc_sock, int *sock, char **host);
    109107static int host_ip(char *str, unsigned char ip[4]);
    110108
    static int ssl_sock_init(void) 
    234232        return(1);
    235233        }
    236234
    237 int init_client(int *sock, char *host, int port, int type)
     235int init_client(int *sock, char *host, char *port, int type)
    238236        {
    239         unsigned char ip[4];
    240 
    241         if (!host_ip(host,&(ip[0])))
    242                 {
    243                 return(0);
    244                 }
    245         return(init_client_ip(sock,ip,port,type));
    246         }
    247 
    248 static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
    249         {
    250         unsigned long addr;
    251         struct sockaddr_in them;
    252         int s,i;
     237        struct addrinfo *res, *res0, hints;
     238        char * failed_call = NULL;
     239        int s;
     240        int e;
    253241
    254242        if (!ssl_sock_init()) return(0);
    255243
    256         memset((char *)&them,0,sizeof(them));
    257         them.sin_family=AF_INET;
    258         them.sin_port=htons((unsigned short)port);
    259         addr=(unsigned long)
    260                 ((unsigned long)ip[0]<<24L)|
    261                 ((unsigned long)ip[1]<<16L)|
    262                 ((unsigned long)ip[2]<< 8L)|
    263                 ((unsigned long)ip[3]);
    264         them.sin_addr.s_addr=htonl(addr);
    265 
    266         if (type == SOCK_STREAM)
    267                 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
    268         else /* ( type == SOCK_DGRAM) */
    269                 s=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
    270                        
    271         if (s == INVALID_SOCKET) { perror("socket"); return(0); }
     244        memset(&hints, '\0', sizeof(hints));
     245        hints.ai_socktype = type;
     246        hints.ai_flags = AI_ADDRCONFIG;
     247
     248        e = getaddrinfo(host, port, &hints, &res);
     249        if (e)
     250        {
     251                fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
     252                if (e == EAI_SYSTEM)
     253                        perror("getaddrinfo");
     254                return (0);
     255                }
    272256
     257        res0 = res;
     258        while (res)
     259                {
     260                s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
     261                if (s == INVALID_SOCKET)
     262                        {
     263                        failed_call = "socket";
     264                        goto nextres;
     265                        }
    273266#if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
    274267        if (type == SOCK_STREAM)
    275268                {
    276                 i=0;
    277                 i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
    278                 if (i < 0) { closesocket(s); perror("keepalive"); return(0); }
     269                        int i=0;
     270                        i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,
     271                                (char *)&i,sizeof(i));
     272                        if (i < 0) {
     273                                failed_call = "keepalive";
     274                                goto nextres;
     275                                }
    279276                }
    280277#endif
    281 
    282         if (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1)
    283                 { closesocket(s); perror("connect"); return(0); }
     278                if (connect(s,(struct sockaddr *)res->ai_addr,
     279                        res->ai_addrlen) == 0)
     280                        {
     281                        freeaddrinfo(res0);
    284282        *sock=s;
    285283        return(1);
    286284        }
    287285
    288 int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)
     286                failed_call = "socket";
     287nextres:
     288                if (s != INVALID_SOCKET)
     289                        close(s);
     290                res = res->ai_next;
     291                }
     292        freeaddrinfo(res0);
     293
     294        perror(failed_call);
     295        return(0);
     296        }
     297
     298int do_server(char *port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)
    289299        {
    290300        int sock;
    291301        char *name = NULL;
    int do_server(int port, int type, int *r 
    323333                }
    324334        }
    325335
    326 static int init_server_long(int *sock, int port, char *ip, int type)
     336static int init_server(int *sock, char *port, int type)
    327337        {
    328         int ret=0;
    329         struct sockaddr_in server;
    330         int s= -1;
     338        struct addrinfo *res, *res0, hints;
     339        char * failed_call = NULL;
     340        char port_name[8];
     341        int s;
     342        int e;
    331343
    332344        if (!ssl_sock_init()) return(0);
    333345
    334         memset((char *)&server,0,sizeof(server));
    335         server.sin_family=AF_INET;
    336         server.sin_port=htons((unsigned short)port);
    337         if (ip == NULL)
    338                 server.sin_addr.s_addr=INADDR_ANY;
    339         else
    340 /* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */
    341 #ifndef BIT_FIELD_LIMITS
    342                 memcpy(&server.sin_addr.s_addr,ip,4);
    343 #else
    344                 memcpy(&server.sin_addr,ip,4);
    345 #endif
     346        memset(&hints, '\0', sizeof(hints));
     347        hints.ai_socktype = type;
     348        hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
    346349       
    347                 if (type == SOCK_STREAM)
    348                         s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
    349                 else /* type == SOCK_DGRAM */
    350                         s=socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP);
     350        e = getaddrinfo(NULL, port, &hints, &res);
     351        if (e)
     352                {
     353                fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
     354                if (e == EAI_SYSTEM)
     355                        perror("getaddrinfo");
     356                return (0);
     357                }
    351358
    352         if (s == INVALID_SOCKET) goto err;
     359        res0 = res;
     360        while (res)
     361                {
     362                s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
     363                if (s == INVALID_SOCKET)
     364                        {
     365                        failed_call = "socket";
     366                        goto nextres;
     367                        }
    353368#if defined SOL_SOCKET && defined SO_REUSEADDR
    354369                {
    355370                int j = 1;
    static int init_server_long(int *sock, i 
    357372                           (void *) &j, sizeof j);
    358373                }
    359374#endif
    360         if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
     375
     376                if (bind(s,(struct sockaddr *)res->ai_addr, res->ai_addrlen) == -1)
    361377                {
    362 #ifndef OPENSSL_SYS_WINDOWS
    363                 perror("bind");
    364 #endif
    365                 goto err;
     378                        failed_call = "bind";
     379                        goto nextres;
    366380                }
    367         /* Make it 128 for linux */
    368         if (type==SOCK_STREAM && listen(s,128) == -1) goto err;
    369         *sock=s;
    370         ret=1;
    371 err:
    372         if ((ret == 0) && (s != -1))
     381                if (type==SOCK_STREAM && listen(s,128) == -1)
    373382                {
    374                 SHUTDOWN(s);
     383                        failed_call = "listen";
     384                        goto nextres;
    375385                }
    376         return(ret);
     386
     387                *sock=s;
     388                return(1);
     389
     390nextres:
     391                if (s != INVALID_SOCKET)
     392                        close(s);
     393                res = res->ai_next;
    377394        }
     395        freeaddrinfo(res0);
    378396
    379 static int init_server(int *sock, int port, int type)
    380         {
    381         return(init_server_long(sock, port, NULL, type));
     397        if (s == INVALID_SOCKET) { perror("socket"); return(0); }
     398
     399        perror(failed_call);
     400        return(0);
    382401        }
    383402
    384403static int do_accept(int acc_sock, int *sock, char **host)
    385404        {
     405        static struct sockaddr_storage from;
     406        char buffer[NI_MAXHOST];
    386407        int ret;
    387         struct hostent *h1,*h2;
    388         static struct sockaddr_in from;
    389408        int len;
    390409/*      struct linger ling; */
    391410
    redoit: 
    432451*/
    433452
    434453        if (host == NULL) goto end;
    435 #ifndef BIT_FIELD_LIMITS
    436         /* I should use WSAAsyncGetHostByName() under windows */
    437         h1=gethostbyaddr((char *)&from.sin_addr.s_addr,
    438                 sizeof(from.sin_addr.s_addr),AF_INET);
    439 #else
    440         h1=gethostbyaddr((char *)&from.sin_addr,
    441                 sizeof(struct in_addr),AF_INET);
    442 #endif
    443         if (h1 == NULL)
     454
     455        if (getnameinfo((struct sockaddr *)&from, sizeof(from),
     456                buffer, sizeof(buffer),
     457                NULL, 0, 0))
    444458                {
    445                 BIO_printf(bio_err,"bad gethostbyaddr\n");
     459                BIO_printf(bio_err,"getnameinfo failed\n");
    446460                *host=NULL;
    447461                /* return(0); */
    448462                }
    449463        else
    450464                {
    451                 if ((*host=(char *)OPENSSL_malloc(strlen(h1->h_name)+1)) == NULL)
     465                if ((*host=(char *)OPENSSL_malloc(strlen(buffer)+1)) == NULL)
    452466                        {
    453467                        perror("OPENSSL_malloc");
    454468                        closesocket(ret);
    455469                        return(0);
    456470                        }
    457                 BUF_strlcpy(*host,h1->h_name,strlen(h1->h_name)+1);
    458 
    459                 h2=GetHostByName(*host);
    460                 if (h2 == NULL)
    461                         {
    462                         BIO_printf(bio_err,"gethostbyname failure\n");
    463                         closesocket(ret);
    464                         return(0);
    465                         }
    466                 if (h2->h_addrtype != AF_INET)
    467                         {
    468                         BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n");
    469                         closesocket(ret);
    470                         return(0);
    471                         }
     471                strcpy(*host, buffer);
    472472                }
    473473end:
    474474        *sock=ret;
    475475        return(1);
    476476        }
    477477
    478 int extract_host_port(char *str, char **host_ptr, unsigned char *ip,
    479              short *port_ptr)
     478int extract_host_port(char *str, char **host_ptr,
     479             char **port_ptr)
    480480        {
    481         char *h,*p;
     481        char *h,*p,*x;
    482482
    483         h=str;
    484         p=strchr(str,':');
     483        x=h=str;
     484        if (*h == '[')
     485                {
     486                h++;
     487                p=strchr(h,']');
    485488        if (p == NULL)
    486489                {
    487                 BIO_printf(bio_err,"no port defined\n");
     490                        BIO_printf(bio_err,"no ending bracket for IPv6 address\n");
    488491                return(0);
    489492                }
    490493        *(p++)='\0';
    491 
    492         if ((ip != NULL) && !host_ip(str,ip))
    493                 goto err;
    494         if (host_ptr != NULL) *host_ptr=h;
    495 
    496         if (!extract_port(p,port_ptr))
    497                 goto err;
    498         return(1);
    499 err:
    500         return(0);
     494                x = p;
    501495        }
    502 
    503 static int host_ip(char *str, unsigned char ip[4])
    504         {
    505         unsigned int in[4];
    506         int i;
    507 
    508         if (sscanf(str,"%u.%u.%u.%u",&(in[0]),&(in[1]),&(in[2]),&(in[3])) == 4)
    509                 {
    510                 for (i=0; i<4; i++)
    511                         if (in[i] > 255)
    512                                 {
    513                                 BIO_printf(bio_err,"invalid IP address\n");
    514                                 goto err;
    515                                 }
    516                 ip[0]=in[0];
    517                 ip[1]=in[1];
    518                 ip[2]=in[2];
    519                 ip[3]=in[3];
    520                 }
    521         else
    522                 { /* do a gethostbyname */
    523                 struct hostent *he;
    524 
    525                 if (!ssl_sock_init()) return(0);
    526 
    527                 he=GetHostByName(str);
    528                 if (he == NULL)
    529                         {
    530                         BIO_printf(bio_err,"gethostbyname failure\n");
    531                         goto err;
    532                         }
    533                 /* cast to short because of win16 winsock definition */
    534                 if ((short)he->h_addrtype != AF_INET)
     496        p=strchr(x,':');
     497        if (p == NULL)
    535498                        {
    536                         BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n");
    537                         return(0);
    538                         }
    539                 ip[0]=he->h_addr_list[0][0];
    540                 ip[1]=he->h_addr_list[0][1];
    541                 ip[2]=he->h_addr_list[0][2];
    542                 ip[3]=he->h_addr_list[0][3];
    543                 }
    544         return(1);
    545 err:
     499                BIO_printf(bio_err,"no port defined\n");
    546500        return(0);
    547501        }
     502        *(p++)='\0';
    548503
    549 int extract_port(char *str, short *port_ptr)
    550         {
    551         int i;
    552         struct servent *s;
     504        if (host_ptr != NULL) *host_ptr=h;
     505        if (port_ptr != NULL) *port_ptr=p;
    553506
    554         i=atoi(str);
    555         if (i != 0)
    556                 *port_ptr=(unsigned short)i;
    557         else
    558                 {
    559                 s=getservbyname(str,"tcp");
    560                 if (s == NULL)
    561                         {
    562                         BIO_printf(bio_err,"getservbyname failure for %s\n",str);
    563                         return(0);
    564                         }
    565                 *port_ptr=ntohs((unsigned short)s->s_port);
    566                 }
    567507        return(1);
    568508        }
    569509
Note: See TracBrowser for help on using the repository browser.