Skip to content

Commit a0a0a21

Browse files
author
David Kowalski
committed
Merge branch '1.3' into 1.3.1
2 parents 506035f + 78f23cb commit a0a0a21

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

docs/orchestrating-elastic-stack-applications/beat.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ stringData:
188188
hosts: ["quickstart-es-http.default.svc:9200"]
189189
----
190190

191-
For more details, see the link:https://https://www.elastic.co/guide/en/beats/libbeat/current/config-file-format.html[Beats configuration] section.
191+
For more details, see the link:https://www.elastic.co/guide/en/beats/libbeat/current/config-file-format.html[Beats configuration] section.
192192

193193
[id="{p}-beat-deploy-elastic-beat"]
194194
=== Deploy a Beat
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"license":{"uid":"F983C1D2-1676-4427-8B6A-EF954AEEC174","type":"enterprise","issue_date_in_millis":1606262400000,"start_date_in_millis":1606262400000,"expiry_date_in_millis":1640995199999,"max_resource_units":100,"issued_to":"ECK Unit & test <>","issuer":"ECK Unit tests","signature":"AAAABAAAAA2BVF3v7DTBA3aIN5VKAAABmC9ZN0hjZDBGYnVyRXpCOW5Bb3FjZDAxOWpSbTVoMVZwUzRxVk1PSmkxakxlZzM5QU1HeFFJV3Jic1lDa1c0SU4wWHlKTHVGY1lNNm1GWCszenRqckZkSmVwcTRERjdnZk8yUlhtczJ4QS9pYUEwOFo3TUdVYVhpTEN6bkgwQ0FWV1luQ0dWeVRGSXVFZTAzQXJXc2N3YXBpaTgxMC81R0FYR0FLYkJZZ2Y5LzA4NktBSWtxS3RHSFJTdkNFbFl0VTZlSTlmMVYxQWVXeXIzWXg4cHM2TW9OdDNnSzVNV2NUeWE3cTVSTitWSlorMjJ4ZjFxRHJVNG1UdHN5MXN5a3l1TjZLM2RsSWNqL0FRakY4SFdSdVk3MkR3ZUdXdXpRcG5PMmRnYmI2UUNxanU5NHQ0WC9Ud2poTTE3V1JVMTdYVzNVeTUrbUpwZCtrYWRDcDVmTHo1Q2pwVkw3ZVRaYXZWRUxkRk04VDdmK0ExS044NXBOeFRVZ0tTa3JJcXFZUDlpeVhLaGgyUmxhOWJTdy82eTVBV2c9PQAAAQBfAHdLIIy8BuD0eWZVh2lO4WG7Ck3LaN1Trid8Z0ZhdhN2AQY7TuTCe6VGQA7SfjtJ5RHZvQ223CZicoplCc8mSqblV1ZhbmqfFMvHqmuTJxjMW4abINcVSExBLWe4R/8nx6vKNdslt7qJuwO9KBc3Aqcv3V5UJRS59rXao4c/N5BwxhweCy0uQbLlnvTIbjjERgFC7L+k7TC55atdjUkYlV9yIik3w7mBvcQzNYoeTcYom/TyGQe8maYOYLbojyZ2B8NLKgxGCIzoVxEB9vxcz9wtNDiBpU7M8Ep6282COy0qHstJrmOult0rGZbGIdhk4GDVtCEPbi+S0jfvCM0n"}}

pkg/controller/common/license/verifier.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ type licenseSpec struct {
216216
}
217217

218218
func (l EnterpriseLicense) SignableContentBytes() ([]byte, error) {
219-
return json.Marshal(licenseSpec{
219+
return unescapedJSONMarshal(licenseSpec{
220220
UID: l.License.UID,
221221
LicenseType: string(l.License.Type),
222222
IssueDateInMillis: l.License.IssueDateInMillis,
@@ -229,6 +229,22 @@ func (l EnterpriseLicense) SignableContentBytes() ([]byte, error) {
229229
})
230230
}
231231

232+
// unescapedJSONMarshal is a custom JSON encoder that turns off Go json's default behaviour of escaping > < and &
233+
// which is problematic and would lead to failed signature checks as our license signing does not escape those characters.
234+
func unescapedJSONMarshal(t interface{}) ([]byte, error) {
235+
buffer := &bytes.Buffer{}
236+
encoder := json.NewEncoder(buffer)
237+
encoder.SetEscapeHTML(false)
238+
err := encoder.Encode(t)
239+
if err != nil {
240+
return nil, err
241+
}
242+
marshaledBytes := buffer.Bytes()
243+
// json.Encoder adds an additional newline between objects which we do not want here
244+
// as it is not part of the signature. That's we we are trimming it here.
245+
return bytes.TrimRight(marshaledBytes, "\n"), err
246+
}
247+
232248
func (l EnterpriseLicense) Version() int {
233249
return l.License.Version
234250
}

pkg/controller/common/license/verifier_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"crypto/rsa"
1010
"crypto/x509"
1111
"encoding/base64"
12+
"encoding/json"
13+
"io/ioutil"
1214
"reflect"
1315
"testing"
1416
"time"
@@ -145,6 +147,19 @@ func TestNewLicenseVerifier(t *testing.T) {
145147
require.NoError(t, v.ValidSignature(withSignature(licenseFixtureV3, bytes)))
146148
},
147149
},
150+
{
151+
name: "Can verify license signed by external tooling",
152+
want: func(v *Verifier) {
153+
// license attributes contain <> and & which json.Marshal escapes by default leading to a signature
154+
// mismatch unless handled explicitly
155+
bytes, err := ioutil.ReadFile("testdata/externally-generated-lic.json")
156+
require.NoError(t, err)
157+
var lic EnterpriseLicense
158+
err = json.Unmarshal(bytes, &lic)
159+
require.NoError(t, err)
160+
require.NoError(t, v.ValidSignature(lic))
161+
},
162+
},
148163
}
149164
for _, tt := range tests {
150165
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)