Access a username/password protected url through C++
I'm an individual developer (not a professional developer. I'm a graphic designer who likes to code ;) ) and I mainly code plugins for Cinema 4D (I don't know if anyone knows this application).
I used to code in COFFEE (a javascript like language, only for Cinema 4D) and python.
But, recently, I started coding in C++.
I start my development on a Mac, using Xcode. But then, to generate Windows versions of my plugins, I take my source code to Visual Studio, perform the necessary adjustments, and create Win32 and Win64 code.
Lately, I was trying to devise a scheme to protect my plugins from being pirated. Yes, I know it is virtually impossible, but if I could make it harder for hackers to crack my plugins, it would be fine.
I made it work fine in python and in C++, but only in Xcode.
In Windows it is a headache. I only need to be able to access a username/password protected folder in my server and check if there is a file there. I don't even need to read the content of the file (but it would be nice to be able to do that too).
I started out using the cURL library but it is so complicated to make it work. I need 32 and 64 bit versions. Then I also have to include three .dll files in the folder of the application (that means that I would have to ask to the people who buy my plugins to copy three additional files to the main application folder... not a good thing :( )
So, would anyone point me in the right direction to find a way to access a username/password protected folder on the net? (the username/password is generated in my code so, of course, I know what are the username/password to provide).
Also, I would need a way for the code to be completely self-contained, meaning that the users would not have to manually add any other files (libraries), besides the folder containing my plugin.
And, if the solution was free, it would be great. I'm a freelancer and I don't even sell my plugins for a lot of money.
Thank you all, in advance.
Re: Access a username/password protected url through C++
What you need to do is supply an interface that gets accessed over the interface.
Users would pass username/password information to the interface and internally it would perform the authentication (using your 'folder' approach or some other mechanism).
Re: Access a username/password protected url through C++
Quote:
Originally Posted by
Arjay
What you need to do is supply an interface that gets accessed over the interface.
Users would pass username/password information to the interface and internally it would perform the authentication (using your 'folder' approach or some other mechanism).
Thank you for your reply, Arjay, but that is not what I need.
I have a username/password protected folder inside my server (where my homepage resides).
When someone buys me a plugin, I create a new username/password entry manually for that folder and I place a specific file inside it.
Then, I just send the plugin to the buyer.
So, I need my plugin to access that folder at runtime. If it can't access it, no username/password entry was created, so the plugin doesn't adds itself to Cinema4D. If it can access it, it will check if that specific file exists. If it doesn't, the plugin doesn't adds itself to Cinema4D.
That verification is done the first time the plugin run, every week from that time and, sometimes, randomly.
So, I don't want any user intervention. The plugin must do it all on its own. I already made it work perfectly on MacOS, using C++ in Xcode (it is so much simpler).
But I can't make it work with the system libraries in Windows.
Once again, I only need to be able to check if a file with a specific name exists in a username/password protected online folder.
Re: Access a username/password protected url through C++
Quote:
Originally Posted by
rui_mac
Thank you for your reply, Arjay, but that is not what I need.
Perhaps, but on Windows due to security, that's what you may need to do.
Re: Access a username/password protected url through C++
Well, I can do it with cURL, like this:
...
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, the_url);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_easy_setopt(curl, CURLOPT_USERPWD , passcode);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
...
So, it is possible.
But this method forces me to include three .dll files in the main application folder and I don't want to force the users to do that.
I also know that other Cinema 4D plugin developers can do it on Windows (and on Mac) but they are using a commercial library from Chilkat Software (http://www.chilkatsoft.com/).
I don't sell enough plugins to justify buying an expensive commercial library :-(
I could buy one if it was cheap but I also know that there are free ones. I just need to know which one would allow me to do this and don't require adding .dll files, producing self contained code.
So, I know it is possible. But I'm a Mac guy that only uses Windows to compile Windows versions of its plugins. So, I really would appreciate some help or advice from Windows professional developers :-)
Re: Access a username/password protected url through C++
What protocols are used when accessing your server? Is it plain HTTP? Through TCPIP or TLS (SSL)?
What libraries did you use to achieve this access on MacOS?
gg
Re: Access a username/password protected url through C++
Didn't see your last post...
Well, you wouldn't want to link statically to GPL source (without purchasing a license to do so). And some may even require a license to be used in a commercial application (like gSoap). What you may be able to do is package these DLL's into your module as resources. Then save them out to disk at startup. This will require that these DLL's be delay loaded or dynamically loaded.
http://forums.codeguru.com/showthrea...21#post1722821
gg
Re: Access a username/password protected url through C++
It is plain HTTP.
On MacOS I just compiled cURL through the Terminal and then, in Xcode I included:
#include <curl/curl.h>
In Windows I installed cURL but, even after compiling the code, to make it work, I still had to include libcurl.dll, libssh2.dll and MSVCR120.dll in the Cinema 4D folder.
On my Mac, the plugin just works without anything else needed.
Re: Access a username/password protected url through C++
Can't Visual Studio embed everything it needs in the generated code, even if that means creating a much larger file in the end?
Re: Access a username/password protected url through C++
>> ... and MSVCR120.dll in the Cinema 4D folder
That should be handled by the appropriate VS runtime redistributable. (eg. http://www.microsoft.com/en-us/downl....aspx?id=30679)
You could check that it's installed and tell the user you're not loading because it isn't. (http://blogs.msdn.com/b/astebner/arc.../10008146.aspx)
Or if you aren't using too much MS compiler tech. then you could get your stuff to compile using MinGW. It's runtime is based on msvcrt.dll (by default), which is an OS/system DLL.
>> Can't Visual Studio embed everything it needs in the generated code, even if that means creating a much larger file in the end?
That implies linking statically, which may have repercussions depending on the license (like having to pay, or having to make your source code open and available as well under the same license, etc...)
libCurl seems to have a fairly liberal license, so you may be able to link statically and use it for "free" - but don't take my work for it :)
https://stackoverflow.com/questions/...rl-without-dll
If you do link everything statically, then that can also include the runtime - which would take care of any msvcr*.dll dependencies.
gg
Re: Access a username/password protected url through C++
Well, I don't know how to do that ;)
I must go to bed now (it is late here and tomorrow I have to get up early).
I will investigate and, if I get into a corner (I will probably will), I will get back here.
Thank you all, so far :)
Re: Access a username/password protected url through C++
Just FYI.
It is ridicilously easy to redirect internet traffic to the local PC. This doesn't even need code, you just edit the hosts file.
All it then takes is installing off the shelf apps like a simple webserver to emulate YOUR webserver.
I've seen (and done) hacks like this for educational purposes to show how easy it is to break/reverse engineer something.
With hacking, it's equally easy to disable your protection code entirely and just 'jump over it'.
So to summirize (again, I did this before on CG):
- if all you want to do is stop Joe Average User from violating your software license, you can do with with a few lines of simple code.
- You have no chance to stop a hacker unless you are a more capable hacker than that guy yourself.
- if you never seen a hacker at work, you can just give up right now. They have better tools than you. And unless you know what y ou're doing, they'll spend less time breaking your software than it took you to try and protect it.
- Hackers do this for 'fun' and have no issues with spending days/weeks on a hack, if you make software for a living, you have no way to counter a dedicated hacker with an equal amount of effort and still make it worth it.
- the more difficult you make it, the more prestige the hacker gets if they do break your code. That alone is the big incentive for them to keep at it.
- you can not stop a hacker... ever... period. you can make it hard enough to stop some or most. But that requires a big effort on your part.
That doesn't mean there's no way to make your program hack proof. You can solve it by offloading important work/calculations to an online server. THey can't hack that out or the important work/calculations will not be happening.
It does cause problems with your server of course, it needs to be powerfull enough to handle the workload generated by all your users.
Note that even that doesn't Always stop them. Offloaded work has been figured out as well, look at the world of warcraft (wow) public servers for example. THe entire protocol got reverse engineered and server side software developed to make this work. THe servers aren't doing things exactly the same as the real wow servers, but it's close enough for at least some people to play on them.
Re: Access a username/password protected url through C++
Thank you for your information, OReubens.
I understand and agree with all you say.
Even so, I would like to add this layer of protection (that I know that is not perfect... far from it).
I can even try to intermingle the verification code with important parts of the calculation code so that it is harder to crack (not impossible, I know).
But, even so, I still need to know to access my online folder in a way that the code is completely self-contained. I searched a bit more and still nothing :-(
Re: Access a username/password protected url through C++
accessing folder contents would require an FTP server on your server and a (simple) FTP client in your code.
HTTP is a notch easier, but you can only access/read resources from the webserver, you can't typically get folder contents.
So if you can afford to, just request a resource/file from your http server. if it's there, it'll return the contents of the file, if not, you'll get a 404 (not found) HTTP status.
WinInet is simple to access HTTP, so is cURL, either will work.
Re: Access a username/password protected url through C++
I don't need to download anything. I just need to check if a file exists there.
I already used cURL but the generated code is not self contained. Meaning that my code also requires that three additional .dll files be placed in the folder of the mail app (not the plugins folder where my plugin resides).
Will WinInet be able to create self-contained code out of Visual Studio?
Oh, by the way, I'm using VS 2010 (I need to use that version to develop the plugins).