mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-09-11 12:10:46 +03:00
.github
3rdparty
ChangeLog.d
cmake
configs
docs
doxygen
include
library
programs
scripts
tests
.jenkins
configs
data_files
docker
git-scripts
include
opt-testcases
scripts
all-in-docker.sh
all.sh
analyze_outcomes.py
basic-build-test.sh
basic-in-docker.sh
check-doxy-blocks.pl
check-generated-files.sh
check-python-files.sh
check_files.py
check_names.py
check_test_cases.py
depends.py
docker_env.sh
doxygen.sh
gen_ctr_drbg.pl
gen_gcm_decrypt.pl
gen_gcm_encrypt.pl
gen_pkcs1_v21_sign_verify.pl
generate-afl-tests.sh
generate_bignum_tests.py
generate_psa_tests.py
generate_test_code.py
generate_tls13_compat_tests.py
list-identifiers.sh
list_internal_identifiers.py
psa_collect_statuses.py
recursion.pl
run-test-suites.pl
scripts_path.py
set_psa_test_dependencies.py
tcp_client.pl
test-ref-configs.pl
test_config_script.py
test_generate_test_code.py
test_psa_compliance.py
test_psa_constant_names.py
test_zeroize.gdb
translate_ciphers.py
travis-log-failure.sh
src
suites
.gitignore
CMakeLists.txt
Descriptions.txt
Makefile
compat-in-docker.sh
compat.sh
context-info.sh
make-in-docker.sh
ssl-opt-in-docker.sh
ssl-opt.sh
visualc
.gitattributes
.gitignore
.globalrc
.mypy.ini
.pylintrc
.travis.yml
.uncrustify.cfg
BRANCHES.md
BUGS.md
CMakeLists.txt
CONTRIBUTING.md
ChangeLog
DartConfiguration.tcl
LICENSE
Makefile
README.md
SECURITY.md
SUPPORT.md
dco.txt
As a result, the copyright of contributors other than Arm is now acknowledged, and the years of publishing are no longer tracked in the source files. Also remove the now-redundant lines declaring that the files are part of MbedTLS. This commit was generated using the following script: # ======================== #!/bin/sh # Find files find '(' -path './.git' -o -path './3rdparty' ')' -prune -o -type f -print | xargs sed -bi ' # Replace copyright attribution line s/Copyright.*Arm.*/Copyright The Mbed TLS Contributors/I # Remove redundant declaration and the preceding line $!N /This file is part of Mbed TLS/Id P D ' # ======================== Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
102 lines
3.2 KiB
Perl
Executable File
102 lines
3.2 KiB
Perl
Executable File
#!/usr/bin/env perl
|
|
|
|
# A simple TCP client that sends some data and expects a response.
|
|
# Usage: tcp_client.pl HOSTNAME PORT DATA1 RESPONSE1
|
|
# DATA: hex-encoded data to send to the server
|
|
# RESPONSE: regexp that must match the server's response
|
|
#
|
|
# Copyright The Mbed TLS Contributors
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
use warnings;
|
|
use strict;
|
|
use IO::Socket::INET;
|
|
|
|
# Pack hex digits into a binary string, ignoring whitespace.
|
|
sub parse_hex {
|
|
my ($hex) = @_;
|
|
$hex =~ s/\s+//g;
|
|
return pack('H*', $hex);
|
|
}
|
|
|
|
## Open a TCP connection to the specified host and port.
|
|
sub open_connection {
|
|
my ($host, $port) = @_;
|
|
my $socket = IO::Socket::INET->new(PeerAddr => $host,
|
|
PeerPort => $port,
|
|
Proto => 'tcp',
|
|
Timeout => 1);
|
|
die "Cannot connect to $host:$port: $!" unless $socket;
|
|
return $socket;
|
|
}
|
|
|
|
## Close the TCP connection.
|
|
sub close_connection {
|
|
my ($connection) = @_;
|
|
$connection->shutdown(2);
|
|
# Ignore shutdown failures (at least for now)
|
|
return 1;
|
|
}
|
|
|
|
## Write the given data, expressed as hexadecimal
|
|
sub write_data {
|
|
my ($connection, $hexdata) = @_;
|
|
my $data = parse_hex($hexdata);
|
|
my $total_sent = 0;
|
|
while ($total_sent < length($data)) {
|
|
my $sent = $connection->send($data, 0);
|
|
if (!defined $sent) {
|
|
die "Unable to send data: $!";
|
|
}
|
|
$total_sent += $sent;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
## Read a response and check it against an expected prefix
|
|
sub read_response {
|
|
my ($connection, $expected_hex) = @_;
|
|
my $expected_data = parse_hex($expected_hex);
|
|
my $start_offset = 0;
|
|
while ($start_offset < length($expected_data)) {
|
|
my $actual_data;
|
|
my $ok = $connection->recv($actual_data, length($expected_data));
|
|
if (!defined $ok) {
|
|
die "Unable to receive data: $!";
|
|
}
|
|
if (($actual_data ^ substr($expected_data, $start_offset)) =~ /[^\000]/) {
|
|
printf STDERR ("Received \\x%02x instead of \\x%02x at offset %d\n",
|
|
ord(substr($actual_data, $-[0], 1)),
|
|
ord(substr($expected_data, $start_offset + $-[0], 1)),
|
|
$start_offset + $-[0]);
|
|
return 0;
|
|
}
|
|
$start_offset += length($actual_data);
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
if (@ARGV != 4) {
|
|
print STDERR "Usage: $0 HOSTNAME PORT DATA1 RESPONSE1\n";
|
|
exit(3);
|
|
}
|
|
my ($host, $port, $data1, $response1) = @ARGV;
|
|
my $connection = open_connection($host, $port);
|
|
write_data($connection, $data1);
|
|
if (!read_response($connection, $response1)) {
|
|
exit(1);
|
|
}
|
|
close_connection($connection);
|