cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

crypto.h (4965B)


      1/**
      2 * FreeRDP: A Remote Desktop Protocol Implementation
      3 * Cryptographic Abstraction Layer
      4 *
      5 * Copyright 2011-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
      6 *
      7 * Licensed under the Apache License, Version 2.0 (the "License");
      8 * you may not use this file except in compliance with the License.
      9 * You may obtain a copy of the License at
     10 *
     11 *     http://www.apache.org/licenses/LICENSE-2.0
     12 *
     13 * Unless required by applicable law or agreed to in writing, software
     14 * distributed under the License is distributed on an "AS IS" BASIS,
     15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 * See the License for the specific language governing permissions and
     17 * limitations under the License.
     18 */
     19
     20#ifndef FREERDP_CRYPTO_H
     21#define FREERDP_CRYPTO_H
     22
     23/* OpenSSL includes windows.h */
     24#include <winpr/windows.h>
     25#include <winpr/custom-crypto.h>
     26
     27#include <openssl/ssl.h>
     28#include <openssl/err.h>
     29#include <openssl/bn.h>
     30#include <openssl/x509v3.h>
     31
     32#if OPENSSL_VERSION_NUMBER >= 0x0090800f
     33#define D2I_X509_CONST const
     34#else
     35#define D2I_X509_CONST
     36#endif
     37
     38#define EXPONENT_MAX_SIZE 4
     39
     40#include <freerdp/api.h>
     41#include <freerdp/freerdp.h>
     42#include <freerdp/crypto/certificate.h>
     43
     44struct crypto_cert_struct
     45{
     46	X509* px509;
     47	STACK_OF(X509) * px509chain;
     48};
     49
     50#ifdef __cplusplus
     51extern "C"
     52{
     53#endif
     54
     55	typedef struct crypto_cert_struct* CryptoCert;
     56
     57	FREERDP_API CryptoCert crypto_cert_read(BYTE* data, UINT32 length);
     58	FREERDP_API WINPR_MD_TYPE crypto_cert_get_signature_alg(X509* xcert);
     59	FREERDP_API BYTE* crypto_cert_hash(X509* xcert, const char* hash, UINT32* length);
     60	FREERDP_API char* crypto_cert_fingerprint_by_hash(X509* xcert, const char* hash);
     61	FREERDP_API char* crypto_cert_fingerprint(X509* xcert);
     62	FREERDP_API char* crypto_cert_subject(X509* xcert);
     63	FREERDP_API char* crypto_cert_subject_common_name(X509* xcert, int* length);
     64	FREERDP_API char** crypto_cert_get_dns_names(X509* xcert, int* count, int** lengths);
     65	FREERDP_API char* crypto_cert_get_email(X509* x509);
     66	FREERDP_API char* crypto_cert_get_upn(X509* x509);
     67	FREERDP_API void crypto_cert_dns_names_free(int count, int* lengths, char** dns_names);
     68	FREERDP_API char* crypto_cert_issuer(X509* xcert);
     69	FREERDP_API void crypto_cert_print_info(X509* xcert);
     70	FREERDP_API void crypto_cert_free(CryptoCert cert);
     71
     72#if !defined(DEFINE_NO_DEPRECATED)
     73	/*
     74	Deprecated function names: crypto_cert_subject_alt_name and crypto_cert_subject_alt_name_free.
     75	Use crypto_cert_get_dns_names and crypto_cert_dns_names_free instead.
     76	(old names kept for now for compatibility of FREERDP_API).
     77	Note: email and upn amongst others are also alt_names,
     78	but the old crypto_cert_get_alt_names returned only the dns_names
     79	*/
     80	FREERDP_API WINPR_DEPRECATED(char** crypto_cert_subject_alt_name(X509* xcert, int* count,
     81	                                                                 int** lengths));
     82	FREERDP_API WINPR_DEPRECATED(void crypto_cert_subject_alt_name_free(int count, int* lengths,
     83	                                                                    char** alt_names));
     84#endif
     85
     86	FREERDP_API BOOL x509_verify_certificate(CryptoCert cert, const char* certificate_store_path);
     87	FREERDP_API rdpCertificateData* crypto_get_certificate_data(X509* xcert, const char* hostname,
     88	                                                            UINT16 port);
     89	FREERDP_API BOOL crypto_cert_get_public_key(CryptoCert cert, BYTE** PublicKey,
     90	                                            DWORD* PublicKeyLength);
     91
     92#define TSSK_KEY_LENGTH 64
     93	WINPR_API extern const BYTE tssk_modulus[];
     94	WINPR_API extern const BYTE tssk_privateExponent[];
     95	WINPR_API extern const BYTE tssk_exponent[];
     96
     97	FREERDP_API int crypto_rsa_public_encrypt(const BYTE* input, int length, UINT32 key_length,
     98	                                          const BYTE* modulus, const BYTE* exponent,
     99	                                          BYTE* output);
    100	FREERDP_API int crypto_rsa_public_decrypt(const BYTE* input, int length, UINT32 key_length,
    101	                                          const BYTE* modulus, const BYTE* exponent,
    102	                                          BYTE* output);
    103	FREERDP_API int crypto_rsa_private_encrypt(const BYTE* input, int length, UINT32 key_length,
    104	                                           const BYTE* modulus, const BYTE* private_exponent,
    105	                                           BYTE* output);
    106	FREERDP_API int crypto_rsa_private_decrypt(const BYTE* input, int length, UINT32 key_length,
    107	                                           const BYTE* modulus, const BYTE* private_exponent,
    108	                                           BYTE* output);
    109	FREERDP_API void crypto_reverse(BYTE* data, int length);
    110
    111	FREERDP_API char* crypto_base64_encode(const BYTE* data, int length);
    112	FREERDP_API void crypto_base64_decode(const char* enc_data, int length, BYTE** dec_data,
    113	                                      int* res_length);
    114
    115#ifdef __cplusplus
    116}
    117#endif
    118
    119#endif /* FREERDP_CRYPTO_H */