<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
How do I actually select the protocol for ALPN?  I have this:</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
SSL_client_hello_cb_fn set_alpn_cb(SSL* ssl, int* alert, const unsigned char* arg)
<div>{</div>
<div>      constexpr int ext_type{ TLSEXT_TYPE_application_layer_protocol_negotiation };</div>
<div>      int extensions[1]{ ext_type };</div>
<div>      std::size_t extensions_len{ 1u };</div>
<div>      int extensions_present{ SSL_client_hello_get1_extensions_present(ssl, </div>
<div>            reinterpret_cast<int**>(extensions), &extensions_len) };</div>
<div>      const unsigned char** alpn_str;</div>
<div>      std::size_t alpn_str_len{};</div>
<div><br>
</div>
<div>      // 1 means success</div>
<div>      if (extensions_present == 1)</div>
<div>      {</div>
<div>            SSL_client_hello_get0_ext(ssl, ext_type, alpn_str, &alpn_str_len);</div>
<div>            std::cout << "alpn_str: " << alpn_str << std::endl;</div>
<div>            return reinterpret_cast<SSL_client_hello_cb_fn>(SSL_CLIENT_HELLO_SUCCESS);</div>
<div>      }</div>
<div>      else if (extensions_present == 0)</div>
<div>      {</div>
<div>            return reinterpret_cast<SSL_client_hello_cb_fn>(SSL_CLIENT_HELLO_ERROR);</div>
<div>      }</div>
<div>      return reinterpret_cast<SSL_client_hello_cb_fn>(SSL_CLIENT_HELLO_RETRY);</div>
}<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Would I be correct to assume that I have to set <code>arg</code>​ to point to "h2" in wire-format?  Hopefully someone good at parsing the ClientHello message and who also knows C++ would answer too.  Thanks.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
I'm thinking it may actually be easier for me to just use SSL_CTX_set_alpn_select_cb since it has those out and in parameters.  I do also want to know what I should initialize the SSL* pointer to point to, though, in either case.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Osman</div>
</body>
</html>