20#ifndef FREERDP_LIB_CRYPTO_OPENSSLCOMPAT_H 
   21#define FREERDP_LIB_CRYPTO_OPENSSLCOMPAT_H 
   23#include <winpr/winpr.h> 
   24#include <winpr/assert.h> 
   25#include <freerdp/config.h> 
   27#include <freerdp/api.h> 
   29#include <openssl/x509.h> 
   33#include <openssl/opensslv.h> 
   35#if OPENSSL_VERSION_NUMBER < 0x10100000L || \ 
   36    (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL) 
   38#include <openssl/bio.h> 
   39#include <openssl/rsa.h> 
   40#include <openssl/bn.h> 
   42#define BIO_get_data(b) (b)->ptr 
   43#define BIO_set_data(b, v) (b)->ptr = v 
   44#define BIO_get_init(b) (b)->init 
   45#define BIO_set_init(b, v) (b)->init = v 
   46#define BIO_get_next(b, v) (b)->next_bio 
   47#define BIO_set_next(b, v) (b)->next_bio = v 
   48#define BIO_get_shutdown(b) (b)->shutdown 
   49#define BIO_set_shutdown(b, v) (b)->shutdown = v 
   50#define BIO_get_retry_reason(b) (b)->retry_reason 
   51#define BIO_set_retry_reason(b, v) (b)->retry_reason = v 
   53#define BIO_meth_set_write(b, f) (b)->bwrite = (f) 
   54#define BIO_meth_set_read(b, f) (b)->bread = (f) 
   55#define BIO_meth_set_puts(b, f) (b)->bputs = (f) 
   56#define BIO_meth_set_gets(b, f) (b)->bgets = (f) 
   57#define BIO_meth_set_ctrl(b, f) (b)->ctrl = (f) 
   58#define BIO_meth_set_create(b, f) (b)->create = (f) 
   59#define BIO_meth_set_destroy(b, f) (b)->destroy = (f) 
   60#define BIO_meth_set_callback_ctrl(b, f) (b)->callback_ctrl = (f) 
   62BIO_METHOD* BIO_meth_new(
int type, 
const char* name);
 
   63void RSA_get0_key(
const RSA* r, 
const BIGNUM** n, 
const BIGNUM** e, 
const BIGNUM** d);
 
   69#if defined(LIBRESSL_VERSION_NUMBER) || \ 
   70    (defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER < 0x1010000fL)) 
   72static inline STACK_OF(X509) * sk_X509_deep_copy(
const STACK_OF(X509) * sk,
 
   73                                                 X509* (*copyfunc)(
const X509*),
 
   74                                                 void (*freefunc)(X509*))
 
   76  WINPR_ASSERT(copyfunc);
 
   77  WINPR_ASSERT(freefunc);
 
   79  STACK_OF(X509)* stack = sk_X509_new_null();
 
   85    for (
int i = 0; i < sk_X509_num(sk); i++)
 
   87      X509* cert = sk_X509_value(sk, i);
 
   88      X509* copy = copyfunc(cert);
 
   91      const int rc = sk_X509_push(stack, copy);
 
  100  sk_X509_pop_free(stack, freefunc);
 
  109static inline X509* X509_const_dup(
const X509* x509)
 
  111  X509* ptr = WINPR_CAST_CONST_PTR_AWAY(x509, X509*);
 
  112  return X509_dup(ptr);