Picture of Wim 4127
Registered 6 years 252 days
Wim 4127 Friday, 3 December 2021, 08:35 AM
Devices app returns error when app backend tries to login (blocking)
Hi, we are creating our own mechanism of the Servics API to be able to work with all services (e.g. the Files api) from the back-end, since at this time it only allows to work with the devices api. However, when we login with our app implementation in the devices app for example, the devices app returns an error... unfortunately, the devices app logging doesn't tell us why it returns an error (all diagnostic levels are enabled). See the below output of the devices app from the app platform, the error line is marked in red. Attached to this ticket you can find the log output of our application, which I think does all things right: it gets a challenge from the devices app, uses the services api to get a service login from the pbx and then performs an applogin on the devices app. I've also implemented this with the ServicesApi implementation from innovaphone (and then it suddenly works), and, the message flow is 100% identical, even the message content is exactly the same except for the authentication related attributes such as digest and so on. Why do I get this error? How can I figure out what I'm doing wrong and which values in my message cause this error?

12-03 07:19:07.038 devices@xqting.be WebserverPlugin(0x1b61a8,0x1b60d0)::SocketRecvResult: Received message WSM_WEBSOCKET_LISTEN_RESULT (data size: 52)
12-03 07:19:07.038 devices@xqting.be IWebsocket(connection id: 9915)::IWebsocket(): resourceName: '/', reqPathForRequest: ''
12-03 07:19:07.038 devices@xqting.be WebserverPlugin(001b60d0,001b5cc8)::WebserverPluginWebsocketListenResult(): path = /, registeredPathForRequest = , host = 10.0.0.241
12-03 07:19:07.038 devices@xqting.be AppWebsocket(001feff8)::AppWebsocket
12-03 07:19:07.038 devices@xqting.be WebserverPlugin(001b60d0,001b5cc8)::WebsocketAccept(): user = 0x001feff8
12-03 07:19:07.038 devices@xqting.be WebserverPlugin(connection id: 9915)::WebsocketAccept() request accepted
12-03 07:19:07.038 devices@xqting.be WebserverMessage(connection id: 88)::WebsocketSend: Sending Websocket message WS_WEBSOCKET_CONNECT_ACCEPT (fragmented: false, text: false, sdata ize: 0)
12-03 07:19:07.039 devices@xqting.be IWebsocket(connection id: 9915)::SocketRecvResult(): Received Websocket message WS_WEBSOCKET_CONNECT_COMPLETE (fragmented: false, text: false, data size: 0)
12-03 07:19:07.039 devices@xqting.be WebserverWebsocketHandler(001cfae8,001feff8,9915)::Recv buffer:0x00000000 len:0
12-03 07:19:07.039 devices@xqting.be WebserverMessage(connection id: 9915)::WebsocketSend: Sending Websocket message WS_WEBSOCKET_RECV (fragmented: false, text: false, sdata ize: 0)
12-03 07:19:07.045 devices@xqting.be IWebsocket(connection id: 9915)::RecvBuffer(): size: 21
12-03 07:19:07.045 devices@xqting.be IWebsocket(connection id: 9915)::SocketRecvResult(): Received Websocket message WS_WEBSOCKET_RECV_RESULT (fragmented: false, text: true, data size: 21)
12-03 07:19:07.045 devices@xqting.be WebserverWebsocketHandler(001cfae8,001feff8,9915)::Send buffer:0x7eaf6790 len:58 text:TRUE
12-03 07:19:07.045 devices@xqting.be WebserverMessage(connection id: 9915)::WebsocketSend: Sending Websocket message WS_WEBSOCKET_SEND (fragmented: false, text: true, sdata ize: 58)
12-03 07:19:07.045 devices@xqting.be AppWebsocket(001feff8)::AppWebsocketRecv
12-03 07:19:07.045 devices@xqting.be WebserverWebsocketHandler(001cfae8,001feff8,9915)::Recv buffer:0x00000000 len:0
12-03 07:19:07.045 devices@xqting.be WebserverMessage(connection id: 9915)::WebsocketSend: Sending Websocket message WS_WEBSOCKET_RECV (fragmented: false, text: false, sdata ize: 0)
12-03 07:19:07.046 devices@xqting.be IWebsocket(connection id: 9915)::SocketRecvResult(): Received Websocket message WS_WEBSOCKET_SEND_RESULT (fragmented: false, text: false, data size: 0)
12-03 07:19:07.046 devices@xqting.be AppWebsocket(001feff8)::WebsocketSendResult() connected=0 sendCount=0
12-03 07:19:07.107 devices@xqting.be IWebsocket(connection id: 9915)::RecvBuffer(): size: 455
12-03 07:19:07.108 devices@xqting.be IWebsocket(connection id: 9915)::SocketRecvResult(): Received Websocket message WS_WEBSOCKET_RECV_RESULT (fragmented: false, text: true, data size: 455)
12-03 07:19:07.108 devices@xqting.be WebserverWebsocketHandler(001cfae8,001feff8,9915)::Send buffer:0x7eaf6790 len:51 text:TRUE
12-03 07:19:07.108 devices@xqting.be WebserverMessage(connection id: 9915)::WebsocketSend: Sending Websocket message WS_WEBSOCKET_SEND (fragmented: false, text: true, sdata ize: 51)
12-03 07:19:07.108 devices@xqting.be AppWebsocket(001feff8)::Error
12-03 07:19:07.108 devices@xqting.be WebserverWebsocketHandler(001cfae8,001feff8,9915)::Close
12-03 07:19:07.109 devices@xqting.be IWebsocket(connection id: 9915)::SocketRecvResult(): Received Websocket message WS_WEBSOCKET_SEND_RESULT (fragmented: false, text: false, data size: 0)
12-03 07:19:07.109 devices@xqting.be AppWebsocket(001feff8)::WebsocketSendResult() connected=0 sendCount=0
12-03 07:19:07.109 devices@xqting.be ExtendedHeader::Encode(): Extended header encoded (cid: 9915, h-len: 7, b-size: 11)
12-03 07:19:07.109 devices@xqting.be WebserverMessage(connection id: 9915)::WebsocketSend: Sending Websocket message WS_WEBSOCKET_CLOSE (fragmented: false, text: false, sdata ize: 11)
12-03 07:19:07.120 devices@xqting.be IWebsocket(connection id: 9915)::SocketRecvResult(): Received Websocket message WS_WEBSOCKET_CLOSE_COMPLETE (fragmented: false, text: false, data size: 2)
12-03 07:19:07.120 devices@xqting.be IWebsocket(connection id: 9915)::~IWebsocket()
12-03 07:19:07.120 devices@xqting.be AppWebsocket(001feff8)::AppWebsocketClosed
12-03 07:19:07.120 devices@xqting.be AppWebsocket(001feff8)::~AppWebsocket
12-03 07:19:07.121 devices@xqting.be WebserverPlugin(0x1b61a8,0x1b60d0)::SocketRecvResult: Received message WSM_SHUTDOWN_COMPLETE (data size: 0)
12-03 07:19:07.121 devices@xqting.be WARNING: IWebserverPlugin received unexpected message (WSM_SHUTDOWN_COMPLETE) - ignoring
Applogging.txt
Picture of Wim 4127
Registered 6 years 252 days
Wim 4127 Saturday, 4 December 2021, 05:36 PM
1 of 1 users consider this post helpful
Re: Devices app returns error when app backend tries to login (blocking)
Hi, some further research and looking for a solution gave me a view on what the problem is: the "info" element must be serialized in the same way all the time because the digest is calculated based on that string.

However, in JSON, the order of elements is not defined, and depending on the JSON parser library that is used, the serialization from JSON message to a string might result in a different order of the elements in the string, which is correct according to JSON standard, but, results in a different digest being generated, and, therefore giving an login error.

With the JSON library we use it is easy to just serialize the whole info element, but, it results in a different order of the messages... which is a pitty.

So I tried to use the innovaphone JSON library with the json_io class. Question is now: how do serialize the info element (and all it's children) to a string. Only the info element, so I can returned it to the WebAuthenticator who will send the AppLogin (and hope this is done the same way as the server side).
If I try info = msg.get_string(base, "info"); this generates an error, since info is an object. If I uses word info = msg.get_object(base, "info") I get a reference to the info element, but how can I serialize this element then? Please advise on how to do this. Or just provide the code from your ServicesApi/IAppWebsocketAuthenticator implementation because there you must do the exact same thing.

This is currently blocking our implementation of our app, so please advise quickly
Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 121 days
Daniel Deterding (innovaphone) Monday, 6 December 2021, 07:23 AM
1 of 1 users consider this post helpful
Re: Devices app returns error when app backend tries to login (blocking)
Hi Wim,

try:
word infoBase = msg.get_object(base, "info");
char buffer[2048]; // or how large info might get ...
char * tmp = buffer;
msg.write(infoBase, tmp, JSON_ID_NONE);
word lenWritten = tmp - buffer;

Greetings,
Daniel
Picture of Wim 4127
Registered 6 years 252 days
Wim 4127 Monday, 6 December 2021, 09:22 AM
Re: Devices app returns error when app backend tries to login (blocking)
Ok, that seems to work and preserve the order of the elements.Thx for the quick response

Kr

Wim
← You can define your color theme preference here