Coverage Report

Created: 2025-07-01 06:46

/src/FreeRDP/libfreerdp/crypto/opensslcompat.h
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * OpenSSL Compatibility
4
 *
5
 * Copyright (C) 2016 Norbert Federa <norbert.federa@thincast.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_LIB_CRYPTO_OPENSSLCOMPAT_H
21
#define FREERDP_LIB_CRYPTO_OPENSSLCOMPAT_H
22
23
#include <winpr/winpr.h>
24
#include <winpr/assert.h>
25
#include <freerdp/config.h>
26
27
#include <freerdp/api.h>
28
29
#include <openssl/x509.h>
30
31
#ifdef WITH_OPENSSL
32
33
#include <openssl/opensslv.h>
34
35
#if OPENSSL_VERSION_NUMBER < 0x10100000L || \
36
    (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL)
37
38
#include <openssl/bio.h>
39
#include <openssl/rsa.h>
40
#include <openssl/bn.h>
41
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
52
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)
61
62
BIO_METHOD* BIO_meth_new(int type, const char* name);
63
void RSA_get0_key(const RSA* r, const BIGNUM** n, const BIGNUM** e, const BIGNUM** d);
64
65
#endif /* OPENSSL < 1.1.0 || LIBRESSL */
66
#endif /* WITH_OPENSSL */
67
68
/* Drop in replacement for older OpenSSL and LibRESSL */
69
#if defined(LIBRESSL_VERSION_NUMBER) || \
70
    (defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER < 0x1010000fL))
71
72
static INLINE STACK_OF(X509) * sk_X509_deep_copy(const STACK_OF(X509) * sk,
73
                                                 X509* (*copyfunc)(const X509*),
74
                                                 void (*freefunc)(X509*))
75
{
76
  WINPR_ASSERT(copyfunc);
77
  WINPR_ASSERT(freefunc);
78
79
  STACK_OF(X509)* stack = sk_X509_new_null();
80
  if (!stack)
81
    return NULL;
82
83
  if (sk)
84
  {
85
    for (int i = 0; i < sk_X509_num(sk); i++)
86
    {
87
      X509* cert = sk_X509_value(sk, i);
88
      X509* copy = copyfunc(cert);
89
      if (!copy)
90
        goto fail;
91
      const int rc = sk_X509_push(stack, copy);
92
      if (rc <= 0)
93
        goto fail;
94
    }
95
  }
96
97
  return stack;
98
99
fail:
100
  sk_X509_pop_free(stack, freefunc);
101
  return NULL;
102
}
103
#endif
104
105
/* OpenSSL API is not const consistent.
106
 * While the TYPE_dup function take non const arguments
107
 * the TYPE_sk versions require the arguments to be const...
108
 */
109
static INLINE X509* X509_const_dup(const X509* x509)
110
0
{
111
0
  X509* ptr = WINPR_CAST_CONST_PTR_AWAY(x509, X509*);
112
0
  return X509_dup(ptr);
113
0
}
Unexecuted instantiation: privatekey.c:X509_const_dup
Unexecuted instantiation: certificate.c:X509_const_dup
Unexecuted instantiation: tsg.c:X509_const_dup
Unexecuted instantiation: rdg.c:X509_const_dup
Unexecuted instantiation: wst.c:X509_const_dup
Unexecuted instantiation: cert_common.c:X509_const_dup
Unexecuted instantiation: tls.c:X509_const_dup
Unexecuted instantiation: tcp.c:X509_const_dup
Unexecuted instantiation: arm.c:X509_const_dup
114
#endif /* FREERDP_LIB_CRYPTO_OPENSSLCOMPAT_H */