return status;
}
-NTSTATUS smb2_signing_decrypt_pdu(DATA_BLOB decryption_key,
+NTSTATUS smb2_signing_decrypt_pdu(struct smb2_signing_key *decryption_key,
uint16_t cipher_id,
struct iovec *vector,
int count)
uint32_t tag_size = 0;
uint8_t _key[16] = {0};
gnutls_cipher_algorithm_t algo = 0;
- gnutls_aead_cipher_hd_t cipher_hnd = NULL;
gnutls_datum_t key;
gnutls_datum_t iv;
NTSTATUS status;
tf = (uint8_t *)vector[0].iov_base;
- if (decryption_key.length == 0) {
- DEBUG(2,("Wrong decryption key length %u for SMB2 signing\n",
- (unsigned)decryption_key.length));
+ if (!smb2_signing_key_valid(decryption_key)) {
+ DBG_WARNING("Wrong decryption key length %zu for SMB2 signing\n",
+ decryption_key->blob.length);
return NT_STATUS_ACCESS_DENIED;
}
};
memcpy(key.data,
- decryption_key.data,
- MIN(decryption_key.length, key.size));
+ decryption_key->blob.data,
+ MIN(decryption_key->blob.length, key.size));
iv = (gnutls_datum_t) {
.data = tf + SMB2_TF_NONCE,
.size = iv_size,
};
- rc = gnutls_aead_cipher_init(&cipher_hnd,
- algo,
- &key);
- if (rc < 0) {
- status = NT_STATUS_NO_MEMORY;
- goto out;
+ if (decryption_key->cipher_hnd == NULL) {
+ rc = gnutls_aead_cipher_init(&decryption_key->cipher_hnd,
+ algo,
+ &key);
+ if (rc < 0) {
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
+ }
}
{
ptext = talloc_size(talloc_tos(), ptext_size);
if (ptext == NULL) {
- gnutls_aead_cipher_deinit(cipher_hnd);
status = NT_STATUS_NO_MEMORY;
goto out;
}
ctext = talloc_size(talloc_tos(), ctext_size);
if (ctext == NULL) {
TALLOC_FREE(ptext);
- gnutls_aead_cipher_deinit(cipher_hnd);
status = NT_STATUS_NO_MEMORY;
goto out;
}
if (len != m_total) {
TALLOC_FREE(ptext);
TALLOC_FREE(ctext);
- gnutls_aead_cipher_deinit(cipher_hnd);
status = NT_STATUS_INTERNAL_ERROR;
goto out;
}
tag_size);
/* This function will verify the tag */
- rc = gnutls_aead_cipher_decrypt(cipher_hnd,
+ rc = gnutls_aead_cipher_decrypt(decryption_key->cipher_hnd,
iv.data,
iv.size,
tf + SMB2_TF_NONCE,
DBG_ERR("ERROR: %s\n", gnutls_strerror(rc));
TALLOC_FREE(ptext);
TALLOC_FREE(ctext);
- gnutls_aead_cipher_deinit(cipher_hnd);
status = NT_STATUS_INTERNAL_ERROR;
goto out;
}
TALLOC_FREE(ptext);
TALLOC_FREE(ctext);
}
- gnutls_aead_cipher_deinit(cipher_hnd);
DBG_INFO("Decrypted SMB2 message\n");