assistant: Fix local pairing when ssh pubkey comment contains spaces.
This commit is contained in:
parent
beb46355c0
commit
c6b5f2f3c4
4 changed files with 25 additions and 24 deletions
|
@ -23,12 +23,11 @@ import qualified Data.Text as T
|
||||||
{- Authorized keys are set up before pairing is complete, so that the other
|
{- Authorized keys are set up before pairing is complete, so that the other
|
||||||
- side can immediately begin syncing. -}
|
- side can immediately begin syncing. -}
|
||||||
setupAuthorizedKeys :: PairMsg -> FilePath -> IO ()
|
setupAuthorizedKeys :: PairMsg -> FilePath -> IO ()
|
||||||
setupAuthorizedKeys msg repodir = do
|
setupAuthorizedKeys msg repodir = case validateSshPubKey $ remoteSshPubKey $ pairMsgData msg of
|
||||||
validateSshPubKey pubkey
|
Left err -> error err
|
||||||
unlessM (liftIO $ addAuthorizedKeys True repodir pubkey) $
|
Right pubkey ->
|
||||||
error "failed setting up ssh authorized keys"
|
unlessM (liftIO $ addAuthorizedKeys True repodir pubkey) $
|
||||||
where
|
error "failed setting up ssh authorized keys"
|
||||||
pubkey = remoteSshPubKey $ pairMsgData msg
|
|
||||||
|
|
||||||
{- When local pairing is complete, this is used to set up the remote for
|
{- When local pairing is complete, this is used to set up the remote for
|
||||||
- the host we paired with. -}
|
- the host we paired with. -}
|
||||||
|
|
|
@ -111,34 +111,26 @@ sshTranscript :: [String] -> (Maybe String) -> IO (String, Bool)
|
||||||
sshTranscript opts input = processTranscript "ssh" opts input
|
sshTranscript opts input = processTranscript "ssh" opts input
|
||||||
|
|
||||||
{- Ensure that the ssh public key doesn't include any ssh options, like
|
{- Ensure that the ssh public key doesn't include any ssh options, like
|
||||||
- command=foo, or other weirdness -}
|
- command=foo, or other weirdness.
|
||||||
validateSshPubKey :: SshPubKey -> IO ()
|
-
|
||||||
|
- The returned version of the key has its comment removed.
|
||||||
|
-}
|
||||||
|
validateSshPubKey :: SshPubKey -> Either String SshPubKey
|
||||||
validateSshPubKey pubkey
|
validateSshPubKey pubkey
|
||||||
| length (lines pubkey) == 1 =
|
| length (lines pubkey) == 1 = check $ words pubkey
|
||||||
either error return $ check $ words pubkey
|
| otherwise = Left "too many lines in ssh public key"
|
||||||
| otherwise = error "too many lines in ssh public key"
|
|
||||||
where
|
where
|
||||||
check [prefix, _key, comment] = do
|
check (prefix:key:_) = checkprefix prefix (unwords [prefix, key])
|
||||||
checkprefix prefix
|
|
||||||
checkcomment comment
|
|
||||||
check [prefix, _key] =
|
|
||||||
checkprefix prefix
|
|
||||||
check _ = err "wrong number of words in ssh public key"
|
check _ = err "wrong number of words in ssh public key"
|
||||||
|
|
||||||
ok = Right ()
|
|
||||||
err msg = Left $ unwords [msg, pubkey]
|
err msg = Left $ unwords [msg, pubkey]
|
||||||
|
|
||||||
checkprefix prefix
|
checkprefix prefix validpubkey
|
||||||
| ssh == "ssh" && all isAlphaNum keytype = ok
|
| ssh == "ssh" && all isAlphaNum keytype = Right validpubkey
|
||||||
| otherwise = err "bad ssh public key prefix"
|
| otherwise = err "bad ssh public key prefix"
|
||||||
where
|
where
|
||||||
(ssh, keytype) = separate (== '-') prefix
|
(ssh, keytype) = separate (== '-') prefix
|
||||||
|
|
||||||
checkcomment comment = case filter (not . safeincomment) comment of
|
|
||||||
[] -> ok
|
|
||||||
badstuff -> err $ "bad comment in ssh public key (contains: \"" ++ badstuff ++ "\")"
|
|
||||||
safeincomment c = isAlphaNum c || c == '@' || c == '-' || c == '_' || c == '.'
|
|
||||||
|
|
||||||
addAuthorizedKeys :: Bool -> FilePath -> SshPubKey -> IO Bool
|
addAuthorizedKeys :: Bool -> FilePath -> SshPubKey -> IO Bool
|
||||||
addAuthorizedKeys gitannexshellonly dir pubkey = boolSystem "sh"
|
addAuthorizedKeys gitannexshellonly dir pubkey = boolSystem "sh"
|
||||||
[ Param "-c" , Param $ addAuthorizedKeysCommand gitannexshellonly dir pubkey ]
|
[ Param "-c" , Param $ addAuthorizedKeysCommand gitannexshellonly dir pubkey ]
|
||||||
|
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -30,6 +30,7 @@ git-annex (5.20150114) UNRELEASED; urgency=medium
|
||||||
annex.tune.branchhash1.
|
annex.tune.branchhash1.
|
||||||
* Remove support for building without cryptohash.
|
* Remove support for building without cryptohash.
|
||||||
* Added MD5 and MD5E backends.
|
* Added MD5 and MD5E backends.
|
||||||
|
* assistant: Fix local pairing when ssh pubkey comment contains spaces.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Tue, 13 Jan 2015 17:03:39 -0400
|
-- Joey Hess <id@joeyh.name> Tue, 13 Jan 2015 17:03:39 -0400
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
[[!comment format=mdwn
|
||||||
|
username="joey"
|
||||||
|
subject="""comment 1"""
|
||||||
|
date="2015-02-04T18:04:51Z"
|
||||||
|
content="""
|
||||||
|
Please report bugs at [[bugs]], not in the forum.
|
||||||
|
|
||||||
|
I've fixed this one.
|
||||||
|
"""]]
|
Loading…
Add table
Add a link
Reference in a new issue