Jump to content

LibServerkey Compatible with OpenSSL v1.0+


Recommended Posts

  • Former Staff

Hello, this is a small upgrade in order to build libserverkey for OpenSSL 1.0 or greater, it builds with OpenSSL v1.4d (Win32 build) fine.

 

All this changes has to be made in RSACrypto.cpp

Function RSACrypto::PublicKey::PublicKey

Replace:

		BN_hex2bn(&rsa_->n, n);
		BN_hex2bn(&rsa_->e, e);

to:

#if OPENSSL_VERSION_NUMBER < 0x10100000L
		BN_hex2bn(&rsa_->n, n);
		BN_hex2bn(&rsa_->e, e);
#else
		BIGNUM* rsa_n, * rsa_e, * rsa_d;

		RSA_get0_key(rsa_, (const BIGNUM**)&rsa_n, (const BIGNUM**)&rsa_e, (const BIGNUM**)&rsa_d);

		BN_hex2bn(&rsa_n, n);
		BN_hex2bn(&rsa_e, e);

		RSA_set0_key(rsa_, rsa_n, rsa_e, rsa_d);
#endif

 

Function RSACrypto::PublicKey::Alloc

Replace:

		rsa->n = BN_new();
		rsa->e = BN_new();

to:

#if OPENSSL_VERSION_NUMBER < 0x10100000L
		rsa->n = BN_new();
		rsa->e = BN_new();
#else
		BIGNUM* n = BN_new(), * e = BN_new();
		RSA_set0_key(rsa, n, e, NULL);
#endif

 

Function RSACrypto::PublicKey::Copy

Replace:

		BN_copy(to->n, from->n);
		BN_copy(to->e, from->e);

to:

#if OPENSSL_VERSION_NUMBER < 0x10100000L
		BN_copy(to->n, from->n);
		BN_copy(to->e, from->e);
#else
		BIGNUM* to_n, * to_e,* to_d;
		const BIGNUM* from_n = RSA_get0_n(from), * from_e = RSA_get0_e(from);

		RSA_get0_key(to, (const BIGNUM**)&to_n, (const BIGNUM**)&to_e, (const BIGNUM**)&to_d);

		BN_copy(to_n, from_n);
		BN_copy(to_e, from_e);

		RSA_set0_key(to, to_n, to_e, to_d);
#endif

 

Function RSACrypto::PrivateKey::Alloc

Replace:

		rsa->d = BN_new();
		rsa->p = BN_new();
		rsa->q = BN_new();

to:

#if OPENSSL_VERSION_NUMBER < 0x10100000L
		rsa->d = BN_new();
		rsa->p = BN_new();
		rsa->q = BN_new();
#else
		BIGNUM* d = BN_new(), * p = BN_new(), * q = BN_new();
		RSA_set0_key(rsa, NULL, NULL, d);
		RSA_set0_factors(rsa, p, q);
#endif

 

Function RSACrypto::PrintKey (k, n, e)

Replace:

		char* tmp = BN_bn2hex(k->rsa_->e);

to:

#if OPENSSL_VERSION_NUMBER < 0x10100000L
		char* tmp = BN_bn2hex(k->rsa_->e);
#else
		const BIGNUM* rsa_e = RSA_get0_e(k->rsa_);
		char* tmp = BN_bn2hex(rsa_e);
#endif

 

Replace:

		tmp = BN_bn2hex(k->rsa_->n);

to:

#if OPENSSL_VERSION_NUMBER < 0x10100000L
		tmp = BN_bn2hex(k->rsa_->n);
#else
		const BIGNUM* rsa_n = RSA_get0_n(k->rsa_);
		tmp = BN_bn2hex(rsa_n);
#endif

 

Function RSACrypto::PrintKey(k, n, e, d)

Replace:

		char* tmp = BN_bn2hex(k->rsa_->n);

to:

#if OPENSSL_VERSION_NUMBER < 0x10100000L
		char* tmp = BN_bn2hex(k->rsa_->n);
#else
		const BIGNUM* rsa_n = RSA_get0_n(k->rsa_);
		char* tmp = BN_bn2hex(rsa_n);
#endif

 

Replace:

		tmp = BN_bn2hex(k->rsa_->e);

to:

#if OPENSSL_VERSION_NUMBER < 0x10100000L
		tmp = BN_bn2hex(k->rsa_->e);
#else
		const BIGNUM* rsa_e = RSA_get0_e(k->rsa_);
		tmp = BN_bn2hex(rsa_e);
#endif

 

Replace:

		tmp = BN_bn2hex(k->rsa_->d);

to:

#if OPENSSL_VERSION_NUMBER < 0x10100000L
		tmp = BN_bn2hex(k->rsa_->d);
#else
		const BIGNUM* rsa_d = RSA_get0_d(k->rsa_);
		tmp = BN_bn2hex(rsa_d);
#endif

 

 

The changes, explained:

1) the ifdefs are there for compatibility with the old openssl version.

2) OpenSSL 1.0 do not expose the "rsa_" structure, so we need to use OpenSSL own api to get the required data from it.

 

A question that you might have at this point is what is the purpouse of libserverkey.

It looks like ymir had an issue about leaking game files back in this day, this might explain why this feature was added.

It bundles a RSA private and public key to your core, which verifies if the current machine should be able to use such core or not.

It is not an important feature as it isn't that hard to bypass with the required knownledge and it could be removed safetly from the game.

I'm thinking about covering this protection in the wiki, until then I hope I made some clarification about this library.

 

 

  • Metin2 Dev 1
  • Love 22

Everyday you wake up as a Metin2 developer is a bad day...

METIN1 src when

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.