mirror of https://github.com/portainer/portainer
feat(api): update DigitalSignatureService (#2539)
parent
5c2e714e69
commit
8a186b4024
|
@ -8,8 +8,6 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/portainer/portainer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -105,10 +103,10 @@ func (service *ECDSAService) GenerateKeyPair() ([]byte, []byte, error) {
|
||||||
// CreateSignature creates a digital signature.
|
// CreateSignature creates a digital signature.
|
||||||
// It automatically hash a specific message using MD5 and creates a signature from
|
// It automatically hash a specific message using MD5 and creates a signature from
|
||||||
// that hash.
|
// that hash.
|
||||||
|
// If a secret is associated to the service, it will be used instead of the specified
|
||||||
|
// message.
|
||||||
// It then encodes the generated signature in base64.
|
// It then encodes the generated signature in base64.
|
||||||
func (service *ECDSAService) CreateSignature() (string, error) {
|
func (service *ECDSAService) CreateSignature(message string) (string, error) {
|
||||||
|
|
||||||
message := portainer.PortainerAgentSignatureMessage
|
|
||||||
if service.secret != "" {
|
if service.secret != "" {
|
||||||
message = service.secret
|
message = service.secret
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ func createAgentClient(endpoint *portainer.Endpoint, signatureService portainer.
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
signature, err := signatureService.CreateSignature()
|
signature, err := signatureService.CreateSignature(portainer.PortainerAgentSignatureMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ func (manager *SwarmStackManager) updateDockerCLIConfiguration(dataPath string)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
signature, err := manager.signatureService.CreateSignature()
|
signature, err := manager.signatureService.CreateSignature(portainer.PortainerAgentSignatureMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ func (handler *Handler) proxyWebsocketRequest(w http.ResponseWriter, r *http.Req
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signature, err := handler.SignatureService.CreateSignature()
|
signature, err := handler.SignatureService.CreateSignature(portainer.PortainerAgentSignatureMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (p *proxyTransport) proxyDockerRequest(request *http.Request) (*http.Respon
|
||||||
request.URL.Path = path
|
request.URL.Path = path
|
||||||
|
|
||||||
if p.enableSignature {
|
if p.enableSignature {
|
||||||
signature, err := p.SignatureService.CreateSignature()
|
signature, err := p.SignatureService.CreateSignature(portainer.PortainerAgentSignatureMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -683,7 +683,7 @@ type (
|
||||||
GenerateKeyPair() ([]byte, []byte, error)
|
GenerateKeyPair() ([]byte, []byte, error)
|
||||||
EncodedPublicKey() string
|
EncodedPublicKey() string
|
||||||
PEMHeaders() (string, string)
|
PEMHeaders() (string, string)
|
||||||
CreateSignature() (string, error)
|
CreateSignature(message string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// JWTService represents a service for managing JWT tokens
|
// JWTService represents a service for managing JWT tokens
|
||||||
|
|
Loading…
Reference in New Issue