Skip to content
Stephen De Gabrielle edited this page Jan 16, 2023 · 2 revisions

This page captures useful code snippets that are too small to be a package.

There is also an GitHub organisation for larger examples https://github.com/racket-artifacts

Please contribute your own!


Directly calling the OpenSSL executable from Racket

This example generates a 1024-bit RSA key in PEM format

Idea courtesy of Neil Van Dyke. Control flow suggested by Neil Van Dyke, Robby Findler and Eli Barzilay.

(parameterize ([current-input-port (open-input-string "")])
  (with-output-to-string (λ _(system* (build-path "c:" "openssl-win32" "bin" "openssl.exe")
                                      "genrsa" 
                                      "1024"))))

Generating an HMAC-SHA1 digest

;;returns the string "(stdin)= 5df23ffdf57d5d925f150c885d64bee2eaf55a43\n"

(parameterize ([current-input-port (open-input-string "We are Spinal Tap!")])
  (with-output-to-string (λ _ (system* (build-path "c:" "openssl-win32" "bin" "openssl.exe")
                                      "dgst" 
                                      "-sha1"
                                      "-hex"
                                      "-hmac"
                                      #"mysecretkey"))))

OpenSSL on Amazon Linux

When installing Racket on the Amazon Linux AMI, choose the Fedora build. For example use the racket-5.2.1-bin-x86_64-linux-f14.sh installer for Racket 5.2.1 with the 64-bit Amazon Linux AMI.

You may find that openssl module calls give a runtime error. This includes procedures like ssl-connect, and procedures that use it indirectly such as get-pure-port with an https scheme in the URI.

To fix, install the openssl-devel package:

$ sudo yum install openssl-devel

Clone this wiki locally