Compare commits
1 Commits
master
...
stream-rea
Author | SHA1 | Date | |
---|---|---|---|
250d59495b |
39
ocdec.sh
39
ocdec.sh
@ -124,31 +124,38 @@ function decryptFile() {
|
|||||||
|
|
||||||
decFileKeyContent="$( openssl rc4 -d -in "$encFileKeyPath" -iv 0 -K $decUserFileShareKeyHEX )"
|
decFileKeyContent="$( openssl rc4 -d -in "$encFileKeyPath" -iv 0 -K $decUserFileShareKeyHEX )"
|
||||||
decFileKeyContentHEX="$( echo -n $decFileKeyContent |od -An -tx1 |tr -dc '[:xdigit:]' )"
|
decFileKeyContentHEX="$( echo -n $decFileKeyContent |od -An -tx1 |tr -dc '[:xdigit:]' )"
|
||||||
decFileKeyContentHEX=${decFileKeyContentHEX:0:64}
|
|
||||||
# --- Get the FileKey ---
|
# --- Get the FileKey ---
|
||||||
|
|
||||||
# --- Decrypt the file ---
|
# --- Decrypt the file ---
|
||||||
# OC writes the encrypted file in 8K chunks, each containing it's own iv in the end
|
encFileContentsALL="$(cat "${USER}/$encFilePath")"
|
||||||
chunkSize=8192
|
encFileContentsNOHEAD=$(echo -n "$encFileContentsALL" | sed -r 's/^HBEGIN:.+:HEND-*//')
|
||||||
while read -d '' -n $chunkSize CHUNK || [ ! -z "$CHUNK" ]; do
|
|
||||||
#split chunk into payload an iv string (strip padding from iv)
|
pos=0; posc=0; encStream="";
|
||||||
read payload iv <<<`echo $CHUNK | sed -r 's/(.*)00iv00(.{16})xx/\1 \2/'`
|
# bottleneck: bash read by character is super slow
|
||||||
CHUNK=
|
while IFS= read -r -n1 char; do
|
||||||
#if [ -z $CHUNK ]; then break; fi
|
(( posc++ ))
|
||||||
# convert base64 iv into hex
|
if $(echo ${encStream: -24} |grep -Eq "^00iv00.{16}xx$"); then
|
||||||
iv=$(echo -n "$iv" | od -An -tx1 | tr -dc '[:xdigit:]' )
|
plainIV=$(echo ${encStream: -24} |sed -r 's/^00iv00//;s/xx$//')
|
||||||
# decode chunk
|
encStreamReady=${encStream:((posc - pos - 1)):((pos - 24))}
|
||||||
openssl enc -AES-256-CFB -d -nosalt -base64 -A -K $decFileKeyContentHEX -iv $iv -in <(echo "$payload")
|
(( pos=0 ))
|
||||||
#done <<<`sed -r 's/^HBEGIN:.+:HEND-*//' <"${USER}/$encFilePath"` # pipe the encrypted file without head into the loop
|
|
||||||
done < <(dd bs=$chunkSize skip=1 if="${USER}/$encFilePath")
|
#echo "[::] DEBUG: " $encStreamReady with $plainIV
|
||||||
|
# can decrypt now
|
||||||
|
plainFileIVHEX=$(echo -n "$plainIV" |od -An -tx1 |tr -dc '[:xdigit:]')
|
||||||
|
openssl enc -AES-256-CFB -d -nosalt -base64 -A -K $decFileKeyContentHEX -iv $plainFileIVHEX -in <(echo "$encStreamReady")
|
||||||
|
#php -r "echo openssl_decrypt('$encStreamReady', 'AES-256-CFB', '$decFileKeyContent', false, '$plainIV');"
|
||||||
|
fi
|
||||||
|
(( pos++ ))
|
||||||
|
encStream="$encStream$char"
|
||||||
|
done <<< $encFileContentsNOHEAD
|
||||||
# --- Decrypt the file ---
|
# --- Decrypt the file ---
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get a username from the path (arg1)
|
# Get a username from the path (arg1)
|
||||||
USER="$(echo "$1" |cut -sd / -f 1)"
|
USER="$(echo $1 |cut -sd / -f 1)"
|
||||||
|
|
||||||
# Strip off the username from the path (arg1)
|
# Strip off the username from the path (arg1)
|
||||||
FILETD="$(echo "$1" |cut -sd / -f 2-)"
|
FILETD="$(echo $1 |cut -sd / -f 2-)"
|
||||||
|
|
||||||
if [ ! -r "$USER" ]; then
|
if [ ! -r "$USER" ]; then
|
||||||
echo "User directory cannot be found! Are you sure you are in ownCloud's data directory?"
|
echo "User directory cannot be found! Are you sure you are in ownCloud's data directory?"
|
||||||
|
Loading…
Reference in New Issue
Block a user