1 /* ssl_port.h - standard porting things */ 2 /*- 3 * Copyright (c) 2002, 2004 Nick Leuta 4 * All rights reserved. 5 * 6 * This software is based on code developed by Tim Hudson <tjh@cryptsoft.com> 7 * for use in the SSLftp project. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #ifndef HEADER_SSL_PORT_H 34 #define HEADER_SSL_PORT_H 35 36 /* 37 * SSL security flags 38 */ 39 #define SSL_USE_NONSECURE 0x01 /* non-secure mode */ 40 #define SSL_USE_COMPAT 0x02 /* FTP-SSL compatibility mode */ 41 #define SSL_USE_TLS 0x04 /* RFC2228 compliant FTP-TLS mode */ 42 #define SSL_ENABLED 0x06 /* SSL_USE_TLS | SSL_USE_COMPAT */ 43 44 /* Binary inversion */ 45 #define SSL_FINV(FLAG) (FLAG^0xff) 46 /* Turn FLAG bits on */ 47 #define SSL_secure_flags_ON(FLAG) ssl_secure_flags|=FLAG 48 /* Turn FLAG bits off */ 49 #define SSL_secure_flags_OFF(FLAG) ssl_secure_flags&=SSL_FINV(FLAG) 50 51 extern char ssl_secure_flags; 52 53 extern void PRINTF(const char *fmt, ...); 54 55 #ifdef USE_SSL 56 57 #include <stdio.h> 58 59 #include <openssl/buffer.h> 60 #include <openssl/x509.h> 61 #include <openssl/ssl.h> 62 63 extern SSL *ssl_data_con; 64 65 extern int ssl_compat_flag; 66 extern int PBSZ_used_flag; 67 68 extern int ssl_encrypt_data; 69 extern int ssl_data_active_flag; 70 71 extern int ssl_read(); 72 extern int ssl_write(); 73 74 extern int ssl_putc(); 75 extern int ssl_putc_flush(); 76 extern int ssl_getc(); 77 78 /* This cute macro makes things much easier to handle ... */ 79 #define GETC(X) (ssl_active_flag && (((X)==cin)||((X)==cout)) ? ssl_getc(ssl_con) : getc((X))) 80 #define PUTC(X,Y) (ssl_active_flag && (((Y)==cin)||((Y)==cout)||((Y)==stdout)) ? ssl_putc(ssl_con,(X)) : putc((X),(Y))) 81 #define DATAGETC(X) (ssl_data_active_flag && ((fileno(X)==data)||(fileno(X)==pdata)) ? ssl_getc(ssl_data_con) : getc((X))) 82 #define DATAPUTC(X,Y) (ssl_data_active_flag && ((fileno(Y)==data)||(fileno(Y)==pdata)) ? ssl_putc(ssl_data_con,(X)) : putc((X),(Y))) 83 #define FFLUSH(X) (ssl_active_flag && (((X)==cin)||((X)==cout)) ? 1 : fflush((X)) ) 84 #define DATAFLUSH(X) (ssl_data_active_flag && ((fileno(X)==data)||(fileno(X)==pdata)) ? ssl_putc_flush(ssl_data_con) : fflush((X))) 85 86 #else 87 88 #define GETC(X) getc((X)) 89 #define PUTC(X,Y) putc((X),(Y)) 90 #define DATAGETC(X) getc((X)) 91 #define DATAPUTC(X,Y) putc((X),(Y)) 92 #define FFLUSH(X) fflush((X)) 93 #define DATAFLUSH(X) fflush((X)) 94 95 #endif /* USE_SSL */ 96 97 #endif /* HEADER_SSL_PORT_H */ 98