Joe Subbiani | 97cd599 | 2021-07-22 16:08:29 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Joe Subbiani | a16ccac | 2021-07-22 18:52:17 +0100 | [diff] [blame^] | 3 | # test_translate_format.sh |
| 4 | # |
| 5 | # Copyright The Mbed TLS Contributors |
| 6 | # SPDX-License-Identifier: Apache-2.0 |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 9 | # not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 16 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | # |
| 20 | # Purpose |
| 21 | # |
| 22 | # Test translate_ciphers.py formatting by comparing the translated |
| 23 | # ciphersuite names to the true names. As in compat.sh, the spaces between |
| 24 | # the ciphersuite names are normalised. |
| 25 | # |
| 26 | # On fail, the translated cipher suite names do not match the correct ones. |
| 27 | # In this case the difference will be printed in stdout. |
| 28 | # |
| 29 | # This files main purpose is to ensure translate_ciphers.py can take strings |
| 30 | # in the expected format and return them in the format compat.sh will expect. |
| 31 | |
Joe Subbiani | 97cd599 | 2021-07-22 16:08:29 +0100 | [diff] [blame] | 32 | # Ciphers that will use translate_ciphers.py |
| 33 | M_CIPHERS="" |
| 34 | O_CIPHERS="" |
| 35 | G_CIPHERS="" |
| 36 | |
| 37 | # Ciphers taken directly from compat.sh |
| 38 | Mt_CIPHERS="" |
| 39 | Ot_CIPHERS="" |
| 40 | Gt_CIPHERS="" |
| 41 | |
| 42 | # Initial list to be split into 3 |
| 43 | CIPHERS="TLS-ECDHE-ECDSA-WITH-NULL-SHA \ |
| 44 | TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA \ |
| 45 | TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA \ |
| 46 | TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA \ |
| 47 | " |
| 48 | |
| 49 | M_CIPHERS="$M_CIPHERS \ |
| 50 | $CIPHERS" |
Joe Subbiani | a16ccac | 2021-07-22 18:52:17 +0100 | [diff] [blame^] | 51 | |
Joe Subbiani | 97cd599 | 2021-07-22 16:08:29 +0100 | [diff] [blame] | 52 | G=`python3 translate_ciphers.py g "$CIPHERS"` |
| 53 | G_CIPHERS="$G_CIPHERS \ |
| 54 | $G" |
| 55 | |
| 56 | O=`python3 translate_ciphers.py o "$CIPHERS"` |
| 57 | O_CIPHERS="$O_CIPHERS \ |
| 58 | $O" |
| 59 | |
| 60 | Mt_CIPHERS="$Mt_CIPHERS \ |
| 61 | TLS-ECDHE-ECDSA-WITH-NULL-SHA \ |
| 62 | TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA \ |
| 63 | TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA \ |
| 64 | TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA \ |
| 65 | " |
| 66 | Gt_CIPHERS="$Gt_CIPHERS \ |
| 67 | +ECDHE-ECDSA:+NULL:+SHA1 \ |
| 68 | +ECDHE-ECDSA:+3DES-CBC:+SHA1 \ |
| 69 | +ECDHE-ECDSA:+AES-128-CBC:+SHA1 \ |
| 70 | +ECDHE-ECDSA:+AES-256-CBC:+SHA1 \ |
| 71 | " |
| 72 | Ot_CIPHERS="$Ot_CIPHERS \ |
| 73 | ECDHE-ECDSA-NULL-SHA \ |
| 74 | ECDHE-ECDSA-DES-CBC3-SHA \ |
| 75 | ECDHE-ECDSA-AES128-SHA \ |
| 76 | ECDHE-ECDSA-AES256-SHA \ |
| 77 | " |
| 78 | |
| 79 | |
| 80 | # Initial list to be split into 3 |
| 81 | CIPHERS="TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 \ |
| 82 | TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384 \ |
| 83 | TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \ |
| 84 | TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384 \ |
| 85 | " |
| 86 | |
| 87 | M_CIPHERS="$M_CIPHERS \ |
| 88 | $CIPHERS" |
| 89 | |
| 90 | G=`python3 translate_ciphers.py g "$CIPHERS"` |
| 91 | G_CIPHERS="$G_CIPHERS \ |
| 92 | $G" |
| 93 | |
| 94 | O=`python3 translate_ciphers.py o "$CIPHERS"` |
| 95 | O_CIPHERS="$O_CIPHERS \ |
| 96 | $O" |
| 97 | |
| 98 | Mt_CIPHERS="$Mt_CIPHERS \ |
| 99 | TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 \ |
| 100 | TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384 \ |
| 101 | TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \ |
| 102 | TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384 \ |
| 103 | " |
| 104 | Gt_CIPHERS="$Gt_CIPHERS \ |
| 105 | +ECDHE-ECDSA:+AES-128-CBC:+SHA256 \ |
| 106 | +ECDHE-ECDSA:+AES-256-CBC:+SHA384 \ |
| 107 | +ECDHE-ECDSA:+AES-128-GCM:+AEAD \ |
| 108 | +ECDHE-ECDSA:+AES-256-GCM:+AEAD \ |
| 109 | " |
| 110 | Ot_CIPHERS="$Ot_CIPHERS \ |
| 111 | ECDHE-ECDSA-AES128-SHA256 \ |
| 112 | ECDHE-ECDSA-AES256-SHA384 \ |
| 113 | ECDHE-ECDSA-AES128-GCM-SHA256 \ |
| 114 | ECDHE-ECDSA-AES256-GCM-SHA384 \ |
| 115 | " |
| 116 | |
| 117 | # Normalise spacing |
| 118 | M_CIPHERS=$( echo "$M_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//') |
| 119 | G_CIPHERS=$( echo "$G_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//') |
| 120 | O_CIPHERS=$( echo "$O_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//') |
| 121 | |
| 122 | Mt_CIPHERS=$( echo "$Mt_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//') |
| 123 | Gt_CIPHERS=$( echo "$Gt_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//') |
| 124 | Ot_CIPHERS=$( echo "$Ot_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//') |
| 125 | |
| 126 | # Compare the compat.sh names with the translated names |
| 127 | # Upon fail, print them to view the differences |
| 128 | if [ "$Mt_CIPHERS" != "$M_CIPHERS" ] |
| 129 | then |
| 130 | echo "MBED Translated: $M_CIPHERS" |
| 131 | echo "MBED Original: $Mt_CIPHERS" |
| 132 | fi |
| 133 | if [ "$Gt_CIPHERS" != "$G_CIPHERS" ] |
| 134 | then |
| 135 | echo "GNU Translated: $G_CIPHERS" |
| 136 | echo "GNU Original: $Gt_CIPHERS" |
| 137 | fi |
| 138 | if [ "$Ot_CIPHERS" != "$O_CIPHERS" ] |
| 139 | then |
| 140 | echo "OpenSSL Translated: $O_CIPHERS" |
| 141 | echo "OpenSSL Original: $Ot_CIPHERS" |
Joe Subbiani | a16ccac | 2021-07-22 18:52:17 +0100 | [diff] [blame^] | 142 | fi |