Deleted Added
full compact
common.c (97866) common.c (97868)
1/*-
2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/lib/libfetch/common.c 97866 2002-06-05 12:19:08Z des $");
30__FBSDID("$FreeBSD: head/lib/libfetch/common.c 97868 2002-06-05 12:46:36Z des $");
31
32#include <sys/param.h>
33#include <sys/socket.h>
34#include <sys/time.h>
35#include <sys/uio.h>
36#include <netinet/in.h>
37
31
32#include <sys/param.h>
33#include <sys/socket.h>
34#include <sys/time.h>
35#include <sys/uio.h>
36#include <netinet/in.h>
37
38#include <ctype.h> /* XXX */
39#include <errno.h>
40#include <netdb.h>
41#include <stdarg.h>
42#include <stdlib.h>
43#include <stdio.h>
44#include <string.h>
45#include <unistd.h>
46

--- 213 unchanged lines hidden (view full) ---

260
261 if ((conn = _fetch_reopen(sd)) == NULL)
262 close(sd);
263 return (conn);
264}
265
266
267/*
38#include <errno.h>
39#include <netdb.h>
40#include <stdarg.h>
41#include <stdlib.h>
42#include <stdio.h>
43#include <string.h>
44#include <unistd.h>
45

--- 213 unchanged lines hidden (view full) ---

259
260 if ((conn = _fetch_reopen(sd)) == NULL)
261 close(sd);
262 return (conn);
263}
264
265
266/*
267 * Enable SSL on a connection.
268 */
269int
270_fetch_ssl(conn_t *conn, int verbose)
271{
272
273 /* Init the SSL library and context */
274 if (!SSL_library_init()){
275 fprintf(stderr, "SSL library init failed\n");
276 return (-1);
277 }
278
279 SSL_load_error_strings();
280
281 conn->ssl_meth = SSLv23_client_method();
282 conn->ssl_ctx = SSL_CTX_new(conn->ssl_meth);
283
284 conn->ssl = SSL_new(conn->ssl_ctx);
285 if (conn->ssl == NULL){
286 fprintf(stderr, "SSL context creation failed\n");
287 return (-1);
288 }
289 SSL_set_fd(conn->ssl, conn->sd);
290 if (SSL_connect(conn->ssl) == -1){
291 ERR_print_errors_fp(stderr);
292 return (-1);
293 }
294
295 if (verbose) {
296 X509_NAME *name;
297 char *str;
298
299 fprintf(stderr, "SSL connection established using %s\n",
300 SSL_get_cipher(conn->ssl));
301 conn->ssl_cert = SSL_get_peer_certificate(conn->ssl);
302 name = X509_get_subject_name(conn->ssl_cert);
303 str = X509_NAME_oneline(name, 0, 0);
304 printf("Certificate subject: %s\n", str);
305 free(str);
306 name = X509_get_issuer_name(conn->ssl_cert);
307 str = X509_NAME_oneline(name, 0, 0);
308 printf("Certificate issuer: %s\n", str);
309 free(str);
310 }
311
312 return (0);
313}
314
315/*
268 * Read a character from a connection w/ timeout
269 */
270ssize_t
271_fetch_read(conn_t *conn, char *buf, size_t len)
272{
273 struct timeval now, timeout, wait;
274 fd_set readfds;
275 ssize_t rlen, total;

--- 211 unchanged lines hidden ---
316 * Read a character from a connection w/ timeout
317 */
318ssize_t
319_fetch_read(conn_t *conn, char *buf, size_t len)
320{
321 struct timeval now, timeout, wait;
322 fd_set readfds;
323 ssize_t rlen, total;

--- 211 unchanged lines hidden ---