Is the Nx Cloud up? Visit our Status Page for the current health and performance of the Nx Cloud.

Status Page

Authentication from network optics plugin

Answered

Comments

7 comments

  • Ali Ergin Hacimahmutoglu

    The right format, to add the header,  should be: 

    digestResponse = "Digest username=\"" + _userName + "\"" + ", realm=\"" + _realm + "\"" + ", nonce=\"" + _nonce + "\"" + ", uri=\"" + urlAfterIp +"\"" + ", algorithm=MD5" + ", response=" + "\"" + ha3 +"\"" + ", qop=" + _qop + ", nc=" + _ncString + ", cnonce=\"" +_cnonce + "\"";

    networkRequest.setRawHeader(QByteArray("Authorization"), digestResponse.c_str());

    but it is not working.  

     

    0
  • Anton Babinov
    • Network Optix team

    Hi Ali,

    In order to communicate from network optics to a device, I need to use digest authentication.

    Could you please provide more details about your third party system which you need to communicate with? Understanding your use case scenario might allow me to provide you with more simple solution to your problem. 

    but it is not working.  

    Could you please log and show me full reply from your server(one where server provides you with nonce) and your request containing proper Authorization header.

     

     

    0
  • Ali Ergin Hacimahmutoglu

    Hi Anton, 

    We are working with Bosch Cameras and  these devices accepts digest authentication by default. In order to make a connection from Plugin to Bosch devices, digest authentication with C++ has to be written in the plugin. Network optics is using Qt library by default, therefore It is better to write, digest authentication  in c++ with Qt library.      

    Digest authentication is a two way communication by itself. First client asks a token > Server sends  the token > And client is connects to device with the combination of token + username + password. 

    I couldn't find a clear sample of digest authentication in qt. Then I copy from c# language,  how digest authentication can be done in detailed way. And I have written it in detailed way in c++(Qt). Below the link shows how digest authentication in c#.  

      https://stackoverflow.com/questions/3172510/how-can-i-do-digest-authentication-with-httpwebrequest

    As I mentioned in my previous post, what I couldn't manage to authorize although I am sending the right string data.  I am comparing the string header data  with c#  and c++. It is the same string. It is working in c# but not working in c++.  Below is the code, I am using, is not working.   

     

    digestResponse = "Digest username=\"" + _userName + "\"" + ", realm=\"" + _realm + "\"" + ", nonce=\"" + _nonce + "\""
    + ", uri=\"" + urlAfterIp +"\"" + ", algorithm=MD5" + ", response=" + "\"" + ha3 +"\"" + ", qop=" + _qop + ", nc="
    + _ncString + ", cnonce=\"" +_cnonce + "\"";

    QEventLoop loop;

    QNetworkAccessManager* manager = new QNetworkAccessManager();
    QNetworkRequest networkRequest;
    networkRequest.setUrl(QUrl("http://172.16.101.68/reset"));

    networkRequest.setRawHeader("Authorization", digestResponse.c_str()); //.is where I send header data****

    QLabel *label = new QLabel();
    QNetworkReply *reply = manager->get(networkRequest);

    QObject::connect(reply, SIGNAL(readyRead()),
    label, SLOT(slotReadyRead()));
    QObject::connect(reply, SIGNAL(finished()),
    label, SLOT(slotOnRequestCompleted()));
    QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
    label, SLOT(slotOnRequestError(QNetworkReply::NetworkError)));
    QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
    label, SLOT(slotSslErrors(QList<QSslError>)));

    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));loop.exec();

    QByteArray dataReceived = reply->readAll();
    QString dataReply(dataReceived)

     

    I receive a message  unauthorize below 

    "<HTML><HEAD><TITLE>401 Authorization Required</TITLE></HEAD><BODY><H1>Authorization Required</H1>this server could not verify that you are authorized to access the document you requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesnt understand how to supply the credentials required.</BODY></HTML>"

    Thanks for help

     

     

     

      

    0
  • Anton Babinov
    • Network Optix team

    We are working with Bosch Cameras and  these devices accepts digest authentication by default. In order to make a connection from Plugin to Bosch devices, Digest authentication with C++ has to be written in the plugin. Network optics is using Qt library by default, therefore It is better to write, digest authentication  in c++ with Qt library.      

    Just out of curiosity, what kind of info you wish to pull from Bosch Camera? 

    As I mentioned in my previous post, what I couldn't manage to authorize although I am sending the right string data.  I am comparing the string header data  with c#  and c++. It is the same string. It is working in c# but not working in c++.   Below is the code, I am using, is not working.   

    Sorry, but we are not using QT for generating auth headers, so I'm not able to tell you what's wrong just by viewing at your code. I'd recommend to collect WireShark capture, it would show what exactly is wrong with the Authorization header in your request and will point us at the problem. This article might help you to setup Wireshark capture.

    By the way, have you tried using authenticationRequired signal to set login/pass credentials?

    https://doc.qt.io/qt-5/qnetworkaccessmanager.html#authenticationRequired

    https://doc.qt.io/archives/qt-5.5/qtwebkitexamples-webkitwidgets-browser-networkaccessmanager-cpp.html

     

     

     

    0
  • Ali Ergin Hacimahmutoglu

      For my case, I am thinking the worst scenario. If I give up with Qt  which library, would you advise me to use. And also which library are you using?  I had tried to integrate Poco and Curl but I had difficulties to add  these libraries to cmake project.(win 64bit) 

    Thanks in advance,   

    0
  • Anton Babinov
    • Network Optix team

    I don't think switching libraries would be helpful. Please collect and show me WireShark capture of communication between your plugin and your camera. It will show which lines in your code causes the issue.

     

    Could you please tell me how you plan to interact with Bosh camera? Latest patch of mediaserver has build-in analytic plugin for Bosch cameras which can receive some metadata from camera. Just want to be sure that you're not developing something that already exists in the product.

    0
  • Ali Ergin Hacimahmutoglu

    Hi Anton, 

    Thanks for help,

    I  found my failure. Wireshark was helpful for me. There is nothing wrong about Qt library and the codes above.  In my previous codes, I got a bug  in refining received nonce value. That was causing error.  Now I achieve the connection. It works properly. 

    Thanks   

    0

Please sign in to leave a comment.