feat(api): update DigitalSignatureService (#2539)

pull/2543/head
Anthony Lapenna 2018-12-12 11:19:23 +13:00 committed by GitHub
parent 5c2e714e69
commit 8a186b4024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 10 deletions

View File

@ -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
} }

View File

@ -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
} }

View File

@ -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
} }

View File

@ -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
} }

View File

@ -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
} }

View File

@ -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