<div dir="ltr">Hi,<div><br></div><div>I'm working on mutual authentication feature between MQTT client and broker, and I follow these tutorials: <a href="https://www.nginx.com/blog/nginx-plus-iot-load-balancing-mqtt" target="_blank">https://www.nginx.com/blog/nginx-plus-iot-load-balancing-mqtt</a> and <a href="https://www.nginx.com/blog/nginx-plus-iot-security-encrypt-authenticate-mqtt/#mqtt-client-certs" target="_blank">https://www.nginx.com/blog/nginx-plus-iot-security-encrypt-authenticate-mqtt/#mqtt-client-certs</a>. However, the code examples are extremely out of date and this JavaScript code does not work with recent versions of njs, so I've tried to write my own code following your example from here:<a href="https://gist.github.com/nginx-gists/0e93fe7813ec131fed8329d10ead70ea#file-mqtt-js" target="_blank"> https://gist.github.com/nginx-gists/0e93fe7813ec131fed8329d10ead70ea#file-mqtt-js</a>. However, I can't figure out what is the possible replacement for the following snippet:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">if</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"> ( </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">s</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">.</span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">buffer</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">.</span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">toString</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">().</span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">length</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"> </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">==</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"> </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">0</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"> ) { </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box;color:rgb(106,115,125);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box">//</span> Initial calls may<br></span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box;color:rgb(106,115,125);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">    s</span><span style="color:rgb(36,41,46)">.</span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">log</span><span style="color:rgb(36,41,46)">(</span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-pds" style="box-sizing:border-box">"</span>No buffer yet<span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-pds" style="box-sizing:border-box">"</span></span><span style="color:rgb(36,41,46)">);              </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box"><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box">//</span> contain no data, so<br></span></span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box;color:rgb(106,115,125);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box"><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">    return</span><span style="color:rgb(36,41,46)"> </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">s</span><span style="color:rgb(36,41,46)">.</span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">AGAIN</span><span style="color:rgb(36,41,46)">;                      </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box"><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box">//</span> ask that we get called again</span></span></span> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">} </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">else</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"> </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">if</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"> ( client_messages </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">==</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"> </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">1</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"> ) {     </span><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box;color:rgb(106,115,125);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap"><span class="gmail-m_-3019429482593808288gmail-m_5002134885204160122gmail-m_6997121796465494061gmail-pl-c" style="box-sizing:border-box">//</span> CONNECT is first packet from the client</span>... </blockquote><div>From version 0.2.4, s.(OK, ABORT, AGAIN, DECLINED, ERROR) are replace with s.(allow(), done(), decline()). In my case, the initial call does not contain any data. In logs, I can see that I always read only 4 bytes of data received from the client. So when I send, let say, 50 bytes of data, an event is triggered, but data passed to `upload` callback is empty. Is this a bug? Can I somehow trigger this callback again?<br></div><div><br></div><div>Best regards,</div><div>Dušan Borovčanin</div></div>