mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
(copyright and licence itself remain unchanged) fix configure to set Qt include dir code justifying
186 lines
3.2 KiB
C++
186 lines
3.2 KiB
C++
/* vi: set sw=4 ts=4:
|
|
*
|
|
* Copyright (C) 2001 - 2007 Christian Hohnstaedt.
|
|
*
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#include "x509v3ext.h"
|
|
#include <openssl/x509v3.h>
|
|
#include <openssl/stack.h>
|
|
#include <qstringlist.h>
|
|
#include "base.h"
|
|
|
|
x509v3ext::x509v3ext()
|
|
{
|
|
ext = X509_EXTENSION_new();
|
|
}
|
|
|
|
x509v3ext::x509v3ext(const X509_EXTENSION *n)
|
|
{
|
|
ext = X509_EXTENSION_dup((X509_EXTENSION *)n);
|
|
}
|
|
|
|
x509v3ext::x509v3ext(const x509v3ext &n)
|
|
{
|
|
ext = NULL;
|
|
set(n.ext);
|
|
}
|
|
|
|
x509v3ext::~x509v3ext()
|
|
{
|
|
X509_EXTENSION_free(ext);
|
|
}
|
|
|
|
x509v3ext &x509v3ext::set(const X509_EXTENSION *n)
|
|
{
|
|
if (ext != NULL)
|
|
X509_EXTENSION_free(ext);
|
|
ext = X509_EXTENSION_dup((X509_EXTENSION *)n);
|
|
return *this;
|
|
}
|
|
|
|
x509v3ext &x509v3ext::create(int nid, const QString &et, X509V3_CTX *ctx)
|
|
{
|
|
if (ext) {
|
|
X509_EXTENSION_free(ext);
|
|
ext = NULL;
|
|
}
|
|
if (!et.isEmpty()) {
|
|
ext = X509V3_EXT_conf_nid(NULL, ctx, nid, (char*)CCHAR(et));
|
|
}
|
|
if (!ext) ext = X509_EXTENSION_new();
|
|
return *this;
|
|
}
|
|
|
|
int x509v3ext::nid() const
|
|
{
|
|
ASN1_OBJECT *obj = X509_EXTENSION_get_object(ext);
|
|
return OBJ_obj2nid(obj);
|
|
}
|
|
|
|
void *x509v3ext::d2i()
|
|
{
|
|
return X509V3_EXT_d2i(ext);
|
|
}
|
|
|
|
/*
|
|
bool x509v3ext::operator == (const x509v3ext &x) const
|
|
{
|
|
return (X509_EXTENSION_cmp(ext, x.ext) == 0);
|
|
}
|
|
*/
|
|
x509v3ext &x509v3ext::operator = (const x509v3ext &x)
|
|
{
|
|
set(x.ext);
|
|
return *this;
|
|
}
|
|
|
|
QString x509v3ext::getObject() const
|
|
{
|
|
QString a = OBJ_nid2ln(nid());
|
|
return a;
|
|
}
|
|
|
|
int x509v3ext::getCritical() const
|
|
{
|
|
return X509_EXTENSION_get_critical(ext);
|
|
}
|
|
|
|
QString x509v3ext::getValue() const
|
|
{
|
|
#define V3_BUF 100
|
|
QString text = "";
|
|
int len;
|
|
char buffer[V3_BUF+1];
|
|
BIO *bio = BIO_new(BIO_s_mem());
|
|
if(!X509V3_EXT_print(bio, ext, X509V3_EXT_PARSE_UNKNOWN, 0))
|
|
return text;
|
|
do {
|
|
len = BIO_read(bio, buffer, V3_BUF);
|
|
if (len < 0) break;
|
|
buffer[len] = '\0';
|
|
text+=buffer;
|
|
} while (len == V3_BUF);
|
|
#undef V3_BUF
|
|
return text;
|
|
}
|
|
|
|
QString x509v3ext::getHtml() const
|
|
{
|
|
QString html;
|
|
html = "<b><u>" + getObject();
|
|
if (getCritical() != 0)
|
|
html += " <font color=\"red\">critical</font>";
|
|
html += ":</u></b><br><tt>" + getValue() + "</tt>";
|
|
return html;
|
|
}
|
|
|
|
X509_EXTENSION *x509v3ext::get() const
|
|
{
|
|
return X509_EXTENSION_dup(ext);
|
|
}
|
|
|
|
bool x509v3ext::isValid() const
|
|
{
|
|
return ext->value->length > 0;
|
|
}
|
|
|
|
/*************************************************************/
|
|
|
|
void extList::setStack(STACK_OF(X509_EXTENSION) *st)
|
|
{
|
|
clear();
|
|
int cnt = sk_X509_EXTENSION_num(st);
|
|
x509v3ext e;
|
|
for (int i=0; i<cnt; i++) {
|
|
e.set(sk_X509_EXTENSION_value(st,i));
|
|
append(e);
|
|
}
|
|
}
|
|
|
|
STACK_OF(X509_EXTENSION) *extList::getStack()
|
|
{
|
|
STACK_OF(X509_EXTENSION) *sk;
|
|
sk = sk_X509_EXTENSION_new_null();
|
|
for (int i=0; i< count(); i++) {
|
|
sk_X509_EXTENSION_push(sk, operator[](i).get());
|
|
}
|
|
return sk;
|
|
}
|
|
|
|
QString extList::getHtml(const QString &sep)
|
|
{
|
|
x509v3ext e;
|
|
QStringList s;
|
|
for (int i=0; i< size(); i++)
|
|
s << at(i).getHtml();
|
|
QString a = s.join(sep);
|
|
return a;
|
|
}
|
|
|
|
int extList::delByNid(int nid)
|
|
{
|
|
int removed=0;
|
|
for(int i = 0; i< size(); i++) {
|
|
if (at(i).nid() == nid) {
|
|
removeAt(i);
|
|
removed=1;
|
|
}
|
|
}
|
|
return removed;
|
|
}
|
|
|
|
int extList::delInvalid(void)
|
|
{
|
|
int removed=0;
|
|
for(int i = 0; i<size(); i++) {
|
|
if (!at(i).isValid()) {
|
|
removeAt(i);
|
|
removed=1;
|
|
i--;
|
|
}
|
|
}
|
|
return removed;
|
|
}
|