diff options
author | Clombrong <cromblong@egregore.fun> | 2025-06-28 10:38:25 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-06-28 16:44:54 +0200 |
commit | be107f70dd54e8977f7f0fadc5578d248dc3cfea (patch) | |
tree | 064805d691719499156d10c7347e147002b1b5ed /lib/starttls.ml | |
parent | be1094936794bd99baf8c49a02e91566b892ec5a (diff) |
feat(starttls): add upgrade function
Diffstat (limited to 'lib/starttls.ml')
-rw-r--r-- | lib/starttls.ml | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/starttls.ml b/lib/starttls.ml index e69de29..7391fd6 100644 --- a/lib/starttls.ml +++ b/lib/starttls.ml @@ -0,0 +1,28 @@ +open Lwt.Syntax +open Xml + +exception TLSError +exception STARTTLSFailure + +let stanza = + Markup.of_list + [`Start_element + ((Xmlns.tls, "starttls"), + [(("http://www.w3.org/2000/xmlns/", "xmlns"), Xmlns.tls)]); + `End_element] + +let parse_reply response = + match response with + | {namespace=ns; local_name="proceed"; + attributes=[]; children=[]} when ns = Xmlns.tls -> `Proceed + | {namespace=ns; local_name="failure"; + attributes=[]; children=[]} when ns = Xmlns.tls -> `Failure + | _ -> `Error + +let upgrade (portal : Portal.t) : unit Lwt.t = + portal.push (Some stanza); + let* response = Wire.get portal.stream + in match parse_reply response with + | `Failure | `Error -> Lwt.fail STARTTLSFailure + | `Proceed -> Portal.starttls portal + |