Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hello everybody! I have been studying cryptography, specifically the RSA algorithm . I wanted to practice, and what could be better practice than implementing RSA in a MCreator mod?
- Note: this is a work-in-progress. Currently, only the core system is almost ready. If you have any ideas, feedback or want to say anything related to the topic - post it in the replies. I would be very very happy to see it.
- This mod wouldn't have been possible without Goldorion & NerdyPuzzle's plugin, File Manager.
- So, how does it work? Or, actually, how it will work, because I am yet to start making the actual message exchanging system.
- Imagine you’re playing on a server with friends. Even if the server admins are trustworthy, who knows who could gain access to the server console? That’s where SimpleRSA comes in.
- To put it simply, RSA works like this:
- Client wants to talk to server
- Client asks server for the server’s pub key
- Server sends the pub key to the client
- Client encodes its message using the server’s pub key
- Client sends the encoded message to the server
- Server receives the encoded message
- Server uses its priv key to decode the message
- Only the server can decode it, because only the server has the priv key.
- So this is what I want to make here. First of all, we need to generate the keys - this is pretty simple. We only need to make a few mathematical operations for this (MCreator doesn't have built-in functions for checking if a number is prime or finding the GCD of two numbers, so I made those myself). These operations happen the first time the mod is loaded in the game. Now, we have to store the keys somewhere. And this is where the first challenge arises - we can't simply have the client's keys on the server, because what is the point encrypting something if everything you need to decrypt it is already in the hands of a bad actor?
- This is where File Manager comes in. We can store the keys in a JSON file on client side:
- {
- "n": [modulus],
- "e": [pub key exponent],
- "d": [sec key exponent]
- }
- As long as nobody has access to the client's computer, the data is safe.
- Now, we have to tell the server we are joining our pub key. But MCreator's "Player joins world" Global trigger is server-side, meaning that we cannot access the client files. So in order to share our pub key with the server, we need to have it stored in a global_session variable. After joining the server we tell our pub key to the server, keeping our secret key, well, a secret.
- There are a few problems with this mod - for example:
- We need a way to stop the game from creating keys if we are starting as a server (for obvious reasons)
- Writing this I realized that each client connected to the server will try to write their pub key to the joined player's pub key server variable (as global_session doesn't have a "Event/target entity" scope.
- I hope you have enjoyed reading this. I will upload the workspace zip regularly starting with the next update.
Advertisement
Add Comment
Please, Sign In to add comment