e-alfred / ocdownloader

ocDownloader - AGPL-licensed multi-protocol download manager for Nextcloud using ARIA2, youtube-dl and Curl (supports Youtube, BitTorrent, HTTP, FTP)
https://github.com/e-alfred/ocdownloader
GNU Affero General Public License v3.0
375 stars 85 forks source link

When encryption is activated, aria2c can't decode the torrent file #14

Open depado opened 7 years ago

depado commented 7 years ago

Hi ! I've been wondering why aria2c kept throwing me those :

08/28 11:59:02 [DEBUG] Exception caught
Exception: [download_helper.cc:291] errorCode=25 Bencode decoding failed

Turns out, ocdownloader gives the filepath to aria2c, aria2c receives an encrypted torrent file and can't do much about this...

Is there a quick way I can fix this, without disabling encryption in Nextcloud ?

Nibbels commented 7 years ago

Nice catch!

Nibbels commented 7 years ago

My next question is whether or not your files get encrypted when downloaded. Does scan folder encrypt the files not encrypted? If not they are just there - unencrypted.

depado commented 7 years ago

I don't understand your question 😞
I tried uploading a torrent file directly form ocdownloader's interface, looks like the issue is the same, as soon as the file is received it is encrypted, then the path is sent to aria which can't make sense of the data it is given. When giving this torrent file (unencrypted) to aria, it works fine.

Nibbels commented 7 years ago

Well when we just write a file to your downloads folder, then nextcloud has to read and encrypt and save it somehow. Else it would be not encrypted. This might not be a problem at all but we need to consider this.

I remember reading some documentation .. and found it again: https://docs.nextcloud.com/server/12/admin_manual/configuration_files/encryption_configuration.html https://docs.nextcloud.com/server/12/admin_manual/_images/encryption3.png "Files are encrypted while uploading"

There are commands for encrypting some users only but I dont see one to encrypt / have decrypted some folders only. if we or you might find some occ command for that I might be able to find the function for decrypting one file/folder and adapt it for those .torrents

depado commented 7 years ago

Yes that's one limitation of the encryption module, it's all or nothing. According to the documentation "Third-party app data" aren't encrypted. Maybe there is a way to store the uploaded torrent files as app data ? I don't know much about third party apps (and just started using nextcloud a few weeks ago).

Also it looks like there is no way to decrypt a single file or folder using occ command line tool.

depado commented 7 years ago

This may be useful Note that using the occ command you can check if encryption is activated or not. If encryption is activated, then maybe upload the torrent file to AppData instead of user's storage ? Just a suggestion, I don't know if that's easily implemented.

Nibbels commented 7 years ago

aria2 would be able to have a link sent instead of the torrent, i guess... $ aria2c --follow-torrent=mem "http://host/file.torrent" https://aria2.github.io/manual/en/html/aria2c.html#download-files-using-a-remote-bittorrent-file this seems to work like magnet links would work, (i guess... untested)

depado commented 7 years ago

That would indeed be a solution :) Would it be possible to add a field for pasting a torrent link in ocdownloader ?

depado commented 7 years ago

In fact the "better" option would be to add :

I'll have a look at how ocdownloader is coded, I don't know much in PHP so not sure if I'm going to be any help with that, but I'll try automatically check if the encryption module is enabled and if so, how to write torrents to an app data folder. (Or even to a temporary unencrypted folder)

Nibbels commented 7 years ago

I am totally with you! My time got a bit limited these days. But that is a good solution I think. For me less fields within the UI look better: If local file then use local file if magnet then use magnet if .torrent in link then download...

Nibbels commented 7 years ago

there is some function: /httpdocs/apps/encryption/lib/Recovery.php https://github.com/nextcloud/server/blob/master/apps/encryption/lib/Recovery.php#L304 or this for folders? https://github.com/nextcloud/server/blob/master/apps/encryption/lib/Recovery.php#L282

with respect to getting the privatekey of the encryptedkey with the users password; https://github.com/nextcloud/server/blob/master/apps/encryption/lib/Recovery.php#L266

Hmmmmmm I dont know how policy on such might be.

e-alfred commented 7 years ago

I think there could be an additional Bittorrent download screen allowing people to enter both Magnet links and links to *.torrent files. Depending on how the link starts (magnet: or http/https:), Aria2 would then be started in the right mode.

The issue about magnet links is located here:

https://github.com/e-alfred/ocdownloader/issues/13

depado commented 7 years ago

That would be awesome 😃

ghost commented 4 years ago

Any Progress on this? I'm facing the same issue with server side encryption enabled.

2020-01-13 15:08:25.721496 [INFO] [HttpListenCommand.cc:78] RPC: Accepted the connection from 127.0.0.1:47480.
2020-01-13 15:08:25.721594 [INFO] [HttpServer.cc:187] HTTP Server received request
POST /jsonrpc HTTP/1.1
Host: 127.0.0.1:6800
Accept: */*
Content-Length: 63209
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

2020-01-13 15:08:26.722989 [INFO] [SaveSessionCommand.cc:74] No change since last serialization or startup. No serialization is necessary this time.
2020-01-13 15:08:26.723390 [INFO] [rpc_helper.cc:103] Executing RPC method aria2.addTorrent
2020-01-13 15:08:26.725601 [INFO] [RpcMethodImpl.cc:302] Uploaded torrent data was saved as /home/nextcloud/xxxxxx/files/Downloads/xxx.mkv/1x5cxxxfxx3x00xbxxxxxxxxxxe712bf.torrent
2020-01-13 15:08:26.725942 [DEBUG] [RpcMethod.cc:101] 捕捉到异常
Exception: [download_helper.cc:322] errorCode=25 Bencode decoding failed
2020-01-13 15:08:26.726043 [DEBUG] [HttpServer.cc:296] HTTP Server sends response:
HTTP/1.1 400 Bad Request
Date: Mon, 13 Jan 2020 07:08:26 GMT
Content-Length: 92
Expires: Mon, 13 Jan 2020 07:08:26 GMT
Cache-Control: no-cache
Content-Type: application/json-rpc
Access-Control-Allow-Origin: *
Connection: close

2020-01-13 15:08:26.726161 [INFO] [AbstractHttpServerResponseCommand.cc:118] CUID#12 - HttpServer: all response transmitted.
anguschang007 commented 1 year ago

Any possible solution for this issue? I am facing the same issue, there will come out an error message "Returned GID is null ! Is Aria2c running as a daemon ?" when I am trying to use the encrypted torrent file to start the download task. However, it is fine if the torrent is not encrypted. Also, I tried to use the "New Magnet/HTTP download" to download the torrent file, and think that it will start to download the torrent's content automatically. But ocdownloader doesn't start the download's progress properly, the Download folder will appear the torrent's content with the correct filesize but ocdownloader will not have the task for torrent and I use the iotop to check the hard drive IO but no any read/write there. It means the torrent's content in the Download folder is fake content.