Add support for MS "fast SGC".
[openssl.git] / ssl / s3_both.c
index d5f8c464ba4449c31a293ae352ca19f888c50dcb..9de3e45f50bef7a8c925924f71d553b564d05471 100644 (file)
  */
 
 #include <stdio.h>
-#include "buffer.h"
-#include "rand.h"
-#include "objects.h"
-#include "evp.h"
-#include "x509.h"
+#include <openssl/buffer.h>
+#include <openssl/rand.h>
+#include <openssl/objects.h>
+#include <openssl/evp.h>
+#include <openssl/x509.h>
 #include "ssl_locl.h"
 
-#define BREAK  break
-
-/* SSL3err(SSL_F_SSL3_GET_FINISHED,SSL_R_EXCESSIVE_MESSAGE_SIZE);
- */
-
 int ssl3_send_finished(SSL *s, int a, int b, unsigned char *sender,
             int slen)
        {
@@ -114,7 +109,7 @@ int ssl3_get_finished(SSL *s, int a, int b)
        unsigned char *p;
 
        /* the mac has already been generated when we received the
-        * change cipher spec message and is in s->s3->tmp.in_dgst[12]
+        * change cipher spec message and is in s->s3->tmp.finish_md
         */ 
 
        n=ssl3_get_message(s,
@@ -284,9 +279,8 @@ long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
 
        if (s->state == st1)
                {
-               i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,
-                       (char *)&(p[s->init_num]),
-                       4-s->init_num);
+               i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],
+                                 4-s->init_num);
                if (i < (4-s->init_num))
                        {
                        *ok=0;
@@ -299,6 +293,18 @@ long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
                        SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
                        goto f_err;
                        }
+               if((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) &&
+                                       (st1 == SSL3_ST_SR_CERT_A) &&
+                                       (stn == SSL3_ST_SR_CERT_B))
+                       {
+                       /* At this point we have got an MS SGC second client
+                        * hello. We need to restart the mac and mac the data
+                        * currently received.
+                        */
+                       ssl3_init_finished_mac(s);
+                       ssl3_finish_mac(s, p + s->init_num, i);
+                       }
+                       
                s->s3->tmp.message_type= *(p++);
 
                n2l3(p,l);
@@ -324,8 +330,7 @@ long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
        n=s->s3->tmp.message_size;
        if (n > 0)
                {
-               i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,
-                       (char *)&(p[s->init_num]),(int)n);
+               i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n);
                if (i != (int)n)
                        {
                        *ok=0;