blob: 55d8a8a8e81b0686c5b73853bd4236681d0e69b3 [file] [log] [blame]
Joe Subbiani97cd5992021-07-22 16:08:29 +01001#!/bin/sh
2
Joe Subbiania16ccac2021-07-22 18:52:17 +01003# 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 Subbiani97cd5992021-07-22 16:08:29 +010032# Ciphers that will use translate_ciphers.py
33M_CIPHERS=""
34O_CIPHERS=""
35G_CIPHERS=""
36
37# Ciphers taken directly from compat.sh
38Mt_CIPHERS=""
39Ot_CIPHERS=""
40Gt_CIPHERS=""
41
42# Initial list to be split into 3
43CIPHERS="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
49M_CIPHERS="$M_CIPHERS \
50 $CIPHERS"
Joe Subbiania16ccac2021-07-22 18:52:17 +010051
Joe Subbiani97cd5992021-07-22 16:08:29 +010052G=`python3 translate_ciphers.py g "$CIPHERS"`
53G_CIPHERS="$G_CIPHERS \
54 $G"
55
56O=`python3 translate_ciphers.py o "$CIPHERS"`
57O_CIPHERS="$O_CIPHERS \
58 $O"
59
60Mt_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 "
66Gt_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 "
72Ot_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
81CIPHERS="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
87M_CIPHERS="$M_CIPHERS \
88 $CIPHERS"
89
90G=`python3 translate_ciphers.py g "$CIPHERS"`
91G_CIPHERS="$G_CIPHERS \
92 $G"
93
94O=`python3 translate_ciphers.py o "$CIPHERS"`
95O_CIPHERS="$O_CIPHERS \
96 $O"
97
98Mt_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 "
104Gt_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 "
110Ot_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
118M_CIPHERS=$( echo "$M_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
119G_CIPHERS=$( echo "$G_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
120O_CIPHERS=$( echo "$O_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
121
122Mt_CIPHERS=$( echo "$Mt_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
123Gt_CIPHERS=$( echo "$Gt_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
124Ot_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
128if [ "$Mt_CIPHERS" != "$M_CIPHERS" ]
129then
130 echo "MBED Translated: $M_CIPHERS"
131 echo "MBED Original: $Mt_CIPHERS"
132fi
133if [ "$Gt_CIPHERS" != "$G_CIPHERS" ]
134then
135 echo "GNU Translated: $G_CIPHERS"
136 echo "GNU Original: $Gt_CIPHERS"
137fi
138if [ "$Ot_CIPHERS" != "$O_CIPHERS" ]
139then
140 echo "OpenSSL Translated: $O_CIPHERS"
141 echo "OpenSSL Original: $Ot_CIPHERS"
Joe Subbiania16ccac2021-07-22 18:52:17 +0100142fi