{"id":19885653,"url":"https://github.com/asmod4n/mruby-tls","last_synced_at":"2025-05-02T16:31:50.048Z","repository":{"id":25737575,"uuid":"29175038","full_name":"Asmod4n/mruby-tls","owner":"Asmod4n","description":"mruby wrapper for libtls from http://www.libressl.org/","archived":false,"fork":false,"pushed_at":"2024-12-01T02:20:01.000Z","size":5376,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T03:34:34.381Z","etag":null,"topics":["libressl","mruby","ssl","tls"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Asmod4n.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":"2015-01-13T05:52:11.000Z","updated_at":"2024-12-01T02:20:04.000Z","dependencies_parsed_at":"2024-04-13T15:10:17.008Z","dependency_job_id":null,"html_url":"https://github.com/Asmod4n/mruby-tls","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asmod4n%2Fmruby-tls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asmod4n%2Fmruby-tls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asmod4n%2Fmruby-tls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asmod4n%2Fmruby-tls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Asmod4n","download_url":"https://codeload.github.com/Asmod4n/mruby-tls/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252071840,"owners_count":21690099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["libressl","mruby","ssl","tls"],"created_at":"2024-11-12T17:35:12.691Z","updated_at":"2025-05-02T16:31:44.966Z","avatar_url":"https://github.com/Asmod4n.png","language":"C","readme":"# mruby-tls\n\nPrerequisites\n=============\n[libtls](https://www.libressl.org) needs to be somewhere the mruby compiler can find it.\n\nFor example on macOS you need to add the folowing to your build_config.rb after installing it with\n```brew install libressl```\n\n```ruby\nconf.gem mgem: 'mruby-tls' do |spec|\n  spec.cc.include_paths \u003c\u003c '/usr/local/opt/libressl/include'\n  spec.linker.library_paths \u003c\u003c '/usr/local/opt/libressl/lib'\nend\n```\n\nBy default libtls looks in /etc/ssl/cert.pem for ca certs, you can find how to change that in the examples below.\n\n\nClient example with blocking IO\n================================\n```ruby\nclient = Tls::Client.new\nclient.connect('github.com:443').write(\"GET / HTTP/1.1\\r\\nHost: github.com\\r\\nConnection: close\\r\\n\\r\\n\")\nprint client.read\nclient.close\n```\n\nIts also possible to connect via service descriptions.\n```ruby\nclient.connect('github.com', 'https')\n```\n\nYou can also use port numbers as the second Argument.\n```ruby\nclient.connect('github.com', '443')\n```\n\nIf your ca certs are in another path.\n\n```ruby\nclient = Tls::Client.new(ca_file: '/usr/local/etc/libressl/cert.pem')\n```\n\nIf you later want to change a config setting\n```ruby\nclient.config.ca_file = '/etc/ssl/cert.pem'\n```\n\nClient example with non blocking IO\n====================================\nrequires mruby-poll gem\n```ruby\ntcp_socket = TCPSocket.new \"github.com\", 443\nclient = Tls::Client.new\nclient.connect_socket tcp_socket.fileno, \"github.com\"\ntcp_socket._setnonblock(true)\npoll = Poll.new\ntcp_socket_pi = poll.add(tcp_socket, Poll::Out)\n\nbuf = \"GET / HTTP/1.1\\r\\nHost: github.com\\r\\nConnection: close\\r\\n\\r\\n\"\nwhile buf\n  unless poll.wait\n    raise \"Can't write to socket\"\n  end\n  tmp = client.write_nonblock(buf)\n  case tmp\n    when :tls_want_pollin\n      tcp_socket_pi.events = Poll::In\n    when :tls_want_pollout\n      tcp_socket_pi.events = Poll::Out\n    when Fixnum\n      buf = buf[tmp+1...-1]\n  end\nend\n\ntcp_socket_pi.events = Poll::In\npoll.wait\nuntil (buf = client.read_nonblock()).is_a? String\n  case buf\n    when :tls_want_pollin\n      tcp_socket_pi.events = Poll::In\n    when :tls_want_pollout\n      tcp_socket_pi.events = Poll::Out\n  end\n  unless poll.wait\n    raise \"Can't read from socket\"\n  end\nend\n\nputs buf\n\ntcp_socket._setnonblock(false)\nclient.close\ntcp_socket.close\n```\n\nConfiguration Examples\n======================\nYou can create a configuration object to share with several connections.\n```ruby\nconfig = Tls::Config.new # see https://github.com/Asmod4n/mruby-tls/blob/master/mrblib/config.rb for options.\n\nclient = Tls::Client.new config\n```\n\nYou can later on change the configuration object\n```ruby\nclient.config = config\n```\n\nServer example\n==============\n```sh\nopenssl ecparam -name secp256r1 -genkey -out private-key.pem\nopenssl req -new -x509 -key private-key.pem -out server.pem\n```\n```ruby\ntls_server = Tls::Server.new(key_file: 'private-key.pem', cert_file: 'server.pem')\ntcp_server = TCPServer.new 5000 # requires mruby-socket\ntcp_client = tcp_server.accept\ntls_client = tls_server.accept_socket tcp_client.fileno\ntls_client.write \"hallo\\n\"\ntls_client.close\n```\n\nClient Connections don't have a configurable config at the moment\n\nThis maps the C Api 1:1, to get a overview http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/tls_accept_fds.3?query=tls%5finit\u0026sec=3 is a good starting point.\n\nLicense\n=======\nCopyright 2015,2016,2024 Hendrik Beskow\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this project except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasmod4n%2Fmruby-tls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasmod4n%2Fmruby-tls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasmod4n%2Fmruby-tls/lists"}