2424
2525import jenkins .security .SlaveToMasterCallable ;
2626import jenkins .util .JenkinsJVM ;
27+ import net .sf .json .JSONObject ;
2728import org .jenkinsci .plugins .workflow .support .concurrent .Timeout ;
2829import org .kohsuke .accmod .Restricted ;
2930import org .kohsuke .accmod .restrictions .NoExternalUse ;
@@ -350,8 +351,6 @@ private Object writeReplace() {
350351
351352 private static final class DelegatingGitHubAppCredentials extends BaseStandardCredentials implements StandardUsernamePasswordCredentials {
352353
353- private static final String SEP = "%%%" ;
354-
355354 private final String appID ;
356355 /**
357356 * An encrypted form of all data needed to refresh the token.
@@ -366,7 +365,12 @@ private static final class DelegatingGitHubAppCredentials extends BaseStandardCr
366365 super (onMaster .getScope (), onMaster .getId (), onMaster .getDescription ());
367366 JenkinsJVM .checkJenkinsJVM ();
368367 appID = onMaster .appID ;
369- tokenRefreshData = Secret .fromString (onMaster .appID + SEP + onMaster .privateKey .getPlainText () + SEP + onMaster .actualApiUri () + SEP + onMaster .owner ).getEncryptedValue ();
368+ JSONObject j = new JSONObject ();
369+ j .put ("appID" , appID );
370+ j .put ("privateKey" , onMaster .privateKey .getPlainText ());
371+ j .put ("apiUri" , onMaster .actualApiUri ());
372+ j .put ("owner" , onMaster .owner );
373+ tokenRefreshData = Secret .fromString (j .toString ()).getEncryptedValue ();
370374
371375 // Check token is valid before sending it to the agent.
372376 // Ensuring the cached token is not stale before sending it to agents keeps agents from having to
@@ -445,15 +449,16 @@ private static final class GetToken extends SlaveToMasterCallable<AppInstallatio
445449 @ Override
446450 public AppInstallationToken call () throws RuntimeException {
447451 JenkinsJVM .checkJenkinsJVM ();
448- String [] fields = Secret .fromString (data ).getPlainText ().split (SEP );
449- LOGGER .log (Level .FINE , "Generating App Installation Token for app ID {0} for agent" , fields [0 ]);
450- AppInstallationToken token = generateAppInstallationToken (fields [0 ],
451- fields [1 ],
452- fields [2 ],
453- fields [3 ]);
452+ JSONObject fields = JSONObject .fromObject (Secret .fromString (data ).getPlainText ());
453+ LOGGER .log (Level .FINE , "Generating App Installation Token for app ID {0} for agent" , fields .get ("appID" ));
454+ AppInstallationToken token = generateAppInstallationToken (
455+ (String )fields .get ("appID" ),
456+ (String )fields .get ("privateKey" ),
457+ (String )fields .get ("apiUri" ),
458+ (String )fields .get ("owner" ));
454459 LOGGER .log (Level .FINER ,
455460 "Retrieved GitHub App Installation Token for app ID {0} for agent" ,
456- fields [ 0 ] );
461+ fields . get ( "appID" ) );
457462 return token ;
458463 }
459464 }
0 commit comments