check-signature-test 7.45 KB
Newer Older
1 2 3
#! /bin/sh

conv () {
4
    echo "$1" | sexp-conv -s transport | tee test.in
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
}

die () {
    echo "Test failed:" "$@"
    exit 1
}

test_valid () {    
    name="$1"
    shift
    if [ $# = 2 ] ; then
	msg="$1"
	flags=""
	shift
    else
	msg=""
	flags="--no-data"
    fi
    sign="$1"

    # echo $msg : ../tools/spki-check-signature $flags "`conv "$sign"`" 
    echo "$msg" | ../tools/spki-check-signature $flags "`conv "$sign"`" \
	|| die "$name"
}

test_invalid () {
    name="$1"
    shift
    if [ $# = 2 ] ; then
	msg="$1"
	flags=""
	shift
    else
	msg=""
	flags="--no-data"
    fi
    sign="$1"

    # echo $msg : ../tools/spki-check-signature $flags "`conv "$sign"`" 
    if echo "$msg" | ../tools/spki-check-signature $flags "`conv "$sign"`"
    then die "$name"
    fi
}

test_valid "valid rsa" '
(signature (hash sha1
                 |8dLS+STphqyG/fezbJS83zK+7BU=|)
           (public-key (rsa-pkcs1-sha1 (n |CijcTD4ZSRQtpqa9nLT2rVFtkPFIu
                                           Daxy8FShFh2LLQhSpONFObSR30MXm
                                           KFLgi8vn7RQyqn85bLbqbkRahR|)
                                       (e |J4NiEw==|)))
           (rsa-pkcs1-sha1 |AsI2rx8wZmfYRGsUDfzcq3ycWWNThNP3NmU07Y7rONR2
                            xaHDqfwpm5n+j3kzToBxyWQb+5G7mqXZBPfwlpGJ|))'

test_invalid "rsa, different hash" '
(signature (hash sha1
                 |8dLSxSTphqyG/fezbJS83zK+7BU=|)
           (public-key (rsa-pkcs1-sha1 (n |CijcTD4ZSRQtpqa9nLT2rVFtkPFIu
                                           Daxy8FShFh2LLQhSpONFObSR30MXm
                                           KFLgi8vn7RQyqn85bLbqbkRahR|)
                                       (e |J4NiEw==|)))
           (rsa-pkcs1-sha1 |AsI2rx8wZmfYRGsUDfzcq3ycWWNThNP3NmU07Y7rONR2
                            xaHDqfwpm5n+j3kzToBxyWQb+5G7mqXZBPfwlpGJ|))'

test_invalid "rsa, too long hash" '
(signature (hash sha1
                 |8dLS+STphqyG/fezbJS83zK+7BUx|)
           (public-key (rsa-pkcs1-sha1 (n |CijcTD4ZSRQtpqa9nLT2rVFtkPFIu
                                           Daxy8FShFh2LLQhSpONFObSR30MXm
                                           KFLgi8vn7RQyqn85bLbqbkRahR|)
                                       (e |J4NiEw==|)))
           (rsa-pkcs1-sha1 |AsI2rx8wZmfYRGsUDfzcq3ycWWNThNP3NmU07Y7rONR2
                            xaHDqfwpm5n+j3kzToBxyWQb+5G7mqXZBPfwlpGJ|))'

test_invalid "valid rsa, too short hash" '
(signature (hash sha1
                 |8dLS+STphqyG/fezbJS83zK+7A==|)
           (public-key (rsa-pkcs1-sha1 (n |CijcTD4ZSRQtpqa9nLT2rVFtkPFIu
                                           Daxy8FShFh2LLQhSpONFObSR30MXm
                                           KFLgi8vn7RQyqn85bLbqbkRahR|)
                                       (e |J4NiEw==|)))
           (rsa-pkcs1-sha1 |AsI2rx8wZmfYRGsUDfzcq3ycWWNThNP3NmU07Y7rONR2
                            xaHDqfwpm5n+j3kzToBxyWQb+5G7mqXZBPfwlpGJ|))'

test_valid "valid rsa, with message" "foo" '
(signature (hash sha1
                 |8dLS+STphqyG/fezbJS83zK+7BU=|)
           (public-key (rsa-pkcs1-sha1 (n |CijcTD4ZSRQtpqa9nLT2rVFtkPFIu
                                           Daxy8FShFh2LLQhSpONFObSR30MXm
                                           KFLgi8vn7RQyqn85bLbqbkRahR|)
                                       (e |J4NiEw==|)))
           (rsa-pkcs1-sha1 |AsI2rx8wZmfYRGsUDfzcq3ycWWNThNP3NmU07Y7rONR2
                            xaHDqfwpm5n+j3kzToBxyWQb+5G7mqXZBPfwlpGJ|))'

test_invalid "rsa, with invalid message" "bar" '
(signature (hash sha1
                 |8dLS+STphqyG/fezbJS83zK+7BU=|)
           (public-key (rsa-pkcs1-sha1 (n |CijcTD4ZSRQtpqa9nLT2rVFtkPFIu
                                           Daxy8FShFh2LLQhSpONFObSR30MXm
                                           KFLgi8vn7RQyqn85bLbqbkRahR|)
                                       (e |J4NiEw==|)))
           (rsa-pkcs1-sha1 |AsI2rx8wZmfYRGsUDfzcq3ycWWNThNP3NmU07Y7rONR2
                            xaHDqfwpm5n+j3kzToBxyWQb+5G7mqXZBPfwlpGJ|))'

test_valid "valid dsa" '
   (signature
    (hash sha1 |UNGhcpNFWg5UhtoV2yxV6wPMJPA=|)
    (public-key
     (dsa-sha1
      (p
       |AMxZt4PXzxBFGaF5r+cGpXQzNXCHjjk1awgnr4LCzXYbC97QVXi/Xes
       1k28t0YcDlon56Yut0lTz39fziBpHbGBfc1LvOgW1P5MIa1W8eM3UXi4
       dzWjWtjCn/QM2s33qyELDsCmgAeKg3sVygjKavNgZiSxf44R7RcIEnZB
       xkcN/|)
      (g
       |fbT/lMbMgBWb81X2kRyklLLO/TamsDbLCyp2esdrf/3771RKgsI1RZT
       WMxIpR51D6maNNpEywxhy4L8isXFXplysrAMCfDjpaUCowhQNSDRT8Yz
       ygxZHJpZIU8it+QtLc4fIxA/qSqFL4N3fTIe7xApQlmmG9bI2lgBlZbi
       1/OU=|)
      (q |AP9n7Cy++blLMxOaB0ML3Z3Cc+qh|)
      (y
       |ALpgrX32c8zRlqBSBMtvJzYwrXXpCj3oqeevPna/9zND2LX7wVZd1c9
       K6ZxmQCqxDqGl/anDVToNAnlzr2btlS32cymsxpEm8bIlAJ6Jk4clT3N
       rxuTDRft/W+rgvndiK8fEmtNZ2iaYgAKoM2M3zbij6Ts1H0FfjODHZrt
       ULyNB|)))
    (dsa-sha1
     (r |APyNegTrlzLMCCcMRWoMlnKAOHIu|)
     (s |AIPV/423068nuoNmoQQupyW3x+S1|)))'

test_invalid "dsa, different hash" '
   (signature
    (hash sha1 |UNGhcpNFWg5UhtoV3yxV6wPMJPA=|)
    (public-key
     (dsa-sha1
      (p
       |AMxZt4PXzxBFGaF5r+cGpXQzNXCHjjk1awgnr4LCzXYbC97QVXi/Xes
       1k28t0YcDlon56Yut0lTz39fziBpHbGBfc1LvOgW1P5MIa1W8eM3UXi4
       dzWjWtjCn/QM2s33qyELDsCmgAeKg3sVygjKavNgZiSxf44R7RcIEnZB
       xkcN/|)
      (g
       |fbT/lMbMgBWb81X2kRyklLLO/TamsDbLCyp2esdrf/3771RKgsI1RZT
       WMxIpR51D6maNNpEywxhy4L8isXFXplysrAMCfDjpaUCowhQNSDRT8Yz
       ygxZHJpZIU8it+QtLc4fIxA/qSqFL4N3fTIe7xApQlmmG9bI2lgBlZbi
       1/OU=|)
      (q |AP9n7Cy++blLMxOaB0ML3Z3Cc+qh|)
      (y
       |ALpgrX32c8zRlqBSBMtvJzYwrXXpCj3oqeevPna/9zND2LX7wVZd1c9
       K6ZxmQCqxDqGl/anDVToNAnlzr2btlS32cymsxpEm8bIlAJ6Jk4clT3N
       rxuTDRft/W+rgvndiK8fEmtNZ2iaYgAKoM2M3zbij6Ts1H0FfjODHZrt
       ULyNB|)))
    (dsa-sha1
     (r |APyNegTrlzLMCCcMRWoMlnKAOHIu|)
     (s |AIPV/423068nuoNmoQQupyW3x+S1|)))'

test_invalid "dsa, too long hash" '
   (signature
    (hash sha1 |UNGhcpNFWg5UhtoV2yxV6wPMJPAB|)
    (public-key
     (dsa-sha1
      (p
       |AMxZt4PXzxBFGaF5r+cGpXQzNXCHjjk1awgnr4LCzXYbC97QVXi/Xes
       1k28t0YcDlon56Yut0lTz39fziBpHbGBfc1LvOgW1P5MIa1W8eM3UXi4
       dzWjWtjCn/QM2s33qyELDsCmgAeKg3sVygjKavNgZiSxf44R7RcIEnZB
       xkcN/|)
      (g
       |fbT/lMbMgBWb81X2kRyklLLO/TamsDbLCyp2esdrf/3771RKgsI1RZT
       WMxIpR51D6maNNpEywxhy4L8isXFXplysrAMCfDjpaUCowhQNSDRT8Yz
       ygxZHJpZIU8it+QtLc4fIxA/qSqFL4N3fTIe7xApQlmmG9bI2lgBlZbi
       1/OU=|)
      (q |AP9n7Cy++blLMxOaB0ML3Z3Cc+qh|)
      (y
       |ALpgrX32c8zRlqBSBMtvJzYwrXXpCj3oqeevPna/9zND2LX7wVZd1c9
       K6ZxmQCqxDqGl/anDVToNAnlzr2btlS32cymsxpEm8bIlAJ6Jk4clT3N
       rxuTDRft/W+rgvndiK8fEmtNZ2iaYgAKoM2M3zbij6Ts1H0FfjODHZrt
       ULyNB|)))
    (dsa-sha1
     (r |APyNegTrlzLMCCcMRWoMlnKAOHIu|)
     (s |AIPV/423068nuoNmoQQupyW3x+S1|)))'

test_invalid "dsa, too short hash" '
   (signature
    (hash sha1 |UNGhcpNFWg5UhtoV2yxV6wPMJA==|)
    (public-key
     (dsa-sha1
      (p
       |AMxZt4PXzxBFGaF5r+cGpXQzNXCHjjk1awgnr4LCzXYbC97QVXi/Xes
       1k28t0YcDlon56Yut0lTz39fziBpHbGBfc1LvOgW1P5MIa1W8eM3UXi4
       dzWjWtjCn/QM2s33qyELDsCmgAeKg3sVygjKavNgZiSxf44R7RcIEnZB
       xkcN/|)
      (g
       |fbT/lMbMgBWb81X2kRyklLLO/TamsDbLCyp2esdrf/3771RKgsI1RZT
       WMxIpR51D6maNNpEywxhy4L8isXFXplysrAMCfDjpaUCowhQNSDRT8Yz
       ygxZHJpZIU8it+QtLc4fIxA/qSqFL4N3fTIe7xApQlmmG9bI2lgBlZbi
       1/OU=|)
      (q |AP9n7Cy++blLMxOaB0ML3Z3Cc+qh|)
      (y
       |ALpgrX32c8zRlqBSBMtvJzYwrXXpCj3oqeevPna/9zND2LX7wVZd1c9
       K6ZxmQCqxDqGl/anDVToNAnlzr2btlS32cymsxpEm8bIlAJ6Jk4clT3N
       rxuTDRft/W+rgvndiK8fEmtNZ2iaYgAKoM2M3zbij6Ts1H0FfjODHZrt
       ULyNB|)))
    (dsa-sha1
     (r |APyNegTrlzLMCCcMRWoMlnKAOHIu|)
     (s |AIPV/423068nuoNmoQQupyW3x+S1|)))'