Index: terepaima-0.4.16/sources/mainwindow.cpp
===================================================================
--- terepaima-0.4.16/sources/mainwindow.cpp	(revision 9840ac5809a61dfb917e35751e97821325105b7c)
+++ terepaima-0.4.16/sources/mainwindow.cpp	(revision 63dadfc95c45ecbd4c1d2a21904654fa1351e6d3)
@@ -50,4 +50,7 @@
 #include <QVBoxLayout>
 #include <QWidgetAction>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QUrlQuery>
 
 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
@@ -115,4 +118,7 @@
 #include <stdio.h>
 #include <QByteArray>
+#include <QUrl>
+#include <QNetworkReply>
+
 
 #include "include/pkcs11.h"
@@ -3855,4 +3861,8 @@
 void MainWindow::on_verify_signature() {
 
+    qDebug("Entro en callMurachi()");
+    callMurachi();
+    qDebug("Salio en callMurachi()");
+
     qDebug("Entro a on_verify_signature()");
     verify_signature();
@@ -3959,6 +3969,76 @@
 }
 
+void MainWindow::callMurachi() {
+
+
+   // QString version = executeRest("https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/version","admin","admin");
+    QString fileid = "c73efabb-d771-4328-be4f-36b11c4add57";
+
+   QUrlQuery postData;
+    //postData.addQueryItem("fileId", fileid);
+    //postData.addQueryItem("certificate", certInHex);
+    //postData.addQueryItem("reason", "Certificado");
+    //postData.addQueryItem("location", "CENDITEL");
+    //postData.addQueryItem("contact", "582746574336");
+    //postData.addQueryItem("signatureVisible","true" );
+    //postData.addQueryItem("signaturePage","1" );
+    //postData.addQueryItem("xPos","10" );
+    //postData.addQueryItem("yPos","10" );
+    //postData.addQueryItem("lastSignature","false" );
+
+    QString parameters = QString("{\"fileId\":\"%1\",\"certificate\":\"%2\",\"reason\":\"Certificado\", \"location\":\"CENDITEL\", "
+                                 "\"contact\":\"582746574336\",\"signatureVisible\":\"true\","
+                                  "\"signaturePage\":\"1\",\"xPos\":\"10\",\"yPos\":\"10\",\"lastSignature\":\"false\" }")
+            .arg(fileid).arg(certInHex);
+
+    //postData.addQueryItem("", parameters);
+
+/*    QByteArray postData;
+    postData.append(QString("fileId=%1&").arg(fileid));
+    postData.append(QString("certificate=%1&").arg(certInHex));
+    postData.append(QString("reason=%1&").arg("Certificado"));
+    postData.append(QString("location=%1&").arg("CENDITEL"));
+    postData.append(QString("contact=%1&").arg("582746574336"));
+    postData.append(QString("signatureVisible=%1&").arg("true"));
+    postData.append(QString("signaturePage=%1&").arg("1"));
+    postData.append(QString("xPos=%1&").arg("10"));
+    postData.append(QString("yPos=%1&").arg("10"));
+    postData.append(QString("lastSignature=%1").arg("false"));
+
+*/
+
+    //parameters = "{}";
+
+    qDebug("Parameters: |%s|", qPrintable(parameters));
+
+   // qDebug("Verifying...... SIGNED...fileid |%s|", qPrintable(fileid));
+    //qDebug("certInHex: |%s|", qPrintable(certInHex));
+
+//    QString newverify  = privateExecuteRest("https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs",
+//                                         "admin","admin", "post",postData);
+
+ //   QString newverify  = privateExecuteRest("https://192.168.12.154:8443/Murachi/0.1/archivos/pdfs",
+//                                         "admin","admin", "post",postData);
+
+    //qDebug("Verifying...... SIGNED...hash |%s|", qPrintable(newverify));
+
+
+    //QUrlQuery postData1;
+
+    QString newverify =  executeRest("https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs","admin","admin"
+                                     ,parameters);
+
+    //QString verify  = privateExecuteRest("https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/aee1a794-5fc7-4008-ac6d-de2e79583074.pdf",
+    //                                     "admin","admin",method="post",postData);
+
+    qDebug(".....................*Verify: newverify %s", qPrintable(newverify));
+
+ //   qDebug("Version: %s", qPrintable(version));
+
+}
+
 void MainWindow::on_signature() {
     qDebug("** on_signature **");
+
     on_windowCertificate();
 }
@@ -4039,4 +4119,201 @@
 }
 
+
+
+void MainWindow::handleNetworkData(QNetworkReply *networkReply)
+{
+    qDebug("MainWindow::handleNetworkData....*1");
+
+    QUrl url = networkReply->url();
+
+    qDebug("MainWindow::handleNetworkData....*2");
+
+    if (!networkReply->error()) {
+
+        QString response(networkReply->readAll());
+        _currentrest = response;
+        qDebug("CALLING_REST_SERVICE....response: |%s|",qPrintable(response));
+
+
+     } else {
+     qDebug("handleNetworkData  OCURRED ERROR network error: |%s|",qPrintable(networkReply->errorString()));
+    }
+
+
+    networkReply->deleteLater();
+}
+
+
+void MainWindow::slotError(QNetworkReply::NetworkError e) {
+
+    QString currenterror = QString("Error ocurred: |%1|").arg(e);
+
+    qDebug("Error network.............1");
+    //SYD << currenterror;
+
+    _currentrest = currenterror;
+
+}
+
+
+
+QString MainWindow::privateExecuteRest(const QString &url, const QString &name,
+                                       const QString &pass,
+                                       QString method, const QUrlQuery& postData )
+{
+    _currentrest = "";
+
+    qDebug("Private Executing Rest...1");
+
+    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
+
+  //  int nargs;
+  //  char** argv =NULL;
+  //  QCoreApplication myapp(nargs,argv);
+
+
+
+        QNetworkRequest request;
+        QSslConfiguration conf = request.sslConfiguration();
+        conf.setPeerVerifyMode(QSslSocket::VerifyNone);
+     //   conf.setProtocol(QSsl::TlsV1SslV3);
+        request.setSslConfiguration(conf);
+
+
+        qDebug("Executing Rest...4");
+
+     QUrl myurl(url);
+
+     //   myurl.setUserName(name);
+     //   myurl.setPassword(pass);
+        request.setUrl(myurl);
+        qDebug("Private Executing Rest...URL CALLING:|%s|", qPrintable(url));
+
+      qDebug("Private Executing Rest...4");
+
+      connect(manager, SIGNAL(finished(QNetworkReply*)),
+              this, SLOT(handleNetworkData(QNetworkReply*)));
+
+
+      qDebug("Private Executing Rest...5");
+      QNetworkReply *reply = NULL;
+      if (method == "post") {
+          qDebug("Private Executing Rest...**6");
+          qDebug("CALLING_REST_SERVICE... method IS POST");
+
+           request.setHeader(QNetworkRequest::ContentTypeHeader,
+              "application/json");
+           QString headerData = QString("Basic YWRtaW46YWRtaW4=");
+           request.setRawHeader("Authorization", headerData.toLocal8Bit());
+
+           //QNetworkReply *reply = manager->post(request, postData.encodedQuery());
+           qDebug("Private Executing Rest...7");
+
+           reply = manager->post(request,  postData.toString(QUrl::FullyEncoded).toUtf8());
+          // reply = manager->post(request,  postData);
+
+
+           connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
+                     this, SLOT(slotError(QNetworkReply::NetworkError)));
+
+           qDebug("Private Executing Rest...8");
+
+
+      } else {
+            qDebug("CALLING_REST_SERVICE... method IS GET");
+            reply = manager->get(request);
+
+      }
+
+
+      qDebug("Private Executing Rest...9");
+      QEventLoop loop;
+      connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
+      loop.exec();
+
+
+      qDebug("Private Executing Rest...10");
+      QString result = _currentrest;
+      //QString result = "....test1";
+      return result;
+
+}
+
+
+
+QString MainWindow::executeRest(const QString &url, const QString &name, const QString &pass, const QString& postData) {
+    _currentrest = "";
+
+    qDebug("Executing Executing...Rest...1");
+
+    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
+
+    qDebug("Executing Executing...Rest...2");
+
+    //int nargs;
+    //char** argv =NULL;
+    //QCoreApplication myapp(nargs,argv);
+
+    qDebug("Executing Rest...3");
+
+      QNetworkRequest request;
+    QSslConfiguration conf = request.sslConfiguration();
+    conf.setPeerVerifyMode(QSslSocket::VerifyNone);
+    //conf.setPeerVerifyMode(QSslSocket::AutoVerifyPeer);
+    //conf.setProtocol(QSsl::AnyProtocol);
+    request.setSslConfiguration(conf);
+
+    qDebug("Executing Rest...4");
+
+       QUrl myurl(url);
+
+      //myurl.setUserName(name);
+      //myurl.setPassword(pass);
+      request.setUrl(myurl);
+
+      qDebug("Executing Rest...5");
+
+      connect(manager, SIGNAL(finished(QNetworkReply*)),
+              this, SLOT(handleNetworkData(QNetworkReply*)));
+
+
+      qDebug("Executing Rest...6");
+
+      request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
+      //QNetworkReply *reply = manager->get(QNetworkRequest(QUrl("http://127.0.0.1:8000")));
+      request.setHeader(QNetworkRequest::ContentTypeHeader,
+       //  "application/x-www-form-urlencoded");
+      "application/json");
+
+      //request.setAttribute(QNetworkRequest::ConnectionEncryptedAttribute,QVariant(true));
+
+      QString headerData = QString("Basic YWRtaW46YWRtaW4=");
+      request.setRawHeader("Authorization", headerData.toUtf8());
+
+      //QNetworkReply *reply = manager->post(request, postData.encodedQuery());
+      //QNetworkReply *reply = manager->get(request);
+
+      QNetworkReply *reply = manager->post(request, postData.toUtf8());
+      //QNetworkReply *reply = manager->post(request,postData.toString(QUrl::FullyEncoded).toUtf8());
+      qDebug("Executing Rest..............*7");
+
+      connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
+                this, SLOT(slotError(QNetworkReply::NetworkError)));
+
+      QEventLoop loop;
+      connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
+      loop.exec();
+
+      connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
+                this, SLOT(slotError(QNetworkReply::NetworkError)));
+
+      qDebug("Executing Rest...8");
+
+      QString result = _currentrest;
+      //QString result = "....test1";
+      return result;
+
+}
+
 void MainWindow::on_windowCertificate() {
 
@@ -4058,7 +4335,23 @@
     m_nct = new CryptoToken();
 
+
+
+
     //Sección para verificar si hay dispositivo cryptografico conectado
     try {
         certificateInformationListN = m_nct->getDeviceCertificates(); //obtener los certificados disponible en el dispositivo
+
+        qDebug("******************* Certification Info **********************");
+        for(int i= 0; i < certificateInformationListN.size(); i++) {
+            for(int j= 0; j < certificateInformationListN[i].size(); j++) {
+                QString data = certificateInformationListN[i].at(j);
+                if (j == 3)  {
+                    certInHex = data;
+                }
+                qDebug(",,,,addngCERTIFICATION INFO %d %d: |%s|",i,j, qPrintable(data));
+
+            }
+            qDebug(".................");
+        }
     }catch(std::runtime_error e){
         ok = "falso";
@@ -4070,4 +4363,6 @@
         msgBox.exec();
      }
+
+
     
     //Si hay dispositivo conectado creo la ventana para mostrar los certificados si hay disponibles
