mirror of
https://github.com/distribution/distribution.git
synced 2025-06-25 23:13:50 +00:00
Merge 4c82daa1be
into da404778ed
This commit is contained in:
commit
33aa7f7d2e
@ -354,6 +354,9 @@ func newAccessController(options map[string]interface{}) (auth.AccessController,
|
|||||||
if key := GetJWKThumbprint(rootCert.PublicKey); key != "" {
|
if key := GetJWKThumbprint(rootCert.PublicKey); key != "" {
|
||||||
trustedKeys[key] = rootCert.PublicKey
|
trustedKeys[key] = rootCert.PublicKey
|
||||||
}
|
}
|
||||||
|
if key := GetLibtrustKeyID(rootCert.PublicKey); key != "" {
|
||||||
|
trustedKeys[key] = rootCert.PublicKey
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if jwks != nil {
|
if jwks != nil {
|
||||||
|
@ -143,8 +143,8 @@ func TestRootCertIncludedInTrustedKeys(t *testing.T) {
|
|||||||
// newAccessController return type is an interface built from
|
// newAccessController return type is an interface built from
|
||||||
// accessController struct. The type check can be safely ignored.
|
// accessController struct. The type check can be safely ignored.
|
||||||
ac2, _ := ac.(*accessController)
|
ac2, _ := ac.(*accessController)
|
||||||
if got := len(ac2.trustedKeys); got != 1 {
|
if got := len(ac2.trustedKeys); got != 2 {
|
||||||
t.Fatalf("Unexpected number of trusted keys, expected 1 got: %d", got)
|
t.Fatalf("Unexpected number of trusted keys, expected 2 got: %d", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
package token
|
package token
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"crypto/x509"
|
||||||
|
"encoding/base32"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// actionSet is a special type of stringSet.
|
// actionSet is a special type of stringSet.
|
||||||
@ -101,3 +105,26 @@ func getJWKThumbprint(publickey crypto.PublicKey, skipED25519 bool) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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…
Reference in New Issue
Block a user