Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnutls 3.6.16 on MacOS 10.15.7 fails to generate certificate bundle from keychain #81022

Closed
2 tasks done
TheRealGlumfish opened this issue Jul 11, 2021 · 22 comments
Closed
2 tasks done

Comments

@TheRealGlumfish
Copy link

@TheRealGlumfish TheRealGlumfish commented Jul 11, 2021

brew gist-logs <formula> link OR brew config AND brew doctor output

HOMEBREW_VERSION: 3.2.1-70-g5659d74
ORIGIN: https://github.com/Homebrew/brew
HEAD: 5659d74ff59414d22e285d77a7fcfcd3c1bf0614
Last commit: 2 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 2528ff2d8a532857077704251e388b1901d34a25
Core tap last commit: 78 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_EDITOR: vim
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3_2/bin/ruby
CPU: octa-core 64-bit ivybridge
Clang: 12.0.0 build 1200
Git: 2.32.0 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 10.15.7-x86_64
CLT: 12.0.0.32.29
Xcode: 12.4

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  ghostscript

Warning: Some installed formulae are missing dependencies.
You should `brew install` the missing dependencies:
  brew install ilmbase

Run `brew missing` for more details.

# ghostscript is provided by MacTex so I can't have two installed, ilmbase is required by neofetch but its actually been merged with another package which is installed, so again its not needed

  • I ran brew update and am still able to reproduce my issue.
  • I have resolved all warnings from brew doctor and that did not fix my problem.

What were you trying to do (and why)?

I was trying to use and install gnutls as its required by weechat to connect with SSL on IRC servers

What happened (include all command output)?

The issue

I was trying to use gnutls with weechat (weechat uses TLS/SSL to connect to some servers) but I kept getting the error (while it was working fine previously) The certificate is NOT trusted. The certificate issuer is unknown. . This happens generally when using gnutls as seen below.

$ gnutls-cli youtube.com
Processed 0 CA certificate(s).
Resolving 'youtube.com:443'...
Connecting to '2a00:1450:4001:810::200e:443'...
- Certificate type: X.509
- Got a certificate list of 3 certificates.
- Certificate[0] info:
 - subject `CN=*.google.com', issuer `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', serial 0x39252e20e18cd90c0a00000000e8323f, EC/ECDSA key 256 bits, signed using RSA-SHA256, activated `2021-06-22 13:37:09 UTC', expires `2021-09-14 13:37:08 UTC', pin-sha256="s2UchvbdFUYc4gQ9IJRhM+ZK2FUud6gHzdM4WUHYOyg="
	Public Key ID:
		sha1:ccd1819a1c32aa65769076ba5453dadcf65bfa3a
		sha256:b3651c86f6dd15461ce2043d20946133e64ad8552e77a807cdd3385941d83b28
	Public Key PIN:
		pin-sha256:s2UchvbdFUYc4gQ9IJRhM+ZK2FUud6gHzdM4WUHYOyg=

- Certificate[1] info:
 - subject `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', issuer `CN=GTS Root R1,O=Google Trust Services LLC,C=US', serial 0x0203bc53596b34c718f5015066, RSA key 2048 bits, signed using RSA-SHA256, activated `2020-08-13 00:00:42 UTC', expires `2027-09-30 00:00:42 UTC', pin-sha256="zCTnfLwLKbS9S2sbp+uFz4KZOocFvXxkV06Ce9O5M2w="
- Certificate[2] info:
 - subject `CN=GTS Root R1,O=Google Trust Services LLC,C=US', issuer `CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE', serial 0x77bd0d6cdb36f91aea210fc4f058d30d, RSA key 4096 bits, signed using RSA-SHA256, activated `2020-06-19 00:00:42 UTC', expires `2028-01-28 00:00:42 UTC', pin-sha256="hxqRlPTu1bMS/0DITB1SSu0vd4u/8l8TjPgfaAp63Gc="
- Status: The certificate is NOT trusted. The certificate issuer is unknown.
*** PKI verification of server certificate failed...
*** Fatal error: Error in the certificate.

The solution

The issue was only fixed when I manually when into keychain and regenerated a certificate bundle and placed it into /usr/local/etc/gnutls/cert.pem. See image below.
Screen Shot 2021-07-11 at 11 36 32 AM
This is something which the homebrew formula (should be doing according to its output): Regenerating CA certificate bundle from keychain, this may take a while.... For some reason it is failing.

What did you expect to happen?

I expected to be able to connect with SSL to servers. Successful invocation found below.

$ gnutls-cli youtube.com
Processed 175 CA certificate(s).
Resolving 'youtube.com:443'...
Connecting to '2a00:1450:4001:810::200e:443'...
- Certificate type: X.509
- Got a certificate list of 3 certificates.
- Certificate[0] info:
 - subject `CN=*.google.com', issuer `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', serial 0x39252e20e18cd90c0a00000000e8323f, EC/ECDSA key 256 bits, signed using RSA-SHA256, activated `2021-06-22 13:37:09 UTC', expires `2021-09-14 13:37:08 UTC', pin-sha256="s2UchvbdFUYc4gQ9IJRhM+ZK2FUud6gHzdM4WUHYOyg="
	Public Key ID:
		sha1:ccd1819a1c32aa65769076ba5453dadcf65bfa3a
		sha256:b3651c86f6dd15461ce2043d20946133e64ad8552e77a807cdd3385941d83b28
	Public Key PIN:
		pin-sha256:s2UchvbdFUYc4gQ9IJRhM+ZK2FUud6gHzdM4WUHYOyg=

- Certificate[1] info:
 - subject `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', issuer `CN=GTS Root R1,O=Google Trust Services LLC,C=US', serial 0x0203bc53596b34c718f5015066, RSA key 2048 bits, signed using RSA-SHA256, activated `2020-08-13 00:00:42 UTC', expires `2027-09-30 00:00:42 UTC', pin-sha256="zCTnfLwLKbS9S2sbp+uFz4KZOocFvXxkV06Ce9O5M2w="
- Certificate[2] info:
 - subject `CN=GTS Root R1,O=Google Trust Services LLC,C=US', issuer `CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE', serial 0x77bd0d6cdb36f91aea210fc4f058d30d, RSA key 4096 bits, signed using RSA-SHA256, activated `2020-06-19 00:00:42 UTC', expires `2028-01-28 00:00:42 UTC', pin-sha256="hxqRlPTu1bMS/0DITB1SSu0vd4u/8l8TjPgfaAp63Gc="
- Status: The certificate is trusted.
- Description: (TLS1.3-X.509)-(ECDHE-X25519)-(ECDSA-SECP256R1-SHA256)-(AES-256-GCM)
- Options:
- Handshake was completed

As seen above gnutls finds all the certificates and is able to successfully complete the handshake.

Step-by-step reproduction instructions (by running brew commands)

$ brew update
$ brew install gnutls
@SMillerDev
Copy link
Member

@SMillerDev SMillerDev commented Jul 11, 2021

What is the output when you run brew postinstall gnutls?

@TheRealGlumfish
Copy link
Author

@TheRealGlumfish TheRealGlumfish commented Jul 11, 2021

What is the output when you run brew postinstall gnutls?

$ brew postinstall gnutls
==> Postinstalling gnutls
==> Regenerating CA certificate bundle from keychain, this may take a while...

@gromgit
Copy link
Member

@gromgit gromgit commented Jul 12, 2021

How about brew postinstall -d -v gnutls?

@TheRealGlumfish
Copy link
Author

@TheRealGlumfish TheRealGlumfish commented Jul 12, 2021

How about brew postinstall -d -v gnutls?

$ brew postinstall -d -v gnutls
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gnutls.rb
==> Postinstalling gnutls
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromPathLoader): loading /usr/local/opt/gnutls/.brew/gnutls.rb
/usr/bin/sandbox-exec -f /private/tmp/homebrew20210712-52474-fgg4sv.sb nice ruby -W1 -I $LOAD_PATH -- /usr/local/Homebrew/Library/Homebrew/postinstall.rb /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gnutls.rb
==> Regenerating CA certificate bundle from keychain, this may take a while...

@cho-m
Copy link
Member

@cho-m cho-m commented Jul 12, 2021

There aren't really any extra logs during the post-install, so it probably won't give much information without modifying the Formula with extra ohai/etc.

After running postinstall, can you check your /usr/local/etc/gnutls/cert.pem and see it has been modified with current timestamp and then check the data inside looks reasonable?

Maybe delete the file before rerunning postinstall to make sure it is getting generated.


If it gets generated with certificates, that should mean that at least first/last commands are working. Hard to tell what is exactly wrong in this situation though

  • Finding certificates: /usr/bin/security find-certificate -a -p /Library/Keychains/System.keychain /System/Library/Keychains/SystemRootCertificates.keychain
  • Writing PEM file: (pkgetc/"cert.pem").atomic_write(trusted_certs.join("\n") << "\n")

If there is a file generated but it is empty, there are multiple possibilities:

  • Find certificates not outputting correctly. Try the /usr/bin/security command on terminal to make sure output has BEGIN CERTIFICATE/etc.
  • Step to detect select non-expired certificates is seeing all your certificates as expired
  • Step to detect select trusted certificates is seeing all your certificates as untrusted

If no file is generated, that is an odd situation. I would expect something to error if this happened.

@TheRealGlumfish
Copy link
Author

@TheRealGlumfish TheRealGlumfish commented Jul 14, 2021

There aren't really any extra logs during the post-install, so it probably won't give much information without modifying the Formula with extra ohai/etc.

After running postinstall, can you check your /usr/local/etc/gnutls/cert.pem and see it has been modified with current timestamp and then check the data inside looks reasonable?

Maybe delete the file before rerunning postinstall to make sure it is getting generated.

If it gets generated with certificates, that should mean that at least first/last commands are working. Hard to tell what is exactly wrong in this situation though

  • Finding certificates: /usr/bin/security find-certificate -a -p /Library/Keychains/System.keychain /System/Library/Keychains/SystemRootCertificates.keychain
  • Writing PEM file: (pkgetc/"cert.pem").atomic_write(trusted_certs.join("\n") << "\n")

If there is a file generated but it is empty, there are multiple possibilities:

  • Find certificates not outputting correctly. Try the /usr/bin/security command on terminal to make sure output has BEGIN CERTIFICATE/etc.
  • Step to detect select non-expired certificates is seeing all your certificates as expired
  • Step to detect select trusted certificates is seeing all your certificates as untrusted

If no file is generated, that is an odd situation. I would expect something to error if this happened.

The file is definitely getting generated since when I run brew postinstall gnutls the manually generated file (which works correctly), stops working, meaning it is getting replaced with the one that brew is generating.

I found that when I run security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain it outputs a lot of certificates (more than the terminal buffer) so I assume it the 175 root certs.

So I ran $ security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain > /usr/local/etc/gnutls/cert.pem and low and behold it fixed the broken brew installation and gnutls worked as expected.

@TheRealGlumfish
Copy link
Author

@TheRealGlumfish TheRealGlumfish commented Jul 14, 2021

I wish I know and understood Ruby so I could troubleshoot the code. I checked the paths in the formula and they look fine.

Important note: When brew generates the certificates, gnutls finds 3, see below:

$ gnutls-cli youtube.com
Processed 0 CA certificate(s).
Resolving 'youtube.com:443'...
Connecting to '2a00:1450:4001:812::200e:443'...
- Certificate type: X.509
- Got a certificate list of 3 certificates.
- Certificate[0] info:
 - subject `CN=*.google.com', issuer `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', serial 0x39252e20e18cd90c0a00000000e8323f, EC/ECDSA key 256 bits, signed using RSA-SHA256, activated `2021-06-22 13:37:09 UTC', expires `2021-09-14 13:37:08 UTC', pin-sha256="s2UchvbdFUYc4gQ9IJRhM+ZK2FUud6gHzdM4WUHYOyg="
	Public Key ID:
		sha1:ccd1819a1c32aa65769076ba5453dadcf65bfa3a
		sha256:b3651c86f6dd15461ce2043d20946133e64ad8552e77a807cdd3385941d83b28
	Public Key PIN:
		pin-sha256:s2UchvbdFUYc4gQ9IJRhM+ZK2FUud6gHzdM4WUHYOyg=

- Certificate[1] info:
 - subject `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', issuer `CN=GTS Root R1,O=Google Trust Services LLC,C=US', serial 0x0203bc53596b34c718f5015066, RSA key 2048 bits, signed using RSA-SHA256, activated `2020-08-13 00:00:42 UTC', expires `2027-09-30 00:00:42 UTC', pin-sha256="zCTnfLwLKbS9S2sbp+uFz4KZOocFvXxkV06Ce9O5M2w="
- Certificate[2] info:
 - subject `CN=GTS Root R1,O=Google Trust Services LLC,C=US', issuer `CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE', serial 0x77bd0d6cdb36f91aea210fc4f058d30d, RSA key 4096 bits, signed using RSA-SHA256, activated `2020-06-19 00:00:42 UTC', expires `2028-01-28 00:00:42 UTC', pin-sha256="hxqRlPTu1bMS/0DITB1SSu0vd4u/8l8TjPgfaAp63Gc="
- Status: The certificate is NOT trusted. The certificate issuer is unknown.
*** PKI verification of server certificate failed...
*** Fatal error: Error in the certificate.

These three are from /Library/Keychains/System.keychain as running security find-certificate also yields three certificates (in that specific keychain), while when I manually generate them using either Keychain Access or security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain gnutls correctly identifies all 175 root certs.

Conclusion: for one reason or another the brew formula is not correctly adding the certificates from /System/Library/Keychains/SystemRootCertificates.keychain (to cert.pem) which are needed to connect to common websites and IRC.

@cho-m
Copy link
Member

@cho-m cho-m commented Jul 14, 2021

From your command, the important line is Processed 0 CA certificate(s).
On my system, I get Processed 166 CA certificate(s).

The 3 certificates should refer to what is received from website (similar to what you may see on your Web Browser when you click the "lock" icon on an HTTPS page)


Based on your reply, it is possible the certificates in /System/Library/Keychains/SystemRootCertificates.keychain are either seen as expired or untrusted.

Perhaps try:

  1. Copy a certificate to a file via:
    /usr/bin/security find-certificate -p /System/Library/Keychains/SystemRootCertificates.keychain > test.pem
    
  2. Do the check for expiration (should output 0):
    openssl x509 -inform pem -checkend 0 -noout -in test.pem; echo $?
    
  3. Do the check for trust status (should output a line of text and then 0)
    /usr/bin/security verify-cert -l -L -R offline -c test.pem; echo $?
    

@TheRealGlumfish
Copy link
Author

@TheRealGlumfish TheRealGlumfish commented Jul 14, 2021

/usr/bin/security verify-cert -l -L -R offline -c test.pem; echo $?

The commands ran successfully, the root certs seem fine because when cert.pem is generated manually gnutls says Processed 175 CA certificate(s). and is able to successfully connect to the server with SSL.

@cho-m
Copy link
Member

@cho-m cho-m commented Jul 17, 2021

Hard to say why your system is filtering out the certificates.
Maybe add some extra print statements to postinstall like:

--- a/Formula/gnutls.rb
+++ b/Formula/gnutls.rb
@@ -88,6 +88,7 @@ class Gnutls < Formula
     certs = certs_list.scan(
       /-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----/m,
     )
+    ohai "#{certs.length} certificates found"

     # Check that the certificate has not expired
     valid_certs = certs.select do |cert|
@@ -98,6 +99,7 @@ class Gnutls < Formula

       $CHILD_STATUS.success?
     end
+    ohai "#{valid_certs.length} non-expired certificates"

     # Check that the certificate is trusted in keychain
     trusted_certs = begin
@@ -115,6 +117,7 @@ class Gnutls < Formula
     ensure
       tmpfile&.close!
     end
+    ohai "#{trusted_certs.length} trusted certificates"

     pkgetc.mkpath
     (pkgetc/"cert.pem").atomic_write(trusted_certs.join("\n") << "\n")

And then rerun the postinstall step like:

brew postinstall gnutls
==> Postinstalling gnutls
==> Regenerating CA certificate bundle from keychain, this may take a while...
==> 169 certificates found
==> 166 non-expired certificates
==> 166 trusted certificates

To try to see where the number of certificates drop.

@TheRealGlumfish
Copy link
Author

@TheRealGlumfish TheRealGlumfish commented Jul 17, 2021

Hard to say why your system is filtering out the certificates.
Maybe add some extra print statements to postinstall like:

--- a/Formula/gnutls.rb
+++ b/Formula/gnutls.rb
@@ -88,6 +88,7 @@ class Gnutls < Formula
     certs = certs_list.scan(
       /-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----/m,
     )
+    ohai "#{certs.length} certificates found"

     # Check that the certificate has not expired
     valid_certs = certs.select do |cert|
@@ -98,6 +99,7 @@ class Gnutls < Formula

       $CHILD_STATUS.success?
     end
+    ohai "#{valid_certs.length} non-expired certificates"

     # Check that the certificate is trusted in keychain
     trusted_certs = begin
@@ -115,6 +117,7 @@ class Gnutls < Formula
     ensure
       tmpfile&.close!
     end
+    ohai "#{trusted_certs.length} trusted certificates"

     pkgetc.mkpath
     (pkgetc/"cert.pem").atomic_write(trusted_certs.join("\n") << "\n")

And then rerun the postinstall step like:

❯ brew postinstall gnutls
==> Postinstalling gnutls
==> Regenerating CA certificate bundle from keychain, this may take a while...
==> 169 certificates found
==> 166 non-expired certificates
==> 166 trusted certificates

To try to see where the number of certificates drop.

Sorry for the stupid question but how could I apply the patch to the formula locally?

@carlocab
Copy link
Member

@carlocab carlocab commented Jul 17, 2021

You can do

brew edit gnutls

and apply the patch manually.

Don't forget to

git -C $(brew --repo homebrew/core) restore Formula/gnutls.rb

when you're done to undo your changes.

@TheRealGlumfish
Copy link
Author

@TheRealGlumfish TheRealGlumfish commented Jul 17, 2021

Output with added debug info is:

$ brew postinstall gnutls
==> Postinstalling gnutls                                                   
==> Regenerating CA certificate bundle from keychain, this may take a while...             
==> 178 certificates found                     
==> 165 non-expired certificates
==> 165 trusted certificates

@cho-m
Copy link
Member

@cho-m cho-m commented Jul 17, 2021

==> 178 certificates found                     
==> 165 non-expired certificates
==> 165 trusted certificates

Now I am not sure what is happening as postinstall sees 165 certificates before writing the file.

The last easy thing to check would be the size/permissions of the file, e.g.

ls -al "$(brew --prefix)/etc/gnutls/"
total 260
drwxr-xr-x  3 cho-m admin     96 Jul 16 19:27 .
drwxrwxr-x 28 cho-m admin    896 Jul 16 14:09 ..
-rw-r--r--  1 cho-m admin 264162 Jul 16 19:27 cert.pemwc "$(brew --prefix)/etc/gnutls/cert.pem"
    4334    4666  264162 /usr/local/etc/gnutls/cert.pemgrep "BEGIN CERT" "$(brew --prefix)/etc/gnutls/cert.pem" | wc -l
     166

@farrokhi
Copy link

@farrokhi farrokhi commented Jul 18, 2021

Seems like I get totally different results when selecting all certificates under System Roots in Keychain.app and export them, versus running following command:

/usr/bin/security find-certificate -a -p  /Library/Keychains/System.keychain 
 /System/Library/Keychains/SystemRootCertificates.keychain
% grep -c BEGIN cert.pem*
cert.pem-from-cli:166
cert.pem-from-keychain-app:163

and using the certificates exported using Keychain.app solves the problem:

% cat cert.pem-from-keychain-app > /usr/local/etc/gnutls/cert.pem 

% % gnutls-cli smtp.gmail.com:465
Processed 163 CA certificate(s).
Resolving 'smtp.gmail.com:465'...
Connecting to '142.250.102.108:465'...
- Certificate type: X.509
- Got a certificate list of 3 certificates.
- Certificate[0] info:
 - subject `CN=smtp.gmail.com', issuer `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', serial 0x00889863079c163dae0a00000000e83cf8, EC/ECDSA key 256 bits, signed using RSA-SHA256, activated `2021-06-22 15:17:51 UTC', expires `2021-09-14 15:17:50 UTC', pin-sha256="0LWSINe8vapuFk8LOeBz2gAm1mMdyVv7w3frAKo58NI="
	Public Key ID:
		sha1:db20f5800ccc0b10f186e1b13a08fdd955ad58e6
		sha256:d0b59220d7bcbdaa6e164f0b39e073da0026d6631dc95bfbc377eb00aa39f0d2
	Public Key PIN:
		pin-sha256:0LWSINe8vapuFk8LOeBz2gAm1mMdyVv7w3frAKo58NI=

- Certificate[1] info:
 - subject `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', issuer `CN=GTS Root R1,O=Google Trust Services LLC,C=US', serial 0x0203bc53596b34c718f5015066, RSA key 2048 bits, signed using RSA-SHA256, activated `2020-08-13 00:00:42 UTC', expires `2027-09-30 00:00:42 UTC', pin-sha256="zCTnfLwLKbS9S2sbp+uFz4KZOocFvXxkV06Ce9O5M2w="
- Certificate[2] info:
 - subject `CN=GTS Root R1,O=Google Trust Services LLC,C=US', issuer `CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE', serial 0x77bd0d6cdb36f91aea210fc4f058d30d, RSA key 4096 bits, signed using RSA-SHA256, activated `2020-06-19 00:00:42 UTC', expires `2028-01-28 00:00:42 UTC', pin-sha256="hxqRlPTu1bMS/0DITB1SSu0vd4u/8l8TjPgfaAp63Gc="
- Status: The certificate is trusted. 
- Description: (TLS1.3-X.509)-(ECDHE-X25519)-(ECDSA-SECP256R1-SHA256)-(AES-256-GCM)
- Options:
- Handshake was completed

- Simple Client Mode:

220 smtp.gmail.com ESMTP u20sm6211858edr.50 - gsmtp
^C

@farrokhi
Copy link

@farrokhi farrokhi commented Jul 18, 2021

I guess I found the culprit. Removing /Library/Keychains/System.keychain when exporting from CLI seems to have solved the problem.

with System.keychain:

 % /usr/bin/security find-certificate -a -p  /Library/Keychains/System.keychain  /System/Library/Keychains/SystemRootCertificates.keychain  > /usr/local/etc/gnutls/cert.pem

% gnutls-cli smtp.gmail.com:465
Processed 0 CA certificate(s).
Resolving 'smtp.gmail.com:465'...
Connecting to '142.250.102.108:465'...
- Certificate type: X.509
- Got a certificate list of 3 certificates.
- Certificate[0] info:
 - subject `CN=smtp.gmail.com', issuer `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', serial 0x00889863079c163dae0a00000000e83cf8, EC/ECDSA key 256 bits, signed using RSA-SHA256, activated `2021-06-22 15:17:51 UTC', expires `2021-09-14 15:17:50 UTC', pin-sha256="0LWSINe8vapuFk8LOeBz2gAm1mMdyVv7w3frAKo58NI="
    Public Key ID:
        sha1:db20f5800ccc0b10f186e1b13a08fdd955ad58e6
        sha256:d0b59220d7bcbdaa6e164f0b39e073da0026d6631dc95bfbc377eb00aa39f0d2
    Public Key PIN:
        pin-sha256:0LWSINe8vapuFk8LOeBz2gAm1mMdyVv7w3frAKo58NI=

- Certificate[1] info:
 - subject `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', issuer `CN=GTS Root R1,O=Google Trust Services LLC,C=US', serial 0x0203bc53596b34c718f5015066, RSA key 2048 bits, signed using RSA-SHA256, activated `2020-08-13 00:00:42 UTC', expires `2027-09-30 00:00:42 UTC', pin-sha256="zCTnfLwLKbS9S2sbp+uFz4KZOocFvXxkV06Ce9O5M2w="
- Certificate[2] info:
 - subject `CN=GTS Root R1,O=Google Trust Services LLC,C=US', issuer `CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE', serial 0x77bd0d6cdb36f91aea210fc4f058d30d, RSA key 4096 bits, signed using RSA-SHA256, activated `2020-06-19 00:00:42 UTC', expires `2028-01-28 00:00:42 UTC', pin-sha256="hxqRlPTu1bMS/0DITB1SSu0vd4u/8l8TjPgfaAp63Gc="
- Status: The certificate is NOT trusted. The certificate issuer is unknown. 
*** PKI verification of server certificate failed...
*** Fatal error: Error in the certificate.

without System.keychain:

% /usr/bin/security find-certificate -a -p    /System/Library/Keychains/SystemRootCertificates.keychain  > /usr/local/etc/gnutls/cert.pem

% gnutls-cli smtp.gmail.com:465
Processed 166 CA certificate(s).
Resolving 'smtp.gmail.com:465'...
Connecting to '142.250.102.108:465'...
- Certificate type: X.509
- Got a certificate list of 3 certificates.
- Certificate[0] info:
 - subject `CN=smtp.gmail.com', issuer `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', serial 0x00889863079c163dae0a00000000e83cf8, EC/ECDSA key 256 bits, signed using RSA-SHA256, activated `2021-06-22 15:17:51 UTC', expires `2021-09-14 15:17:50 UTC', pin-sha256="0LWSINe8vapuFk8LOeBz2gAm1mMdyVv7w3frAKo58NI="
    Public Key ID:
        sha1:db20f5800ccc0b10f186e1b13a08fdd955ad58e6
        sha256:d0b59220d7bcbdaa6e164f0b39e073da0026d6631dc95bfbc377eb00aa39f0d2
    Public Key PIN:
        pin-sha256:0LWSINe8vapuFk8LOeBz2gAm1mMdyVv7w3frAKo58NI=

- Certificate[1] info:
 - subject `CN=GTS CA 1C3,O=Google Trust Services LLC,C=US', issuer `CN=GTS Root R1,O=Google Trust Services LLC,C=US', serial 0x0203bc53596b34c718f5015066, RSA key 2048 bits, signed using RSA-SHA256, activated `2020-08-13 00:00:42 UTC', expires `2027-09-30 00:00:42 UTC', pin-sha256="zCTnfLwLKbS9S2sbp+uFz4KZOocFvXxkV06Ce9O5M2w="
- Certificate[2] info:
 - subject `CN=GTS Root R1,O=Google Trust Services LLC,C=US', issuer `CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE', serial 0x77bd0d6cdb36f91aea210fc4f058d30d, RSA key 4096 bits, signed using RSA-SHA256, activated `2020-06-19 00:00:42 UTC', expires `2028-01-28 00:00:42 UTC', pin-sha256="hxqRlPTu1bMS/0DITB1SSu0vd4u/8l8TjPgfaAp63Gc="
- Status: The certificate is trusted. 
- Description: (TLS1.3-X.509)-(ECDHE-X25519)-(ECDSA-SECP256R1-SHA256)-(AES-256-GCM)
- Options:
- Handshake was completed

- Simple Client Mode:

220 smtp.gmail.com ESMTP e7sm1100436edk.3 - gsmtp

@romankulikov
Copy link
Contributor

@romankulikov romankulikov commented Jul 23, 2021

I met the same issue with openconnect has became broken after recent update of Homebrew. Digging deeper showed that now gnutls gets all certificates from System keychain into its trust store. This keychain contains certificates "com.apple.kerberos.kdc". On some macOS systems such certificates may have duplicating extensions which makes them invalid for gnutls. But due to the logic bug gnutls drops the whole trust store if such certificate is met. That's why some of us get Processed 0 CA certificate(s). when running gnutls-cli.

Here's the ticket I've filed to gnutls upstream: https://gitlab.com/gnutls/gnutls/-/issues/1255.

From my point we need to manually filter out either certs with duplicating extensions or all "com.apple.kerberos.kdc" when building trust store.

romankulikov added a commit to romankulikov/homebrew-core that referenced this issue Jul 25, 2021
Due to [1] gnutls may drop the whole trust store if there's at least one
certificate with duplicating extensions. I'm not 100% sure but most
likely macOS may have "com.apple.kerberos.kdc" certificate to be of such
kind. So let's filter them out when building trust store.

[1] https://gitlab.com/gnutls/gnutls/-/issues/1255

(Homebrew#81022)
@github-actions
Copy link

@github-actions github-actions bot commented Aug 14, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Aug 14, 2021
@TheRealGlumfish
Copy link
Author

@TheRealGlumfish TheRealGlumfish commented Aug 16, 2021

Has this been fixed in the end (upsteam)?

@github-actions github-actions bot removed the stale label Aug 16, 2021
@romankulikov
Copy link
Contributor

@romankulikov romankulikov commented Aug 17, 2021

Has this been fixed in the end (upsteam)?

My pull request with suggested fix is still not approved.

@github-actions
Copy link

@github-actions github-actions bot commented Sep 8, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Sep 8, 2021
carlocab pushed a commit that referenced this issue Sep 8, 2021
Due to [1] gnutls may drop the whole trust store if there's at least one
certificate with duplicating extensions. I'm not 100% sure but most
likely macOS may have "com.apple.kerberos.kdc" certificate to be of such
kind. So let's filter them out when building trust store.

[1] https://gitlab.com/gnutls/gnutls/-/issues/1255

(#81022)
@carlocab
Copy link
Member

@carlocab carlocab commented Sep 8, 2021

Closed in #81851.

Apologies for the delay here!

@carlocab carlocab closed this Sep 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
@farrokhi @gromgit @SMillerDev @romankulikov @cho-m @carlocab @TheRealGlumfish and others