|
| 1 | +-- | This module defines low-level bindings to the Node HTTPS module. |
| 2 | + |
| 3 | +module Node.HTTP.Secure |
| 4 | + ( createServer |
| 5 | + |
| 6 | + , SSLOptions |
| 7 | + , handshakeTimeout |
| 8 | + , requestCert |
| 9 | + , rejectUnauthorized |
| 10 | + |
| 11 | + , NPNProtocols |
| 12 | + , npnProtocolsString |
| 13 | + , npnProtocolsBuffer |
| 14 | + , npnProtocolsUint8Array |
| 15 | + , npnProtocolsStringArray |
| 16 | + , npnProtocolsBufferArray |
| 17 | + , npnProtocolsUint8ArrayArray |
| 18 | + , npnProtocols |
| 19 | + |
| 20 | + , ALPNProtocols |
| 21 | + , alpnProtocolsString |
| 22 | + , alpnProtocolsBuffer |
| 23 | + , alpnProtocolsUint8Array |
| 24 | + , alpnProtocolsStringArray |
| 25 | + , alpnProtocolsBufferArray |
| 26 | + , alpnProtocolsUint8ArrayArray |
| 27 | + , alpnProtocols |
| 28 | + |
| 29 | + , sessionTimeout |
| 30 | + , ticketKeys |
| 31 | + |
| 32 | + , PFX |
| 33 | + , pfxString |
| 34 | + , pfxBuffer |
| 35 | + , pfx |
| 36 | + |
| 37 | + , Key |
| 38 | + , keyString |
| 39 | + , keyBuffer |
| 40 | + , keyStringArray |
| 41 | + , keyBufferArray |
| 42 | + , key |
| 43 | + |
| 44 | + , passphrase |
| 45 | + |
| 46 | + , Cert |
| 47 | + , certString |
| 48 | + , certBuffer |
| 49 | + , certStringArray |
| 50 | + , certBufferArray |
| 51 | + , cert |
| 52 | + |
| 53 | + , CA |
| 54 | + , caString |
| 55 | + , caBuffer |
| 56 | + , caStringArray |
| 57 | + , caBufferArray |
| 58 | + , ca |
| 59 | + |
| 60 | + , CRL |
| 61 | + , crlString |
| 62 | + , crlBuffer |
| 63 | + , crlStringArray |
| 64 | + , crlBufferArray |
| 65 | + , crl |
| 66 | + |
| 67 | + , ciphers |
| 68 | + , honorCipherOrder |
| 69 | + , ecdhCurve |
| 70 | + |
| 71 | + , DHParam |
| 72 | + , dhparamString |
| 73 | + , dhparamBuffer |
| 74 | + , dhparam |
| 75 | + |
| 76 | + , secureProtocol |
| 77 | + , secureOptions |
| 78 | + , sessionIdContext |
| 79 | + ) where |
| 80 | + |
| 81 | +import Prelude |
| 82 | + |
| 83 | +import Control.Monad.Eff (Eff) |
| 84 | +import Data.ArrayBuffer.Types (Uint8Array) |
| 85 | +import Data.Foreign (Foreign) |
| 86 | +import Data.Options (Options, Option, options, opt) |
| 87 | +import Node.Buffer (Buffer) |
| 88 | +import Node.HTTP (Request, Response, Server, HTTP) |
| 89 | +import Unsafe.Coerce (unsafeCoerce) |
| 90 | + |
| 91 | +-- | The type of HTTPS server options |
| 92 | +data SSLOptions |
| 93 | + |
| 94 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) |
| 95 | +handshakeTimeout :: Option SSLOptions Int |
| 96 | +handshakeTimeout = opt "handshakeTimeout" |
| 97 | + |
| 98 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) |
| 99 | +requestCert :: Option SSLOptions Boolean |
| 100 | +requestCert = opt "requestCert" |
| 101 | + |
| 102 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) |
| 103 | +rejectUnauthorized :: Option SSLOptions Boolean |
| 104 | +rejectUnauthorized = opt "rejectUnauthorized" |
| 105 | + |
| 106 | +-- | The npnProtocols option can be a String, a Buffer, a Uint8Array, or an |
| 107 | +-- | array of any of those types. |
| 108 | +data NPNProtocols |
| 109 | +npnProtocolsString :: String -> NPNProtocols |
| 110 | +npnProtocolsString = unsafeCoerce |
| 111 | +npnProtocolsBuffer :: Buffer -> NPNProtocols |
| 112 | +npnProtocolsBuffer = unsafeCoerce |
| 113 | +npnProtocolsUint8Array :: Uint8Array -> NPNProtocols |
| 114 | +npnProtocolsUint8Array = unsafeCoerce |
| 115 | +npnProtocolsStringArray :: Array String -> NPNProtocols |
| 116 | +npnProtocolsStringArray = unsafeCoerce |
| 117 | +npnProtocolsBufferArray :: Array Buffer -> NPNProtocols |
| 118 | +npnProtocolsBufferArray = unsafeCoerce |
| 119 | +npnProtocolsUint8ArrayArray :: Array Uint8Array -> NPNProtocols |
| 120 | +npnProtocolsUint8ArrayArray = unsafeCoerce |
| 121 | + |
| 122 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) |
| 123 | +npnProtocols :: Option SSLOptions NPNProtocols |
| 124 | +npnProtocols = opt "NPNProtocols" |
| 125 | + |
| 126 | +-- | The alpnProtocols option can be a String, a Buffer, a Uint8Array, or an |
| 127 | +-- | array of any of those types. |
| 128 | +data ALPNProtocols |
| 129 | +alpnProtocolsString :: String -> ALPNProtocols |
| 130 | +alpnProtocolsString = unsafeCoerce |
| 131 | +alpnProtocolsBuffer :: Buffer -> ALPNProtocols |
| 132 | +alpnProtocolsBuffer = unsafeCoerce |
| 133 | +alpnProtocolsUint8Array :: Uint8Array -> ALPNProtocols |
| 134 | +alpnProtocolsUint8Array = unsafeCoerce |
| 135 | +alpnProtocolsStringArray :: Array String -> ALPNProtocols |
| 136 | +alpnProtocolsStringArray = unsafeCoerce |
| 137 | +alpnProtocolsBufferArray :: Array Buffer -> ALPNProtocols |
| 138 | +alpnProtocolsBufferArray = unsafeCoerce |
| 139 | +alpnProtocolsUint8ArrayArray :: Array Uint8Array -> ALPNProtocols |
| 140 | +alpnProtocolsUint8ArrayArray = unsafeCoerce |
| 141 | + |
| 142 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) |
| 143 | +alpnProtocols :: Option SSLOptions ALPNProtocols |
| 144 | +alpnProtocols = opt "ALPNProtocols" |
| 145 | + |
| 146 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) |
| 147 | +sessionTimeout :: Option SSLOptions Int |
| 148 | +sessionTimeout = opt "sessionTimeout" |
| 149 | + |
| 150 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) |
| 151 | +ticketKeys :: Option SSLOptions Buffer |
| 152 | +ticketKeys = opt "ticketKeys" |
| 153 | + |
| 154 | +-- | The PFX option can take either a String or a Buffer |
| 155 | +data PFX |
| 156 | +pfxString :: String -> PFX |
| 157 | +pfxString = unsafeCoerce |
| 158 | +pfxBuffer :: Buffer -> PFX |
| 159 | +pfxBuffer = unsafeCoerce |
| 160 | + |
| 161 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 162 | +pfx :: Option SSLOptions PFX |
| 163 | +pfx = opt "pfx" |
| 164 | + |
| 165 | +-- | The key option can be a String, a Buffer, an array of strings, or an array |
| 166 | +-- | of buffers. |
| 167 | +data Key |
| 168 | +keyString :: String -> Key |
| 169 | +keyString = unsafeCoerce |
| 170 | +keyBuffer :: Buffer -> Key |
| 171 | +keyBuffer = unsafeCoerce |
| 172 | +keyStringArray :: Array String -> Key |
| 173 | +keyStringArray = unsafeCoerce |
| 174 | +keyBufferArray :: Array Buffer -> Key |
| 175 | +keyBufferArray = unsafeCoerce |
| 176 | + |
| 177 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 178 | +key :: Option SSLOptions Key |
| 179 | +key = opt "key" |
| 180 | + |
| 181 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 182 | +passphrase :: Option SSLOptions String |
| 183 | +passphrase = opt "passphrase" |
| 184 | + |
| 185 | +-- | The cert option can be a String, a Buffer, an array of strings, or an array |
| 186 | +-- | of buffers. |
| 187 | +data Cert |
| 188 | +certString :: String -> Cert |
| 189 | +certString = unsafeCoerce |
| 190 | +certBuffer :: Buffer -> Cert |
| 191 | +certBuffer = unsafeCoerce |
| 192 | +certStringArray :: Array String -> Cert |
| 193 | +certStringArray = unsafeCoerce |
| 194 | +certBufferArray :: Array Buffer -> Cert |
| 195 | +certBufferArray = unsafeCoerce |
| 196 | + |
| 197 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 198 | +cert :: Option SSLOptions Cert |
| 199 | +cert = opt "cert" |
| 200 | + |
| 201 | +-- | The CA option can be a String, a Buffer, an array of strings, or an array |
| 202 | +-- | of buffers. |
| 203 | +data CA |
| 204 | +caString :: String -> CA |
| 205 | +caString = unsafeCoerce |
| 206 | +caBuffer :: Buffer -> CA |
| 207 | +caBuffer = unsafeCoerce |
| 208 | +caStringArray :: Array String -> CA |
| 209 | +caStringArray = unsafeCoerce |
| 210 | +caBufferArray :: Array Buffer -> CA |
| 211 | +caBufferArray = unsafeCoerce |
| 212 | + |
| 213 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 214 | +ca :: Option SSLOptions CA |
| 215 | +ca = opt "ca" |
| 216 | + |
| 217 | +-- | The CRL option can be a String, a Buffer, an array of strings, or an array |
| 218 | +-- | of buffers. |
| 219 | +data CRL |
| 220 | +crlString :: String -> CRL |
| 221 | +crlString = unsafeCoerce |
| 222 | +crlBuffer :: Buffer -> CRL |
| 223 | +crlBuffer = unsafeCoerce |
| 224 | +crlStringArray :: Array String -> CRL |
| 225 | +crlStringArray = unsafeCoerce |
| 226 | +crlBufferArray :: Array Buffer -> CRL |
| 227 | +crlBufferArray = unsafeCoerce |
| 228 | + |
| 229 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 230 | +crl :: Option SSLOptions CRL |
| 231 | +crl = opt "crl" |
| 232 | + |
| 233 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 234 | +ciphers :: Option SSLOptions String |
| 235 | +ciphers = opt "ciphers" |
| 236 | + |
| 237 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 238 | +honorCipherOrder :: Option SSLOptions Boolean |
| 239 | +honorCipherOrder = opt "honorCipherOrder" |
| 240 | + |
| 241 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 242 | +ecdhCurve :: Option SSLOptions String |
| 243 | +ecdhCurve = opt "ecdhCurve" |
| 244 | + |
| 245 | +-- | The DHParam option can take either a String or a Buffer |
| 246 | +data DHParam |
| 247 | +dhparamString :: String -> DHParam |
| 248 | +dhparamString = unsafeCoerce |
| 249 | +dhparamBuffer :: Buffer -> DHParam |
| 250 | +dhparamBuffer = unsafeCoerce |
| 251 | + |
| 252 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 253 | +dhparam :: Option SSLOptions DHParam |
| 254 | +dhparam = opt "dhparam" |
| 255 | + |
| 256 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 257 | +secureProtocol :: Option SSLOptions String |
| 258 | +secureProtocol = opt "secureProtocol" |
| 259 | + |
| 260 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 261 | +secureOptions :: Option SSLOptions Int |
| 262 | +secureOptions = opt "secureOptions" |
| 263 | + |
| 264 | +-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) |
| 265 | +sessionIdContext :: Option SSLOptions String |
| 266 | +sessionIdContext = opt "sessionIdContext" |
| 267 | + |
| 268 | +-- | Create an HTTPS server, given the SSL options and a function to be executed |
| 269 | +-- | when a request is received. |
| 270 | +foreign import createServerImpl :: |
| 271 | + forall eff. |
| 272 | + Foreign -> |
| 273 | + (Request -> Response -> Eff (http :: HTTP | eff) Unit) -> |
| 274 | + Eff (http :: HTTP | eff) Server |
| 275 | + |
| 276 | +-- | Create an HTTPS server, given the SSL options and a function to be executed |
| 277 | +-- | when a request is received. |
| 278 | +createServer :: forall eff. |
| 279 | + Options SSLOptions -> |
| 280 | + (Request -> Response -> Eff (http :: HTTP | eff) Unit) -> |
| 281 | + Eff (http :: HTTP | eff) Server |
| 282 | +createServer = createServerImpl <<< options |
0 commit comments