{"id":14966151,"url":"https://github.com/raku-community-modules/OpenSSL","last_synced_at":"2025-10-25T16:30:40.781Z","repository":{"id":2326515,"uuid":"21610508","full_name":"sergot/openssl","owner":"sergot","description":"OpenSSL bindings for Perl 6","archived":false,"fork":false,"pushed_at":"2024-02-17T23:24:40.000Z","size":3678,"stargazers_count":14,"open_issues_count":26,"forks_count":31,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-01-31T07:51:26.492Z","etag":null,"topics":["openssl","openssl-bindings","perl6","socket"],"latest_commit_sha":null,"homepage":null,"language":"Raku","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/sergot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"sergot"}},"created_at":"2014-07-08T11:40:48.000Z","updated_at":"2024-04-16T22:36:36.000Z","dependencies_parsed_at":"2024-01-22T03:44:49.954Z","dependency_job_id":null,"html_url":"https://github.com/sergot/openssl","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergot%2Fopenssl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergot%2Fopenssl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergot%2Fopenssl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergot%2Fopenssl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergot","download_url":"https://codeload.github.com/sergot/openssl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238174092,"owners_count":19428624,"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":["openssl","openssl-bindings","perl6","socket"],"created_at":"2024-09-24T13:35:55.854Z","updated_at":"2025-10-25T16:30:40.776Z","avatar_url":"https://github.com/sergot.png","language":"Raku","funding_links":["https://github.com/sponsors/sergot"],"categories":[],"sub_categories":[],"readme":"[![Actions Status](https://github.com/raku-community-modules/OpenSSL/actions/workflows/linux.yml/badge.svg)](https://github.com/raku-community-modules/OpenSSL/actions) [![Actions Status](https://github.com/raku-community-modules/OpenSSL/actions/workflows/macos.yml/badge.svg)](https://github.com/raku-community-modules/OpenSSL/actions) [![Actions Status](https://github.com/raku-community-modules/OpenSSL/actions/workflows/windows.yml/badge.svg)](https://github.com/raku-community-modules/OpenSSL/actions)\n\nNAME\n====\n\nOpenSSL - OpenSSL bindings\n\nSYNOPSIS\n========\n\n```raku\nuse OpenSSL;\nmy $openssl = OpenSSL.new;\n$openssl.set-fd(123);\n$openssl.write(\"GET / HTTP/1.1\\r\\nHost: somehost\\r\\n\\r\\n\");\n```\n\nDESCRIPTION\n===========\n\nA module which provides OpenSSL bindings, making us able to set up a TLS/SSL connection.\n\nMETHODS\n=======\n\nmethod new\n----------\n\n```raku\nmethod new(Bool :$client = False, Int :$version?)\n```\n\nA constructor. Initializes OpenSSL library, sets method and context. If $version is not specified, the highest possible version is negotiated.\n\nmethod set-fd\n-------------\n\n```raku\nmethod set-fd(OpenSSL:, int32 $fd)\n```\n\nAssigns connection's file descriptor (file handle) $fd to the SSL object.\n\nTo get the $fd we should use C to set up the connection. (See [NativeCall](NativeCall)) I hope we will be able to use Raku's IO::Socket module instead of connecting through C soon-ish.\n\nmethod set-connect-state\n------------------------\n\n```raku\nmethod set-connect-state(OpenSSL:)\n```\n\nSets SSL object to connect (client) state.\n\nUse it when you want to connect to SSL servers.\n\nmethod set-accept-state\n-----------------------\n\n```raku\nmethod set-accept-state(OpenSSL:)\n```\n\nSets SSL object to accept (server) state.\n\nUse it when you want to provide an SSL server.\n\nmethod connect\n--------------\n\n```raku\nmethod connect(OpenSSL:)\n```\n\nConnects to the server using $fd (passed using .set-fd).\n\nDoes all the SSL stuff like handshaking.\n\nmethod accept\n-------------\n\n```raku\nmethod accept(OpenSSL:)\n```\n\nAccepts new client connection.\n\nDoes all the SSL stuff like handshaking.\n\nmethod write\n------------\n\n```raku\nmethod write(OpenSSL:, Str $s)\n```\n\nSends $s to the other side (server/client).\n\nmethod read\n-----------\n\n```raku\nmethod read(OpenSSL:, Int $n, Bool :$bin)\n```\n\nReads $n bytes from the other side (server/client).\n\nBool :$bin if we want it to return Buf instead of Str.\n\nmethod use-certificate-file\n---------------------------\n\n```raku\nmethod use-certificate-file(OpenSSL:, Str $file)\n```\n\nAssings a certificate (from file) to the SSL object.\n\nmethod use-privatekey-file\n--------------------------\n\n```raku\nmethod use-privatekey-file(OpenSSL:, Str $file)\n```\n\nAssings a private key (from file) to the SSL object.\n\nmethod check-private-key\n------------------------\n\n```raku\nmethod check-private-key(OpenSSL:)\n```\n\nChecks if private key is valid.\n\nmethod shutdown\n---------------\n\n```raku\nmethod shutdown(OpenSSL:)\n```\n\nTurns off the connection.\n\nmethod ctx-free\n---------------\n\n```raku\nmethod ctx-free(OpenSSL:)\n```\n\nFrees C's SSL_CTX struct.\n\nmethod ssl-free\n---------------\n\n```raku\nmethod ssl-free(OpenSSL:)\n```\n\nFrees C's SSL struct.\n\nmethod close\n------------\n\n```raku\nmethod close(OpenSSL:)\n```\n\nCloses the connection.\n\nUnlike .shutdown it calls ssl-free, ctx-free, and then it shutdowns.\n\nTOOLS\n=====\n\nPublic key signing tools.\n\nOpenSSL::RSATools\n-----------------\n\n```raku\nuse OpenSSL::RSATools;\n\nmy $pem = slurp 'key.pem';\nmy $rsa = OpenSSL::RSAKey.new(private-pem =\u003e $pem);\nmy $data = 'as df jk l';\nmy $signature = $rsa.sign($data.encode);\nmy $rsa = OpenSSL::RSAKey.new(public-pem =\u003e $public);\nif $rsa.verify($data.encode, $signature) { ... }\n```\n\nOpenSSL::CryptTools\n-------------------\n\nSymmetric encryption tools (currently only AES256/192/128 encrypt/decrypt)\n\n```raku\nuse OpenSSL::CryptTools;\n\nmy $ciphertext = encrypt(\"asdf\".encode,\n                         :aes256,\n                         :iv((\"0\" x 16).encode),\n                         :key(('x' x 32).encode));\nmy $plaintext = decrypt($ciphertext,\n                        :aes256,\n                        :iv((\"0\" x 16).encode),\n                        :key(('x' x 32).encode));\n```\n\nOpenSSL::Digest\n---------------\n\n```raku\nuse OpenSSL::Digest;\n\nmy Blob $digest = md5(\"filename\".IO);    # IO::Path object\nmy Blob $digest = md5(Blob.new(1,2,3));  # Blob object\nmy Blob $digest = md5(\"foo bar\");        # coercible to string\n\nsay md5-hex(\"foo bar\");  # 327b6f07435811239bc47e1544353273\n```\n\nDigest Functions exported as subroutines. Takes either an `IO::Path` object of a path of which to create a digest, or a `Blob` object, or an object that can be coerced to a string. A `Blob` is always returned.\n\n  * md5\n\n  * sha1\n\n  * sha224\n\n  * sha256\n\n  * sha384\n\n  * sha512\n\nThese subroutines have hexified counterparts with the same name, but postfixed with \"-hex\", which return a string (lowercase hexadecimal characters) representation of the digest.\n\n  * md5-hex\n\n  * sha1-hex\n\n  * sha224-hex\n\n  * sha256-hex\n\n  * sha384-hex\n\n  * sha512-hex\n\nOpenSSL::Digest::MD5\n--------------------\n\nOO-Interface supporting incremental digesting\n\n```raku\nuse OpenSSL::Digest::MD5;\n\nmy $md5 = OpenSSL::Digest::MD5.new; # Create fresh object\n$md5.add('abc');                    # pass in Str or Blob\n$md5.add('def');                    # Add some more data\nmy $digest = $md5.hash;             # Blob hash (and reset)\n$md5.addfile('myfile');             # Read a file\nmy $hexdigest = $md5.hex;           # hex hash  (and reset)\n```\n\nCAVEATS\n=======\n\nMacOS\n-----\n\nMany native libraries on MacOS are installed with the `brew` command line interface. For this module one would typically have to do a `brew install openssl`.\n\nThe use of native libraries is slightly more complicated on the MacOS operating system than on other operating systems. This generally means that a symlink needs to be installed in a trusted filesystem location. If the [`MacOS::NativeLib`](https://raku.land/zef:lizmat/MacOS::NativeLib) distribution is installed, then these symlinks will be automatically created when this module is built.\n\nSEE ALSO\n========\n\n[IO::Socket::SSL](IO::Socket::SSL)\n\nAUTHORS\n=======\n\n  * Filip Sergot\n\n  * Elizabeth Mattijsen\n\nSource can be located at: https://github.com/raku-community-modules/OpenSSL . Comments and Pull Requests are welcome.\n\nCOPYRIGHT AND LICENSE\n=====================\n\nCopyright 2014 - 2022 Filip Sergot\n\nCopyright 2023 - 2025 The Raku Community\n\nThis library is free software; you can redistribute it and/or modify it under the MIT License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraku-community-modules%2FOpenSSL","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraku-community-modules%2FOpenSSL","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraku-community-modules%2FOpenSSL/lists"}