#!/usr/bin/bash #*************************************************************************** # This file is part of the CRYPTO BONE # File : requesttarball (client) # Version : 2.0 (ALL-IN-ONE) # License : BSD-3-Clause # Date : 23 Mar 2025 # Contact : Please send enquiries and bug-reports to innovation@senderek.ie # # # Copyright (c) 2015-2025 # Ralf Senderek, Ireland. All rights reserved. (https://senderek.ie) # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by Ralf Senderek. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # #**************************************************************************** # load functions and global variables . /usr/lib/cryptobone/safewebdrop.header . ${CBHOME}/safewebdrop/bin/client-functions REQ=${RAM}/filerequest FETCH="${RAM}/tarball.tgz" PASS=$(/usr/bin/echo "get-element webdropsecret" | /usr/bin/socat -t15 - UNIX-connect:$SOCK 2> /dev/null) HOST=$(/usr/bin/echo "get-element webdropserver" | /usr/bin/socat -t15 - UNIX-connect:$SOCK 2> /dev/null) ID=$(/usr/bin/echo "get-element webdropuser" | /usr/bin/socat -t15 - UNIX-connect:$SOCK 2> /dev/null) log "---tarball---" if [[ ${PASS} ]] && [[ ${HOST} ]] && [[ ${ID} ]] ; then # PHASE 1: send NEW request CHALLENGE=$(curl https://${HOST}/cgi-bin/safewebdropgettarball?${ID}\&NEW 2> /dev/null) if (( ${#CHALLENGE} != 64 )) ; then log "1: no challenge EXIT" exit 2 fi log "1: ${ID} got challenge from server" # PHASE 2: create a valid request /usr/bin/rm -f ${REQ}.hash.sig 2> /dev/null # user:request /usr/bin/echo -n "${ID}:" > $REQ /usr/bin/echo -n "${CHALLENGE}:" >> $REQ /usr/bin/echo -n "ALL" >> $REQ # generate a hash of the request generate_requesthash # and send it if (( ${#SIG} > 10 )) ; then /usr/bin/sleep 1 REQUEST=$(/usr/bin/cat ${REQ}) /usr/bin/curl https://${HOST}/cgi-bin/safewebdropgettarball?${ID}\&${REQUEST}\&${SIG} 2>/dev/null > ${FETCH} NUM=$(/usr/bin/wc -c ${FETCH} | /usr/bin/cut -f1 -d" ") log "2: $ID ${NUM} bytes received " if (( ${NUM} > 10 )) ; then # we've got a real tarball HASH=$(filehash ${FETCH}) if (( ${#HASH} == 64 )) ; then # fetched data has been SHA-256 hashed ###log "${#HASH} ${HASH}" # return the hash of the fetched data to the server /usr/bin/rm -f ${REQ}.hash.sig 2> /dev/null # user:challenge:hash /usr/bin/echo -n "${ID}:" > $REQ /usr/bin/echo -n "${CHALLENGE}:" >> $REQ /usr/bin/echo -n "${HASH}" >> $REQ # generate a hash of the request generate_requesthash # and send it if (( ${#SIG} > 10 )) ; then /usr/bin/sleep 1 REQUEST=$(/usr/bin/cat ${REQ}) # phase 3 : send the hash back to the server, so files can be deleted there OK=$(/usr/bin/curl https://${HOST}/cgi-bin/safewebdropgettarball?${ID}\&${REQUEST}\&${SIG} 2> /dev/null) if [[ ${OK} = "OK" ]] ; then log "3: deleted: ${OK} - END" else log "Files remain on the server" fi else log "3: no signature" fi fi else # we've got NOFILES in ${FETCH}, remove it /usr/bin/rm -f "${FETCH}" log "3: ${ID} EMPTY" fi else log "2: no signature" fi exit 0 # split the file batch into files in ${RAM}/FILES INFILE="${RAM}/allfiles" if [[ -r ${INFILE} ]] ; then log "splitting ${INFILE}" # remove \r from INFILE /usr/bin/cat ${INFILE} | /usr/bin/tr -d '\r' > ${INFILE}.new /usr/bin/mv ${INFILE}.new ${INFILE} FILENAME=${RAM}/FILES/newattachment.asc while read LINE do if (( ${#LINE} == 1 )) && [[ ${LINE} = "." ]] then LASTLINE=$(/usr/bin/tail -1 ${FILENAME}) ATTACHMENTNAME=${LASTLINE##*:} NUMBER=${LASTLINE%%:*} ATTACHMENT=${ATTACHMENTNAME}.asc if [[ ${ATTACHMENT} ]]; then /usr/bin/mv ${FILENAME} ${RAM}/FILES/${ATTACHMENT} log " ${ATTACHMENT} moved" log "$(/usr/bin/ls -l ${ATTACHMENT})" fi else /usr/bin/echo ${LINE} >> ${FILENAME} fi done < ${INFILE} /usr/bin/mv ${INFILE} "${INFILE}-$(/usr/bin/date +%y.%m.%d-%H.%M)" 2> /dev/null /usr/bin/chmod 600 "${INFILE}-$(/usr/bin/date +%y.%m.%d-%H.%M)" # clean up empty file newattachment.asc, resulting on the last newline after . /usr/bin/rm -f ${RAM}/FILES/newattachment.asc 2>/dev/null fi else log "not enough parameter" exit 1 fi exit 0