Problem with pkg upgrade - certificate verification failed - SOLVED

I am running 14.5-RELEASE. When I run 'pkg upgrade', I now get a long series of error messages complaining about ssl certificate verification failures. I am currently unable to upgrade any packages.

# pkg upgrade 2>&1 | tee out
Updating FreeBSD repository catalogue...
Certificate verification failed for /CN=pkg.freebsd.org
10A0862BE62D0000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:/usr/src/crypto/openssl/ssl/statem/statem_clnt.c:1890:
Certificate verification failed for /CN=pkg.freebsd.org
10A0862BE62D0000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:/usr/src/crypto/openssl/ssl/statem/statem_clnt.c:1890:
...

The error message repeats many time. Full output is here https://termbin.com/ixwz

Does anyone know what has gone wrong?
 
Well, you were right, thanks for the hint! Chrony had stopped working for some reason and it was about 12 hours behind. Strange as it's been working for weeks. I switched over to ntpd and now everything is working again, the pkg upgrade now works. I noticed something was wrong with name service earlier too, it couldn't resolve certain names, although others worked normally. Perhaps a problem in the upstream nameservers (cloudflare). It's all working again now. I may have screwed up the chrony config of course. I'll leave it running on ntpd for the time being, I'll go back and check the chrony config when I have some time.
 
Something strange was happening in addition to the ssl cert problem, because I couldn't get network names resolved for some (but not all) sites, at the same time as I saw the ssl cert errors. The system could resolve google.com, yahoo.com, but not some uk sites, it couldn't resolve bbc.co.uk for example and came back with "name not found". It was able to resolve freebsd.org. I left it for perhaps 8 or 9 hours and tried it again, at whicn point I found name service was all working normally again, without my having changed anything. I am using local unbound, configured to talk to cloudflare dns servers, with the secure dns protocol. So it looks like something wasn't fully working in the dns chain at the time I got the ssl cert errors. However, once dns started working properly again, I still got the ssl cert errors from pkg upgrade until I switched over from chrony to ntpd and got time sync working correctly, at which point pkg upgrade worked again. It's all a bit strange because I've been running chrony for a while and pkg upgrade has been working normally, but perhaps if the clock drifts enough that might cause a problem, it may be that I didn't spot the clock drift previously. I'm sure there's a logical explanation but it's probably not worth debugging it in depth unless it starts happening more often, this is only the the first time I have ever seen this issue. Anyhow everything is back up and running normally now.
 
I had a similar problem with chrony when I changed motherboards, and it didn't set the time. By default chrony isn't allowed to step the system clock, and 12 hours would take nearly 3 years to fix by slewing.

In /usr/local/etc/chrony.conf, there is a commented out makestep setting. I set mine to "makestep 20 1" to avoid stepping in normal circumstances.

I'm doubtful that chrony caused the problem. You might want to have a look at your own user scripts and see if anything might be misusing date(1).
 
Yes I need to revisit my chrony config, I probably missed some steps, for the time being I've switched back to ntpd. Good point about scripts, I'll check to make sure. I have a hunch the partial name service outage I had was something to do with this problem too, it's too much of a co-incidence that it happened at the same time as I got those ssl cert error messages from pkg.
 
I am using local unbound, configured to talk to cloudflare dns servers, with the secure dns protocol.
which also needs a correct time to work properly. the sites that kept working most likely had a longer TTL and were still cached.

Seriously - why would you want to replace the standard ntp daemon? NTP has been a solved problem for 40 years (41 actually) and the standard implementation (i.e. ntpd) just works. Unless we're talking Windows (for MS ntp like many other things is still an unsolved problem and their implementation does not work reliably / at all) there is absolutely no need to replace the standard ntp daemon...
 
Chrony is just another ntp client, a modern re-write. It's supposed to have better support for intermittent network connections, as on a laptop, which is what I'm using.
For example see:-

There is a more detailed discussion of some of the pros and cons here https://anarc.at/blog/2022-01-23-chrony/ , chrony does appear to have some advantages. For the time being I've switched back to ntpd, as you say, that is known to work.
 
Chrony is just another ntp client, a modern re-write. It's supposed to have better support for intermittent network connections, as on a laptop, which is what I'm using.
"supposed to" seems to be the important bit here... TBH to me this sounds more like an attempt to fix something that isn't broken.
As said: ntpd just works. I also use it on my laptop which often isn't used for days or even weeks. If your clock drifts considerably in that time so ntp can't catch up, you should replace its RTC/BIOS battery. Also there's always the 'ntpd_sync_on_start' option for rc.conf(5) to bring systems with a low-quality RTC back in sync at boot.
On a laptop that has no uplink at boot, a dhclient-exit-hook that (re-)starts ntpd with the -g flag is also a viable solution.
 
which also needs a correct time to work properly. the sites that kept working most likely had a longer TTL and were still cached.
Maybe. But if a name is not found in its lru cache, unbound should go out to the upstream dns server to resolve the name, and the network was up, I checked that I could ping the upstream servers. But perhaps unbound also had a problem connecting to upstream over dnssec, and failed silently. I could attempt to recreate the bug by setting up a similar clock skew and see if the same behaviour occurs again, and then investigate it in detail, but I have too many other calls on my time at present. I guess it's plausible, perhaps probable, but not yet proven, that clock skew was the root cause of the problem here. If I get some time I will try and see if I can recreate the behaviour.
 
Hahaha, yes I read that a while back, that was written 9 years ago so it's probably even worse now. I've actually been switching between opendns (cisco), google public dns and cloudflare, at the moment it's set up to use the latter. Yes they get a lot of bad press, this one will run and run. I haven't seen the captchas that article talks about, on sites that I visit. It does seem to be reliable. At least you get a warm fuzzy feeling that your dns request was 'secure' and protected from dns spoofing, but whether any of these companies (including quad9, that seems to be the current favourite) can really be trusted is an open question. As the old saying goes, "if it's free, you are the product".
 
google and cloudflare are first and foremost data-mongering companies, so all your queries to their servers will be used to further increase the value of the dataset they already gather about you (which they of course sell to whoever pays good money for it).
So for simple forwarding nameservers in small-scale networks quad9 is the way to go; otherwise or if you have more than a handful of hosts just run a recursive resolver in your network (which can be also used as an authorative NS for your local zone). Both will circumvent local dns blacklisting/hijacking, which sadly is rather common at ISP nameservers. For added security you might use TLS and/or DNSSEC - both will have the caveat that system time on that local nameserver *has* to be reasonably precise. (This should obviously be mandatory for a server, but since I've seen more than enough threads about raspberries or other toys being misused as 'servers', I better mention it...)
 
Yes I'm using dnssec and tls (DoT). Perhaps you're right about the clock skew being the root problem, it certainly seems plausible, but I would need to experiment with a recreate and define a testcase to prove it. I should probably get around to giving quad9 a try some time. As to whether any of these companies are really any better than the others, or whether you can trust their public assurances, I am skeptical. You have to ask the question, how do any of them (even self-declared 'non-profit's) fund the free service. Anyhow, this is drifting into a different area of discussion.
 
Back
Top