[rdct] use pinentry data env with prefix to distinguish between possible different custom pinentry programs

Follow-up: a06ba8c87946fb3a9b2818996e81e81a4ed90408

GitOrigin-RevId: 89951442ccaf2feec1b6b04efb9dff4dd1b0d32c
This commit is contained in:
Dmitry Zhuravlev
2024-09-27 16:50:45 +02:00
committed by intellij-monorepo-bot
parent c16197ec2a
commit 559abb4f0f
6 changed files with 15 additions and 7 deletions

View File

@@ -51,6 +51,7 @@ public final class PinentryApp implements ExternalApp {
if (pinentryUserData == null) {
pinentryUserData = "";
}
pinentryUserData = pinentryUserData.replace("IJ_PINENTRY=", "");
String[] pinentryData = pinentryUserData.split(":");
if (pinentryData.length != 3) {

View File

@@ -200,7 +200,7 @@ public final class GitHandlerAuthenticationManager implements AutoCloseable {
if (needGpgSigning) {
PinentryService.PinentryData pinentryData = PinentryService.getInstance(project).startSession();
if (pinentryData != null) {
myHandler.addCustomEnvironmentVariable(PinentryService.PINENTRY_USER_DATA_ENV, pinentryData.toString());
myHandler.addCustomEnvironmentVariable(PinentryService.PINENTRY_USER_DATA_ENV, pinentryData.toEnv());
myHandler.addListener(new GitHandlerListener() {
@Override
public void processTerminated(int exitCode) {

View File

@@ -25,6 +25,7 @@ import git4idea.commit.signing.GpgAgentPathsLocator.Companion.GPG_AGENT_CONF_FIL
import git4idea.commit.signing.GpgAgentPathsLocator.Companion.GPG_HOME_DIR
import git4idea.commit.signing.GpgAgentPathsLocator.Companion.PINENTRY_LAUNCHER_FILE_NAME
import git4idea.commit.signing.PinentryService.Companion.PINENTRY_USER_DATA_ENV
import git4idea.commit.signing.PinentryService.PinentryData
import git4idea.config.GitExecutable
import git4idea.config.GitExecutableListener
import git4idea.config.GitExecutableManager
@@ -355,7 +356,8 @@ internal class PinentryShellScriptLauncherGenerator(override val executable: Git
}
return """|#!/bin/sh
|if [ -n "${'$'}$PINENTRY_USER_DATA_ENV" ]; then
|if [ -n "${'$'}$PINENTRY_USER_DATA_ENV" ] && [[
| "${'$'}$PINENTRY_USER_DATA_ENV" == "${PinentryData.PREFIX}"* ]]; then
| ${addParameters(*getCommandLineParameters()).commandLine(PinentryApp::class.java, false)}
|else
| exec $fallbackPinentryPath "$@"

View File

@@ -156,7 +156,12 @@ internal class PinentryService(private val cs: CoroutineScope) {
}
data class PinentryData(val publicKey: String, val address: Address) {
override fun toString(): String = "$publicKey:$address"
fun toEnv(): String = "$PREFIX$publicKey:$address"
companion object {
const val PREFIX = "IJ_PINENTRY="
}
}
companion object {

View File

@@ -21,9 +21,9 @@ class PinentryDataEncryptTest : UsefulTestCase() {
fun `test public key serialization`() {
val publicKey = CryptoUtils.generateKeyPair().public
val address = PinentryService.Address(NetUtils.getLocalHostString(), NetUtils.findAvailableSocketPort())
val pinentryData = PinentryService.PinentryData(CryptoUtils.publicKeyToString(publicKey), address).toString()
val pinentryData = PinentryService.PinentryData(CryptoUtils.publicKeyToString(publicKey), address).toEnv()
val keyToDeserialize = pinentryData.split(':')[0]
val keyToDeserialize = pinentryData.split(PinentryService.PinentryData.PREFIX)[1].split(':')[0]
val deserializedKey = CryptoUtils.stringToPublicKey(keyToDeserialize)
assertEquals(publicKey, deserializedKey)

View File

@@ -130,9 +130,9 @@ class PinentryExecutionTest : GitSingleRepoTest() {
}
}
private fun requestPassword(paths: GpgAgentPaths, pinentryData: PinentryService.PinentryData?): List<@NlsSafe String> {
private fun requestPassword(paths: GpgAgentPaths, pinentryData: PinentryService.PinentryData): List<@NlsSafe String> {
val cmd = GeneralCommandLine(paths.gpgPinentryAppLauncherConfigPath)
.withEnvironment(PinentryService.PINENTRY_USER_DATA_ENV, pinentryData.toString())
.withEnvironment(PinentryService.PINENTRY_USER_DATA_ENV, pinentryData.toEnv())
val output = object : CapturingProcessHandler.Silent(cmd) {
override fun createProcessAdapter(processOutput: ProcessOutput): CapturingProcessAdapter? {