Skip to content

Commit ba30aff

Browse files
committed
Fix SSH signature validation when principal name contains spaces (jorio#105)
1 parent 9489583 commit ba30aff

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

gitfourchette/tasks/misctasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class VerifyGpgSignature(RepoTask):
208208
"BADSIG" : GpgStatus.Bad,
209209
}
210210

211-
_SshGoodTrustedPattern = re.compile(r'^Good "git" signature for (\S+) with \S+ key (.+)')
211+
_SshGoodTrustedPattern = re.compile(r'^Good "git" signature for (.+) with \S+ key (.+)')
212212
_SshGoodUntrustedPattern = re.compile(r'^Good "git" signature with \S+ key (.+)')
213213

214214
def flow(self, oid: Oid, dialogParent: QWidget | None = None):

test/test_gpgsigning.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,17 @@ def copySshKey(tempPath: str, testKeyName: str) -> str:
9292
return Path(pubPath).as_posix()
9393

9494

95-
def setUpForSshSigning(tempPath: str, repoWorkdir: str, testKeyName: str = "simple"):
95+
def setUpForSshSigning(
96+
tempPath: str,
97+
repoWorkdir: str,
98+
testKeyName: str = "simple",
99+
principal: str = "CriquetteRockwell",
100+
):
96101
pubKeyCopy = copySshKey(tempPath, testKeyName)
97-
allowedSigners = f"{tempPath}/allowedSigners"
98-
writeFile(allowedSigners, "CriquetteRockwell " + readTextFile(pubKeyCopy))
102+
pubKeyText = readTextFile(pubKeyCopy)
103+
104+
allowedSigners = f"{tempPath}/allowed_signers"
105+
writeFile(allowedSigners, f"{principal} {pubKeyText}")
99106

100107
with RepoContext(repoWorkdir) as repo:
101108
repo.config["gpg.format"] = "ssh"
@@ -269,17 +276,23 @@ def testVerifyGoodPgpSignatureWithMissingKey(tempDir, mainWindow, tempGpgHome):
269276

270277

271278
@requiresGpg
272-
def testVerifyGoodSshSignature(tempDir, mainWindow, tempGpgHome):
279+
@pytest.mark.parametrize("principal", [
280+
# Principal names usually don't contain spaces, but the allowed_signers file
281+
# allows quoting the principal field (see ssh-keygen(1)).
282+
"criquette@example.com",
283+
'"Criquette Rockwell <criquette@example.com>"',
284+
])
285+
def testVerifyGoodSshSignature(tempDir, mainWindow, tempGpgHome, principal):
273286
wd = unpackRepo(tempDir)
274-
_pubKey, allowedSigners = setUpForSshSigning(tempDir.name, wd)
287+
_pubKey, allowedSigners = setUpForSshSigning(tempDir.name, wd, principal=principal)
275288

276289
signedOid = makeSignedCommit(wd)
277290

278291
rw = mainWindow.openRepo(wd)
279292
rw.jump(NavLocator.inCommit(signedOid, ""), check=True)
280293

281294
triggerContextMenuAction(rw.graphView.viewport(), "verify signature")
282-
acceptQMessageBox(rw, "good signature; key trusted.+CriquetteRockwell")
295+
acceptQMessageBox(rw, "good signature; key trusted.+criquette")
283296

284297
# Clear allowed signers, then verify the signature again
285298
writeFile(allowedSigners, "")

0 commit comments

Comments
 (0)