add ssl23_peek
authorBodo Möller <bodo@openssl.org>
Thu, 8 Mar 2001 21:53:29 +0000 (21:53 +0000)
committerBodo Möller <bodo@openssl.org>
Thu, 8 Mar 2001 21:53:29 +0000 (21:53 +0000)
ssl/s23_lib.c
ssl/ssl.h
ssl/ssl_err.c
ssl/ssl_lib.c

index dded7a19c5a56ebe3378872635b6ab52a4f3b8ec..ad2d8dadf75567bcdc0a39240aa0dd1d8a613f9a 100644 (file)
@@ -63,6 +63,7 @@
 static int ssl23_num_ciphers(void );
 static SSL_CIPHER *ssl23_get_cipher(unsigned int u);
 static int ssl23_read(SSL *s, void *buf, int len);
+static int ssl23_peek(SSL *s, void *buf, int len);
 static int ssl23_write(SSL *s, const void *buf, int len);
 static long ssl23_default_timeout(void );
 static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p);
@@ -77,7 +78,7 @@ static SSL_METHOD SSLv23_data= {
        ssl_undefined_function,
        ssl_undefined_function,
        ssl23_read,
-       (int (*)(struct ssl_st *, char *, int))ssl_undefined_function,
+       ssl23_peek,
        ssl23_write,
        ssl_undefined_function,
        ssl_undefined_function,
@@ -169,13 +170,6 @@ static int ssl23_read(SSL *s, void *buf, int len)
        {
        int n;
 
-#if 0
-       if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
-               {
-               s->rwstate=SSL_NOTHING;
-               return(0);
-               }
-#endif
        clear_sys_error();
        if (SSL_in_init(s) && (!s->in_handshake))
                {
@@ -195,17 +189,33 @@ static int ssl23_read(SSL *s, void *buf, int len)
                }
        }
 
-static int ssl23_write(SSL *s, const void *buf, int len)
+static int ssl23_peek(SSL *s, void *buf, int len)
        {
        int n;
 
-#if 0
-       if (s->shutdown & SSL_SENT_SHUTDOWN)
+       clear_sys_error();
+       if (SSL_in_init(s) && (!s->in_handshake))
+               {
+               n=s->handshake_func(s);
+               if (n < 0) return(n);
+               if (n == 0)
+                       {
+                       SSLerr(SSL_F_SSL23_PEEK,SSL_R_SSL_HANDSHAKE_FAILURE);
+                       return(-1);
+                       }
+               return(SSL_peek(s,buf,len));
+               }
+       else
                {
-               s->rwstate=SSL_NOTHING;
-               return(0);
+               ssl_undefined_function(s);
+               return(-1);
                }
-#endif
+       }
+
+static int ssl23_write(SSL *s, const void *buf, int len)
+       {
+       int n;
+
        clear_sys_error();
        if (SSL_in_init(s) && (!s->in_handshake))
                {
index fad7a0e70b36c57034828749107bd197c89cf2bb..bafefe6ad0974251171d4f6ab1a9a38222b6f4f0 100644 (file)
--- a/ssl/ssl.h
+++ b/ssl/ssl.h
@@ -1209,6 +1209,7 @@ int SSL_COMP_add_compression_method(int id,char *cm);
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
  */
+void ERR_load_SSL_strings(void);
 
 /* Error codes for the SSL functions. */
 
@@ -1233,6 +1234,7 @@ int SSL_COMP_add_compression_method(int id,char *cm);
 #define SSL_F_SSL23_CONNECT                             117
 #define SSL_F_SSL23_GET_CLIENT_HELLO                    118
 #define SSL_F_SSL23_GET_SERVER_HELLO                    119
+#define SSL_F_SSL23_PEEK                                237
 #define SSL_F_SSL23_READ                                120
 #define SSL_F_SSL23_WRITE                               121
 #define SSL_F_SSL2_ACCEPT                               122
@@ -1562,4 +1564,3 @@ int SSL_COMP_add_compression_method(int id,char *cm);
 }
 #endif
 #endif
-
index 9945758104b597027269822b8db290be0905e090..1ae333340794c3b128be73461c56fef376309157 100644 (file)
@@ -86,6 +86,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
 {ERR_PACK(0,SSL_F_SSL23_CONNECT,0),    "SSL23_CONNECT"},
 {ERR_PACK(0,SSL_F_SSL23_GET_CLIENT_HELLO,0),   "SSL23_GET_CLIENT_HELLO"},
 {ERR_PACK(0,SSL_F_SSL23_GET_SERVER_HELLO,0),   "SSL23_GET_SERVER_HELLO"},
+{ERR_PACK(0,SSL_F_SSL23_PEEK,0),       "SSL23_PEEK"},
 {ERR_PACK(0,SSL_F_SSL23_READ,0),       "SSL23_READ"},
 {ERR_PACK(0,SSL_F_SSL23_WRITE,0),      "SSL23_WRITE"},
 {ERR_PACK(0,SSL_F_SSL2_ACCEPT,0),      "SSL2_ACCEPT"},
index fec98dd8f43d44eee71df442be777ec74a43c4a6..5f670e276afb971d508bd29fa95a75acacd25fb6 100644 (file)
@@ -726,6 +726,12 @@ int SSL_read(SSL *s,char *buf,int num)
 
 int SSL_peek(SSL *s,char *buf,int num)
        {
+       if (s->handshake_func == 0)
+               {
+               SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED);
+               return -1;
+               }
+
        if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
                {
                return(0);