timecheck

This commit is contained in:
Josh Yan 2024-07-17 14:53:29 -07:00
parent 8548d1d596
commit 09431f353d
2 changed files with 11 additions and 0 deletions

View File

@ -343,6 +343,7 @@ func getLocalPath(ctx context.Context, digest string) (string, error) {
}
request.Header.Set("Authorization", authz)
request.Header.Set("Timestamp", time.Now().Format(time.RFC3339))
request.Header.Set("User-Agent", fmt.Sprintf("ollama/%s (%s %s) Go/%s", version.Version, runtime.GOARCH, runtime.GOOS, runtime.Version()))
request.Header.Set("X-Redirect-Create", "1")

View File

@ -997,6 +997,16 @@ func (s *Server) IsServerKeyPublicKey(c *gin.Context) bool {
serverPublicKey, err := auth.GetPublicKey()
if err != nil {
slog.Error(fmt.Sprintf("failed to get server public key: %v", err))
return false
}
timestamp, err := time.Parse(time.RFC3339, c.GetHeader("Timestamp"))
if err != nil {
return false
}
if time.Since(timestamp) > time.Minute {
return false
}
if bytes.Equal(serverPublicKey.Marshal(), clientPublicKey.Marshal()) {