Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit fd52607

Browse files
committed
tlsConfig passed via launcherConfig
1 parent bc3563c commit fd52607

File tree

5 files changed

+21
-35
lines changed

5 files changed

+21
-35
lines changed

cardano-launcher/app/Main.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ import Cardano.BM.Tracing
3939
import Cardano.Shell.Application (checkIfApplicationIsRunning)
4040
import Cardano.Shell.CLI (LauncherOptionPath, getDefaultConfigPath,
4141
getLauncherOptions, launcherArgsParser)
42-
import Cardano.Shell.Configuration (ConfigurationOptions (..),
43-
LauncherOptions (..),
42+
import Cardano.Shell.Configuration (LauncherOptions (..),
4443
DaedalusBin (..), getUpdaterData,
4544
getDPath,
4645
setWorkingDirectory)
@@ -51,6 +50,7 @@ import Cardano.Shell.Launcher (LoggingDependencies (..), TLSError,
5150
import Cardano.Shell.Launcher.Types (nullLogging)
5251
import Cardano.Shell.Update.Lib (UpdaterData (..),
5352
runDefaultUpdateProcess)
53+
import Cardano.X509.Configuration (TLSConfiguration)
5454

5555
--------------------------------------------------------------------------------
5656
-- Main
@@ -172,8 +172,8 @@ main = silence $ do
172172
throwM . WorkingDirectoryDoesNotExist $ workingDir
173173

174174
-- Configuration from the launcher options.
175-
let mConfigurationOptions :: Maybe ConfigurationOptions
176-
mConfigurationOptions = loConfiguration launcherOptions
175+
let mTlsConfig :: Maybe TLSConfiguration
176+
mTlsConfig = loTlsConfig launcherOptions
177177

178178
let daedalusBin :: DaedalusBin
179179
daedalusBin = getDPath launcherOptions
@@ -187,14 +187,14 @@ main = silence $ do
187187
mTlsPath = TLSPath <$> loTlsPath launcherOptions
188188

189189
-- If the path doesn't exist, then TLS has been disabled!
190-
case (mTlsPath, mConfigurationOptions) of
191-
(Just tlsPath, Just configurationOptions) -> do
190+
case (mTlsPath, mTlsConfig) of
191+
(Just tlsPath, Just tlsConfig) -> do
192192
-- | If we need to, we first check if there are certificates so we don't have
193193
-- to generate them. Since the function is called `generate...`, that's what
194194
-- it does, it generates the certificates.
195195
eTLSGeneration <- generateTlsCertificates
196196
loggingDependencies
197-
configurationOptions
197+
tlsConfig
198198
tlsPath
199199

200200
case eTLSGeneration of

cardano-launcher/cardano-launcher.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ executable cardano-launcher
7474
base >=4.7 && <5
7575
, cardano-prelude
7676
, cardano-launcher
77+
, cardano-sl-x509
7778
-- formatting
7879
, filepath
7980
, formatting

cardano-launcher/src/Cardano/Shell/Configuration.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Data.Yaml (FromJSON (..), withObject, (.:), (.:?))
2020
import System.Directory (doesDirectoryExist, setCurrentDirectory)
2121

2222
import Cardano.Shell.Update.Lib (UpdaterData (..))
23+
import Cardano.X509.Configuration (TLSConfiguration)
2324

2425
--------------------------------------------------------------------------------
2526
-- Configuration
@@ -43,6 +44,7 @@ newtype DaedalusBin = DaedalusBin
4344
data LauncherOptions = LauncherOptions
4445
{ loConfiguration :: !(Maybe ConfigurationOptions)
4546
, loTlsPath :: !(Maybe FilePath)
47+
, loTlsConfig :: !(Maybe TLSConfiguration)
4648
, loUpdaterPath :: !FilePath
4749
, loUpdaterArgs :: ![Text]
4850
, loUpdateArchive :: !FilePath
@@ -62,13 +64,15 @@ instance FromJSON LauncherOptions where
6264
updateArchive <- o .: "updateArchive"
6365
configuration <- o .:? "configuration"
6466
tlsPath <- o .:? "tlsPath"
67+
tlsConfig <- o .:? "tlsConfig"
6568
workingDir <- o .: "workingDir"
6669
stateDir <- o .: "stateDir"
6770
logsPrefix <- o .: "logsPrefix"
6871

6972
pure $ LauncherOptions
7073
configuration
7174
tlsPath
75+
tlsConfig
7276
updaterPath
7377
updaterArgs
7478
updateArchive

cardano-launcher/src/Cardano/Shell/Launcher.hs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,20 @@ import Prelude (Show (..))
3030
import qualified System.Process as Process
3131
import Turtle (system)
3232

33-
import Cardano.Shell.Configuration (ConfigurationOptions (..),
34-
WalletArguments (..),
33+
import Cardano.Shell.Configuration (WalletArguments (..),
3534
DaedalusBin (..))
3635
import Cardano.Shell.Launcher.Types (LoggingDependencies (..))
3736
import Cardano.Shell.Update.Lib (RemoveArchiveAfterInstall (..),
3837
RunUpdateFunc, UpdaterData (..),
3938
runUpdater)
40-
import Cardano.X509.Configuration (ConfigurationKey (..),
41-
DirConfiguration (..), certChecks,
39+
import Cardano.X509.Configuration (DirConfiguration (..), certChecks,
4240
certFilename, certOutDir,
43-
decodeConfigFile,
41+
TLSConfiguration,
4442
fromConfiguration, genCertificate)
45-
import Control.Exception.Safe (onException)
4643
import Data.X509.Extra (genRSA256KeyPair, validateCertificate,
4744
writeCertificate, writeCredentials)
4845
import Data.X509.Validation (FailedReason)
49-
import System.Directory (createDirectoryIfMissing, doesDirectoryExist,
50-
doesFileExist)
46+
import System.Directory (createDirectoryIfMissing)
5147
import System.FilePath ((</>))
5248

5349
--------------------------------------------------------------------------------
@@ -297,21 +293,18 @@ runLauncher loggingDependencies walletRunner daedalusBin runUpdateFunc updaterDa
297293
-- This just covers the generation of the TLS certificates and nothing else.
298294
generateTlsCertificates
299295
:: LoggingDependencies
300-
-> ConfigurationOptions
296+
-> TLSConfiguration
301297
-> TLSPath
302298
-> IO (Either TLSError ())
303-
generateTlsCertificates externalDependencies' configurationOptions (TLSPath tlsPath) = runExceptT $ do
304-
doesCertConfigExist <- liftIO $ doesFileExist (cfoFilePath configurationOptions)
305-
doesTLSPathExist <- liftIO $ doesDirectoryExist tlsPath
306-
unless doesCertConfigExist $ throwError . CertConfigNotFound . cfoFilePath $ configurationOptions
307-
unless doesTLSPathExist $ throwError . TLSDirectoryNotFound $ tlsPath
299+
generateTlsCertificates externalDependencies' tlsConfig (TLSPath tlsPath) = runExceptT $ do
308300

309301
let tlsServer = tlsPath </> "server"
310302
let tlsClient = tlsPath </> "client"
311303

312304
-- Create the directories.
313305
liftIO $ do
314306
logInfo externalDependencies' $ "Generating the certificates!"
307+
createDirectoryIfMissing True tlsPath
315308
createDirectoryIfMissing True tlsServer
316309
createDirectoryIfMissing True tlsClient
317310

@@ -322,23 +315,13 @@ generateTlsCertificates externalDependencies' configurationOptions (TLSPath tlsP
322315
-- `cardano-sl`.
323316
generateCertificates :: FilePath -> FilePath -> ExceptT TLSError IO ()
324317
generateCertificates tlsServer' tlsClient = do
325-
326-
let configFile = cfoFilePath configurationOptions
327-
-- Configuration key within the config file
328-
let configKey :: ConfigurationKey
329-
configKey = ConfigurationKey . textToFilePath . cfoKey $ configurationOptions
330-
331318
let outDirectories :: DirConfiguration -- ^ Output directories configuration
332319
outDirectories = DirConfiguration
333320
{ outDirServer = tlsServer'
334321
, outDirClients = tlsClient
335-
, outDirCA = Nothing -- TODO(KS): AFAIK, we don't output the CA.
322+
, outDirCA = Nothing
336323
}
337324

338-
-- TLS configuration
339-
tlsConfig <- decodeConfigFile configKey configFile `onException`
340-
(throwError . InvalidKey . cfoKey $ configurationOptions)
341-
342325
-- From configuraiton
343326
(caDesc, descs) <-
344327
liftIO $ fromConfiguration tlsConfig outDirectories genRSA256KeyPair <$> genRSA256KeyPair
@@ -366,9 +349,6 @@ generateTlsCertificates externalDependencies' configurationOptions (TLSPath tlsP
366349
liftIO $ do
367350
writeCredentials (certOutDir desc </> certFilename desc) (key, cert)
368351
writeCertificate (certOutDir desc </> caName) caCert
369-
-- Utility function.
370-
textToFilePath :: Text -> FilePath
371-
textToFilePath = strConv Strict
372352

373353
-- | Error that can be thrown when generating TSL certificates
374354
data TLSError =

nix/.stack.nix/cardano-launcher.nix

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)