From: Laszlo Ersek <lersek@redhat.com>
To: edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>, Qin Long <qin.long@intel.com>,
Siyuan Fu <siyuan.fu@intel.com>, Ting Ye <ting.ye@intel.com>
Subject: [PATCH 08/13] CryptoPkg/TlsLib: add the "TlsMappingTable.sh" POSIX shell script
Date: Tue, 3 Apr 2018 16:51:44 +0200 [thread overview]
Message-ID: <20180403145149.8925-9-lersek@redhat.com> (raw)
In-Reply-To: <20180403145149.8925-1-lersek@redhat.com>
Add a shell script that will help us keep "TlsCipherMappingTable" in
"TlsConfig.c" up-to-date.
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Qin Long <qin.long@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Ting Ye <ting.ye@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=915
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
CryptoPkg/Library/TlsLib/TlsLib.inf | 2 +
CryptoPkg/Library/TlsLib/TlsMappingTable.sh | 140 ++++++++++++++++++++
2 files changed, 142 insertions(+)
diff --git a/CryptoPkg/Library/TlsLib/TlsLib.inf b/CryptoPkg/Library/TlsLib/TlsLib.inf
index a3f93e7165cb..dc7f3a5dbd23 100644
--- a/CryptoPkg/Library/TlsLib/TlsLib.inf
+++ b/CryptoPkg/Library/TlsLib/TlsLib.inf
@@ -52,6 +52,8 @@ [BuildOptions]
#
# suppress the following warnings so we do not break the build with warnings-as-errors:
# C4090: 'function' : different 'const' qualifiers
#
MSFT:*_*_*_CC_FLAGS = /wd4090
+[UserExtensions.TianoCore."ExtraFiles"]
+ TlsMappingTable.sh
diff --git a/CryptoPkg/Library/TlsLib/TlsMappingTable.sh b/CryptoPkg/Library/TlsLib/TlsMappingTable.sh
new file mode 100644
index 000000000000..0cb4a4faa597
--- /dev/null
+++ b/CryptoPkg/Library/TlsLib/TlsMappingTable.sh
@@ -0,0 +1,140 @@
+## @file
+#
+# POSIX shell script to refresh "TlsCipherMappingTable" in "TlsConfig.c".
+#
+# Note: the output of this script is not meant to blindly replace the current
+# contents of "TlsCipherMappingTable". It only helps with the composition and
+# formatting of candidate lines.
+#
+# Copyright (C) 2018, Red Hat, Inc.
+#
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+# Exit on error, treat unset variables as errors, don't overwrite existing
+# files with the ">" output redirection operator.
+set -e -u -C
+
+# This script uses a few utilities that are not defined by POSIX. Check if they
+# are available.
+if ( ! command -v mktemp ||
+ ! command -v openssl ||
+ ! command -v curl ||
+ ! command -v column ) >/dev/null
+then
+ BASENAME=$(basename -- "$0")
+ {
+ printf -- '%s: please install the following utilities first:\n' "$BASENAME"
+ printf -- '%s: mktemp openssl curl column\n' "$BASENAME"
+ } >&2
+ exit 1
+fi
+
+# Create a temporary file for saving the OpenSSL output.
+OPENSSL_LIST=$(mktemp)
+trap 'rm -f -- "$OPENSSL_LIST"' EXIT
+
+# Create a temporary file for saving the IANA TLS Cipher Suite Registry.
+IANA_LIST=$(mktemp)
+trap 'rm -f -- "$OPENSSL_LIST" "$IANA_LIST"' EXIT
+
+# Sorting, and range expressions in regular expressions, depend on the locale.
+# Use a well-defined locale.
+LC_ALL=C
+export LC_ALL
+
+# Get OPENSSL_LIST.
+{
+ # List cipher suite codes and names from OpenSSL.
+ openssl ciphers -V ALL
+
+ # This produces a line format like:
+ # 0xC0,0x30 - ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD
+ # (sequences of space characters squeezed for brevity).
+} |
+{
+ # Project the list to UINT16 hex codes (network byte order interpretation)
+ # and OpenSSL cipher suite names.
+ sed -r -n -e 's/^ *0x([0-9A-F]{2}),0x([0-9A-F]{2}) - ([^ ]+) .*$/\1\2 \3/p'
+
+ # This produces a line format like:
+ # C030 ECDHE-RSA-AES256-GCM-SHA384
+} |
+{
+ # Sort the output so we can later join it on the UINT16 hex code as key.
+ sort
+} >>"$OPENSSL_LIST"
+
+# Get IANA_LIST.
+{
+ # Download the CSV file from the IANA website.
+ curl -s https://www.iana.org/assignments/tls-parameters/tls-parameters-4.csv
+
+ # This produces a line format like:
+ # Value,Description,DTLS-OK,Reference
+ # "0x00,0x00",TLS_NULL_WITH_NULL_NULL,Y,[RFC5246]
+} |
+{
+ # Project the list to UINT16 hex codes (network byte order interpretation)
+ # and Descriptions (TLS_xxx macros).
+ sed -r -n \
+ -e 's/^"0x([0-9A-F]{2}),0x([0-9A-F]{2})",([A-Za-z0-9_]+).*$/\1\2 \3/p'
+
+ # This produces a line format like:
+ # 0000 TLS_NULL_WITH_NULL_NULL
+} |
+{
+ # Sort the output so we can later join it on the UINT16 hex code as key.
+ sort
+} >>"$IANA_LIST"
+
+# Produce the C source code on stdout.
+{
+ # Join the two lists first. Elements that are in exactly one input file are
+ # dropped.
+ join -- "$OPENSSL_LIST" "$IANA_LIST"
+
+ # This produces a line format like:
+ # 0004 RC4-MD5 TLS_RSA_WITH_RC4_128_MD5
+ # And the output remains sorted by UINT16 hex key.
+} |
+{
+ # Produce a valid C language line. Be careful that only one space character
+ # is preserved, for the next step.
+ sed -r -n -e 's!^([0-9A-F]{4}) ([^ ]+) ([^ ]+)$!{0x\1,"\2"}, ///\3!p'
+
+ # This produces a line format like:
+ # {0x0004,"RC4-MD5"}, ///TLS_RSA_WITH_RC4_128_MD5
+} |
+{
+ # Align the rightmost column nicely (the TLS_xxx macros). The "column"
+ # command will expand the space character as necessary.
+ column -t
+
+ # This produces a line format like:
+ # {0x0004,"RC4-MD5"}, ///TLS_RSA_WITH_RC4_128_MD5
+} |
+{
+ # Final touches:
+ # - replace the opening brace "{" with " MAP ( ",
+ # - insert one space character after the first comma ","
+ # - replace the closing brace "}" with " )",
+ # - remove one space character after the second comma "," (because the
+ # "column" utility pads space characters to at least two),
+ # - insert one space character after the comment marker "///"
+ sed \
+ -e 's/^{/ MAP ( /' \
+ -e 's/,/, /' \
+ -e 's/}, / ),/' \
+ -e 's!///!/// !'
+
+ # This produces a line format like:
+ # MAP ( 0x0004, "RC4-MD5" ), /// TLS_RSA_WITH_RC4_128_MD5
+}
--
2.14.1.3.gb7cf6e02401b
next prev parent reply other threads:[~2018-04-03 14:52 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-03 14:51 [PATCH 00/13] {Ovmf, Mde, Network, Crypto}Pkg: fixes+features for setting HTTPS cipher suites Laszlo Ersek
2018-04-03 14:51 ` [PATCH 01/13] OvmfPkg/TlsAuthConfigLib: configure trusted cipher suites for HTTPS boot Laszlo Ersek
2018-04-03 14:51 ` [PATCH 02/13] MdePkg/Include/Protocol/Tls.h: pack structures from the TLS RFC Laszlo Ersek
2018-04-03 15:08 ` Gao, Liming
2018-04-04 10:32 ` Laszlo Ersek
2018-04-10 1:51 ` Fu, Siyuan
2018-04-03 14:51 ` [PATCH 03/13] NetworkPkg/TlsDxe: verify DataSize for EfiTlsCipherList Laszlo Ersek
2018-04-10 1:51 ` Fu, Siyuan
2018-04-03 14:51 ` [PATCH 04/13] NetworkPkg/TlsDxe: clean up byte order conversion " Laszlo Ersek
2018-04-10 1:53 ` Fu, Siyuan
2018-04-03 14:51 ` [PATCH 05/13] CryptoPkg/TlsLib: replace TlsGetCipherString() with TlsGetCipherMapping() Laszlo Ersek
2018-04-03 14:51 ` [PATCH 06/13] CryptoPkg/TlsLib: use binary search in the TlsGetCipherMapping() function Laszlo Ersek
2018-04-03 14:51 ` [PATCH 07/13] CryptoPkg/TlsLib: pre-compute OpensslCipherLength in TlsCipherMappingTable Laszlo Ersek
2018-04-03 14:51 ` Laszlo Ersek [this message]
2018-04-03 14:51 ` [PATCH 09/13] CryptoPkg/TlsLib: extend "TlsCipherMappingTable" Laszlo Ersek
2018-04-03 14:51 ` [PATCH 10/13] CryptoPkg/TlsLib: sort [LibraryClasses] section in the INF file Laszlo Ersek
2018-04-03 14:51 ` [PATCH 11/13] CryptoPkg/TlsLib: sanitize lib classes in internal header and INF Laszlo Ersek
2018-04-03 14:51 ` [PATCH 12/13] CryptoPkg/TlsLib: clean up leading comment for TlsSetCipherList() Laszlo Ersek
2018-04-03 14:51 ` [PATCH 13/13] CryptoPkg/TlsLib: rewrite TlsSetCipherList() Laszlo Ersek
2018-04-10 4:09 ` [PATCH 00/13] {Ovmf, Mde, Network, Crypto}Pkg: fixes+features for setting HTTPS cipher suites Wu, Jiaxin
2018-04-10 7:40 ` Long, Qin
2018-04-10 10:02 ` Laszlo Ersek
2018-04-10 10:10 ` Laszlo Ersek
2018-04-10 16:56 ` Long, Qin
2018-04-10 9:47 ` Laszlo Ersek
2018-04-10 17:06 ` Long, Qin
2018-04-10 20:06 ` Laszlo Ersek
2018-04-11 1:59 ` Wu, Jiaxin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180403145149.8925-9-lersek@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox