puma: error: implicit declaration of function 'SSL_get1_peer_certificate'

Describe the bug

When trying to bundle install in a clean .gem directory and fresh ruby 3.1 install:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/wlipa/.gem/ruby/3.1/gems/puma-5.6.2/ext/puma_http11
/opt/local/bin/ruby3.1 -I /opt/local/lib/ruby3.1/3.1.0 -r ./siteconf20220303-44365-8je480.rb extconf.rb
using OpenSSL pkgconfig (openssl.pc)
checking for openssl/bio.h... yes
checking for DTLS_method() in openssl/ssl.h... yes
checking for TLS_server_method() in openssl/ssl.h... yes
checking for SSL_CTX_set_min_proto_version(NULL, 0) in openssl/ssl.h... yes
checking for X509_STORE_up_ref()... yes
checking for SSL_CTX_set_ecdh_auto(NULL, 0) in openssl/ssl.h... yes
checking for SSL_get1_peer_certificate() in openssl/ssl.h... yes
checking for Random.bytes... yes
creating Makefile

current directory: /Users/wlipa/.gem/ruby/3.1/gems/puma-5.6.2/ext/puma_http11
make DESTDIR\= clean

current directory: /Users/wlipa/.gem/ruby/3.1/gems/puma-5.6.2/ext/puma_http11
make DESTDIR\=
compiling http11_parser.c
compiling mini_ssl.c
mini_ssl.c:565:10: error: implicit declaration of function 'SSL_get1_peer_certificate' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
  cert = SSL_get1_peer_certificate(conn->ssl);
         ^
mini_ssl.c:565:10: note: did you mean 'SSL_get_peer_certificate'?
/opt/local/libexec/openssl11/include/openssl/ssl.h:1678:14: note: 'SSL_get_peer_certificate' declared here
__owur X509 *SSL_get_peer_certificate(const SSL *s);
             ^
mini_ssl.c:565:8: warning: incompatible integer to pointer conversion assigning to 'X509 *' (aka 'struct x509_st *') from 'int'
[-Wint-conversion]
  cert = SSL_get1_peer_certificate(conn->ssl);
       ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.
make: *** [mini_ssl.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/wlipa/.gem/ruby/3.1/gems/puma-5.6.2 for inspection.
Results logged to /Users/wlipa/.gem/ruby/3.1/extensions/arm64-darwin-21/3.1.0/puma-5.6.2/gem_make.out

  /opt/local/lib/ruby3.1/3.1.0/rubygems/ext/builder.rb:95:in `run'
  /opt/local/lib/ruby3.1/3.1.0/rubygems/ext/builder.rb:44:in `block in make'
  /opt/local/lib/ruby3.1/3.1.0/rubygems/ext/builder.rb:36:in `each'
  /opt/local/lib/ruby3.1/3.1.0/rubygems/ext/builder.rb:36:in `make'
  /opt/local/lib/ruby3.1/3.1.0/rubygems/ext/ext_conf_builder.rb:63:in `block in build'
  /opt/local/lib/ruby3.1/3.1.0/tempfile.rb:317:in `open'
  /opt/local/lib/ruby3.1/3.1.0/rubygems/ext/ext_conf_builder.rb:26:in `build'
  /opt/local/lib/ruby3.1/3.1.0/rubygems/ext/builder.rb:161:in `build_extension'
  /opt/local/lib/ruby3.1/3.1.0/rubygems/ext/builder.rb:195:in `block in build_extensions'
  /opt/local/lib/ruby3.1/3.1.0/rubygems/ext/builder.rb:192:in `each'
  /opt/local/lib/ruby3.1/3.1.0/rubygems/ext/builder.rb:192:in `build_extensions'
  /opt/local/lib/ruby3.1/3.1.0/rubygems/installer.rb:853:in `build_extensions'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/rubygems_gem_installer.rb:71:in `build_extensions'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/source/rubygems.rb:204:in `install'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/installer/gem_installer.rb:54:in `install'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/installer/parallel_installer.rb:186:in `do_install'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/installer/parallel_installer.rb:177:in `block in worker_pool'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/worker.rb:62:in `apply_func'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/worker.rb:57:in `block in process_queue'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/worker.rb:54:in `loop'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/worker.rb:54:in `process_queue'
  /Users/wlipa/.gem/ruby/3.1/gems/bundler-2.3.6/lib/bundler/worker.rb:91:in `block (2 levels) in create_threads'

An error occurred while installing puma (5.6.2), and Bundler cannot continue.

In Gemfile:
  puma

Desktop (please complete the following information):

  • OS: macOS 12.2.1, M1 chip, macports 2.7.1
  • Puma Version 5.6.2

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 45 (18 by maintainers)

Commits related to this issue

Most upvoted comments

This looks like what I need for my setup:

bundle config build.puma --with-openssl-dir=/opt/local/libexec/openssl11 --without-openssl-lib=/opt/local/lib

I had this problem and couldn’t find much information about it, even fewer possible fixes, and none of them worked. So I hope this helps someone.

I have Ruby v2.7.5 installed and it’s using these OpenSSL versions:

$ ruby -ropenssl -e "puts %Q[\ \ \ Build: #{OpenSSL::OPENSSL_VERSION}\n Runtime: #{OpenSSL::OPENSSL_LIBRARY_VERSION}]"
   Build: OpenSSL 1.1.1n  15 Mar 2022
 Runtime: OpenSSL 1.1.1n  15 Mar 2022

I was getting the same error as the others; what fixed it for me was installing openssl@1.1:

brew install openssl@1.1

Running

PKG_CONFIG_PATH=`brew --prefix openssl@1.1`/lib/pkgconfig/ pkg-config openssl --cflags

Should return something like -I/opt/homebrew/Cellar/openssl@1.1/1.1.1o/include. If it does, install puma like this:

PKG_CONFIG_PATH=`brew --prefix openssl@1.1`/lib/pkgconfig/ gem install puma

Doing this solved the issue, and everything seems to be working fine so far.

Ah, that is great! Looks like this solves the problem (if you don’t need SSL):

DISABLE_SSL=1 bundle install

Oh we should probably prefix that ENV with PUMA_? Something for 6.0 perhaps