mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 17:09:34 -05:00
CertificatePage
- enable export of own certificate to file - enable import certificate of friend from file read and write of file is done in the gui, because the methods for load from file and save to file on p3Peers are not implemented yet git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3093 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
c3b6da6386
commit
04aaceaf4d
@ -354,6 +354,9 @@ bool TextPage::fileSave()
|
|||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QFile::WriteOnly))
|
if (!file.open(QFile::WriteOnly))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//Todo: move save to file to p3Peers::SaveCertificateToFile
|
||||||
|
|
||||||
QTextStream ts(&file);
|
QTextStream ts(&file);
|
||||||
ts.setCodec(QTextCodec::codecForName("UTF-8"));
|
ts.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
ts << userCertEdit->document()->toPlainText();
|
ts << userCertEdit->document()->toPlainText();
|
||||||
@ -609,8 +612,7 @@ CertificatePage::CertificatePage(QWidget *parent) : QWizardPage(parent) {
|
|||||||
|
|
||||||
userFileCreateButton = new QPushButton;
|
userFileCreateButton = new QPushButton;
|
||||||
userFileCreateButton->setText(tr("Export my certificate..."));
|
userFileCreateButton->setText(tr("Export my certificate..."));
|
||||||
connect(userFileCreateButton, SIGNAL( clicked() ),
|
connect(userFileCreateButton, SIGNAL( clicked() ), this, SLOT( generateCertificateCalled()));
|
||||||
this, SLOT( generateCertificateCalled()));
|
|
||||||
|
|
||||||
userFileLayout = new QHBoxLayout;
|
userFileLayout = new QHBoxLayout;
|
||||||
userFileLayout->addWidget(userFileLabel);
|
userFileLayout->addWidget(userFileLabel);
|
||||||
@ -628,8 +630,7 @@ CertificatePage::CertificatePage(QWidget *parent) : QWizardPage(parent) {
|
|||||||
|
|
||||||
friendFileNameOpenButton= new QPushButton;
|
friendFileNameOpenButton= new QPushButton;
|
||||||
friendFileNameOpenButton->setText(tr("Browse"));
|
friendFileNameOpenButton->setText(tr("Browse"));
|
||||||
connect(friendFileNameOpenButton, SIGNAL( clicked()),
|
connect(friendFileNameOpenButton, SIGNAL( clicked()), this, SLOT( loadFriendCert()));
|
||||||
this , SLOT( loadFriendCert()));
|
|
||||||
|
|
||||||
friendFileLayout = new QHBoxLayout;
|
friendFileLayout = new QHBoxLayout;
|
||||||
friendFileLayout->addWidget(friendFileNameEdit) ;
|
friendFileLayout->addWidget(friendFileNameEdit) ;
|
||||||
@ -662,22 +663,38 @@ void CertificatePage::loadFriendCert() {
|
|||||||
void CertificatePage::generateCertificateCalled() {
|
void CertificatePage::generateCertificateCalled() {
|
||||||
qDebug() << " generateCertificateCalled";
|
qDebug() << " generateCertificateCalled";
|
||||||
|
|
||||||
|
std::string cert = rsPeers->saveCertificateToString(rsPeers->getOwnId());
|
||||||
|
if (cert.empty()) {
|
||||||
|
QMessageBox::information(this, tr("RetroShare"),
|
||||||
|
tr("Sorry, create certificate failed"),
|
||||||
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString qdir = QFileDialog::getSaveFileName(this,
|
QString qdir = QFileDialog::getSaveFileName(this,
|
||||||
tr("Please choose a filename"),
|
tr("Please choose a filename"),
|
||||||
QDir::homePath(),
|
QDir::homePath(),
|
||||||
"RetroShare Certificate (*.rsc)");
|
"RetroShare Certificate (*.rsc)");
|
||||||
|
//Todo: move save to file to p3Peers::SaveCertificateToFile
|
||||||
|
|
||||||
if ( rsPeers->saveCertificateToFile(rsPeers->getOwnId(), qdir.toStdString()) )
|
if (qdir.isEmpty() == false) {
|
||||||
{
|
QFile CertFile (qdir);
|
||||||
QMessageBox::information(this, tr("RetroShare"),
|
if (CertFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
tr("Certificate file successfully created"),
|
if (CertFile.write(QByteArray(cert.c_str())) > 0) {
|
||||||
QMessageBox::Ok, QMessageBox::Ok);
|
QMessageBox::information(this, tr("RetroShare"),
|
||||||
}
|
tr("Certificate file successfully created"),
|
||||||
else
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
{
|
} else {
|
||||||
QMessageBox::information(this, tr("RetroShare"),
|
QMessageBox::information(this, tr("RetroShare"),
|
||||||
tr("Sorry, certificate file creation failed"),
|
tr("Sorry, certificate file creation failed"),
|
||||||
QMessageBox::Ok, QMessageBox::Ok);
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
}
|
||||||
|
CertFile.close();
|
||||||
|
} else {
|
||||||
|
QMessageBox::information(this, tr("RetroShare"),
|
||||||
|
tr("Sorry, certificate file creation failed"),
|
||||||
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -689,39 +706,57 @@ bool CertificatePage::isComplete() const {
|
|||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
int CertificatePage::nextId() const {
|
int CertificatePage::nextId() const
|
||||||
std::string id;
|
{
|
||||||
|
|
||||||
QString fn = friendFileNameEdit->text();
|
QString fn = friendFileNameEdit->text();
|
||||||
if (QFile::exists(fn))
|
if (QFile::exists(fn)) {
|
||||||
{
|
//Todo: move read from file to p3Peers::loadCertificateFromFile
|
||||||
std::string fnstr = fn.toStdString();
|
|
||||||
// if ( rsPeers->LoadCertificateFromFile(fnstr, id) )
|
// read from file
|
||||||
if ( false )
|
std::string certstr;
|
||||||
{
|
QFile CertFile (fn);
|
||||||
wizard()->setField(SSL_ID_FIELD_CONNECT_FRIEND_WIZARD, QString::fromStdString(id));
|
if (CertFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
certstr = QString (CertFile.readAll()).toStdString();
|
||||||
return ConnectFriendWizard::Page_Conclusion;
|
CertFile.close();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (certstr.empty() == false) {
|
||||||
wizard()->setField("errorMessage",
|
RsPeerDetails pd;
|
||||||
// QString(tr("Certificate Load Failed:something is wrong with %1 ")).arg(fn) );
|
if ( rsPeers->loadDetailsFromStringCert(certstr, pd) ) {
|
||||||
QString(tr("Not implemented ")));
|
#ifdef FRIEND_WIZARD_DEBUG
|
||||||
|
std::cerr << "ConnectFriendWizard got id : " << pd.id << "; gpg_id : " << pd.gpg_id << std::endl;
|
||||||
|
#endif
|
||||||
|
wizard()->setField(SSL_ID_FIELD_CONNECT_FRIEND_WIZARD, QString::fromStdString(pd.id));
|
||||||
|
wizard()->setField(GPG_ID_FIELD_CONNECT_FRIEND_WIZARD, QString::fromStdString(pd.gpg_id));
|
||||||
|
wizard()->setField(LOCATION_FIELD_CONNECT_FRIEND_WIZARD, QString::fromStdString(pd.location));
|
||||||
|
wizard()->setField(CERT_STRING_FIELD_CONNECT_FRIEND_WIZARD, QString::fromStdString(certstr));
|
||||||
|
|
||||||
|
wizard()->setField("ext_friend_ip", QString::fromStdString(pd.extAddr));
|
||||||
|
wizard()->setField("ext_friend_port", QString::number(pd.extPort));
|
||||||
|
wizard()->setField("local_friend_ip", QString::fromStdString(pd.localAddr));
|
||||||
|
wizard()->setField("local_friend_port", QString::number(pd.localPort));
|
||||||
|
wizard()->setField("dyndns", QString::fromStdString(pd.dyndns));
|
||||||
|
|
||||||
|
return ConnectFriendWizard::Page_Conclusion ;
|
||||||
|
} else {
|
||||||
|
wizard()->setField("errorMessage", QString(tr("Certificate Load Failed:something is wrong with %1 ")).arg(fn) );
|
||||||
|
return ConnectFriendWizard::Page_ErrorMessage;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wizard()->setField("errorMessage", QString(tr("Certificate Load Failed:can't read from file %1 ")).arg(fn) );
|
||||||
return ConnectFriendWizard::Page_ErrorMessage;
|
return ConnectFriendWizard::Page_ErrorMessage;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
QString mess =
|
QString mess =
|
||||||
QString(tr("Certificate Load Failed:file %1 not found"))
|
QString(tr("Certificate Load Failed:file %1 not found"))
|
||||||
.arg(fn);
|
.arg(fn);
|
||||||
|
|
||||||
wizard()->setField("errorMessage", mess);
|
wizard()->setField("errorMessage", mess);
|
||||||
|
|
||||||
return ConnectFriendWizard::Page_ErrorMessage;
|
return ConnectFriendWizard::Page_ErrorMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//============================================================================
|
//============================================================================
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
Loading…
Reference in New Issue
Block a user