@@ -129,6 +129,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
129129 // so, if the flags to override the default keys are used, we try override the corresponding platform property nonetheless.
130130 // It's not possible to use the default name for the keys since there could be more tools to sign and encrypt.
131131 // So it's mandatory to use all the tree flags to sign and encrypt the binary
132+ securityKeysOverride := []string {}
132133 if req .KeysKeychain != "" && req .SignKey != "" && req .EncryptKey != "" {
133134 keysDirPath := paths .New (req .KeysKeychain )
134135 if ! keysDirPath .IsDir () {
@@ -142,8 +143,8 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
142143 if ! encryptKeyPath .Exist () {
143144 return nil , & arduino.NotFoundError {Message : tr ("The path of the specified encryption key does not exist: %s" , encryptKeyPath ), Cause : err }
144145 }
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)
147148 }
148149
149150 builderCtx := & types.Context {}
@@ -186,6 +187,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
186187 builderCtx .WarningsLevel = req .GetWarnings ()
187188
188189 builderCtx .CustomBuildProperties = append (req .GetBuildProperties (), "build.warn_data_percentage=75" )
190+ builderCtx .CustomBuildProperties = append (req .GetBuildProperties (), securityKeysOverride ... )
189191
190192 if req .GetBuildCachePath () != "" {
191193 builderCtx .BuildCachePath = paths .New (req .GetBuildCachePath ())
@@ -317,28 +319,3 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
317319
318320 return r , nil
319321}
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