10000 Load libtrust KeyIDs from token certificate bundle by brandond · Pull Request #4521 · distribution/distribution · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Load libtrust KeyIDs from token certificate bundle #4521

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions registry/auth/token/accesscontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ func newAccessController(options map[string]interface{}) (auth.AccessController,
if key := GetRFC7638Thumbprint(rootCert.PublicKey); key != "" {
trustedKeys[key] = rootCert.PublicKey
}
if key := GetLibtrustKeyID(rootCert.PublicKey); key != "" {
trustedKeys[key] = rootCert.PublicKey
}
}

if jwks != nil {
Expand Down
4 changes: 2 additions & 2 deletions registry/auth/token/accesscontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func TestRootCertIncludedInTrustedKeys(t *testing.T) {
// newAccessController return type is an interface built from
// accessController struct. The type check can be safely ignored.
ac2, _ := ac.(*accessController)
if got := len(ac2.trustedKeys); got != 1 {
t.Fatalf("Unexpected number of trusted keys, expected 1 got: %d", got)
if got := len(ac2.trustedKeys); got != 2 {
t.Fatalf("Unexpected number of trusted keys, expected 2 got: %d", got)
}
}

Expand Down
27 changes: 27 additions & 0 deletions registry/auth/token/util.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package token

import (
"bytes"
"crypto"
"crypto/ecdsa"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/base32"
"encoding/base64"
"fmt"
"math/big"
"strings"
)

// actionSet is a special type of stringSet.
Expand Down Expand Up @@ -84,3 +88,26 @@ func GetRFC7638Thumbprint(publickey crypto.PublicKey) string {

return hashAndEncode(payload)
}

// Returns a libtrust-compatible Key ID, for backwards compatibility
// with JWT headers expected by distribution/v2
func GetLibtrustKeyID(publickey crypto.PublicKey) string {
keyBytes, err := x509.MarshalPKIXPublicKey(publickey)
if err != nil {
return ""
}

sum := sha256.Sum256(keyBytes)
b64 := strings.TrimRight(base32.StdEncoding.EncodeToString(sum[:30]), "=")

var buf bytes.Buffer
var i int
for i = 0; i < len(b64)/4-1; i++ {
start := i * 4
end := start + 4
buf.WriteString(b64[start:end] + ":")
}
buf.WriteString(b64[i*4:])

return buf.String()
}
Loading
0