Browse code

openssl : Upgrade to 1.0.2n

Change-Id: I2170ca2ceb307609f41a67858a707a24732b53e5
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/4585
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Anish Swaminathan <anishs@vmware.com>

xiaolin-vmware authored on 2018/01/03 10:07:31
Showing 3 changed files
1 1
deleted file mode 100644
... ...
@@ -1,526 +0,0 @@
1
-diff -up openssl-1.0.2a/apps/s_apps.h.ipv6-apps openssl-1.0.2a/apps/s_apps.h
2
-+++ openssl-1.0.2a/apps/s_apps.h	2015-04-20 15:05:00.353137701 +0200
3
-@@ -151,7 +151,7 @@ typedef fd_mask fd_set;
4
- #define PORT_STR        "4433"
5
- #define PROTOCOL        "tcp"
6
- 
7
--int do_server(int port, int type, int *ret,
8
-+int do_server(char *port, int type, int *ret,
9
-               int (*cb) (char *hostname, int s, int stype,
10
-                          unsigned char *context), unsigned char *context,
11
-               int naccept);
12
-@@ -167,11 +167,10 @@ int ssl_print_point_formats(BIO *out, SS
13
- int ssl_print_curves(BIO *out, SSL *s, int noshared);
14
- #endif
15
- int ssl_print_tmp_key(BIO *out, SSL *s);
16
--int init_client(int *sock, char *server, int port, int type);
17
-+int init_client(int *sock, char *server, char *port, int type);
18
- int should_retry(int i);
19
- int extract_port(char *str, short *port_ptr);
20
--int extract_host_port(char *str, char **host_ptr, unsigned char *ip,
21
--                      short *p);
22
-+int extract_host_port(char *str, char **host_ptr, char **port_ptr);
23
- 
24
- long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
25
-                                    int argi, long argl, long ret);
26
-diff -up openssl-1.0.2a/apps/s_client.c.ipv6-apps openssl-1.0.2a/apps/s_client.c
27
-+++ openssl-1.0.2a/apps/s_client.c	2015-04-20 15:06:42.338503234 +0200
28
-@@ -662,7 +662,7 @@ int MAIN(int argc, char **argv)
29
-     int cbuf_len, cbuf_off;
30
-     int sbuf_len, sbuf_off;
31
-     fd_set readfds, writefds;
32
--    short port = PORT;
33
-+    char *port_str = PORT_STR;
34
-     int full_log = 1;
35
-     char *host = SSL_HOST_NAME;
36
-     char *cert_file = NULL, *key_file = NULL, *chain_file = NULL;
37
-@@ -785,13 +785,11 @@ int MAIN(int argc, char **argv)
38
-         } else if (strcmp(*argv, "-port") == 0) {
39
-             if (--argc < 1)
40
-                 goto bad;
41
--            port = atoi(*(++argv));
42
--            if (port == 0)
43
--                goto bad;
44
-+            port_str = *(++argv);
45
-         } else if (strcmp(*argv, "-connect") == 0) {
46
-             if (--argc < 1)
47
-                 goto bad;
48
--            if (!extract_host_port(*(++argv), &host, NULL, &port))
49
-+            if (!extract_host_port(*(++argv), &host, &port_str))
50
-                 goto bad;
51
-         } else if (strcmp(*argv, "-verify") == 0) {
52
-             verify = SSL_VERIFY_PEER;
53
-@@ -1417,7 +1415,7 @@ int MAIN(int argc, char **argv)
54
- 
55
-  re_start:
56
- 
57
--    if (init_client(&s, host, port, socket_type) == 0) {
58
-+    if (init_client(&s, host, port_str, socket_type) == 0) {
59
-         BIO_printf(bio_err, "connect:errno=%d\n", get_last_socket_error());
60
-         SHUTDOWN(s);
61
-         goto end;
62
-diff -up openssl-1.0.2a/apps/s_server.c.ipv6-apps openssl-1.0.2a/apps/s_server.c
63
-+++ openssl-1.0.2a/apps/s_server.c	2015-04-20 15:10:47.245187746 +0200
64
-@@ -1061,7 +1061,7 @@ int MAIN(int argc, char *argv[])
65
- {
66
-     X509_VERIFY_PARAM *vpm = NULL;
67
-     int badarg = 0;
68
--    short port = PORT;
69
-+    char *port_str = PORT_STR;
70
-     char *CApath = NULL, *CAfile = NULL;
71
-     char *chCApath = NULL, *chCAfile = NULL;
72
-     char *vfyCApath = NULL, *vfyCAfile = NULL;
73
-@@ -1148,7 +1148,8 @@ int MAIN(int argc, char *argv[])
74
-         if ((strcmp(*argv, "-port") == 0) || (strcmp(*argv, "-accept") == 0)) {
75
-             if (--argc < 1)
76
-                 goto bad;
77
--            if (!extract_port(*(++argv), &port))
78
-+            port_str = *(++argv);
79
-+            if (port_str == NULL || *port_str == '\0')
80
-                 goto bad;
81
-         } else if (strcmp(*argv, "-naccept") == 0) {
82
-             if (--argc < 1)
83
-@@ -2020,13 +2021,13 @@ int MAIN(int argc, char *argv[])
84
-     BIO_printf(bio_s_out, "ACCEPT\n");
85
-     (void)BIO_flush(bio_s_out);
86
-     if (rev)
87
--        do_server(port, socket_type, &accept_socket, rev_body, context,
88
-+        do_server(port_str, socket_type, &accept_socket, rev_body, context,
89
-                   naccept);
90
-     else if (www)
91
--        do_server(port, socket_type, &accept_socket, www_body, context,
92
-+        do_server(port_str, socket_type, &accept_socket, www_body, context,
93
-                   naccept);
94
-     else
95
--        do_server(port, socket_type, &accept_socket, sv_body, context,
96
-+        do_server(port_str, socket_type, &accept_socket, sv_body, context,
97
-                   naccept);
98
-     print_stats(bio_s_out, ctx);
99
-     ret = 0;
100
-diff -up openssl-1.0.2a/apps/s_socket.c.ipv6-apps openssl-1.0.2a/apps/s_socket.c
101
-+++ openssl-1.0.2a/apps/s_socket.c	2015-04-20 15:32:53.960079507 +0200
102
-@@ -106,9 +106,7 @@ static struct hostent *GetHostByName(cha
103
- static void ssl_sock_cleanup(void);
104
- # endif
105
- static int ssl_sock_init(void);
106
--static int init_client_ip(int *sock, unsigned char ip[4], int port, int type);
107
--static int init_server(int *sock, int port, int type);
108
--static int init_server_long(int *sock, int port, char *ip, int type);
109
-+static int init_server(int *sock, char *port, int type);
110
- static int do_accept(int acc_sock, int *sock, char **host);
111
- static int host_ip(char *str, unsigned char ip[4]);
112
- 
113
-@@ -231,65 +229,66 @@ static int ssl_sock_init(void)
114
-     return (1);
115
- }
116
- 
117
--int init_client(int *sock, char *host, int port, int type)
118
-+int init_client(int *sock, char *host, char *port, int type)
119
- {
120
--    unsigned char ip[4];
121
--
122
--    memset(ip, '\0', sizeof ip);
123
--    if (!host_ip(host, &(ip[0])))
124
--        return 0;
125
--    return init_client_ip(sock, ip, port, type);
126
--}
127
--
128
--static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
129
--{
130
--    unsigned long addr;
131
--    struct sockaddr_in them;
132
--    int s, i;
133
-+    struct addrinfo *res, *res0, hints;
134
-+    char *failed_call = NULL;
135
-+    int s;
136
-+    int e;
137
- 
138
-     if (!ssl_sock_init())
139
-         return (0);
140
- 
141
--    memset((char *)&them, 0, sizeof(them));
142
--    them.sin_family = AF_INET;
143
--    them.sin_port = htons((unsigned short)port);
144
--    addr = (unsigned long)
145
--        ((unsigned long)ip[0] << 24L) |
146
--        ((unsigned long)ip[1] << 16L) |
147
--        ((unsigned long)ip[2] << 8L) | ((unsigned long)ip[3]);
148
--    them.sin_addr.s_addr = htonl(addr);
149
--
150
--    if (type == SOCK_STREAM)
151
--        s = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL);
152
--    else                        /* ( type == SOCK_DGRAM) */
153
--        s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
154
--
155
--    if (s == INVALID_SOCKET) {
156
--        perror("socket");
157
-+    memset(&hints, '\0', sizeof(hints));
158
-+    hints.ai_socktype = type;
159
-+    hints.ai_flags = AI_ADDRCONFIG;
160
-+
161
-+    e = getaddrinfo(host, port, &hints, &res);
162
-+    if (e) {
163
-+        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
164
-+        if (e == EAI_SYSTEM)
165
-+            perror("getaddrinfo");
166
-         return (0);
167
-     }
168
-+
169
-+    res0 = res;
170
-+    while (res) {
171
-+        s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
172
-+        if (s == INVALID_SOCKET) {
173
-+            failed_call = "socket";
174
-+            goto nextres;
175
-+        }
176
- # if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
177
--    if (type == SOCK_STREAM) {
178
--        i = 0;
179
--        i = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&i, sizeof(i));
180
--        if (i < 0) {
181
--            closesocket(s);
182
--            perror("keepalive");
183
--            return (0);
184
-+        if (type == SOCK_STREAM) {
185
-+            int i = 0;
186
-+            i = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,
187
-+                           (char *)&i, sizeof(i));
188
-+            if (i < 0) {
189
-+                failed_call = "keepalive";
190
-+                goto nextres;
191
-+            }
192
-         }
193
--    }
194
- # endif
195
--
196
--    if (connect(s, (struct sockaddr *)&them, sizeof(them)) == -1) {
197
--        closesocket(s);
198
--        perror("connect");
199
--        return (0);
200
-+        if (connect(s, (struct sockaddr *)res->ai_addr, res->ai_addrlen) == 0) {
201
-+            freeaddrinfo(res0);
202
-+            *sock = s;
203
-+            return (1);
204
-+        }
205
-+
206
-+        failed_call = "socket";
207
-+ nextres:
208
-+        if (s != INVALID_SOCKET)
209
-+            close(s);
210
-+        res = res->ai_next;
211
-     }
212
--    *sock = s;
213
--    return (1);
214
-+    freeaddrinfo(res0);
215
-+    closesocket(s);
216
-+
217
-+    perror(failed_call);
218
-+    return (0);
219
- }
220
- 
221
--int do_server(int port, int type, int *ret,
222
-+int do_server(char *port, int type, int *ret,
223
-               int (*cb) (char *hostname, int s, int stype,
224
-                          unsigned char *context), unsigned char *context,
225
-               int naccept)
226
-@@ -328,69 +327,89 @@ int do_server(int port, int type, int *r
227
-     }
228
- }
229
- 
230
--static int init_server_long(int *sock, int port, char *ip, int type)
231
-+static int init_server(int *sock, char *port, int type)
232
- {
233
--    int ret = 0;
234
--    struct sockaddr_in server;
235
--    int s = -1;
236
-+    struct addrinfo *res, *res0 = NULL, hints;
237
-+    char *failed_call = NULL;
238
-+    int s = INVALID_SOCKET;
239
-+    int e;
240
- 
241
-     if (!ssl_sock_init())
242
-         return (0);
243
- 
244
--    memset((char *)&server, 0, sizeof(server));
245
--    server.sin_family = AF_INET;
246
--    server.sin_port = htons((unsigned short)port);
247
--    if (ip == NULL)
248
--        server.sin_addr.s_addr = INADDR_ANY;
249
--    else
250
--/* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */
251
--# ifndef BIT_FIELD_LIMITS
252
--        memcpy(&server.sin_addr.s_addr, ip, 4);
253
--# else
254
--        memcpy(&server.sin_addr, ip, 4);
255
--# endif
256
--
257
--    if (type == SOCK_STREAM)
258
--        s = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL);
259
--    else                        /* type == SOCK_DGRAM */
260
--        s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
261
-+    memset(&hints, '\0', sizeof(hints));
262
-+    hints.ai_family = AF_INET6;
263
-+ tryipv4:
264
-+    hints.ai_socktype = type;
265
-+    hints.ai_flags = AI_PASSIVE;
266
-+
267
-+    e = getaddrinfo(NULL, port, &hints, &res);
268
-+    if (e) {
269
-+        if (hints.ai_family == AF_INET) {
270
-+            fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
271
-+            if (e == EAI_SYSTEM)
272
-+                perror("getaddrinfo");
273
-+            return (0);
274
-+        } else
275
-+            res = NULL;
276
-+    }
277
- 
278
--    if (s == INVALID_SOCKET)
279
--        goto err;
280
-+    res0 = res;
281
-+    while (res) {
282
-+        s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
283
-+        if (s == INVALID_SOCKET) {
284
-+            failed_call = "socket";
285
-+            goto nextres;
286
-+        }
287
-+        if (hints.ai_family == AF_INET6) {
288
-+            int j = 0;
289
-+            setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&j, sizeof j);
290
-+        }
291
- # if defined SOL_SOCKET && defined SO_REUSEADDR
292
--    {
293
--        int j = 1;
294
--        setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&j, sizeof j);
295
--    }
296
--# endif
297
--    if (bind(s, (struct sockaddr *)&server, sizeof(server)) == -1) {
298
--# ifndef OPENSSL_SYS_WINDOWS
299
--        perror("bind");
300
-+        {
301
-+            int j = 1;
302
-+            setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&j, sizeof j);
303
-+        }
304
- # endif
305
--        goto err;
306
-+
307
-+        if (bind(s, (struct sockaddr *)res->ai_addr, res->ai_addrlen) == -1) {
308
-+            failed_call = "bind";
309
-+            goto nextres;
310
-+        }
311
-+        if (type == SOCK_STREAM && listen(s, 128) == -1) {
312
-+            failed_call = "listen";
313
-+            goto nextres;
314
-+        }
315
-+
316
-+        *sock = s;
317
-+        return (1);
318
-+
319
-+ nextres:
320
-+        if (s != INVALID_SOCKET)
321
-+            close(s);
322
-+        res = res->ai_next;
323
-     }
324
--    /* Make it 128 for linux */
325
--    if (type == SOCK_STREAM && listen(s, 128) == -1)
326
--        goto err;
327
--    *sock = s;
328
--    ret = 1;
329
-- err:
330
--    if ((ret == 0) && (s != -1)) {
331
--        SHUTDOWN(s);
332
-+    if (res0)
333
-+        freeaddrinfo(res0);
334
-+
335
-+    if (s == INVALID_SOCKET) {
336
-+        if (hints.ai_family == AF_INET6) {
337
-+            hints.ai_family = AF_INET;
338
-+            goto tryipv4;
339
-+        }
340
-+        perror("socket");
341
-+        return (0);
342
-     }
343
--    return (ret);
344
--}
345
- 
346
--static int init_server(int *sock, int port, int type)
347
--{
348
--    return (init_server_long(sock, port, NULL, type));
349
-+    perror(failed_call);
350
-+    return (0);
351
- }
352
- 
353
- static int do_accept(int acc_sock, int *sock, char **host)
354
- {
355
-+    static struct sockaddr_storage from;
356
-+    char buffer[NI_MAXHOST];
357
-     int ret;
358
--    struct hostent *h1, *h2;
359
--    static struct sockaddr_in from;
360
-     int len;
361
- /*      struct linger ling; */
362
- 
363
-@@ -432,134 +451,60 @@ static int do_accept(int acc_sock, int *
364
-     ling.l_onoff=1;
365
-     ling.l_linger=0;
366
-     i=setsockopt(ret,SOL_SOCKET,SO_LINGER,(char *)&ling,sizeof(ling));
367
--    if (i < 0) { perror("linger"); return(0); }
368
-+    if (i < 0) { closesocket(ret); perror("linger"); return(0); }
369
-     i=0;
370
-     i=setsockopt(ret,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
371
--    if (i < 0) { perror("keepalive"); return(0); }
372
-+    if (i < 0) { closesocket(ret); perror("keepalive"); return(0); }
373
- */
374
- 
375
-     if (host == NULL)
376
-         goto end;
377
--# ifndef BIT_FIELD_LIMITS
378
--    /* I should use WSAAsyncGetHostByName() under windows */
379
--    h1 = gethostbyaddr((char *)&from.sin_addr.s_addr,
380
--                       sizeof(from.sin_addr.s_addr), AF_INET);
381
--# else
382
--    h1 = gethostbyaddr((char *)&from.sin_addr,
383
--                       sizeof(struct in_addr), AF_INET);
384
--# endif
385
--    if (h1 == NULL) {
386
--        BIO_printf(bio_err, "bad gethostbyaddr\n");
387
-+
388
-+    if (getnameinfo((struct sockaddr *)&from, sizeof(from),
389
-+                    buffer, sizeof(buffer), NULL, 0, 0)) {
390
-+        BIO_printf(bio_err, "getnameinfo failed\n");
391
-         *host = NULL;
392
-         /* return(0); */
393
-     } else {
394
--        if ((*host = (char *)OPENSSL_malloc(strlen(h1->h_name) + 1)) == NULL) {
395
-+        if ((*host = (char *)OPENSSL_malloc(strlen(buffer) + 1)) == NULL) {
396
-             perror("OPENSSL_malloc");
397
-             closesocket(ret);
398
-             return (0);
399
-         }
400
--        BUF_strlcpy(*host, h1->h_name, strlen(h1->h_name) + 1);
401
--
402
--        h2 = GetHostByName(*host);
403
--        if (h2 == NULL) {
404
--            BIO_printf(bio_err, "gethostbyname failure\n");
405
--            closesocket(ret);
406
--            return (0);
407
--        }
408
--        if (h2->h_addrtype != AF_INET) {
409
--            BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n");
410
--            closesocket(ret);
411
--            return (0);
412
--        }
413
-+        strcpy(*host, buffer);
414
-     }
415
-  end:
416
-     *sock = ret;
417
-     return (1);
418
- }
419
- 
420
--int extract_host_port(char *str, char **host_ptr, unsigned char *ip,
421
--                      short *port_ptr)
422
-+int extract_host_port(char *str, char **host_ptr, char **port_ptr)
423
- {
424
--    char *h, *p;
425
-+    char *h, *p, *x;
426
- 
427
--    h = str;
428
--    p = strchr(str, ':');
429
-+    x = h = str;
430
-+    if (*h == '[') {
431
-+        h++;
432
-+        p = strchr(h, ']');
433
-+        if (p == NULL) {
434
-+            BIO_printf(bio_err, "no ending bracket for IPv6 address\n");
435
-+            return (0);
436
-+        }
437
-+        *(p++) = '\0';
438
-+        x = p;
439
-+    }
440
-+    p = strchr(x, ':');
441
-     if (p == NULL) {
442
-         BIO_printf(bio_err, "no port defined\n");
443
-         return (0);
444
-     }
445
-     *(p++) = '\0';
446
- 
447
--    if ((ip != NULL) && !host_ip(str, ip))
448
--        goto err;
449
-     if (host_ptr != NULL)
450
-         *host_ptr = h;
451
-+    if (port_ptr != NULL)
452
-+        *port_ptr = p;
453
- 
454
--    if (!extract_port(p, port_ptr))
455
--        goto err;
456
--    return (1);
457
-- err:
458
--    return (0);
459
--}
460
--
461
--static int host_ip(char *str, unsigned char ip[4])
462
--{
463
--    unsigned int in[4];
464
--    int i;
465
--
466
--    if (sscanf(str, "%u.%u.%u.%u", &(in[0]), &(in[1]), &(in[2]), &(in[3])) ==
467
--        4) {
468
--        for (i = 0; i < 4; i++)
469
--            if (in[i] > 255) {
470
--                BIO_printf(bio_err, "invalid IP address\n");
471
--                goto err;
472
--            }
473
--        ip[0] = in[0];
474
--        ip[1] = in[1];
475
--        ip[2] = in[2];
476
--        ip[3] = in[3];
477
--    } else {                    /* do a gethostbyname */
478
--        struct hostent *he;
479
--
480
--        if (!ssl_sock_init())
481
--            return (0);
482
--
483
--        he = GetHostByName(str);
484
--        if (he == NULL) {
485
--            BIO_printf(bio_err, "gethostbyname failure\n");
486
--            goto err;
487
--        }
488
--        /* cast to short because of win16 winsock definition */
489
--        if ((short)he->h_addrtype != AF_INET) {
490
--            BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n");
491
--            return (0);
492
--        }
493
--        ip[0] = he->h_addr_list[0][0];
494
--        ip[1] = he->h_addr_list[0][1];
495
--        ip[2] = he->h_addr_list[0][2];
496
--        ip[3] = he->h_addr_list[0][3];
497
--    }
498
--    return (1);
499
-- err:
500
--    return (0);
501
--}
502
--
503
--int extract_port(char *str, short *port_ptr)
504
--{
505
--    int i;
506
--    struct servent *s;
507
--
508
--    i = atoi(str);
509
--    if (i != 0)
510
--        *port_ptr = (unsigned short)i;
511
--    else {
512
--        s = getservbyname(str, "tcp");
513
--        if (s == NULL) {
514
--            BIO_printf(bio_err, "getservbyname failure for %s\n", str);
515
--            return (0);
516
--        }
517
--        *port_ptr = ntohs((unsigned short)s->s_port);
518
--    }
519
-     return (1);
520
- }
521
- 
522
-
523 1
new file mode 100644
... ...
@@ -0,0 +1,526 @@
0
+diff -up openssl-1.0.2a/apps/s_apps.h.ipv6-apps openssl-1.0.2a/apps/s_apps.h
1
+--- openssl-1.0.2a/apps/s_apps.h.ipv6-apps	2015-04-20 15:01:24.029120104 +0200
2
+@@ -151,7 +151,7 @@ typedef fd_mask fd_set;
3
+ #define PORT_STR        "4433"
4
+ #define PROTOCOL        "tcp"
5
+ 
6
+-int do_server(int port, int type, int *ret,
7
++int do_server(char *port, int type, int *ret,
8
+               int (*cb) (char *hostname, int s, int stype,
9
+                          unsigned char *context), unsigned char *context,
10
+               int naccept);
11
+@@ -167,11 +167,10 @@ int ssl_print_point_formats(BIO *out, SS
12
+ int ssl_print_curves(BIO *out, SSL *s, int noshared);
13
+ #endif
14
+ int ssl_print_tmp_key(BIO *out, SSL *s);
15
+-int init_client(int *sock, char *server, int port, int type);
16
++int init_client(int *sock, char *server, char *port, int type);
17
+ int should_retry(int i);
18
+ int extract_port(char *str, short *port_ptr);
19
+-int extract_host_port(char *str, char **host_ptr, unsigned char *ip,
20
+-                      short *p);
21
++int extract_host_port(char *str, char **host_ptr, char **port_ptr);
22
+ 
23
+ long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
24
+                                    int argi, long argl, long ret);
25
+diff -up openssl-1.0.2a/apps/s_client.c.ipv6-apps openssl-1.0.2a/apps/s_client.c
26
+--- openssl-1.0.2a/apps/s_client.c.ipv6-apps	2015-04-20 15:01:24.022119942 +0200
27
+@@ -662,7 +662,7 @@ int MAIN(int argc, char **argv)
28
+     int cbuf_len, cbuf_off;
29
+     int sbuf_len, sbuf_off;
30
+     fd_set readfds, writefds;
31
+-    short port = PORT;
32
++    char *port_str = PORT_STR;
33
+     int full_log = 1;
34
+     char *host = SSL_HOST_NAME;
35
+     char *cert_file = NULL, *key_file = NULL, *chain_file = NULL;
36
+@@ -785,13 +785,11 @@ int MAIN(int argc, char **argv)
37
+         } else if (strcmp(*argv, "-port") == 0) {
38
+             if (--argc < 1)
39
+                 goto bad;
40
+-            port = atoi(*(++argv));
41
+-            if (port == 0)
42
+-                goto bad;
43
++            port_str = *(++argv);
44
+         } else if (strcmp(*argv, "-connect") == 0) {
45
+             if (--argc < 1)
46
+                 goto bad;
47
+-            if (!extract_host_port(*(++argv), &host, NULL, &port))
48
++            if (!extract_host_port(*(++argv), &host, &port_str))
49
+                 goto bad;
50
+         } else if (strcmp(*argv, "-verify") == 0) {
51
+             verify = SSL_VERIFY_PEER;
52
+@@ -1417,7 +1415,7 @@ int MAIN(int argc, char **argv)
53
+ 
54
+  re_start:
55
+ 
56
+-    if (init_client(&s, host, port, socket_type) == 0) {
57
++    if (init_client(&s, host, port_str, socket_type) == 0) {
58
+         BIO_printf(bio_err, "connect:errno=%d\n", get_last_socket_error());
59
+         SHUTDOWN(s);
60
+         goto end;
61
+diff -up openssl-1.0.2a/apps/s_server.c.ipv6-apps openssl-1.0.2a/apps/s_server.c
62
+--- openssl-1.0.2a/apps/s_server.c.ipv6-apps	2015-04-20 15:01:24.030120127 +0200
63
+@@ -1061,7 +1061,7 @@ int MAIN(int argc, char *argv[])
64
+ {
65
+     X509_VERIFY_PARAM *vpm = NULL;
66
+     int badarg = 0;
67
+-    short port = PORT;
68
++    char *port_str = PORT_STR;
69
+     char *CApath = NULL, *CAfile = NULL;
70
+     char *chCApath = NULL, *chCAfile = NULL;
71
+     char *vfyCApath = NULL, *vfyCAfile = NULL;
72
+@@ -1148,7 +1148,8 @@ int MAIN(int argc, char *argv[])
73
+         if ((strcmp(*argv, "-port") == 0) || (strcmp(*argv, "-accept") == 0)) {
74
+             if (--argc < 1)
75
+                 goto bad;
76
+-            if (!extract_port(*(++argv), &port))
77
++            port_str = *(++argv);
78
++            if (port_str == NULL || *port_str == '\0')
79
+                 goto bad;
80
+         } else if (strcmp(*argv, "-naccept") == 0) {
81
+             if (--argc < 1)
82
+@@ -2020,13 +2021,13 @@ int MAIN(int argc, char *argv[])
83
+     BIO_printf(bio_s_out, "ACCEPT\n");
84
+     (void)BIO_flush(bio_s_out);
85
+     if (rev)
86
+-        do_server(port, socket_type, &accept_socket, rev_body, context,
87
++        do_server(port_str, socket_type, &accept_socket, rev_body, context,
88
+                   naccept);
89
+     else if (www)
90
+-        do_server(port, socket_type, &accept_socket, www_body, context,
91
++        do_server(port_str, socket_type, &accept_socket, www_body, context,
92
+                   naccept);
93
+     else
94
+-        do_server(port, socket_type, &accept_socket, sv_body, context,
95
++        do_server(port_str, socket_type, &accept_socket, sv_body, context,
96
+                   naccept);
97
+     print_stats(bio_s_out, ctx);
98
+     ret = 0;
99
+diff -up openssl-1.0.2a/apps/s_socket.c.ipv6-apps openssl-1.0.2a/apps/s_socket.c
100
+--- openssl-1.0.2a/apps/s_socket.c.ipv6-apps	2015-03-19 14:30:36.000000000 +0100
101
+@@ -106,9 +106,7 @@ static struct hostent *GetHostByName(cha
102
+ static void ssl_sock_cleanup(void);
103
+ # endif
104
+ static 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);
108
++static int init_server(int *sock, char *port, int type);
109
+ static int do_accept(int acc_sock, int *sock, char **host);
110
+ static int host_ip(char *str, unsigned char ip[4]);
111
+ 
112
+@@ -231,65 +229,66 @@ static int ssl_sock_init(void)
113
+     return (1);
114
+ }
115
+ 
116
+-int init_client(int *sock, char *host, int port, int type)
117
++int init_client(int *sock, char *host, char *port, int type)
118
+ {
119
+-    unsigned char ip[4];
120
+-
121
+-    memset(ip, '\0', sizeof ip);
122
+-    if (!host_ip(host, &(ip[0])))
123
+-        return 0;
124
+-    return init_client_ip(sock, ip, port, type);
125
+-}
126
+-
127
+-static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
128
+-{
129
+-    unsigned long addr;
130
+-    struct sockaddr_in them;
131
+-    int s, i;
132
++    struct addrinfo *res, *res0, hints;
133
++    char *failed_call = NULL;
134
++    int s;
135
++    int e;
136
+ 
137
+     if (!ssl_sock_init())
138
+         return (0);
139
+ 
140
+-    memset((char *)&them, 0, sizeof(them));
141
+-    them.sin_family = AF_INET;
142
+-    them.sin_port = htons((unsigned short)port);
143
+-    addr = (unsigned long)
144
+-        ((unsigned long)ip[0] << 24L) |
145
+-        ((unsigned long)ip[1] << 16L) |
146
+-        ((unsigned long)ip[2] << 8L) | ((unsigned long)ip[3]);
147
+-    them.sin_addr.s_addr = htonl(addr);
148
+-
149
+-    if (type == SOCK_STREAM)
150
+-        s = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL);
151
+-    else                        /* ( type == SOCK_DGRAM) */
152
+-        s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
153
+-
154
+-    if (s == INVALID_SOCKET) {
155
+-        perror("socket");
156
++    memset(&hints, '\0', sizeof(hints));
157
++    hints.ai_socktype = type;
158
++    hints.ai_flags = AI_ADDRCONFIG;
159
++
160
++    e = getaddrinfo(host, port, &hints, &res);
161
++    if (e) {
162
++        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
163
++        if (e == EAI_SYSTEM)
164
++            perror("getaddrinfo");
165
+         return (0);
166
+     }
167
++
168
++    res0 = res;
169
++    while (res) {
170
++        s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
171
++        if (s == INVALID_SOCKET) {
172
++            failed_call = "socket";
173
++            goto nextres;
174
++        }
175
+ # if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
176
+-    if (type == SOCK_STREAM) {
177
+-        i = 0;
178
+-        i = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&i, sizeof(i));
179
+-        if (i < 0) {
180
+-            closesocket(s);
181
+-            perror("keepalive");
182
+-            return (0);
183
++        if (type == SOCK_STREAM) {
184
++            int i = 0;
185
++            i = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,
186
++                           (char *)&i, sizeof(i));
187
++            if (i < 0) {
188
++                failed_call = "keepalive";
189
++                goto nextres;
190
++            }
191
+         }
192
+-    }
193
+ # endif
194
+-
195
+-    if (connect(s, (struct sockaddr *)&them, sizeof(them)) == -1) {
196
+-        closesocket(s);
197
+-        perror("connect");
198
+-        return (0);
199
++        if (connect(s, (struct sockaddr *)res->ai_addr, res->ai_addrlen) == 0) {
200
++            freeaddrinfo(res0);
201
++            *sock = s;
202
++            return (1);
203
++        }
204
++
205
++        failed_call = "socket";
206
++ nextres:
207
++        if (s != INVALID_SOCKET)
208
++            close(s);
209
++        res = res->ai_next;
210
+     }
211
+-    *sock = s;
212
+-    return (1);
213
++    freeaddrinfo(res0);
214
++    closesocket(s);
215
++
216
++    perror(failed_call);
217
++    return (0);
218
+ }
219
+ 
220
+-int do_server(int port, int type, int *ret,
221
++int do_server(char *port, int type, int *ret,
222
+               int (*cb) (char *hostname, int s, int stype,
223
+                          unsigned char *context), unsigned char *context,
224
+               int naccept)
225
+@@ -328,69 +327,89 @@ int do_server(int port, int type, int *r
226
+     }
227
+ }
228
+ 
229
+-static int init_server_long(int *sock, int port, char *ip, int type)
230
++static int init_server(int *sock, char *port, int type)
231
+ {
232
+-    int ret = 0;
233
+-    struct sockaddr_in server;
234
+-    int s = -1;
235
++    struct addrinfo *res, *res0 = NULL, hints;
236
++    char *failed_call = NULL;
237
++    int s = INVALID_SOCKET;
238
++    int e;
239
+ 
240
+     if (!ssl_sock_init())
241
+         return (0);
242
+ 
243
+-    memset((char *)&server, 0, sizeof(server));
244
+-    server.sin_family = AF_INET;
245
+-    server.sin_port = htons((unsigned short)port);
246
+-    if (ip == NULL)
247
+-        server.sin_addr.s_addr = INADDR_ANY;
248
+-    else
249
+-/* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */
250
+-# ifndef BIT_FIELD_LIMITS
251
+-        memcpy(&server.sin_addr.s_addr, ip, 4);
252
+-# else
253
+-        memcpy(&server.sin_addr, ip, 4);
254
+-# endif
255
+-
256
+-    if (type == SOCK_STREAM)
257
+-        s = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL);
258
+-    else                        /* type == SOCK_DGRAM */
259
+-        s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
260
++    memset(&hints, '\0', sizeof(hints));
261
++    hints.ai_family = AF_INET6;
262
++ tryipv4:
263
++    hints.ai_socktype = type;
264
++    hints.ai_flags = AI_PASSIVE;
265
++
266
++    e = getaddrinfo(NULL, port, &hints, &res);
267
++    if (e) {
268
++        if (hints.ai_family == AF_INET) {
269
++            fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
270
++            if (e == EAI_SYSTEM)
271
++                perror("getaddrinfo");
272
++            return (0);
273
++        } else
274
++            res = NULL;
275
++    }
276
+ 
277
+-    if (s == INVALID_SOCKET)
278
+-        goto err;
279
++    res0 = res;
280
++    while (res) {
281
++        s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
282
++        if (s == INVALID_SOCKET) {
283
++            failed_call = "socket";
284
++            goto nextres;
285
++        }
286
++        if (hints.ai_family == AF_INET6) {
287
++            int j = 0;
288
++            setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&j, sizeof j);
289
++        }
290
+ # if defined SOL_SOCKET && defined SO_REUSEADDR
291
+-    {
292
+-        int j = 1;
293
+-        setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&j, sizeof j);
294
+-    }
295
+-# endif
296
+-    if (bind(s, (struct sockaddr *)&server, sizeof(server)) == -1) {
297
+-# ifndef OPENSSL_SYS_WINDOWS
298
+-        perror("bind");
299
++        {
300
++            int j = 1;
301
++            setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&j, sizeof j);
302
++        }
303
+ # endif
304
+-        goto err;
305
++
306
++        if (bind(s, (struct sockaddr *)res->ai_addr, res->ai_addrlen) == -1) {
307
++            failed_call = "bind";
308
++            goto nextres;
309
++        }
310
++        if (type == SOCK_STREAM && listen(s, 128) == -1) {
311
++            failed_call = "listen";
312
++            goto nextres;
313
++        }
314
++
315
++        *sock = s;
316
++        return (1);
317
++
318
++ nextres:
319
++        if (s != INVALID_SOCKET)
320
++            close(s);
321
++        res = res->ai_next;
322
+     }
323
+-    /* Make it 128 for linux */
324
+-    if (type == SOCK_STREAM && listen(s, 128) == -1)
325
+-        goto err;
326
+-    *sock = s;
327
+-    ret = 1;
328
+- err:
329
+-    if ((ret == 0) && (s != -1)) {
330
+-        SHUTDOWN(s);
331
++    if (res0)
332
++        freeaddrinfo(res0);
333
++
334
++    if (s == INVALID_SOCKET) {
335
++        if (hints.ai_family == AF_INET6) {
336
++            hints.ai_family = AF_INET;
337
++            goto tryipv4;
338
++        }
339
++        perror("socket");
340
++        return (0);
341
+     }
342
+-    return (ret);
343
+-}
344
+ 
345
+-static int init_server(int *sock, int port, int type)
346
+-{
347
+-    return (init_server_long(sock, port, NULL, type));
348
++    perror(failed_call);
349
++    return (0);
350
+ }
351
+ 
352
+ static int do_accept(int acc_sock, int *sock, char **host)
353
+ {
354
++    static struct sockaddr_storage from;
355
++    char buffer[NI_MAXHOST];
356
+     int ret;
357
+-    struct hostent *h1, *h2;
358
+-    static struct sockaddr_in from;
359
+     int len;
360
+ /*      struct linger ling; */
361
+ 
362
+@@ -432,134 +451,60 @@ static int do_accept(int acc_sock, int *
363
+     ling.l_onoff=1;
364
+     ling.l_linger=0;
365
+     i=setsockopt(ret,SOL_SOCKET,SO_LINGER,(char *)&ling,sizeof(ling));
366
+-    if (i < 0) { perror("linger"); return(0); }
367
++    if (i < 0) { closesocket(ret); perror("linger"); return(0); }
368
+     i=0;
369
+     i=setsockopt(ret,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
370
+-    if (i < 0) { perror("keepalive"); return(0); }
371
++    if (i < 0) { closesocket(ret); perror("keepalive"); return(0); }
372
+ */
373
+ 
374
+     if (host == NULL)
375
+         goto end;
376
+-# ifndef BIT_FIELD_LIMITS
377
+-    /* I should use WSAAsyncGetHostByName() under windows */
378
+-    h1 = gethostbyaddr((char *)&from.sin_addr.s_addr,
379
+-                       sizeof(from.sin_addr.s_addr), AF_INET);
380
+-# else
381
+-    h1 = gethostbyaddr((char *)&from.sin_addr,
382
+-                       sizeof(struct in_addr), AF_INET);
383
+-# endif
384
+-    if (h1 == NULL) {
385
+-        BIO_printf(bio_err, "bad gethostbyaddr\n");
386
++
387
++    if (getnameinfo((struct sockaddr *)&from, sizeof(from),
388
++                    buffer, sizeof(buffer), NULL, 0, 0)) {
389
++        BIO_printf(bio_err, "getnameinfo failed\n");
390
+         *host = NULL;
391
+         /* return(0); */
392
+     } else {
393
+-        if ((*host = (char *)OPENSSL_malloc(strlen(h1->h_name) + 1)) == NULL) {
394
++        if ((*host = (char *)OPENSSL_malloc(strlen(buffer) + 1)) == NULL) {
395
+             perror("OPENSSL_malloc");
396
+             closesocket(ret);
397
+             return (0);
398
+         }
399
+-        BUF_strlcpy(*host, h1->h_name, strlen(h1->h_name) + 1);
400
+-
401
+-        h2 = GetHostByName(*host);
402
+-        if (h2 == NULL) {
403
+-            BIO_printf(bio_err, "gethostbyname failure\n");
404
+-            closesocket(ret);
405
+-            return (0);
406
+-        }
407
+-        if (h2->h_addrtype != AF_INET) {
408
+-            BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n");
409
+-            closesocket(ret);
410
+-            return (0);
411
+-        }
412
++        strcpy(*host, buffer);
413
+     }
414
+  end:
415
+     *sock = ret;
416
+     return (1);
417
+ }
418
+ 
419
+-int extract_host_port(char *str, char **host_ptr, unsigned char *ip,
420
+-                      short *port_ptr)
421
++int extract_host_port(char *str, char **host_ptr, char **port_ptr)
422
+ {
423
+-    char *h, *p;
424
++    char *h, *p, *x;
425
+ 
426
+-    h = str;
427
+-    p = strchr(str, ':');
428
++    x = h = str;
429
++    if (*h == '[') {
430
++        h++;
431
++        p = strchr(h, ']');
432
++        if (p == NULL) {
433
++            BIO_printf(bio_err, "no ending bracket for IPv6 address\n");
434
++            return (0);
435
++        }
436
++        *(p++) = '\0';
437
++        x = p;
438
++    }
439
++    p = strchr(x, ':');
440
+     if (p == NULL) {
441
+         BIO_printf(bio_err, "no port defined\n");
442
+         return (0);
443
+     }
444
+     *(p++) = '\0';
445
+ 
446
+-    if ((ip != NULL) && !host_ip(str, ip))
447
+-        goto err;
448
+     if (host_ptr != NULL)
449
+         *host_ptr = h;
450
++    if (port_ptr != NULL)
451
++        *port_ptr = p;
452
+ 
453
+-    if (!extract_port(p, port_ptr))
454
+-        goto err;
455
+-    return (1);
456
+- err:
457
+-    return (0);
458
+-}
459
+-
460
+-static int host_ip(char *str, unsigned char ip[4])
461
+-{
462
+-    unsigned int in[4];
463
+-    int i;
464
+-
465
+-    if (sscanf(str, "%u.%u.%u.%u", &(in[0]), &(in[1]), &(in[2]), &(in[3])) ==
466
+-        4) {
467
+-        for (i = 0; i < 4; i++)
468
+-            if (in[i] > 255) {
469
+-                BIO_printf(bio_err, "invalid IP address\n");
470
+-                goto err;
471
+-            }
472
+-        ip[0] = in[0];
473
+-        ip[1] = in[1];
474
+-        ip[2] = in[2];
475
+-        ip[3] = in[3];
476
+-    } else {                    /* do a gethostbyname */
477
+-        struct hostent *he;
478
+-
479
+-        if (!ssl_sock_init())
480
+-            return (0);
481
+-
482
+-        he = GetHostByName(str);
483
+-        if (he == NULL) {
484
+-            BIO_printf(bio_err, "gethostbyname failure\n");
485
+-            goto err;
486
+-        }
487
+-        /* cast to short because of win16 winsock definition */
488
+-        if ((short)he->h_addrtype != AF_INET) {
489
+-            BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n");
490
+-            return (0);
491
+-        }
492
+-        ip[0] = he->h_addr_list[0][0];
493
+-        ip[1] = he->h_addr_list[0][1];
494
+-        ip[2] = he->h_addr_list[0][2];
495
+-        ip[3] = he->h_addr_list[0][3];
496
+-    }
497
+-    return (1);
498
+- err:
499
+-    return (0);
500
+-}
501
+-
502
+-int extract_port(char *str, short *port_ptr)
503
+-{
504
+-    int i;
505
+-    struct servent *s;
506
+-
507
+-    i = atoi(str);
508
+-    if (i != 0)
509
+-        *port_ptr = (unsigned short)i;
510
+-    else {
511
+-        s = getservbyname(str, "tcp");
512
+-        if (s == NULL) {
513
+-            BIO_printf(bio_err, "getservbyname failure for %s\n", str);
514
+-            return (0);
515
+-        }
516
+-        *port_ptr = ntohs((unsigned short)s->s_port);
517
+-    }
518
+     return (1);
519
+ }
520
+ 
521
+
... ...
@@ -1,6 +1,6 @@
1 1
 Summary:        Management tools and libraries relating to cryptography
2 2
 Name:           openssl
3
-Version:        1.0.2m
3
+Version:        1.0.2n
4 4
 Release:        1%{?dist}
5 5
 License:        OpenSSL
6 6
 URL:            http://www.openssl.org
... ...
@@ -8,9 +8,9 @@ Group:          System Environment/Security
8 8
 Vendor:         VMware, Inc.
9 9
 Distribution:   Photon
10 10
 Source0:        http://www.openssl.org/source/%{name}-%{version}.tar.gz
11
-%define sha1    openssl=27fb00641260f97eaa587eb2b80fab3647f6013b
11
+%define sha1    openssl=0ca2957869206de193603eca6d89f532f61680b1
12 12
 Patch0:         c_rehash.patch
13
-Patch1:         openssl-1.0.2m-ipv6apps.patch
13
+Patch1:         openssl-1.0.2n-ipv6apps.patch
14 14
 Patch2:         openssl-init-conslidate.patch
15 15
 Patch3:         openssl-drbg-default-read-system-fips.patch
16 16
 %if %{with_check}
... ...
@@ -115,6 +115,8 @@ rm -rf %{buildroot}/*
115 115
 /%{_bindir}/c_rehash
116 116
 
117 117
 %changelog
118
+*   Tue Jan 02 2018 Xiaolin Li <xiaolinl@vmware.com> 1.0.2n-1
119
+-   Upgrade to 1.0.2n
118 120
 *   Tue Nov 07 2017 Anish Swaminathan <anishs@vmware.com> 1.0.2m-1
119 121
 -   Upgrade to 1.0.2m
120 122
 *   Tue Oct 10 2017 Vinay Kulkarni <kulkarniv@vmware.com> 1.0.2l-2