JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 22.03.2024, 19:05
Wh0Care5 Wh0Care5 is offline
Baby Loader
 
Join Date: Feb 2024
Posts: 7
Default C# API help request

Hi everyone.
I am working on a own project which involves the repository **External links are only visible to Support Staff**Cr1TiKa7/My.Jdownloader.Api

This project is a lot of outdated so I am working currently on it.

My problem actually is about the `RijndaelManaged` which is outdated.

It does not work by replacing the RijndealManaged part inside the Handler.cs.

I tried from:
Code:
			var rj = new RijndaelManaged
			{
				Key = key,
				IV = iv,
				Mode = CipherMode.CBC,
				BlockSize = 128
			};
to different variants like:
Code:
// also obsolette but still not working
            var rj = new AesManaged();
            rj.Key = key;
            rj.IV = iv;
            rj.Mode = CipherMode.CBC;
            rj.BlockSize = 128;
or
Code:
            var rj = Aes.Create();
            rj.Key = key;
            rj.IV = iv;
            rj.Mode = CipherMode.CBC;
            rj.BlockSize = 128;
Do someone has an advice?

Last edited by Wh0Care5; 22.03.2024 at 19:23.
Reply With Quote
  #2  
Old 23.03.2024, 22:08
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,544
Default

@Wh0Care5: most likely you have to specify the padding scheme.
see stackoverflow.com/questions/76347316/net-7-way-of-file-encryption-rijndaelmanaged-is-obsolete
In Java it's
Quote:
AES/CBC/PKCS5Padding
You should create simple test and use RijndealManaged and AES and encrypt same input and compare their output and find the cause.
Please just let us know if you need further help or still can't get it work
__________________
JD-Dev & Server-Admin
Reply With Quote
  #3  
Old 26.03.2024, 08:42
Wh0Care5 Wh0Care5 is offline
Baby Loader
 
Join Date: Feb 2024
Posts: 7
Default

Hi there,
yes, before I wrote here, I also tried a lot of different stuff. Also the padding option without success.
But yes, I will have to do some tests comparing both inputs and outputs. Atm I already invested enough time in this which has a low priority atm for me. I will do this later on.
Reply With Quote
  #4  
Old 26.03.2024, 09:31
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,544
Default

@Wh0Care5: Can you tell/explain to me an easy way/setup how I can do testing/coding in this language? With working development environment I can help better/faster.

Comparing RijndaelManaged with AES should lead to fastest result/solution as you know what output is expected and can do tests with different sorts of parameters. Maybe the issue comes from total different line of code and you just oversee it
__________________
JD-Dev & Server-Admin
Reply With Quote
  #5  
Old 27.03.2024, 18:40
Wh0Care5 Wh0Care5 is offline
Baby Loader
 
Join Date: Feb 2024
Posts: 7
Default

Oh, that would be rly nice from you, even if I, to be honest, would not want to give you that job, because I also did only invest just a few hours in understanding the jdownloader api, how it works and this encrypt/decrypt part and its always hard at the beginning to understand stranger projects. I just had a lot of other work to do why, this for me is just a lower prio. Even if I think, that would be still great to have a working jdownloader open source api for everyone.

If you want to give it a try, you can find both, the encryption and decryption on github (link already posted in the first thread) under `src/My.JDownloader.Api/ApiHandler/JDownloaderApiHandler.cs`
Or search for `Cr1TiKa7/My.Jdownloader.Api`

Atm I just do not have the capacity to change this as long as it still works even this way

Edit: Because this is c#, I think, this should not be that hard to test this as a java developer (i always hated java ).
1. You would need vs studio which can be used for free
2. download the dotnet/8.0 sdk,
3. Download the github repo from link in the first thread
4. Opening the *.sln file with vs studio
5. Click on My.JDownloader.Api & My.JDownloader.Api.Sample and change the `TargetFrameworks` to `<TargetFrameworks>net8.0</TargetFrameworks>`
6. Run an JDownloader on your pc which is connected to the My.JDownloader
7. Under My.JDownloader.Api.Sample --> Program.cs you have to enter your credentials like you do on the web of my.jdownloader
8. Make a breakpoint at the row 19
9. Right Click the My.JDownloader.Api.Sample and Set as Startup project
10. Press F6 once for build then you can press f5
11. Breakpoint should trigger and you should be able to see the tmp variable set if you have any QueryPackages. You can also add your own stuff to get but this should definitively work as expected if you have anything in the querypackages.


This should be enough to run the project. Note, vscode also works but to be honest, even if I use vscode for python, reactjs and other languages, I just like vs studio way more for c# so cant tell on what to do for vscode. sorry
Edit2: There is also a pull request for "Upgrade to net8" so you can also use this

Last edited by Wh0Care5; 27.03.2024 at 19:49.
Reply With Quote
  #6  
Old 27.03.2024, 19:45
Wh0Care5 Wh0Care5 is offline
Baby Loader
 
Join Date: Feb 2024
Posts: 7
Default

Quote:
Originally Posted by Jiaz View Post
@Wh0Care5: Can you tell/explain to me an easy way/setup how I can do testing/coding in this language? With working development environment I can help better/faster.

Comparing RijndaelManaged with AES should lead to fastest result/solution as you know what output is expected and can do tests with different sorts of parameters. Maybe the issue comes from total different line of code and you just oversee it
I just updated my previous message. Just as a hint if you did just saw the old message. Let me know if you need any help or have any questions.
Reply With Quote
  #7  
Old 27.03.2024, 21:26
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,544
Default

@Wh0Care5: already installing vs studio and trying my best to setup a running environment
Already found a bug in Reconnect as it throws away email/password (this is correct) but device connect wants those again
__________________
JD-Dev & Server-Admin

Last edited by Jiaz; 27.03.2024 at 21:54.
Reply With Quote
  #8  
Old 27.03.2024, 22:09
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,544
Default

Solution was quiet easy/simple and you can easily find it by looking at the thrown exception
Quote:
var rj = Aes.Create();
rj.Mode = CipherMode.CBC;
rj.BlockSize = 128;
rj.KeySize = 128;
rj.Key = key;
rj.IV = iv;
It's important to first set block-/keysize and then key/iv. I guess setting those values internally validates/clears other fields
With setting key/iv first, the exception states that iv or key was missing.

Also note my Reconnect bug finding. But there is no need to use Reconnect as we don't allow session reconnect for unknown apps/clients.
Many/near all projects simply create new sessions without disconnecting the old session, which caused "millions of never to be used again" sessions waiting for their reconnect timeout/death and just wasting cpu/memory.

In case you need further help/got questions, now I have a running dev environment, thanks to your help
__________________
JD-Dev & Server-Admin

Last edited by Jiaz; 27.03.2024 at 22:21.
Reply With Quote
  #9  
Old 28.03.2024, 08:34
Wh0Care5 Wh0Care5 is offline
Baby Loader
 
Join Date: Feb 2024
Posts: 7
Default

Omg... that was the missing part... The order. KeySize seams also not to be needed but still good to set it.

I would never have thought of that, because I have never seen anything like it, especially in a root library. Im glad, you did took a look into it

I'm wondering where you got the exception. Because if I just leave the wrong sequence, I don't get one, only that there is supposedly no device connected.

And about your topic of the sessions. Your right, that is why by default for connections and such thing, using should be used. This also disposes the connections if not used anymore and such.

Also for the crypto part. It should be:

using (var rj = Aes.Create())
{
rj.Mode = CipherMode.CBC;
rj.BlockSize = 128;
rj.KeySize = 128;
rj.Key = key;
rj.IV = iv;
}
Reply With Quote
  #10  
Old 28.03.2024, 08:39
Wh0Care5 Wh0Care5 is offline
Baby Loader
 
Join Date: Feb 2024
Posts: 7
Default

Edit:
about your Reconnect concern. I dont think this will be the case because inside the '_apiHandler.CallServer' uses the own 'string response = PostMethod(url, param, key);' which always creates a new HttpClient and disposes it after the use:
using (var httpClient = new HttpClient())
So this connection always will be closed after the execution part of the
string result = response.Content.ReadAsStringAsync().Result;

And even so, the Reconnect() has 0 references which means, it is never used.

Last edited by Wh0Care5; 28.03.2024 at 08:42.
Reply With Quote
  #11  
Old 28.03.2024, 09:26
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,544
Default

@Wh0Care5:
Quote:
Originally Posted by Wh0Care5 View Post
I'm wondering where you got the exception. Because if I just leave the wrong sequence, I don't get one, only that there is supposedly no device connected.
There was a
Quote:
}catch(exception)
that the debugger went into but did not see it, so I've changed to
Quote:
}catch(exception e)
and then I saw error message like, IV is missing, key is missing, so I though that maybe setting those values will cause internal initialisation of the AES and changed init order and then it worked just fine

Quote:
Originally Posted by Wh0Care5 View Post
Also for the crypto part. It should be:
using (var rj = Aes.Create())
{
rj.Mode = CipherMode.CBC;
rj.BlockSize = 128;
rj.KeySize = 128;
rj.Key = key;
rj.IV = iv;
}
Yes, nice and clean but I just wanted to debug and find the culprit
__________________
JD-Dev & Server-Admin

Last edited by Jiaz; 28.03.2024 at 09:40.
Reply With Quote
  #12  
Old 28.03.2024, 09:33
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,544
Default

About reconnect method. The initial LoginObject object also holds email+password and the generated secrets and tokens. On reconnect, this one will be replaced with new one (holding tokens and secrets) but without email+password. then the device client tried to login again and failed because wanted to do a fresh/complete login and failed because email+password are null -> nullpointer.
After initial login, the Loginobject should no longer have any email+password as they are only meant to be available during login and then thrown away. but as long as you don't make use of reconnect, as explained no need to, it's just fine
__________________
JD-Dev & Server-Admin
Reply With Quote
  #13  
Old 28.03.2024, 09:45
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,544
Default

In case you need further help/got questions or need new api endpoints, just let me know
__________________
JD-Dev & Server-Admin
Reply With Quote
  #14  
Old 28.03.2024, 14:43
Wh0Care5 Wh0Care5 is offline
Baby Loader
 
Join Date: Feb 2024
Posts: 7
Default

Quote:
Originally Posted by Jiaz View Post
About reconnect method. The initial LoginObject object also holds email+password and the generated secrets and tokens. On reconnect, this one will be replaced with new one (holding tokens and secrets) but without email+password. then the device client tried to login again and failed because wanted to do a fresh/complete login and failed because email+password are null -> nullpointer.
After initial login, the Loginobject should no longer have any email+password as they are only meant to be available during login and then thrown away. but as long as you don't make use of reconnect, as explained no need to, it's just fine
Ah, got now your point. There are anyway multiple bugs which I found about the namespaces and such but still better this way than coding everything from scratch. And as long as it does the job, its great.

Quote:
Originally Posted by Jiaz View Post
In case you need further help/got questions or need new api endpoints, just let me know
I will count on you
Atm I have a lot planed for my project. Atm I am working on the OAuth with OpenId authentication, the websocket between the backend and also the reactts site for direct media streaming without passing the internet, tracking of the downloaded files with jdownloader, all the links already downloaded and excluding them from adding, comparisation of the files with czkawka. If content duplication, also tracking the parent url eg: 1 file with multiple links to not download them again and many many more.

Also following best practices of CQRS patterns, splitting between, Domain, Infrastructure, Web, and Application.
Best practices with react hooks and others for reactts

Meanwhile also creating a accountings software for a company...

Time is the missing part

Last edited by Wh0Care5; 28.03.2024 at 14:47.
Reply With Quote
  #15  
Old 28.03.2024, 20:29
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,544
Default

Quote:
Originally Posted by Wh0Care5 View Post
Atm I have a lot planed for my project.
Oh yes, you have! Better implement the clone method first and get yourself some little helpers
__________________
JD-Dev & Server-Admin
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 16:21.
Provided By AppWork GmbH | Privacy | Imprint
Parts of the Design are used from Kirsch designed by Andrew & Austin
Powered by vBulletin® Version 3.8.10 Beta 1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.