use timestamp from challenge, fallback to local time
This commit is contained in:
parent
cb42e607c5
commit
70d31c1e9a
@ -20,9 +20,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type registryChallenge struct {
|
type registryChallenge struct {
|
||||||
Realm string
|
Realm string
|
||||||
Service string
|
Service string
|
||||||
Scope string
|
Scope string
|
||||||
|
Timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r registryChallenge) URL() (*url.URL, error) {
|
func (r registryChallenge) URL() (*url.URL, error) {
|
||||||
@ -37,7 +38,7 @@ func (r registryChallenge) URL() (*url.URL, error) {
|
|||||||
values.Add("scope", s)
|
values.Add("scope", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
values.Add("ts", strconv.FormatInt(time.Now().Unix(), 10))
|
values.Add("ts", strconv.FormatInt(r.Timestamp.Unix(), 10))
|
||||||
|
|
||||||
nonce, err := auth.NewNonce(rand.Reader, 16)
|
nonce, err := auth.NewNonce(rand.Reader, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ollama/ollama/api"
|
"github.com/ollama/ollama/api"
|
||||||
"github.com/ollama/ollama/auth"
|
"github.com/ollama/ollama/auth"
|
||||||
@ -1111,10 +1112,16 @@ func getValue(header, key string) string {
|
|||||||
func parseRegistryChallenge(authStr string) registryChallenge {
|
func parseRegistryChallenge(authStr string) registryChallenge {
|
||||||
authStr = strings.TrimPrefix(authStr, "Bearer ")
|
authStr = strings.TrimPrefix(authStr, "Bearer ")
|
||||||
|
|
||||||
|
s, err := strconv.ParseInt(getValue(authStr, "timestamp"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
s = time.Now().Unix()
|
||||||
|
}
|
||||||
|
|
||||||
return registryChallenge{
|
return registryChallenge{
|
||||||
Realm: getValue(authStr, "realm"),
|
Realm: getValue(authStr, "realm"),
|
||||||
Service: getValue(authStr, "service"),
|
Service: getValue(authStr, "service"),
|
||||||
Scope: getValue(authStr, "scope"),
|
Scope: getValue(authStr, "scope"),
|
||||||
|
Timestamp: time.Unix(s, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user