cowboy_req.cert.asciidoc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. = cowboy_req:cert(3)
  2. == Name
  3. cowboy_req:cert - Client TLS certificate
  4. == Description
  5. [source,erlang]
  6. ----
  7. cert(Req :: cowboy_req:req()) -> binary() | undefined
  8. ----
  9. Return the peer's TLS certificate.
  10. Using the default configuration this function will always return
  11. `undefined`. You need to explicitly configure Cowboy to request
  12. the client certificate. To do this you need to set the `verify`
  13. transport option to `verify_peer`:
  14. [source,erlang]
  15. ----
  16. {ok, _} = cowboy:start_tls(example, [
  17. {port, 8443},
  18. {certfile, "path/to/cert.pem"},
  19. {verify, verify_peer}
  20. ], #{
  21. env => #{dispatch => Dispatch}
  22. }).
  23. ----
  24. You may also want to customize the `verify_fun` function. Please
  25. consult the `ssl` application's manual for more details.
  26. TCP connections do not allow a certificate and this function
  27. will therefore always return `undefined`.
  28. The certificate can also be obtained using pattern matching:
  29. [source,erlang]
  30. ----
  31. #{cert := Cert} = Req.
  32. ----
  33. == Arguments
  34. Req::
  35. The Req object.
  36. == Return value
  37. The client TLS certificate.
  38. == Changelog
  39. * *2.1*: Function introduced.
  40. == Examples
  41. .Get the client TLS certificate.
  42. [source,erlang]
  43. ----
  44. Cert = cowboy_req:cert(Req).
  45. ----
  46. == See also
  47. link:man:cowboy_req(3)[cowboy_req(3)],
  48. link:man:cowboy_req:peer(3)[cowboy_req:peer(3)],
  49. link:man:cowboy_req:sock(3)[cowboy_req:sock(3)]