2
* Stonith module for Dell DRACIII (Dell Remote Access Card)
4
* Copyright (C) 2003 Alfa21 Outsourcing
5
* Copyright (C) 2003 Roberto Moreda <moreda@alfa21.com>
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
#include <lha_internal.h>
27
#include <clplumbing/base64.h>
28
#include <clplumbing/md5.h>
31
#include "drac3_hash.h"
33
#define BUFLEN 1024 /* buffer */
34
#define SBUFLEN 256 /* small buffer */
35
#define MD5LEN 16 /* md5 buffer */
37
/* Hash functions for DRAC3 authentication */
40
drac3Crc16(const char *str,
47
crc = crc ^ (str[i] << 8);
49
crc = ( (crc & 0x8000) == 32768 ? (crc<<1) ^ 0x1021 : crc<<1);
56
drac3AuthHash(const char * chall,
62
char challBytes[MD5LEN];
64
char xorBytes[MD5LEN];
65
char xorBytesMD5[MD5LEN];
67
char response[MD5LEN+2];
68
char responseb64[SBUFLEN];
71
/* decodes chall -> challBytes */
72
memset(challBytes, 0, MD5LEN);
73
chall_dup = g_strdup(chall);
74
if (chall_dup[strlen(chall_dup) - 1] == '\n' ) {
75
chall_dup[strlen(chall_dup) - 1] = '\0';
77
base64_to_binary(chall_dup, strlen(chall_dup), challBytes, MD5LEN);
79
/* gets MD5 from pass -> passMD5 */
80
MD5((const unsigned char *)pass, strlen(pass), (unsigned char *)passMD5);
82
/* calculate challBytes and passMD5 xor -> xorBytes */
83
for (i=0; i<MD5LEN; i++) {
84
xorBytes[i] = challBytes[i] ^ passMD5[i];
87
/* calculate xorBytes MD5 -> xorBytesMD5 */
88
MD5((unsigned char *)xorBytes, MD5LEN, (unsigned char *)xorBytesMD5);
90
/* calculate xorBytesMD5 crc16 */
91
crc = drac3Crc16(xorBytesMD5, MD5LEN);
93
/* joins xorBytesMD5 and crc16 -> response */
94
memcpy(response, xorBytesMD5, MD5LEN);
95
memcpy(response+MD5LEN, &crc, 2);
97
/* calculate response base64 -> responseb64 */
98
memset(responseb64, 0, SBUFLEN);
99
binary_to_base64(response, MD5LEN+2, responseb64, SBUFLEN);
101
/* assuring null-termination */
102
responseb64[SBUFLEN-1]=0x00;
104
snprintf(token, len, "%s", responseb64);