Compare commits
3 Commits
2024.3.4-s
...
2024.3.4-s
Author | SHA1 | Date | |
---|---|---|---|
0b34b485da | |||
ab08d30d2a | |||
f6ffb68c43 |
@ -183,7 +183,7 @@ func assertMatchingAgent() assertAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
agent := u.Agent()
|
agent := u.Agent()
|
||||||
if agent != nil && agent.ID == agentID {
|
if agent != nil && agent.ID == agentID && agent.Status == datastore.AgentStatusAccepted {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ func (m *Mount) registerAgent(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !validSignature {
|
if !validSignature {
|
||||||
logger.Warn(ctx, "conflicting signature", logger.F("signature", registerAgentReq.Signature))
|
logger.Warn(ctx, "invalid thumbprint signature", logger.F("signature", registerAgentReq.Signature))
|
||||||
api.ErrorResponse(w, http.StatusConflict, ErrCodeConflict, nil)
|
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeInvalidRequest, nil)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -109,29 +109,39 @@ func (m *Mount) registerAgent(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
validSignature, err = jwk.Verify(agent.KeySet.Set, registerAgentReq.Signature, registerAgentReq.Thumbprint, registerAgentReq.Metadata)
|
if agent.Status != datastore.AgentStatusForgotten {
|
||||||
if err != nil {
|
validSignature, err = jwk.Verify(agent.KeySet.Set, registerAgentReq.Signature, registerAgentReq.Thumbprint, registerAgentReq.Metadata)
|
||||||
err = errors.WithStack(err)
|
if err != nil {
|
||||||
logger.Error(ctx, "could not validate signature using previous keyset", logger.CapturedE(err))
|
err = errors.WithStack(err)
|
||||||
|
logger.Error(ctx, "could not validate signature using previous keyset", logger.CapturedE(err))
|
||||||
|
|
||||||
api.ErrorResponse(w, http.StatusConflict, ErrCodeConflict, nil)
|
api.ErrorResponse(w, http.StatusConflict, ErrCodeConflict, nil)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !validSignature {
|
||||||
|
logger.Error(ctx, "invalid signature")
|
||||||
|
api.ErrorResponse(w, http.StatusConflict, ErrCodeConflict, nil)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !validSignature {
|
updates := []datastore.AgentUpdateOptionFunc{
|
||||||
logger.Error(ctx, "invalid signature")
|
datastore.WithAgentUpdateKeySet(keySet),
|
||||||
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeInvalidRequest, nil)
|
datastore.WithAgentUpdateMetadata(metadata),
|
||||||
|
datastore.WithAgentUpdateThumbprint(registerAgentReq.Thumbprint),
|
||||||
|
}
|
||||||
|
|
||||||
return
|
if agent.Status == datastore.AgentStatusForgotten {
|
||||||
|
updates = append(updates, datastore.WithAgentUpdateStatus(datastore.AgentStatusPending))
|
||||||
}
|
}
|
||||||
|
|
||||||
agent, err = m.agentRepo.Update(
|
agent, err = m.agentRepo.Update(
|
||||||
ctx,
|
ctx,
|
||||||
agents[0].ID,
|
agents[0].ID,
|
||||||
datastore.WithAgentUpdateKeySet(keySet),
|
updates...,
|
||||||
datastore.WithAgentUpdateMetadata(metadata),
|
|
||||||
datastore.WithAgentUpdateThumbprint(registerAgentReq.Thumbprint),
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.WithStack(err)
|
err = errors.WithStack(err)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -95,12 +96,15 @@ func (c *Client) apiDo(ctx context.Context, method string, path string, payload
|
|||||||
|
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
decoder := json.NewDecoder(res.Body)
|
data, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
if err := decoder.Decode(&response); err != nil {
|
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(data, &response); err != nil {
|
||||||
|
return errors.Wrapf(err, "could not parse json: got '%s'", data)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user