Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.cabal-sandbox/
.stack-work/
cabal.sandbox.config
dist/
2 changes: 0 additions & 2 deletions SSH/Agent.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module SSH.Agent where

import Control.Applicative ((<$>), (<*>))
import Control.Monad (replicateM)
import Data.Binary.Get (Get, runGet, getWord8, getWord32be)
import Data.Binary.Put (Put, runPut, putWord8, putWord32be)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as LB
import Data.Monoid ((<>))
import Data.Word (Word8, Word32)
import SSH.Types (getWord32be', getString, putWord32be', putString)

Expand Down
14 changes: 11 additions & 3 deletions SSH/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ module SSH.Key
, putPublicKey
) where

import Control.Applicative ((<$>), (<*>))
import Control.Monad (unless, replicateM)
import Data.Binary.Get (Get, getWord32be, getByteString, getRemainingLazyByteString)
import Data.Binary.Put (Put, putWord32be, putByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Char8 as BC
import Data.ByteString.Lazy (toStrict)
import Data.Monoid ((<>))
import Data.List (unfoldr)
import SSH.Types (getWord32be', getString, putString, runStrictGet, runStrictPut)

data KeyBox = KeyBox
Expand Down Expand Up @@ -64,8 +63,17 @@ dearmorPrivateKey =
armorPrivateKey :: B.ByteString -> B.ByteString
armorPrivateKey k =
armor_start <> "\n"
<> B64.joinWith "\n" 70 (B64.encode k)
<> foldMap (<>"\n") (chunksOf 70 (B64.encode k))
<> armor_end <> "\n"
where
justWhen :: (a -> Bool) -> (a -> b) -> (a -> Maybe b)
justWhen f g a = if f a then Just (g a) else Nothing

nothingWhen :: (a -> Bool) -> (a -> b) -> (a -> Maybe b)
nothingWhen f = justWhen (not . f)

chunksOf :: Int -> B.ByteString -> [B.ByteString]
chunksOf x = unfoldr (nothingWhen B.null (B.splitAt x))

getKeyBox :: Get KeyBox
getKeyBox = do
Expand Down
1 change: 0 additions & 1 deletion SSH/Key/Derived.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module SSH.Key.Derived (deriveKey) where
import Argh (seed_keypair)
import qualified Crypto.Hash.SHA256 as SHA256
import Data.ByteString (ByteString)
import Data.Monoid ((<>))
import SSH.Key (PrivateKey(Ed25519PrivateKey), PublicKey(Ed25519PublicKey))

deriveKey :: ByteString -> ByteString -> (PublicKey, PrivateKey)
Expand Down
1 change: 0 additions & 1 deletion SSH/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module SSH.Types
, runStrictPut
) where

import Control.Applicative ((<$>))
import Data.Binary.Get (Get, getWord32be, getByteString, runGet)
import Data.Binary.Put (Put, putWord32be, putByteString, runPut)
import qualified Data.ByteString as B
Expand Down
2 changes: 0 additions & 2 deletions app/KeyTool.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module Main (main) where

import Control.Applicative ((<$>), (<*>))
import Control.Monad (when)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import Data.Monoid ((<>))
import Options.Applicative (eitherReader, Parser, strOption, long, short, metavar, help, option, ReadM, execParser, info, fullDesc, progDesc, header, helper)
import SSH.Key (PrivateKey(Ed25519PrivateKey), serialiseKey, parseKey, privateKeys)
import SSH.Key.Derived (deriveKey)
Expand Down
71 changes: 71 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/

# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/14.yaml

nix:
enable: true
packages: [ libsodium, zlib ]

# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
# extra-deps: []

# Override default flag values for local packages and extra-deps
# flags: {}

# Extra package databases containing global packages
# extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.7"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
13 changes: 13 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
snapshots:
- completed:
size: 586069
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/14.yaml
sha256: 87842ecbaa8ca9cee59a7e6be52369dbed82ed075cb4e0d152614a627e8fd488
original:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/14.yaml