Merge pull request #3156 from akallabeth/ssl_wrapper_merge
Ssl wrapper merge
This commit is contained in:
commit
4217262680
@ -25,13 +25,8 @@
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rc4.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#if defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER >= 0x0090800f)
|
||||
#define D2I_X509_CONST const
|
||||
@ -44,31 +39,11 @@
|
||||
#include <freerdp/api.h>
|
||||
#include <freerdp/freerdp.h>
|
||||
|
||||
struct crypto_sha1_struct
|
||||
{
|
||||
SHA_CTX sha_ctx;
|
||||
};
|
||||
|
||||
struct crypto_md5_struct
|
||||
{
|
||||
MD5_CTX md5_ctx;
|
||||
};
|
||||
|
||||
struct crypto_rc4_struct
|
||||
{
|
||||
RC4_KEY rc4_key;
|
||||
};
|
||||
|
||||
struct crypto_des3_struct
|
||||
{
|
||||
EVP_CIPHER_CTX des3_ctx;
|
||||
};
|
||||
|
||||
struct crypto_hmac_struct
|
||||
{
|
||||
HMAC_CTX hmac_ctx;
|
||||
};
|
||||
|
||||
struct crypto_cert_struct
|
||||
{
|
||||
X509 * px509;
|
||||
@ -79,26 +54,6 @@ struct crypto_cert_struct
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CRYPTO_SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
|
||||
typedef struct crypto_sha1_struct* CryptoSha1;
|
||||
|
||||
FREERDP_API CryptoSha1 crypto_sha1_init(void);
|
||||
FREERDP_API void crypto_sha1_update(CryptoSha1 sha1, const BYTE* data, UINT32 length);
|
||||
FREERDP_API void crypto_sha1_final(CryptoSha1 sha1, BYTE* out_data);
|
||||
|
||||
#define CRYPTO_MD5_DIGEST_LENGTH MD5_DIGEST_LENGTH
|
||||
typedef struct crypto_md5_struct* CryptoMd5;
|
||||
|
||||
FREERDP_API CryptoMd5 crypto_md5_init(void);
|
||||
FREERDP_API void crypto_md5_update(CryptoMd5 md5, const BYTE* data, UINT32 length);
|
||||
FREERDP_API void crypto_md5_final(CryptoMd5 md5, BYTE* out_data);
|
||||
|
||||
typedef struct crypto_rc4_struct* CryptoRc4;
|
||||
|
||||
FREERDP_API CryptoRc4 crypto_rc4_init(const BYTE* key, UINT32 length);
|
||||
FREERDP_API void crypto_rc4(CryptoRc4 rc4, UINT32 length, const BYTE* in_data, BYTE* out_data);
|
||||
FREERDP_API void crypto_rc4_free(CryptoRc4 rc4);
|
||||
|
||||
typedef struct crypto_des3_struct* CryptoDes3;
|
||||
|
||||
FREERDP_API CryptoDes3 crypto_des3_encrypt_init(const BYTE* key, const BYTE* ivec);
|
||||
@ -107,15 +62,6 @@ FREERDP_API BOOL crypto_des3_encrypt(CryptoDes3 des3, UINT32 length, const BYTE
|
||||
FREERDP_API BOOL crypto_des3_decrypt(CryptoDes3 des3, UINT32 length, const BYTE *in_data, BYTE* out_data);
|
||||
FREERDP_API void crypto_des3_free(CryptoDes3 des3);
|
||||
|
||||
typedef struct crypto_hmac_struct* CryptoHmac;
|
||||
|
||||
FREERDP_API CryptoHmac crypto_hmac_new(void);
|
||||
FREERDP_API BOOL crypto_hmac_sha1_init(CryptoHmac hmac, const BYTE *data, UINT32 length);
|
||||
FREERDP_API BOOL crypto_hmac_md5_init(CryptoHmac hmac, const BYTE *data, UINT32 length);
|
||||
FREERDP_API void crypto_hmac_update(CryptoHmac hmac, const BYTE *data, UINT32 length);
|
||||
FREERDP_API void crypto_hmac_final(CryptoHmac hmac, BYTE *out_data, UINT32 length);
|
||||
FREERDP_API void crypto_hmac_free(CryptoHmac hmac);
|
||||
|
||||
typedef struct crypto_cert_struct* CryptoCert;
|
||||
|
||||
#include <freerdp/crypto/certificate.h>
|
||||
|
@ -22,16 +22,13 @@
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
#include <winpr/print.h>
|
||||
#include <winpr/windows.h>
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/rc4.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/engine.h>
|
||||
|
||||
#include <freerdp/log.h>
|
||||
@ -523,7 +520,7 @@ char* freerdp_assistance_generate_pass_stub(DWORD flags)
|
||||
* Example: WB^6HsrIaFmEpi
|
||||
*/
|
||||
|
||||
RAND_bytes((BYTE*) nums, sizeof(nums));
|
||||
winpr_RAND((BYTE*) nums, sizeof(nums));
|
||||
|
||||
passStub[0] = set1[nums[0] % sizeof(set1)]; /* character 0 */
|
||||
passStub[1] = set2[nums[1] % sizeof(set2)]; /* character 1 */
|
||||
@ -547,11 +544,11 @@ char* freerdp_assistance_generate_pass_stub(DWORD flags)
|
||||
BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* passStub, int* pEncryptedSize)
|
||||
{
|
||||
int status;
|
||||
MD5_CTX md5Ctx;
|
||||
WINPR_MD5_CTX md5Ctx;
|
||||
int cbPasswordW;
|
||||
int cbPassStubW;
|
||||
int EncryptedSize;
|
||||
BYTE PasswordHash[16];
|
||||
BYTE PasswordHash[WINPR_MD5_DIGEST_LENGTH];
|
||||
EVP_CIPHER_CTX rc4Ctx;
|
||||
BYTE* pbIn, *pbOut;
|
||||
int cbOut, cbIn, cbFinal;
|
||||
@ -565,14 +562,29 @@ BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* pas
|
||||
|
||||
cbPasswordW = (status - 1) * 2;
|
||||
|
||||
MD5_Init(&md5Ctx);
|
||||
MD5_Update(&md5Ctx, PasswordW, cbPasswordW);
|
||||
MD5_Final((void*) PasswordHash, &md5Ctx);
|
||||
if (!winpr_MD5_Init(&md5Ctx))
|
||||
{
|
||||
free (PasswordW);
|
||||
return NULL;
|
||||
}
|
||||
if (!winpr_MD5_Update(&md5Ctx, (BYTE*)PasswordW, cbPasswordW))
|
||||
{
|
||||
free (PasswordW);
|
||||
return NULL;
|
||||
}
|
||||
if (!winpr_MD5_Final(&md5Ctx, (BYTE*) PasswordHash, sizeof(PasswordHash)))
|
||||
{
|
||||
free (PasswordW);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
status = ConvertToUnicode(CP_UTF8, 0, passStub, -1, &PassStubW, 0);
|
||||
|
||||
if (status <= 0)
|
||||
{
|
||||
free (PasswordW);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cbPassStubW = (status - 1) * 2;
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/crypto.h>
|
||||
|
||||
#include "autodetect.h"
|
||||
|
||||
#define RDP_RTT_REQUEST_TYPE_CONTINUOUS 0x0001
|
||||
@ -173,7 +175,7 @@ BOOL autodetect_send_bandwidth_measure_payload(rdpContext* context, UINT16 paylo
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RAND_bytes(buffer, payloadLength);
|
||||
winpr_RAND(buffer, payloadLength);
|
||||
Stream_Write(s, buffer, payloadLength);
|
||||
|
||||
bResult = rdp_send_message_channel_pdu(context->rdp, s, SEC_AUTODETECT_REQ);
|
||||
@ -225,7 +227,7 @@ static BOOL autodetect_send_bandwidth_measure_stop(rdpContext* context, UINT16 p
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RAND_bytes(buffer, payloadLength);
|
||||
winpr_RAND(buffer, payloadLength);
|
||||
Stream_Write(s, buffer, payloadLength);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/rsa.h>
|
||||
@ -398,18 +399,17 @@ static BOOL certificate_process_server_public_signature(rdpCertificate* certific
|
||||
const BYTE* sigdata, int sigdatalen, wStream* s, UINT32 siglen)
|
||||
{
|
||||
int i, sum;
|
||||
CryptoMd5 md5ctx;
|
||||
WINPR_MD5_CTX md5ctx;
|
||||
BYTE sig[TSSK_KEY_LENGTH];
|
||||
BYTE encsig[TSSK_KEY_LENGTH + 8];
|
||||
BYTE md5hash[CRYPTO_MD5_DIGEST_LENGTH];
|
||||
BYTE md5hash[WINPR_MD5_DIGEST_LENGTH];
|
||||
|
||||
md5ctx = crypto_md5_init();
|
||||
|
||||
if (!md5ctx)
|
||||
return FALSE;
|
||||
|
||||
crypto_md5_update(md5ctx, sigdata, sigdatalen);
|
||||
crypto_md5_final(md5ctx, md5hash);
|
||||
if (!winpr_MD5_Init(&md5ctx))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5ctx, sigdata, sigdatalen))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Final(&md5ctx, md5hash, sizeof(md5hash)))
|
||||
return FALSE;
|
||||
Stream_Read(s, encsig, siglen);
|
||||
|
||||
/* Last 8 bytes shall be all zero. */
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "transport.h"
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
|
||||
#include <freerdp/log.h>
|
||||
#include <freerdp/error.h>
|
||||
@ -502,7 +503,7 @@ static BOOL rdp_client_establish_keys(rdpRdp* rdp)
|
||||
goto end;
|
||||
}
|
||||
|
||||
rdp->fips_hmac = crypto_hmac_new();
|
||||
rdp->fips_hmac = calloc(1, sizeof(WINPR_HMAC_CTX));
|
||||
if (!rdp->fips_hmac)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate fips hmac");
|
||||
@ -512,19 +513,9 @@ static BOOL rdp_client_establish_keys(rdpRdp* rdp)
|
||||
goto end;
|
||||
}
|
||||
|
||||
rdp->rc4_decrypt_key = crypto_rc4_init(rdp->decrypt_key, rdp->rc4_key_len);
|
||||
if (!rdp->rc4_decrypt_key)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate rc4 decrypt key");
|
||||
goto end;
|
||||
}
|
||||
winpr_RC4_Init(rdp->rc4_decrypt_key, rdp->decrypt_key, rdp->rc4_key_len);
|
||||
winpr_RC4_Init(rdp->rc4_encrypt_key, rdp->encrypt_key, rdp->rc4_key_len);
|
||||
|
||||
rdp->rc4_encrypt_key = crypto_rc4_init(rdp->encrypt_key, rdp->rc4_key_len);
|
||||
if (!rdp->rc4_encrypt_key)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate rc4 encrypt key");
|
||||
goto end;
|
||||
}
|
||||
ret = TRUE;
|
||||
end:
|
||||
free(crypt_client_random);
|
||||
@ -620,7 +611,7 @@ BOOL rdp_server_establish_keys(rdpRdp* rdp, wStream* s)
|
||||
goto end;
|
||||
}
|
||||
|
||||
rdp->fips_hmac = crypto_hmac_new();
|
||||
rdp->fips_hmac = calloc(1, sizeof(WINPR_HMAC_CTX));
|
||||
if (!rdp->fips_hmac)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate fips hmac");
|
||||
@ -630,19 +621,9 @@ BOOL rdp_server_establish_keys(rdpRdp* rdp, wStream* s)
|
||||
goto end;
|
||||
}
|
||||
|
||||
rdp->rc4_decrypt_key = crypto_rc4_init(rdp->decrypt_key, rdp->rc4_key_len);
|
||||
if (!rdp->rc4_decrypt_key)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate rc4 decrypt key");
|
||||
goto end;
|
||||
}
|
||||
winpr_RC4_Init(rdp->rc4_decrypt_key, rdp->decrypt_key, rdp->rc4_key_len);
|
||||
winpr_RC4_Init(rdp->rc4_encrypt_key, rdp->encrypt_key, rdp->rc4_key_len);
|
||||
|
||||
rdp->rc4_encrypt_key = crypto_rc4_init(rdp->encrypt_key, rdp->rc4_key_len);
|
||||
if (!rdp->rc4_encrypt_key)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate rc4 encrypt key");
|
||||
goto end;
|
||||
}
|
||||
ret = TRUE;
|
||||
end:
|
||||
free(crypt_client_random);
|
||||
|
@ -29,8 +29,6 @@
|
||||
#include <winpr/dsparse.h>
|
||||
#include <winpr/winhttp.h>
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#define TAG FREERDP_TAG("core.gateway.ntlm")
|
||||
|
||||
wStream* rpc_ntlm_http_request(rdpRpc* rpc, HttpContext* http, const char* method, int contentLength, SecBuffer* ntlmToken)
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include <winpr/dsparse.h>
|
||||
|
||||
#include <freerdp/log.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include "http.h"
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include <freerdp/log.h>
|
||||
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/bio.h>
|
||||
|
||||
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
||||
|
@ -22,6 +22,7 @@
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
#include <winpr/winhttp.h>
|
||||
|
||||
#include <freerdp/log.h>
|
||||
@ -422,7 +423,7 @@ int rts_ping_traffic_sent_notify_command_write(BYTE* buffer, UINT32 PingTrafficS
|
||||
|
||||
void rts_generate_cookie(BYTE* cookie)
|
||||
{
|
||||
RAND_pseudo_bytes(cookie, 16);
|
||||
winpr_RAND(cookie, 16);
|
||||
}
|
||||
|
||||
/* CONN/A Sequence */
|
||||
|
@ -24,6 +24,7 @@
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
|
||||
#include <freerdp/log.h>
|
||||
|
||||
@ -1178,7 +1179,7 @@ const BYTE tssk_exponent[] =
|
||||
|
||||
BOOL gcc_write_server_security_data(wStream* s, rdpMcs* mcs)
|
||||
{
|
||||
CryptoMd5 md5;
|
||||
WINPR_MD5_CTX md5;
|
||||
BYTE* sigData;
|
||||
int expLen, keyLen, sigDataLen;
|
||||
BYTE encryptedSignature[TSSK_KEY_LENGTH];
|
||||
@ -1375,15 +1376,12 @@ BOOL gcc_write_server_security_data(wStream* s, rdpMcs* mcs)
|
||||
|
||||
memcpy(signature, initial_signature, sizeof(initial_signature));
|
||||
|
||||
md5 = crypto_md5_init();
|
||||
if (!md5)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a md5");
|
||||
if (!winpr_MD5_Init(&md5))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, sigData, sigDataLen))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Final(&md5, signature, sizeof(signature)))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
crypto_md5_update(md5, sigData, sigDataLen);
|
||||
crypto_md5_final(md5, signature);
|
||||
|
||||
crypto_rsa_private_encrypt(signature, sizeof(signature), TSSK_KEY_LENGTH,
|
||||
tssk_modulus, tssk_privateExponent, encryptedSignature);
|
||||
|
@ -45,7 +45,7 @@ static const char* const INFO_TYPE_LOGON_STRINGS[4] =
|
||||
|
||||
BOOL rdp_compute_client_auto_reconnect_cookie(rdpRdp* rdp)
|
||||
{
|
||||
CryptoHmac hmac;
|
||||
WINPR_HMAC_CTX hmac;
|
||||
BYTE ClientRandom[32];
|
||||
BYTE AutoReconnectRandom[32];
|
||||
ARC_SC_PRIVATE_PACKET* serverCookie;
|
||||
@ -68,18 +68,14 @@ BOOL rdp_compute_client_auto_reconnect_cookie(rdpRdp* rdp)
|
||||
if (settings->SelectedProtocol == PROTOCOL_RDP)
|
||||
CopyMemory(ClientRandom, settings->ClientRandom, settings->ClientRandomLength);
|
||||
|
||||
hmac = crypto_hmac_new();
|
||||
|
||||
if (!hmac)
|
||||
return FALSE;
|
||||
|
||||
/* SecurityVerifier = HMAC_MD5(AutoReconnectRandom, ClientRandom) */
|
||||
|
||||
if (!crypto_hmac_md5_init(hmac, AutoReconnectRandom, 16))
|
||||
if (!winpr_HMAC_Init(&hmac, WINPR_MD_MD5, AutoReconnectRandom, 16))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Update(&hmac, ClientRandom, 32))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Final(&hmac, clientCookie->securityVerifier, 16))
|
||||
return FALSE;
|
||||
crypto_hmac_update(hmac, ClientRandom, 32);
|
||||
crypto_hmac_final(hmac, clientCookie->securityVerifier, 16);
|
||||
crypto_hmac_free(hmac);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
#include <freerdp/log.h>
|
||||
|
||||
#include "redirection.h"
|
||||
@ -384,22 +385,19 @@ BOOL license_generate_keys(rdpLicense* license)
|
||||
|
||||
BOOL license_generate_hwid(rdpLicense* license)
|
||||
{
|
||||
CryptoMd5 md5;
|
||||
WINPR_MD5_CTX md5;
|
||||
BYTE macAddress[6];
|
||||
|
||||
ZeroMemory(macAddress, sizeof(macAddress));
|
||||
ZeroMemory(license->HardwareId, HWID_LENGTH);
|
||||
|
||||
md5 = crypto_md5_init();
|
||||
|
||||
if (!md5)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a md5");
|
||||
if (!winpr_MD5_Init(&md5))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, macAddress, sizeof(macAddress)))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Final(&md5, &license->HardwareId[HWID_PLATFORM_ID_LENGTH], WINPR_MD5_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
crypto_md5_update(md5, macAddress, sizeof(macAddress));
|
||||
crypto_md5_final(md5, &license->HardwareId[HWID_PLATFORM_ID_LENGTH]);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -460,27 +458,19 @@ BOOL license_encrypt_premaster_secret(rdpLicense* license)
|
||||
|
||||
BOOL license_decrypt_platform_challenge(rdpLicense* license)
|
||||
{
|
||||
CryptoRc4 rc4;
|
||||
WINPR_RC4_CTX rc4;
|
||||
|
||||
license->PlatformChallenge->data = (BYTE *)malloc(license->EncryptedPlatformChallenge->length);
|
||||
if (!license->PlatformChallenge->data)
|
||||
return FALSE;
|
||||
license->PlatformChallenge->length = license->EncryptedPlatformChallenge->length;
|
||||
|
||||
rc4 = crypto_rc4_init(license->LicensingEncryptionKey, LICENSING_ENCRYPTION_KEY_LENGTH);
|
||||
if (!rc4)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a rc4");
|
||||
free(license->PlatformChallenge->data);
|
||||
license->PlatformChallenge->data = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
crypto_rc4(rc4, license->EncryptedPlatformChallenge->length,
|
||||
winpr_RC4_Init(&rc4, license->LicensingEncryptionKey, LICENSING_ENCRYPTION_KEY_LENGTH);
|
||||
winpr_RC4_Update(&rc4, license->EncryptedPlatformChallenge->length,
|
||||
license->EncryptedPlatformChallenge->data,
|
||||
license->PlatformChallenge->data);
|
||||
|
||||
crypto_rc4_free(rc4);
|
||||
winpr_RC4_Final(&rc4);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1025,7 +1015,7 @@ BOOL license_send_platform_challenge_response_packet(rdpLicense* license)
|
||||
wStream* s;
|
||||
int length;
|
||||
BYTE* buffer;
|
||||
CryptoRc4 rc4;
|
||||
WINPR_RC4_CTX rc4;
|
||||
BYTE mac_data[16];
|
||||
BOOL status;
|
||||
|
||||
@ -1046,19 +1036,15 @@ BOOL license_send_platform_challenge_response_packet(rdpLicense* license)
|
||||
if (!status)
|
||||
return FALSE;
|
||||
|
||||
rc4 = crypto_rc4_init(license->LicensingEncryptionKey, LICENSING_ENCRYPTION_KEY_LENGTH);
|
||||
if (!rc4)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a rc4");
|
||||
return FALSE;
|
||||
}
|
||||
winpr_RC4_Init(&rc4, license->LicensingEncryptionKey, LICENSING_ENCRYPTION_KEY_LENGTH);
|
||||
|
||||
buffer = (BYTE*) malloc(HWID_LENGTH);
|
||||
if (!buffer)
|
||||
return FALSE;
|
||||
|
||||
crypto_rc4(rc4, HWID_LENGTH, license->HardwareId, buffer);
|
||||
crypto_rc4_free(rc4);
|
||||
winpr_RC4_Update(&rc4, HWID_LENGTH, license->HardwareId, buffer);
|
||||
winpr_RC4_Final(&rc4);
|
||||
|
||||
license->EncryptedHardwareId->type = BB_DATA_BLOB;
|
||||
license->EncryptedHardwareId->data = buffer;
|
||||
license->EncryptedHardwareId->length = HWID_LENGTH;
|
||||
|
@ -27,6 +27,7 @@ typedef struct rdp_nla rdpNla;
|
||||
|
||||
#include <winpr/sspi.h>
|
||||
#include <winpr/stream.h>
|
||||
#include <winpr/crypto.h>
|
||||
|
||||
#include <freerdp/crypto/tls.h>
|
||||
#include <freerdp/crypto/ber.h>
|
||||
@ -75,7 +76,7 @@ struct rdp_nla
|
||||
SecBuffer authInfo;
|
||||
SecBuffer PublicKey;
|
||||
SecBuffer tsCredentials;
|
||||
CryptoRc4 rc4SealState;
|
||||
WINPR_RC4_CTX rc4SealState;
|
||||
LPTSTR ServicePrincipalName;
|
||||
SEC_WINNT_AUTH_IDENTITY* identity;
|
||||
PSecurityFunctionTable table;
|
||||
|
@ -1590,13 +1590,13 @@ void rdp_reset(rdpRdp* rdp)
|
||||
|
||||
if (rdp->rc4_decrypt_key)
|
||||
{
|
||||
crypto_rc4_free(rdp->rc4_decrypt_key);
|
||||
winpr_RC4_Final(rdp->rc4_decrypt_key);
|
||||
rdp->rc4_decrypt_key = NULL;
|
||||
}
|
||||
|
||||
if (rdp->rc4_encrypt_key)
|
||||
{
|
||||
crypto_rc4_free(rdp->rc4_encrypt_key);
|
||||
winpr_RC4_Final(rdp->rc4_encrypt_key);
|
||||
rdp->rc4_encrypt_key = NULL;
|
||||
}
|
||||
|
||||
@ -1614,7 +1614,7 @@ void rdp_reset(rdpRdp* rdp)
|
||||
|
||||
if (rdp->fips_hmac)
|
||||
{
|
||||
crypto_hmac_free(rdp->fips_hmac);
|
||||
free(rdp->fips_hmac);
|
||||
rdp->fips_hmac = NULL;
|
||||
}
|
||||
|
||||
@ -1661,11 +1661,11 @@ void rdp_free(rdpRdp* rdp)
|
||||
{
|
||||
if (rdp)
|
||||
{
|
||||
crypto_rc4_free(rdp->rc4_decrypt_key);
|
||||
crypto_rc4_free(rdp->rc4_encrypt_key);
|
||||
winpr_RC4_Final(rdp->rc4_decrypt_key);
|
||||
winpr_RC4_Final(rdp->rc4_encrypt_key);
|
||||
crypto_des3_free(rdp->fips_encrypt);
|
||||
crypto_des3_free(rdp->fips_decrypt);
|
||||
crypto_hmac_free(rdp->fips_hmac);
|
||||
free(rdp->fips_hmac);
|
||||
freerdp_settings_free(rdp->settings);
|
||||
freerdp_settings_free(rdp->settingsCopy);
|
||||
transport_free(rdp->transport);
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include <freerdp/log.h>
|
||||
|
||||
#include <winpr/stream.h>
|
||||
#include <winpr/crypto.h>
|
||||
|
||||
/* Security Header Flags */
|
||||
#define SEC_EXCHANGE_PKT 0x0001
|
||||
@ -147,15 +148,15 @@ struct rdp_rdp
|
||||
rdpAutoDetect* autodetect;
|
||||
rdpHeartbeat* heartbeat;
|
||||
rdpMultitransport* multitransport;
|
||||
struct crypto_rc4_struct* rc4_decrypt_key;
|
||||
WINPR_RC4_CTX* rc4_decrypt_key;
|
||||
int decrypt_use_count;
|
||||
int decrypt_checksum_use_count;
|
||||
struct crypto_rc4_struct* rc4_encrypt_key;
|
||||
WINPR_RC4_CTX* rc4_encrypt_key;
|
||||
int encrypt_use_count;
|
||||
int encrypt_checksum_use_count;
|
||||
struct crypto_des3_struct* fips_encrypt;
|
||||
struct crypto_des3_struct* fips_decrypt;
|
||||
struct crypto_hmac_struct* fips_hmac;
|
||||
WINPR_HMAC_CTX* fips_hmac;
|
||||
UINT32 sec_flags;
|
||||
BOOL do_crypt;
|
||||
BOOL do_crypt_license;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "security.h"
|
||||
|
||||
#include <freerdp/log.h>
|
||||
#include <winpr/crypto.h>
|
||||
|
||||
#define TAG FREERDP_TAG("core")
|
||||
|
||||
@ -126,35 +127,35 @@ fips_oddparity_table[256] =
|
||||
static BOOL security_salted_hash(const BYTE* salt, const BYTE* input, int length,
|
||||
const BYTE* salt1, const BYTE* salt2, BYTE* output)
|
||||
{
|
||||
CryptoMd5 md5;
|
||||
CryptoSha1 sha1;
|
||||
BYTE sha1_digest[CRYPTO_SHA1_DIGEST_LENGTH];
|
||||
WINPR_MD5_CTX md5;
|
||||
WINPR_SHA1_CTX sha1;
|
||||
BYTE sha1_digest[WINPR_SHA1_DIGEST_LENGTH];
|
||||
|
||||
/* SaltedHash(Salt, Input, Salt1, Salt2) = MD5(S + SHA1(Input + Salt + Salt1 + Salt2)) */
|
||||
|
||||
/* SHA1_Digest = SHA1(Input + Salt + Salt1 + Salt2) */
|
||||
sha1 = crypto_sha1_init();
|
||||
if (!sha1)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a sha1");
|
||||
if (!winpr_SHA1_Init(&sha1))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, input, length)) /* Input */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, salt, 48)) /* Salt (48 bytes) */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, salt1, 32)) /* Salt1 (32 bytes) */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, salt2, 32)) /* Salt2 (32 bytes) */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Final(&sha1, sha1_digest, sizeof(sha1_digest)))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_sha1_update(sha1, input, length); /* Input */
|
||||
crypto_sha1_update(sha1, salt, 48); /* Salt (48 bytes) */
|
||||
crypto_sha1_update(sha1, salt1, 32); /* Salt1 (32 bytes) */
|
||||
crypto_sha1_update(sha1, salt2, 32); /* Salt2 (32 bytes) */
|
||||
crypto_sha1_final(sha1, sha1_digest);
|
||||
|
||||
/* SaltedHash(Salt, Input, Salt1, Salt2) = MD5(S + SHA1_Digest) */
|
||||
md5 = crypto_md5_init();
|
||||
if (!md5)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a md5");
|
||||
if (!winpr_MD5_Init(&md5))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, salt, 48)) /* Salt (48 bytes) */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, sha1_digest, sizeof(sha1_digest))) /* SHA1_Digest */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Final(&md5, output, WINPR_MD5_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_md5_update(md5, salt, 48); /* Salt (48 bytes) */
|
||||
crypto_md5_update(md5, sha1_digest, sizeof(sha1_digest)); /* SHA1_Digest */
|
||||
crypto_md5_final(md5, output);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -199,18 +200,18 @@ void security_mac_salt_key(const BYTE* session_key_blob, const BYTE* client_rand
|
||||
|
||||
BOOL security_md5_16_32_32(const BYTE* in0, const BYTE* in1, const BYTE* in2, BYTE* output)
|
||||
{
|
||||
CryptoMd5 md5;
|
||||
WINPR_MD5_CTX md5;
|
||||
|
||||
md5 = crypto_md5_init();
|
||||
if (!md5)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a md5");
|
||||
if (!winpr_MD5_Init(&md5))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, in0, 16))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, in1, 32))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, in2, 32))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Final(&md5, output, WINPR_MD5_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_md5_update(md5, in0, 16);
|
||||
crypto_md5_update(md5, in1, 32);
|
||||
crypto_md5_update(md5, in2, 32);
|
||||
crypto_md5_final(md5, output);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -232,76 +233,78 @@ void security_UINT32_le(BYTE* output, UINT32 value)
|
||||
BOOL security_mac_data(const BYTE* mac_salt_key, const BYTE* data, UINT32 length,
|
||||
BYTE* output)
|
||||
{
|
||||
CryptoMd5 md5;
|
||||
CryptoSha1 sha1;
|
||||
WINPR_MD5_CTX md5;
|
||||
WINPR_SHA1_CTX sha1;
|
||||
BYTE length_le[4];
|
||||
BYTE sha1_digest[CRYPTO_SHA1_DIGEST_LENGTH];
|
||||
BYTE sha1_digest[WINPR_SHA1_DIGEST_LENGTH];
|
||||
|
||||
/* MacData = MD5(MacSaltKey + pad2 + SHA1(MacSaltKey + pad1 + length + data)) */
|
||||
|
||||
security_UINT32_le(length_le, length); /* length must be little-endian */
|
||||
|
||||
/* SHA1_Digest = SHA1(MacSaltKey + pad1 + length + data) */
|
||||
sha1 = crypto_sha1_init();
|
||||
if (!sha1)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a sha1");
|
||||
if (!winpr_SHA1_Init(&sha1))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, mac_salt_key, 16)) /* MacSaltKey */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, pad1, sizeof(pad1))) /* pad1 */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, length_le, sizeof(length_le))) /* length */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, data, length)) /* data */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Final(&sha1, sha1_digest, sizeof(sha1_digest)))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_sha1_update(sha1, mac_salt_key, 16); /* MacSaltKey */
|
||||
crypto_sha1_update(sha1, pad1, sizeof(pad1)); /* pad1 */
|
||||
crypto_sha1_update(sha1, length_le, sizeof(length_le)); /* length */
|
||||
crypto_sha1_update(sha1, data, length); /* data */
|
||||
crypto_sha1_final(sha1, sha1_digest);
|
||||
|
||||
/* MacData = MD5(MacSaltKey + pad2 + SHA1_Digest) */
|
||||
md5 = crypto_md5_init();
|
||||
if (!md5)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a md5");
|
||||
if (!winpr_MD5_Init(&md5))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, mac_salt_key, 16)) /* MacSaltKey */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, pad2, sizeof(pad2))) /* pad2 */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, sha1_digest, sizeof(sha1_digest))) /* SHA1_Digest */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Final(&md5, output, WINPR_MD5_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_md5_update(md5, mac_salt_key, 16); /* MacSaltKey */
|
||||
crypto_md5_update(md5, pad2, sizeof(pad2)); /* pad2 */
|
||||
crypto_md5_update(md5, sha1_digest, sizeof(sha1_digest)); /* SHA1_Digest */
|
||||
crypto_md5_final(md5, output);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL security_mac_signature(rdpRdp *rdp, const BYTE* data, UINT32 length, BYTE* output)
|
||||
{
|
||||
CryptoMd5 md5;
|
||||
CryptoSha1 sha1;
|
||||
WINPR_MD5_CTX md5;
|
||||
WINPR_SHA1_CTX sha1;
|
||||
BYTE length_le[4];
|
||||
BYTE md5_digest[CRYPTO_MD5_DIGEST_LENGTH];
|
||||
BYTE sha1_digest[CRYPTO_SHA1_DIGEST_LENGTH];
|
||||
BYTE md5_digest[WINPR_MD5_DIGEST_LENGTH];
|
||||
BYTE sha1_digest[WINPR_SHA1_DIGEST_LENGTH];
|
||||
|
||||
security_UINT32_le(length_le, length); /* length must be little-endian */
|
||||
|
||||
/* SHA1_Digest = SHA1(MACKeyN + pad1 + length + data) */
|
||||
sha1 = crypto_sha1_init();
|
||||
if (!sha1)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a sha1");
|
||||
if (!winpr_SHA1_Init(&sha1))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, rdp->sign_key, rdp->rc4_key_len)) /* MacKeyN */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, pad1, sizeof(pad1))) /* pad1 */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, length_le, sizeof(length_le))) /* length */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, data, length)) /* data */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Final(&sha1, sha1_digest, sizeof(sha1_digest)))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_sha1_update(sha1, rdp->sign_key, rdp->rc4_key_len); /* MacKeyN */
|
||||
crypto_sha1_update(sha1, pad1, sizeof(pad1)); /* pad1 */
|
||||
crypto_sha1_update(sha1, length_le, sizeof(length_le)); /* length */
|
||||
crypto_sha1_update(sha1, data, length); /* data */
|
||||
crypto_sha1_final(sha1, sha1_digest);
|
||||
|
||||
/* MACSignature = First64Bits(MD5(MACKeyN + pad2 + SHA1_Digest)) */
|
||||
md5 = crypto_md5_init();
|
||||
if (!md5)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a md5");
|
||||
if (!winpr_MD5_Init(&md5))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, rdp->sign_key, rdp->rc4_key_len)) /* MacKeyN */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, pad2, sizeof(pad2))) /* pad2 */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, sha1_digest, sizeof(sha1_digest))) /* SHA1_Digest */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Final(&md5, md5_digest, sizeof(md5_digest)))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_md5_update(md5, rdp->sign_key, rdp->rc4_key_len); /* MacKeyN */
|
||||
crypto_md5_update(md5, pad2, sizeof(pad2)); /* pad2 */
|
||||
crypto_md5_update(md5, sha1_digest, sizeof(sha1_digest)); /* SHA1_Digest */
|
||||
crypto_md5_final(md5, md5_digest);
|
||||
|
||||
memcpy(output, md5_digest, 8);
|
||||
return TRUE;
|
||||
@ -310,12 +313,12 @@ BOOL security_mac_signature(rdpRdp *rdp, const BYTE* data, UINT32 length, BYTE*
|
||||
BOOL security_salted_mac_signature(rdpRdp *rdp, const BYTE* data, UINT32 length,
|
||||
BOOL encryption, BYTE* output)
|
||||
{
|
||||
CryptoMd5 md5;
|
||||
CryptoSha1 sha1;
|
||||
WINPR_MD5_CTX md5;
|
||||
WINPR_SHA1_CTX sha1;
|
||||
BYTE length_le[4];
|
||||
BYTE use_count_le[4];
|
||||
BYTE md5_digest[CRYPTO_MD5_DIGEST_LENGTH];
|
||||
BYTE sha1_digest[CRYPTO_SHA1_DIGEST_LENGTH];
|
||||
BYTE md5_digest[WINPR_MD5_DIGEST_LENGTH];
|
||||
BYTE sha1_digest[WINPR_SHA1_DIGEST_LENGTH];
|
||||
|
||||
security_UINT32_le(length_le, length); /* length must be little-endian */
|
||||
|
||||
@ -333,30 +336,32 @@ BOOL security_salted_mac_signature(rdpRdp *rdp, const BYTE* data, UINT32 length,
|
||||
}
|
||||
|
||||
/* SHA1_Digest = SHA1(MACKeyN + pad1 + length + data) */
|
||||
sha1 = crypto_sha1_init();
|
||||
if (!sha1)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a sha1");
|
||||
if (!winpr_SHA1_Init(&sha1))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, rdp->sign_key, rdp->rc4_key_len)) /* MacKeyN */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, pad1, sizeof(pad1))) /* pad1 */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, length_le, sizeof(length_le))) /* length */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, data, length)) /* data */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, use_count_le, sizeof(use_count_le))) /* encryptionCount */
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Final(&sha1, sha1_digest, sizeof(sha1_digest)))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_sha1_update(sha1, rdp->sign_key, rdp->rc4_key_len); /* MacKeyN */
|
||||
crypto_sha1_update(sha1, pad1, sizeof(pad1)); /* pad1 */
|
||||
crypto_sha1_update(sha1, length_le, sizeof(length_le)); /* length */
|
||||
crypto_sha1_update(sha1, data, length); /* data */
|
||||
crypto_sha1_update(sha1, use_count_le, sizeof(use_count_le)); /* encryptionCount */
|
||||
crypto_sha1_final(sha1, sha1_digest);
|
||||
|
||||
/* MACSignature = First64Bits(MD5(MACKeyN + pad2 + SHA1_Digest)) */
|
||||
md5 = crypto_md5_init();
|
||||
if (!md5)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a md5");
|
||||
if (!winpr_MD5_Init(&md5))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, rdp->sign_key, rdp->rc4_key_len)) /* MacKeyN */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, pad2, sizeof(pad2))) /* pad2 */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, sha1_digest, sizeof(sha1_digest))) /* SHA1_Digest */
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Final(&md5, md5_digest, sizeof(md5_digest)))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_md5_update(md5, rdp->sign_key, rdp->rc4_key_len); /* MacKeyN */
|
||||
crypto_md5_update(md5, pad2, sizeof(pad2)); /* pad2 */
|
||||
crypto_md5_update(md5, sha1_digest, sizeof(sha1_digest)); /* SHA1_Digest */
|
||||
crypto_md5_final(md5, md5_digest);
|
||||
|
||||
memcpy(output, md5_digest, 8);
|
||||
return TRUE;
|
||||
@ -428,40 +433,38 @@ BOOL security_establish_keys(const BYTE* client_random, rdpRdp* rdp)
|
||||
|
||||
if (settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
||||
{
|
||||
CryptoSha1 sha1;
|
||||
BYTE client_encrypt_key_t[CRYPTO_SHA1_DIGEST_LENGTH + 1];
|
||||
BYTE client_decrypt_key_t[CRYPTO_SHA1_DIGEST_LENGTH + 1];
|
||||
sha1 = crypto_sha1_init();
|
||||
if (!sha1)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a sha1");
|
||||
WINPR_SHA1_CTX sha1;
|
||||
BYTE client_encrypt_key_t[WINPR_SHA1_DIGEST_LENGTH + 1];
|
||||
BYTE client_decrypt_key_t[WINPR_SHA1_DIGEST_LENGTH + 1];
|
||||
|
||||
if (!winpr_SHA1_Init(&sha1))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, client_random + 16, 16))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, server_random + 16, 16))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Final(&sha1, client_encrypt_key_t, sizeof(client_encrypt_key_t)))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_sha1_update(sha1, client_random + 16, 16);
|
||||
crypto_sha1_update(sha1, server_random + 16, 16);
|
||||
crypto_sha1_final(sha1, client_encrypt_key_t);
|
||||
client_encrypt_key_t[20] = client_encrypt_key_t[0];
|
||||
|
||||
sha1 = crypto_sha1_init();
|
||||
if (!sha1)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a sha1");
|
||||
if (!winpr_SHA1_Init(&sha1))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, client_random, 16))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, server_random, 16))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Final(&sha1, client_decrypt_key_t, sizeof(client_decrypt_key_t)))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_sha1_update(sha1, client_random, 16);
|
||||
crypto_sha1_update(sha1, server_random, 16);
|
||||
crypto_sha1_final(sha1, client_decrypt_key_t);
|
||||
client_decrypt_key_t[20] = client_decrypt_key_t[0];
|
||||
|
||||
sha1 = crypto_sha1_init();
|
||||
if (!sha1)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a sha1");
|
||||
if (!winpr_SHA1_Init(&sha1))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, client_decrypt_key_t, WINPR_SHA1_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, client_encrypt_key_t, WINPR_SHA1_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Final(&sha1, rdp->fips_sign_key, WINPR_SHA1_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_sha1_update(sha1, client_decrypt_key_t, 20);
|
||||
crypto_sha1_update(sha1, client_encrypt_key_t, 20);
|
||||
crypto_sha1_final(sha1, rdp->fips_sign_key);
|
||||
|
||||
if (rdp->settings->ServerMode)
|
||||
{
|
||||
@ -532,42 +535,40 @@ BOOL security_establish_keys(const BYTE* client_random, rdpRdp* rdp)
|
||||
|
||||
BOOL security_key_update(BYTE* key, BYTE* update_key, int key_len, rdpRdp* rdp)
|
||||
{
|
||||
BYTE sha1h[CRYPTO_SHA1_DIGEST_LENGTH];
|
||||
CryptoMd5 md5;
|
||||
CryptoSha1 sha1;
|
||||
CryptoRc4 rc4;
|
||||
BYTE sha1h[WINPR_SHA1_DIGEST_LENGTH];
|
||||
WINPR_MD5_CTX md5;
|
||||
WINPR_SHA1_CTX sha1;
|
||||
WINPR_RC4_CTX rc4;
|
||||
BYTE salt[] = { 0xD1, 0x26, 0x9E }; /* 40 bits: 3 bytes, 56 bits: 1 byte */
|
||||
|
||||
sha1 = crypto_sha1_init();
|
||||
if (!sha1)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a sha1");
|
||||
if (!winpr_SHA1_Init(&sha1))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, update_key, key_len))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, pad1, sizeof(pad1)))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&sha1, key, key_len))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Final(&sha1, sha1h, sizeof(sha1h)))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_sha1_update(sha1, update_key, key_len);
|
||||
crypto_sha1_update(sha1, pad1, sizeof(pad1));
|
||||
crypto_sha1_update(sha1, key, key_len);
|
||||
crypto_sha1_final(sha1, sha1h);
|
||||
|
||||
md5 = crypto_md5_init();
|
||||
if (!md5)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a md5");
|
||||
if (!winpr_MD5_Init(&md5))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, update_key, key_len))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, pad2, sizeof(pad2)))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&md5, sha1h, sizeof(sha1h)))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Final(&md5, key, WINPR_MD5_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_md5_update(md5, update_key, key_len);
|
||||
crypto_md5_update(md5, pad2, sizeof(pad2));
|
||||
crypto_md5_update(md5, sha1h, sizeof(sha1h));
|
||||
crypto_md5_final(md5, key);
|
||||
|
||||
rc4 = crypto_rc4_init(key, key_len);
|
||||
if (!rc4)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate a rc4");
|
||||
if (!winpr_RC4_Init(&rc4, key, key_len))
|
||||
return FALSE;
|
||||
if (!winpr_RC4_Update(&rc4, key_len, key, key))
|
||||
return FALSE;
|
||||
if (!winpr_RC4_Final(&rc4))
|
||||
return FALSE;
|
||||
}
|
||||
crypto_rc4(rc4, key_len, key, key);
|
||||
crypto_rc4_free(rc4);
|
||||
|
||||
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_40BIT)
|
||||
memcpy(key, salt, 3);
|
||||
@ -584,17 +585,16 @@ BOOL security_encrypt(BYTE* data, int length, rdpRdp* rdp)
|
||||
if (!security_key_update(rdp->encrypt_key, rdp->encrypt_update_key, rdp->rc4_key_len, rdp))
|
||||
return FALSE;
|
||||
|
||||
crypto_rc4_free(rdp->rc4_encrypt_key);
|
||||
rdp->rc4_encrypt_key = crypto_rc4_init(rdp->encrypt_key, rdp->rc4_key_len);
|
||||
if (!rdp->rc4_encrypt_key)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate rc4 encrypt key");
|
||||
if (!winpr_RC4_Final(rdp->rc4_encrypt_key))
|
||||
return FALSE;
|
||||
}
|
||||
if (!winpr_RC4_Init(rdp->rc4_encrypt_key, rdp->encrypt_key, rdp->rc4_key_len))
|
||||
return FALSE;
|
||||
|
||||
rdp->encrypt_use_count = 0;
|
||||
}
|
||||
|
||||
crypto_rc4(rdp->rc4_encrypt_key, length, data, data);
|
||||
if (!winpr_RC4_Update(rdp->rc4_encrypt_key, length, data, data))
|
||||
return FALSE;
|
||||
rdp->encrypt_use_count++;
|
||||
rdp->encrypt_checksum_use_count++;
|
||||
return TRUE;
|
||||
@ -609,17 +609,15 @@ BOOL security_decrypt(BYTE* data, int length, rdpRdp* rdp)
|
||||
{
|
||||
if (!security_key_update(rdp->decrypt_key, rdp->decrypt_update_key, rdp->rc4_key_len, rdp))
|
||||
return FALSE;
|
||||
crypto_rc4_free(rdp->rc4_decrypt_key);
|
||||
rdp->rc4_decrypt_key = crypto_rc4_init(rdp->decrypt_key, rdp->rc4_key_len);
|
||||
if (!rdp->rc4_decrypt_key)
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate rc4 decrypt key");
|
||||
if (!winpr_RC4_Final(rdp->rc4_decrypt_key))
|
||||
return FALSE;
|
||||
if (!winpr_RC4_Init(rdp->rc4_decrypt_key, rdp->decrypt_key, rdp->rc4_key_len))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
rdp->decrypt_use_count = 0;
|
||||
}
|
||||
crypto_rc4(rdp->rc4_decrypt_key, length, data, data);
|
||||
if (!winpr_RC4_Update(rdp->rc4_decrypt_key, length, data, data))
|
||||
return FALSE;
|
||||
rdp->decrypt_use_count += 1;
|
||||
rdp->decrypt_checksum_use_count++;
|
||||
return TRUE;
|
||||
@ -627,17 +625,20 @@ BOOL security_decrypt(BYTE* data, int length, rdpRdp* rdp)
|
||||
|
||||
BOOL security_hmac_signature(const BYTE* data, int length, BYTE* output, rdpRdp* rdp)
|
||||
{
|
||||
BYTE buf[20];
|
||||
BYTE buf[WINPR_SHA1_DIGEST_LENGTH];
|
||||
BYTE use_count_le[4];
|
||||
|
||||
security_UINT32_le(use_count_le, rdp->encrypt_use_count);
|
||||
|
||||
if (!crypto_hmac_sha1_init(rdp->fips_hmac, rdp->fips_sign_key, 20))
|
||||
if (!winpr_HMAC_Init(rdp->fips_hmac, WINPR_MD_SHA1,
|
||||
rdp->fips_sign_key, WINPR_SHA1_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Update(rdp->fips_hmac, data, length))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Update(rdp->fips_hmac, use_count_le, 4))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Final(rdp->fips_hmac, buf, WINPR_SHA1_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
|
||||
crypto_hmac_update(rdp->fips_hmac, data, length);
|
||||
crypto_hmac_update(rdp->fips_hmac, use_count_le, 4);
|
||||
crypto_hmac_final(rdp->fips_hmac, buf, 20);
|
||||
|
||||
memmove(output, buf, 8);
|
||||
return TRUE;
|
||||
@ -658,16 +659,20 @@ BOOL security_fips_decrypt(BYTE* data, int length, rdpRdp* rdp)
|
||||
|
||||
BOOL security_fips_check_signature(const BYTE* data, int length, const BYTE* sig, rdpRdp* rdp)
|
||||
{
|
||||
BYTE buf[20];
|
||||
BYTE buf[WINPR_SHA1_DIGEST_LENGTH];
|
||||
BYTE use_count_le[4];
|
||||
|
||||
security_UINT32_le(use_count_le, rdp->decrypt_use_count);
|
||||
|
||||
if (!crypto_hmac_sha1_init(rdp->fips_hmac, rdp->fips_sign_key, 20))
|
||||
if (!winpr_HMAC_Init(rdp->fips_hmac, WINPR_MD_SHA1,
|
||||
rdp->fips_sign_key, WINPR_SHA1_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Update(rdp->fips_hmac, data, length))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Update(rdp->fips_hmac, use_count_le, 4))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Final(rdp->fips_hmac, buf, WINPR_SHA1_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
crypto_hmac_update(rdp->fips_hmac, data, length);
|
||||
crypto_hmac_update(rdp->fips_hmac, use_count_le, 4);
|
||||
crypto_hmac_final(rdp->fips_hmac, buf, 20);
|
||||
|
||||
rdp->decrypt_use_count++;
|
||||
|
||||
|
@ -22,71 +22,13 @@
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/crypto.h>
|
||||
|
||||
#include <freerdp/log.h>
|
||||
#include <freerdp/crypto/crypto.h>
|
||||
|
||||
#define TAG FREERDP_TAG("crypto")
|
||||
|
||||
CryptoSha1 crypto_sha1_init(void)
|
||||
{
|
||||
CryptoSha1 sha1 = malloc(sizeof(*sha1));
|
||||
if (!sha1)
|
||||
return NULL;
|
||||
SHA1_Init(&sha1->sha_ctx);
|
||||
return sha1;
|
||||
}
|
||||
|
||||
void crypto_sha1_update(CryptoSha1 sha1, const BYTE* data, UINT32 length)
|
||||
{
|
||||
SHA1_Update(&sha1->sha_ctx, data, length);
|
||||
}
|
||||
|
||||
void crypto_sha1_final(CryptoSha1 sha1, BYTE* out_data)
|
||||
{
|
||||
SHA1_Final(out_data, &sha1->sha_ctx);
|
||||
free(sha1);
|
||||
}
|
||||
|
||||
CryptoMd5 crypto_md5_init(void)
|
||||
{
|
||||
CryptoMd5 md5 = malloc(sizeof(*md5));
|
||||
if (!md5)
|
||||
return NULL;
|
||||
MD5_Init(&md5->md5_ctx);
|
||||
return md5;
|
||||
}
|
||||
|
||||
void crypto_md5_update(CryptoMd5 md5, const BYTE* data, UINT32 length)
|
||||
{
|
||||
MD5_Update(&md5->md5_ctx, data, length);
|
||||
}
|
||||
|
||||
void crypto_md5_final(CryptoMd5 md5, BYTE* out_data)
|
||||
{
|
||||
MD5_Final(out_data, &md5->md5_ctx);
|
||||
free(md5);
|
||||
}
|
||||
|
||||
CryptoRc4 crypto_rc4_init(const BYTE* key, UINT32 length)
|
||||
{
|
||||
CryptoRc4 rc4 = malloc(sizeof(*rc4));
|
||||
if (!rc4)
|
||||
return NULL;
|
||||
RC4_set_key(&rc4->rc4_key, length, key);
|
||||
return rc4;
|
||||
}
|
||||
|
||||
void crypto_rc4(CryptoRc4 rc4, UINT32 length, const BYTE* in_data, BYTE* out_data)
|
||||
{
|
||||
RC4(&rc4->rc4_key, length, in_data, out_data);
|
||||
}
|
||||
|
||||
void crypto_rc4_free(CryptoRc4 rc4)
|
||||
{
|
||||
free(rc4);
|
||||
}
|
||||
|
||||
CryptoDes3 crypto_des3_encrypt_init(const BYTE* key, const BYTE* ivec)
|
||||
{
|
||||
CryptoDes3 des3 = malloc(sizeof(*des3));
|
||||
@ -135,55 +77,6 @@ void crypto_des3_free(CryptoDes3 des3)
|
||||
free(des3);
|
||||
}
|
||||
|
||||
CryptoHmac crypto_hmac_new(void)
|
||||
{
|
||||
CryptoHmac hmac = malloc(sizeof(*hmac));
|
||||
if (!hmac)
|
||||
return NULL;
|
||||
|
||||
HMAC_CTX_init(&hmac->hmac_ctx);
|
||||
return hmac;
|
||||
}
|
||||
|
||||
BOOL crypto_hmac_sha1_init(CryptoHmac hmac, const BYTE* data, UINT32 length)
|
||||
{
|
||||
#if (OPENSSL_VERSION_NUMBER >= 0x00909000)
|
||||
return HMAC_Init_ex(&hmac->hmac_ctx, data, length, EVP_sha1(), NULL) == 1;
|
||||
#else
|
||||
HMAC_Init_ex(&hmac->hmac_ctx, data, length, EVP_sha1(), NULL);
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOL crypto_hmac_md5_init(CryptoHmac hmac, const BYTE* data, UINT32 length)
|
||||
{
|
||||
#if (OPENSSL_VERSION_NUMBER >= 0x00909000)
|
||||
return HMAC_Init_ex(&hmac->hmac_ctx, data, length, EVP_md5(), NULL) == 1;
|
||||
#else
|
||||
HMAC_Init_ex(&hmac->hmac_ctx, data, length, EVP_md5(), NULL);
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
void crypto_hmac_update(CryptoHmac hmac, const BYTE* data, UINT32 length)
|
||||
{
|
||||
HMAC_Update(&hmac->hmac_ctx, data, length);
|
||||
}
|
||||
|
||||
void crypto_hmac_final(CryptoHmac hmac, BYTE* out_data, UINT32 length)
|
||||
{
|
||||
HMAC_Final(&hmac->hmac_ctx, out_data, &length);
|
||||
}
|
||||
|
||||
void crypto_hmac_free(CryptoHmac hmac)
|
||||
{
|
||||
if (hmac == NULL)
|
||||
return;
|
||||
|
||||
HMAC_CTX_cleanup(&hmac->hmac_ctx);
|
||||
free(hmac);
|
||||
}
|
||||
|
||||
CryptoCert crypto_cert_read(BYTE* data, UINT32 length)
|
||||
{
|
||||
CryptoCert cert = malloc(sizeof(*cert));
|
||||
@ -349,7 +242,7 @@ void crypto_reverse(BYTE* data, int length)
|
||||
|
||||
void crypto_nonce(BYTE* nonce, int size)
|
||||
{
|
||||
RAND_bytes((void*) nonce, size);
|
||||
winpr_RAND((void*) nonce, size);
|
||||
}
|
||||
|
||||
char* crypto_cert_fingerprint(X509* xcert)
|
||||
|
@ -642,14 +642,16 @@ union _WINPR_MD5_CTX
|
||||
};
|
||||
typedef union _WINPR_MD5_CTX WINPR_MD5_CTX;
|
||||
|
||||
#define WINPR_MD5_DIGEST_LENGTH 16
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WINPR_API void winpr_MD5_Init(WINPR_MD5_CTX* ctx);
|
||||
WINPR_API void winpr_MD5_Update(WINPR_MD5_CTX* ctx, const BYTE* input, size_t ilen);
|
||||
WINPR_API void winpr_MD5_Final(WINPR_MD5_CTX* ctx, BYTE* output);
|
||||
WINPR_API void winpr_MD5(const BYTE* input, size_t ilen, BYTE* output);
|
||||
WINPR_API BOOL winpr_MD5_Init(WINPR_MD5_CTX* ctx);
|
||||
WINPR_API BOOL winpr_MD5_Update(WINPR_MD5_CTX* ctx, const BYTE* input, size_t ilen);
|
||||
WINPR_API BOOL winpr_MD5_Final(WINPR_MD5_CTX* ctx, BYTE* output, size_t ilen);
|
||||
WINPR_API BOOL winpr_MD5(const BYTE* input, size_t ilen, BYTE* output, size_t olen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -683,14 +685,16 @@ union _WINPR_MD4_CTX
|
||||
};
|
||||
typedef union _WINPR_MD4_CTX WINPR_MD4_CTX;
|
||||
|
||||
#define WINPR_MD4_DIGEST_LENGTH 16
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WINPR_API void winpr_MD4_Init(WINPR_MD4_CTX* ctx);
|
||||
WINPR_API void winpr_MD4_Update(WINPR_MD4_CTX* ctx, const BYTE* input, size_t ilen);
|
||||
WINPR_API void winpr_MD4_Final(WINPR_MD4_CTX* ctx, BYTE* output);
|
||||
WINPR_API void winpr_MD4(const BYTE* input, size_t ilen, BYTE* output);
|
||||
WINPR_API BOOL winpr_MD4_Init(WINPR_MD4_CTX* ctx);
|
||||
WINPR_API BOOL winpr_MD4_Update(WINPR_MD4_CTX* ctx, const BYTE* input, size_t ilen);
|
||||
WINPR_API BOOL winpr_MD4_Final(WINPR_MD4_CTX* ctx, BYTE* output, size_t ilen);
|
||||
WINPR_API BOOL winpr_MD4(const BYTE* input, size_t ilen, BYTE* output, size_t olen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -700,6 +704,8 @@ WINPR_API void winpr_MD4(const BYTE* input, size_t ilen, BYTE* output);
|
||||
* SHA1 Hashing
|
||||
*/
|
||||
|
||||
#define WINPR_SHA1_DIGEST_LENGTH 20
|
||||
|
||||
struct _OPENSSL_SHA1_CTX
|
||||
{
|
||||
UINT32 h0, h1, h2, h3, h4;
|
||||
@ -728,10 +734,10 @@ typedef union _WINPR_SHA1_CTX WINPR_SHA1_CTX;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WINPR_API void winpr_SHA1_Init(WINPR_SHA1_CTX* ctx);
|
||||
WINPR_API void winpr_SHA1_Update(WINPR_SHA1_CTX* ctx, const BYTE* input, size_t ilen);
|
||||
WINPR_API void winpr_SHA1_Final(WINPR_SHA1_CTX* ctx, BYTE* output);
|
||||
WINPR_API void winpr_SHA1(const BYTE* input, size_t ilen, BYTE* output);
|
||||
WINPR_API BOOL winpr_SHA1_Init(WINPR_SHA1_CTX* ctx);
|
||||
WINPR_API BOOL winpr_SHA1_Update(WINPR_SHA1_CTX* ctx, const BYTE* input, size_t ilen);
|
||||
WINPR_API BOOL winpr_SHA1_Final(WINPR_SHA1_CTX* ctx, BYTE* output, size_t ilen);
|
||||
WINPR_API BOOL winpr_SHA1(const BYTE* input, size_t ilen, BYTE* output, size_t olen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -740,17 +746,19 @@ WINPR_API void winpr_SHA1(const BYTE* input, size_t ilen, BYTE* output);
|
||||
/**
|
||||
* HMAC
|
||||
*/
|
||||
|
||||
#define WINPR_MD_NONE 0
|
||||
#define WINPR_MD_MD2 1
|
||||
#define WINPR_MD_MD4 2
|
||||
#define WINPR_MD_MD5 3
|
||||
#define WINPR_MD_SHA1 4
|
||||
#define WINPR_MD_SHA224 5
|
||||
#define WINPR_MD_SHA256 6
|
||||
#define WINPR_MD_SHA384 7
|
||||
#define WINPR_MD_SHA512 8
|
||||
#define WINPR_MD_RIPEMD160 9
|
||||
typedef enum
|
||||
{
|
||||
WINPR_MD_NONE = 0,
|
||||
WINPR_MD_MD2 = 1,
|
||||
WINPR_MD_MD4 = 2,
|
||||
WINPR_MD_MD5 = 3,
|
||||
WINPR_MD_SHA1 = 4,
|
||||
WINPR_MD_SHA224 = 5,
|
||||
WINPR_MD_SHA256 = 6,
|
||||
WINPR_MD_SHA384 = 7,
|
||||
WINPR_MD_SHA512 = 8,
|
||||
WINPR_MD_RIPEMD160 = 9
|
||||
} WINPR_MD_TYPE;
|
||||
|
||||
struct _OPENSSL_EVP_MD_CTX
|
||||
{
|
||||
@ -793,10 +801,11 @@ typedef union _WINPR_HMAC_CTX WINPR_HMAC_CTX;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WINPR_API int winpr_HMAC_Init(WINPR_HMAC_CTX* ctx, int md, const BYTE* key, size_t keylen);
|
||||
WINPR_API int winpr_HMAC_Update(WINPR_HMAC_CTX* ctx, const BYTE* input, size_t ilen);
|
||||
WINPR_API int winpr_HMAC_Final(WINPR_HMAC_CTX* ctx, BYTE* output);
|
||||
WINPR_API int winpr_HMAC(int md, const BYTE* key, size_t keylen, const BYTE* input, size_t ilen, BYTE* output);
|
||||
WINPR_API BOOL winpr_HMAC_Init(WINPR_HMAC_CTX* ctx, WINPR_MD_TYPE md, const BYTE* key, size_t keylen);
|
||||
WINPR_API BOOL winpr_HMAC_Update(WINPR_HMAC_CTX* ctx, const BYTE* input, size_t ilen);
|
||||
WINPR_API BOOL winpr_HMAC_Final(WINPR_HMAC_CTX* ctx, BYTE* output, size_t ilen);
|
||||
WINPR_API BOOL winpr_HMAC(WINPR_MD_TYPE md, const BYTE* key, size_t keylen,
|
||||
const BYTE* input, size_t ilen, BYTE* output, size_t olen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -838,10 +847,10 @@ typedef union _WINPR_DIGEST_CTX WINPR_DIGEST_CTX;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WINPR_API int winpr_Digest_Init(WINPR_DIGEST_CTX* ctx, int md);
|
||||
WINPR_API int winpr_Digest_Update(WINPR_DIGEST_CTX* ctx, const BYTE* input, size_t ilen);
|
||||
WINPR_API int winpr_Digest_Final(WINPR_DIGEST_CTX* ctx, BYTE* output);
|
||||
WINPR_API int winpr_Digest(int md, const BYTE* input, size_t ilen, BYTE* output);
|
||||
WINPR_API BOOL winpr_Digest_Init(WINPR_DIGEST_CTX* ctx, WINPR_MD_TYPE md);
|
||||
WINPR_API BOOL winpr_Digest_Update(WINPR_DIGEST_CTX* ctx, const BYTE* input, size_t ilen);
|
||||
WINPR_API BOOL winpr_Digest_Final(WINPR_DIGEST_CTX* ctx, BYTE* output, size_t ilen);
|
||||
WINPR_API BOOL winpr_Digest(int md, const BYTE* input, size_t ilen, BYTE* output, size_t olen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -892,9 +901,9 @@ typedef union _WINPR_RC4_CTX WINPR_RC4_CTX;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WINPR_API void winpr_RC4_Init(WINPR_RC4_CTX* ctx, const BYTE* key, size_t keylen);
|
||||
WINPR_API int winpr_RC4_Update(WINPR_RC4_CTX* ctx, size_t length, const BYTE* input, BYTE* output);
|
||||
WINPR_API void winpr_RC4_Final(WINPR_RC4_CTX* ctx);
|
||||
WINPR_API BOOL winpr_RC4_Init(WINPR_RC4_CTX* ctx, const BYTE* key, size_t keylen);
|
||||
WINPR_API BOOL winpr_RC4_Update(WINPR_RC4_CTX* ctx, size_t length, const BYTE* input, BYTE* output);
|
||||
WINPR_API BOOL winpr_RC4_Final(WINPR_RC4_CTX* ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -1007,9 +1016,9 @@ typedef union _WINPR_CIPHER_CTX WINPR_CIPHER_CTX;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WINPR_API int winpr_Cipher_Init(WINPR_CIPHER_CTX* ctx, int cipher, int op, const BYTE* key, const BYTE* iv);
|
||||
WINPR_API int winpr_Cipher_Update(WINPR_CIPHER_CTX* ctx, const BYTE* input, size_t ilen, BYTE* output, size_t* olen);
|
||||
WINPR_API int winpr_Cipher_Final(WINPR_CIPHER_CTX* ctx, BYTE* output, size_t* olen);
|
||||
WINPR_API BOOL winpr_Cipher_Init(WINPR_CIPHER_CTX* ctx, int cipher, int op, const BYTE* key, const BYTE* iv);
|
||||
WINPR_API BOOL winpr_Cipher_Update(WINPR_CIPHER_CTX* ctx, const BYTE* input, size_t ilen, BYTE* output, size_t* olen);
|
||||
WINPR_API BOOL winpr_Cipher_Final(WINPR_CIPHER_CTX* ctx, BYTE* output, size_t* olen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -43,7 +43,7 @@
|
||||
* RC4
|
||||
*/
|
||||
|
||||
void winpr_RC4_Init(WINPR_RC4_CTX* ctx, const BYTE* key, size_t keylen)
|
||||
BOOL winpr_RC4_Init(WINPR_RC4_CTX* ctx, const BYTE* key, size_t keylen)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
RC4_set_key((RC4_KEY*) ctx, keylen, key);
|
||||
@ -51,25 +51,29 @@ void winpr_RC4_Init(WINPR_RC4_CTX* ctx, const BYTE* key, size_t keylen)
|
||||
mbedtls_arc4_init((mbedtls_arc4_context*) ctx);
|
||||
mbedtls_arc4_setup((mbedtls_arc4_context*) ctx, key, keylen);
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int winpr_RC4_Update(WINPR_RC4_CTX* ctx, size_t length, const BYTE* input, BYTE* output)
|
||||
BOOL winpr_RC4_Update(WINPR_RC4_CTX* ctx, size_t length, const BYTE* input, BYTE* output)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
RC4((RC4_KEY*) ctx, length, input, output);
|
||||
return 0;
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_ARC4_C)
|
||||
return mbedtls_arc4_crypt((mbedtls_arc4_context*) ctx, length, input, output);
|
||||
if (mbedtls_arc4_crypt((mbedtls_arc4_context*) ctx, length, input, output) != 0)
|
||||
return FALSE;
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void winpr_RC4_Final(WINPR_RC4_CTX* ctx)
|
||||
BOOL winpr_RC4_Final(WINPR_RC4_CTX* ctx)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_ARC4_C)
|
||||
mbedtls_arc4_free((mbedtls_arc4_context*) ctx);
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -496,7 +500,7 @@ mbedtls_cipher_type_t winpr_mbedtls_get_cipher_type(int cipher)
|
||||
}
|
||||
#endif
|
||||
|
||||
int winpr_Cipher_Init(WINPR_CIPHER_CTX* ctx, int cipher, int op, const BYTE* key, const BYTE* iv)
|
||||
BOOL winpr_Cipher_Init(WINPR_CIPHER_CTX* ctx, int cipher, int op, const BYTE* key, const BYTE* iv)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
int operation;
|
||||
@ -504,13 +508,13 @@ int winpr_Cipher_Init(WINPR_CIPHER_CTX* ctx, int cipher, int op, const BYTE* key
|
||||
evp = winpr_openssl_get_evp_cipher(cipher);
|
||||
|
||||
if (!evp)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
operation = (op == WINPR_ENCRYPT) ? 1 : 0;
|
||||
EVP_CIPHER_CTX_init((EVP_CIPHER_CTX*) ctx);
|
||||
|
||||
if (EVP_CipherInit_ex((EVP_CIPHER_CTX*) ctx, evp, NULL, key, iv, operation) != 1)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS)
|
||||
int key_bitlen;
|
||||
mbedtls_operation_t operation;
|
||||
@ -520,55 +524,55 @@ int winpr_Cipher_Init(WINPR_CIPHER_CTX* ctx, int cipher, int op, const BYTE* key
|
||||
cipher_info = mbedtls_cipher_info_from_type(cipher_type);
|
||||
|
||||
if (!cipher_info)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
operation = (op == WINPR_ENCRYPT) ? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT;
|
||||
mbedtls_cipher_init((mbedtls_cipher_context_t*) ctx);
|
||||
|
||||
if (mbedtls_cipher_setup((mbedtls_cipher_context_t*) ctx, cipher_info) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
key_bitlen = mbedtls_cipher_get_key_bitlen((mbedtls_cipher_context_t*) ctx);
|
||||
|
||||
if (mbedtls_cipher_setkey((mbedtls_cipher_context_t*) ctx, key, key_bitlen, operation) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#endif
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int winpr_Cipher_Update(WINPR_CIPHER_CTX* ctx, const BYTE* input, size_t ilen, BYTE* output, size_t* olen)
|
||||
BOOL winpr_Cipher_Update(WINPR_CIPHER_CTX* ctx, const BYTE* input, size_t ilen, BYTE* output, size_t* olen)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
int outl = (int) *olen;
|
||||
|
||||
if (EVP_CipherUpdate((EVP_CIPHER_CTX*) ctx, output, &outl, input, ilen) != 1)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
*olen = (size_t) outl;
|
||||
#elif defined(WITH_MBEDTLS)
|
||||
if (mbedtls_cipher_update((mbedtls_cipher_context_t*) ctx, input, ilen, output, olen) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#endif
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int winpr_Cipher_Final(WINPR_CIPHER_CTX* ctx, BYTE* output, size_t* olen)
|
||||
BOOL winpr_Cipher_Final(WINPR_CIPHER_CTX* ctx, BYTE* output, size_t* olen)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
int outl = (int) *olen;
|
||||
|
||||
if (EVP_CipherFinal_ex((EVP_CIPHER_CTX*) ctx, output, &outl) != 1)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
EVP_CIPHER_CTX_cleanup((EVP_CIPHER_CTX*) ctx);
|
||||
*olen = (size_t) outl;
|
||||
#elif defined(WITH_MBEDTLS)
|
||||
if (mbedtls_cipher_finish((mbedtls_cipher_context_t*) ctx, output, olen) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
mbedtls_cipher_free((mbedtls_cipher_context_t*) ctx);
|
||||
#endif
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,123 +43,167 @@
|
||||
* MD5
|
||||
*/
|
||||
|
||||
void winpr_MD5_Init(WINPR_MD5_CTX* ctx)
|
||||
BOOL winpr_MD5_Init(WINPR_MD5_CTX* ctx)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
MD5_Init((MD5_CTX*) ctx);
|
||||
if (MD5_Init((MD5_CTX*) ctx) != 1)
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_MD5_C)
|
||||
mbedtls_md5_init((mbedtls_md5_context*) ctx);
|
||||
mbedtls_md5_starts((mbedtls_md5_context*) ctx);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void winpr_MD5_Update(WINPR_MD5_CTX* ctx, const BYTE* input, size_t ilen)
|
||||
BOOL winpr_MD5_Update(WINPR_MD5_CTX* ctx, const BYTE* input, size_t ilen)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
MD5_Update((MD5_CTX*) ctx, input, ilen);
|
||||
if (MD5_Update((MD5_CTX*) ctx, input, ilen) != 1)
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_MD5_C)
|
||||
mbedtls_md5_update((mbedtls_md5_context*) ctx, input, ilen);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void winpr_MD5_Final(WINPR_MD5_CTX* ctx, BYTE* output)
|
||||
BOOL winpr_MD5_Final(WINPR_MD5_CTX* ctx, BYTE* output, size_t ilen)
|
||||
{
|
||||
if (ilen < WINPR_MD5_DIGEST_LENGTH)
|
||||
return FALSE;
|
||||
|
||||
#if defined(WITH_OPENSSL)
|
||||
MD5_Final(output, (MD5_CTX*) ctx);
|
||||
if (MD5_Final(output, (MD5_CTX*) ctx) != 1)
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_MD5_C)
|
||||
mbedtls_md5_finish((mbedtls_md5_context*) ctx, output);
|
||||
mbedtls_md5_free((mbedtls_md5_context*) ctx);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void winpr_MD5(const BYTE* input, size_t ilen, BYTE* output)
|
||||
BOOL winpr_MD5(const BYTE* input, size_t ilen, BYTE* output, size_t olen)
|
||||
{
|
||||
WINPR_MD5_CTX ctx;
|
||||
winpr_MD5_Init(&ctx);
|
||||
winpr_MD5_Update(&ctx, input, ilen);
|
||||
winpr_MD5_Final(&ctx, output);
|
||||
|
||||
if (!winpr_MD5_Init(&ctx))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&ctx, input, ilen))
|
||||
return FALSE;
|
||||
return winpr_MD5_Final(&ctx, output, olen);
|
||||
}
|
||||
|
||||
/**
|
||||
* MD4
|
||||
*/
|
||||
|
||||
void winpr_MD4_Init(WINPR_MD4_CTX* ctx)
|
||||
BOOL winpr_MD4_Init(WINPR_MD4_CTX* ctx)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
MD4_Init((MD4_CTX*) ctx);
|
||||
if (MD4_Init((MD4_CTX*) ctx) != 1)
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_MD4_C)
|
||||
mbedtls_md4_init((mbedtls_md4_context*) ctx);
|
||||
mbedtls_md4_starts((mbedtls_md4_context*) ctx);
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void winpr_MD4_Update(WINPR_MD4_CTX* ctx, const BYTE* input, size_t ilen)
|
||||
BOOL winpr_MD4_Update(WINPR_MD4_CTX* ctx, const BYTE* input, size_t ilen)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
MD4_Update((MD4_CTX*) ctx, input, ilen);
|
||||
if (MD4_Update((MD4_CTX*) ctx, input, ilen) != 1)
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_MD4_C)
|
||||
mbedtls_md4_update((mbedtls_md4_context*) ctx, input, ilen);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void winpr_MD4_Final(WINPR_MD4_CTX* ctx, BYTE* output)
|
||||
BOOL winpr_MD4_Final(WINPR_MD4_CTX* ctx, BYTE* output, size_t olen)
|
||||
{
|
||||
if (olen < WINPR_MD4_DIGEST_LENGTH)
|
||||
return FALSE;
|
||||
|
||||
#if defined(WITH_OPENSSL)
|
||||
MD4_Final(output, (MD4_CTX*) ctx);
|
||||
if (MD4_Final(output, (MD4_CTX*) ctx) != 1)
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_MD4_C)
|
||||
mbedtls_md4_finish((mbedtls_md4_context*) ctx, output);
|
||||
mbedtls_md4_free((mbedtls_md4_context*) ctx);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void winpr_MD4(const BYTE* input, size_t ilen, BYTE* output)
|
||||
BOOL winpr_MD4(const BYTE* input, size_t ilen, BYTE* output, size_t olen)
|
||||
{
|
||||
WINPR_MD4_CTX ctx;
|
||||
winpr_MD4_Init(&ctx);
|
||||
winpr_MD4_Update(&ctx, input, ilen);
|
||||
winpr_MD4_Final(&ctx, output);
|
||||
|
||||
if (!winpr_MD4_Init(&ctx))
|
||||
return FALSE;
|
||||
if (!winpr_MD4_Update(&ctx, input, ilen))
|
||||
return FALSE;
|
||||
return winpr_MD4_Final(&ctx, output, olen);
|
||||
}
|
||||
|
||||
/**
|
||||
* SHA1
|
||||
*/
|
||||
|
||||
void winpr_SHA1_Init(WINPR_SHA1_CTX* ctx)
|
||||
BOOL winpr_SHA1_Init(WINPR_SHA1_CTX* ctx)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
SHA1_Init((SHA_CTX*) ctx);
|
||||
if (SHA1_Init((SHA_CTX*) ctx) != 1)
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_SHA1_C)
|
||||
mbedtls_sha1_init((mbedtls_sha1_context*) ctx);
|
||||
mbedtls_sha1_starts((mbedtls_sha1_context*) ctx);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void winpr_SHA1_Update(WINPR_SHA1_CTX* ctx, const BYTE* input, size_t ilen)
|
||||
BOOL winpr_SHA1_Update(WINPR_SHA1_CTX* ctx, const BYTE* input, size_t ilen)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
SHA1_Update((SHA_CTX*) ctx, input, ilen);
|
||||
if (SHA1_Update((SHA_CTX*) ctx, input, ilen) != 1)
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_SHA1_C)
|
||||
mbedtls_sha1_update((mbedtls_sha1_context*) ctx, input, ilen);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void winpr_SHA1_Final(WINPR_SHA1_CTX* ctx, BYTE* output)
|
||||
BOOL winpr_SHA1_Final(WINPR_SHA1_CTX* ctx, BYTE* output, size_t olen)
|
||||
{
|
||||
if (olen < WINPR_SHA1_DIGEST_LENGTH)
|
||||
return FALSE;
|
||||
|
||||
#if defined(WITH_OPENSSL)
|
||||
SHA1_Final(output, (SHA_CTX*) ctx);
|
||||
if (SHA1_Final(output, (SHA_CTX*) ctx) != 1)
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_SHA1_C)
|
||||
mbedtls_sha1_finish((mbedtls_sha1_context*) ctx, output);
|
||||
mbedtls_sha1_free((mbedtls_sha1_context*) ctx);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void winpr_SHA1(const BYTE* input, size_t ilen, BYTE* output)
|
||||
BOOL winpr_SHA1(const BYTE* input, size_t ilen, BYTE* output, size_t olen)
|
||||
{
|
||||
WINPR_SHA1_CTX ctx;
|
||||
winpr_SHA1_Init(&ctx);
|
||||
winpr_SHA1_Update(&ctx, input, ilen);
|
||||
winpr_SHA1_Final(&ctx, output);
|
||||
|
||||
if (!winpr_SHA1_Init(&ctx))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&ctx, input, ilen))
|
||||
return FALSE;
|
||||
return winpr_SHA1_Final(&ctx, output, olen);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,13 +308,13 @@ mbedtls_md_type_t winpr_mbedtls_get_md_type(int md)
|
||||
}
|
||||
#endif
|
||||
|
||||
int winpr_HMAC_Init(WINPR_HMAC_CTX* ctx, int md, const BYTE* key, size_t keylen)
|
||||
BOOL winpr_HMAC_Init(WINPR_HMAC_CTX* ctx, WINPR_MD_TYPE md, const BYTE* key, size_t keylen)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
const EVP_MD* evp = winpr_openssl_get_evp_md(md);
|
||||
|
||||
if (!evp)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
HMAC_CTX_init((HMAC_CTX*) ctx);
|
||||
|
||||
@ -278,7 +322,7 @@ int winpr_HMAC_Init(WINPR_HMAC_CTX* ctx, int md, const BYTE* key, size_t keylen)
|
||||
HMAC_Init_ex((HMAC_CTX*) ctx, key, keylen, evp, NULL);
|
||||
#else
|
||||
if (HMAC_Init_ex((HMAC_CTX*) ctx, key, keylen, evp, NULL) != 1)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#endif
|
||||
|
||||
#elif defined(WITH_MBEDTLS)
|
||||
@ -287,143 +331,150 @@ int winpr_HMAC_Init(WINPR_HMAC_CTX* ctx, int md, const BYTE* key, size_t keylen)
|
||||
md_info = mbedtls_md_info_from_type(md_type);
|
||||
|
||||
if (!md_info)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
mbedtls_md_init((mbedtls_md_context_t*) ctx);
|
||||
|
||||
if (mbedtls_md_setup((mbedtls_md_context_t*) ctx, md_info, 1) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
if (mbedtls_md_hmac_starts((mbedtls_md_context_t*) ctx, key, keylen) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#endif
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int winpr_HMAC_Update(WINPR_HMAC_CTX* ctx, const BYTE* input, size_t ilen)
|
||||
BOOL winpr_HMAC_Update(WINPR_HMAC_CTX* ctx, const BYTE* input, size_t ilen)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
|
||||
HMAC_Update((HMAC_CTX*) ctx, input, ilen);
|
||||
#else
|
||||
if (HMAC_Update((HMAC_CTX*) ctx, input, ilen) != 1)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#endif
|
||||
#elif defined(WITH_MBEDTLS)
|
||||
if (mbedtls_md_hmac_update((mbedtls_md_context_t*) ctx, input, ilen) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#endif
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int winpr_HMAC_Final(WINPR_HMAC_CTX* ctx, BYTE* output)
|
||||
BOOL winpr_HMAC_Final(WINPR_HMAC_CTX* ctx, BYTE* output, size_t olen)
|
||||
{
|
||||
/* TODO
|
||||
if (olen < ctx->digestLength)
|
||||
return FALSE;
|
||||
*/
|
||||
|
||||
#if defined(WITH_OPENSSL)
|
||||
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
|
||||
HMAC_Final((HMAC_CTX*) ctx, output, NULL);
|
||||
#else
|
||||
if (HMAC_Final((HMAC_CTX*) ctx, output, NULL) != 1)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#endif
|
||||
HMAC_CTX_cleanup((HMAC_CTX*) ctx);
|
||||
#elif defined(WITH_MBEDTLS)
|
||||
if (mbedtls_md_hmac_finish((mbedtls_md_context_t*) ctx, output) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
mbedtls_md_free((mbedtls_md_context_t*) ctx);
|
||||
#endif
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int winpr_HMAC(int md, const BYTE* key, size_t keylen, const BYTE* input, size_t ilen, BYTE* output)
|
||||
BOOL winpr_HMAC(WINPR_MD_TYPE md, const BYTE* key, size_t keylen,
|
||||
const BYTE* input, size_t ilen, BYTE* output, size_t olen)
|
||||
{
|
||||
WINPR_HMAC_CTX ctx;
|
||||
|
||||
if (winpr_HMAC_Init(&ctx, md, key, keylen) != 0)
|
||||
return -1;
|
||||
if (!winpr_HMAC_Init(&ctx, md, key, keylen))
|
||||
return FALSE;
|
||||
|
||||
if (winpr_HMAC_Update(&ctx, input, ilen) != 0)
|
||||
return -1;
|
||||
if (!winpr_HMAC_Update(&ctx, input, ilen))
|
||||
return FALSE;
|
||||
|
||||
if (winpr_HMAC_Final(&ctx, output) != 0)
|
||||
return -1;
|
||||
if (!winpr_HMAC_Final(&ctx, output, olen))
|
||||
return FALSE;
|
||||
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic Digest API
|
||||
*/
|
||||
|
||||
int winpr_Digest_Init(WINPR_DIGEST_CTX* ctx, int md)
|
||||
BOOL winpr_Digest_Init(WINPR_DIGEST_CTX* ctx, WINPR_MD_TYPE md)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
const EVP_MD* evp = winpr_openssl_get_evp_md(md);
|
||||
|
||||
if (!evp)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
EVP_MD_CTX_init((EVP_MD_CTX*) ctx);
|
||||
|
||||
if (EVP_DigestInit_ex((EVP_MD_CTX*) ctx, evp, NULL) != 1)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS)
|
||||
const mbedtls_md_info_t* md_info;
|
||||
mbedtls_md_type_t md_type = winpr_mbedtls_get_md_type(md);
|
||||
md_info = mbedtls_md_info_from_type(md_type);
|
||||
|
||||
if (!md_info)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
mbedtls_md_init((mbedtls_md_context_t*) ctx);
|
||||
|
||||
if (mbedtls_md_setup((mbedtls_md_context_t*) ctx, md_info, 0) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
if (mbedtls_md_starts((mbedtls_md_context_t*) ctx) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#endif
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int winpr_Digest_Update(WINPR_DIGEST_CTX* ctx, const BYTE* input, size_t ilen)
|
||||
BOOL winpr_Digest_Update(WINPR_DIGEST_CTX* ctx, const BYTE* input, size_t ilen)
|
||||
{
|
||||
#if defined(WITH_OPENSSL)
|
||||
if (EVP_DigestUpdate((EVP_MD_CTX*) ctx, input, ilen) != 1)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS)
|
||||
if (mbedtls_md_update((mbedtls_md_context_t*) ctx, input, ilen) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#endif
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int winpr_Digest_Final(WINPR_DIGEST_CTX* ctx, BYTE* output)
|
||||
BOOL winpr_Digest_Final(WINPR_DIGEST_CTX* ctx, BYTE* output, size_t olen)
|
||||
{
|
||||
// TODO: output length check
|
||||
#if defined(WITH_OPENSSL)
|
||||
if (EVP_DigestFinal_ex((EVP_MD_CTX*) ctx, output, NULL) != 1)
|
||||
return -1;
|
||||
return FALSE;
|
||||
#elif defined(WITH_MBEDTLS)
|
||||
if (mbedtls_md_finish((mbedtls_md_context_t*) ctx, output) != 0)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
mbedtls_md_free((mbedtls_md_context_t*) ctx);
|
||||
#endif
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int winpr_Digest(int md, const BYTE* input, size_t ilen, BYTE* output)
|
||||
BOOL winpr_Digest(int md, const BYTE* input, size_t ilen, BYTE* output, size_t olen)
|
||||
{
|
||||
WINPR_DIGEST_CTX ctx;
|
||||
|
||||
if (winpr_Digest_Init(&ctx, md) != 0)
|
||||
return -1;
|
||||
if (!winpr_Digest_Init(&ctx, md))
|
||||
return FALSE;
|
||||
|
||||
if (winpr_Digest_Update(&ctx, input, ilen) != 0)
|
||||
return -1;
|
||||
if (!winpr_Digest_Update(&ctx, input, ilen))
|
||||
return FALSE;
|
||||
|
||||
if (winpr_Digest_Final(&ctx, output) != 0)
|
||||
return -1;
|
||||
if (!winpr_Digest_Final(&ctx, output, olen))
|
||||
return FALSE;
|
||||
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -8,20 +8,23 @@ static const BYTE* TEST_MD5_HASH = (BYTE*) "\x09\x8f\x6b\xcd\x46\x21\xd3\x73\xca
|
||||
|
||||
BOOL test_crypto_hash_md5()
|
||||
{
|
||||
BYTE hash[16];
|
||||
BYTE hash[WINPR_MD5_DIGEST_LENGTH];
|
||||
WINPR_MD5_CTX ctx;
|
||||
|
||||
winpr_MD5_Init(&ctx);
|
||||
winpr_MD5_Update(&ctx, (BYTE*) TEST_MD5_DATA, strlen(TEST_MD5_DATA));
|
||||
winpr_MD5_Final(&ctx, hash);
|
||||
if (!winpr_MD5_Init(&ctx))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Update(&ctx, (BYTE*) TEST_MD5_DATA, strlen(TEST_MD5_DATA)))
|
||||
return FALSE;
|
||||
if (!winpr_MD5_Final(&ctx, hash, sizeof(hash)))
|
||||
return FALSE;
|
||||
|
||||
if (memcmp(hash, TEST_MD5_HASH, 16) != 0)
|
||||
if (memcmp(hash, TEST_MD5_HASH, WINPR_MD5_DIGEST_LENGTH) != 0)
|
||||
{
|
||||
char* actual;
|
||||
char* expected;
|
||||
|
||||
actual = winpr_BinToHexString(hash, 16, FALSE);
|
||||
expected = winpr_BinToHexString(TEST_MD5_HASH, 16, FALSE);
|
||||
actual = winpr_BinToHexString(hash, WINPR_MD5_DIGEST_LENGTH, FALSE);
|
||||
expected = winpr_BinToHexString(TEST_MD5_HASH, WINPR_MD5_DIGEST_LENGTH, FALSE);
|
||||
|
||||
fprintf(stderr, "unexpected MD5 hash: Actual: %s Expected: %s\n", actual, expected);
|
||||
|
||||
@ -39,20 +42,23 @@ static const BYTE* TEST_MD4_HASH = (BYTE*) "\xdb\x34\x6d\x69\x1d\x7a\xcc\x4d\xc2
|
||||
|
||||
BOOL test_crypto_hash_md4()
|
||||
{
|
||||
BYTE hash[16];
|
||||
BYTE hash[WINPR_MD4_DIGEST_LENGTH];
|
||||
WINPR_MD4_CTX ctx;
|
||||
|
||||
winpr_MD4_Init(&ctx);
|
||||
winpr_MD4_Update(&ctx, (BYTE*) TEST_MD4_DATA, strlen(TEST_MD4_DATA));
|
||||
winpr_MD4_Final(&ctx, hash);
|
||||
if (!winpr_MD4_Init(&ctx))
|
||||
return FALSE;
|
||||
if (!winpr_MD4_Update(&ctx, (BYTE*) TEST_MD4_DATA, strlen(TEST_MD4_DATA)))
|
||||
return FALSE;
|
||||
if (!winpr_MD4_Final(&ctx, hash, sizeof(hash)))
|
||||
return FALSE;
|
||||
|
||||
if (memcmp(hash, TEST_MD4_HASH, 16) != 0)
|
||||
if (memcmp(hash, TEST_MD4_HASH, WINPR_MD4_DIGEST_LENGTH) != 0)
|
||||
{
|
||||
char* actual;
|
||||
char* expected;
|
||||
|
||||
actual = winpr_BinToHexString(hash, 16, FALSE);
|
||||
expected = winpr_BinToHexString(TEST_MD4_HASH, 16, FALSE);
|
||||
actual = winpr_BinToHexString(hash, WINPR_MD4_DIGEST_LENGTH, FALSE);
|
||||
expected = winpr_BinToHexString(TEST_MD4_HASH, WINPR_MD4_DIGEST_LENGTH, FALSE);
|
||||
|
||||
fprintf(stderr, "unexpected MD4 hash: Actual: %s Expected: %s\n", actual, expected);
|
||||
|
||||
@ -70,20 +76,23 @@ static const BYTE* TEST_SHA1_HASH = (BYTE*) "\xa9\x4a\x8f\xe5\xcc\xb1\x9b\xa6\x1
|
||||
|
||||
BOOL test_crypto_hash_sha1()
|
||||
{
|
||||
BYTE hash[20];
|
||||
BYTE hash[WINPR_SHA1_DIGEST_LENGTH];
|
||||
WINPR_SHA1_CTX ctx;
|
||||
|
||||
winpr_SHA1_Init(&ctx);
|
||||
winpr_SHA1_Update(&ctx, (BYTE*) TEST_SHA1_DATA, strlen(TEST_SHA1_DATA));
|
||||
winpr_SHA1_Final(&ctx, hash);
|
||||
if (!winpr_SHA1_Init(&ctx))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Update(&ctx, (BYTE*) TEST_SHA1_DATA, strlen(TEST_SHA1_DATA)))
|
||||
return FALSE;
|
||||
if (!winpr_SHA1_Final(&ctx, hash, sizeof(hash)))
|
||||
return FALSE;
|
||||
|
||||
if (memcmp(hash, TEST_SHA1_HASH, 20) != 0)
|
||||
if (memcmp(hash, TEST_SHA1_HASH, WINPR_MD5_DIGEST_LENGTH) != 0)
|
||||
{
|
||||
char* actual;
|
||||
char* expected;
|
||||
|
||||
actual = winpr_BinToHexString(hash, 20, FALSE);
|
||||
expected = winpr_BinToHexString(TEST_SHA1_HASH, 20, FALSE);
|
||||
actual = winpr_BinToHexString(hash, WINPR_MD5_DIGEST_LENGTH, FALSE);
|
||||
expected = winpr_BinToHexString(TEST_SHA1_HASH, WINPR_MD5_DIGEST_LENGTH, FALSE);
|
||||
|
||||
fprintf(stderr, "unexpected SHA1 hash: Actual: %s Expected: %s\n", actual, expected);
|
||||
|
||||
@ -102,20 +111,23 @@ static const BYTE* TEST_HMAC_MD5_HASH = (BYTE*) "\x92\x94\x72\x7a\x36\x38\xbb\x1
|
||||
|
||||
BOOL test_crypto_hash_hmac_md5()
|
||||
{
|
||||
BYTE hash[16];
|
||||
BYTE hash[WINPR_MD5_DIGEST_LENGTH];
|
||||
WINPR_HMAC_CTX ctx;
|
||||
|
||||
winpr_HMAC_Init(&ctx, WINPR_MD_MD5, TEST_HMAC_MD5_KEY, 16);
|
||||
winpr_HMAC_Update(&ctx, (BYTE*) TEST_HMAC_MD5_DATA, strlen(TEST_HMAC_MD5_DATA));
|
||||
winpr_HMAC_Final(&ctx, hash);
|
||||
if (!winpr_HMAC_Init(&ctx, WINPR_MD_MD5, TEST_HMAC_MD5_KEY, WINPR_SHA1_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Update(&ctx, (BYTE*) TEST_HMAC_MD5_DATA, strlen(TEST_HMAC_MD5_DATA)))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Final(&ctx, hash, sizeof(hash)))
|
||||
return FALSE;
|
||||
|
||||
if (memcmp(hash, TEST_HMAC_MD5_HASH, 16) != 0)
|
||||
if (memcmp(hash, TEST_HMAC_MD5_HASH, WINPR_SHA1_DIGEST_LENGTH) != 0)
|
||||
{
|
||||
char* actual;
|
||||
char* expected;
|
||||
|
||||
actual = winpr_BinToHexString(hash, 16, FALSE);
|
||||
expected = winpr_BinToHexString(TEST_HMAC_MD5_HASH, 16, FALSE);
|
||||
actual = winpr_BinToHexString(hash, WINPR_SHA1_DIGEST_LENGTH, FALSE);
|
||||
expected = winpr_BinToHexString(TEST_HMAC_MD5_HASH, WINPR_SHA1_DIGEST_LENGTH, FALSE);
|
||||
|
||||
fprintf(stderr, "unexpected HMAC-MD5 hash: Actual: %s Expected: %s\n", actual, expected);
|
||||
|
||||
@ -134,20 +146,23 @@ static const BYTE* TEST_HMAC_SHA1_HASH = (BYTE*) "\xb6\x17\x31\x86\x55\x05\x72\x
|
||||
|
||||
BOOL test_crypto_hash_hmac_sha1()
|
||||
{
|
||||
BYTE hash[20];
|
||||
BYTE hash[WINPR_SHA1_DIGEST_LENGTH];
|
||||
WINPR_HMAC_CTX ctx;
|
||||
|
||||
winpr_HMAC_Init(&ctx, WINPR_MD_SHA1, TEST_HMAC_SHA1_KEY, 20);
|
||||
winpr_HMAC_Update(&ctx, (BYTE*) TEST_HMAC_SHA1_DATA, strlen(TEST_HMAC_SHA1_DATA));
|
||||
winpr_HMAC_Final(&ctx, hash);
|
||||
if (!winpr_HMAC_Init(&ctx, WINPR_MD_SHA1, TEST_HMAC_SHA1_KEY, WINPR_SHA1_DIGEST_LENGTH))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Update(&ctx, (BYTE*) TEST_HMAC_SHA1_DATA, strlen(TEST_HMAC_SHA1_DATA)))
|
||||
return FALSE;
|
||||
if (!winpr_HMAC_Final(&ctx, hash, sizeof(hash)))
|
||||
return FALSE;
|
||||
|
||||
if (memcmp(hash, TEST_HMAC_SHA1_HASH, 20) != 0)
|
||||
if (memcmp(hash, TEST_HMAC_SHA1_HASH, WINPR_SHA1_DIGEST_LENGTH) != 0)
|
||||
{
|
||||
char* actual;
|
||||
char* expected;
|
||||
|
||||
actual = winpr_BinToHexString(hash, 20, FALSE);
|
||||
expected = winpr_BinToHexString(TEST_HMAC_SHA1_HASH, 20, FALSE);
|
||||
actual = winpr_BinToHexString(hash, WINPR_SHA1_DIGEST_LENGTH, FALSE);
|
||||
expected = winpr_BinToHexString(TEST_HMAC_SHA1_HASH, WINPR_SHA1_DIGEST_LENGTH, FALSE);
|
||||
|
||||
fprintf(stderr, "unexpected HMAC-SHA1 hash: Actual: %s Expected: %s\n", actual, expected);
|
||||
|
||||
|
@ -889,7 +889,7 @@ SECURITY_STATUS SEC_ENTRY ntlm_EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
|
||||
int length;
|
||||
void* data;
|
||||
UINT32 SeqNo;
|
||||
BYTE digest[16];
|
||||
BYTE digest[WINPR_MD5_DIGEST_LENGTH];
|
||||
BYTE checksum[8];
|
||||
BYTE* signature;
|
||||
ULONG version = 1;
|
||||
@ -923,10 +923,10 @@ SECURITY_STATUS SEC_ENTRY ntlm_EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
|
||||
|
||||
CopyMemory(data, data_buffer->pvBuffer, length);
|
||||
/* Compute the HMAC-MD5 hash of ConcatenationOf(seq_num,data) using the client signing key */
|
||||
winpr_HMAC_Init(&hmac, WINPR_MD_MD5, context->SendSigningKey, 16);
|
||||
winpr_HMAC_Init(&hmac, WINPR_MD_MD5, context->SendSigningKey, WINPR_MD5_DIGEST_LENGTH);
|
||||
winpr_HMAC_Update(&hmac, (void*) &(SeqNo), 4);
|
||||
winpr_HMAC_Update(&hmac, (void*) data, length);
|
||||
winpr_HMAC_Final(&hmac, digest);
|
||||
winpr_HMAC_Final(&hmac, digest, WINPR_MD5_DIGEST_LENGTH);
|
||||
|
||||
/* Encrypt message using with RC4, result overwrites original buffer */
|
||||
|
||||
@ -963,12 +963,12 @@ SECURITY_STATUS SEC_ENTRY ntlm_DecryptMessage(PCtxtHandle phContext, PSecBufferD
|
||||
int length;
|
||||
void* data;
|
||||
UINT32 SeqNo;
|
||||
BYTE digest[16];
|
||||
BYTE digest[WINPR_MD5_DIGEST_LENGTH];
|
||||
BYTE checksum[8];
|
||||
UINT32 version = 1;
|
||||
WINPR_HMAC_CTX hmac;
|
||||
NTLM_CONTEXT* context;
|
||||
BYTE expected_signature[16];
|
||||
BYTE expected_signature[WINPR_MD5_DIGEST_LENGTH];
|
||||
PSecBuffer data_buffer = NULL;
|
||||
PSecBuffer signature_buffer = NULL;
|
||||
SeqNo = (UINT32) MessageSeqNo;
|
||||
@ -1005,10 +1005,10 @@ SECURITY_STATUS SEC_ENTRY ntlm_DecryptMessage(PCtxtHandle phContext, PSecBufferD
|
||||
CopyMemory(data_buffer->pvBuffer, data, length);
|
||||
|
||||
/* Compute the HMAC-MD5 hash of ConcatenationOf(seq_num,data) using the client signing key */
|
||||
winpr_HMAC_Init(&hmac, WINPR_MD_MD5, context->RecvSigningKey, 16);
|
||||
winpr_HMAC_Init(&hmac, WINPR_MD_MD5, context->RecvSigningKey, WINPR_MD5_DIGEST_LENGTH);
|
||||
winpr_HMAC_Update(&hmac, (void*) &(SeqNo), 4);
|
||||
winpr_HMAC_Update(&hmac, (void*) data_buffer->pvBuffer, data_buffer->cbBuffer);
|
||||
winpr_HMAC_Final(&hmac, digest);
|
||||
winpr_HMAC_Final(&hmac, digest, WINPR_MD5_DIGEST_LENGTH);
|
||||
#ifdef WITH_DEBUG_NTLM
|
||||
WLog_DBG(TAG, "Encrypted Data Buffer (length = %d)", length);
|
||||
winpr_HexDump(TAG, WLOG_DEBUG, data, length);
|
||||
|
@ -260,7 +260,7 @@ void ntlm_compute_channel_bindings(NTLM_CONTEXT* context)
|
||||
UINT32 ChannelBindingTokenLength;
|
||||
SEC_CHANNEL_BINDINGS* ChannelBindings;
|
||||
|
||||
ZeroMemory(context->ChannelBindingsHash, 16);
|
||||
ZeroMemory(context->ChannelBindingsHash, WINPR_MD5_DIGEST_LENGTH);
|
||||
ChannelBindings = context->Bindings.Bindings;
|
||||
|
||||
if (!ChannelBindings)
|
||||
@ -275,7 +275,7 @@ void ntlm_compute_channel_bindings(NTLM_CONTEXT* context)
|
||||
ntlm_md5_update_uint32_be(&md5, ChannelBindings->cbAcceptorLength);
|
||||
ntlm_md5_update_uint32_be(&md5, ChannelBindings->cbApplicationDataLength);
|
||||
winpr_MD5_Update(&md5, (void*) ChannelBindingToken, ChannelBindingTokenLength);
|
||||
winpr_MD5_Final(&md5, context->ChannelBindingsHash);
|
||||
winpr_MD5_Final(&md5, context->ChannelBindingsHash, WINPR_MD5_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
void ntlm_compute_single_host_data(NTLM_CONTEXT* context)
|
||||
|
@ -315,7 +315,7 @@ int ntlm_compute_ntlm_v2_hash(NTLM_CONTEXT* context, BYTE* hash)
|
||||
int ntlm_compute_lm_v2_response(NTLM_CONTEXT* context)
|
||||
{
|
||||
BYTE* response;
|
||||
BYTE value[16];
|
||||
BYTE value[WINPR_MD5_DIGEST_LENGTH];
|
||||
|
||||
if (context->LmCompatibilityLevel < 2)
|
||||
{
|
||||
@ -340,7 +340,9 @@ int ntlm_compute_lm_v2_response(NTLM_CONTEXT* context)
|
||||
|
||||
response = (BYTE*) context->LmChallengeResponse.pvBuffer;
|
||||
/* Compute the HMAC-MD5 hash of the resulting value using the NTLMv2 hash as the key */
|
||||
winpr_HMAC(WINPR_MD_MD5, (void*) context->NtlmV2Hash, 16, (BYTE*) value, 16, (BYTE*) response);
|
||||
winpr_HMAC(WINPR_MD_MD5, (void*) context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH,
|
||||
(BYTE*) value, WINPR_MD5_DIGEST_LENGTH,
|
||||
(BYTE*) response, WINPR_MD5_DIGEST_LENGTH);
|
||||
/* Concatenate the resulting HMAC-MD5 hash and the client challenge, giving us the LMv2 response (24 bytes) */
|
||||
CopyMemory(&response[16], context->ClientChallenge, 8);
|
||||
return 1;
|
||||
@ -356,7 +358,7 @@ int ntlm_compute_lm_v2_response(NTLM_CONTEXT* context)
|
||||
int ntlm_compute_ntlm_v2_response(NTLM_CONTEXT* context)
|
||||
{
|
||||
BYTE* blob;
|
||||
BYTE nt_proof_str[16];
|
||||
BYTE nt_proof_str[WINPR_MD5_DIGEST_LENGTH];
|
||||
SecBuffer ntlm_v2_temp;
|
||||
SecBuffer ntlm_v2_temp_chal;
|
||||
PSecBuffer TargetInfo;
|
||||
@ -385,7 +387,7 @@ int ntlm_compute_ntlm_v2_response(NTLM_CONTEXT* context)
|
||||
WLog_DBG(TAG, "Workstation (length = %d)", context->Workstation.Length);
|
||||
winpr_HexDump(TAG, WLOG_DEBUG, (BYTE*) context->Workstation.Buffer, context->Workstation.Length);
|
||||
WLog_DBG(TAG, "NTOWFv2, NTLMv2 Hash");
|
||||
winpr_HexDump(TAG, WLOG_DEBUG, context->NtlmV2Hash, 16);
|
||||
winpr_HexDump(TAG, WLOG_DEBUG, context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH);
|
||||
#endif
|
||||
/* Construct temp */
|
||||
blob[0] = 1; /* RespType (1 byte) */
|
||||
@ -409,8 +411,9 @@ int ntlm_compute_ntlm_v2_response(NTLM_CONTEXT* context)
|
||||
blob = (BYTE*) ntlm_v2_temp_chal.pvBuffer;
|
||||
CopyMemory(blob, context->ServerChallenge, 8);
|
||||
CopyMemory(&blob[8], ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer);
|
||||
winpr_HMAC(WINPR_MD_MD5, (BYTE*) context->NtlmV2Hash, 16, (BYTE*) ntlm_v2_temp_chal.pvBuffer,
|
||||
ntlm_v2_temp_chal.cbBuffer, (BYTE*) nt_proof_str);
|
||||
winpr_HMAC(WINPR_MD_MD5, (BYTE*) context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH,
|
||||
(BYTE*) ntlm_v2_temp_chal.pvBuffer, ntlm_v2_temp_chal.cbBuffer,
|
||||
(BYTE*) nt_proof_str, WINPR_MD5_DIGEST_LENGTH);
|
||||
|
||||
/* NtChallengeResponse, Concatenate NTProofStr with temp */
|
||||
|
||||
@ -421,7 +424,9 @@ int ntlm_compute_ntlm_v2_response(NTLM_CONTEXT* context)
|
||||
CopyMemory(blob, nt_proof_str, 16);
|
||||
CopyMemory(&blob[16], ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer);
|
||||
/* Compute SessionBaseKey, the HMAC-MD5 hash of NTProofStr using the NTLMv2 hash as the key */
|
||||
winpr_HMAC(WINPR_MD_MD5, (BYTE*) context->NtlmV2Hash, 16, (BYTE*) nt_proof_str, 16, (BYTE*) context->SessionBaseKey);
|
||||
winpr_HMAC(WINPR_MD_MD5, (BYTE*) context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH,
|
||||
(BYTE*) nt_proof_str, WINPR_MD5_DIGEST_LENGTH,
|
||||
(BYTE*) context->SessionBaseKey, WINPR_MD5_DIGEST_LENGTH);
|
||||
sspi_SecBufferFree(&ntlm_v2_temp);
|
||||
sspi_SecBufferFree(&ntlm_v2_temp_chal);
|
||||
return 1;
|
||||
@ -544,18 +549,18 @@ int ntlm_generate_signing_key(BYTE* exported_session_key, PSecBuffer sign_magic,
|
||||
BYTE* value;
|
||||
WINPR_MD5_CTX md5;
|
||||
|
||||
length = 16 + sign_magic->cbBuffer;
|
||||
length = WINPR_MD5_DIGEST_LENGTH + sign_magic->cbBuffer;
|
||||
value = (BYTE*) malloc(length);
|
||||
|
||||
if (!value)
|
||||
return -1;
|
||||
|
||||
/* Concatenate ExportedSessionKey with sign magic */
|
||||
CopyMemory(value, exported_session_key, 16);
|
||||
CopyMemory(&value[16], sign_magic->pvBuffer, sign_magic->cbBuffer);
|
||||
CopyMemory(value, exported_session_key, WINPR_MD5_DIGEST_LENGTH);
|
||||
CopyMemory(&value[WINPR_MD5_DIGEST_LENGTH], sign_magic->pvBuffer, sign_magic->cbBuffer);
|
||||
winpr_MD5_Init(&md5);
|
||||
winpr_MD5_Update(&md5, value, length);
|
||||
winpr_MD5_Final(&md5, signing_key);
|
||||
winpr_MD5_Final(&md5, signing_key, WINPR_MD5_DIGEST_LENGTH);
|
||||
free(value);
|
||||
return 1;
|
||||
}
|
||||
@ -602,16 +607,16 @@ int ntlm_generate_sealing_key(BYTE* exported_session_key, PSecBuffer seal_magic,
|
||||
WINPR_MD5_CTX md5;
|
||||
SecBuffer buffer;
|
||||
|
||||
if (!sspi_SecBufferAlloc(&buffer, 16 + seal_magic->cbBuffer))
|
||||
if (!sspi_SecBufferAlloc(&buffer, WINPR_MD5_DIGEST_LENGTH + seal_magic->cbBuffer))
|
||||
return -1;
|
||||
|
||||
p = (BYTE*) buffer.pvBuffer;
|
||||
/* Concatenate ExportedSessionKey with seal magic */
|
||||
CopyMemory(p, exported_session_key, 16);
|
||||
CopyMemory(&p[16], seal_magic->pvBuffer, seal_magic->cbBuffer);
|
||||
CopyMemory(p, exported_session_key, WINPR_MD5_DIGEST_LENGTH);
|
||||
CopyMemory(&p[WINPR_MD5_DIGEST_LENGTH], seal_magic->pvBuffer, seal_magic->cbBuffer);
|
||||
winpr_MD5_Init(&md5);
|
||||
winpr_MD5_Update(&md5, buffer.pvBuffer, buffer.cbBuffer);
|
||||
winpr_MD5_Final(&md5, sealing_key);
|
||||
winpr_MD5_Final(&md5, sealing_key, WINPR_MD5_DIGEST_LENGTH);
|
||||
sspi_SecBufferFree(&buffer);
|
||||
return 1;
|
||||
}
|
||||
@ -679,9 +684,9 @@ void ntlm_compute_message_integrity_check(NTLM_CONTEXT* context)
|
||||
* CHALLENGE_MESSAGE, AUTHENTICATE_MESSAGE) using the ExportedSessionKey
|
||||
*/
|
||||
|
||||
winpr_HMAC_Init(&hmac, WINPR_MD_MD5, context->ExportedSessionKey, 16);
|
||||
winpr_HMAC_Init(&hmac, WINPR_MD_MD5, context->ExportedSessionKey, WINPR_MD5_DIGEST_LENGTH);
|
||||
winpr_HMAC_Update(&hmac, (BYTE*) context->NegotiateMessage.pvBuffer, context->NegotiateMessage.cbBuffer);
|
||||
winpr_HMAC_Update(&hmac, (BYTE*) context->ChallengeMessage.pvBuffer, context->ChallengeMessage.cbBuffer);
|
||||
winpr_HMAC_Update(&hmac, (BYTE*) context->AuthenticateMessage.pvBuffer, context->AuthenticateMessage.cbBuffer);
|
||||
winpr_HMAC_Final(&hmac, context->MessageIntegrityCheck);
|
||||
winpr_HMAC_Final(&hmac, context->MessageIntegrityCheck, WINPR_MD5_DIGEST_LENGTH);
|
||||
}
|
||||
|
@ -42,9 +42,12 @@ BYTE* NTOWFv1W(LPWSTR Password, UINT32 PasswordLength, BYTE* NtHash)
|
||||
if (!NtHash && !(NtHash = malloc(16)))
|
||||
return NULL;
|
||||
|
||||
winpr_MD4_Init(&md4);
|
||||
winpr_MD4_Update(&md4, (BYTE*) Password, (size_t) PasswordLength);
|
||||
winpr_MD4_Final(&md4, NtHash);
|
||||
if (!winpr_MD4_Init(&md4))
|
||||
return NULL;
|
||||
if (!winpr_MD4_Update(&md4, (BYTE*) Password, (size_t) PasswordLength))
|
||||
return NULL;
|
||||
if (!winpr_MD4_Final(&md4, NtHash, WINPR_MD4_DIGEST_LENGTH))
|
||||
return NULL;
|
||||
|
||||
return NtHash;
|
||||
}
|
||||
@ -77,11 +80,12 @@ BYTE* NTOWFv2W(LPWSTR Password, UINT32 PasswordLength, LPWSTR User,
|
||||
{
|
||||
BYTE* buffer;
|
||||
BYTE NtHashV1[16];
|
||||
BYTE* result = NtHash;
|
||||
|
||||
if ((!User) || (!Password))
|
||||
return NULL;
|
||||
|
||||
if (!NtHash && !(NtHash = (BYTE*) malloc(16)))
|
||||
if (!NtHash && !(NtHash = (BYTE*) malloc(WINPR_MD4_DIGEST_LENGTH)))
|
||||
return NULL;
|
||||
|
||||
if (!NTOWFv1W(Password, PasswordLength, NtHashV1))
|
||||
@ -103,11 +107,12 @@ BYTE* NTOWFv2W(LPWSTR Password, UINT32 PasswordLength, LPWSTR User,
|
||||
CopyMemory(&buffer[UserLength], Domain, DomainLength);
|
||||
|
||||
/* Compute the HMAC-MD5 hash of the above value using the NTLMv1 hash as the key, the result is the NTLMv2 hash */
|
||||
winpr_HMAC(WINPR_MD_MD5, NtHashV1, 16, buffer, UserLength + DomainLength, NtHash);
|
||||
if (!winpr_HMAC(WINPR_MD_MD5, NtHashV1, 16, buffer, UserLength + DomainLength, NtHash, WINPR_MD4_DIGEST_LENGTH))
|
||||
result = NULL;
|
||||
|
||||
free(buffer);
|
||||
|
||||
return NtHash;
|
||||
return result;
|
||||
}
|
||||
|
||||
BYTE* NTOWFv2A(LPSTR Password, UINT32 PasswordLength, LPSTR User,
|
||||
@ -141,11 +146,12 @@ out_fail:
|
||||
BYTE* NTOWFv2FromHashW(BYTE* NtHashV1, LPWSTR User, UINT32 UserLength, LPWSTR Domain, UINT32 DomainLength, BYTE* NtHash)
|
||||
{
|
||||
BYTE* buffer;
|
||||
BYTE* result = NtHash;
|
||||
|
||||
if (!User)
|
||||
return NULL;
|
||||
|
||||
if (!NtHash && !(NtHash = (BYTE*) malloc(16)))
|
||||
if (!NtHash && !(NtHash = (BYTE*) malloc(WINPR_MD4_DIGEST_LENGTH)))
|
||||
return NULL;
|
||||
|
||||
if (!(buffer = (BYTE*) malloc(UserLength + DomainLength)))
|
||||
@ -165,11 +171,12 @@ BYTE* NTOWFv2FromHashW(BYTE* NtHashV1, LPWSTR User, UINT32 UserLength, LPWSTR Do
|
||||
}
|
||||
|
||||
/* Compute the HMAC-MD5 hash of the above value using the NTLMv1 hash as the key, the result is the NTLMv2 hash */
|
||||
winpr_HMAC(WINPR_MD_MD5, NtHashV1, 16, buffer, UserLength + DomainLength, NtHash);
|
||||
if (!winpr_HMAC(WINPR_MD_MD5, NtHashV1, 16, buffer, UserLength + DomainLength, NtHash, WINPR_MD4_DIGEST_LENGTH))
|
||||
result = NULL;
|
||||
|
||||
free(buffer);
|
||||
|
||||
return NtHash;
|
||||
return result;
|
||||
}
|
||||
|
||||
BYTE* NTOWFv2FromHashA(BYTE* NtHashV1, LPSTR User, UINT32 UserLength, LPSTR Domain, UINT32 DomainLength, BYTE* NtHash)
|
||||
|
Loading…
x
Reference in New Issue
Block a user