{"id":15871260,"url":"https://github.com/tomerheber/libael_openssl","last_synced_at":"2026-06-24T22:31:02.803Z","repository":{"id":106133312,"uuid":"242451291","full_name":"TomerHeber/libael_openssl","owner":"TomerHeber","description":"An OpenSSL filter for the C++ libael library","archived":false,"fork":false,"pushed_at":"2020-04-25T21:33:59.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-09T04:18:41.924Z","etag":null,"topics":["asynchronous","asyncio","libael","library","openssl"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TomerHeber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-23T03:41:18.000Z","updated_at":"2022-01-02T15:23:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc1b94a7-6d94-4efb-bc1c-414b8ad32fc2","html_url":"https://github.com/TomerHeber/libael_openssl","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/TomerHeber/libael_openssl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerHeber%2Flibael_openssl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerHeber%2Flibael_openssl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerHeber%2Flibael_openssl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerHeber%2Flibael_openssl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TomerHeber","download_url":"https://codeload.github.com/TomerHeber/libael_openssl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerHeber%2Flibael_openssl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34752465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-24T02:00:07.484Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous","asyncio","libael","library","openssl"],"created_at":"2024-10-06T00:42:32.342Z","updated_at":"2026-06-24T22:31:02.782Z","avatar_url":"https://github.com/TomerHeber.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libael_openssl\nAn OpenSSL filter for stream buffers in the C++ [libael](https://github.com/TomerHeber/libael) library.\n\n## Install\n```shell\ngit clone https://github.com/TomerHeber/libael_openssl\ncd libael_openssl \u0026\u0026 mkdir build \u0026\u0026 cd build\ncmake ..\n```\n\n##### Compile\n```shell\ncmake --build .\n```\n\n##### Compile \u0026 Install\n```shell\ncmake --build . --target install\n```\n\n## Platforms\n* Linux\n\u003e Additional platforms may be added in the future (please open feature requests).\n\n## Features\n* OpenSSL support for the [libael](https://github.com/TomerHeber/libael) stream buffers.\n\u003e Additional features may be added in the future (please open feature requests).\n\n## Usage Samples\nSample files are available in the [samples](samples/) directory\n\n#### Create an SSL over SSL \"pingpong\" Server and Client\nThe filter may be added to the stream buffer during the \"HandleConnected\" callback method (view code below).\nIn this case \"HandleConnected\" will be called 3 times:\n* 1st on TCP Connected.\n* 2nd on SSL Connected.\n* 3rd on SSL over SSL Connected.\n\nOnce the tunnel has been established the client will send a \"ping\" string. The server will reply with a \"pong\". When the client receives the \"pong\" it will close the connection (this will also do proper SSL_shutdown).\n\n###### Code - Server\n```c++\n#include \u003ciostream\u003e\n#include \u003cchrono\u003e\n#include \u003cmemory\u003e\n#include \u003cunordered_map\u003e\n#include \u003cfuture\u003e\n\n#include \u003cael/event_loop.h\u003e\n#include \u003cael/stream_buffer.h\u003e\n#include \u003cael/stream_listener.h\u003e\n\n#include \u003cael/openssl/ssl_stream_buffer_filter.h\u003e\n\n#include \"elapsed.h\"\n\nusing namespace std;\nusing namespace ael;\n\nstatic Elapsed elapsed;\n\n#define TCP_CONNECT 2\n#define SSL_FIRST_CONNECT 1\n#define SSL_SECOND_CONNECT 0\n\nclass PingServer : public NewConnectionHandler, public StreamBufferHandler, public enable_shared_from_this\u003cStreamBufferHandler\u003e {\npublic:\n    PingServer(shared_ptr\u003cEventLoop\u003e event_loop) : event_loop_(event_loop) {\n        ssl_ctx_ = SSL_CTX_new(SSLv23_server_method());\n\n\t    if (SSL_CTX_use_certificate_file(ssl_ctx_, \"fake1.crt\", SSL_FILETYPE_PEM) \u003c= 0) {\n\t    \tthrow \"failed to load certificate\";\n\t    }\n\n\t    if (SSL_CTX_use_PrivateKey_file(ssl_ctx_, \"fake1.key\", SSL_FILETYPE_PEM) \u003c= 0 ) {\n\t    \tthrow \"failed to load key\";\n\t    }\n    }\n\n    virtual ~PingServer() {\n        SSL_CTX_free(ssl_ctx_);\n    }\n\n    void HandleNewConnection(Handle handle) override {\n        cout \u003c\u003c elapsed \u003c\u003c \"new connection\" \u003c\u003c endl;\n        auto stream_buffer = StreamBuffer::CreateForServer(shared_from_this(), handle);\n        streams_buffers_[stream_buffer] = TCP_CONNECT;\n        event_loop_-\u003eAttach(stream_buffer);\n    }\n\n    void HandleData(std::shared_ptr\u003cStreamBuffer\u003e stream_buffer, const std::shared_ptr\u003cconst DataView\u003e \u0026data_view) override {\n        string data;\n        data_view-\u003eAppendToString(data);\n\n        if (data.find(\"ping\") != string::npos) {\n            stream_buffer-\u003eWrite(string(\"pong\"));\n        }\n    }\n\n\tvoid HandleConnected(std::shared_ptr\u003cStreamBuffer\u003e stream_buffer) override { \n        int \u0026state = streams_buffers_[stream_buffer];\n        SSL *ssl;\n        shared_ptr\u003cSSLStreamBufferFilter\u003e ssl_filter;\n\n        switch(state) {\n        case TCP_CONNECT:\n            cout \u003c\u003c elapsed \u003c\u003c \"connected TCP - upgrading to SSL\" \u003c\u003c endl;\n            state = SSL_FIRST_CONNECT;\n            ssl = SSL_new(ssl_ctx_);\n\t    ssl_filter = std::make_shared\u003cSSLStreamBufferFilter\u003e(stream_buffer, ssl);\n\t    stream_buffer-\u003eAddStreamBufferFilter(ssl_filter);    \n            break;        \n        case SSL_FIRST_CONNECT:        \n            cout \u003c\u003c elapsed \u003c\u003c \"connected SSL - upgrading to SSL over SSL\" \u003c\u003c endl; \n            state = SSL_SECOND_CONNECT;\n            ssl = SSL_new(ssl_ctx_);\n            ssl_filter = std::make_shared\u003cSSLStreamBufferFilter\u003e(stream_buffer, ssl);\n            stream_buffer-\u003eAddStreamBufferFilter(ssl_filter);    \n            break;           \n        case SSL_SECOND_CONNECT:\n            cout \u003c\u003c elapsed \u003c\u003c \"connected SSL over SSL\" \u003c\u003c endl;     \n            break;\n        default:\n            throw \"unexpected case\";\n        }\n    }\n\n    void HandleEOF(std::shared_ptr\u003cStreamBuffer\u003e stream_buffer) override {\n        cout \u003c\u003c elapsed \u003c\u003c \"connection closed\" \u003c\u003c endl;\n        streams_buffers_.erase(stream_buffer);\n    }\nprivate:\n    shared_ptr\u003cEventLoop\u003e event_loop_;\n    SSL_CTX *ssl_ctx_;\n    unordered_map\u003cstd::shared_ptr\u003cStreamBuffer\u003e, int\u003e streams_buffers_;\n};\n\nint main() \n{\n    cout \u003c\u003c elapsed \u003c\u003c \"ping server started\" \u003c\u003c endl;\n    auto event_loop = EventLoop::Create();\n    auto ping_server = make_shared\u003cPingServer\u003e(event_loop);\n    auto stream_listener = StreamListener::Create(ping_server, \"127.0.0.1\", 12345);\n    event_loop-\u003eAttach(stream_listener);\n\n    promise\u003cvoid\u003e().get_future().wait();\n}\n```\n\n###### Code - Client\n```c++\n#include \u003ciostream\u003e\n#include \u003cchrono\u003e\n#include \u003cmemory\u003e\n#include \u003cfuture\u003e\n\n#include \u003cael/event_loop.h\u003e\n#include \u003cael/stream_buffer.h\u003e\n\n#include \u003cael/openssl/ssl_stream_buffer_filter.h\u003e\n\n#include \"elapsed.h\"\n\nusing namespace std;\nusing namespace ael;\n\nstatic Elapsed elapsed;\n\n#define TCP_CONNECT 2\n#define SSL_FIRST_CONNECT 1\n#define SSL_SECOND_CONNECT 0\n\nclass PingClient : public StreamBufferHandler {\npublic:\n    PingClient(shared_ptr\u003cpromise\u003cvoid\u003e\u003e done_promise) : done_promise_(done_promise), state_(TCP_CONNECT) {\n       ssl_ctx_ = SSL_CTX_new(SSLv23_client_method());\n    }\n    virtual ~PingClient() {\n        SSL_CTX_free(ssl_ctx_);\n    }\n\n    void HandleData(std::shared_ptr\u003cStreamBuffer\u003e stream_buffer, const std::shared_ptr\u003cconst DataView\u003e \u0026data_view) override {\n        string data;\n        data_view-\u003eAppendToString(data);\n\n        if (data.find(\"pong\") != string::npos) {\n            cout \u003c\u003c elapsed \u003c\u003c \"pong received, closing connection\" \u003c\u003c endl;\n            stream_buffer-\u003eClose();\n        }\n    }\n\n    void HandleConnected(std::shared_ptr\u003cStreamBuffer\u003e stream_buffer) override { \n        SSL *ssl;\n        shared_ptr\u003cSSLStreamBufferFilter\u003e ssl_filter;\n\n        switch(state_) {\n        case TCP_CONNECT:\n            cout \u003c\u003c elapsed \u003c\u003c \"connected TCP - upgrading to SSL\" \u003c\u003c endl;\n            state_ = SSL_FIRST_CONNECT;\n            ssl = SSL_new(ssl_ctx_);\n\t    ssl_filter = std::make_shared\u003cSSLStreamBufferFilter\u003e(stream_buffer, ssl);\n\t    stream_buffer-\u003eAddStreamBufferFilter(ssl_filter);    \n            break;        \n        case SSL_FIRST_CONNECT:        \n            cout \u003c\u003c elapsed \u003c\u003c \"connected SSL - upgrading to SSL over SSL\" \u003c\u003c endl; \n            state_ = SSL_SECOND_CONNECT;\n            ssl = SSL_new(ssl_ctx_);\n            ssl_filter = std::make_shared\u003cSSLStreamBufferFilter\u003e(stream_buffer, ssl);\n            stream_buffer-\u003eAddStreamBufferFilter(ssl_filter);    \n            break;           \n        case SSL_SECOND_CONNECT:\n            cout \u003c\u003c elapsed \u003c\u003c \"connected SSL over SSL, sending ping\" \u003c\u003c endl;\n            stream_buffer-\u003eWrite(string(\"ping\"));\n            break;\n        default:\n            throw \"unexpected case\";\n        }    \n    }\n\n    void HandleEOF(std::shared_ptr\u003cStreamBuffer\u003e stream_buffer) override {\n        cout \u003c\u003c elapsed \u003c\u003c \"connection closed\" \u003c\u003c endl;\n        // Release the \"main\" thread.\n        done_promise_-\u003eset_value();\n    }\nprivate:\n    shared_ptr\u003cpromise\u003cvoid\u003e\u003e done_promise_;\n    SSL_CTX *ssl_ctx_;\n    int state_;\n};\n\nint main() \n{\n    cout \u003c\u003c elapsed \u003c\u003c \"ping client started\" \u003c\u003c endl;\n    \n    auto event_loop = EventLoop::Create();\n    auto done_promise = make_shared\u003cpromise\u003cvoid\u003e\u003e();\n    shared_future\u003cvoid\u003e done_future(done_promise-\u003eget_future());\n    auto ping_client = make_shared\u003cPingClient\u003e(done_promise);\n    auto stream_buffer = StreamBuffer::CreateForClient(ping_client, \"127.0.0.1\", 12345);\n    event_loop-\u003eAttach(stream_buffer);\n\n    done_future.wait();\n    EventLoop::DestroyAll();\n\n    cout \u003c\u003c elapsed \u003c\u003c \"ping client finished\" \u003c\u003c endl;\n}\n```\n\n###### Output - Server\n```shell\n[thread #139661554677568][   0ms] ping server started\n[thread #139661522036480][13323ms] new connection\n[thread #139661522036480][13323ms] connected TCP - upgrading to SSL\n[thread #139661522036480][13335ms] connected SSL - upgrading to SSL over SSL\n[thread #139661522036480][13338ms] connected SSL over SSL\n[thread #139661522036480][13339ms] connection closed\n```\n\n###### Output - Client\n```shell\n[thread #139822899824448][   0ms] ping client started\n[thread #139822867183360][   3ms] connected TCP - upgrading to SSL\n[thread #139822867183360][  14ms] connected SSL - upgrading to SSL over SSL\n[thread #139822867183360][  17ms] connected SSL over SSL, sending ping\n[thread #139822867183360][  18ms] pong received, closing connection\n[thread #139822867183360][  19ms] connection closed\n[thread #139822899824448][  20ms] ping client finished\n```\n\n## Documentation\nAt the moment there is no documentation available. For any questions or concerns please open an issue. Documentation will be added in time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomerheber%2Flibael_openssl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomerheber%2Flibael_openssl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomerheber%2Flibael_openssl/lists"}