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

Commit 2a0d779

Browse files
authored
Merge pull request #3390 from input-output-hk/devops-992-x509-san-backport-release
[DEVOPS-992] Fix x509 generator SANs to work with IP addresses
2 parents 350d158 + 24899b0 commit 2a0d779

File tree

4 files changed

+79
-4
lines changed

4 files changed

+79
-4
lines changed

pkgs/default.nix

+46
Original file line numberDiff line numberDiff line change
@@ -17386,11 +17386,13 @@ license = stdenv.lib.licenses.mit;
1738617386
, Glob
1738717387
, hourglass
1738817388
, hspec
17389+
, ip
1738917390
, lens
1739017391
, lifted-async
1739117392
, log-warper
1739217393
, mtl
1739317394
, neat-interpolation
17395+
, network-transport
1739417396
, network-transport-tcp
1739517397
, optparse-applicative
1739617398
, optparse-generic
@@ -17477,11 +17479,13 @@ filepath
1747717479
formatting
1747817480
Glob
1747917481
hourglass
17482+
ip
1748017483
lens
1748117484
lifted-async
1748217485
log-warper
1748317486
mtl
1748417487
neat-interpolation
17488+
network-transport
1748517489
network-transport-tcp
1748617490
optparse-applicative
1748717491
optparse-generic
@@ -46471,6 +46475,48 @@ homepage = "http://snapframework.com/";
4647146475
description = "HAProxy protocol 1.5 support for io-streams";
4647246476
license = stdenv.lib.licenses.bsd3;
4647346477

46478+
}) {};
46479+
"ip" = callPackage
46480+
({
46481+
mkDerivation
46482+
, aeson
46483+
, attoparsec
46484+
, base
46485+
, bytestring
46486+
, fetchgit
46487+
, hashable
46488+
, primitive
46489+
, stdenv
46490+
, text
46491+
, vector
46492+
}:
46493+
mkDerivation {
46494+
46495+
pname = "ip";
46496+
version = "1.3.0";
46497+
src = fetchgit {
46498+
46499+
url = "https://github.com/andrewthad/haskell-ip";
46500+
sha256 = "199mfpbgca7rvwvwk2zsmcpibc0sk0ni7c5zlf4gk3cps8s85gyr";
46501+
rev = "9bb453139aa82cc973125091800422a523e1eb8f";
46502+
46503+
};
46504+
libraryHaskellDepends = [
46505+
aeson
46506+
attoparsec
46507+
base
46508+
bytestring
46509+
hashable
46510+
primitive
46511+
text
46512+
vector
46513+
];
46514+
doHaddock = false;
46515+
doCheck = false;
46516+
homepage = "https://github.com/andrewthad/haskell-ip#readme";
46517+
description = "Library for IP and MAC addresses";
46518+
license = stdenv.lib.licenses.bsd3;
46519+
4647446520
}) {};
4647546521
"ip6addr" = callPackage
4647646522
({

stack.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ packages:
9292
git: https://github.com/input-output-hk/cardano-crypto
9393
commit: 287cc575fafe86af9d24af9d012c47f9d3f04da0
9494
extra-dep: true
95+
# to be removed when haskell-ip is in the current stackage version
96+
- location:
97+
git: https://github.com/andrewthad/haskell-ip
98+
commit: 9bb453139aa82cc973125091800422a523e1eb8f
99+
extra-dep: true
95100

96101
# Required for explorer.
97102
# We forked it because it has some unacceptable version bounds. We didn't

tools/cardano-sl-tools.cabal

+6-3
Original file line numberDiff line numberDiff line change
@@ -499,18 +499,21 @@ executable cardano-x509-certificates
499499
, aeson
500500
, asn1-encoding
501501
, asn1-types
502-
, bytestring
503502
, base64-bytestring
503+
, bytestring
504504
, cryptonite
505+
, data-default-class
505506
, filepath
506507
, hourglass
508+
, ip
509+
, network-transport
507510
, optparse-applicative
511+
, text
508512
, universum
509513
, unordered-containers
510514
, x509
511-
, x509-validation
512515
, x509-store
513-
, data-default-class
516+
, x509-validation
514517
, yaml
515518

516519
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)