aboutsummaryrefslogtreecommitdiff
path: root/build/android/Makefile
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2014-09-22 11:02:26 +0200
committerKahrl <kahrl@gmx.net>2014-09-22 11:02:26 +0200
commit5ca5630a116458910fdffa097417bb211b89ba4e (patch)
tree834ab19e89f966f8fa184db02021bebdbe1ce0d8 /build/android/Makefile
parent56195dc2e45b85b7177cfa97aade77e92cff8805 (diff)
Fix command line parsing
Broken by 6bc4cad0eddd7a7cf593ca1471599e2d75727379, e.g. minetest --worldname world would be parsed as minetest --worldname --worldname
Diffstat (limited to 'build/android/Makefile')
0 files changed, 0 insertions, 0 deletions
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
/*
Minetest
Copyright (C) 2015 est31 <MTest31@outlook.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <algorithm>
#include <string>
#include "auth.h"
#include "base64.h"
#include "sha1.h"
#include "srp.h"
#include "string.h"

// Get an sha-1 hash of the player's name combined with
// the password entered. That's what the server uses as
// their password. (Exception : if the password field is
// blank, we send a blank password - this is for backwards
// compatibility with password-less players).
std::string translatePassword(const std::string &name,
	const std::string &password)
{
	if (password.length() == 0)
		return "";

	std::string slt = name + password;
	SHA1 sha1;
	sha1.addBytes(slt.c_str(), slt.length());
	unsigned char *digest = sha1.getDigest();
	std::string pwd = base64_encode(digest, 20);
	free(digest);
	return pwd;
}

void getSRPVerifier(const std::string &name,
	const std::string &password, char **salt, size_t *salt_len,
	char **bytes_v, size_t *len_v)
{
	std::string n_name = lowercase(name);
	srp_create_salted_verification_key(SRP_SHA256, SRP_NG_2048,
		n_name.c_str(), (const unsigned char *)password.c_str(),
		password.size(), (unsigned char **)salt, salt_len,
		(unsigned char **)bytes_v, len_v, NULL, NULL);
}

// Get a db-ready SRP verifier
// The salt param is only modifyable by this method so that you can free it
// if it was allocated. You shouldn't use it for other purposes, as you will
// need the contents of salt_len too.
inline static std::string getSRPVerifier(const std::string &name,
	const std::string &password, char ** salt, size_t salt_len)
{
	char * bytes_v = NULL;
	size_t len_v;
	getSRPVerifier(name, password, salt, &salt_len,
		&bytes_v, &len_v);
	std::string ret_val = encodeSRPVerifier(std::string(bytes_v, len_v),
		std::string(*salt, salt_len));
	free(bytes_v);
	return ret_val;
}

// Get a db-ready SRP verifier
std::string getSRPVerifier(const std::string &name,
	const std::string &password)
{
	char * salt = NULL;
	std::string ret_val = getSRPVerifier(name,
		password, &salt, 0);
	free(salt);
	return ret_val;
}