Draft: Replace old C code with current huacnlee/rucaptcha Rust code #4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "gitlab-mr-iid-3"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Ok before you say anything, I don't expect this to be merged but I wanna just put the alternative on record share some ideas I think are good.
This is based on the same project as the C code that was used in this Elixir library, but it is now Rust, however, the captchas the new code generates seems much stronger.
I just took the project, removed all the Ruby code I didn't need and made a main function to output the same thing as the old C code, in this repository.
I think the new captchas look much stronger and may be harder to crack than the current easy ones right out of the box.
You may say requiring Rust seems like a showstopper because not every one uses captcha or has open registrations, and I would agree with that, however I propose an alternative:
I think the tricky part about this would be check for GNU LibC or MUSL. Maybe just try compile some code like this and check the return code from make or the compile, if it's not 0, it's MUSL?
I'd also like to show another person had the same idea as me, and used a Go captcha library instead.

This is what his captchas look like:
The main takeaway here is that modifying the existing C code is way harder than it would be in either of those implementations, and they may also get improved/updated upstream and we could just use that, but custom code can also be added downstream much more easily.
Anyway, this is just an idea not a serious merge request, let me know if any of this makes sense.
I don't think Rust makes much sense as AFAIK none of the Pleroma devs have any experience programming in Rust (while C is pretty extensive) and personally as long as Rust doesn't fixes it's bootstrapping story and distro packaging support, I'd end up maintaining a non-Rust version anyway…
Check https://docs.pleroma.social/backend/installation/otp_en/#detecting-flavour for a way to detect it through shell.
And
#include <gnu/libc-version.h>wouldn't compile on anything non-glibc.Go code could be a bit interesting but I'm not sure how maintainable the one you pointed at is, it seems to depend on a pretty large dependency.
Yeah, like you said it doesn't make sense to add Rust code if nobody can work with it.

I looked for other C or C++ captcha libraries and saw CImg had one captcha example in the repository and it actually seems to be much stronger than either of those examples.
I copied just the captcha code here to make it easier to work with. As you can see CImg.h can be just copied on its own, so it doesn't create a depedency.
It does depend on libpng currently, but both ffmpeg and ImageMagick install that, though they are optional installs in the current Pleroma install guide. The code can be easily changed to save as .bmp if you really don't want that dependency, just by replacing
save_pngtosave_bmp.I think this one is actually worth exploring, since it's C++.
Edit: I forgot to mention, I replaced the hardcoded captchas from the example with code I found here, it does use C++17 templates but compiles on as low as GCC 7.1 and Clang 5.0.0.
See: https://godbolt.org/z/Yz6hErrbP
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.