1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-29 16:50:11 +02:00

Import qt-certificate-addon

This commit is contained in:
Uwe L. Korn
2014-06-27 02:17:10 +01:00
parent 2c9fefebeb
commit 12bd51c3ef
48 changed files with 3515 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
output.*
create_certificate

View File

@@ -0,0 +1,9 @@
TEMPLATE = app
TARGET = create_certificate
QT += network
LIBS += -Wl,-rpath,../../src/certificate -L../../src/certificate -lcertificate
INCLUDEPATH += ../../src/certificate
SOURCES = main.cpp

View File

@@ -0,0 +1,63 @@
#include <QByteArray>
#include <QFile>
#include <QDateTime>
#include <QSslKey>
#include <QSslCertificate>
#include "keybuilder.h"
#include "certificaterequestbuilder.h"
#include "certificaterequest.h"
#include "certificatebuilder.h"
#include "certificate.h"
QT_USE_NAMESPACE_CERTIFICATE
int main(int argc, char **argv)
{
QSslKey key = KeyBuilder::generate( QSsl::Rsa, KeyBuilder::StrengthNormal );
QFile k("output.key");
k.open(QIODevice::WriteOnly);
k.write(key.toPem());
k.close();
CertificateRequestBuilder reqbuilder;
reqbuilder.setVersion(1);
reqbuilder.setKey(key);
reqbuilder.addNameEntry(Certificate::EntryCountryName, "GB");
reqbuilder.addNameEntry(Certificate::EntryOrganizationName, "Westpoint");
reqbuilder.addNameEntry(Certificate::EntryOrganizationName, "West");
reqbuilder.addNameEntry(Certificate::EntryCommonName, "www.example.com");
// Sign the request
CertificateRequest req = reqbuilder.signedRequest(key);
//
// Export the results
//
QFile f("output.req");
f.open(QIODevice::WriteOnly);
f.write(req.toPem());
f.close();
//
// Now make a certificate
//
CertificateBuilder builder;
builder.setRequest(req);
builder.setVersion(3);
builder.setSerial("helloworld");
builder.setActivationTime(QDateTime::currentDateTimeUtc());
builder.setExpirationTime(QDateTime::currentDateTimeUtc());
builder.setBasicConstraints(true);
builder.setKeyUsage(CertificateBuilder::UsageCrlSign|CertificateBuilder::UsageKeyCertSign);
builder.addSubjectKeyIdentifier();
QSslCertificate cert = builder.signedCertificate(key);
QFile c("output.crt");
c.open(QIODevice::WriteOnly);
c.write(cert.toPem());
c.close();
}