@@ -129,6 +129,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
129
129
// so, if the flags to override the default keys are used, we try override the corresponding platform property nonetheless.
130
130
// It's not possible to use the default name for the keys since there could be more tools to sign and encrypt.
131
131
// So it's mandatory to use all the tree flags to sign and encrypt the binary
132
+ securityKeysOverride := []string {}
132
133
if req .KeysKeychain != "" && req .SignKey != "" && req .EncryptKey != "" {
133
134
keysDirPath := paths .New (req .KeysKeychain )
134
135
if ! keysDirPath .IsDir () {
@@ -142,8 +143,8 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
142
143
if ! encryptKeyPath .Exist () {
143
144
return nil , & arduino.NotFoundError {Message : tr ("The path of the specified encryption key does not exist: %s" , encryptKeyPath ), Cause : err }
144
145
}
145
- InstalledPlatformRelease := pm . GetInstalledPlatformRelease ( targetPlatform )
146
- ReplaceSecurityKeys (InstalledPlatformRelease . Properties , req .KeysKeychain , req .SignKey , req .EncryptKey )
146
+ securityKeysOverride = append ( securityKeysOverride , "build.keys.keychain=" + req . KeysKeychain , "build.keys.sign_key=" + req . GetSignKey (), "build.keys.encrypt_key=" + req . EncryptKey )
147
+ // ReplaceSecurityKeys(req.KeysKeychain, req.SignKey, req.EncryptKey)
147
148
}
148
149
149
150
builderCtx := & types.Context {}
@@ -186,6 +187,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
186
187
builderCtx .WarningsLevel = req .GetWarnings ()
187
188
188
189
builderCtx .CustomBuildProperties = append (req .GetBuildProperties (), "build.warn_data_percentage=75" )
190
+ builderCtx .CustomBuildProperties = append (req .GetBuildProperties (), securityKeysOverride ... )
189
191
190
192
if req .GetBuildCachePath () != "" {
191
193
builderCtx .BuildCachePath = paths .New (req .GetBuildCachePath ())
@@ -317,28 +319,3 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
317
319
318
320
return r , nil
319
321
}
320
-
321
- // ReplaceSecurityKeys function will override the properties representing the security keys specified in the platform.txt file of a platform with the ones provided by the user.
322
- // The keys are stored in the keyPath
323
- // signKey is the key used to sign a binary
324
- // encryptKey is the key used to encrypt it
325
- func ReplaceSecurityKeys (properties * properties.Map , keysKKeysKeychain , signKey , encryptKey string ) {
326
- toolsProps := properties .SubTree ("tools" ).FirstLevelOf ()
327
- for toolName , toolProps := range toolsProps {
328
- if toolProps .ContainsKey ("keys.path" ) {
329
- key := "tools." + toolName + ".keys.path"
330
- properties .Set (key , keysKKeysKeychain )
331
- logrus .Tracef ("Overriding Property: %s: %s" , key , keysKKeysKeychain )
332
- }
333
- if toolProps .ContainsKey ("sign.name" ) {
334
- key := "tools." + toolName + ".sign.name"
335
- properties .Set (key , signKey )
336
- logrus .Tracef ("Overriding Property: %s: %s" , key , signKey )
337
- }
338
- if toolProps .ContainsKey ("encrypt.name" ) {
339
- key := "tools." + toolName + ".encrypt.name"
340
- properties .Set (key , encryptKey )
341
- logrus .Tracef ("Overriding Property: %s: %s" , key , encryptKey )
342
- }
343
- }
344
- }
0 commit comments