| 1 |
/* |
| 2 |
* PROGRAM: JRD Access Method |
| 3 |
* MODULE: LegacyHash.h |
| 4 |
* DESCRIPTION: Firebird 2.X style hash |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Interbase Public |
| 7 |
* License Version 1.0 (the "License"); you may not use this file |
| 8 |
* except in compliance with the License. You may obtain a copy |
| 9 |
* of the License at http://www.Inprise.com/IPL.html |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an |
| 12 |
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express |
| 13 |
* or implied. See the License for the specific language governing |
| 14 |
* rights and limitations under the License. |
| 15 |
* |
| 16 |
* The Original Code was created by Inprise Corporation |
| 17 |
* and its predecessors. Portions created by Inprise Corporation are |
| 18 |
* Copyright (C) Inprise Corporation. |
| 19 |
* |
| 20 |
* All Rights Reserved. |
| 21 |
* Contributor(s): ______________________________________. |
| 22 |
* |
| 23 |
* 2002.10.29 Sean Leyne - Removed obsolete "Netware" port |
| 24 |
* 2003.02.02 Dmitry Yemanov: Implemented cached security database connection |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifndef AUTH_LEGACY_HASH_H |
| 28 |
#define AUTH_LEGACY_HASH_H |
| 29 |
|
| 30 |
#include "../common/utils_proto.h" |
| 31 |
#include "../common/sha.h" |
| 32 |
#include "../common/os/guid.h" |
| 33 |
#include "../common/utils_proto.h" |
| 34 |
|
| 35 |
namespace Auth { |
| 36 |
|
| 37 |
const size_t MAX_LEGACY_PASSWORD_LENGTH = 64; // used to store passwords internally |
| 38 |
static const char* const LEGACY_PASSWORD_SALT = "9z"; // for old ENC_crypt() |
| 39 |
const size_t SALT_LENGTH = 12; // measured after base64 coding |
| 40 |
|
| 41 |
class LegacyHash |
| 42 |
{ |
| 43 |
public: |
| 44 |
static void hash(Firebird::string& h, const Firebird::string& userName, const TEXT* passwd) |
| 45 |
{ |
| 46 |
Firebird::string salt; |
| 47 |
fb_utils::random64(salt, SALT_LENGTH); |
| 48 |
hash(h, userName, passwd, salt); |
| 49 |
} |
| 50 |
|
| 51 |
static void hash(Firebird::string& h, |
| 52 |
const Firebird::string& userName, |
| 53 |
const Firebird::string& passwd, |
| 54 |
const Firebird::string& oldHash) |
| 55 |
{ |
| 56 |
Firebird::string salt(oldHash); |
| 57 |
salt.resize(SALT_LENGTH, '='); |
| 58 |
Firebird::string allData(salt); |
| 59 |
allData += userName; |
| 60 |
allData += passwd; |
| 61 |
Firebird::Sha1::hashBased64(h, allData); |
| 62 |
h = salt + h; |
| 63 |
} |
| 64 |
}; |
| 65 |
|
| 66 |
} // namespace Auth |
| 67 |
|
| 68 |
#endif // AUTH_LEGACY_SERVER_H |