alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
975 stars 422 forks source link

Feature Request: Add built-in hash_file and hash_string functions like AMX #781

Open DarkDeviL opened 6 years ago

DarkDeviL commented 6 years ago

As the title says, I would find it nice if the two functions hash_file and hash_string that AMX already has would be added to SourceMod as well:

-> https://www.amxmodx.org/api/amxmodx/hash_file -> https://www.amxmodx.org/api/amxmodx/hash_string

-> https://github.com/alliedmodders/amxmodx/blob/56324208278521fde6ac78fb9bef65500486f295/plugins/include/amxconst.inc#L432-L452

There are obviously stocks for the weaker MD5 and SHA1 out there,, however for the rest the only option seems currently to be the cURL extension, which according to the community members seems quite buggy and not maintained at all.

Based on the "MD5 Stocks" thread from 2008, it also sounded a little like @dvander was thinking about something in this direction, though I could have misunderstood it. After the comment about RC4:

someday we need to wrap libcrypto

The following post also requests this functions, however, just for the weak MD5. Again, I believe the community would benefit a lot from adding hash_file and hash_string with multiple hashing mechanisms into SourceMod.

Edit 2019-05-10: Modified GitHub link from master branch to specific commit URL, so line numbers doesn't mess up.

asherkin commented 6 years ago

Again, I believe the community would benefit a lot from adding hash_file and hash_string with multiple hashing mechanisms into SourceMod.

Please add specific use cases for what you need this functionality for.

ramonberrutti commented 6 years ago

@asherkin I build my own module, just to use Json Web Tokens (JWT)

DarkDeviL commented 6 years ago

One use case could be using hash_string to hash argument lists sent to remote API's (e.g via SteamWorks, Webternet, if it's being added some day, or any other extensions) to verify provide some sort of integrity check of whether the data has been altered between the server and the end point.

Some plugins delivering custom game data files are having issues from time to time, author could here add checks via hash_file, to see if the game data files are matching files known to bring issues with the plugin, and if so, unload and/or use SetFailState to inform disable the plugin and inform the users that they need to update their (old) game data as well.

If you in a plugin need to perform things like file uploads, you could also use the hash_file to produce a hash and verify with the backend whether or not the system has already received that file before wasting a lot of bandwidth to upload the same file( again).

These are just a few though, but I believe there are many other use cases out there.

fakuivan commented 4 years ago

Again, I believe the community would benefit a lot from adding hash_file and hash_string with multiple hashing mechanisms into SourceMod.

Please add specific use cases for what you need this functionality for.

For tf2idb we'd like to insert a hash of items_game.txt on the items database so that we can detect if the database needs to be updated. The plugin for now will need to call the server binary to compute this hash since this functionality is not included. More gamedata yay!

https://github.com/FlaminSarge/tf2idb/issues/27