1 From e6d83cc7babb978ba53ae8686159b41ab0f448cc Mon Sep 17 00:00:00 2001
 
   2 From: Jouni Malinen <jouni@qca.qualcomm.com>
 
   3 Date: Mon, 19 May 2014 23:26:19 +0300
 
   4 Subject: [PATCH] PKCS #1: Allow only BT=01 for signature in internal TLS
 
   6 Based on PKCS #1, v1.5, 10.1.3, the block type shall be 01 for a
 
   7 signature. This avoids a potential attack vector for internal TLS/X.509
 
  10 Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
 
  12  src/tls/pkcs1.c | 29 ++++++++++-------------------
 
  13  1 file changed, 10 insertions(+), 19 deletions(-)
 
  15 diff --git a/src/tls/pkcs1.c b/src/tls/pkcs1.c
 
  16 index b6fde5ee868a..af58a42987c6 100644
 
  19 @@ -142,35 +142,26 @@ int pkcs1_decrypt_public_key(struct crypto_rsa_key *key,
 
  21          * PS = k-3-||D|| times (00 if BT=00) or (FF if BT=01)
 
  22          * k = length of modulus in octets
 
  24 +        * Based on 10.1.3, "The block type shall be 01" for a signature.
 
  27         if (len < 3 + 8 + 16 /* min hash len */ ||
 
  28 -           plain[0] != 0x00 || (plain[1] != 0x00 && plain[1] != 0x01)) {
 
  29 +           plain[0] != 0x00 || plain[1] != 0x01) {
 
  30                 wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature EB "
 
  36 -       if (plain[1] == 0x00) {
 
  38 -               if (plain[2] != 0x00) {
 
  39 -                       wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature "
 
  43 -               while (pos + 1 < plain + len && *pos == 0x00 && pos[1] == 0x00)
 
  47 -               if (plain[2] != 0xff) {
 
  48 -                       wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature "
 
  52 -               while (pos < plain + len && *pos == 0xff)
 
  55 +       if (plain[2] != 0xff) {
 
  56 +               wpa_printf(MSG_INFO, "LibTomCrypt: Invalid signature "
 
  60 +       while (pos < plain + len && *pos == 0xff)
 
  63         if (pos - plain - 2 < 8) {
 
  64                 /* PKCS #1 v1.5, 8.1: At least eight octets long PS */