@@ -33,6 +33,11 @@ var licensePublicKeyPem []byte
33
33
34
34
const defaultLicenseFilepath = "/etc/redpanda/redpanda.license"
35
35
36
+ var openSourceLicense = RedpandaLicense {
37
+ Type : - 1 ,
38
+ Expiry : time .Now ().Add (time .Hour * 24 * 365 * 10 ).Unix (),
39
+ }
40
+
36
41
// Service is the license service.
37
42
type Service struct {
38
43
logger * service.Logger
@@ -101,30 +106,18 @@ func InjectTestService(res *service.Resources) {
101
106
func (s * Service ) readAndValidateLicense () (RedpandaLicense , error ) {
102
107
licenseBytes , err := s .readLicense ()
103
108
if err != nil {
104
- return RedpandaLicense {} , err
109
+ return openSourceLicense , err
105
110
}
106
111
107
- var license RedpandaLicense
112
+ license := openSourceLicense
108
113
if len (licenseBytes ) > 0 {
109
114
if license , err = s .validateLicense (licenseBytes ); err != nil {
110
- return RedpandaLicense {}, fmt .Errorf ("failed to validate license: %w" , err )
111
- }
112
- if license .Type == 0 {
113
- // If the license is a trial then we reject it because connect does
114
- // not support trials.
115
- return RedpandaLicense {}, errors .New ("trial license detected, Redpanda Connect does not support enterprise license trials" )
116
- }
117
- } else {
118
- // An open source license is the final fall back.
119
- year := time .Hour * 24 * 365
120
- license = RedpandaLicense {
121
- Expiry : time .Now ().Add (10 * year ).Unix (),
122
- Type : - 1 ,
115
+ return openSourceLicense , fmt .Errorf ("failed to validate license: %w" , err )
123
116
}
124
117
}
125
118
126
119
if err := license .CheckExpiry (); err != nil {
127
- return RedpandaLicense {} , err
120
+ return openSourceLicense , err
128
121
}
129
122
130
123
s .logger .With (
@@ -175,11 +168,11 @@ func (s *Service) validateLicense(license []byte) (RedpandaLicense, error) {
175
168
block , _ := pem .Decode (publicKeyBytes )
176
169
publicKey , err := x509 .ParsePKIXPublicKey (block .Bytes )
177
170
if err != nil {
178
- return RedpandaLicense {} , fmt .Errorf ("failed to parse public key: %w" , err )
171
+ return openSourceLicense , fmt .Errorf ("failed to parse public key: %w" , err )
179
172
}
180
173
publicKeyRSA , ok := publicKey .(* rsa.PublicKey )
181
174
if ! ok {
182
- return RedpandaLicense {} , errors .New ("failed to parse public key, expected dateFormat is not RSA" )
175
+ return openSourceLicense , errors .New ("failed to parse public key, expected dateFormat is not RSA" )
183
176
}
184
177
185
178
// Trim Whitespace and Linebreaks for input license
@@ -188,32 +181,32 @@ func (s *Service) validateLicense(license []byte) (RedpandaLicense, error) {
188
181
// 2. Split license contents by delimiter
189
182
splitParts := bytes .Split (license , []byte ("." ))
190
183
if len (splitParts ) != 2 {
191
- return RedpandaLicense {} , errors .New ("failed to split license contents by delimiter" )
184
+ return openSourceLicense , errors .New ("failed to split license contents by delimiter" )
192
185
}
193
186
194
187
licenseDataEncoded := splitParts [0 ]
195
188
signatureEncoded := splitParts [1 ]
196
189
197
190
licenseData , err := base64 .StdEncoding .DecodeString (string (licenseDataEncoded ))
198
191
if err != nil {
199
- return RedpandaLicense {} , fmt .Errorf ("failed to decode license data: %w" , err )
192
+ return openSourceLicense , fmt .Errorf ("failed to decode license data: %w" , err )
200
193
}
201
194
202
195
signature , err := base64 .StdEncoding .DecodeString (string (signatureEncoded ))
203
196
if err != nil {
204
- return RedpandaLicense {} , fmt .Errorf ("failed to decode license signature: %w" , err )
197
+ return openSourceLicense , fmt .Errorf ("failed to decode license signature: %w" , err )
205
198
}
206
199
hash := sha256 .Sum256 (licenseDataEncoded )
207
200
208
201
// 3. Verify license contents with static public key
209
202
if err := rsa .VerifyPKCS1v15 (publicKeyRSA , crypto .SHA256 , hash [:], signature ); err != nil {
210
- return RedpandaLicense {} , fmt .Errorf ("failed to verify license signature: %w" , err )
203
+ return openSourceLicense , fmt .Errorf ("failed to verify license signature: %w" , err )
211
204
}
212
205
213
206
// 4. If license contents seem to be legit, we will continue unpacking the license
214
207
var rpLicense RedpandaLicense
215
208
if err := json .Unmarshal (licenseData , & rpLicense ); err != nil {
216
- return RedpandaLicense {} , fmt .Errorf ("failed to unmarshal license data: %w" , err )
209
+ return openSourceLicense , fmt .Errorf ("failed to unmarshal license data: %w" , err )
217
210
}
218
211
219
212
return rpLicense , nil
0 commit comments