-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interface for certs/signer fetching to remove mutex
For all but the file CA implementation, locking when retrieving the certs/signer is not necessary. This refactors the intermediate CA struct by embedding an interface to fetch the certs/signer. Each CA type can use either the basic structure that simply returns certs/signer, or one that has a mutex to protect access to the variables. This also fixes a bug with the mutex. File CA used a different lock than the intermediate CA struct, so locking while writing wouldn't have actually protected against concurrent reads. This fixes it by moving the mutex to the certs/signer struct, and file CA reaches into that struct to lock while writing. Also small test fix - go 1.18 checks for duplicate extensions in certs now, so I had to regenerate a test certificate. Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
- Loading branch information
1 parent
30dba00
commit b732504
Showing
13 changed files
with
170 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIBTzCCAQGgAwIBAgIUBO1MTUDAijUkpFiDr53xJJmPxLAwBQYDK2VwMBIxEDAO | ||
BgNVBAMMB29wZW5zc2wwIBcNMjIwMTE4MjAzOTU1WhgPMjEyMTEyMjUyMDM5NTVa | ||
MBIxEDAOBgNVBAMMB29wZW5zc2wwKjAFBgMrZXADIQBCrnxleddPY3TkNV8DtEWJ | ||
9Avw/w17xtYhgVqzBOdOTaNnMGUwHQYDVR0OBBYEFA9ssW0mYnwHXMmdlADKaJaY | ||
Ie7TMB8GA1UdIwQYMBaAFA9ssW0mYnwHXMmdlADKaJaYIe7TMA8GA1UdEwEB/wQF | ||
MAMBAf8wEgYDVR0TAQH/BAgwBgEB/wIBATAFBgMrZXADQQCo2r09KAdu78YhQF1m | ||
SVgxm1jgsoA/tAjKmzLi6sAuOV57WDd1vmMpu1ggqeaeQhzXNH4Qm76c+XUPBY2n | ||
fkUB | ||
MIIBPTCB8KADAgECAhQOFCGq1F/UFACHhW2z51EE+dodDTAFBgMrZXAwEjEQMA4G | ||
A1UEAwwHb3BlbnNzbDAgFw0yMjA2MTAwNDUzMzZaGA8yMTIyMDUxNzA0NTMzNlow | ||
EjEQMA4GA1UEAwwHb3BlbnNzbDAqMAUGAytlcAMhAHoP6VgvmjkF7TQktmsqA2WD | ||
FKuEus/Uf1IV+heG91lQo1YwVDAdBgNVHQ4EFgQUZx7Tvdvg0FtL4NwBHyq+vEdA | ||
KUswHwYDVR0jBBgwFoAUZx7Tvdvg0FtL4NwBHyq+vEdAKUswEgYDVR0TAQH/BAgw | ||
BgEB/wIBATAFBgMrZXADQQDWdhDWFYcX5dDmHuPi3MpgX5lyR+7yOA5keUVWQU8U | ||
62DPFRRsfcpmWELx/RNQD/OgdIUZ9/YTPgFBoTngeD4G | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
-----BEGIN ENCRYPTED PRIVATE KEY----- | ||
MIGKME4GCSqGSIb3DQEFDTBBMCkGCSqGSIb3DQEFDDAcBAifqugsEv+5eQICCAAw | ||
DAYIKoZIhvcNAgkFADAUBggqhkiG9w0DBwQIsETz73+d0CkEOEfccSS2FSSCYchJ | ||
61nyishJ4/AFxpsG5935bt+UvfcaUALH1RKQkwNvoGbry6afYY+qvW+LNy6g | ||
MIGKME4GCSqGSIb3DQEFDTBBMCkGCSqGSIb3DQEFDDAcBAjrbQwLQsaVYgICCAAw | ||
DAYIKoZIhvcNAgkFADAUBggqhkiG9w0DBwQIo5IbVAAU0f8EOEZix/CL4zM7FCfN | ||
RlNM1GD99ZEouGO5jEae7q0medijaG1IbD4y4B90nLuQfc4aDlIMG5AyA8wP | ||
-----END ENCRYPTED PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2022 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package ca | ||
|
||
import ( | ||
"crypto" | ||
"crypto/x509" | ||
"sync" | ||
) | ||
|
||
// SignerWithChain provides a getter for a CA's certificate chain and signing key. | ||
type SignerWithChain interface { | ||
GetSignerWithChain() ([]*x509.Certificate, crypto.Signer) | ||
} | ||
|
||
// SignerCerts holds a certificate chain and signer. | ||
type SignerCerts struct { | ||
// Signer signs issued certificates | ||
Signer crypto.Signer | ||
// Certs contains the chain of certificates from intermediate to root | ||
Certs []*x509.Certificate | ||
} | ||
|
||
func (s *SignerCerts) GetSignerWithChain() ([]*x509.Certificate, crypto.Signer) { | ||
return s.Certs, s.Signer | ||
} | ||
|
||
// SignerCertsMutex holds a certificate chain and signer, and holds a reader lock | ||
// when accessing the chain and signer. Use if a separate thread can concurrently | ||
// update the chain and signer. | ||
type SignerCertsMutex struct { | ||
sync.RWMutex | ||
|
||
// Certs contains the chain of certificates from intermediate to root | ||
Certs []*x509.Certificate | ||
// Signer signs issued certificates | ||
Signer crypto.Signer | ||
} | ||
|
||
func (s *SignerCertsMutex) GetSignerWithChain() ([]*x509.Certificate, crypto.Signer) { | ||
s.RLock() | ||
defer s.RUnlock() | ||
|
||
return s.Certs, s.Signer | ||
} |
Oops, something went wrong.