2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Guenther Deschner 2008.
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.
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.
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/>.
21 #include "../libcli/auth/libcli_auth.h"
22 #include "rpc_client/init_samr.h"
23 #include "librpc/rpc/dcerpc_samr.h"
25 #include "lib/crypto/gnutls_helpers.h"
26 #include <gnutls/gnutls.h>
27 #include <gnutls/crypto.h>
29 /*************************************************************************
30 inits a samr_CryptPasswordEx structure
31 *************************************************************************/
33 NTSTATUS
init_samr_CryptPasswordEx(const char *pwd
,
34 DATA_BLOB
*session_key
,
35 struct samr_CryptPasswordEx
*pwd_buf
)
37 return encode_rc4_passwd_buffer(pwd
, session_key
, pwd_buf
);
40 /*************************************************************************
41 inits a samr_CryptPassword structure
42 *************************************************************************/
44 NTSTATUS
init_samr_CryptPassword(const char *pwd
,
45 DATA_BLOB
*session_key
,
46 struct samr_CryptPassword
*pwd_buf
)
48 /* samr_CryptPassword */
49 gnutls_cipher_hd_t cipher_hnd
= NULL
;
50 gnutls_datum_t sess_key
= {
51 .data
= session_key
->data
,
52 .size
= session_key
->length
,
57 ok
= encode_pw_buffer(pwd_buf
->data
, pwd
, STR_UNICODE
);
59 return NT_STATUS_INTERNAL_ERROR
;
62 rc
= gnutls_cipher_init(&cipher_hnd
,
63 GNUTLS_CIPHER_ARCFOUR_128
,
67 return gnutls_error_to_ntstatus(rc
, NT_STATUS_ACCESS_DISABLED_BY_POLICY_OTHER
);
69 rc
= gnutls_cipher_encrypt(cipher_hnd
,
72 gnutls_cipher_deinit(cipher_hnd
);
74 return gnutls_error_to_ntstatus(rc
, NT_STATUS_ACCESS_DISABLED_BY_POLICY_OTHER
);
80 NTSTATUS
init_samr_CryptPasswordAES(TALLOC_CTX
*mem_ctx
,
83 DATA_BLOB
*session_key
,
84 struct samr_EncryptedPasswordAES
*ppwd_buf
)
86 uint8_t pw_data
[514] = {0};
87 DATA_BLOB plaintext
= {
89 .length
= sizeof(pw_data
),
91 DATA_BLOB ciphertext
= data_blob_null
;
92 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
95 if (ppwd_buf
== NULL
) {
96 return NT_STATUS_INVALID_PARAMETER
;
99 ok
= encode_pwd_buffer514_from_str(pw_data
, password
, STR_UNICODE
);
101 return NT_STATUS_INTERNAL_ERROR
;
104 status
= samba_gnutls_aead_aes_256_cbc_hmac_sha512_encrypt(
108 &samr_aes256_enc_key_salt
,
109 &samr_aes256_mac_key_salt
,
112 ppwd_buf
->auth_data
);
114 if (!NT_STATUS_IS_OK(status
)) {
118 ppwd_buf
->cipher_len
= ciphertext
.length
;
119 ppwd_buf
->cipher
= ciphertext
.data
;
120 ppwd_buf
->PBKDF2Iterations
= 0;
122 SMB_ASSERT(salt
->length
== sizeof(ppwd_buf
->salt
));
123 memcpy(ppwd_buf
->salt
, salt
->data
, salt
->length
);