Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
1ac28307
Commit
1ac28307
authored
Mar 05, 2022
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support OpenSSL versions < 1.1
parent
cc9f5516
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
52 deletions
+20
-52
libcaf_net/caf/net/openssl_transport.hpp
libcaf_net/caf/net/openssl_transport.hpp
+20
-52
No files found.
libcaf_net/caf/net/openssl_transport.hpp
View file @
1ac28307
...
...
@@ -27,61 +27,40 @@ CAF_PUSH_WARNINGS
#include <openssl/ssl.h>
CAF_POP_WARNINGS
#if OPENSSL_VERSION_NUMBER < 0x10100000L
# error "OpenSSL version too old. CAF::net requires at least OpenSSL 1.1"
#endif
#include <memory>
#include <string>
#include <string_view>
// -- small wrappers to help working with OpenSSL ------------------------------
namespace
caf
{
template
<
>
struct
intrusive_ptr_access
<
SSL_CTX
>
{
public:
static
void
add_ref
(
SSL_CTX
*
ptr
)
noexcept
{
SSL_CTX_up_ref
(
ptr
);
}
namespace
caf
::
net
::
openssl
{
static
void
release
(
SSL_CTX
*
ptr
)
noexcept
{
struct
deleter
{
void
operator
()(
SSL_CTX
*
ptr
)
const
noexcept
{
SSL_CTX_free
(
ptr
);
}
};
template
<
>
struct
intrusive_ptr_access
<
SSL
>
{
public:
static
void
add_ref
(
SSL
*
ptr
)
noexcept
{
SSL_up_ref
(
ptr
);
}
static
void
release
(
SSL
*
ptr
)
noexcept
{
void
operator
()(
SSL
*
ptr
)
const
noexcept
{
SSL_free
(
ptr
);
}
};
}
// namespace caf
namespace
caf
::
net
::
openssl
{
/// A smart pointer to an `SSL_CTX` structure.
/// @note technically, SSL structures are reference counted and we could use
/// `intrusive_ptr` instead. However, we have no need for shared ownership
/// semantics here and use `unique_ptr` for simplicity.
using
ctx_ptr
=
intrusive_ptr
<
SSL_CTX
>
;
using
ctx_ptr
=
std
::
unique_ptr
<
SSL_CTX
,
deleter
>
;
/// A smart pointer to an `SSL` structure.
/// @note technically, SSL structures are reference counted and we could use
/// `intrusive_ptr` instead. However, we have no need for shared ownership
/// semantics here and use `unique_ptr` for simplicity.
using
conn_ptr
=
intrusive_ptr
<
SSL
>
;
using
conn_ptr
=
std
::
unique_ptr
<
SSL
,
deleter
>
;
/// Convenience function for creating an OpenSSL context for given method.
inline
ctx_ptr
make_ctx
(
const
SSL_METHOD
*
method
)
{
if
(
auto
ptr
=
SSL_CTX_new
(
method
))
return
ctx_ptr
{
ptr
,
false
};
return
ctx_ptr
{
ptr
};
else
CAF_RAISE_ERROR
(
"SSL_CTX_new failed"
);
}
...
...
@@ -127,7 +106,7 @@ inline error private_key_pem_file(const ctx_ptr& ctx, const std::string& path) {
/// Convenience function for creating a new SSL structure from given context.
inline
conn_ptr
make_conn
(
const
ctx_ptr
&
ctx
)
{
if
(
auto
ptr
=
SSL_new
(
ctx
.
get
()))
return
conn_ptr
{
ptr
,
false
};
return
conn_ptr
{
ptr
};
else
CAF_RAISE_ERROR
(
"SSL_new failed"
);
}
...
...
@@ -149,40 +128,33 @@ public:
policy
()
=
delete
;
policy
(
const
policy
&
)
=
de
fault
;
policy
(
const
policy
&
)
=
de
lete
;
policy
&
operator
=
(
const
policy
&
)
=
de
fault
;
policy
&
operator
=
(
const
policy
&
)
=
de
lete
;
policy
(
policy
&&
)
=
default
;
policy
&
operator
=
(
policy
&&
)
=
default
;
policy
(
ctx_ptr
ctx
,
conn_ptr
conn
)
:
ctx_
(
std
::
move
(
ctx
)),
conn_
(
std
::
move
(
conn
))
{
explicit
policy
(
conn_ptr
conn
)
:
conn_
(
std
::
move
(
conn
))
{
// nop
}
// -- factories --------------------------------------------------------------
/// Creates a policy from an SSL context and socket.
static
policy
make
(
const
ctx_ptr
&
ctx
,
stream_socket
fd
)
{
return
policy
{
make_conn
(
ctx
,
fd
)};
}
/// Creates a policy from an SSL method and socket.
static
policy
make
(
const
SSL_METHOD
*
method
,
stream_socket
fd
)
{
auto
ctx
=
make_ctx
(
method
);
auto
conn
=
make_conn
(
ctx
,
fd
);
return
policy
{
std
::
move
(
ctx
),
std
::
move
(
conn
)};
}
/// Creates a policy from an SSL context and socket.
static
policy
make
(
ctx_ptr
ctx
,
stream_socket
fd
)
{
auto
conn
=
make_conn
(
ctx
,
fd
);
return
policy
{
std
::
move
(
ctx
),
std
::
move
(
conn
)};
return
policy
{
make_conn
(
ctx
,
fd
)};
}
// -- properties -------------------------------------------------------------
SSL_CTX
*
ctx
()
{
return
ctx_
.
get
();
}
SSL
*
conn
()
{
return
conn_
.
get
();
}
...
...
@@ -270,9 +242,6 @@ public:
}
private:
/// Our SSL context.
openssl
::
ctx_ptr
ctx_
;
/// Our SSL connection data.
openssl
::
conn_ptr
conn_
;
};
...
...
@@ -346,9 +315,8 @@ public:
// -- constructors, destructors, and assignment operators --------------------
template
<
class
...
Ts
>
openssl_transport
(
openssl
::
ctx_ptr
ctx
,
openssl
::
conn_ptr
conn
,
Ts
&&
...
xs
)
:
super
(
openssl
::
policy
{
std
::
move
(
ctx
),
std
::
move
(
conn
)},
std
::
forward
<
Ts
>
(
xs
)...)
{
explicit
openssl_transport
(
openssl
::
conn_ptr
conn
,
Ts
&&
...
xs
)
:
super
(
openssl
::
policy
{
std
::
move
(
conn
)},
std
::
forward
<
Ts
>
(
xs
)...)
{
// nop
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment