Skip to content

Commit 35f755a

Browse files
Move TlsSecureContextOptions to types
1 parent b9879c6 commit 35f755a

File tree

3 files changed

+173
-54
lines changed

3 files changed

+173
-54
lines changed

src/Node/Http2/Client.purs

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module Node.Http2.Client
77
import Data.Maybe (Maybe(..), fromMaybe)
88
import Effect (Effect)
99
import Effect.Uncurried (EffectFn1, EffectFn2, runEffectFn1, runEffectFn2)
10-
import Node.Http2.Types (Client, Http2Session, Settings)
10+
import Node.Buffer.Immutable (ImmutableBuffer)
11+
import Node.Http2.Types (Client, Http2Session, Settings, TlsSecureContextOptions)
12+
import Node.Net.Socket (Socket)
1113
import Type.Row (type (+))
1214

1315
connect :: String -> Effect (Http2Session Client)
@@ -48,9 +50,44 @@ type ConnectOptions f r =
4850
| r
4951
)
5052

53+
type TlsConnectOptions :: (Type -> Type) -> Row Type -> Row Type
54+
type TlsConnectOptions f r =
55+
( enableTrace :: f Boolean
56+
, socket :: f Socket
57+
, allowHalfOpen :: f Boolean
58+
, rejectUnauthorized :: f Boolean
59+
-- , pskCallback :: <Function
60+
, "ALPNProtocols" :: f (Array ImmutableBuffer)
61+
, servername :: f String
62+
-- , checkServerIdentity :: EffectFn2 String ? (Nullable Error) -- ignoring for now
63+
, session :: f ImmutableBuffer
64+
, minDHSize :: f Int
65+
, highWaterMark :: f Int
66+
-- , secureContext :: f TlsSecureContext -- ignoring for now
67+
-- , onread :: <Object> -- ignoring
68+
| r
69+
)
70+
71+
type TcpConnectOptions :: (Type -> Type) -> Row Type -> Row Type
72+
type TcpConnectOptions f r =
73+
( port :: f Int
74+
, host :: f String
75+
, localAddress :: f String
76+
, localPort :: f Int
77+
, family :: f Int
78+
-- , hints :: f number
79+
-- , lookup :: f Function
80+
, noDelay :: f Boolean
81+
, keepAlive :: f Boolean
82+
, keepAliveInitialDelay :: f Number -- is this milliseconds or seconds?
83+
-- , autoSelectFamily :: f Boolean
84+
-- , autoSelectFamilyAttemptTimeout :: f number
85+
| r
86+
)
87+
5188
connect'
5289
:: String
53-
-> ({ | ConnectOptions Maybe + () } -> { | ConnectOptions Maybe + () })
90+
-> ({ | ConnectOptions Maybe + TlsConnectOptions Maybe + TlsSecureContextOptions Maybe + TcpConnectOptions Maybe + () } -> { | ConnectOptions Maybe + TlsConnectOptions Maybe + TlsSecureContextOptions Maybe + TcpConnectOptions Maybe + () })
5491
-> Effect (Http2Session Client)
5592
connect' authority buildOptions = do
5693
let
@@ -67,9 +104,50 @@ connect' authority buildOptions = do
67104
, protocol: Nothing
68105
, settings: Nothing
69106
, unknownProtocolTimeout: Nothing
107+
-- TlsConnect
108+
, enableTrace: Nothing
109+
, socket: Nothing
110+
, allowHalfOpen: Nothing
111+
, rejectUnauthorized: Nothing
112+
, "ALPNProtocols": Nothing
113+
, servername: Nothing
114+
, session: Nothing
115+
, minDHSize: Nothing
116+
, highWaterMark: Nothing
117+
-- TlsSecureContext
118+
, ca: Nothing
119+
, cert: Nothing
120+
, sigalgs: Nothing
121+
, ciphers: Nothing
122+
, clientCertEngine: Nothing
123+
, crl: Nothing
124+
, dhparam: Nothing
125+
, ecdhCurve: Nothing
126+
, honorCipherOrder: Nothing
127+
, key: Nothing
128+
, privateKeyEngine: Nothing
129+
, privateKeyIdentifier: Nothing
130+
, maxVersion: Nothing
131+
, minVersion: Nothing
132+
, passphrase: Nothing
133+
, pfx: Nothing
134+
, secureOptions: Nothing
135+
, secureProtocol: Nothing
136+
, sessionIdContext: Nothing
137+
, ticketKeys: Nothing
138+
, sessionTimeout: Nothing
139+
-- TcpConnect
140+
, port: Nothing
141+
, host: Nothing
142+
, localAddress: Nothing
143+
, localPort: Nothing
144+
, family: Nothing
145+
, noDelay: Nothing
146+
, keepAlive: Nothing
147+
, keepAliveInitialDelay: Nothing
70148
}
71149

72-
finalOptions :: { | ConnectOptions Unlift () }
150+
finalOptions :: { | ConnectOptions Unlift + TlsConnectOptions Unlift + TlsSecureContextOptions Unlift + TcpConnectOptions Unlift + () }
73151
finalOptions =
74152
{ maxDeflateDynamicTableSize: fromMaybe undefined o.maxDeflateDynamicTableSize
75153
, maxSettings: fromMaybe undefined o.maxSettings
@@ -83,11 +161,52 @@ connect' authority buildOptions = do
83161
, protocol: fromMaybe undefined o.protocol
84162
, settings: fromMaybe undefined o.settings
85163
, unknownProtocolTimeout: fromMaybe undefined o.unknownProtocolTimeout
164+
-- TlsConnect
165+
, enableTrace: fromMaybe undefined o.enableTrace
166+
, socket: fromMaybe undefined o.socket
167+
, allowHalfOpen: fromMaybe undefined o.allowHalfOpen
168+
, rejectUnauthorized: fromMaybe undefined o.rejectUnauthorized
169+
, "ALPNProtocols": fromMaybe undefined o."ALPNProtocols"
170+
, servername: fromMaybe undefined o.servername
171+
, session: fromMaybe undefined o.session
172+
, minDHSize: fromMaybe undefined o.minDHSize
173+
, highWaterMark: fromMaybe undefined o.highWaterMark
174+
-- TlsSecureContext
175+
, ca: fromMaybe undefined o.ca
176+
, cert: fromMaybe undefined o.cert
177+
, sigalgs: fromMaybe undefined o.sigalgs
178+
, ciphers: fromMaybe undefined o.ciphers
179+
, clientCertEngine: fromMaybe undefined o.clientCertEngine
180+
, crl: fromMaybe undefined o.crl
181+
, dhparam: fromMaybe undefined o.dhparam
182+
, ecdhCurve: fromMaybe undefined o.ecdhCurve
183+
, honorCipherOrder: fromMaybe undefined o.honorCipherOrder
184+
, key: fromMaybe undefined o.key
185+
, privateKeyEngine: fromMaybe undefined o.privateKeyEngine
186+
, privateKeyIdentifier: fromMaybe undefined o.privateKeyIdentifier
187+
, maxVersion: fromMaybe undefined o.maxVersion
188+
, minVersion: fromMaybe undefined o.minVersion
189+
, passphrase: fromMaybe undefined o.passphrase
190+
, pfx: fromMaybe undefined o.pfx
191+
, secureOptions: fromMaybe undefined o.secureOptions
192+
, secureProtocol: fromMaybe undefined o.secureProtocol
193+
, sessionIdContext: fromMaybe undefined o.sessionIdContext
194+
, ticketKeys: fromMaybe undefined o.ticketKeys
195+
, sessionTimeout: fromMaybe undefined o.sessionTimeout
196+
-- TcpConnect
197+
, port: fromMaybe undefined o.port
198+
, host: fromMaybe undefined o.host
199+
, localAddress: fromMaybe undefined o.localAddress
200+
, localPort: fromMaybe undefined o.localPort
201+
, family: fromMaybe undefined o.family
202+
, noDelay: fromMaybe undefined o.noDelay
203+
, keepAlive: fromMaybe undefined o.keepAlive
204+
, keepAliveInitialDelay: fromMaybe undefined o.keepAliveInitialDelay
86205
}
87206

88207
runEffectFn2 connectAuthOptionsImpl authority finalOptions
89208

90-
foreign import connectAuthOptionsImpl :: EffectFn2 (String) ({ | ConnectOptions Unlift + () }) (Http2Session Client)
209+
foreign import connectAuthOptionsImpl :: EffectFn2 (String) ({ | ConnectOptions Unlift + TlsConnectOptions Unlift + TlsSecureContextOptions Unlift + TcpConnectOptions Unlift + () }) (Http2Session Client)
91210

92211
type Unlift :: Type -> Type
93212
type Unlift a = a

src/Node/Http2/Server.purs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Node.Http2.Server
22
( Http2CreateSecureServerOptions
33
, TlsCreateServerOptions
4-
, TlsSecureContextOptions
54
, NetCreateServerOptions
65
, createSecureServer
76
, listen
@@ -26,8 +25,7 @@ import Data.Time.Duration (Milliseconds)
2625
import Effect (Effect)
2726
import Effect.Exception (Error)
2827
import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn4, mkEffectFn1, mkEffectFn2, mkEffectFn4, runEffectFn1, runEffectFn2)
29-
import Node.Buffer.Immutable (ImmutableBuffer)
30-
import Node.Http2.Types (Headers, Http2SecureServer, Http2ServerRequest, Http2ServerResponse, Http2Session, Http2Stream, Server, Settings)
28+
import Node.Http2.Types (Headers, Http2SecureServer, Http2ServerRequest, Http2ServerResponse, Http2Session, Http2Stream, Server, Settings, TlsSecureContextOptions)
3129
import Node.Stream (Duplex)
3230
import Type.Row (type (+))
3331

@@ -94,53 +92,6 @@ type TlsCreateServerOptions f r =
9492
| r
9593
)
9694

97-
-- | `ca` <string> | <string[]> | <Buffer> | <Buffer[]> Optionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla. Mozilla's CAs are completely replaced when CAs are explicitly specified using this option. The value can be a string or Buffer, or an Array of strings and/or Buffers. Any string or Buffer can contain multiple PEM CAs concatenated together. The peer's certificate must be chainable to a CA trusted by the server for the connection to be authenticated. When using certificates that are not chainable to a well-known CA, the certificate's CA must be explicitly specified as a trusted or the connection will fail to authenticate. If the peer uses a certificate that doesn't match or chain to one of the default CAs, use the ca option to provide a CA certificate that the peer's certificate can match or chain to. For self-signed certificates, the certificate is its own CA, and must be provided. For PEM encoded certificates, supported types are "TRUSTED CERTIFICATE", "X509 CERTIFICATE", and "CERTIFICATE". See also tls.rootCertificates.
98-
-- | `cert` <string> | <string[]> | <Buffer> | <Buffer[]> Cert chains in PEM format. One cert chain should be provided per private key. Each cert chain should consist of the PEM formatted certificate for a provided private key, followed by the PEM formatted intermediate certificates (if any), in order, and not including the root CA (the root CA must be pre-known to the peer, see ca). When providing multiple cert chains, they do not have to be in the same order as their private keys in key. If the intermediate certificates are not provided, the peer will not be able to validate the certificate, and the handshake will fail.
99-
-- | `sigalgs` <string> Colon-separated list of supported signature algorithms. The list can contain digest algorithms (SHA256, MD5 etc.), public key algorithms (RSA-PSS, ECDSA etc.), combination of both (e.g 'RSA+SHA384') or TLS v1.3 scheme names (e.g. rsa_pss_pss_sha512). See OpenSSL man pages for more info.
100-
-- | `ciphers` <string> Cipher suite specification, replacing the default. For more information, see Modifying the default TLS cipher suite. Permitted ciphers can be obtained via tls.getCiphers(). Cipher names must be uppercased in order for OpenSSL to accept them.
101-
-- | `clientCertEngine` <string> Name of an OpenSSL engine which can provide the client certificate.
102-
-- | `crl` <string> | <string[]> | <Buffer> | <Buffer[]> PEM formatted CRLs (Certificate Revocation Lists).
103-
-- | `dhparam` <string> | <Buffer> 'auto' or custom Diffie-Hellman parameters, required for non-ECDHE perfect forward secrecy. If omitted or invalid, the parameters are silently discarded and DHE ciphers will not be available. ECDHE-based perfect forward secrecy will still be available.
104-
-- | `ecdhCurve` <string> A string describing a named curve or a colon separated list of curve NIDs or names, for example P-521:P-384:P-256, to use for ECDH key agreement. Set to auto to select the curve automatically. Use crypto.getCurves() to obtain a list of available curve names. On recent releases, openssl ecparam -list_curves will also display the name and description of each available elliptic curve. Default: tls.DEFAULT_ECDH_CURVE.
105-
-- | `honorCipherOrder` <boolean> Attempt to use the server's cipher suite preferences instead of the client's. When true, causes SSL_OP_CIPHER_SERVER_PREFERENCE to be set in secureOptions, see OpenSSL Options for more information.
106-
-- | `key` <string> | <string[]> | <Buffer> | <Buffer[]> | <Object[]> Private keys in PEM format. PEM allows the option of private keys being encrypted. Encrypted keys will be decrypted with options.passphrase. Multiple keys using different algorithms can be provided either as an array of unencrypted key strings or buffers, or an array of objects in the form {pem: <string|buffer>[, passphrase: <string>]}. The object form can only occur in an array. object.passphrase is optional. Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.
107-
-- | `privateKeyEngine` <string> Name of an OpenSSL engine to get private key from. Should be used together with privateKeyIdentifier.
108-
-- | `privateKeyIdentifier` <string> Identifier of a private key managed by an OpenSSL engine. Should be used together with privateKeyEngine. Should not be set together with key, because both options define a private key in different ways.
109-
-- | `maxVersion` <string> Optionally set the maximum TLS version to allow. One of 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Cannot be specified along with the secureProtocol option; use one or the other. Default: tls.DEFAULT_MAX_VERSION.
110-
-- | `minVersion` <string> Optionally set the minimum TLS version to allow. One of 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Cannot be specified along with the secureProtocol option; use one or the other. Avoid setting to less than TLSv1.2, but it may be required for interoperability. Default: tls.DEFAULT_MIN_VERSION.
111-
-- | `passphrase` <string> Shared passphrase used for a single private key and/or a PFX.
112-
-- | `pfx` <string> | <string[]> | <Buffer> | <Buffer[]> | <Object[]> PFX or PKCS12 encoded private key and certificate chain. pfx is an alternative to providing key and cert individually. PFX is usually encrypted, if it is, passphrase will be used to decrypt it. Multiple PFX can be provided either as an array of unencrypted PFX buffers, or an array of objects in the form {buf: <string|buffer>[, passphrase: <string>]}. The object form can only occur in an array. object.passphrase is optional. Encrypted PFX will be decrypted with object.passphrase if provided, or options.passphrase if it is not.
113-
-- | `secureOptions` <number> Optionally affect the OpenSSL protocol behavior, which is not usually necessary. This should be used carefully if at all! Value is a numeric bitmask of the SSL_OP_* options from OpenSSL Options.
114-
-- | `secureProtocol` <string> Legacy mechanism to select the TLS protocol version to use, it does not support independent control of the minimum and maximum version, and does not support limiting the protocol to TLSv1.3. Use minVersion and maxVersion instead. The possible values are listed as SSL_METHODS, use the function names as strings. For example, use 'TLSv1_1_method' to force TLS version 1.1, or 'TLS_method' to allow any TLS protocol version up to TLSv1.3. It is not recommended to use TLS versions less than 1.2, but it may be required for interoperability. Default: none, see minVersion.
115-
-- | `sessionIdContext` <string> Opaque identifier used by servers to ensure session state is not shared between applications. Unused by clients.
116-
-- | `ticketKeys`: <Buffer> 48-bytes of cryptographically strong pseudorandom data. See Session Resumption for more information.
117-
-- | `sessionTimeout` <number> The number of seconds after which a TLS session created by the server will no longer be resumable. See Session Resumption for more information. Default: 300.
118-
type TlsSecureContextOptions :: (Type -> Type) -> Row Type -> Row Type
119-
type TlsSecureContextOptions f r =
120-
( ca :: f (Array ImmutableBuffer)
121-
, cert :: f (Array ImmutableBuffer)
122-
, sigalgs :: f String
123-
, ciphers :: f String
124-
, clientCertEngine :: f String
125-
, crl :: f (Array ImmutableBuffer)
126-
, dhparam :: f (Array ImmutableBuffer)
127-
, ecdhCurve :: f String
128-
, honorCipherOrder :: f Boolean
129-
, key :: f (Array ImmutableBuffer)
130-
, privateKeyEngine :: f String
131-
, privateKeyIdentifier :: f String
132-
, maxVersion :: f String
133-
, minVersion :: f String
134-
, passphrase :: f String
135-
, pfx :: f (Array ImmutableBuffer)
136-
, secureOptions :: f Int
137-
, secureProtocol :: f String
138-
, sessionIdContext :: f String
139-
, ticketKeys :: f ImmutableBuffer
140-
, sessionTimeout :: f Int
141-
| r
142-
)
143-
14495
-- | `allowHalfOpen` <boolean> If set to false, then the socket will automatically end the writable side when the readable side ends. Default: false.
14596
-- | `pauseOnConnet` <boolean> Indicates whether the socket should be paused on incoming connections. Default: false.
14697
-- | `noDelay` <booean> If set to true, it disables the use of Nagle's algorithm immediately after a new incoming connection is received. Default: false.

0 commit comments

Comments
 (0)