Fetching SelfEndorseCertificate works
diff --git a/src/addcontactpanel.cpp b/src/addcontactpanel.cpp
index a3dabf7..9d332a7 100644
--- a/src/addcontactpanel.cpp
+++ b/src/addcontactpanel.cpp
@@ -11,28 +11,41 @@
#include "addcontactpanel.h"
#include "ui_addcontactpanel.h"
+#ifndef Q_MOC_RUN
+#include "logging.h"
+#endif
+
using namespace ndn;
using namespace std;
+INIT_LOGGER("AddContactPanel");
+
AddContactPanel::AddContactPanel(Ptr<ContactManager> contactManager,
QWidget *parent)
: QDialog(parent)
, ui(new Ui::AddContactPanel)
, m_contactManager(contactManager)
+ , m_warningDialog(new WarningDialog())
{
ui->setupUi(this);
+
+ qRegisterMetaType<ndn::Name>("NdnName");
+ qRegisterMetaType<EndorseCertificate>("EndorseCertificate");
connect(ui->cancelButton, SIGNAL(clicked()),
this, SLOT(onCancelClicked()));
connect(ui->searchButton, SIGNAL(clicked()),
this, SLOT(onSearchClicked()));
- connect(&*m_contactManager, SIGNAL(contactFetched(ndn::Ptr<EndorseCertificate>)),
- this, SLOT(selfEndorseCertificateFetched(ndn::Ptr<EndorseCertificate>)));
+ connect(&*m_contactManager, SIGNAL(contactFetched(const EndorseCertificate&>)),
+ this, SLOT(selfEndorseCertificateFetched(const EndorseCertificate&>)));
+ connect(&*m_contactManager, SIGNAL(contactFetchFailed(const ndn::Name&)),
+ this, SLOT(selfEndorseCertificateFetchFailed(const ndn::Name&)));
}
AddContactPanel::~AddContactPanel()
{
delete ui;
+ delete m_warningDialog;
}
void
@@ -44,6 +57,8 @@
{
QString inputIdentity = ui->contactInput->text();
m_searchIdentity = Name(inputIdentity.toUtf8().constData());
+
+ m_contactManager->fetchSelfEndorseCertificate(m_searchIdentity);
}
void
@@ -52,8 +67,16 @@
}
void
-AddContactPanel::selfEndorseCertificateFetched(Ptr<EndorseCertificate> endorseCertificate)
+AddContactPanel::selfEndorseCertificateFetched(const EndorseCertificate& endorseCertificate)
{
+ _LOG_DEBUG("CALLED");
+}
+
+void
+AddContactPanel::selfEndorseCertificateFetchFailed(const Name& identity)
+{
+ m_warningDialog->setMsg("Cannot fetch contact profile");
+ m_warningDialog->show();
}
#if WAF
diff --git a/src/addcontactpanel.h b/src/addcontactpanel.h
index fb547a1..f6776c0 100644
--- a/src/addcontactpanel.h
+++ b/src/addcontactpanel.h
@@ -12,6 +12,8 @@
#define ADDCONTACTPANEL_H
#include <QDialog>
+#include <QMetaType>
+#include "warningdialog.h"
#ifndef Q_MOC_RUN
#include "endorse-certificate.h"
@@ -22,6 +24,10 @@
class AddContactPanel;
}
+Q_DECLARE_METATYPE(ndn::Name)
+
+Q_DECLARE_METATYPE(EndorseCertificate)
+
class AddContactPanel : public QDialog
{
Q_OBJECT
@@ -43,12 +49,16 @@
onAddClicked();
void
- selfEndorseCertificateFetched(ndn::Ptr<EndorseCertificate> endorseCertificate);
+ selfEndorseCertificateFetched(const EndorseCertificate& endorseCertificate);
+
+ void
+ selfEndorseCertificateFetchFailed(const ndn::Name& identity);
private:
Ui::AddContactPanel *ui;
ndn::Name m_searchIdentity;
ndn::Ptr<ContactManager> m_contactManager;
+ WarningDialog* m_warningDialog;
};
#endif // ADDCONTACTPANEL_H
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index 7b07824..01168a0 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -193,19 +193,22 @@
void
ContactManager::onDnsSelfEndorseCertificateVerified(Ptr<Data> data, const Name& identity)
{
- const Blob& dataContentBlob = data->content();
-
- boost::iostreams::stream
- <boost::iostreams::array_source> is (dataContentBlob.buf(), dataContentBlob.size());
+ Ptr<Blob> dataContentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size()));
- Ptr<Data> plainData = Data::decodeFromWire(is);
+ Ptr<Data> plainData = Data::decodeFromWire(dataContentBlob);
+
Ptr<EndorseCertificate> selfEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*plainData));
-
+
const security::Publickey& ksk = selfEndorseCertificate->getPublicKeyInfo();
+
if(security::PolicyManager::verifySignature(*plainData, ksk))
- emit contactFetched (selfEndorseCertificate);
+ {
+ emit contactFetched (*selfEndorseCertificate);
+ }
else
- emit contactFetchFailed (identity);
+ {
+ emit contactFetchFailed (identity);
+ }
}
void
@@ -247,9 +250,15 @@
Name dnsName = identity;
dnsName.append("DNS").append("PROFILE").append(oss.str());
-
+
data->setName(dnsName);
Ptr<Blob> blob = selfEndorseCertificate->encodeToWire();
+
+ // string encoded;
+ // CryptoPP::StringSource ss(reinterpret_cast<const unsigned char *>(blob->buf()), blob->size(), true,
+ // new CryptoPP::Base64Encoder(new CryptoPP::StringSink(encoded), false));
+
+ // Content content(encoded.c_str(), encoded.size());
Content content(blob->buf(), blob->size());
data->setContent(content);
diff --git a/src/contact-manager.h b/src/contact-manager.h
index 3cc816d..42fd847 100644
--- a/src/contact-manager.h
+++ b/src/contact-manager.h
@@ -75,7 +75,7 @@
signals:
void
- contactFetched(ndn::Ptr<EndorseCertificate> selfEndorseCertificate);
+ contactFetched(const EndorseCertificate& selfEndorseCertificate);
void
contactFetchFailed(const ndn::Name& identity);
diff --git a/src/endorse-certificate.h b/src/endorse-certificate.h
index c4d160d..3b992c4 100644
--- a/src/endorse-certificate.h
+++ b/src/endorse-certificate.h
@@ -55,6 +55,8 @@
class EndorseCertificate : public ndn::security::Certificate
{
public:
+ EndorseCertificate() {}
+
EndorseCertificate(const ndn::security::IdentityCertificate& kskCertificate,
const ndn::Time& notBefore,
const ndn::Time& notAfter,
diff --git a/src/warningdialog.cpp b/src/warningdialog.cpp
index 135403c..6c7eb8a 100644
--- a/src/warningdialog.cpp
+++ b/src/warningdialog.cpp
@@ -1,11 +1,26 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
#include "warningdialog.h"
#include "ui_warningdialog.h"
+using namespace std;
+
WarningDialog::WarningDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::WarningDialog)
{
- ui->setupUi(this);
+ ui->setupUi(this);
+
+ connect(ui->okButton, SIGNAL(clicked()),
+ this, SLOT(onOkClicked()));
}
WarningDialog::~WarningDialog()
@@ -13,6 +28,14 @@
delete ui;
}
+void
+WarningDialog::setMsg(const string& msg)
+{ ui->message->setText(QApplication::translate("WarningDialog",msg.c_str(), 0, QApplication::UnicodeUTF8)); }
+
+void
+WarningDialog::onOkClicked()
+{ this->hide(); }
+
#if WAF
#include "warningdialog.moc"
#include "warningdialog.cpp.moc"
diff --git a/src/warningdialog.h b/src/warningdialog.h
index 7b3125a..a2f3481 100644
--- a/src/warningdialog.h
+++ b/src/warningdialog.h
@@ -1,3 +1,13 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
#ifndef WARNINGDIALOG_H
#define WARNINGDIALOG_H
@@ -9,14 +19,22 @@
class WarningDialog : public QDialog
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit WarningDialog(QWidget *parent = 0);
- ~WarningDialog();
+ explicit WarningDialog(QWidget *parent = 0);
+
+ ~WarningDialog();
+
+ void
+ setMsg(const std::string& msg);
+
+private slots:
+ void
+ onOkClicked();
private:
- Ui::WarningDialog *ui;
+ Ui::WarningDialog *ui;
};
#endif // WARNINGDIALOG_H
diff --git a/src/warningdialog.ui b/src/warningdialog.ui
index 1edc546..e67bc40 100644
--- a/src/warningdialog.ui
+++ b/src/warningdialog.ui
@@ -13,19 +13,6 @@
<property name="windowTitle">
<string>Error</string>
</property>
- <widget class="QPushButton" name="okButton">
- <property name="geometry">
- <rect>
- <x>100</x>
- <y>160</y>
- <width>100</width>
- <height>32</height>
- </rect>
- </property>
- <property name="text">
- <string>OK</string>
- </property>
- </widget>
<widget class="QLabel" name="message">
<property name="geometry">
<rect>
@@ -42,6 +29,22 @@
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
+ <widget class="QPushButton" name="okButton">
+ <property name="geometry">
+ <rect>
+ <x>100</x>
+ <y>150</y>
+ <width>100</width>
+ <height>32</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>OK</string>
+ </property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
+ </widget>
</widget>
<resources/>
<connections/>