s23_lib.c revision 280304
11541Srgrimes/* ssl/s23_lib.c */ 21541Srgrimes/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 31541Srgrimes * All rights reserved. 41541Srgrimes * 51541Srgrimes * This package is an SSL implementation written 61541Srgrimes * by Eric Young (eay@cryptsoft.com). 71541Srgrimes * The implementation was written so as to conform with Netscapes SSL. 81541Srgrimes * 91541Srgrimes * This library is free for commercial and non-commercial use as long as 101541Srgrimes * the following conditions are aheared to. The following conditions 111541Srgrimes * apply to all code found in this distribution, be it the RC4, RSA, 121541Srgrimes * lhash, DES, etc., code; not just the SSL code. The SSL documentation 131541Srgrimes * included with this distribution is covered by the same copyright terms 141541Srgrimes * except that the holder is Tim Hudson (tjh@cryptsoft.com). 151541Srgrimes * 161541Srgrimes * Copyright remains Eric Young's, and as such any Copyright notices in 171541Srgrimes * the code are not to be removed. 181541Srgrimes * If this package is used in a product, Eric Young should be given attribution 191541Srgrimes * as the author of the parts of the library used. 201541Srgrimes * This can be in the form of a textual message at program startup or 211541Srgrimes * in documentation (online or textual) provided with the package. 221541Srgrimes * 231541Srgrimes * Redistribution and use in source and binary forms, with or without 241541Srgrimes * modification, are permitted provided that the following conditions 251541Srgrimes * are met: 261541Srgrimes * 1. Redistributions of source code must retain the copyright 271541Srgrimes * notice, this list of conditions and the following disclaimer. 281541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 291541Srgrimes * notice, this list of conditions and the following disclaimer in the 3050477Speter * documentation and/or other materials provided with the distribution. 311541Srgrimes * 3. All advertising materials mentioning features or use of this software 321541Srgrimes * must display the following acknowledgement: 3313459Sbde * "This product includes cryptographic software written by 3413459Sbde * Eric Young (eay@cryptsoft.com)" 3513459Sbde * The word 'cryptographic' can be left out if the rouines from the library 3615311Sbde * being used are not cryptographic related :-). 371541Srgrimes * 4. If you include any Windows specific code (or a derivative thereof) from 3865401Speter * the apps directory (application code) you must include an acknowledgement: 3965393Speter * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 4065401Speter * 411541Srgrimes * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4213459Sbde * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4313459Sbde * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4413459Sbde * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4513459Sbde * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4613459Sbde * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4713459Sbde * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4813459Sbde * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4913459Sbde * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5013459Sbde * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 518010Sbde * SUCH DAMAGE. 528010Sbde * 538010Sbde * The licence and distribution terms for any publically available version or 548010Sbde * derivative of this code cannot be changed. i.e. this code cannot simply be 558010Sbde * copied and put under another distribution licence 568010Sbde * [including the GNU Public Licence.] 578010Sbde */ 588010Sbde 598010Sbde#include <stdio.h> 608010Sbde#include <openssl/objects.h> 611541Srgrimes#include "ssl_locl.h" 62109447Smdodd 63109447Smdoddlong ssl23_default_timeout(void) 64109447Smdodd{ 65109268Smdodd return (300); 661541Srgrimes} 67111506Srwatson 68104900Sphkint ssl23_num_ciphers(void) 69104900Sphk{ 7092719Salfred return (ssl3_num_ciphers() 7192719Salfred#ifndef OPENSSL_NO_SSL2 7292719Salfred + ssl2_num_ciphers() 73124480Sdes#endif 7492719Salfred ); 754477Sbde} 76124480Sdes 77124480Sdesconst SSL_CIPHER *ssl23_get_cipher(unsigned int u) 78124480Sdes{ 7917385Swollman unsigned int uu = ssl3_num_ciphers(); 8092719Salfred 8117385Swollman if (u < uu) 82124480Sdes return (ssl3_get_cipher(u)); 83124480Sdes else 84124480Sdes#ifndef OPENSSL_NO_SSL2 85104652Sdd return (ssl2_get_cipher(u - uu)); 8692719Salfred#else 8792719Salfred return (NULL); 8893008Sbde#endif 89132228Sglebius} 90132228Sglebius 9192719Salfred/* 9292719Salfred * This function needs to check if the ciphers required are actually 9392719Salfred * available 9492719Salfred */ 9592719Salfredconst SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p) 9692719Salfred{ 97110605Shsu const SSL_CIPHER *cp; 9892719Salfred 99110605Shsu cp = ssl3_get_cipher_by_char(p); 100111506Srwatson#ifndef OPENSSL_NO_SSL2 101102863Sbrooks if (cp == NULL) 102102863Sbrooks cp = ssl2_get_cipher_by_char(p); 10392719Salfred#endif 10492719Salfred return (cp); 105110605Shsu} 106104799Srwatson 10792719Salfredint ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) 10812170Sphk{ 10965371Sphk long l; 11065371Sphk 11165371Sphk /* We can write SSLv2 and SSLv3 ciphers */ 11265371Sphk /* but no ECC ciphers */ 11365371Sphk if (c->algorithm_mkey == SSL_kECDHr || 11465371Sphk c->algorithm_mkey == SSL_kECDHe || 11565371Sphk c->algorithm_mkey == SSL_kEECDH || 11665371Sphk c->algorithm_auth == SSL_aECDH || c->algorithm_auth == SSL_aECDSA) 11765371Sphk return 0; 11865371Sphk if (p != NULL) { 11965371Sphk l = c->id; 12065371Sphk p[0] = ((unsigned char)(l >> 16L)) & 0xFF; 12165371Sphk p[1] = ((unsigned char)(l >> 8L)) & 0xFF; 12265371Sphk p[2] = ((unsigned char)(l)) & 0xFF; 12365371Sphk } 12484061Sluigi return (3); 12565371Sphk} 12665371Sphk 12765371Sphkint ssl23_read(SSL *s, void *buf, int len) 12865371Sphk{ 129104652Sdd int n; 130104652Sdd 131104652Sdd clear_sys_error(); 132104652Sdd if (SSL_in_init(s) && (!s->in_handshake)) { 133104652Sdd n = s->handshake_func(s); 134104652Sdd if (n < 0) 135104652Sdd return (n); 136104652Sdd if (n == 0) { 137104652Sdd SSLerr(SSL_F_SSL23_READ, SSL_R_SSL_HANDSHAKE_FAILURE); 138104652Sdd return (-1); 139104652Sdd } 140104652Sdd return (SSL_read(s, buf, len)); 14113459Sbde } else { 142 ssl_undefined_function(s); 143 return (-1); 144 } 145} 146 147int ssl23_peek(SSL *s, void *buf, int len) 148{ 149 int n; 150 151 clear_sys_error(); 152 if (SSL_in_init(s) && (!s->in_handshake)) { 153 n = s->handshake_func(s); 154 if (n < 0) 155 return (n); 156 if (n == 0) { 157 SSLerr(SSL_F_SSL23_PEEK, SSL_R_SSL_HANDSHAKE_FAILURE); 158 return (-1); 159 } 160 return (SSL_peek(s, buf, len)); 161 } else { 162 ssl_undefined_function(s); 163 return (-1); 164 } 165} 166 167int ssl23_write(SSL *s, const void *buf, int len) 168{ 169 int n; 170 171 clear_sys_error(); 172 if (SSL_in_init(s) && (!s->in_handshake)) { 173 n = s->handshake_func(s); 174 if (n < 0) 175 return (n); 176 if (n == 0) { 177 SSLerr(SSL_F_SSL23_WRITE, SSL_R_SSL_HANDSHAKE_FAILURE); 178 return (-1); 179 } 180 return (SSL_write(s, buf, len)); 181 } else { 182 ssl_undefined_function(s); 183 return (-1); 184 } 185} 186