Compare commits
10 Commits
stream-rea
...
master
Author | SHA1 | Date | |
---|---|---|---|
a703dae710 | |||
![]() |
d1cb5a5ac9 | ||
![]() |
163fb8eab7 | ||
1375e66607 | |||
a01fd0e848 | |||
![]() |
2adaf0464f | ||
![]() |
f5156ef14c | ||
![]() |
6839809335 | ||
![]() |
d25fc4b5c8 | ||
![]() |
15bbe37986 |
31
ocdec.sh
31
ocdec.sh
@ -124,30 +124,31 @@ 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 ---
|
||||||
# TODO: to figure out how to speed-up the decryption process.
|
# OC writes the encrypted file in 8K chunks, each containing it's own iv in the end
|
||||||
# bottlenecks:
|
chunkSize=8192
|
||||||
# - awk is running really slow, consuming lot of CPU
|
while read -d '' -n $chunkSize CHUNK || [ ! -z "$CHUNK" ]; do
|
||||||
encFileContentsALL="$(cat "${USER}/$encFilePath")"
|
#split chunk into payload an iv string (strip padding from iv)
|
||||||
encFileContentsNOHEAD=$(echo -n "$encFileContentsALL" | sed -r 's/^HBEGIN:.+:HEND-*//')
|
read payload iv <<<`echo $CHUNK | sed -r 's/(.*)00iv00(.{16})xx/\1 \2/'`
|
||||||
N=0
|
CHUNK=
|
||||||
for IV in $(echo -n "$encFileContentsNOHEAD" |grep -E -o '00iv00.{16}xx' |sed -r 's/^00iv00//;s/xx$//'); do
|
#if [ -z $CHUNK ]; then break; fi
|
||||||
N=$[N+1]
|
# convert base64 iv into hex
|
||||||
encFileContentsBASE64=$(echo -n "$encFileContentsNOHEAD" |awk -F '00iv00................xx' -v N=$N '{print $N}')
|
iv=$(echo -n "$iv" | od -An -tx1 | tr -dc '[:xdigit:]' )
|
||||||
plainFileIVHEX=$(echo -n "$IV" |od -An -tx1 |tr -dc '[:xdigit:]')
|
# decode chunk
|
||||||
openssl enc -AES-256-CFB -d -nosalt -base64 -A -K $decFileKeyContentHEX -iv $plainFileIVHEX -in <(echo "$encFileContentsBASE64")
|
openssl enc -AES-256-CFB -d -nosalt -base64 -A -K $decFileKeyContentHEX -iv $iv -in <(echo "$payload")
|
||||||
#php -r "echo openssl_decrypt('$encFileContentsBASE64', 'AES-256-CFB', '$decFileKeyContent', false, '$IV');"
|
#done <<<`sed -r 's/^HBEGIN:.+:HEND-*//' <"${USER}/$encFilePath"` # pipe the encrypted file without head into the loop
|
||||||
done
|
done < <(dd bs=$chunkSize skip=1 if="${USER}/$encFilePath")
|
||||||
# --- 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