• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Tutorial] Generate RSA keys

Sun

Knowledge is power - France is bacon
Joined
Jan 26, 2015
Messages
333
Solutions
22
Reaction score
244
After recent changes to tfs 1.3 by @Lordfire the rsa private key is now loaded from PEM file & it might be a bit confusing for some to generate custom rsa

This tutorial requires openssl to be installed on your system.
Debian & Ubuntu have it pre-installed.

First generate your private key
Code:
openssl genrsa -out key.pem 1024
Export the RSA Public Key to a File
Code:
openssl rsa -in key.pem -outform PEM -pubout -out public.pem

Now to extract modulus from the public key
Code:
openssl asn1parse -in public.pem
That should print something like this:

0:d=0 hl=3 l= 159 cons: SEQUENCE
3:d=1 hl=2 l= 13 cons: SEQUENCE
5:d=2 hl=2 l= 9 prim: OBJECT :rsaEncryption
16:d=2 hl=2 l= 0 prim: NULL
18:d=1 hl=3 l= 141 prim: BIT STRING

See the line with BIT STRING? Use the first number in the next command
Code:
openssl asn1parse -in public.pem -strparse 18

Your result should be similar to this:

0:d=0 hl=3 l= 137 cons: SEQUENCE
3:d=1 hl=3 l= 129 prim: INTEGER :A67E67F1BB0330A9BFEAB7306DDE4DE4EED66714519E0A97B096DCAAE35014EE
400BA718DBBFBD1065CAEB6029CAF6A6D5FA8F53C9154FB04BAB993CC051453CF00B71E1DC11DA0962BBFC770D8B855D65C1D953AEBB3CCD1A6BC70C3CB5EAC2B97FC1FAA20C322A732D4CF160DAE16FD028E13D54B52EC815BBF57CDD37184F
135:d=1 hl=2 l= 3 prim: INTEGER :010001

copy the hex from the first INTEGER (the string that starts with A6)

if you're using debian or ubuntu you can run this command
Code:
python -c 'print(int("pasteHERE", 16))'
otherwise there are different alternatives.

If the link above doesn't work just google hex to decimal converter and you should find something.

The long ass number you get from the conversion is your modulus that you use to replace the one in your client.

don't forget to change the default key.pem with your newly generated key.pem
 
Hello. Thanks for the topic.

I heard that on my server it stores on a line in otserv.cpp, not in key.pem. In that case, how can I proceed? Over time, I wanted to know more about RSA, grateful to have found his topic.
 
Amazing tutorial @Sun
rsakey.png

The RSA key that this is generating is shorter than the original one. What can I do to fill the space?

Example OLD RSA
Code:
109120132967399429278860960508995541528237502902798129123468757937266291492576446330739696001110603907230888610072655818825358503429057592827629436413108566029093628212635953836686562675849720620786279431090218017681061521755056710823876476444260558147179707119674283982419152118103759076030616683978566631413

Example NEW RSA
Code:
D0D40BE9987D6093626F93658C495B66FF031ACA9CE979D6C10845C92B58224E693252C5753209AB1A4BE3282297E0E01679C98317A73C030E25AB2DD35B418172C83C80F94E8EDF36F6DB26CE7AED1C3DC9C81C3793C56CD40A7791BED6578A032FE04C913390B1E1AA2E773C95261799C29BBF7FEE4AB25BD037F04C34846B

Tried to fill with ceros, but didnt work
ceros fill.png

The game client return with Disconnected from server. (2000002) but there's no packet error on console, why doesn't work?
 
Last edited:
Amazing tutorial @Sun
View attachment 60259

The RSA key that this is generating is shorter than the original one. What can I do to fill the space?

Example OLD RSA
Code:
109120132967399429278860960508995541528237502902798129123468757937266291492576446330739696001110603907230888610072655818825358503429057592827629436413108566029093628212635953836686562675849720620786279431090218017681061521755056710823876476444260558147179707119674283982419152118103759076030616683978566631413

Example NEW RSA
Code:
D0D40BE9987D6093626F93658C495B66FF031ACA9CE979D6C10845C92B58224E693252C5753209AB1A4BE3282297E0E01679C98317A73C030E25AB2DD35B418172C83C80F94E8EDF36F6DB26CE7AED1C3DC9C81C3793C56CD40A7791BED6578A032FE04C913390B1E1AA2E773C95261799C29BBF7FEE4AB25BD037F04C34846B

Tried to fill with ceros, but didnt work
View attachment 60261

The game client return with Disconnected from server. (2000002) but there's no packet error on console, why doesn't work?

You skipped the last step of the guide

if you're using debian or ubuntu you can run this command
Code:
python -c 'print(int("pasteHERE", 16))'
otherwise there are different alternatives.[/B]
If the link above doesn't work just google hex to decimal converter and you should find something.

The long ass number you get from the conversion is your modulus that you use to replace the one in your client.
 
Hi, I have generated everything nice RSA according to the guide, but when I want to log into the protocol version 8.6 (otc v1.0 from meeha) I get the following message:
"Invalid authentication token" any idea how to get rid of this error?
 
Hi, I have generated everything nice RSA according to the guide, but when I want to log into the protocol version 8.6 (otc v1.0 from meeha) I get the following message:
"Invalid authentication token" any idea how to get rid of this error?
Auth token? Do you have any 'secret' (column name) set in table 'account' for your account?

I prepared site that generate random RSA keys. Just not tested it yet. You can try it :)
 
Back
Top