mirror of https://github.com/JakubMelka/PDF4QT.git
Install certificate tool
This commit is contained in:
parent
78215e89af
commit
290c769cc3
|
@ -317,6 +317,11 @@ void PDFToolAbstractApplication::initializeCommandLineParser(QCommandLineParser*
|
||||||
parser->addOption(QCommandLineOption("list-user-certs", "Show list of user certificates.", "bool", "1"));
|
parser->addOption(QCommandLineOption("list-user-certs", "Show list of user certificates.", "bool", "1"));
|
||||||
parser->addOption(QCommandLineOption("list-system-certs", "Show list of system certificates.", "bool", "0"));
|
parser->addOption(QCommandLineOption("list-system-certs", "Show list of system certificates.", "bool", "0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (optionFlags.testFlag(CertStoreInstall))
|
||||||
|
{
|
||||||
|
parser->addPositionalArgument("certificate", "Certificate file");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFToolOptions PDFToolAbstractApplication::getOptions(QCommandLineParser* parser) const
|
PDFToolOptions PDFToolAbstractApplication::getOptions(QCommandLineParser* parser) const
|
||||||
|
@ -852,6 +857,11 @@ PDFToolOptions PDFToolAbstractApplication::getOptions(QCommandLineParser* parser
|
||||||
options.certStoreEnumerateUserCertificates = parser->value("list-user-certs").toInt();
|
options.certStoreEnumerateUserCertificates = parser->value("list-user-certs").toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (optionFlags.testFlag(CertStoreInstall))
|
||||||
|
{
|
||||||
|
options.certificateStoreInstallCertificateFile = positionalArguments.isEmpty() ? QString() : positionalArguments.front();
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,9 @@ struct PDFToolOptions
|
||||||
bool certStoreEnumerateSystemCertificates = false;
|
bool certStoreEnumerateSystemCertificates = false;
|
||||||
bool certStoreEnumerateUserCertificates = true;
|
bool certStoreEnumerateUserCertificates = true;
|
||||||
|
|
||||||
|
// For option 'CertStoreInstall'
|
||||||
|
QString certificateStoreInstallCertificateFile;
|
||||||
|
|
||||||
/// Returns page range. If page range is invalid, then \p errorMessage is empty.
|
/// Returns page range. If page range is invalid, then \p errorMessage is empty.
|
||||||
/// \param pageCount Page count
|
/// \param pageCount Page count
|
||||||
/// \param[out] errorMessage Error message
|
/// \param[out] errorMessage Error message
|
||||||
|
@ -184,6 +187,7 @@ public:
|
||||||
ErrorUnknown,
|
ErrorUnknown,
|
||||||
ErrorNoDocumentSpecified,
|
ErrorNoDocumentSpecified,
|
||||||
ErrorDocumentReading,
|
ErrorDocumentReading,
|
||||||
|
ErrorCertificateReading,
|
||||||
ErrorInvalidArguments,
|
ErrorInvalidArguments,
|
||||||
ErrorFailedWriteToFile,
|
ErrorFailedWriteToFile,
|
||||||
ErrorPermissions,
|
ErrorPermissions,
|
||||||
|
@ -223,6 +227,7 @@ public:
|
||||||
Unite = 0x00080000, ///< Settings for Unite tool
|
Unite = 0x00080000, ///< Settings for Unite tool
|
||||||
Optimize = 0x00100000, ///< Settings for Optimize tool
|
Optimize = 0x00100000, ///< Settings for Optimize tool
|
||||||
CertStore = 0x00200000, ///< Settings for certificate store tool
|
CertStore = 0x00200000, ///< Settings for certificate store tool
|
||||||
|
CertStoreInstall = 0x00400000, ///< Settings for certificate store install certificate tool
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(Options, Option)
|
Q_DECLARE_FLAGS(Options, Option)
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ namespace pdftool
|
||||||
{
|
{
|
||||||
|
|
||||||
static PDFToolCertStore s_certStoreApplication;
|
static PDFToolCertStore s_certStoreApplication;
|
||||||
|
static PDFToolCertStoreInstallCertificate s_certStoreAddApplication;
|
||||||
|
|
||||||
QString PDFToolCertStore::getStandardString(PDFToolAbstractApplication::StandardString standardString) const
|
QString PDFToolCertStore::getStandardString(PDFToolAbstractApplication::StandardString standardString) const
|
||||||
{
|
{
|
||||||
|
@ -143,4 +144,61 @@ PDFToolAbstractApplication::Options PDFToolCertStore::getOptionsFlags() const
|
||||||
return ConsoleFormat | DateFormat | CertStore;
|
return ConsoleFormat | DateFormat | CertStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString PDFToolCertStoreInstallCertificate::getStandardString(PDFToolAbstractApplication::StandardString standardString) const
|
||||||
|
{
|
||||||
|
switch (standardString)
|
||||||
|
{
|
||||||
|
case Command:
|
||||||
|
return "cert-store-install";
|
||||||
|
|
||||||
|
case Name:
|
||||||
|
return PDFToolTranslationContext::tr("Install Certificate");
|
||||||
|
|
||||||
|
case Description:
|
||||||
|
return PDFToolTranslationContext::tr("Install a new user certificate to certificate store.");
|
||||||
|
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
int PDFToolCertStoreInstallCertificate::execute(const PDFToolOptions& options)
|
||||||
|
{
|
||||||
|
QByteArray certificateData;
|
||||||
|
QFile file(options.certificateStoreInstallCertificateFile);
|
||||||
|
if (file.open(QFile::ReadOnly))
|
||||||
|
{
|
||||||
|
certificateData = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PDFConsole::writeError(PDFToolTranslationContext::tr("Cannot open file '%1'. %2").arg(options.certificateStoreInstallCertificateFile, file.errorString()), options.outputCodec);
|
||||||
|
return ErrorCertificateReading;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdf::PDFCertificateStore certificateStore;
|
||||||
|
certificateStore.loadDefaultUserCertificates();
|
||||||
|
|
||||||
|
if (certificateStore.add(pdf::PDFCertificateStore::EntryType::User, certificateData))
|
||||||
|
{
|
||||||
|
certificateStore.saveDefaultUserCertificates();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PDFConsole::writeError(PDFToolTranslationContext::tr("Cannot read certificate from file '%1'.").arg(options.certificateStoreInstallCertificateFile), options.outputCodec);
|
||||||
|
return ErrorCertificateReading;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ExitSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFToolAbstractApplication::Options PDFToolCertStoreInstallCertificate::getOptionsFlags() const
|
||||||
|
{
|
||||||
|
return ConsoleFormat | CertStoreInstall;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace pdftool
|
} // namespace pdftool
|
||||||
|
|
|
@ -31,6 +31,14 @@ public:
|
||||||
virtual Options getOptionsFlags() const override;
|
virtual Options getOptionsFlags() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PDFToolCertStoreInstallCertificate : public PDFToolAbstractApplication
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual QString getStandardString(StandardString standardString) const override;
|
||||||
|
virtual int execute(const PDFToolOptions& options) override;
|
||||||
|
virtual Options getOptionsFlags() const override;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace pdftool
|
} // namespace pdftool
|
||||||
|
|
||||||
#endif // PDFTOOLCERTSTORE_H
|
#endif // PDFTOOLCERTSTORE_H
|
||||||
|
|
Loading…
Reference in New Issue