Skip to content

Commit 0bf1984

Browse files
committedSep 30, 2015
Fix some SRP issues
-> Remove memory allocation bugs -> Merge changes from upstream, enabling customizeable memory allocation
1 parent 2a7d01b commit 0bf1984

File tree

4 files changed

+153
-82
lines changed

4 files changed

+153
-82
lines changed
 

Diff for: ‎src/client.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1059,8 +1059,10 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism)
10591059
m_password.length(), NULL, NULL);
10601060
char *bytes_A = 0;
10611061
size_t len_A = 0;
1062-
srp_user_start_authentication((struct SRPUser *) m_auth_data,
1063-
NULL, NULL, 0, (unsigned char **) &bytes_A, &len_A);
1062+
SRP_Result res = srp_user_start_authentication(
1063+
(struct SRPUser *) m_auth_data, NULL, NULL, 0,
1064+
(unsigned char **) &bytes_A, &len_A);
1065+
FATAL_ERROR_IF(res != SRP_OK, "Creating local SRP user failed.");
10641066

10651067
NetworkPacket resp_pkt(TOSERVER_SRP_BYTES_A, 0);
10661068
resp_pkt << std::string(bytes_A, len_A) << based_on;

Diff for: ‎src/util/auth.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2424
#include "sha1.h"
2525
#include "srp.h"
2626
#include "string.h"
27+
#include "debug.h"
2728

2829
// Get an sha-1 hash of the player's name combined with
2930
// the password entered. That's what the server uses as
@@ -50,10 +51,11 @@ void getSRPVerifier(const std::string &name,
5051
char **bytes_v, size_t *len_v)
5152
{
5253
std::string n_name = lowercase(name);
53-
srp_create_salted_verification_key(SRP_SHA256, SRP_NG_2048,
54+
SRP_Result res = srp_create_salted_verification_key(SRP_SHA256, SRP_NG_2048,
5455
n_name.c_str(), (const unsigned char *)password.c_str(),
5556
password.size(), (unsigned char **)salt, salt_len,
5657
(unsigned char **)bytes_v, len_v, NULL, NULL);
58+
FATAL_ERROR_IF(res != SRP_OK, "Couldn't create salted SRP verifier");
5759
}
5860

5961
// Get a db-ready SRP verifier
@@ -67,6 +69,7 @@ inline static std::string getSRPVerifier(const std::string &name,
6769
size_t len_v;
6870
getSRPVerifier(name, password, salt, &salt_len,
6971
&bytes_v, &len_v);
72+
assert(*salt); // usually, srp_create_salted_verification_key promises us to return SRP_ERR when *salt == NULL
7073
std::string ret_val = encodeSRPVerifier(std::string(bytes_v, len_v),
7174
std::string(*salt, salt_len));
7275
free(bytes_v);

0 commit comments

Comments
 (0)