Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BASH SCRIPT Digital Signatures For the files contained in a directory (given as a command line argument) match each digital signature ( *.sign files )

BASH SCRIPT

Digital Signatures

For the files contained in a directory (given as a command line argument) match each digital signature (*.sign files) to it's corresponding data file (*.dat files). The public key required to verified a signature will be given as a second command line argument.

Any hashes were created using the following: $ openssl dgst -sha256 -binary

Below is the general signing and verification process for reference.

Example:

$ bash script.sh folder pub.key

Data File | Signature

qwerty.dat - signature_one.sign

cookies.dat - signature_two.sign

Sol22:

Here's a possible Bash script to match digital signatures to their corresponding data files and verify them using a public key:

#!/bin/bash

# Check that the correct number of arguments were provided

if [ "$#" -ne 2 ]; then

echo "Usage: $0 "

exit 1

fi

# Save the directory and public key arguments

directory="$1"

public_key="$2"

# Loop through each signature file in the directory

for signature_file in "${directory}"/*.sign; do

# Extract the name of the corresponding data file

data_file="${signature_file%.sign}.dat"

# Verify the signature using the public key

if openssl dgst -sha256 -verify "${public_key}" -signature "${signature_file}" "${data_file}"; then

echo "Verified: ${data_file} | ${signature_file}"

else

echo "Not verified: ${data_file} | ${signature_file}"

fi

done

The script takes two command line arguments: the directory containing the data and signature files, and the public key used to verify the signatures. It then loops through each signature file in the directory, extracts the name of the corresponding data file by replacing the ".sign" extension with ".dat", and verifies the signature using the openssl dgst command. If the verification succeeds, it outputs a message indicating that the data file was verified with the corresponding signature file. If the verification fails, it outputs a message indicating that the data file was not verified with the corresponding signature file.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

which of the following is included on a decedent's final return?

Answered: 1 week ago