tinyca export improved

This commit is contained in:
chris2511 2003-02-19 15:31:08 +00:00
parent cf22f99374
commit d79f1e2da6
5 changed files with 94 additions and 34 deletions

View File

@ -164,6 +164,7 @@ class MainWindow: public MainWindow_UI
void newPath(QFileDialog *dlg);
void newPath(QString str);
bool mkDir(QString dir);
void writeCrl(QString s, pki_x509 *cert);
public slots:
void loadKey();
void loadReq();

View File

@ -1114,9 +1114,7 @@ void MainWindow::setTemplate()
void MainWindow::genCrl()
{
QStringList filt;
QList<pki_x509> list;
pki_x509 *cert = (pki_x509 *)certs->getSelectedPKI();
pki_x509 *issuedcert = NULL;
if (!cert) return;
if (cert->getKey()->isPubKey()) return;
filt.append(tr("CRLs ( *.crl )"));
@ -1132,6 +1130,13 @@ void MainWindow::genCrl()
delete dlg;
if (s.isEmpty()) return;
s = QDir::convertSeparators(s);
writeCrl(s, cert);
}
void MainWindow::writeCrl(QString s, pki_x509 *cert)
{
QList<pki_x509> list;
pki_x509 *issuedcert = NULL;
try {
pki_crl *crl = new pki_crl(cert->getDescription(), cert);
@ -1178,7 +1183,8 @@ void MainWindow::toTinyCA()
pki_key *key = crt->getKey();
if (!key) return;
FILE *fp;
QList<pki_x509> list;
pki_x509 *issuedcert;
QString dname = crt->getDescription().c_str();
QString tcatempdir = settings->getString("TinyCAtempdir").c_str();
QString tcadir = settings->getString("TinyCAdir").c_str();
@ -1200,6 +1206,9 @@ void MainWindow::toTinyCA()
if (dname.isEmpty()) return;
const EVP_CIPHER *enc = EVP_des_ede3_cbc();
settings->putString("TinyCAtempdir", tcatempdir.latin1());
settings->putString("TinyCAdir", tcadir.latin1());
// OK, we have all names now...
tcadir += QDir::separator();
tcadir += dname;
@ -1215,13 +1224,37 @@ void MainWindow::toTinyCA()
crt->writeCert("cacert.pem", true, false);
key->writeKey("cacert.key", enc, &MainWindow::passWrite, true);
chdir("crl");
writeCrl("crl.pem", crt);
chdir("..");
fp = fopen("serial", "w");
if (!fp) return;
fprintf(fp, "%x", crt->getCaSerial());
fprintf(fp, "%04x", crt->getCaSerial());
fclose(fp);
settings->putString("TinyCAtempdir", tcatempdir.latin1());
settings->putString("TinyCAdir", tcadir.latin1());
// store the issued certificates
fp = fopen("index.txt", "w");
if (!fp) return;
list = certs->getIssuedCerts(crt);
if (!list.isEmpty()) {
for ( issuedcert = list.first(); issuedcert != NULL; issuedcert = list.next() ) {
bool rev = issuedcert->isRevoked();
string revdate = issuedcert->revokedAt(TIMEFORM_PLAIN);
string nadate = issuedcert->notAfter(TIMEFORM_PLAIN);
string fname = issuedcert->tinyCAfname();
chdir("certs");
crt->writeCert(fname, true, false);
chdir("..");
chdir("keys");
key = crt->getKey();
key->writeKey(fname, NULL, &MainWindow::passWrite, true);
chdir("..");
fprintf(fp, "%c\t%s\t%s\tunknown %s\n", rev? 'R':'V', nadate.c_str(), revdate.c_str(),"------");
}
}
fclose(fp);
}

View File

@ -158,12 +158,12 @@ void db_x509::updateViewPKI(pki_base *pki)
current->setPixmap(0, *certicon[pixnum]);
current->setText(1, ((pki_x509 *)pki)->getDNs(NID_commonName).c_str());
current->setText(2, ((pki_x509 *)pki)->getSerial().c_str() );
current->setText(3, ((pki_x509 *)pki)->notAfterS().c_str() );
current->setText(3, ((pki_x509 *)pki)->notAfter(TIMEFORM_SORTABLE).c_str() );
MARK
CERR(((pki_x509 *)pki)->getTrust());
current->setText(4, truststatus[((pki_x509 *)pki)->getTrust() ]);
MARK
current->setText(5, ((pki_x509 *)pki)->revokedAt().c_str());
current->setText(5, ((pki_x509 *)pki)->revokedAt(TIMEFORM_SORTABLE).c_str());
}

View File

@ -381,33 +381,43 @@ string pki_x509::getDNi(int nid)
return s;
}
string pki_x509::notBefore()
string pki_x509::notBefore(int format)
{
return asn1TimeToString(X509_get_notBefore(cert));
return asn1TimeToString(X509_get_notBefore(cert), format);
}
string pki_x509::notBeforeS()
string pki_x509::notAfter(int format)
{
return asn1TimeToSortableString(X509_get_notBefore(cert));
return asn1TimeToString(X509_get_notAfter(cert), format);
}
string pki_x509::notAfter()
string pki_x509::revokedAt(int format)
{
return asn1TimeToString(X509_get_notAfter(cert));
}
string pki_x509::notAfterS()
{
return asn1TimeToSortableString(X509_get_notAfter(cert));
}
string pki_x509::revokedAt()
{
return asn1TimeToString(revoked);
return asn1TimeToString(revoked, format);
}
string pki_x509::asn1TimeToString(ASN1_TIME *a)
string pki_x509::asn1TimeToString(ASN1_TIME *a, int format)
{
string time = "";
switch (format) {
case TIMEFORM_PRETTY:
time = asn1TimeToPretty(a);
break;
case TIMEFORM_PLAIN:
time = asn1TimeToPlain(a);
break;
case TIMEFORM_SORTABLE:
time = asn1TimeToSortable(a);
break;
default:
time="Unknown Format";
}
return time;
}
string pki_x509::asn1TimeToPretty(ASN1_TIME *a)
{
string time = "";
if (!a) return time;
@ -421,7 +431,18 @@ string pki_x509::asn1TimeToString(ASN1_TIME *a)
return time;
}
string pki_x509::asn1TimeToSortableString(ASN1_TIME *a)
string pki_x509::asn1TimeToPlain(ASN1_TIME *a)
{
string time = "";
char b[15];
if (!a) return time;
memcpy(b, a->data, a->length);
b[a->length] = '\0';
time = b;
return time;
}
string pki_x509::asn1TimeToSortable(ASN1_TIME *a)
{
int y,m,d,g;
string time = "";

View File

@ -59,6 +59,11 @@
#ifndef PKI_X509_H
#define PKI_X509_H
#define TIMEFORM_PRETTY 1
#define TIMEFORM_PLAIN 2
#define TIMEFORM_SORTABLE 3
class pki_x509 : public pki_base
{
friend class pki_crl;
@ -93,12 +98,9 @@ class pki_x509 : public pki_base
pki_key *getPubKey(); // will be created temporarily and must be freed
void delKey();
bool setKey(pki_key *key);
string notAfter();
string notBefore();
string notAfterS();
string notBeforeS();
string revokedAt();
string asn1TimeToString(ASN1_TIME *a);
string notAfter(int format = TIMEFORM_PRETTY);
string notBefore(int format = TIMEFORM_PRETTY);
string revokedAt(int format = TIMEFORM_PRETTY);
pki_x509 *getSigner();
void delSigner();
string fingerprint(const EVP_MD *digest);
@ -129,7 +131,10 @@ class pki_x509 : public pki_base
void setDates(int days);
void setSerial(int serial);
string tinyCAfname();
string asn1TimeToSortableString(ASN1_TIME *a);
string asn1TimeToSortable(ASN1_TIME *a);
string asn1TimeToString(ASN1_TIME *a, int format);
string asn1TimeToPlain(ASN1_TIME *a);
string asn1TimeToPretty(ASN1_TIME *a);
int asn1TimeYMDG(ASN1_TIME *a, int *y, int *m, int *d, int *g);
};