| 1 | #include<qdom.h>
|
|---|
| 2 | #include<qfile.h>
|
|---|
| 3 | #include"base64.h"
|
|---|
| 4 | #include"qca.h"
|
|---|
| 5 |
|
|---|
| 6 | QCA::Cert readCertXml(const QDomElement &e)
|
|---|
| 7 | {
|
|---|
| 8 | QCA::Cert cert;
|
|---|
| 9 | // there should be one child data tag
|
|---|
| 10 | QDomElement data = e.elementsByTagName("data").item(0).toElement();
|
|---|
| 11 | if(!data.isNull())
|
|---|
| 12 | cert.fromDER(Base64::stringToArray(data.text()));
|
|---|
| 13 | return cert;
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | void showCertInfo(const QCA::Cert &cert)
|
|---|
| 17 | {
|
|---|
| 18 | printf(" CN: %s\n", cert.subject()["CN"].latin1());
|
|---|
| 19 | printf(" Valid from: %s, until %s\n",
|
|---|
| 20 | cert.notBefore().toString().latin1(),
|
|---|
| 21 | cert.notAfter().toString().latin1());
|
|---|
| 22 | printf(" PEM:\n%s\n", cert.toPEM().latin1());
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | int main()
|
|---|
| 26 | {
|
|---|
| 27 | if(!QCA::isSupported(QCA::CAP_X509)) {
|
|---|
| 28 | printf("X509 not supported!\n");
|
|---|
| 29 | return 1;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | // open the Psi rootcerts file
|
|---|
| 33 | QFile f("/usr/local/share/psi/certs/rootcert.xml");
|
|---|
| 34 | if(!f.open(IO_ReadOnly)) {
|
|---|
| 35 | printf("unable to open %s\n", f.name().latin1());
|
|---|
| 36 | return 1;
|
|---|
| 37 | }
|
|---|
| 38 | QDomDocument doc;
|
|---|
| 39 | doc.setContent(&f);
|
|---|
| 40 | f.close();
|
|---|
| 41 |
|
|---|
| 42 | QDomElement base = doc.documentElement();
|
|---|
| 43 | if(base.tagName() != "store") {
|
|---|
| 44 | printf("wrong format of %s\n", f.name().latin1());
|
|---|
| 45 | return 1;
|
|---|
| 46 | }
|
|---|
| 47 | QDomNodeList cl = base.elementsByTagName("certificate");
|
|---|
| 48 | if(cl.count() == 0) {
|
|---|
| 49 | printf("no certs found in %s\n", f.name().latin1());
|
|---|
| 50 | return 1;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | for(int n = 0; n < (int)cl.count(); ++n) {
|
|---|
| 54 | printf("-- Cert %d --\n", n);
|
|---|
| 55 | QCA::Cert cert = readCertXml(cl.item(n).toElement());
|
|---|
| 56 | if(cert.isNull()) {
|
|---|
| 57 | printf("error reading cert\n");
|
|---|
| 58 | continue;
|
|---|
| 59 | }
|
|---|
| 60 | showCertInfo(cert);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | return 0;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|