pay attention to blocksize before attempting decryption
[openssl.git] / ssl / t1_enc.c
index 5f0976f9e7a9983e8176edf56d7ca1a9db195f10..d3a15e3441d05d6ddba52da2461cba6d760fe3c2 100644 (file)
@@ -509,6 +509,16 @@ int tls1_enc(SSL *s, int send)
                }
 #endif /* KSSL_DEBUG */
 
+               if (!send)
+                       {
+                       if (l == 0 || l%bs != 0)
+                               {
+                               SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG);
+                               ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPT_ERROR);
+                               return(0);
+                               }
+                       }
+               
                EVP_Cipher(ds,rec->data,rec->input,l);
 
 #ifdef KSSL_DEBUG
@@ -522,7 +532,7 @@ int tls1_enc(SSL *s, int send)
 
                if ((bs != 1) && !send)
                        {
-                       ii=i=rec->data[l-1];
+                       ii=i=rec->data[l-1]; /* padding_length */
                        i++;
                        if (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG)
                                {
@@ -533,6 +543,8 @@ int tls1_enc(SSL *s, int send)
                                if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG)
                                        i--;
                                }
+                       /* TLS 1.0 does not bound the number of padding bytes by the block size.
+                        * All of them must have value 'padding_length'. */
                        if (i > (int)rec->length)
                                {
                                SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG);