1 | /*
|
---|
2 | * Unix SMB/CIFS implementation.
|
---|
3 | * RPC Pipe client / server routines
|
---|
4 | * Copyright (C) Guenther Deschner 2008.
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 3 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "includes.h"
|
---|
21 | #include "../libcli/auth/libcli_auth.h"
|
---|
22 |
|
---|
23 | /*************************************************************************
|
---|
24 | inits a samr_CryptPasswordEx structure
|
---|
25 | *************************************************************************/
|
---|
26 |
|
---|
27 | void init_samr_CryptPasswordEx(const char *pwd,
|
---|
28 | DATA_BLOB *session_key,
|
---|
29 | struct samr_CryptPasswordEx *pwd_buf)
|
---|
30 | {
|
---|
31 | /* samr_CryptPasswordEx */
|
---|
32 |
|
---|
33 | uchar pwbuf[532];
|
---|
34 | struct MD5Context md5_ctx;
|
---|
35 | uint8_t confounder[16];
|
---|
36 | DATA_BLOB confounded_session_key = data_blob(NULL, 16);
|
---|
37 |
|
---|
38 | encode_pw_buffer(pwbuf, pwd, STR_UNICODE);
|
---|
39 |
|
---|
40 | generate_random_buffer((uint8_t *)confounder, 16);
|
---|
41 |
|
---|
42 | MD5Init(&md5_ctx);
|
---|
43 | MD5Update(&md5_ctx, confounder, 16);
|
---|
44 | MD5Update(&md5_ctx, session_key->data,
|
---|
45 | session_key->length);
|
---|
46 | MD5Final(confounded_session_key.data, &md5_ctx);
|
---|
47 |
|
---|
48 | arcfour_crypt_blob(pwbuf, 516, &confounded_session_key);
|
---|
49 | memcpy(&pwbuf[516], confounder, 16);
|
---|
50 |
|
---|
51 | memcpy(pwd_buf->data, pwbuf, sizeof(pwbuf));
|
---|
52 | data_blob_free(&confounded_session_key);
|
---|
53 | }
|
---|
54 |
|
---|
55 | /*************************************************************************
|
---|
56 | inits a samr_CryptPassword structure
|
---|
57 | *************************************************************************/
|
---|
58 |
|
---|
59 | void init_samr_CryptPassword(const char *pwd,
|
---|
60 | DATA_BLOB *session_key,
|
---|
61 | struct samr_CryptPassword *pwd_buf)
|
---|
62 | {
|
---|
63 | /* samr_CryptPassword */
|
---|
64 |
|
---|
65 | encode_pw_buffer(pwd_buf->data, pwd, STR_UNICODE);
|
---|
66 | arcfour_crypt_blob(pwd_buf->data, 516, session_key);
|
---|
67 | }
|
---|