mozilla-services / autograph

Mozilla's digital signature service
https://hub.docker.com/r/mozilla/autograph/
Mozilla Public License 2.0
152 stars 33 forks source link

crypto11: handle nil returns from pcks11.New #1034

Closed jmhodges closed 1 month ago

jmhodges commented 1 month ago

Previous to this patch, a busted Path configuration passed to crypto11 would cause nil pointer panics.

This is because attempt to check the nil pointer of the PKCS11Context interface would run into the usual "nil interface" problems where the pointer would not be technically "nil" but calling methods on it would cause nil pointer panics. See https://go.dev/tour/methods/12 and https://trstringer.com/go-nil-interface-and-interface-with-nil-concrete-value/ for details.

So, to handle this correctly, we need to return an error along with our interface context type.

It's pretty surprising that pkcs11.New can return nil, but we do what we must.

Updates AUT-283