2011-07-06 07:18:00 +04:00
|
|
|
/**
|
2012-02-21 09:56:55 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-06 07:18:00 +04:00
|
|
|
* Cryptographic Abstraction Layer
|
|
|
|
*
|
2012-02-21 09:56:55 +04:00
|
|
|
* Copyright 2011-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2011-07-06 07:18:00 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-02-21 09:56:55 +04:00
|
|
|
#ifndef FREERDP_CRYPTO_H
|
|
|
|
#define FREERDP_CRYPTO_H
|
2011-07-06 07:18:00 +04:00
|
|
|
|
2012-03-06 06:04:42 +04:00
|
|
|
/* OpenSSL includes windows.h */
|
2012-05-05 03:36:35 +04:00
|
|
|
#include <winpr/windows.h>
|
2012-03-06 06:04:42 +04:00
|
|
|
|
2011-07-06 07:18:00 +04:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#include <openssl/rc4.h>
|
|
|
|
#include <openssl/md5.h>
|
|
|
|
#include <openssl/sha.h>
|
2011-09-16 03:54:03 +04:00
|
|
|
#include <openssl/hmac.h>
|
2011-07-06 07:18:00 +04:00
|
|
|
#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
|
|
|
|
#else
|
|
|
|
#define D2I_X509_CONST
|
|
|
|
#endif
|
|
|
|
|
2011-07-15 09:11:09 +04:00
|
|
|
#define EXPONENT_MAX_SIZE 4
|
|
|
|
|
2012-02-21 09:56:55 +04:00
|
|
|
#include <freerdp/api.h>
|
2011-07-06 07:18:00 +04:00
|
|
|
#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;
|
|
|
|
};
|
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
struct crypto_des3_struct
|
|
|
|
{
|
|
|
|
EVP_CIPHER_CTX des3_ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct crypto_hmac_struct
|
|
|
|
{
|
|
|
|
HMAC_CTX hmac_ctx;
|
|
|
|
};
|
|
|
|
|
2011-07-06 07:18:00 +04:00
|
|
|
struct crypto_cert_struct
|
|
|
|
{
|
|
|
|
X509 * px509;
|
|
|
|
};
|
|
|
|
|
2012-01-19 07:33:38 +04:00
|
|
|
#define CRYPTO_SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
|
2011-07-07 19:27:24 +04:00
|
|
|
typedef struct crypto_sha1_struct* CryptoSha1;
|
2012-02-21 09:56:55 +04:00
|
|
|
|
|
|
|
FREERDP_API CryptoSha1 crypto_sha1_init(void);
|
2012-10-09 11:26:39 +04:00
|
|
|
FREERDP_API void crypto_sha1_update(CryptoSha1 sha1, const BYTE* data, UINT32 length);
|
2012-10-09 11:01:37 +04:00
|
|
|
FREERDP_API void crypto_sha1_final(CryptoSha1 sha1, BYTE* out_data);
|
2011-07-06 07:18:00 +04:00
|
|
|
|
2012-01-19 07:33:38 +04:00
|
|
|
#define CRYPTO_MD5_DIGEST_LENGTH MD5_DIGEST_LENGTH
|
2011-07-07 19:27:24 +04:00
|
|
|
typedef struct crypto_md5_struct* CryptoMd5;
|
2012-02-21 09:56:55 +04:00
|
|
|
|
|
|
|
FREERDP_API CryptoMd5 crypto_md5_init(void);
|
2012-10-09 11:26:39 +04:00
|
|
|
FREERDP_API void crypto_md5_update(CryptoMd5 md5, const BYTE* data, UINT32 length);
|
2012-10-09 11:01:37 +04:00
|
|
|
FREERDP_API void crypto_md5_final(CryptoMd5 md5, BYTE* out_data);
|
2011-07-06 07:18:00 +04:00
|
|
|
|
2011-07-07 19:27:24 +04:00
|
|
|
typedef struct crypto_rc4_struct* CryptoRc4;
|
2012-02-21 09:56:55 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
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);
|
2012-02-21 09:56:55 +04:00
|
|
|
FREERDP_API void crypto_rc4_free(CryptoRc4 rc4);
|
2011-07-06 07:18:00 +04:00
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
typedef struct crypto_des3_struct* CryptoDes3;
|
2012-02-21 09:56:55 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
FREERDP_API CryptoDes3 crypto_des3_encrypt_init(const BYTE* key, const BYTE* ivec);
|
|
|
|
FREERDP_API CryptoDes3 crypto_des3_decrypt_init(const BYTE* key, const BYTE* ivec);
|
2012-10-09 11:26:39 +04:00
|
|
|
FREERDP_API void crypto_des3_encrypt(CryptoDes3 des3, UINT32 length, const BYTE *in_data, BYTE *out_data);
|
|
|
|
FREERDP_API void crypto_des3_decrypt(CryptoDes3 des3, UINT32 length, const BYTE *in_data, BYTE* out_data);
|
2012-02-21 09:56:55 +04:00
|
|
|
FREERDP_API void crypto_des3_free(CryptoDes3 des3);
|
2011-09-16 03:54:03 +04:00
|
|
|
|
|
|
|
typedef struct crypto_hmac_struct* CryptoHmac;
|
2012-02-21 09:56:55 +04:00
|
|
|
|
|
|
|
FREERDP_API CryptoHmac crypto_hmac_new(void);
|
2012-10-09 11:26:39 +04:00
|
|
|
FREERDP_API void crypto_hmac_sha1_init(CryptoHmac hmac, const BYTE *data, UINT32 length);
|
2013-10-22 19:14:29 +04:00
|
|
|
FREERDP_API void crypto_hmac_md5_init(CryptoHmac hmac, const BYTE *data, UINT32 length);
|
2012-10-09 11:26:39 +04:00
|
|
|
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);
|
2012-02-21 09:56:55 +04:00
|
|
|
FREERDP_API void crypto_hmac_free(CryptoHmac hmac);
|
2011-09-16 03:54:03 +04:00
|
|
|
|
2011-07-07 19:27:24 +04:00
|
|
|
typedef struct crypto_cert_struct* CryptoCert;
|
2012-02-03 03:20:02 +04:00
|
|
|
|
2012-02-17 09:58:30 +04:00
|
|
|
#include <freerdp/crypto/certificate.h>
|
2012-02-03 03:20:02 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
FREERDP_API CryptoCert crypto_cert_read(BYTE* data, UINT32 length);
|
2012-02-21 09:56:55 +04:00
|
|
|
FREERDP_API char* crypto_cert_fingerprint(X509* xcert);
|
|
|
|
FREERDP_API char* crypto_cert_subject(X509* xcert);
|
|
|
|
FREERDP_API char* crypto_cert_subject_common_name(X509* xcert, int* length);
|
2013-09-02 18:14:22 +04:00
|
|
|
FREERDP_API char** crypto_cert_subject_alt_name(X509* xcert, int* count,
|
|
|
|
int** lengths);
|
|
|
|
FREERDP_API void crypto_cert_subject_alt_name_free(int count, int *lengths,
|
|
|
|
char** alt_name);
|
2012-02-21 09:56:55 +04:00
|
|
|
FREERDP_API char* crypto_cert_issuer(X509* xcert);
|
|
|
|
FREERDP_API void crypto_cert_print_info(X509* xcert);
|
|
|
|
FREERDP_API void crypto_cert_free(CryptoCert cert);
|
2012-02-03 03:20:02 +04:00
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
FREERDP_API BOOL x509_verify_certificate(CryptoCert cert, char* certificate_store_path);
|
2012-02-21 09:56:55 +04:00
|
|
|
FREERDP_API rdpCertificateData* crypto_get_certificate_data(X509* xcert, char* hostname);
|
2012-10-09 10:38:39 +04:00
|
|
|
FREERDP_API BOOL crypto_cert_get_public_key(CryptoCert cert, BYTE** PublicKey, DWORD* PublicKeyLength);
|
2011-07-07 19:27:24 +04:00
|
|
|
|
2012-01-19 07:39:31 +04:00
|
|
|
#define TSSK_KEY_LENGTH 64
|
2012-10-09 11:01:37 +04:00
|
|
|
extern const BYTE tssk_modulus[];
|
|
|
|
extern const BYTE tssk_privateExponent[];
|
|
|
|
extern const BYTE tssk_exponent[];
|
|
|
|
|
2013-08-08 02:28:31 +04:00
|
|
|
FREERDP_API int crypto_rsa_public_encrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* exponent, BYTE* output);
|
|
|
|
FREERDP_API int crypto_rsa_public_decrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* exponent, BYTE* output);
|
|
|
|
FREERDP_API int crypto_rsa_private_encrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* private_exponent, BYTE* output);
|
|
|
|
FREERDP_API int crypto_rsa_private_decrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* private_exponent, BYTE* output);
|
2012-10-09 11:01:37 +04:00
|
|
|
FREERDP_API void crypto_reverse(BYTE* data, int length);
|
|
|
|
FREERDP_API void crypto_nonce(BYTE* nonce, int size);
|
|
|
|
|
2014-05-10 00:36:50 +04:00
|
|
|
FREERDP_API char* crypto_base64_encode(const BYTE* data, int length);
|
2014-05-12 00:42:01 +04:00
|
|
|
FREERDP_API void crypto_base64_decode(const char* enc_data, int length, BYTE** dec_data, int* res_length);
|
2012-03-26 10:45:01 +04:00
|
|
|
|
2012-02-21 09:56:55 +04:00
|
|
|
#endif /* FREERDP_CRYPTO_H */
|