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

Commit 834ade8

Browse files
committed
[DEVOPS-992] Fix x509 generator SANs to work with IP addresses
1 parent 3a6e31a commit 834ade8

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed

pkgs/default.nix

+46
Original file line numberDiff line numberDiff line change
@@ -17128,11 +17128,13 @@ license = stdenv.lib.licenses.mit;
1712817128
, hedgehog
1712917129
, hourglass
1713017130
, hspec
17131+
, ip
1713117132
, lens
1713217133
, lifted-async
1713317134
, log-warper
1713417135
, mtl
1713517136
, neat-interpolation
17137+
, network-transport
1713617138
, network-transport-tcp
1713717139
, optparse-applicative
1713817140
, optparse-generic
@@ -17243,11 +17245,13 @@ filepath
1724317245
formatting
1724417246
Glob
1724517247
hourglass
17248+
ip
1724617249
lens
1724717250
lifted-async
1724817251
log-warper
1724917252
mtl
1725017253
neat-interpolation
17254+
network-transport
1725117255
network-transport-tcp
1725217256
optparse-applicative
1725317257
optparse-generic
@@ -46047,6 +46051,48 @@ homepage = "http://snapframework.com/";
4604746051
description = "HAProxy protocol 1.5 support for io-streams";
4604846052
license = stdenv.lib.licenses.bsd3;
4604946053

46054+
}) {};
46055+
"ip" = callPackage
46056+
({
46057+
mkDerivation
46058+
, aeson
46059+
, attoparsec
46060+
, base
46061+
, bytestring
46062+
, fetchgit
46063+
, hashable
46064+
, primitive
46065+
, stdenv
46066+
, text
46067+
, vector
46068+
}:
46069+
mkDerivation {
46070+
46071+
pname = "ip";
46072+
version = "1.3.0";
46073+
src = fetchgit {
46074+
46075+
url = "https://github.com/andrewthad/haskell-ip";
46076+
sha256 = "199mfpbgca7rvwvwk2zsmcpibc0sk0ni7c5zlf4gk3cps8s85gyr";
46077+
rev = "9bb453139aa82cc973125091800422a523e1eb8f";
46078+
46079+
};
46080+
libraryHaskellDepends = [
46081+
aeson
46082+
attoparsec
46083+
base
46084+
bytestring
46085+
hashable
46086+
primitive
46087+
text
46088+
vector
46089+
];
46090+
doHaddock = false;
46091+
doCheck = false;
46092+
homepage = "https://github.com/andrewthad/haskell-ip#readme";
46093+
description = "Library for IP and MAC addresses";
46094+
license = stdenv.lib.licenses.bsd3;
46095+
4605046096
}) {};
4605146097
"ip6addr" = callPackage
4605246098
({

scripts/launch/connect-to-cluster/default.nix

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
, system ? builtins.currentSystem
88
, pkgs ? import localLib.fetchNixPkgs { inherit system config; }
99
, gitrev ? localLib.commitIdFromGitRepo ./../../../.git
10-
, walletListen ? "localhost:8090"
11-
, walletDocListen ? "localhost:8091"
12-
, ekgListen ? "localhost:8000"
10+
, walletListen ? "127.0.0.1:8090"
11+
, walletDocListen ? "127.0.0.1:8091"
12+
, ekgListen ? "127.0.0.1:8000"
1313
, ghcRuntimeArgs ? "-N2 -qg -A1m -I0 -T"
1414
, additionalNodeArgs ? ""
1515
, confFile ? null

stack.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ packages:
5858
git: https://github.com/input-output-hk/cardano-crypto
5959
commit: 33c7ecc6e4bd71c3ea0195e9d796eeace7be22cf
6060
extra-dep: true
61+
# to be removed when haskell-ip is in the current stackage version
62+
- location:
63+
git: https://github.com/andrewthad/haskell-ip
64+
commit: 9bb453139aa82cc973125091800422a523e1eb8f
65+
extra-dep: true
6166

6267
## Vendored/Forked dependencies
6368
#

tools/cardano-sl-tools.cabal

+6-3
Original file line numberDiff line numberDiff line change
@@ -479,18 +479,21 @@ executable cardano-x509-certificates
479479
, aeson
480480
, asn1-encoding
481481
, asn1-types
482-
, bytestring
483482
, base64-bytestring
483+
, bytestring
484484
, cryptonite
485+
, data-default-class
485486
, filepath
486487
, hourglass
488+
, ip
489+
, network-transport
487490
, optparse-applicative
491+
, text
488492
, universum
489493
, unordered-containers
490494
, x509
491-
, x509-validation
492495
, x509-store
493-
, data-default-class
496+
, x509-validation
494497
, yaml
495498

496499
default-extensions: DeriveGeneric

tools/src/gencerts/Configuration.hs

+22-1
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ import Data.X509
2121
import Data.X509.Validation (ValidationChecks (..), defaultChecks)
2222
import Data.Yaml (decodeFileEither, parseMonad, withObject)
2323
import GHC.Generics (Generic)
24+
import Net.IP (IP, case_, decode)
25+
import Net.IPv4 (IPv4 (..))
26+
import Net.IPv6 (IPv6 (..))
27+
import Network.Transport.Internal (encodeWord32)
2428
import System.IO (FilePath)
2529

2630
import qualified Data.Aeson as Aeson
2731
import qualified Data.Aeson.Types as Aeson
32+
import qualified Data.ByteString.Builder as BS
33+
import qualified Data.ByteString.Lazy as LBS
2834
import qualified Data.Char as Char
2935
import qualified Data.HashMap.Lazy as HM
3036
import qualified Data.List.NonEmpty as NonEmpty
37+
import qualified Data.Text as T
3138

3239

3340
-- | Type-alias for signature readability
@@ -225,10 +232,24 @@ usExtensionsV3 purpose subDN issDN =
225232
svExtensionsV3 :: DistinguishedName -> DistinguishedName -> NonEmpty String -> [ExtensionRaw]
226233
svExtensionsV3 subDN issDN altNames =
227234
let
228-
subjectAltName = ExtSubjectAltName (AltNameDNS <$> NonEmpty.toList altNames)
235+
subjectAltName = ExtSubjectAltName ( parseAltName <$> NonEmpty.toList altNames)
229236
in
230237
extensionEncode False subjectAltName : usExtensionsV3 KeyUsagePurpose_ServerAuth subDN issDN
231238

239+
parseAltName :: String -> AltName
240+
parseAltName name = do
241+
let
242+
ipv4ToByteString :: IPv4 -> ByteString
243+
ipv4ToByteString (IPv4 bytes) = encodeWord32 bytes
244+
ipv6ToByteString :: IPv6 -> ByteString
245+
ipv6ToByteString ipv6 = LBS.toStrict (BS.toLazyByteString $ ipv6ByteStringBuilder ipv6)
246+
ipv6ByteStringBuilder :: IPv6 -> BS.Builder
247+
ipv6ByteStringBuilder (IPv6 parta partb) = BS.word64BE parta <> BS.word64BE partb
248+
249+
go :: Maybe IP -> AltName
250+
go (Just address) = AltNameIP $ case_ ipv4ToByteString ipv6ToByteString address
251+
go Nothing = AltNameDNS name
252+
go $ decode $ T.pack name
232253

233254
clExtensionsV3 :: DistinguishedName -> DistinguishedName -> [ExtensionRaw]
234255
clExtensionsV3 =

0 commit comments

Comments
 (0)