-
Notifications
You must be signed in to change notification settings - Fork 36.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
contrib: Ask for captcha in signet getcoins.py #23162
Conversation
355ece0
to
bd15038
Compare
As the faucet will always ask for a captcha now, the current script is no longer usable. Change the script to print the captcha in dot-matrix to the terminal, using unicode Braille characters.
bd15038
to
a6d9675
Compare
This is incredible! Alternative would be to do the heavy lifting (unicode-ifying) server-side, but that might be too DoS-risky. Testing as soon as ImageMagick finishes installing. |
Tested ACK a6d9675 |
That's a good point! Even having to render the image as a bitmap on the server side might be more DoS-risky. FWIW, I first used Pillow on the Python side, but it doesn't currently support SVG. so I worked around it by using ImageMagick to convert to a trivial image format (PPM) and loading that manually. If the image format was changed to something else we could use Pillow, instead. But I'm not really sure it's a more convenient dependency than ImageMagick. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome solution for this problem.
Tested ACK a6d9675 on Ubuntu 20.04 with the command below:
./contrib/signet/getcoins.py -i /usr/bin/convert -c /path/src/bitcoin-cli -- -signet -datadir=/path/bitcoin -rpcwallet="w1"
Might be nice to use python tensorflow to pre-solve the captcha for the user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK a6d9675
Tested successfully on Ubuntu 20.04
This is quite a significant addition for the bitcoin-cli. Also, the addition of now to able choose the requested amount is cherry on the cake. I do have to mention, though; the captcha looks so beautiful on the command line!
Very neat, Concept ACK! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK a6d9675 on macOS 10.15.7. This PR:
- Fetches the captcha in
res
and uses imagemagick to convert it into pixel representation(stored as bytes object). - It’s then stored as RGB tuples in
self._grid
and usesprint_image()
to print the braille unicode characters.
To prevent spamming of faucet requests, faucet fund requests check captcha and with this script, the captcha gets printed in the terminal so that the script can work again. It’s a great solution!
Concept ACK I love this idea and what a nice compact implementation. Impressive in its simplicity! |
utACK. Theoretically, it is possible to do it in non-unicode terminals using normal ASCII. It doesn't look as pretty though. There's some very advanced algorithms for this, but a dumb You may also want to get ImageMagick to do the binarization. It has a bit more sophisticated facilities for that, if the captcha ever gets harder. |
Viewing the opening comment in Chromium makes it look very unreadable, but the screenshots others have posted look fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK a6d9675 ♟️
Tested with OpenBSD 6.9, worked like a charm after installing the ImageMagick
package. The converted captcha output looks good and is well-readable. Also tried out all of the three newly introduced parameters --imagemagick
, --amount
and --captcha
(though for the last I only tested the failure case due to a lack of alternative signet faucets).
Feel free to add another mode, if you can get that readable enough. Preferably without adding a dependency on libaa or such, or a lot of code, at least this is straightforward and looking at the comments here, unicode Braille support is common enough.
That's an interesting suggestion. It can also do dithering instead of a naive threshold, which might or might not help. I didn't initially want to rely on ImageMagick too much, in case the image format changes to something that Pillow can natively handle, but as it's not using that anymore, it doesn't seem bad to commit further to that direction. Edit: I tried adding |
Concept ACK I had suggested captcha in #22565 (comment) Although now that I was thinking about possible ways to test this, there is one issue which can be managed by adding a warning that "captcha" is based on third party URL. If the website gets hacked, attacker can show something else instead of regular captcha. |
As far as I know, the captcha is generated on the same host as the faucet itself. The faucet could already return any kind of information in an error that is printed directly to the console (including control characters, any unicode and escape sequences). The captcha isn't worse in that sense. If you want to harden it you could do various things:
You're welcome to work on this but I see it as outside the scope of this pull request. |
As the faucet will always ask for a captcha now, the current script is no longer usable.
Change the
getcoins.py
script to print the captcha in dot-matrix to the terminal, using unicode Braille characters.The only added dependency is that
convert
from ImageMagick (or compatible fork) is installed.Captchas are disabled by default for custom faucets, but it is possible to specify a custom captcha URL on the command line.
Also adds a way to change the amount requested with e.g.
-n 0.1
.Edit: credit where credit is due, yope gave me the idea of using Braille characters as a widely available way to do graphics in the terminal. Another possibility is
2x2
block characters but it is a lot less compact. Yet another one is VT340 Sixel graphics but it's not supported in many terminal emulators.