mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
push forward to QT4
This commit is contained in:
parent
d80d1ff6d2
commit
c6622680db
14
lib/Makefile
14
lib/Makefile
@ -7,10 +7,16 @@ ifeq ($(TOPDIR),)
|
||||
TOPDIR=..
|
||||
endif
|
||||
|
||||
MOCNAMES=db_crl db_key db_temp db_x509 db_x509req db_x509super pki_base
|
||||
NAMES=$(MOCNAMES) asn1int oid pki_pkcs7 x509rev asn1time pass_info \
|
||||
pki_temp x509v3ext db_base pki_x509 func pki_crl pki_x509req \
|
||||
load_obj pki_key pki_x509super main pki_pkcs12 x509name
|
||||
#MOCNAMES=db_crl db_key db_temp db_x509 db_x509req db_x509super pki_base
|
||||
#NAMES=$(MOCNAMES) asn1int oid pki_pkcs7 x509rev asn1time pass_info \
|
||||
# pki_temp x509v3ext db_base pki_x509 func pki_crl pki_x509req \
|
||||
# load_obj pki_key pki_x509super main pki_pkcs12 x509name
|
||||
|
||||
MOCNAMES= pki_base db_base db_key db_x509super db_x509req db_x509
|
||||
NAMES=$(MOCNAMES) db asn1int oid asn1time pass_info \
|
||||
func load_obj pki_key pki_x509super \
|
||||
main x509name pki_x509req x509v3ext pki_x509 x509rev
|
||||
|
||||
|
||||
OBJS=$(patsubst %, %.o, $(NAMES)) $(patsubst %, moc_%.o, $(MOCNAMES))
|
||||
DELFILES=$(patsubst %,moc_%.cpp,$(MOCNAMES))
|
||||
|
||||
@ -148,7 +148,7 @@ void a1int::openssl_error() const
|
||||
a1int &a1int::setHex(const QString &s)
|
||||
{
|
||||
BIGNUM *bn=0;
|
||||
if (!BN_hex2bn(&bn,s.latin1()))
|
||||
if (!BN_hex2bn(&bn,s.toAscii()))
|
||||
openssl_error();
|
||||
BN_to_ASN1_INTEGER(bn, in);
|
||||
BN_free(bn);
|
||||
@ -158,7 +158,7 @@ a1int &a1int::setHex(const QString &s)
|
||||
a1int &a1int::setDec(const QString &s)
|
||||
{
|
||||
BIGNUM *bn=0;
|
||||
if (!BN_dec2bn(&bn,s.latin1()))
|
||||
if (!BN_dec2bn(&bn,s.toAscii()))
|
||||
openssl_error();
|
||||
BN_to_ASN1_INTEGER(bn, in);
|
||||
BN_free(bn);
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
#ifndef ASN1INTEGER_H
|
||||
#define ASN1INTEGER_H
|
||||
|
||||
#include <qstring.h>
|
||||
#include <Qt/qstring.h>
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
class a1int
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -178,7 +176,8 @@ QString a1time::toSortable() const
|
||||
|
||||
a1time &a1time::set(const QString &s)
|
||||
{
|
||||
ASN1_GENERALIZEDTIME_set_string(time, (char *)s.latin1());
|
||||
const char *x = s.toAscii();
|
||||
ASN1_GENERALIZEDTIME_set_string(time, (char*)x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@ -35,8 +35,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -51,7 +49,7 @@
|
||||
#ifndef ASN1TIME_H
|
||||
#define ASN1TIME_H
|
||||
|
||||
#include <qstring.h>
|
||||
#include <Qt/qstring.h>
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
class a1time
|
||||
|
||||
17
lib/base.h
17
lib/base.h
@ -5,18 +5,7 @@
|
||||
|
||||
#define XCA_TITLE "X Certificate and Key management"
|
||||
|
||||
#include <qglobal.h>
|
||||
|
||||
#if QT_VERSION >= 0x030000
|
||||
#if QT_VERSION >= 0x040000
|
||||
#define qt4
|
||||
#define QListView Q3ListView
|
||||
#define QListViewItem Q3ListViewItem
|
||||
#define QListViewItemIterator Q3ListViewItemIterator
|
||||
#else
|
||||
#define qt3
|
||||
#endif
|
||||
#endif
|
||||
#include <Qt/qglobal.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
@ -32,4 +21,8 @@
|
||||
#define D2I_CLASHT(f, t, a, PP, s) f(t,a,(unsigned char **)PP,s)
|
||||
#endif
|
||||
|
||||
#define CCHAR(x) ((const char *)(x).toAscii().constData())
|
||||
#endif
|
||||
|
||||
//#define TRACE printf("File: "__FILE__" Func: %s Line: %d\n",__func__, __LINE__);
|
||||
#define TRACE
|
||||
|
||||
444
lib/db.cpp
Normal file
444
lib/db.cpp
Normal file
@ -0,0 +1,444 @@
|
||||
#include "db.h"
|
||||
#include "base.h"
|
||||
#include <netinet/in.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if 0
|
||||
int main()
|
||||
{
|
||||
db mydb("test_db.x");
|
||||
unsigned char *buf;
|
||||
buf = (unsigned char *)malloc(400);
|
||||
|
||||
/*
|
||||
mydb.add(buf, 74, 1, async_key, "First entry");
|
||||
mydb.add(buf, 246, 2, async_key, "Second entry");
|
||||
mydb.add(buf, 43, 3, async_key, "Third thing");
|
||||
mydb.add(buf, 74, 4, x509, "First entry");
|
||||
*/
|
||||
mydb.first();
|
||||
if(mydb.find(async_key, "First entry") == 0)
|
||||
printf("A\n" );
|
||||
mydb.first();
|
||||
if (mydb.find(async_key, "Third thing") == 0)
|
||||
printf("B\n");
|
||||
mydb.first();
|
||||
if (mydb.find(async_key, "Second entry") == 0)
|
||||
printf("C\n");
|
||||
mydb.first();
|
||||
if (mydb.find(async_key, "S-------y") == 0)
|
||||
printf("D\n");
|
||||
if (mydb.rename(async_key, "Second entry", "This is renamed") == 0)
|
||||
printf("Rename success\n");
|
||||
}
|
||||
#endif
|
||||
db::db(QString filename, int mode)
|
||||
{
|
||||
printf("DB->constructor('%s')\n", CCHAR(filename));
|
||||
name = filename;
|
||||
fd = open(CCHAR(filename), O_RDWR | O_CREAT, mode);
|
||||
if (fd<0) {
|
||||
errstr = QString("DB open() failed: ") + filename +" "+
|
||||
strerror(errno);
|
||||
dberrno = errno;
|
||||
} else {
|
||||
first();
|
||||
}
|
||||
}
|
||||
|
||||
db::~db()
|
||||
{
|
||||
printf("DB->destructor()\n");
|
||||
if (fd>=0)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void db::init_header(db_header_t *db, int ver, int len, enum pki_type type,
|
||||
const char *name)
|
||||
{
|
||||
memset(db, 0, sizeof(db_header_t));
|
||||
db->magic = htonl(XCA_MAGIC);
|
||||
db->len = htonl(sizeof(db_header_t)+len);
|
||||
db->headver = htons(1);
|
||||
db->type = htons(type);
|
||||
db->version = htons(ver);
|
||||
db->flags = 0;
|
||||
strncpy(db->name, name, NAMELEN);
|
||||
}
|
||||
|
||||
void db::convert_header(db_header_t *h)
|
||||
{
|
||||
h->magic = ntohl(head.magic);
|
||||
h->len = ntohl(head.len);
|
||||
h->headver = ntohs(head.headver);
|
||||
h->type = ntohs(head.type);
|
||||
h->version = ntohs(head.version);
|
||||
h->flags = ntohs(head.flags);
|
||||
memcpy(h->name, head.name, NAMELEN);
|
||||
}
|
||||
|
||||
bool db::verify_magic(void)
|
||||
{
|
||||
if (head_offset != OFF_EOF)
|
||||
if (ntohl(head.magic) != XCA_MAGIC) {
|
||||
printf("database error at %lu\n", head_offset);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int db::find(enum pki_type type, const char *name)
|
||||
{
|
||||
//int len, ret=0;
|
||||
|
||||
if (head_offset == OFF_EOF)
|
||||
return 1;
|
||||
|
||||
do {
|
||||
//printf("Comparing %s -> %s at %lu\n", head.name, name,
|
||||
// head_offset);
|
||||
if (ntohs(head.type) == type) {
|
||||
if (name == NULL) { /* only compare type */
|
||||
//printf("typematch: %d\n", type);
|
||||
return 0;
|
||||
} else if (!strncmp(head.name, name, NAMELEN)) {
|
||||
//printf("namematch: %s\n", name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (!verify_magic()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
} while (next() == 0);
|
||||
//printf("Returning 1\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
void db::first(void)
|
||||
{
|
||||
int ret;
|
||||
//printf("First\n");
|
||||
memset(&head, 0, sizeof(db_header_t) );
|
||||
head_offset = lseek(fd, 0, SEEK_SET );
|
||||
ret = read(fd, &head, sizeof(db_header_t) );
|
||||
if (ret<=0) {
|
||||
head_offset = OFF_EOF;
|
||||
return;
|
||||
}
|
||||
if (!verify_magic())
|
||||
return;
|
||||
if (ntohs(head.flags) & DBFLAG_DELETED)
|
||||
next();
|
||||
}
|
||||
|
||||
int db::next(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (head_offset == OFF_EOF)
|
||||
return 1;
|
||||
|
||||
head_offset = lseek(fd, head_offset + ntohl(head.len), SEEK_SET );
|
||||
ret = read(fd, &head, sizeof(db_header_t) );
|
||||
if (ret==0) {
|
||||
//printf("Next: EOF at %lu\n", head_offset);
|
||||
head_offset = OFF_EOF;
|
||||
return 1;
|
||||
}
|
||||
if (ret < 0) {
|
||||
printf("read() failed: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (ret != sizeof(db_header_t)) {
|
||||
printf("Length broken: %d instead of %d\n", ret,
|
||||
sizeof(db_header_t) );
|
||||
ftruncate(fd, head_offset);
|
||||
head_offset = OFF_EOF;
|
||||
return -1;
|
||||
}
|
||||
if (!verify_magic()){
|
||||
printf("Garbage found at %lu\n", head_offset);
|
||||
head_offset+=4;
|
||||
return next();
|
||||
}
|
||||
if (ntohs(head.flags) & DBFLAG_DELETED)
|
||||
return next();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int db::rename(enum pki_type type, const char *name, const char *n)
|
||||
{
|
||||
int ret;
|
||||
|
||||
first();
|
||||
printf("Old name: %s new name: %s\n", name, n);
|
||||
if (find(type, n) == 0) {
|
||||
printf("New name: %s already in use\n", n);
|
||||
return -1;
|
||||
}
|
||||
first();
|
||||
if (find(type, name) != 0) {
|
||||
printf("Entry to rename not found: %s\n", name);
|
||||
return -1;
|
||||
}
|
||||
printf("Off = %lu\n", head_offset);
|
||||
strncpy(head.name, n, NAMELEN);
|
||||
lseek(fd, head_offset, SEEK_SET);
|
||||
ret = write(fd, &head, sizeof(head));
|
||||
if (ret != sizeof(head)) {
|
||||
printf("DB: Write error %d - %d\n", ret, sizeof(head));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString db::uniq_name(QString s, enum pki_type type)
|
||||
{
|
||||
int i;
|
||||
QString myname = s;
|
||||
|
||||
first();
|
||||
for (i=1;;i++) {
|
||||
if (find(type, CCHAR(myname)) == 0) {
|
||||
printf("duplicate entry found at %lx\n", head_offset);
|
||||
myname = QString("%1_%2").arg(s).arg(i);
|
||||
printf("Trying '%s'\n", CCHAR(myname));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return myname;
|
||||
}
|
||||
|
||||
int db::add(const unsigned char *p, int len, int ver, enum pki_type type,
|
||||
const char *name)
|
||||
{
|
||||
db_header_t db;
|
||||
|
||||
init_header(&db, ver, len, type, name);
|
||||
lseek(fd, 0, SEEK_END);
|
||||
|
||||
if (write(fd, &db, sizeof(db)) != sizeof(db)) {
|
||||
printf("write() failed\n");
|
||||
return -1;
|
||||
}
|
||||
if (write(fd, p, len) != len) {
|
||||
printf("write() failed\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int db::set(const unsigned char *p, int len, int ver, enum pki_type type,
|
||||
const char *name)
|
||||
{
|
||||
int ret;
|
||||
|
||||
first();
|
||||
ret = find(type, name);
|
||||
if (ret == 1) {
|
||||
printf("## Name not found -> add\n");
|
||||
return add(p, len, ver, type, name);
|
||||
}
|
||||
if (ret == 0) {
|
||||
printf("offs = %x, len=%d, head.len=%d name = %s flags=%x\n",
|
||||
head_offset, len, ntohl(head.len), head.name,
|
||||
ntohs(head.flags));
|
||||
lseek(fd, head_offset, SEEK_SET);
|
||||
if (len != ntohl(head.len) - sizeof(db_header_t)) {
|
||||
printf("## Found and len unequal %d, %d\n",
|
||||
len, ntohl(head.len) - sizeof(db_header_t));
|
||||
int flags;
|
||||
flags = head.flags;
|
||||
head.flags |= htons(DBFLAG_DELETED | DBFLAG_OUTDATED);
|
||||
|
||||
if (write(fd, &head, sizeof(db_header_t)) !=
|
||||
sizeof(db_header_t))
|
||||
{
|
||||
printf("erasing of %s at failed\n", head.name);
|
||||
dberrno = errno;
|
||||
return -1;
|
||||
}
|
||||
if (add(p, len, ver, type, name) < 0) {
|
||||
lseek(fd, head_offset, SEEK_SET);
|
||||
head.flags = flags;
|
||||
write(fd, &head, sizeof(db_header_t));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
printf("## Overwriting entry at %u\n", head_offset);
|
||||
head.version = htons(ver);
|
||||
if (write(fd, &head, sizeof(db_header_t)) !=
|
||||
sizeof(db_header_t)) {
|
||||
printf("write() failed\n");
|
||||
return -1;
|
||||
}
|
||||
if (write(fd, p, len) != len) {
|
||||
printf("write() failed\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
unsigned char *db::load(db_header_t *u_header)
|
||||
{
|
||||
uint32_t size;
|
||||
int ret;
|
||||
unsigned char *data;
|
||||
|
||||
if (head_offset == OFF_EOF)
|
||||
return NULL;
|
||||
size = ntohl(head.len) - sizeof(db_header_t);
|
||||
data = (unsigned char *)malloc(size);
|
||||
lseek(fd, head_offset + sizeof(db_header_t), SEEK_SET);
|
||||
ret = read(fd, data, size);
|
||||
if ((unsigned)ret == size) {
|
||||
if (u_header)
|
||||
convert_header(u_header);
|
||||
return data;
|
||||
|
||||
} else {
|
||||
printf("read of %u bytes failed: %d\n", size, ret);
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int db::erase(void)
|
||||
{
|
||||
if (head_offset == OFF_EOF)
|
||||
return -1;
|
||||
|
||||
head.flags |= htons(DBFLAG_DELETED);
|
||||
|
||||
lseek(fd, head_offset, SEEK_SET);
|
||||
if (write(fd, &head, sizeof(db_header_t)) != sizeof(db_header_t)) {
|
||||
printf("erasing of %s at %u failed\n", head.name, head_offset);
|
||||
dberrno = errno;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int db::shrink(int flags)
|
||||
{
|
||||
int fdn, ret, i=0;
|
||||
uint32_t offs;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
QString filename = name + "{new}";
|
||||
fdn = open(CCHAR(filename), O_RDWR | O_CREAT, 0644);
|
||||
if (fdn<0) {
|
||||
errstr = QString("open() failed: ") + filename +" "+
|
||||
strerror(errno);
|
||||
return 1;
|
||||
}
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
|
||||
while ((ret = read(fd, &head, sizeof(head))) > 0) {
|
||||
if (!verify_magic())
|
||||
return 1;
|
||||
head_offset = ntohl(head.len) - sizeof(head);
|
||||
printf("Read[%d] = %d\n", i++, offs);
|
||||
if (ntohs(head.flags) == flags) {
|
||||
printf("Skip Entry\n");
|
||||
/* FF to the next entry */
|
||||
offs = (int)lseek(fd, head_offset, SEEK_CUR);
|
||||
printf("Seeking to %d\n", offs);
|
||||
if (head_offset == (uint32_t)-1)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
ret = write(fdn, &head, sizeof(head));
|
||||
if (ret<0)
|
||||
break;
|
||||
printf("Write Entry %d of %d\n", BUFSIZ, head_offset);
|
||||
offs = head_offset;
|
||||
while (offs) {
|
||||
ret = read(fd, buf, (offs > BUFSIZ) ? BUFSIZ : offs);
|
||||
if (ret<=0)
|
||||
break;
|
||||
ret = write(fdn, buf, ret);
|
||||
if (ret<0)
|
||||
break;
|
||||
printf("offs=%d, ret=%d\n", offs, ret);
|
||||
offs -= ret;
|
||||
}
|
||||
if (offs)
|
||||
break;
|
||||
|
||||
}
|
||||
printf("Rewriting done, re=%d\n", ret);
|
||||
close(fdn);
|
||||
if (ret) {
|
||||
unlink(CCHAR(filename));
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
fd=-1;
|
||||
// use the global rename() function and not the method of this class
|
||||
::rename(CCHAR(filename), CCHAR(name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int db::intToData(unsigned char **p, uint32_t val)
|
||||
{
|
||||
int s = sizeof(uint32_t);
|
||||
uint32_t v = htonl(val);
|
||||
memcpy(*p, &v, s);
|
||||
*p += s;
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t db::intFromData(const unsigned char **p)
|
||||
{
|
||||
int s = sizeof(uint32_t);
|
||||
uint32_t ret;
|
||||
memcpy(&ret, *p, s);
|
||||
*p += s;
|
||||
return ntohl(ret);
|
||||
}
|
||||
|
||||
int db::boolToData(unsigned char **p, bool val)
|
||||
{
|
||||
unsigned char c = val ? 1 : 0;
|
||||
*(*p)++ = c;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool db::boolFromData(const unsigned char **p)
|
||||
{
|
||||
unsigned char c = *(*p)++;
|
||||
return c ? true : false;
|
||||
}
|
||||
|
||||
int db::stringToData(unsigned char **p, const QString val)
|
||||
{
|
||||
int s = (val.length() +1) * sizeof(char);
|
||||
memcpy(*p, val.toAscii(), s);
|
||||
*p += s;
|
||||
return s;
|
||||
}
|
||||
|
||||
QString db::stringFromData(const unsigned char **p)
|
||||
{
|
||||
QString ret="";
|
||||
while(**p) {
|
||||
ret +=(char)**p;
|
||||
*p += sizeof(char);
|
||||
}
|
||||
*p += sizeof(char);
|
||||
return ret;
|
||||
}
|
||||
79
lib/db.h
Normal file
79
lib/db.h
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef _XCA_DB_H_
|
||||
#define _XCA_DB_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <Qt/qstring.h>
|
||||
|
||||
#define XCA_MAGIC 0xcadb1969
|
||||
#define NAMELEN 80
|
||||
#define FNAMLEN 256
|
||||
#define OFF_EOF ((off_t)-1)
|
||||
|
||||
#define DBFLAG_DELETED 1
|
||||
#define DBFLAG_OUTDATED 2
|
||||
|
||||
enum pki_type {
|
||||
none,
|
||||
async_key,
|
||||
x509_req,
|
||||
x509,
|
||||
crl,
|
||||
tmpl,
|
||||
setting,
|
||||
};
|
||||
|
||||
typedef struct db_header_t {
|
||||
uint32_t magic;
|
||||
uint32_t len; /* length of this entry */
|
||||
uint16_t headver;
|
||||
uint16_t type;
|
||||
uint16_t version;
|
||||
uint16_t flags;
|
||||
char name[NAMELEN]; /* name of the entry */
|
||||
};
|
||||
|
||||
class db
|
||||
{
|
||||
private:
|
||||
int fd;
|
||||
QString name;
|
||||
QString errstr;
|
||||
int dberrno;
|
||||
db_header_t head;
|
||||
off_t head_offset;
|
||||
|
||||
void init_header(db_header_t *db, int ver, int len, enum pki_type type,
|
||||
const char *name);
|
||||
bool verify_magic(void);
|
||||
void convert_header(db_header_t *h);
|
||||
|
||||
public:
|
||||
db(QString, int mode = S_IRUSR | S_IWUSR);
|
||||
~db();
|
||||
void first(void);
|
||||
int find(enum pki_type type, const char *name);
|
||||
int next(void);
|
||||
QString uniq_name(QString s, enum pki_type type);
|
||||
int rename(enum pki_type type, const char *name, const char *n);
|
||||
int add(const unsigned char *p, int len, int ver, enum pki_type type,
|
||||
const char *name);
|
||||
int set(const unsigned char *p, int len, int ver, enum pki_type type,
|
||||
const char *name);
|
||||
unsigned char *load(db_header_t *u_header);
|
||||
int erase(void);
|
||||
int shrink(int flags);
|
||||
|
||||
static int intToData(unsigned char **p, uint32_t val);
|
||||
static uint32_t intFromData(const unsigned char **p);
|
||||
static int boolToData(unsigned char **p, bool val);
|
||||
static bool boolFromData(const unsigned char **p);
|
||||
static int stringToData(unsigned char **p, const QString val);
|
||||
static QString stringFromData(const unsigned char **p);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
645
lib/db_base.cpp
645
lib/db_base.cpp
@ -36,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -52,15 +50,10 @@
|
||||
|
||||
#include "db_base.h"
|
||||
#include "exception.h"
|
||||
#include "view/XcaListView.h"
|
||||
#include <qmessagebox.h>
|
||||
#include <qdir.h>
|
||||
#ifdef qt4
|
||||
#include <q3listview.h>
|
||||
#else
|
||||
#include <qlistview.h>
|
||||
#endif
|
||||
#include <qdir.h>
|
||||
#include <Qt/qmessagebox.h>
|
||||
#include <Qt/qdir.h>
|
||||
#include <Qt/qlistview.h>
|
||||
#include <Qt/qdir.h>
|
||||
#ifdef WIN32
|
||||
#include <direct.h> // to define mkdir function
|
||||
#include <windows.h> // to define mkdir function
|
||||
@ -69,426 +62,378 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#include "widgets/MainWindow.h"
|
||||
//#include "widgets/ImportMulti.h"
|
||||
|
||||
|
||||
db_base::db_base(DbEnv *dbe, QString DBfile, QString DB, DbTxn *global_tid,
|
||||
XcaListView *lvi)
|
||||
db_base::db_base(QString db, MainWindow *mw)
|
||||
:QAbstractItemModel(NULL)
|
||||
{
|
||||
listview = lvi;
|
||||
dbenv = dbe;
|
||||
data = new Db(dbe, 0);
|
||||
dbName = DB;
|
||||
|
||||
try {
|
||||
#if DB_VERSION_MAJOR >= 4 && DB_VERSION_MINOR >=1
|
||||
data->open(NULL, DBfile.latin1(), DB.latin1(), DB_BTREE, DB_CREATE, 0600);
|
||||
#else
|
||||
data->open(DBfile.latin1(), DB.latin1(), DB_BTREE, DB_CREATE, 0600);
|
||||
#endif
|
||||
}
|
||||
catch (DbException &err) {
|
||||
throw errorEx(err.what());
|
||||
}
|
||||
dbName = db;
|
||||
rootItem = newPKI();
|
||||
printf("New DB: %s\n", CCHAR(db));
|
||||
headertext.clear();
|
||||
mainwin = mw;
|
||||
}
|
||||
|
||||
|
||||
db_base::~db_base()
|
||||
{
|
||||
// CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
// fprintf(stderr, "close 1:\n" );
|
||||
// CRYPTO_mem_leaks_fp(stderr);
|
||||
data->close(0);
|
||||
container.setAutoDelete(true);
|
||||
container.clear();
|
||||
// fprintf(stderr, "close 2:\n" );
|
||||
// CRYPTO_mem_leaks_fp(stderr);
|
||||
// CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF);
|
||||
FOR_ALL_pki(pki, pki_base)
|
||||
rootItem->freeChild(pki);
|
||||
delete rootItem;
|
||||
}
|
||||
|
||||
void *db_base::getData(void *key, int length, int *dsize)
|
||||
{
|
||||
*dsize = 0;
|
||||
if ((key == NULL) || (length == 0) ) {
|
||||
return NULL;
|
||||
}
|
||||
try {
|
||||
void *p;
|
||||
Dbt k(key, length);
|
||||
Dbt d(NULL, 0);
|
||||
if (data->get(NULL, &k, &d, 0)) return NULL;
|
||||
p = d.get_data();
|
||||
*dsize = d.get_size();
|
||||
void *q = malloc(*dsize);
|
||||
memcpy(q,p,*dsize);
|
||||
return q;
|
||||
}
|
||||
catch (DbException &err) {
|
||||
throw errorEx(err.what());
|
||||
}
|
||||
return NULL;
|
||||
pki_base *db_base::newPKI(){
|
||||
return new pki_base("rootItem");
|
||||
}
|
||||
|
||||
void *db_base::getData(QString key, int *dsize)
|
||||
void db_base::remFromCont(pki_base *ref)
|
||||
{
|
||||
return getData((void *)key.latin1(), key.length()+ 1, dsize);
|
||||
}
|
||||
|
||||
|
||||
QString db_base::getString(QString key)
|
||||
{
|
||||
QString x = "";
|
||||
int dsize;
|
||||
char *p = (char *)getData(key, &dsize);
|
||||
if (p == NULL) {
|
||||
return x;
|
||||
}
|
||||
if ( p[dsize-1] != '\0' ) {
|
||||
return x;
|
||||
}
|
||||
x = p;
|
||||
free(p);
|
||||
if ( (int)x.length() != (dsize-1) ) {
|
||||
// FIXME: Errorhandling...
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
QString db_base::getString(char *key)
|
||||
{
|
||||
QString x = key;
|
||||
return getString(x);
|
||||
}
|
||||
|
||||
|
||||
int db_base::getInt(QString key)
|
||||
{
|
||||
QString x = getString(key);
|
||||
return atoi(x.latin1());
|
||||
}
|
||||
|
||||
|
||||
void db_base::putData(void *key, int keylen, void *dat, int datalen, DbTxn *tid)
|
||||
{
|
||||
|
||||
Dbt k(key, keylen);
|
||||
Dbt d(dat, datalen);
|
||||
try {
|
||||
data->put(tid, &k, &d, 0 );
|
||||
}
|
||||
catch (DbException &err) {
|
||||
throw errorEx(err.what());
|
||||
}
|
||||
}
|
||||
|
||||
void db_base::putString(QString key, void *dat, int datalen, DbTxn *tid)
|
||||
{
|
||||
putData((void *)key.latin1(), key.length()+1, dat, datalen, tid);
|
||||
}
|
||||
|
||||
void db_base::putString(QString key, QString dat, DbTxn *tid)
|
||||
{
|
||||
putString(key, (void *)dat.latin1(), dat.length() +1, tid);
|
||||
}
|
||||
|
||||
void db_base::putString(char *key, QString dat, DbTxn *tid)
|
||||
{
|
||||
QString x = key;
|
||||
putString(x, dat, tid);
|
||||
}
|
||||
|
||||
void db_base::putInt(QString key, int dat, DbTxn *tid)
|
||||
{
|
||||
char buf[100];
|
||||
sprintf(buf,"%i",dat);
|
||||
QString x = buf;
|
||||
putString(key, x, tid);
|
||||
}
|
||||
|
||||
void db_base::loadContainer()
|
||||
{
|
||||
// CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
DbTxn *tid = NULL;
|
||||
Dbc *cursor = NULL;
|
||||
db mydb(dbName);
|
||||
unsigned char *p;
|
||||
try {
|
||||
dbenv->txn_begin(NULL, &tid, 0);
|
||||
data->cursor(tid, &cursor, 0);
|
||||
Dbt *k = new Dbt();
|
||||
Dbt *d = new Dbt();
|
||||
QString desc;
|
||||
pki_base *pki;
|
||||
container.clear();
|
||||
while (!cursor->get(k, d, DB_NEXT)) {
|
||||
desc = (char *)k->get_data();
|
||||
p = (unsigned char *)d->get_data();
|
||||
int size = d->get_size();
|
||||
try {
|
||||
// fprintf(stderr, "loadContainer 1:\n" );
|
||||
// CRYPTO_mem_leaks_fp(stderr);
|
||||
pki = newPKI();
|
||||
// fprintf(stderr, "loadContainer 2:\n" );
|
||||
// CRYPTO_mem_leaks_fp(stderr);
|
||||
pki->setIntName(desc);
|
||||
// fprintf(stderr, "loadContainer 3:\n" );
|
||||
// CRYPTO_mem_leaks_fp(stderr);
|
||||
pki->fromData(p, size);
|
||||
// fprintf(stderr, "loadContainer 4:\n" );
|
||||
// CRYPTO_mem_leaks_fp(stderr);
|
||||
container.append(pki);
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
QMessageBox::warning(NULL,tr(XCA_TITLE),
|
||||
tr("Error loading: '") + desc + "'\n" +
|
||||
err.getCString());
|
||||
delete pki;
|
||||
}
|
||||
db_header_t head;
|
||||
|
||||
pki_base *pb, *pki;
|
||||
pb = newPKI();
|
||||
while ( mydb.find(pb->getType(), NULL) == 0 ) {
|
||||
QString s;
|
||||
p = mydb.load(&head);
|
||||
if (!p) {
|
||||
printf("Load was empty !\n");
|
||||
break;
|
||||
}
|
||||
delete (k);
|
||||
delete (d);
|
||||
cursor->close();
|
||||
// fprintf(stderr, "loadContainer 5:\n" );
|
||||
// CRYPTO_mem_leaks_fp(stderr);
|
||||
preprocess();
|
||||
// fprintf(stderr, "loadContainer 6:\n" );
|
||||
// CRYPTO_mem_leaks_fp(stderr);
|
||||
tid->commit(0);
|
||||
//printf("load item: %s\n",head.name);
|
||||
if (pb->getVersion() < head.version) {
|
||||
free(p);
|
||||
printf("Item[%s]: Version %d > known version: %d -> ignored\n",
|
||||
head.name, head.version, pb->getVersion() );
|
||||
continue;
|
||||
}
|
||||
pki = newPKI();
|
||||
s = head.name;
|
||||
pki->setIntName(s);
|
||||
|
||||
pki->fromData(p, &head);
|
||||
inToCont(pki);
|
||||
if (mydb.next() != 0)
|
||||
break;
|
||||
}
|
||||
catch (DbException &err) {
|
||||
tid->abort();
|
||||
throw errorEx(err.what());
|
||||
}
|
||||
// fprintf(stderr, "loadContainer 7:\n" );
|
||||
// CRYPTO_mem_leaks_fp(stderr);
|
||||
// CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF);
|
||||
}
|
||||
delete pb;
|
||||
}
|
||||
|
||||
void db_base::insertPKI(pki_base *pki)
|
||||
{
|
||||
DbTxn *tid = NULL;
|
||||
dbenv->txn_begin(NULL, &tid, 0);
|
||||
try {
|
||||
_writePKI(pki, false, tid);
|
||||
inToCont(pki);
|
||||
tid->commit(0);
|
||||
}
|
||||
catch (DbException &err) {
|
||||
tid->abort();
|
||||
throw errorEx(err.what());
|
||||
}
|
||||
if (listview) {
|
||||
|
||||
QListViewItem *lvi = new QListViewItem((QListView *)listview, pki->getIntName());
|
||||
listview->insertItem(lvi);
|
||||
pki->setLvi(lvi);
|
||||
pki->updateView();
|
||||
}
|
||||
}
|
||||
unsigned char *p;
|
||||
int size;
|
||||
QString name;
|
||||
db mydb(dbName);
|
||||
|
||||
void db_base::_writePKI(pki_base *pki, bool overwrite, DbTxn *tid)
|
||||
{
|
||||
int flags = 0;
|
||||
if (!overwrite) flags = DB_NOOVERWRITE;
|
||||
QString desc = pki->getIntName();
|
||||
if (desc.isEmpty()) {
|
||||
desc="unnamed";
|
||||
}
|
||||
QString orig = desc;
|
||||
int size=0;
|
||||
char field[10];
|
||||
unsigned char *p = pki->toData(&size);
|
||||
int cnt=0;
|
||||
int x = DB_KEYEXIST;
|
||||
p = pki->toData(&size);
|
||||
|
||||
try {
|
||||
while (x == DB_KEYEXIST) {
|
||||
Dbt k((void *)desc.latin1(), desc.length() + 1);
|
||||
Dbt d((void *)p, size);
|
||||
if ((x = data->put(tid, &k, &d, flags ))!=0) {
|
||||
sprintf(field,"%02i", ++cnt);
|
||||
QString z = field;
|
||||
desc = orig + "_" + z ;
|
||||
}
|
||||
}
|
||||
pki->setIntName(desc);
|
||||
pki->updateView();
|
||||
}
|
||||
catch (DbException &err) {
|
||||
if (p)
|
||||
OPENSSL_free(p);
|
||||
throw errorEx(err.what(), "_writePKI");
|
||||
}
|
||||
if (p)
|
||||
if (p) {
|
||||
name = mydb.uniq_name(pki->getIntName(), pki->getType());
|
||||
pki->setIntName(name);
|
||||
mydb.add(p, size, pki->getVersion(), pki->getType(), name.toAscii());
|
||||
OPENSSL_free(p);
|
||||
}
|
||||
|
||||
|
||||
void db_base::_removePKI(pki_base *pki, DbTxn *tid)
|
||||
{
|
||||
QString desc = pki->getIntName();
|
||||
removeItem(desc, tid);
|
||||
}
|
||||
|
||||
void db_base::removeItem(QString key, DbTxn *tid)
|
||||
{
|
||||
Dbt k((void *)key.latin1(), key.length() + 1);
|
||||
data->del(tid, &k, 0);
|
||||
}
|
||||
|
||||
|
||||
void db_base::deletePKI(pki_base *pki)
|
||||
{
|
||||
DbTxn *tid = NULL;
|
||||
try {
|
||||
dbenv->txn_begin(NULL, &tid, 0);
|
||||
_removePKI(pki, tid);
|
||||
remFromCont(pki);
|
||||
tid->commit(0);
|
||||
delete(pki);
|
||||
}
|
||||
catch (DbException &err) {
|
||||
tid->abort();
|
||||
throw errorEx(err.what());
|
||||
inToCont(pki);
|
||||
}
|
||||
|
||||
void db_base::deletePKI(QModelIndex &index)
|
||||
{
|
||||
pki_base *pki = static_cast<pki_base*>(index.internalPointer());
|
||||
int row = pki->row();
|
||||
|
||||
printf("Deleting item: %s\n", CCHAR(pki->getIntName()));
|
||||
|
||||
beginRemoveRows(parent(index), row, row);
|
||||
|
||||
db mydb(dbName);
|
||||
mydb.find(pki->getType(), CCHAR(pki->getIntName()));
|
||||
mydb.erase();
|
||||
remFromCont(pki);
|
||||
pki->getParent()->freeChild(pki);
|
||||
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void db_base::deleteSelectedItems(QAbstractItemView* view)
|
||||
{
|
||||
printf("Delete selected items\n");
|
||||
QItemSelectionModel *selectionModel = view->selectionModel();
|
||||
QModelIndexList indexes = selectionModel->selectedIndexes();
|
||||
QModelIndex index;
|
||||
QString items;
|
||||
|
||||
foreach(index, indexes) {
|
||||
if (index.column() != 0)
|
||||
continue;
|
||||
pki_base *pki = static_cast<pki_base*>(index.internalPointer());
|
||||
items += "'" + pki->getIntName() + "' ";
|
||||
}
|
||||
|
||||
if (QMessageBox::information(mainwin, tr(XCA_TITLE),
|
||||
delete_txt + ": " + items + " ?\n" ,
|
||||
tr("Delete"), tr("Cancel"))
|
||||
) return;
|
||||
|
||||
foreach(index, indexes) {
|
||||
if (index.column() != 0)
|
||||
continue;
|
||||
deletePKI(index);
|
||||
}
|
||||
}
|
||||
|
||||
void db_base::renamePKI(pki_base *pki, QString desc)
|
||||
void db_base::showSelectedItems(QAbstractItemView* view)
|
||||
{
|
||||
QString oldname = pki->getIntName();
|
||||
DbTxn *tid = NULL;
|
||||
try {
|
||||
dbenv->txn_begin(NULL, &tid, 0);
|
||||
_removePKI(pki, tid);
|
||||
pki->setIntName(desc);
|
||||
_writePKI(pki, false, tid);
|
||||
tid->commit(0);
|
||||
}
|
||||
catch (DbException &err) {
|
||||
tid->abort();
|
||||
throw errorEx(err.what(), "rename PKI");
|
||||
QItemSelectionModel *selectionModel = view->selectionModel();
|
||||
QModelIndexList indexes = selectionModel->selectedIndexes();
|
||||
QModelIndex index;
|
||||
QString items;
|
||||
|
||||
foreach(index, indexes) {
|
||||
if (index.column() != 0)
|
||||
continue;
|
||||
showItem(index);
|
||||
}
|
||||
}
|
||||
|
||||
void db_base::remFromCont(pki_base *pki)
|
||||
void db_base::storeSelectedItems(QAbstractItemView* view)
|
||||
{
|
||||
container.remove(pki);
|
||||
QItemSelectionModel *selectionModel = view->selectionModel();
|
||||
QModelIndexList indexes = selectionModel->selectedIndexes();
|
||||
QModelIndex index;
|
||||
QString items;
|
||||
|
||||
foreach(index, indexes) {
|
||||
if (index.column() != 0)
|
||||
continue;
|
||||
try {
|
||||
store(index);
|
||||
} catch (errorEx &err) {
|
||||
MainWindow::Error(err);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void db_base::inToCont(pki_base *pki)
|
||||
{
|
||||
container.append(pki);
|
||||
}
|
||||
static int i=0;
|
||||
int row = rootItem->childCount()+1;
|
||||
|
||||
void db_base::updatePKI(pki_base *pki)
|
||||
{
|
||||
DbTxn *tid = NULL;
|
||||
dbenv->txn_begin(NULL, &tid, 0);
|
||||
try {
|
||||
_writePKI(pki, true, tid);
|
||||
tid->commit(0);
|
||||
}
|
||||
catch (DbException &err) {
|
||||
tid->abort();
|
||||
throw errorEx(err.what(), "update PKI");
|
||||
}
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
rootItem->append(pki);
|
||||
pki->setParent(rootItem);
|
||||
endInsertRows();
|
||||
printf("insertRow %d\n", ++i);
|
||||
}
|
||||
|
||||
pki_base *db_base::getByName(QString desc)
|
||||
{
|
||||
if (desc == "" ) return NULL;
|
||||
pki_base *pki;
|
||||
QListIterator<pki_base> it(container);
|
||||
for ( ; it.current(); ++it ) {
|
||||
pki = it.current();
|
||||
if (pki->getIntName() == desc) return pki;
|
||||
FOR_ALL_pki(pki, pki_base) {
|
||||
if (pki->getIntName() == desc)
|
||||
return pki;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pki_base *db_base::getByReference(pki_base *refpki)
|
||||
{
|
||||
pki_base *pki;
|
||||
if (refpki == 0) return NULL;
|
||||
QListIterator<pki_base> it(container);
|
||||
for ( ; it.current(); ++it ) {
|
||||
pki = it.current();
|
||||
if (refpki->compare(pki)) return pki;
|
||||
if (refpki == NULL)
|
||||
return NULL;
|
||||
FOR_ALL_pki(pki, pki_base) {
|
||||
if (refpki->compare(pki))
|
||||
return pki;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pki_base *db_base::getByPtr(void *item)
|
||||
{
|
||||
pki_base *pki;
|
||||
if (item == NULL) return NULL;
|
||||
QListIterator<pki_base> it(container);
|
||||
for ( ; it.current(); ++it ) {
|
||||
pki = it.current();
|
||||
if (item == pki->getLvi()) return pki;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
QStringList db_base::getDesc()
|
||||
{
|
||||
pki_base *pki;
|
||||
QStringList x;
|
||||
x.clear();
|
||||
for ( pki = container.first(); pki != 0; pki = container.next() ){
|
||||
FOR_ALL_pki(pki, pki_base) {
|
||||
x.append(pki->getIntName());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QList<pki_base> db_base::getContainer()
|
||||
{
|
||||
QList<pki_base> c;
|
||||
c.clear();
|
||||
c = container;
|
||||
return c;
|
||||
}
|
||||
|
||||
pki_base *db_base::insert(pki_base *item)
|
||||
{
|
||||
insertPKI(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
void db_base::writeAll(DbTxn *tid)
|
||||
void db_base::writeAll(void)
|
||||
{
|
||||
bool tidwasnull = false;
|
||||
if (tid == NULL) {
|
||||
tidwasnull = true;
|
||||
dbenv->txn_begin(NULL, &tid, 0);
|
||||
}
|
||||
try {
|
||||
for (pki_base *pki=container.first(); pki!=0; pki=container.next() )
|
||||
_writePKI(pki, true, tid);
|
||||
}
|
||||
catch (DbException &err) {
|
||||
tid->abort();
|
||||
throw errorEx(err.what());
|
||||
}
|
||||
if (tidwasnull)
|
||||
tid->commit(0);
|
||||
}
|
||||
|
||||
void db_base::dump(QString dirname)
|
||||
{
|
||||
pki_base *pki;
|
||||
dirname += QDir::separator() + dbName;
|
||||
QDir d(dirname);
|
||||
if ( ! d.exists() && !d.mkdir(dirname)) {
|
||||
throw errorEx("Could not create directory '" + dirname + "'");
|
||||
}
|
||||
|
||||
for ( pki = container.first(); pki != 0; pki = container.next() ){
|
||||
FOR_ALL_pki(pki, pki_base) {
|
||||
pki->writeDefault(dirname);
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex db_base::index(int row, int column, const QModelIndex &parent)
|
||||
const
|
||||
{
|
||||
pki_base *parentItem;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem;
|
||||
else
|
||||
parentItem = static_cast<pki_base*>(parent.internalPointer());
|
||||
|
||||
pki_base *childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex db_base::parent(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
pki_base *childItem = static_cast<pki_base*>(index.internalPointer());
|
||||
pki_base *parentItem = childItem->getParent();
|
||||
|
||||
if (parentItem == rootItem)
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
|
||||
int db_base::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
pki_base *parentItem;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem;
|
||||
else
|
||||
parentItem = static_cast<pki_base*>(parent.internalPointer());
|
||||
|
||||
return parentItem->childCount();
|
||||
}
|
||||
|
||||
int db_base::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
pki_base *item;
|
||||
if (parent.isValid())
|
||||
item = static_cast<pki_base*>(parent.internalPointer());
|
||||
else
|
||||
item = rootItem;
|
||||
|
||||
return item->columns();
|
||||
}
|
||||
|
||||
QVariant db_base::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
pki_base *item = static_cast<pki_base*>(index.internalPointer());
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return item->column_data(index.column());
|
||||
case Qt::DecorationRole:
|
||||
if (!index.column())
|
||||
return item->getIcon();
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant db_base::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return headertext[section];
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags db_base::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::ItemIsEnabled;
|
||||
|
||||
if (index.column() == 0)
|
||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
||||
else
|
||||
return QAbstractItemModel::flags(index);
|
||||
}
|
||||
|
||||
bool db_base::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
//const char *n=NULL, *oldn=NULL;
|
||||
QString on, nn;
|
||||
pki_base *item;
|
||||
if (index.isValid() && role == Qt::EditRole) {
|
||||
//n = value.toString().toAscii().constData();
|
||||
nn = value.toString();
|
||||
//printf("New name: '%s', %p, %p\n", n, n, oldn);
|
||||
db mydb(dbName);
|
||||
item = static_cast<pki_base*>(index.internalPointer());
|
||||
on = item->getIntName();
|
||||
//printf("New name: '%s', old name: '%s' %p %p\n", n, oldn, n, oldn);
|
||||
if (mydb.rename(item->getType(), CCHAR(on), CCHAR(nn)) == 0) {
|
||||
printf("Rename Success !\n");
|
||||
item->setIntName(nn);
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void db_base::load_default(load_base &load)
|
||||
{
|
||||
QStringList slist;
|
||||
|
||||
QFileDialog *dlg = new QFileDialog(mainwin);
|
||||
|
||||
dlg->setWindowTitle(load.caption);
|
||||
dlg->setFilters(load.filter);
|
||||
dlg->setFileMode( QFileDialog::ExistingFiles );
|
||||
dlg->setDirectory(mainwin->getPath());
|
||||
if (dlg->exec()) {
|
||||
slist = dlg->selectedFiles();
|
||||
mainwin->setPath(dlg->directory().path());
|
||||
}
|
||||
delete dlg;
|
||||
|
||||
//ImportMulti *dlgi = NULL;
|
||||
//dlgi = new ImportMulti(mainwin);
|
||||
for ( QStringList::Iterator it = slist.begin(); it != slist.end(); ++it ) {
|
||||
QString s = *it;
|
||||
s = QDir::convertSeparators(s);
|
||||
pki_base *item = NULL;
|
||||
try {
|
||||
item = load.loadItem(s);
|
||||
//dlgi->addItem(item);
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
MainWindow::Error(err);
|
||||
delete item;
|
||||
return;
|
||||
}
|
||||
insert(item);
|
||||
}
|
||||
//dlgi->execute();
|
||||
//delete dlgi;
|
||||
}
|
||||
|
||||
|
||||
@ -35,8 +35,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -51,40 +49,45 @@
|
||||
#ifndef DB_BASE_H
|
||||
#define DB_BASE_H
|
||||
|
||||
#include <db_cxx.h>
|
||||
#include "db.h"
|
||||
#include "base.h"
|
||||
#ifndef qt3
|
||||
#include <qlist.h>
|
||||
#endif
|
||||
#include <qlistview.h>
|
||||
#include <qpixmap.h>
|
||||
#include <qstringlist.h>
|
||||
#include "load_obj.h"
|
||||
#include <Qt/qlistview.h>
|
||||
#include <Qt/qpixmap.h>
|
||||
#include <Qt/qstringlist.h>
|
||||
#include <Qt/qpixmap.h>
|
||||
#include <Qt/qabstractitemmodel.h>
|
||||
#include "pki_base.h"
|
||||
|
||||
#define FOR_ALL_pki(pki, pki_type) \
|
||||
for(pki_type *pki=(pki_type*)rootItem->iterate(); pki; pki=(pki_type*)pki->iterate())
|
||||
|
||||
class XcaListView;
|
||||
class MainWindow;
|
||||
class QContextMenuEvent;
|
||||
|
||||
class db_base: public QObject
|
||||
class db_base: public QAbstractItemModel
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
Db *data;
|
||||
DbEnv *dbenv;
|
||||
XcaListView *listview;
|
||||
QString dbName;
|
||||
QList<pki_base> container;
|
||||
void _writePKI(pki_base *pki, bool overwrite, DbTxn *tid );
|
||||
void _removePKI(pki_base *pki, DbTxn *tid );
|
||||
void removeItem(QString k, DbTxn *tid);
|
||||
QString dbName, delete_txt;
|
||||
pki_base *rootItem;
|
||||
void _writePKI(pki_base *pki, bool overwrite );
|
||||
void _removePKI(pki_base *pki );
|
||||
void removeItem(QString k);
|
||||
enum pki_type pkitype;
|
||||
QList<QVariant> headertext;
|
||||
MainWindow *mainwin;
|
||||
public slots:
|
||||
virtual void store(QModelIndex &index){};
|
||||
|
||||
public:
|
||||
db_base(DbEnv *dbe, QString DBfile, QString db, DbTxn *global_tid,
|
||||
XcaListView *lvi);
|
||||
db_base(QString db, MainWindow *mw);
|
||||
virtual ~db_base();
|
||||
virtual pki_base *newPKI(){return NULL;}
|
||||
virtual pki_base *newPKI();
|
||||
virtual void insertPKI(pki_base *pki);
|
||||
virtual void deletePKI(pki_base *pki);
|
||||
virtual void updatePKI(pki_base *pki);
|
||||
virtual void renamePKI(pki_base *pki, QString desc);
|
||||
virtual void deletePKI(QModelIndex &index);
|
||||
virtual void showItem(QModelIndex &index){};
|
||||
pki_base *getByName(QString desc);
|
||||
pki_base *getByReference(pki_base *refpki);
|
||||
pki_base *getByPtr(void *);
|
||||
@ -94,22 +97,40 @@ class db_base: public QObject
|
||||
/* preprocess should be implemented once to speed up updateView()
|
||||
* i.e search for signers and keys */
|
||||
virtual void preprocess() {return;}
|
||||
virtual void remFromCont(pki_base *pki);
|
||||
virtual void inToCont(pki_base *pki);
|
||||
void remFromCont(pki_base *ref);
|
||||
|
||||
#if 0
|
||||
void *getData(void* key, int length, int *dsize);
|
||||
void *getData(QString key, int *dsize);
|
||||
QString getString(QString key);
|
||||
QString getString(char *key);
|
||||
int getInt(QString key);
|
||||
void putData(void *key, int keylen, void *dat, int datalen, DbTxn *tid = NULL);
|
||||
void putString(QString key, void *dat, int datalen, DbTxn *tid = NULL);
|
||||
void putString(QString key, QString dat, DbTxn *tid = NULL);
|
||||
void putString(char *key, QString dat, DbTxn *tid = NULL);
|
||||
void putInt(QString key, int dat, DbTxn *tid = NULL);
|
||||
void putData(void *key, int keylen, void *dat, int datalen);
|
||||
void putString(QString key, void *dat, int datalen);
|
||||
void putString(QString key, QString dat);
|
||||
void putString(char *key, QString dat);
|
||||
void putInt(QString key, int dat);
|
||||
#endif
|
||||
QPixmap *loadImg(const char *name);
|
||||
void writeAll(DbTxn *tid);
|
||||
QList<pki_base> getContainer();
|
||||
void writeAll(void);
|
||||
void dump(QString dirname);
|
||||
virtual void showContextMenu(QContextMenuEvent * e,
|
||||
const QModelIndex &index) {};
|
||||
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent)const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
int columnCount(const QModelIndex &parent) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||
void deleteSelectedItems(QAbstractItemView* view);
|
||||
void showSelectedItems(QAbstractItemView *view);
|
||||
void storeSelectedItems(QAbstractItemView *view);
|
||||
void load_default(load_base &load);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -54,10 +54,10 @@
|
||||
#include "exception.h"
|
||||
#include "widgets/MainWindow.h"
|
||||
#include "view/CertView.h"
|
||||
#include <qmessagebox.h>
|
||||
#include <Qt/qmessagebox.h>
|
||||
|
||||
db_crl::db_crl(DbEnv *dbe, QString DBfile, DbTxn *tid, XcaListView *lvi)
|
||||
:db_base(dbe, DBfile, "crldb", tid, lvi)
|
||||
db_crl::db_crl(QString DBfile)
|
||||
:db_base(DBfile)
|
||||
{
|
||||
loadContainer();
|
||||
}
|
||||
@ -69,11 +69,9 @@ pki_base *db_crl::newPKI(){
|
||||
void db_crl::preprocess()
|
||||
{
|
||||
if ( container.isEmpty() ) return ;
|
||||
QListIterator<pki_base> iter(container);
|
||||
for ( ; iter.current(); ++iter ) {
|
||||
pki_crl *crl = (pki_crl *)iter.current();
|
||||
pki_x509 *issuer = MainWindow::certs->getBySubject(crl->getIssuerName());
|
||||
crl->setIssuer(issuer);
|
||||
FOR_ALL_pki(crl, pki_crl) {
|
||||
pki_x509 *iss = MainWindow::certs->getBySubject(crl->getIssuerName());
|
||||
crl->setIssuer(iss);
|
||||
revokeCerts(crl);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +51,9 @@
|
||||
|
||||
#include "db_x509.h"
|
||||
#include "pki_crl.h"
|
||||
#include <Qt/qobject.h>
|
||||
#include <Qt/qpixmap.h>
|
||||
|
||||
|
||||
#ifndef DB_CRL_H
|
||||
#define DB_CRL_H
|
||||
@ -63,7 +66,7 @@ class db_crl: public db_base
|
||||
QPixmap *crlicon;
|
||||
db_x509 *certs;
|
||||
public:
|
||||
db_crl(DbEnv *dbe, QString DBfile, DbTxn *tid,XcaListView *lvi);
|
||||
db_crl(QString DBfile);
|
||||
pki_base *newPKI();
|
||||
void revokeCerts(pki_crl *crl);
|
||||
void preprocess();
|
||||
|
||||
165
lib/db_key.cpp
165
lib/db_key.cpp
@ -36,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -51,16 +49,24 @@
|
||||
|
||||
|
||||
#include "db_key.h"
|
||||
#include <qmessagebox.h>
|
||||
#include <Qt/qmessagebox.h>
|
||||
#include <Qt/qprogressbar.h>
|
||||
#include <Qt/qstatusbar.h>
|
||||
#include <Qt/QContextMenuEvent>
|
||||
#include "exception.h"
|
||||
#include "ui/NewKey.h"
|
||||
|
||||
#define FOR_container for (pki_key *pki = (pki_key *)container.first(); \
|
||||
pki != 0; pki = (pki_key *)container.next() )
|
||||
|
||||
#include "widgets/MainWindow.h"
|
||||
#include "widgets/ExportKey.h"
|
||||
#include "widgets/KeyDetail.h"
|
||||
|
||||
db_key::db_key(DbEnv *dbe, QString DBfile, DbTxn *tid, XcaListView *lvi)
|
||||
:db_base(dbe, DBfile, "keydb",tid, lvi)
|
||||
db_key::db_key(QString db, MainWindow *mw)
|
||||
:db_base(db, mw)
|
||||
{
|
||||
delete rootItem;
|
||||
rootItem = newPKI();
|
||||
headertext << "Name" << "Type" << "Size" << "Use counter";
|
||||
delete_txt = tr("Delete the key(s)");
|
||||
loadContainer();
|
||||
}
|
||||
|
||||
@ -73,7 +79,7 @@ QStringList db_key::getPrivateDesc()
|
||||
{
|
||||
QStringList x;
|
||||
x.clear();
|
||||
FOR_container
|
||||
FOR_ALL_pki(pki, pki_key)
|
||||
if (pki->isPrivKey())
|
||||
x.append(pki->getIntName());
|
||||
return x;
|
||||
@ -83,7 +89,7 @@ QStringList db_key::get0PrivateDesc()
|
||||
{
|
||||
QStringList x;
|
||||
x.clear();
|
||||
FOR_container
|
||||
FOR_ALL_pki(pki, pki_key)
|
||||
if (pki->isPrivKey() && pki->getUcount() == 0)
|
||||
x.append(pki->getIntNameWithType());
|
||||
return x;
|
||||
@ -121,8 +127,9 @@ pki_base* db_key::insert(pki_base *item)
|
||||
tr("The database already contains the public part of the imported key as") +":\n'" +
|
||||
oldkey->getIntName() +
|
||||
"'\n" + tr("and will be completed by the new, private part of the key"), "OK");
|
||||
deletePKI(oldkey);
|
||||
lkey->setIntName(oldkey->getIntName());
|
||||
QModelIndex idx = index(oldkey->row(), 0, QModelIndex());
|
||||
deletePKI(idx);
|
||||
}
|
||||
}
|
||||
insertPKI(lkey);
|
||||
@ -130,4 +137,138 @@ pki_base* db_key::insert(pki_base *item)
|
||||
return lkey;
|
||||
}
|
||||
|
||||
#undef FOR_container
|
||||
|
||||
void db_key::newItem()
|
||||
{
|
||||
const int sizeList[] = { 512, 1024, 2048, 4096, 0 };
|
||||
|
||||
QDialog *dlg = new QDialog(qApp->activeWindow());
|
||||
Ui::NewKey ui;
|
||||
ui.setupUi(dlg);
|
||||
QProgressBar *bar = new QProgressBar();
|
||||
QStatusBar *status = mainwin->statusBar();
|
||||
|
||||
pki_key *nkey = NULL;
|
||||
QString x;
|
||||
int keytypes[] = {EVP_PKEY_RSA, EVP_PKEY_DSA };
|
||||
ui.keyLength->setEditable(true);
|
||||
for (int i=0; sizeList[i] != 0; i++ ) {
|
||||
ui.keyLength->addItem( x.number(sizeList[i]) +" bit");
|
||||
}
|
||||
ui.keyLength->setCurrentIndex(1);
|
||||
ui.keyDesc->setFocus();
|
||||
#if 0
|
||||
ui.image->setPixmap(*MainWindow::keyImg);
|
||||
#endif
|
||||
if (dlg->exec()) {
|
||||
db mydb(dbName);
|
||||
|
||||
QString ksizes = ui.keyLength->currentText();
|
||||
ksizes.replace( QRegExp("[^0-9]"), "" );
|
||||
int ksize = ksizes.toInt();
|
||||
if (ksize < 32) throw errorEx(tr("Key size too small !"));
|
||||
if (ksize < 512 || ksize > 4096)
|
||||
if (!QMessageBox::warning(NULL, XCA_TITLE, tr("You are sure to create a key of the size: ")
|
||||
+QString::number(ksize) + " ?", tr("Cancel"), tr("Create") ))
|
||||
return;
|
||||
|
||||
nkey = new pki_key(ui.keyDesc->text());
|
||||
|
||||
QString m = status->currentMessage();
|
||||
status->clearMessage();
|
||||
status->addPermanentWidget(bar,1);
|
||||
nkey->generate(ksize, keytypes[ui.keyType->currentIndex()], bar );
|
||||
status->removeWidget(bar);
|
||||
delete bar;
|
||||
status->showMessage(m);
|
||||
insert(nkey);
|
||||
|
||||
emit keyDone(nkey);
|
||||
}
|
||||
delete dlg;
|
||||
}
|
||||
|
||||
void db_key::load(void)
|
||||
{
|
||||
load_key l;
|
||||
load_default(l);
|
||||
}
|
||||
|
||||
void db_key::showItem(QModelIndex &index)
|
||||
{
|
||||
pki_key *key = static_cast<pki_key*>(index.internalPointer());
|
||||
KeyDetail *dlg;
|
||||
|
||||
dlg = new KeyDetail(mainwin);
|
||||
if (dlg) {
|
||||
dlg->setKey(key);
|
||||
dlg->exec();
|
||||
delete dlg;
|
||||
}
|
||||
}
|
||||
|
||||
void db_key::showContextMenu(QContextMenuEvent *e, const QModelIndex &index)
|
||||
{
|
||||
QMenu *menu = new QMenu(mainwin);
|
||||
|
||||
if (index == QModelIndex()) {
|
||||
menu->addAction(tr("New Key"), this, SLOT(newItem()));
|
||||
menu->addAction(tr("Import"), this, SLOT(load()));
|
||||
}
|
||||
else {
|
||||
menu->addAction(tr("Show Details"), this, SLOT(showItem(index)));
|
||||
menu->addAction(tr("Export"), this, SLOT(store(index)));
|
||||
menu->addAction(tr("Delete"), this, SLOT(deletePKI(index)));
|
||||
menu->addAction(tr("Change password"), this, SLOT(setOwnPass(index)));
|
||||
menu->addAction(tr("Reset password"), this, SLOT(resetOwnPass()));
|
||||
}
|
||||
menu->exec(e->globalPos());
|
||||
delete menu;
|
||||
return;
|
||||
}
|
||||
|
||||
void db_key::store(QModelIndex &index)
|
||||
{
|
||||
bool PEM = false;
|
||||
const EVP_CIPHER *enc = NULL;
|
||||
|
||||
if (!index.isValid())
|
||||
return;
|
||||
|
||||
pki_key *targetKey = static_cast<pki_key*>(index.internalPointer());
|
||||
QString fn = targetKey->getIntName() + ".pem";
|
||||
|
||||
ExportKey *dlg = new ExportKey(mainwin, fn,
|
||||
targetKey->isPubKey(), mainwin->getPath() );
|
||||
//dlg->image->setPixmap(*MainWindow::keyImg);
|
||||
|
||||
if (!dlg->exec()) {
|
||||
delete dlg;
|
||||
return;
|
||||
}
|
||||
mainwin->setPath(dlg->dirPath);
|
||||
QString fname = dlg->filename->text();
|
||||
if (fname.isEmpty()) {
|
||||
delete dlg;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (dlg->exportFormat->currentText() == "PEM") PEM = true;
|
||||
if (dlg->exportFormat->currentText() == "PKCS#8")
|
||||
targetKey->writePKCS8(fname, &MainWindow::passWrite);
|
||||
else if (dlg->exportPrivate->isChecked()) {
|
||||
if (dlg->encryptKey->isChecked())
|
||||
enc = EVP_des_ede3_cbc();
|
||||
targetKey->writeKey(fname, enc, &MainWindow::passWrite, PEM);
|
||||
}
|
||||
else {
|
||||
targetKey->writePublic(fname, PEM);
|
||||
}
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
MainWindow::Error(err);
|
||||
}
|
||||
delete dlg;
|
||||
|
||||
}
|
||||
|
||||
|
||||
28
lib/db_key.h
28
lib/db_key.h
@ -35,8 +35,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -48,31 +46,43 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "db_base.h"
|
||||
#include "pki_key.h"
|
||||
#include <qstringlist.h>
|
||||
|
||||
#ifndef DB_KEY_H
|
||||
#define DB_KEY_H
|
||||
|
||||
#include "db_base.h"
|
||||
#include "pki_key.h"
|
||||
#include <Qt/qstringlist.h>
|
||||
#include <Qt/qobject.h>
|
||||
|
||||
class MainWindow;
|
||||
class QModelIndex;
|
||||
class QContextMenuEvent;
|
||||
|
||||
class db_key: public db_base
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
db_key(DbEnv *dbe, QString DBfile, DbTxn *tid, XcaListView *lvi);
|
||||
db_key(QString db, MainWindow *mw);
|
||||
pki_base *newPKI();
|
||||
QStringList getPrivateDesc();
|
||||
QStringList get0PrivateDesc();
|
||||
void inToCont(pki_base *pki);
|
||||
void remFromCont(pki_base *pki);
|
||||
pki_base* insert(pki_base *item);
|
||||
void writeAll(DbTxn *tid = NULL);
|
||||
void writeAll();
|
||||
void showItem(QModelIndex &index);
|
||||
void showContextMenu(QContextMenuEvent * e, const QModelIndex &index);
|
||||
|
||||
public slots:
|
||||
void newItem(void);
|
||||
void load(void);
|
||||
void store(QModelIndex &index);
|
||||
|
||||
signals:
|
||||
void delKey(pki_key *delkey);
|
||||
void newKey(pki_key *newkey);
|
||||
void keyDone(pki_key *newkey);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -52,8 +52,8 @@
|
||||
#include "db_temp.h"
|
||||
|
||||
|
||||
db_temp::db_temp(DbEnv *dbe, QString DBfile, DbTxn *tid, XcaListView *lvi)
|
||||
:db_base(dbe, DBfile, "tempdb", tid, lvi)
|
||||
db_temp::db_temp(QString DBfile)
|
||||
:db_base(DBfile)
|
||||
{
|
||||
loadContainer();
|
||||
}
|
||||
|
||||
@ -54,6 +54,9 @@
|
||||
|
||||
#include "db_base.h"
|
||||
#include "pki_temp.h"
|
||||
#include <Qt/qobject.h>
|
||||
#include <Qt/qpixmap.h>
|
||||
|
||||
|
||||
|
||||
class db_temp: public db_base
|
||||
@ -62,7 +65,7 @@ class db_temp: public db_base
|
||||
protected:
|
||||
QPixmap *keyicon;
|
||||
public:
|
||||
db_temp(DbEnv *dbe, QString DBfile, DbTxn *tid, XcaListView *lvi);
|
||||
db_temp(QString DBfile);
|
||||
pki_base *newPKI();
|
||||
};
|
||||
|
||||
|
||||
268
lib/db_x509.cpp
268
lib/db_x509.cpp
@ -36,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -51,15 +49,19 @@
|
||||
|
||||
|
||||
#include "db_x509.h"
|
||||
#include <qmessagebox.h>
|
||||
#include <Qt/qmessagebox.h>
|
||||
|
||||
#define FOR_ctr(container) for (pki_x509 *pki = (pki_x509 *)container.first(); \
|
||||
pki != 0; pki = (pki_x509 *)container.next() )
|
||||
|
||||
|
||||
db_x509::db_x509(DbEnv *dbe, QString DBfile, db_key *k, DbTxn *tid, XcaListView *lvi)
|
||||
:db_x509super(dbe, DBfile, "certdb", k, tid, lvi)
|
||||
db_x509::db_x509(QString DBfile, MainWindow *mw)
|
||||
:db_x509super(DBfile, mw)
|
||||
{
|
||||
|
||||
delete rootItem;
|
||||
rootItem = newPKI();
|
||||
headertext << tr("Internal name") << tr("Common name") << tr("Serial") <<
|
||||
tr("not After") << tr("Trust state") << tr("Revocation");
|
||||
|
||||
delete_txt = tr("Delete the certificates(s)");
|
||||
loadContainer();
|
||||
// FIXME:
|
||||
// connect(keyl, SIGNAL(delKey(pki_key *)), this, SLOT(delKey(pki_key *)));
|
||||
@ -78,7 +80,7 @@ pki_x509 *db_x509::findSigner(pki_x509 *client)
|
||||
if (client->verify(client)) {
|
||||
return client;
|
||||
}
|
||||
FOR_ctr(container)
|
||||
FOR_ALL_pki(pki, pki_x509)
|
||||
if (client->verify(pki))
|
||||
return pki;
|
||||
return NULL;
|
||||
@ -87,7 +89,7 @@ pki_x509 *db_x509::findSigner(pki_x509 *client)
|
||||
QStringList db_x509::getPrivateDesc()
|
||||
{
|
||||
QStringList x;
|
||||
FOR_ctr(container)
|
||||
FOR_ALL_pki(pki, pki_x509)
|
||||
if (pki->getRefKey())
|
||||
x.append(pki->getIntName());
|
||||
return x;
|
||||
@ -96,7 +98,7 @@ QStringList db_x509::getPrivateDesc()
|
||||
QStringList db_x509::getSignerDesc()
|
||||
{
|
||||
QStringList x;
|
||||
FOR_ctr(container)
|
||||
FOR_ALL_pki(pki, pki_x509)
|
||||
if (pki->canSign())
|
||||
x.append(pki->getIntName());
|
||||
return x;
|
||||
@ -105,16 +107,15 @@ QStringList db_x509::getSignerDesc()
|
||||
|
||||
void db_x509::remFromCont(pki_base *ref)
|
||||
{
|
||||
container.remove(ref);
|
||||
FOR_ctr(container)
|
||||
db_base::remFromCont(ref);
|
||||
FOR_ALL_pki(pki, pki_x509)
|
||||
pki->delSigner((pki_x509 *)ref);
|
||||
return;
|
||||
}
|
||||
|
||||
void db_x509::preprocess()
|
||||
{
|
||||
QList<pki_base> conta = container;
|
||||
FOR_ctr(conta) {
|
||||
FOR_ALL_pki(pki, pki_x509) {
|
||||
findSigner(pki);
|
||||
findKey(pki);
|
||||
}
|
||||
@ -125,7 +126,7 @@ void db_x509::preprocess()
|
||||
|
||||
void db_x509::calcEffTrust()
|
||||
{
|
||||
FOR_ctr(container)
|
||||
FOR_ALL_pki(pki, pki_x509)
|
||||
pki->calcEffTrust();
|
||||
}
|
||||
|
||||
@ -136,18 +137,18 @@ void db_x509::insertPKI(pki_base *refpki)
|
||||
pki_x509 *x = (pki_x509 *)refpki;
|
||||
findSigner(x);
|
||||
findKey(x);
|
||||
FOR_ctr(container)
|
||||
FOR_ALL_pki(pki, pki_x509)
|
||||
pki->verify(x);
|
||||
calcEffTrust();
|
||||
}
|
||||
|
||||
|
||||
QList<pki_x509> db_x509::getIssuedCerts(const pki_x509 *issuer)
|
||||
QList<pki_x509*> db_x509::getIssuedCerts(const pki_x509 *issuer)
|
||||
{
|
||||
QList<pki_x509> c;
|
||||
QList<pki_x509*> c;
|
||||
c.clear();
|
||||
if (!issuer) return c;
|
||||
FOR_ctr(container)
|
||||
FOR_ALL_pki(pki, pki_x509)
|
||||
if (pki->getSigner() == issuer)
|
||||
c.append(pki);
|
||||
return c;
|
||||
@ -158,7 +159,7 @@ pki_x509 *db_x509::getBySubject(const x509name &xname, pki_x509 *last)
|
||||
bool lastfound = false;
|
||||
if (last == NULL) lastfound = true;
|
||||
|
||||
FOR_ctr(container) {
|
||||
FOR_ALL_pki(pki, pki_x509) {
|
||||
if ( pki->getSubject() == xname) {
|
||||
if (lastfound) {
|
||||
return pki;
|
||||
@ -181,7 +182,7 @@ void db_x509::revokeCert(const x509rev &revok, const pki_x509 *iss)
|
||||
pki_x509 *db_x509::getByIssSerial(const pki_x509 *issuer, const a1int &a)
|
||||
{
|
||||
if (!issuer ) return NULL;
|
||||
FOR_ctr(container) {
|
||||
FOR_ALL_pki(pki, pki_x509) {
|
||||
if ((pki->getSigner() == issuer) && (a == pki->getSerial()))
|
||||
return pki;
|
||||
}
|
||||
@ -190,17 +191,17 @@ pki_x509 *db_x509::getByIssSerial(const pki_x509 *issuer, const a1int &a)
|
||||
|
||||
void db_x509::writeAllCerts(const QString fname, bool onlyTrusted)
|
||||
{
|
||||
FOR_ctr(container) {
|
||||
FOR_ALL_pki(pki, pki_x509) {
|
||||
if (onlyTrusted && pki->getTrust() != 2) continue;
|
||||
pki->writeCert(fname.latin1(),true,true);
|
||||
pki->writeCert(fname.toAscii(),true,true);
|
||||
}
|
||||
}
|
||||
|
||||
QList<pki_x509> db_x509::getCerts(bool onlyTrusted)
|
||||
QList<pki_x509*> db_x509::getCerts(bool onlyTrusted)
|
||||
{
|
||||
QList<pki_x509> c;
|
||||
QList<pki_x509*> c;
|
||||
c.clear();
|
||||
FOR_ctr(container) {
|
||||
FOR_ALL_pki(pki, pki_x509) {
|
||||
if (onlyTrusted && pki->getTrust() != 2) continue;
|
||||
c.append(pki);
|
||||
}
|
||||
@ -214,7 +215,7 @@ a1int db_x509::searchSerial(pki_x509 *signer)
|
||||
a1int sserial, myserial;
|
||||
if (!signer) return sserial;
|
||||
sserial = signer->getCaSerial();
|
||||
FOR_ctr(container)
|
||||
FOR_ALL_pki(pki, pki_x509)
|
||||
if (pki->getSigner() == signer) {
|
||||
myserial = pki->getSerial();
|
||||
if (sserial < myserial ) {
|
||||
@ -229,7 +230,7 @@ pki_base *db_x509::insert(pki_base *item)
|
||||
pki_x509 *cert = (pki_x509 *)item;
|
||||
pki_x509 *oldcert = (pki_x509 *)getByReference(cert);
|
||||
if (oldcert) {
|
||||
QMessageBox::information(NULL, XCA_TITLE,
|
||||
QMessageBox::information(mainwin, XCA_TITLE,
|
||||
tr("The certificate already exists in the database as") +":\n'" +
|
||||
oldcert->getIntName() +
|
||||
"'\n" + tr("and so it was not imported"), "OK");
|
||||
@ -245,7 +246,7 @@ pki_base *db_x509::insert(pki_base *item)
|
||||
serial = cert->getSerial();
|
||||
if (cert->getSigner()->getCaSerial() < ++serial ) {
|
||||
cert->getSigner()->setCaSerial(serial);
|
||||
updatePKI(cert->getSigner());
|
||||
//updatePKI(cert->getSigner());
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,8 +255,213 @@ pki_base *db_x509::insert(pki_base *item)
|
||||
if ( ++serial > cert->getCaSerial()) {
|
||||
cert->setCaSerial(serial);
|
||||
}
|
||||
updatePKI(cert);
|
||||
//updatePKI(cert);
|
||||
return cert;
|
||||
}
|
||||
|
||||
void db_x509::load(void)
|
||||
{
|
||||
load_cert c;
|
||||
load_default(c);
|
||||
}
|
||||
|
||||
void db_x509::newItem()
|
||||
{
|
||||
NewX509 *dlg = new NewX509(mainwin);
|
||||
//emit connNewX509(dlg);
|
||||
dlg->setCert();
|
||||
//dlg->defineSigner((pki_x509*)getSelected());
|
||||
if (dlg->exec()) {
|
||||
newCert(dlg);
|
||||
}
|
||||
delete dlg;
|
||||
}
|
||||
#if 0
|
||||
void db_x509::newCert(pki_x509req *req)
|
||||
{
|
||||
NewX509 *dlg = new NewX509(this, NULL, true);
|
||||
emit connNewX509(dlg);
|
||||
dlg->setCert();
|
||||
dlg->defineRequest(req);
|
||||
dlg->defineSigner((pki_x509*)getSelected());
|
||||
if (dlg->exec()) {
|
||||
newCert(dlg);
|
||||
}
|
||||
delete dlg;
|
||||
}
|
||||
|
||||
void db_x509::newCert(pki_temp *req)
|
||||
{
|
||||
NewX509 *dlg = new NewX509(this, NULL, true);
|
||||
emit connNewX509(dlg);
|
||||
dlg->setCert();
|
||||
dlg->defineTemplate(req);
|
||||
if (dlg->exec()) {
|
||||
newCert(dlg);
|
||||
}
|
||||
delete dlg;
|
||||
}
|
||||
#endif
|
||||
|
||||
void db_x509::newCert(NewX509 *dlg)
|
||||
{
|
||||
pki_x509 *cert = NULL;
|
||||
pki_x509 *signcert = NULL;
|
||||
pki_x509req *req = NULL;
|
||||
pki_key *signkey = NULL, *clientkey = NULL, *tempkey = NULL;
|
||||
a1int serial;
|
||||
a1time notBefore, notAfter;
|
||||
x509name subject;
|
||||
QString intname;
|
||||
|
||||
try {
|
||||
|
||||
// Step 1 - Subject and key
|
||||
if (!dlg->fromReqCB->isChecked()) {
|
||||
clientkey = dlg->getSelectedKey();
|
||||
subject = dlg->getX509name();
|
||||
intname = dlg->description->text();
|
||||
}
|
||||
else {
|
||||
// A PKCS#10 Request was selected
|
||||
req = dlg->getSelectedReq();
|
||||
if (!req)
|
||||
return;
|
||||
clientkey = req->getRefKey();
|
||||
if (clientkey == NULL) {
|
||||
clientkey = req->getPubKey();
|
||||
tempkey = clientkey;
|
||||
}
|
||||
subject = req->getSubject();
|
||||
intname = req->getIntName();
|
||||
}
|
||||
|
||||
// initially create cert
|
||||
cert = new pki_x509();
|
||||
cert->setIntName(intname);
|
||||
cert->setSubject(subject);
|
||||
cert->setPubKey(clientkey);
|
||||
|
||||
// Step 2 - select Signing
|
||||
if (dlg->foreignSignRB->isChecked()) {
|
||||
signcert = dlg->getSelectedSigner();
|
||||
if (!signcert)
|
||||
return;
|
||||
serial = signcert->getIncCaSerial();
|
||||
signkey = signcert->getRefKey();
|
||||
cert->setTrust(1);
|
||||
}
|
||||
#if 0
|
||||
else if (dlg->selfQASignRB->isChecked()){
|
||||
|
||||
PassWrite_UI *dlg1 = new PassWrite_UI(NULL, 0, true);
|
||||
dlg1->image->setPixmap( *MainWindow::keyImg );
|
||||
dlg1->title->setText(XCA_TITLE);
|
||||
dlg1->description->setText(tr("Please enter the new hexadecimal secret number for the QA process."));
|
||||
dlg1->passA->setFocus();
|
||||
dlg1->passA->setValidator(new QRegExpValidator(QRegExp("[0-9a-fA-F]*"),dlg1->passA));
|
||||
dlg1->passB->setValidator(new QRegExpValidator(QRegExp("[0-9a-fA-F]*"),dlg1->passB));
|
||||
dlg1->setCaption(XCA_TITLE);
|
||||
QString A = "x", B="";
|
||||
|
||||
while (dlg1->exec())
|
||||
{
|
||||
A = dlg1->passA->text();
|
||||
B = dlg1->passB->text();
|
||||
if (A==B) break;
|
||||
else
|
||||
QMessageBox::warning(mainwin, XCA_TITLE, tr("The two secret numbers don't match."));
|
||||
}
|
||||
delete dlg1;
|
||||
if (A!=B)
|
||||
throw errorEx(tr("The QA process has been terminated by the user."));
|
||||
signcert = cert;
|
||||
signkey = clientkey;
|
||||
serial.setHex(A);
|
||||
cert->setTrust(2);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
signcert = cert;
|
||||
signkey = clientkey;
|
||||
serial.setHex(dlg->serialNr->text());
|
||||
cert->setTrust(2);
|
||||
}
|
||||
|
||||
dlg->initCtx(cert, signcert);
|
||||
// if we can not sign
|
||||
if (! signkey || signkey->isPubKey()) {
|
||||
throw errorEx(tr("The key you selected for signing is not a private one."));
|
||||
}
|
||||
|
||||
// set the issuers name
|
||||
cert->setIssuer(signcert->getSubject());
|
||||
cert->setSerial(serial);
|
||||
|
||||
// Step 3 - Choose the Date
|
||||
// Date handling
|
||||
cert->setNotBefore( dlg->notBefore->getDate() );
|
||||
cert->setNotAfter( dlg->notAfter->getDate() );
|
||||
|
||||
if (cert->resetTimes(signcert) > 0) {
|
||||
if (QMessageBox::information(mainwin,tr(XCA_TITLE),
|
||||
tr("The validity times for the certificate need to get adjusted to not exceed those of the signer"),
|
||||
tr("Continue creation"), tr("Abort")
|
||||
))
|
||||
throw errorEx("");
|
||||
}
|
||||
|
||||
|
||||
// STEP 4 handle extensions
|
||||
if (dlg->copyReqExtCB->isChecked() && dlg->fromReqCB->isChecked()) {
|
||||
extList el = req->getV3Ext();
|
||||
int m = el.count();
|
||||
for (int i=0; i<m; i++)
|
||||
cert->addV3ext(el[i]);
|
||||
}
|
||||
|
||||
cert->addV3ext(dlg->getBasicConstraints());
|
||||
cert->addV3ext(dlg->getSubKeyIdent());
|
||||
cert->addV3ext(dlg->getAuthKeyIdent());
|
||||
cert->addV3ext(dlg->getKeyUsage());
|
||||
cert->addV3ext(dlg->getEkeyUsage());
|
||||
cert->addV3ext(dlg->getSubAltName());
|
||||
cert->addV3ext(dlg->getIssAltName());
|
||||
cert->addV3ext(dlg->getCrlDist());
|
||||
cert->addV3ext(dlg->getAuthInfAcc());
|
||||
cert->addV3ext(dlg->getCertPol());
|
||||
extList ne = dlg->getNetscapeExt();
|
||||
int m = ne.count();
|
||||
for (int i=0; i<m; i++)
|
||||
cert->addV3ext(ne[i]);
|
||||
|
||||
const EVP_MD *hashAlgo = dlg->getHashAlgo();
|
||||
if (signkey->getType() == EVP_PKEY_DSA)
|
||||
hashAlgo = EVP_dss1();
|
||||
#if 0
|
||||
if (dlg->selfQASignRB->isChecked())
|
||||
{
|
||||
// sign the request intermediately in order to finally fill
|
||||
// up the cert_info substructure.
|
||||
cert->sign(signkey, hashAlgo);
|
||||
// now set the QA serial.
|
||||
cert->setSerial(cert->hashInfo(EVP_md5()));
|
||||
}
|
||||
#endif
|
||||
// and finally sign the request
|
||||
cert->sign(signkey, hashAlgo);
|
||||
insert(cert);
|
||||
//updatePKI(signcert);
|
||||
if (tempkey != NULL)
|
||||
delete(tempkey);
|
||||
}
|
||||
|
||||
catch (errorEx &err) {
|
||||
MainWindow::Error(err);
|
||||
delete cert;
|
||||
if (tempkey != NULL) delete(tempkey);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#undef FOR_ctr
|
||||
|
||||
@ -52,8 +52,9 @@
|
||||
#ifndef DB_X509_H
|
||||
#define DB_X509_H
|
||||
|
||||
#include <qlistview.h>
|
||||
#include <qpixmap.h>
|
||||
#include <Qt/qlistview.h>
|
||||
#include <Qt/qobject.h>
|
||||
#include <Qt/qpixmap.h>
|
||||
#include "db_key.h"
|
||||
#include "db_x509super.h"
|
||||
#include "pki_x509.h"
|
||||
@ -66,7 +67,7 @@ class db_x509: public db_x509super
|
||||
protected:
|
||||
QPixmap *certicon[4];
|
||||
public:
|
||||
db_x509(DbEnv *dbe, QString DBfile, db_key *k, DbTxn *tid, XcaListView *lvi);
|
||||
db_x509(QString DBfile, MainWindow *mw);
|
||||
pki_base *newPKI();
|
||||
pki_x509 *findSigner(pki_x509 *client);
|
||||
bool updateView();
|
||||
@ -78,15 +79,19 @@ class db_x509: public db_x509super
|
||||
QStringList getPrivateDesc();
|
||||
QStringList getSignerDesc();
|
||||
void calcEffTrust();
|
||||
QList<pki_x509> getIssuedCerts(const pki_x509 *issuer);
|
||||
QList<pki_x509> getCerts(bool onlyTrusted);
|
||||
QList<pki_x509*> getIssuedCerts(const pki_x509 *issuer);
|
||||
QList<pki_x509*> getCerts(bool onlyTrusted);
|
||||
a1int searchSerial(pki_x509 *signer);
|
||||
void writeAllCerts(const QString fname, bool onlyTrusted);
|
||||
pki_x509 *getByIssSerial(const pki_x509 *issuer, const a1int &a);
|
||||
pki_x509 *getBySubject(const x509name &xname, pki_x509 *last = NULL);
|
||||
pki_base *db_x509::insert(pki_base *item);
|
||||
pki_base *insert(pki_base *item);
|
||||
void newCert(NewX509 *dlg);
|
||||
|
||||
public slots:
|
||||
void revokeCert(const x509rev &revok, const pki_x509 *issuer);
|
||||
void load(void);
|
||||
void newItem();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -52,12 +50,17 @@
|
||||
|
||||
#include "db_x509req.h"
|
||||
#include "pki_x509req.h"
|
||||
#include <qmessagebox.h>
|
||||
#include "widgets/ReqDetail.h"
|
||||
#include <Qt/qmessagebox.h>
|
||||
|
||||
|
||||
db_x509req::db_x509req(DbEnv *dbe, QString DBfile, db_key *k, DbTxn *tid, XcaListView *lvi)
|
||||
:db_x509super(dbe, DBfile, "reqdb", k, tid, lvi)
|
||||
db_x509req::db_x509req(QString DBfile, MainWindow *mw)
|
||||
:db_x509super(DBfile, mw)
|
||||
{
|
||||
delete rootItem;
|
||||
rootItem = newPKI();
|
||||
headertext << "Name" << "Subject" << "Serial" ;
|
||||
delete_txt = tr("Delete the request(s)");
|
||||
loadContainer();
|
||||
}
|
||||
|
||||
@ -82,3 +85,65 @@ pki_base *db_x509req::insert(pki_base *item)
|
||||
insertPKI(req);
|
||||
return req;
|
||||
}
|
||||
|
||||
void db_x509req::newItem()
|
||||
{
|
||||
pki_x509req *req;
|
||||
NewX509 *dlg = new NewX509(mainwin);
|
||||
//emit connNewX509(dlg);
|
||||
|
||||
// if (temp) {
|
||||
// dlg->defineTemplate(temp);
|
||||
// }
|
||||
dlg->setRequest();
|
||||
if (! dlg->exec()){
|
||||
delete dlg;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const EVP_MD *hashAlgo = dlg->getHashAlgo();
|
||||
pki_key *key = dlg->getSelectedKey();
|
||||
x509name xn = dlg->getX509name();
|
||||
req = new pki_x509req();
|
||||
|
||||
req->setIntName(dlg->description->text());
|
||||
if (key->getType() == EVP_PKEY_DSA)
|
||||
hashAlgo = EVP_dss1();
|
||||
|
||||
req->createReq(key, xn, hashAlgo, dlg->getAllExt());
|
||||
insert(req);
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
MainWindow::Error(err);
|
||||
delete req;
|
||||
}
|
||||
}
|
||||
|
||||
void db_x509req::load(void)
|
||||
{
|
||||
load_req l;
|
||||
load_default(l);
|
||||
}
|
||||
|
||||
void db_x509req::showItem(QModelIndex &index)
|
||||
{
|
||||
pki_x509req *req = static_cast<pki_x509req*>(index.internalPointer());
|
||||
ReqDetail *dlg;
|
||||
|
||||
dlg = new ReqDetail(mainwin);
|
||||
if (dlg) {
|
||||
dlg->setReq(req);
|
||||
dlg->exec();
|
||||
delete dlg;
|
||||
}
|
||||
}
|
||||
|
||||
void db_x509req::store(QModelIndex &index)
|
||||
{
|
||||
if (!index.isValid())
|
||||
return;
|
||||
|
||||
pki_x509req *req = static_cast<pki_x509req*>(index.internalPointer());
|
||||
|
||||
req->writeReq(req->getIntName(), true);
|
||||
}
|
||||
|
||||
@ -35,8 +35,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -51,6 +49,7 @@
|
||||
|
||||
#include "db_key.h"
|
||||
#include "db_x509super.h"
|
||||
#include "widgets/MainWindow.h"
|
||||
|
||||
#ifndef DB_X509REQ_H
|
||||
#define DB_X509REQ_H
|
||||
@ -60,9 +59,13 @@ class db_x509req: public db_x509super
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
db_x509req(DbEnv *dbe, QString DBfile, db_key *k, DbTxn *tid, XcaListView *lvi);
|
||||
db_x509req(QString DBfile, MainWindow *mw);
|
||||
pki_base* insert(pki_base *item);
|
||||
pki_base *newPKI();
|
||||
void load(void);
|
||||
void newItem(void);
|
||||
void showItem(QModelIndex &index);
|
||||
void store(QModelIndex &index);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -35,8 +35,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -48,55 +46,48 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "db_x509super.h"
|
||||
|
||||
#define FOR_container for (pki_x509super *pki = (pki_x509super *)container.first(); \
|
||||
pki != 0; pki = (pki_x509super *)container.next() )
|
||||
|
||||
db_x509super::db_x509super(DbEnv *dbe, QString DBfile, QString db, db_key *k, DbTxn *tid,
|
||||
XcaListView *lvi)
|
||||
:db_base(dbe, DBfile, db, tid, lvi)
|
||||
db_x509super::db_x509super(QString db, MainWindow *mw)
|
||||
:db_base(db, mw)
|
||||
{
|
||||
keylist = k;
|
||||
}
|
||||
|
||||
void db_x509super::setKeyDb(db_key *kd)
|
||||
{
|
||||
keylist = kd;
|
||||
}
|
||||
|
||||
void db_x509super::delKey(pki_key *delkey)
|
||||
{
|
||||
FOR_container { pki->delRefKey(delkey); }
|
||||
FOR_ALL_pki(pki, pki_x509super) { pki->delRefKey(delkey); }
|
||||
}
|
||||
|
||||
void db_x509super::newKey(pki_key *newkey)
|
||||
{
|
||||
FOR_container { pki->setRefKey(newkey); }
|
||||
FOR_ALL_pki(pki,pki_x509super) { pki->setRefKey(newkey); }
|
||||
}
|
||||
|
||||
void db_x509super::preprocess()
|
||||
{
|
||||
FOR_container { findKey(pki); }
|
||||
FOR_ALL_pki(pki,pki_x509super) { findKey(pki); }
|
||||
}
|
||||
|
||||
pki_key *db_x509super::findKey(pki_x509super *ref)
|
||||
{
|
||||
pki_key *key, *refkey;
|
||||
if (!ref) return NULL;
|
||||
if ((key = ref->getRefKey()) != NULL ) return key;
|
||||
if (!ref)
|
||||
return NULL;
|
||||
if ((key = ref->getRefKey()) != NULL )
|
||||
return key;
|
||||
refkey = ref->getPubKey();
|
||||
if (!refkey) return NULL;
|
||||
if (!refkey)
|
||||
return NULL;
|
||||
|
||||
key = (pki_key *)keylist->getByReference(refkey);
|
||||
key = (pki_key *)mainwin->keys->getByReference(refkey);
|
||||
if (key && key->isPubKey()) {
|
||||
key = NULL;
|
||||
}
|
||||
else {
|
||||
ref->setRefKey(key);
|
||||
}
|
||||
if (refkey) delete(refkey);
|
||||
if (refkey)
|
||||
delete(refkey);
|
||||
return key;
|
||||
}
|
||||
|
||||
@ -106,4 +97,3 @@ void db_x509super::inToCont(pki_base *pki)
|
||||
findKey((pki_x509super *)pki);
|
||||
}
|
||||
|
||||
#undef FOR_container
|
||||
|
||||
@ -35,8 +35,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -51,6 +49,7 @@
|
||||
|
||||
#include "db_key.h"
|
||||
#include "pki_x509super.h"
|
||||
#include "widgets/MainWindow.h"
|
||||
|
||||
#ifndef DB_X509SUPER_H
|
||||
#define DB_X509SUPER_H
|
||||
@ -59,13 +58,11 @@
|
||||
class db_x509super: public db_base
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
db_key *keylist;
|
||||
|
||||
public:
|
||||
db_x509super(DbEnv *dbe, QString DBfile, QString db, db_key *k, DbTxn *tid, XcaListView *lvi);
|
||||
db_x509super(QString db, MainWindow *mw);
|
||||
void preprocess();
|
||||
pki_key *findKey(pki_x509super *ref);
|
||||
void setKeyDb(db_key *kd);
|
||||
void inToCont(pki_base *pki);
|
||||
|
||||
public slots:
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
#ifndef PKI_EXCEPTION_H
|
||||
#define PKI_EXCEPTION_H
|
||||
|
||||
#include <qstring.h>
|
||||
#include <Qt/qstring.h>
|
||||
#include "base.h"
|
||||
|
||||
class errorEx
|
||||
@ -66,7 +66,7 @@ class errorEx
|
||||
}
|
||||
errorEx(const errorEx &e) { msg = e.msg; }
|
||||
QString getString() const {return msg;}
|
||||
const char *getCString() const {return msg.latin1();}
|
||||
const char *getCString() const {return msg.toAscii();}
|
||||
bool isEmpty() const { return msg.isEmpty();}
|
||||
};
|
||||
|
||||
|
||||
23
lib/func.cpp
23
lib/func.cpp
@ -52,13 +52,13 @@
|
||||
|
||||
#include "func.h"
|
||||
#include "lib/asn1time.h"
|
||||
#include "widgets/validity.h"
|
||||
#include <qdir.h>
|
||||
#include <qlabel.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qapplication.h>
|
||||
//#include "widgets/validity.h"
|
||||
#include <Qt/qdir.h>
|
||||
#include <Qt/qlabel.h>
|
||||
#include <Qt/qlineedit.h>
|
||||
#include <Qt/qcombobox.h>
|
||||
#include <Qt/qmessagebox.h>
|
||||
#include <Qt/qapplication.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
@ -69,6 +69,7 @@ QPixmap *loadImg(const char *name )
|
||||
{
|
||||
QString path = getPrefix();
|
||||
path += QDir::separator();
|
||||
printf("Load image: '%s'\n", CCHAR(path + name));
|
||||
return new QPixmap(path + name);
|
||||
}
|
||||
|
||||
@ -239,14 +240,14 @@ QString getBaseDir()
|
||||
#ifdef BASEDIR
|
||||
baseDir = BASEDIR;
|
||||
#else
|
||||
baseDir = QDir::homeDirPath();
|
||||
baseDir = QDir::homePath();
|
||||
baseDir += QDir::separator();
|
||||
baseDir += "xca";
|
||||
baseDir += ".xca";
|
||||
#endif
|
||||
#endif
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void applyTD(int number, int range, bool mnc, Validity *nb, Validity *na)
|
||||
{
|
||||
#define d_fac (60 * 60 * 24)
|
||||
@ -272,3 +273,5 @@ void applyTD(int number, int range, bool mnc, Validity *nb, Validity *na)
|
||||
nb->setDate(a.now(), midnight);
|
||||
na->setDate(a.now(delta * d_fac), midnight* (-1));
|
||||
}
|
||||
#endif
|
||||
#warning set Date Time midnight
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
#ifndef FUNC_H
|
||||
#define FUNC_H
|
||||
|
||||
#include <qpixmap.h>
|
||||
#include <Qt/qpixmap.h>
|
||||
#include "base.h"
|
||||
|
||||
class Validity;
|
||||
|
||||
@ -36,12 +36,9 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
*
|
||||
* http://www.hohnstaedt.de/xca
|
||||
* email: christian@hohnstaedt.de
|
||||
*
|
||||
@ -86,13 +83,7 @@ load_key::load_key()
|
||||
pki_base * load_key::loadItem(QString s)
|
||||
{
|
||||
pki_key *lkey = new pki_key();
|
||||
try {
|
||||
lkey->fload(s);
|
||||
}
|
||||
catch (errorEx &err){
|
||||
delete lkey;
|
||||
throw err;
|
||||
}
|
||||
lkey->fload(s);
|
||||
return lkey;
|
||||
};
|
||||
|
||||
@ -139,6 +130,7 @@ pki_base * load_cert::loadItem(QString s)
|
||||
return crt;
|
||||
};
|
||||
|
||||
#if 0
|
||||
/* PKCS#7 Certificates */
|
||||
load_pkcs7::load_pkcs7()
|
||||
:load_base()
|
||||
@ -223,4 +215,4 @@ load_db::load_db()
|
||||
filter.prepend(QObject::tr("XCA Databases ( *.db )"));
|
||||
caption = QObject::tr("Open XCA Database");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -36,12 +36,9 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
*
|
||||
* http://www.hohnstaedt.de/xca
|
||||
* email: christian@hohnstaedt.de
|
||||
*
|
||||
@ -53,7 +50,7 @@
|
||||
#ifndef LOAD_OBJ_H
|
||||
#define LOAD_OBJ_H
|
||||
|
||||
#include <qstringlist.h>
|
||||
#include <Qt/qstringlist.h>
|
||||
|
||||
class pki_base;
|
||||
|
||||
|
||||
17
lib/main.cpp
17
lib/main.cpp
@ -49,10 +49,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qtranslator.h>
|
||||
#include <qtextcodec.h>
|
||||
#include <qdir.h>
|
||||
#include <Qt/qapplication.h>
|
||||
#include <Qt/qtranslator.h>
|
||||
#include <Qt/qtextcodec.h>
|
||||
#include <Qt/qdir.h>
|
||||
#include <Qt/qtranslator.h>
|
||||
#include "widgets/MainWindow.h"
|
||||
#include "lib/func.h"
|
||||
#ifdef WIN32
|
||||
@ -80,7 +81,8 @@ int main( int argc, char *argv[] )
|
||||
default: locale="c";
|
||||
}
|
||||
#else
|
||||
locale = QTextCodec::locale();
|
||||
locale = "C"; //QTextCodec::locale();
|
||||
#warning Fix locale
|
||||
#endif
|
||||
qtTr.load( QString( "qt_" ) + locale, "." );
|
||||
xcaTr.load( QString( "xca_" ) + locale, getPrefix() );
|
||||
@ -88,10 +90,9 @@ int main( int argc, char *argv[] )
|
||||
a.installTranslator( &qtTr );
|
||||
a.installTranslator( &xcaTr );
|
||||
fprintf(stderr, "Locale: %s\nPrefix:%s\n",
|
||||
locale.latin1(), getPrefix().latin1());
|
||||
locale.data(), getPrefix().data());
|
||||
|
||||
mw = new MainWindow( NULL, "Main Widget");
|
||||
a.setMainWidget( mw );
|
||||
mw = new MainWindow( NULL);
|
||||
if (mw->exitApp == 0) {
|
||||
mw->show();
|
||||
ret = a.exec();
|
||||
|
||||
30
lib/oid.cpp
30
lib/oid.cpp
@ -52,9 +52,9 @@
|
||||
/* here we have the possibility to add our own OIDS */
|
||||
|
||||
#include <openssl/objects.h>
|
||||
#include <qstringlist.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qdir.h>
|
||||
#include <Qt/qstringlist.h>
|
||||
#include <Qt/qmessagebox.h>
|
||||
#include <Qt/qdir.h>
|
||||
#include "func.h"
|
||||
#include "oid.h"
|
||||
|
||||
@ -62,29 +62,29 @@
|
||||
static void readOIDs(QString fname)
|
||||
{
|
||||
char buff[128];
|
||||
char *pb;
|
||||
QString pb;
|
||||
FILE *fp;
|
||||
int line = 0;
|
||||
QStringList sl;
|
||||
//fprintf(stderr, "FILE: %s\n", fname.latin1());
|
||||
fp = fopen(fname.latin1(), "r");
|
||||
//fprintf(stderr, "FILE: %s\n", fname.toAscii());
|
||||
fp = fopen(fname.toAscii(), "r");
|
||||
if (fp == NULL) return;
|
||||
while (fgets(buff, 127, fp)) {
|
||||
line++;
|
||||
pb = buff;
|
||||
while (*pb==' ' || *pb=='\t' ) pb++;
|
||||
if (*pb == '#' || *pb=='\n' || *pb=='\0') continue;
|
||||
pb = pb.trimmed();
|
||||
if (pb.startsWith('#') || pb.size() == 0) continue;
|
||||
sl.clear();
|
||||
sl = sl.split(':', QString(pb));
|
||||
sl = pb.split(':');
|
||||
if (sl.count() != 3) {
|
||||
QMessageBox::warning(NULL, QString(XCA_TITLE),
|
||||
QString("Error reading config file: ") + fname + " Line: " + QString::number(line) );
|
||||
return;
|
||||
}
|
||||
else {
|
||||
OBJ_create((char *)sl[0].stripWhiteSpace().latin1(),
|
||||
(char *)sl[1].stripWhiteSpace().latin1(),
|
||||
(char *)sl[2].stripWhiteSpace().latin1());
|
||||
OBJ_create(sl[0].trimmed().toAscii(),
|
||||
sl[1].trimmed().toAscii(),
|
||||
sl[2].trimmed().toAscii());
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
@ -92,7 +92,7 @@ static void readOIDs(QString fname)
|
||||
|
||||
void initOIDs(QString baseDir)
|
||||
{
|
||||
QString oids = (QChar)QDir::separator();
|
||||
QString oids = QString(QDir::separator());
|
||||
oids += "oids.txt";
|
||||
QString dir = getPrefix();
|
||||
|
||||
@ -118,8 +118,7 @@ NIDlist readNIDlist(QString fname)
|
||||
int line = 0, nid;
|
||||
NIDlist nl;
|
||||
nl.clear();
|
||||
//fprintf(stderr, "OID FILE: %s\n", fname.latin1());
|
||||
fp = fopen(fname.latin1(), "r");
|
||||
fp = fopen(CCHAR(fname), "r");
|
||||
if (fp == NULL) return nl;
|
||||
while (fgets(buff, 127, fp)) {
|
||||
line++;
|
||||
@ -129,6 +128,7 @@ NIDlist readNIDlist(QString fname)
|
||||
pbe = buff + strlen(buff) -1;
|
||||
while (*pbe == ' ' || *pbe == '\t' || *pbe == '\r' || *pbe == '\n')
|
||||
*pbe-- = '\0';
|
||||
|
||||
nid = OBJ_txt2nid((char *)pb);
|
||||
if (nid == NID_undef)
|
||||
QMessageBox::warning(NULL, QString(XCA_TITLE),
|
||||
|
||||
@ -51,9 +51,9 @@
|
||||
|
||||
|
||||
class QString;
|
||||
#include <qvaluelist.h>
|
||||
#include <Qt/qlist.h>
|
||||
|
||||
typedef QValueList<int> NIDlist;
|
||||
typedef QList<int> NIDlist;
|
||||
/* reads additional OIDs from a file: oid, sn, ln */
|
||||
|
||||
void initOIDs(QString baseDir);
|
||||
|
||||
@ -48,13 +48,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <qstring.h>
|
||||
#include <Qt/qstring.h>
|
||||
#include <Qt/qwidget.h>
|
||||
#include "pass_info.h"
|
||||
|
||||
pass_info::pass_info(QString t, QString d)
|
||||
pass_info::pass_info(QString t, QString d, QWidget *w)
|
||||
{
|
||||
title=t;
|
||||
description=d;
|
||||
widget=w;
|
||||
}
|
||||
|
||||
QString pass_info::getTitle()
|
||||
@ -67,6 +69,11 @@ QString pass_info::getDescription()
|
||||
return description;
|
||||
}
|
||||
|
||||
QWidget *pass_info::getWidget()
|
||||
{
|
||||
return widget;
|
||||
}
|
||||
|
||||
void pass_info::setTitle(QString t)
|
||||
{
|
||||
title = t;
|
||||
@ -76,4 +83,7 @@ void pass_info::setDescription(QString d)
|
||||
{
|
||||
description = d;
|
||||
}
|
||||
|
||||
void pass_info::setWidget(QWidget *w)
|
||||
{
|
||||
widget = w;
|
||||
}
|
||||
|
||||
@ -51,20 +51,26 @@
|
||||
#ifndef PASS_INFO_H
|
||||
#define PASS_INFO_H
|
||||
|
||||
#include <qstring.h>
|
||||
#include <qobject.h>
|
||||
#include <Qt/qstring.h>
|
||||
#include <Qt/qobject.h>
|
||||
#include <Qt/qwidget.h>
|
||||
|
||||
class pass_info: public QObject
|
||||
{
|
||||
private:
|
||||
QString title;
|
||||
QString description;
|
||||
QWidget *widget;
|
||||
|
||||
public:
|
||||
pass_info(QString t, QString d);
|
||||
pass_info(QString t, QString d, QWidget *w = NULL);
|
||||
QString getTitle();
|
||||
QString getDescription();
|
||||
QWidget *getWidget();
|
||||
|
||||
void setTitle(QString t);
|
||||
void setDescription(QString d);
|
||||
void setWidget(QWidget *w);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
193
lib/pki_base.cpp
193
lib/pki_base.cpp
@ -36,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -52,18 +50,37 @@
|
||||
|
||||
#include "pki_base.h"
|
||||
#include "exception.h"
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
int pki_base::pki_counter = 0;
|
||||
|
||||
pki_base::pki_base(const QString name)
|
||||
pki_base::pki_base(const QString name, pki_base *p)
|
||||
{
|
||||
TRACE
|
||||
desc = name;
|
||||
class_name = "pki_base";
|
||||
pointer = NULL;
|
||||
parent = p;
|
||||
pki_counter++;
|
||||
childItems.clear();
|
||||
dataVersion=0;
|
||||
pkiType=none;
|
||||
cols=1;
|
||||
}
|
||||
|
||||
int pki_base::getVersion()
|
||||
{
|
||||
TRACE
|
||||
return dataVersion;
|
||||
}
|
||||
|
||||
enum pki_type pki_base::getType()
|
||||
{
|
||||
TRACE
|
||||
return pkiType;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// FIXME: remove if unneeded
|
||||
void pki_base::fload(const QString fname)
|
||||
{
|
||||
}
|
||||
@ -71,35 +88,43 @@ void pki_base::fload(const QString fname)
|
||||
void pki_base::writeDefault(const QString fname)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
pki_base::~pki_base(void)
|
||||
{
|
||||
TRACE
|
||||
pki_counter--;
|
||||
}
|
||||
|
||||
|
||||
QString pki_base::getIntName() const
|
||||
{
|
||||
TRACE
|
||||
return desc;
|
||||
}
|
||||
|
||||
int pki_base::get_pki_counter()
|
||||
{
|
||||
TRACE
|
||||
return pki_counter;
|
||||
}
|
||||
|
||||
QString pki_base::getClassName()
|
||||
{
|
||||
return class_name;
|
||||
TRACE
|
||||
QString x = class_name;
|
||||
return x;
|
||||
}
|
||||
|
||||
void pki_base::setIntName(const QString &d)
|
||||
{
|
||||
desc = d.latin1();
|
||||
TRACE
|
||||
desc = d;
|
||||
}
|
||||
|
||||
void pki_base::fopen_error(const QString fname)
|
||||
{
|
||||
TRACE
|
||||
QString txt = "Error opening file: '" + fname + "'";
|
||||
openssl_error(txt);
|
||||
}
|
||||
@ -107,14 +132,16 @@ void pki_base::fopen_error(const QString fname)
|
||||
|
||||
void pki_base::openssl_error(const QString myerr) const
|
||||
{
|
||||
TRACE
|
||||
QString errtxt = "";
|
||||
QString error = "";
|
||||
if (myerr != "") {
|
||||
error += myerr + "\n";
|
||||
}
|
||||
while (int i = ERR_get_error() ) {
|
||||
errtxt = ERR_error_string(i ,NULL);
|
||||
error += errtxt + "\n";
|
||||
errtxt = ERR_error_string(i ,NULL);
|
||||
printf("OpenSSL error: %s\n", ERR_error_string(i ,NULL) );
|
||||
error += errtxt + "\n";
|
||||
}
|
||||
if (!error.isEmpty()) {
|
||||
throw errorEx(error, class_name);
|
||||
@ -124,79 +151,33 @@ void pki_base::openssl_error(const QString myerr) const
|
||||
|
||||
bool pki_base::ign_openssl_error() const
|
||||
{
|
||||
TRACE
|
||||
// ignore openssl errors
|
||||
QString errtxt;
|
||||
while (int i = ERR_get_error() ) {
|
||||
errtxt = ERR_error_string(i ,NULL);
|
||||
//fprintf(stderr,"IGNORED: %s\n",errtxt.latin1());
|
||||
fprintf(stderr,"IGNORED: %s\n", CCHAR(errtxt));
|
||||
}
|
||||
return !errtxt.isEmpty();
|
||||
}
|
||||
|
||||
int pki_base::intToData(unsigned char **p, int val)
|
||||
{
|
||||
int s = sizeof(int);
|
||||
memcpy(*p, &val, s);
|
||||
*p += s;
|
||||
return s;
|
||||
}
|
||||
|
||||
int pki_base::intFromData(const unsigned char **p)
|
||||
{
|
||||
int s = sizeof(int);
|
||||
int ret;
|
||||
memcpy(&ret, *p, s);
|
||||
*p += s;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pki_base::boolToData(unsigned char **p, bool val)
|
||||
{
|
||||
int s = sizeof(bool);
|
||||
memcpy(*p, &val, s);
|
||||
*p += s;
|
||||
return s;
|
||||
}
|
||||
|
||||
bool pki_base::boolFromData(const unsigned char **p)
|
||||
{
|
||||
int s = sizeof(bool);
|
||||
bool ret;
|
||||
memcpy(&ret, *p, s);
|
||||
*p += s;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pki_base::stringToData(unsigned char **p, const QString val)
|
||||
{
|
||||
int s = (val.length() +1) * sizeof(char);
|
||||
memcpy(*p, val.latin1(), s);
|
||||
*p += s;
|
||||
return s;
|
||||
}
|
||||
|
||||
QString pki_base::stringFromData(const unsigned char **p)
|
||||
{
|
||||
QString ret="";
|
||||
while(**p) {
|
||||
ret +=(char)**p;
|
||||
*p += sizeof(char);
|
||||
}
|
||||
*p += sizeof(char);
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString pki_base::rmslashdot(const QString &s)
|
||||
{
|
||||
int r = s.findRev('.');
|
||||
TRACE
|
||||
QByteArray a = s.toAscii();
|
||||
int r = a.lastIndexOf('.');
|
||||
#ifdef WIN32
|
||||
int l = s.findRev('\\');
|
||||
int l = a.lastIndexOf('\\');
|
||||
#else
|
||||
int l = s.findRev('/');
|
||||
int l = a.lastIndexOf('/');
|
||||
#endif
|
||||
return s.mid(l+1,r-l-1);
|
||||
printf("r=%d, l=%d, s='%s', mid='%s'\n",r,l,(const char*)a,
|
||||
CCHAR(s.mid(l+1,r-l-1)));
|
||||
return s.mid(l+1,r-l-1);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// FIXME: remove if unneeded
|
||||
void pki_base::updateView()
|
||||
{
|
||||
if (pointer == NULL) return;
|
||||
@ -205,4 +186,82 @@ void pki_base::updateView()
|
||||
#endif
|
||||
pointer->setText(0, getIntName());
|
||||
}
|
||||
#endif
|
||||
|
||||
pki_base *pki_base::getParent()
|
||||
{
|
||||
TRACE
|
||||
return parent;
|
||||
}
|
||||
|
||||
void pki_base::setParent(pki_base *p)
|
||||
{
|
||||
TRACE
|
||||
parent = p;
|
||||
}
|
||||
|
||||
pki_base *pki_base::child(int row)
|
||||
{
|
||||
TRACE
|
||||
return childItems.value(row);
|
||||
}
|
||||
|
||||
void pki_base::append(pki_base *item)
|
||||
{
|
||||
TRACE
|
||||
childItems.append(item);
|
||||
}
|
||||
|
||||
int pki_base::childCount()
|
||||
{
|
||||
TRACE
|
||||
return childItems.count();
|
||||
}
|
||||
|
||||
int pki_base::row(void) const
|
||||
{
|
||||
TRACE
|
||||
if (parent)
|
||||
return parent->childItems.indexOf(const_cast<pki_base*>(this));
|
||||
return 0;
|
||||
}
|
||||
|
||||
pki_base *pki_base::iterate(pki_base *pki)
|
||||
{
|
||||
TRACE
|
||||
if (pki == NULL)
|
||||
pki = (childItems.isEmpty()) ? NULL : childItems.first();
|
||||
else
|
||||
pki = childItems.value(pki->row()+1);
|
||||
if (pki)
|
||||
return pki;
|
||||
if (!parent)
|
||||
return NULL;
|
||||
return parent->iterate(this);
|
||||
}
|
||||
|
||||
void pki_base::freeChild(pki_base *pki)
|
||||
{
|
||||
TRACE
|
||||
printf("Rows1: %d, delete row %d \n", childCount(), pki->row());
|
||||
childItems.takeAt(pki->row());
|
||||
delete pki;
|
||||
printf("Rows2: %d\n", childCount());
|
||||
}
|
||||
|
||||
int pki_base::columns(void)
|
||||
{
|
||||
TRACE
|
||||
return cols;
|
||||
}
|
||||
|
||||
QVariant pki_base::column_data(int col)
|
||||
{
|
||||
TRACE
|
||||
return QVariant("invalid");
|
||||
}
|
||||
QVariant pki_base::getIcon()
|
||||
{
|
||||
TRACE
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
@ -52,49 +52,60 @@
|
||||
#define PKI_BASE_H
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <qstring.h>
|
||||
#ifdef qt4
|
||||
#include <q3listview.h>
|
||||
#else
|
||||
#include <qlistview.h>
|
||||
#endif
|
||||
#include <Qt/qstring.h>
|
||||
#include <Qt/qlistview.h>
|
||||
#include "db.h"
|
||||
#include "base.h"
|
||||
|
||||
class pki_base : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
static int pki_counter;
|
||||
protected:
|
||||
int cols;
|
||||
char *class_name;
|
||||
QString desc;
|
||||
QString class_name;
|
||||
QListViewItem *pointer;
|
||||
int dataVersion;
|
||||
enum pki_type pkiType;
|
||||
/* model data */
|
||||
pki_base *parent;
|
||||
|
||||
void openssl_error(const QString myerr = "") const;
|
||||
void fopen_error(const QString fname);
|
||||
bool ign_openssl_error() const;
|
||||
int intToData(unsigned char **p, int val);
|
||||
int intFromData(const unsigned char **p);
|
||||
int boolToData(unsigned char **p, bool val);
|
||||
bool boolFromData(const unsigned char **p);
|
||||
int stringToData(unsigned char **p, const QString val);
|
||||
QString stringFromData(const unsigned char **p);
|
||||
|
||||
public:
|
||||
pki_base(const QString d = "");
|
||||
void fload(const QString name);
|
||||
virtual void writeDefault(const QString fname);
|
||||
static int get_pki_counter();
|
||||
virtual void fromData(const unsigned char *p, int size){};
|
||||
virtual unsigned char *toData(int *size){return NULL;};
|
||||
virtual bool compare(pki_base *ref){return false;};
|
||||
virtual ~pki_base();
|
||||
QString getIntName() const;
|
||||
QList<pki_base*> childItems;
|
||||
pki_base(const QString d = "", pki_base *p = NULL);
|
||||
virtual void fload(const QString name){};
|
||||
virtual void writeDefault(const QString fname){};
|
||||
static int get_pki_counter(void);
|
||||
virtual void fromData(const unsigned char *p, db_header_t *head){};
|
||||
virtual unsigned char *toData(int *size){return NULL;}
|
||||
virtual bool compare(pki_base *ref){return false;}
|
||||
virtual ~pki_base(void);
|
||||
QString getIntName(void) const;
|
||||
void setIntName(const QString &d);
|
||||
void delLvi() { pointer = NULL; }
|
||||
QListViewItem *getLvi() { return pointer; }
|
||||
void setLvi(QListViewItem *ptr) { pointer = ptr; }
|
||||
QString getClassName();
|
||||
QString rmslashdot(const QString &fname);
|
||||
virtual void updateView();
|
||||
QString getClassName(void);
|
||||
static QString rmslashdot(const QString &fname);
|
||||
//virtual void updateView();
|
||||
|
||||
int getVersion(void);
|
||||
enum pki_type getType(void);
|
||||
void setParent(pki_base *p);
|
||||
pki_base *getParent();
|
||||
pki_base *child(int row);
|
||||
void append(pki_base *item);
|
||||
int childCount(void);
|
||||
int row(void) const;
|
||||
pki_base *iterate(pki_base *pki = NULL);
|
||||
void freeChild(pki_base *pki);
|
||||
|
||||
int columns(void);
|
||||
virtual QVariant column_data(int col);
|
||||
virtual QVariant getIcon();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
|
||||
//Added by the Qt porting tool:
|
||||
#include <QPixmap>
|
||||
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2001 Christian Hohnstaedt.
|
||||
@ -52,7 +56,7 @@
|
||||
|
||||
#include "pki_crl.h"
|
||||
#include "widgets/MainWindow.h"
|
||||
#include <qdir.h>
|
||||
#include <Qt/qdir.h>
|
||||
|
||||
QPixmap *pki_crl::icon = NULL;
|
||||
|
||||
@ -291,7 +295,7 @@ QString pki_crl::printV3ext()
|
||||
void pki_crl::updateView()
|
||||
{
|
||||
pki_base::updateView();
|
||||
QListViewItem *c = getLvi();
|
||||
Q3ListViewItem *c = getLvi();
|
||||
if (!c) return;
|
||||
c->setPixmap(0, *icon);
|
||||
c->setText(0, getIntName());
|
||||
|
||||
152
lib/pki_key.cpp
152
lib/pki_key.cpp
@ -36,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -53,10 +51,11 @@
|
||||
#include "pki_key.h"
|
||||
#include "pass_info.h"
|
||||
#include "func.h"
|
||||
#include "db.h"
|
||||
#include <openssl/rand.h>
|
||||
#include <qprogressdialog.h>
|
||||
#include <qapplication.h>
|
||||
#include <qdir.h>
|
||||
#include <Qt/qprogressdialog.h>
|
||||
#include <Qt/qapplication.h>
|
||||
#include <Qt/qdir.h>
|
||||
#include <widgets/MainWindow.h>
|
||||
|
||||
char pki_key::passwd[40]={0,};
|
||||
@ -77,12 +76,31 @@ void pki_key::init(int type)
|
||||
encKey = NULL;
|
||||
encKey_len = 0;
|
||||
ownPass = 0;
|
||||
dataVersion=1;
|
||||
pkiType=async_key;
|
||||
cols=4;
|
||||
}
|
||||
|
||||
void pki_key::incProgress(int a, int b, void *progress)
|
||||
{
|
||||
int i = ((QProgressDialog *)progress)->progress();
|
||||
((QProgressDialog *)progress)->setProgress(++i);
|
||||
int i = ((QProgressBar *)progress)->value();
|
||||
((QProgressBar *)progress)->setValue(++i);
|
||||
}
|
||||
|
||||
QString pki_key::getTypeString()
|
||||
{
|
||||
QString type;
|
||||
switch (key->type) {
|
||||
case EVP_PKEY_RSA:
|
||||
type = "RSA";
|
||||
break;
|
||||
case EVP_PKEY_DSA:
|
||||
type = "DSA";
|
||||
break;
|
||||
default:
|
||||
type = "---";
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
QString pki_key::getIntNameWithType()
|
||||
@ -98,9 +116,8 @@ QString pki_key::getIntNameWithType()
|
||||
default:
|
||||
postfix = " (---)";
|
||||
}
|
||||
return getIntName() + postfix;
|
||||
return getIntName() + " (" + getTypeString() + ")";
|
||||
}
|
||||
|
||||
QString pki_key::removeTypeFromIntName(QString n)
|
||||
{
|
||||
if (n.right(1) != ")" ) return n;
|
||||
@ -123,32 +140,28 @@ void pki_key::setOwnPass(int x)
|
||||
encryptKey();
|
||||
}
|
||||
|
||||
void pki_key::generate(int bits, int type)
|
||||
void pki_key::generate(int bits, int type, QProgressBar *progress)
|
||||
{
|
||||
RSA *rsakey = NULL;
|
||||
DSA *dsakey = NULL;
|
||||
QProgressDialog *progress = new QProgressDialog(
|
||||
qApp->tr("Please wait, Key generation is in progress"),
|
||||
qApp->tr("Cancel"),90, 0, 0, true);
|
||||
progress->setMinimumDuration(0);
|
||||
progress->setProgress(0);
|
||||
progress->setCaption(XCA_TITLE);
|
||||
|
||||
progress->setMinimum(0);
|
||||
progress->setMaximum(100);
|
||||
progress->setValue(50);
|
||||
|
||||
if (type == EVP_PKEY_RSA) {
|
||||
rsakey = RSA_generate_key(bits, 0x10001, &incProgress, progress);
|
||||
if (rsakey) EVP_PKEY_set1_RSA(key, rsakey);
|
||||
} else if (type == EVP_PKEY_DSA) {
|
||||
progress->setTotalSteps(250);
|
||||
progress->setMaximum(500);
|
||||
dsakey = DSA_generate_parameters(bits,NULL,0,NULL,NULL,&incProgress, progress);
|
||||
DSA_generate_key(dsakey);
|
||||
if(dsakey) EVP_PKEY_set1_DSA(key,dsakey);
|
||||
}
|
||||
|
||||
progress->cancel();
|
||||
delete progress;
|
||||
|
||||
openssl_error();
|
||||
encryptKey();
|
||||
|
||||
printf("encryption DONE\n");
|
||||
}
|
||||
|
||||
pki_key::pki_key(const pki_key *pk)
|
||||
@ -195,16 +208,15 @@ pki_key::pki_key(EVP_PKEY *pkey)
|
||||
|
||||
void pki_key::fload(const QString fname)
|
||||
{
|
||||
pass_info p(XCA_TITLE, tr("Please enter the password to decrypt the private key.")
|
||||
pass_info p(XCA_TITLE, qApp->translate("MainWindow", "Please enter the password to decrypt the private key.")
|
||||
+ "\n'" + fname + "'");
|
||||
pem_password_cb *cb = &MainWindow::passRead;
|
||||
FILE *fp = fopen(fname.latin1(), "r");
|
||||
pem_password_cb *cb = MainWindow::passRead;
|
||||
FILE *fp = fopen(CCHAR(fname), "r");
|
||||
EVP_PKEY *pkey = NULL;
|
||||
bool priv = true;
|
||||
|
||||
if (fp != NULL) {
|
||||
pkey = PEM_read_PrivateKey(fp, NULL, cb, &p);
|
||||
|
||||
if (!pkey) {
|
||||
ign_openssl_error();
|
||||
rewind(fp);
|
||||
@ -232,41 +244,39 @@ void pki_key::fload(const QString fname)
|
||||
}
|
||||
|
||||
openssl_error();
|
||||
}
|
||||
else fopen_error(fname);
|
||||
} else
|
||||
fopen_error(fname);
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void pki_key::fromData(const unsigned char *p, int size )
|
||||
void pki_key::fromData(const unsigned char *p, db_header_t *head )
|
||||
{
|
||||
const unsigned char *p1;
|
||||
int version, type;
|
||||
|
||||
int version, type, size;
|
||||
|
||||
p1 = p;
|
||||
|
||||
version = intFromData(&p1);
|
||||
if (version != 1) { // backward compatibility
|
||||
oldFromData(p, size);
|
||||
return;
|
||||
}
|
||||
size = head->len - sizeof(db_header_t);
|
||||
version = head->version;
|
||||
|
||||
if (key)
|
||||
EVP_PKEY_free(key);
|
||||
|
||||
|
||||
key = NULL;
|
||||
type = intFromData(&p1);
|
||||
ownPass = intFromData(&p1);
|
||||
|
||||
type = db::intFromData(&p1);
|
||||
ownPass = db::intFromData(&p1);
|
||||
D2I_CLASHT(d2i_PublicKey, type, &key, &p1, size - (2*sizeof(int)));
|
||||
openssl_error();
|
||||
|
||||
|
||||
encKey_len = size - (p1-p);
|
||||
if (encKey_len) {
|
||||
encKey = (unsigned char *)OPENSSL_malloc(encKey_len);
|
||||
memcpy(encKey, p1 ,encKey_len);
|
||||
}
|
||||
printf("from data: size=%d, encKey_len=%d\n", size, encKey_len);
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
void pki_key::oldFromData(const unsigned char *p, int size )
|
||||
{
|
||||
unsigned char *sik, *pdec;
|
||||
@ -317,7 +327,7 @@ void pki_key::oldFromData(const unsigned char *p, int size )
|
||||
openssl_error();
|
||||
encryptKey();
|
||||
}
|
||||
|
||||
#endif
|
||||
EVP_PKEY *pki_key::decryptKey()
|
||||
{
|
||||
unsigned char *p;
|
||||
@ -331,9 +341,9 @@ EVP_PKEY *pki_key::decryptKey()
|
||||
const EVP_CIPHER *cipher = EVP_des_ede3_cbc();
|
||||
char ownPassBuf[MAX_PASS_LENGTH];
|
||||
|
||||
/* This key has its own password */
|
||||
/* This key has its own password */
|
||||
if (ownPass == 1) {
|
||||
pass_info pi(XCA_TITLE, tr("Please enter the password to decrypt the private key: '" + getIntName() + "'"));
|
||||
pass_info pi(XCA_TITLE, qApp->translate("MainWindow", "Please enter the password to decrypt the private key: '") + getIntName() + "'");
|
||||
MainWindow::passRead(ownPassBuf, MAX_PASS_LENGTH, 0, &pi);
|
||||
}
|
||||
else {
|
||||
@ -359,6 +369,7 @@ EVP_PKEY *pki_key::decryptKey()
|
||||
decsize = outl;
|
||||
EVP_DecryptFinal( &ctx, encKey + decsize , &outl );
|
||||
decsize += outl;
|
||||
printf("Decrypt decsize=%d, encKey_len=%d\n", decsize, encKey_len);
|
||||
openssl_error();
|
||||
tmpkey = D2I_CLASHT(d2i_PrivateKey, key->type, NULL, &p1, decsize);
|
||||
OPENSSL_free(p);
|
||||
@ -373,18 +384,19 @@ unsigned char *pki_key::toData(int *size)
|
||||
int pubsize;
|
||||
|
||||
pubsize = i2d_PublicKey(key, NULL);
|
||||
*size = pubsize + encKey_len + (3*sizeof(int));
|
||||
*size = pubsize + encKey_len + (2*sizeof(int));
|
||||
p = (unsigned char *)OPENSSL_malloc(*size);
|
||||
openssl_error();
|
||||
p1 = p;
|
||||
intToData(&p1, 1);
|
||||
intToData(&p1, key->type);
|
||||
intToData(&p1, ownPass);
|
||||
db::intToData(&p1, key->type);
|
||||
db::intToData(&p1, ownPass);
|
||||
i2d_PublicKey(key, &p1);
|
||||
openssl_error();
|
||||
if (encKey_len) {
|
||||
memcpy(p1, encKey, encKey_len);
|
||||
}
|
||||
printf("To data: pubsize=%d, encKey_len: %d, *size=%d\n",
|
||||
pubsize, encKey_len, *size);
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -401,7 +413,7 @@ void pki_key::encryptKey()
|
||||
|
||||
/* This key has its own, private password ? */
|
||||
if (ownPass == 1) {
|
||||
pass_info p(XCA_TITLE, tr("Please enter the password to protect the private key: '" + getIntName() + "'"));
|
||||
pass_info p(XCA_TITLE, qApp->translate("MainWindow", "Please enter the password to protect the private key: '") + getIntName() + "'");
|
||||
MainWindow::passWrite(ownPassBuf, MAX_PASS_LENGTH, 0, &p);
|
||||
}
|
||||
else {
|
||||
@ -459,6 +471,7 @@ void pki_key::encryptKey()
|
||||
|
||||
//CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF);
|
||||
|
||||
printf("Encrypt: encKey_len=%d\n", encKey_len);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -476,8 +489,8 @@ pki_key::~pki_key()
|
||||
void pki_key::writePKCS8(const QString fname, pem_password_cb *cb)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
pass_info p(XCA_TITLE, tr("Please enter the password protecting the PKCS#8 key"));
|
||||
FILE *fp = fopen(fname.latin1(),"w");
|
||||
pass_info p(XCA_TITLE, qApp->translate("MainWindow", "Please enter the password protecting the PKCS#8 key"));
|
||||
FILE *fp = fopen(fname.toAscii(),"w");
|
||||
if (fp != NULL) {
|
||||
if (key){
|
||||
pkey = decryptKey();
|
||||
@ -507,13 +520,13 @@ void pki_key::writeKey(const QString fname, const EVP_CIPHER *enc,
|
||||
pem_password_cb *cb, bool PEM)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
pass_info p(XCA_TITLE, tr("Please enter the export password for the private key"));
|
||||
pass_info p(XCA_TITLE, qApp->translate("MainWindow", "Please enter the export password for the private key"));
|
||||
if (isPubKey()) {
|
||||
writePublic(fname, PEM);
|
||||
return;
|
||||
}
|
||||
FILE *fp = fopen(fname.latin1(), "w");
|
||||
if (fp != NULL) {
|
||||
FILE *fp = fopen(CCHAR(fname), "w");
|
||||
if (!fp) {
|
||||
fopen_error(fname);
|
||||
return;
|
||||
}
|
||||
@ -532,7 +545,7 @@ void pki_key::writeKey(const QString fname, const EVP_CIPHER *enc,
|
||||
|
||||
void pki_key::writePublic(const QString fname, bool PEM)
|
||||
{
|
||||
FILE *fp = fopen(fname.latin1(),"w");
|
||||
FILE *fp = fopen(fname.toAscii(),"w");
|
||||
if (fp == NULL) {
|
||||
fopen_error(fname);
|
||||
return;
|
||||
@ -661,13 +674,13 @@ int pki_key::getType()
|
||||
int pki_key::incUcount()
|
||||
{
|
||||
ucount++;
|
||||
updateView();
|
||||
// updateView();
|
||||
return ucount;
|
||||
}
|
||||
int pki_key::decUcount()
|
||||
{
|
||||
ucount--;
|
||||
updateView();
|
||||
// updateView();
|
||||
return ucount;
|
||||
}
|
||||
|
||||
@ -685,7 +698,7 @@ const EVP_MD *pki_key::getDefaultMD(){
|
||||
}
|
||||
return md;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void pki_key::updateView()
|
||||
{
|
||||
QString type_str = "";
|
||||
@ -706,5 +719,26 @@ void pki_key::updateView()
|
||||
pointer->setText(2, QString::number(getUcount()));
|
||||
pointer->setText(3, type_str);
|
||||
}
|
||||
#endif
|
||||
|
||||
QVariant pki_key::column_data(int col)
|
||||
{
|
||||
switch (col) {
|
||||
case 0:
|
||||
return QVariant(getIntName());
|
||||
case 1:
|
||||
return QVariant(getTypeString());
|
||||
case 2:
|
||||
return QVariant(length());
|
||||
case 3:
|
||||
return QVariant(getUcount());
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant pki_key::getIcon()
|
||||
{
|
||||
int pixnum= isPubKey() ? 1 : 0;
|
||||
return QVariant(*icon[pixnum]);
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,8 @@
|
||||
#ifndef PKI_KEY_H
|
||||
#define PKI_KEY_H
|
||||
|
||||
#include <qstring.h>
|
||||
#include <Qt/qstring.h>
|
||||
#include <Qt/qprogressbar.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/pem.h>
|
||||
@ -79,7 +80,7 @@ class pki_key: public pki_base
|
||||
static QPixmap *icon[2];
|
||||
static char passwd[MAX_PASS_LENGTH];
|
||||
static void erasePasswd();
|
||||
void generate(int bits, int type = EVP_PKEY_RSA);
|
||||
void generate(int bits, int type, QProgressBar *progress);
|
||||
void setOwnPass(int x);
|
||||
pki_key(const QString name = "", int type = EVP_PKEY_RSA);
|
||||
pki_key(EVP_PKEY *pkey);
|
||||
@ -88,12 +89,12 @@ class pki_key: public pki_base
|
||||
/* destructor */
|
||||
~pki_key();
|
||||
|
||||
QString getIntNameWithType();
|
||||
QString pki_key::getTypeString(void);
|
||||
QString getIntNameWithType(void);
|
||||
static QString removeTypeFromIntName(QString n);
|
||||
void fload(const QString fname);
|
||||
void writeDefault(const QString fname);
|
||||
void fromData(const unsigned char *p, int size);
|
||||
void oldFromData(const unsigned char *p, int size);
|
||||
void fromData(const unsigned char *p, db_header_t *head);
|
||||
unsigned char *toData(int *size);
|
||||
bool compare(pki_base *ref);
|
||||
QString length();
|
||||
@ -113,8 +114,9 @@ class pki_key: public pki_base
|
||||
int incUcount();
|
||||
int decUcount();
|
||||
int getUcount();
|
||||
void updateView();
|
||||
const EVP_MD *getDefaultMD();
|
||||
QVariant column_data(int col);
|
||||
QVariant getIcon();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
#include "pass_info.h"
|
||||
#include "exception.h"
|
||||
#include <openssl/err.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <Qt/qmessagebox.h>
|
||||
|
||||
|
||||
pki_pkcs12::pki_pkcs12(const QString d, pki_x509 *acert, pki_key *akey, pem_password_cb *cb):
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
|
||||
//Added by the Qt porting tool:
|
||||
#include <QPixmap>
|
||||
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2001 Christian Hohnstaedt.
|
||||
@ -52,7 +56,7 @@
|
||||
|
||||
#include "pki_temp.h"
|
||||
#include "func.h"
|
||||
#include <qdir.h>
|
||||
#include <Qt/qdir.h>
|
||||
|
||||
QPixmap *pki_temp::icon= NULL;
|
||||
|
||||
|
||||
157
lib/pki_x509.cpp
157
lib/pki_x509.cpp
@ -36,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -54,7 +52,7 @@
|
||||
#include "pki_x509.h"
|
||||
#include "func.h"
|
||||
#include "base.h"
|
||||
#include <qdir.h>
|
||||
#include <Qt/qdir.h>
|
||||
|
||||
QPixmap *pki_x509::icon[4] = { NULL, NULL, NULL, NULL };
|
||||
|
||||
@ -66,21 +64,21 @@ pki_x509::pki_x509(X509 *c)
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
pki_x509::pki_x509(const pki_x509 *crt)
|
||||
:pki_x509super(crt->desc)
|
||||
pki_x509::pki_x509(const pki_x509 &crt)
|
||||
:pki_x509super(crt.desc)
|
||||
{
|
||||
init();
|
||||
cert = X509_dup(crt->cert);
|
||||
cert = X509_dup(crt.cert);
|
||||
openssl_error();
|
||||
psigner = crt->psigner;
|
||||
setRefKey(crt->getRefKey());
|
||||
trust = crt->trust;
|
||||
efftrust = crt->efftrust;
|
||||
revoked = crt->revoked;
|
||||
caSerial = crt->caSerial;
|
||||
caTemplate = crt->caTemplate;
|
||||
crlDays = crt->crlDays;
|
||||
lastCrl = crt->lastCrl;
|
||||
psigner = crt.psigner;
|
||||
setRefKey(crt.getRefKey());
|
||||
trust = crt.trust;
|
||||
efftrust = crt.efftrust;
|
||||
revoked = crt.revoked;
|
||||
caSerial = crt.caSerial;
|
||||
caTemplate = crt.caTemplate;
|
||||
crlDays = crt.crlDays;
|
||||
lastCrl = crt.lastCrl;
|
||||
isrevoked = isrevoked;
|
||||
openssl_error();
|
||||
}
|
||||
@ -96,7 +94,7 @@ pki_x509::pki_x509(const QString name)
|
||||
|
||||
void pki_x509::fload(const QString fname)
|
||||
{
|
||||
FILE *fp = fopen(fname.latin1(),"r");
|
||||
FILE *fp = fopen(fname.toAscii(),"r");
|
||||
X509 *_cert;
|
||||
if (fp != NULL) {
|
||||
_cert = PEM_read_X509(fp, NULL, NULL, NULL);
|
||||
@ -139,6 +137,9 @@ void pki_x509::init()
|
||||
class_name = "pki_x509";
|
||||
cert = NULL;
|
||||
isrevoked = false;
|
||||
dataVersion=1;
|
||||
pkiType=x509;
|
||||
cols=6;
|
||||
}
|
||||
|
||||
void pki_x509::setSerial(const a1int &serial)
|
||||
@ -286,8 +287,6 @@ void pki_x509::sign(pki_key *signkey, const EVP_MD *digest)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Save the Certificate to data and back:
|
||||
* Version 1:
|
||||
* int Version
|
||||
@ -298,107 +297,57 @@ void pki_x509::sign(pki_key *signkey, const EVP_MD *digest)
|
||||
* revocationtime
|
||||
*/
|
||||
|
||||
|
||||
void pki_x509::fromData(const unsigned char *p, int size)
|
||||
void pki_x509::fromData(const unsigned char *p, db_header_t *head)
|
||||
{
|
||||
int version, sCert, sRev, sLastCrl;
|
||||
int version, size;
|
||||
const unsigned char *p1 = p;
|
||||
|
||||
X509 *cert_sik = cert;
|
||||
version = intFromData(&p1);
|
||||
if (version >=1 || version <= 5) {
|
||||
sCert = intFromData(&p1);
|
||||
cert = D2I_CLASH(d2i_X509, NULL, &p1, sCert);
|
||||
trust = intFromData(&p1);
|
||||
sRev = intFromData(&p1);
|
||||
if (sRev) {
|
||||
if (version != 3) isrevoked = true;
|
||||
p1 = revoked.d2i(p1, sRev);
|
||||
}
|
||||
else {
|
||||
isrevoked = false;
|
||||
revoked.now();
|
||||
}
|
||||
|
||||
if (version == 1) {
|
||||
caTemplate="";
|
||||
caSerial=1;
|
||||
lastCrl = NULL;
|
||||
crlDays=30;
|
||||
}
|
||||
|
||||
if (version >= 2 ) {
|
||||
if (version >= 5)
|
||||
caSerial.setHex(stringFromData(&p1));
|
||||
else {
|
||||
int i = intFromData(&p1);
|
||||
if (i>=0)
|
||||
caSerial = i;
|
||||
else {
|
||||
caSerial = getSerial();
|
||||
++caSerial;
|
||||
}
|
||||
}
|
||||
caTemplate = stringFromData(&p1);
|
||||
}
|
||||
if (version >= 3 ) {
|
||||
crlDays = intFromData(&p1);
|
||||
sLastCrl = intFromData(&p1);
|
||||
if (sLastCrl) {
|
||||
lastCrl.d2i(p1, sLastCrl);
|
||||
}
|
||||
}
|
||||
// version 4 saves a NULL as revoked
|
||||
// version 3 did save a recent date :-((
|
||||
}
|
||||
else { // old version
|
||||
cert = D2I_CLASH(d2i_X509, NULL, &p, size);
|
||||
revoked = NULL;
|
||||
trust = 1;
|
||||
efftrust = 1;
|
||||
}
|
||||
version = head->version;
|
||||
size = head->len - sizeof(db_header_t);
|
||||
|
||||
cert = D2I_CLASH(d2i_X509, NULL, &p1, size);
|
||||
trust = db::intFromData(&p1);
|
||||
isrevoked = db::boolFromData(&p1);
|
||||
p1 = revoked.d2i(p1, size - (p1-p));
|
||||
caSerial.setHex(db::stringFromData(&p1));
|
||||
caTemplate = db::stringFromData(&p1);
|
||||
crlDays = db::intFromData(&p1);
|
||||
lastCrl.d2i(p1, size - (p1-p));
|
||||
|
||||
if (cert)
|
||||
X509_free(cert_sik);
|
||||
else
|
||||
cert = cert_sik;
|
||||
openssl_error();
|
||||
|
||||
}
|
||||
|
||||
|
||||
unsigned char *pki_x509::toData(int *size)
|
||||
{
|
||||
#define PKI_DB_VERSION (int)5
|
||||
unsigned char *p, *p1;
|
||||
int sCert = i2d_X509(cert, NULL);
|
||||
int sRev = revoked.derSize();
|
||||
int sLastCrl = lastCrl.derSize();
|
||||
if (!isrevoked) sRev = 0;
|
||||
QString ca_s = caSerial.toHex();
|
||||
|
||||
// calculate the needed size
|
||||
*size = caTemplate.length() + 1 + sCert + sRev + sLastCrl + ca_s.length() + 1 + (6 * sizeof(int));
|
||||
*size = i2d_X509(cert, NULL) + 100;
|
||||
openssl_error();
|
||||
p = (unsigned char*)OPENSSL_malloc(*size);
|
||||
p1 = p;
|
||||
intToData(&p1, (PKI_DB_VERSION)); // version
|
||||
intToData(&p1, sCert); // sizeof(cert)
|
||||
|
||||
i2d_X509(cert, &p1); // cert
|
||||
intToData(&p1, trust); // trust
|
||||
intToData(&p1, sRev); // sizeof(revoked)
|
||||
if (sRev) {
|
||||
p1 = revoked.i2d(p1); // revokation date
|
||||
}
|
||||
|
||||
// version 2
|
||||
// *** caSerial format changed in version 5.
|
||||
stringToData(&p1, caSerial.toHex()); // the serial if this is a CA
|
||||
stringToData(&p1, caTemplate); // the name of the template to use for signing
|
||||
db::intToData(&p1, trust); // trust
|
||||
db::boolToData(&p1, isrevoked);
|
||||
p1 = revoked.i2d(p1); // revokation date
|
||||
|
||||
// the serial if this is a CA
|
||||
db::stringToData(&p1, caSerial.toHex());
|
||||
// the name of the template to use for signing
|
||||
db::stringToData(&p1, caTemplate);
|
||||
// version 3
|
||||
intToData(&p1, crlDays); // the CRL period
|
||||
intToData(&p1, sLastCrl); // size of last CRL
|
||||
if (sLastCrl) {
|
||||
p1 = lastCrl.i2d(p1); // last CRL date
|
||||
}
|
||||
db::intToData(&p1, crlDays); // the CRL period
|
||||
p1 = lastCrl.i2d(p1); // last CRL date
|
||||
openssl_error();
|
||||
printf("###### Size = %d, real size=%d\n", *size, p1-p);
|
||||
*size = p1-p;
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -412,7 +361,7 @@ void pki_x509::writeCert(const QString fname, bool PEM, bool append)
|
||||
FILE *fp;
|
||||
char *_a = "a", *_w="w", *p = _w;
|
||||
if (append) p=_a;
|
||||
fp = fopen(fname.latin1(), p);
|
||||
fp = fopen(fname.toAscii(), p);
|
||||
if (fp != NULL) {
|
||||
if (cert){
|
||||
if (PEM)
|
||||
@ -543,7 +492,7 @@ x509v3ext pki_x509::getExtByNid(int nid)
|
||||
extList el = getExt();
|
||||
x509v3ext e;
|
||||
|
||||
for (unsigned int i=0; i< el.count(); i++){
|
||||
for (int i=0; i< el.count(); i++){
|
||||
if (el[i].nid() == nid) return el[i];
|
||||
}
|
||||
return e;
|
||||
@ -665,6 +614,7 @@ void pki_x509::setLastCrl(const a1time &time)
|
||||
QString pki_x509::tinyCAfname()
|
||||
{
|
||||
QString col;
|
||||
const char *s;
|
||||
x509name x = getSubject();
|
||||
col = x.getEntryByNid(NID_commonName)
|
||||
+(x.getEntryByNid(NID_commonName) == "" ? " :" : ":")
|
||||
@ -682,9 +632,10 @@ QString pki_x509::tinyCAfname()
|
||||
+(x.getEntryByNid(NID_countryName) == "" ? " :" : ":");
|
||||
|
||||
int len = col.length();
|
||||
s = col.toAscii();
|
||||
unsigned char *buf = (unsigned char *)OPENSSL_malloc(len * 2 + 3);
|
||||
|
||||
EVP_EncodeBlock(buf, (unsigned char *)col.latin1(), len );
|
||||
EVP_EncodeBlock(buf, (const unsigned char *)s, len );
|
||||
col = (char *)buf;
|
||||
OPENSSL_free(buf);
|
||||
col += ".pem";
|
||||
@ -698,7 +649,7 @@ x509rev pki_x509::getRev()
|
||||
a.setSerial(getSerial());
|
||||
return a;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void pki_x509::updateView()
|
||||
{
|
||||
pki_base::updateView();
|
||||
@ -722,6 +673,8 @@ void pki_x509::updateView()
|
||||
pointer->setText(5, getRevoked().toSortable());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
QString pki_x509::getSigAlg()
|
||||
{
|
||||
QString alg = OBJ_nid2ln(OBJ_obj2nid(cert->sig_alg->algorithm));
|
||||
|
||||
@ -35,8 +35,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -81,7 +79,7 @@ class pki_x509 : public pki_x509super
|
||||
public:
|
||||
static QPixmap *icon[4];
|
||||
pki_x509(X509 *c);
|
||||
pki_x509(const pki_x509 *crt);
|
||||
pki_x509(const pki_x509 &crt);
|
||||
pki_x509(const QString name = "");
|
||||
~pki_x509();
|
||||
|
||||
@ -100,10 +98,10 @@ class pki_x509 : public pki_x509super
|
||||
x509name getIssuer() const;
|
||||
void setSubject(const x509name &n);
|
||||
void setIssuer(const x509name &n);
|
||||
|
||||
virtual void fromData(const unsigned char *p, int size);
|
||||
virtual unsigned char *toData(int *size);
|
||||
virtual bool compare(pki_base *refcert);
|
||||
|
||||
unsigned char *toData(int *size);
|
||||
void fromData(const unsigned char *p, db_header_t *head);
|
||||
bool compare(pki_base *refcert);
|
||||
bool canSign();
|
||||
void writeCert(const QString fname, bool PEM, bool append = false);
|
||||
bool verify(pki_x509 *signer);
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -57,7 +55,7 @@
|
||||
#include "exception.h"
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <qdir.h>
|
||||
#include <Qt/qdir.h>
|
||||
|
||||
QPixmap *pki_x509req::icon[3] = { NULL, NULL, NULL };
|
||||
|
||||
@ -69,6 +67,9 @@ pki_x509req::pki_x509req(const QString name)
|
||||
request = X509_REQ_new();
|
||||
openssl_error();
|
||||
spki = NULL;
|
||||
dataVersion=1;
|
||||
pkiType=x509_req;
|
||||
cols=3;
|
||||
}
|
||||
|
||||
pki_x509req::~pki_x509req()
|
||||
@ -117,7 +118,7 @@ void pki_x509req::createReq(pki_key *key, const x509name &dn, const EVP_MD *md,
|
||||
void pki_x509req::fload(const QString fname)
|
||||
{
|
||||
// request file section
|
||||
FILE *fp = fopen(fname.latin1(),"r");
|
||||
FILE *fp = fopen(CCHAR(fname), "r");
|
||||
X509_REQ *_req;
|
||||
if (fp != NULL) {
|
||||
_req = PEM_read_X509_REQ(fp, NULL, NULL, NULL);
|
||||
@ -134,7 +135,7 @@ void pki_x509req::fload(const QString fname)
|
||||
load_spkac(fname);
|
||||
openssl_error();
|
||||
}
|
||||
}else
|
||||
} else
|
||||
fopen_error(fname);
|
||||
fclose(fp);
|
||||
|
||||
@ -149,13 +150,17 @@ void pki_x509req::fload(const QString fname)
|
||||
}
|
||||
}
|
||||
|
||||
void pki_x509req::fromData(const unsigned char *p, int size)
|
||||
void pki_x509req::fromData(const unsigned char *p, db_header_t *head )
|
||||
{
|
||||
const unsigned char *ps = p;
|
||||
int version, size;
|
||||
|
||||
size = head->len - sizeof(db_header_t);
|
||||
version = head->version;
|
||||
|
||||
privkey = NULL;
|
||||
request = D2I_CLASH(d2i_X509_REQ, &request, &ps, size);
|
||||
openssl_error();
|
||||
|
||||
if (ps - p < size)
|
||||
spki = D2I_CLASH(d2i_NETSCAPE_SPKI, NULL, &ps , size + p - ps);
|
||||
openssl_error();
|
||||
@ -184,9 +189,11 @@ unsigned char *pki_x509req::toData(int *size)
|
||||
{
|
||||
unsigned char *p, *p1;
|
||||
*size = i2d_X509_REQ(request, NULL);
|
||||
printf("Size=%d\n", *size);
|
||||
if (spki) {
|
||||
*size += i2d_NETSCAPE_SPKI(spki, NULL);
|
||||
}
|
||||
printf("Size=%d\n", *size);
|
||||
openssl_error();
|
||||
p = (unsigned char*)OPENSSL_malloc(*size);
|
||||
p1 = p;
|
||||
@ -204,18 +211,18 @@ void pki_x509req::writeDefault(const QString fname)
|
||||
|
||||
void pki_x509req::writeReq(const QString fname, bool PEM)
|
||||
{
|
||||
FILE *fp = fopen(fname.latin1(),"w");
|
||||
if (fp != NULL) {
|
||||
if (request){
|
||||
if (PEM)
|
||||
PEM_write_X509_REQ(fp, request);
|
||||
else
|
||||
i2d_X509_REQ_fp(fp, request);
|
||||
openssl_error();
|
||||
}
|
||||
}
|
||||
else fopen_error(fname);
|
||||
fclose(fp);
|
||||
FILE *fp = fopen(CCHAR(fname), "w");
|
||||
if (fp) {
|
||||
if (request){
|
||||
if (PEM)
|
||||
PEM_write_X509_REQ(fp, request);
|
||||
else
|
||||
i2d_X509_REQ_fp(fp, request);
|
||||
fclose(fp);
|
||||
openssl_error();
|
||||
}
|
||||
} else
|
||||
fopen_error(fname);
|
||||
}
|
||||
|
||||
bool pki_x509req::compare(pki_base *refreq)
|
||||
@ -242,7 +249,13 @@ int pki_x509req::verify()
|
||||
x = NETSCAPE_SPKI_verify(spki, pkey) >= 0;
|
||||
}
|
||||
EVP_PKEY_free(pkey);
|
||||
openssl_error();
|
||||
try {
|
||||
openssl_error();
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
if (!err.isEmpty())
|
||||
printf("Error: %s\n", CCHAR(err.getString()));
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
@ -256,17 +269,6 @@ pki_key *pki_x509req::getPubKey() const
|
||||
return key;
|
||||
}
|
||||
|
||||
void pki_x509req::updateView()
|
||||
{
|
||||
pki_base::updateView();
|
||||
if (! pointer) return;
|
||||
int pixnum = 0;
|
||||
if (getRefKey() != NULL ) pixnum = 1;
|
||||
if (spki != NULL) pixnum = 2;
|
||||
pointer->setPixmap(0, *icon[pixnum]);
|
||||
pointer->setText(1, getSubject().getEntryByNid(NID_commonName));
|
||||
}
|
||||
|
||||
QString pki_x509req::getSigAlg()
|
||||
{
|
||||
QString alg = OBJ_nid2ln(OBJ_obj2nid(request->sig_alg->algorithm));
|
||||
@ -373,7 +375,7 @@ void pki_x509req::load_spkac(const QString filename)
|
||||
bool spki_found =false;
|
||||
|
||||
try { // be aware of any exceptions
|
||||
parms=CONF_load(NULL,filename.latin1(),&errline);
|
||||
parms = CONF_load(NULL, CCHAR(filename),&errline);
|
||||
if (parms == NULL)
|
||||
openssl_error(QString("error on line %1 of %2\n")
|
||||
.arg(errline).arg(filename));
|
||||
@ -439,3 +441,22 @@ void pki_x509req::load_spkac(const QString filename)
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant pki_x509req::column_data(int col)
|
||||
{
|
||||
switch (col) {
|
||||
case 0:
|
||||
return QVariant(getIntName());
|
||||
case 1:
|
||||
return QVariant(getSubject().getEntryByNid(NID_commonName));
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
QVariant pki_x509req::getIcon()
|
||||
{
|
||||
int pixnum = 0;
|
||||
if (getRefKey() != NULL ) pixnum = 1;
|
||||
if (spki != NULL) pixnum = 2;
|
||||
return QVariant(*icon[pixnum]);
|
||||
}
|
||||
|
||||
|
||||
@ -35,8 +35,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -80,9 +78,9 @@ class pki_x509req : public pki_x509super
|
||||
void fload(const QString fname);
|
||||
void writeDefault(const QString fname);
|
||||
~pki_x509req();
|
||||
virtual void fromData(const unsigned char *p, int size);
|
||||
virtual unsigned char *toData(int *size);
|
||||
virtual bool compare(pki_base *refreq);
|
||||
void fromData(const unsigned char *p, db_header_t *head);
|
||||
unsigned char *toData(int *size);
|
||||
bool compare(pki_base *refreq);
|
||||
x509name getSubject() const;
|
||||
bool isSpki() const;
|
||||
void writeReq(const QString fname, bool PEM);
|
||||
@ -90,13 +88,14 @@ class pki_x509req : public pki_x509super
|
||||
pki_key *getPubKey() const;
|
||||
void createReq(pki_key *key, const x509name &dn, const EVP_MD *md,
|
||||
extList el);
|
||||
void updateView();
|
||||
QString getSigAlg();
|
||||
void setSubject(const x509name &n);
|
||||
/* SPKAC special functions */
|
||||
void setSPKIFromData(const unsigned char *p, int size);
|
||||
void setSPKIBase64(const char *p);
|
||||
void set_spki(NETSCAPE_SPKI *_spki);
|
||||
QVariant column_data(int col);
|
||||
QVariant getIcon();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -35,8 +35,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -48,8 +46,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "pki_x509super.h"
|
||||
|
||||
pki_x509super::pki_x509super(const QString name)
|
||||
@ -68,7 +64,7 @@ pki_x509super::~pki_x509super()
|
||||
x509name pki_x509super::getSubject() const
|
||||
{
|
||||
x509name x;
|
||||
printf("ERROR VIRTUAL getSubject() %s\n", class_name.latin1());
|
||||
printf("ERROR VIRTUAL getSubject() %s\n", class_name);
|
||||
openssl_error();
|
||||
return x;
|
||||
}
|
||||
@ -81,7 +77,7 @@ int pki_x509super::verify()
|
||||
|
||||
pki_key *pki_x509super::getPubKey() const
|
||||
{
|
||||
printf("ERROR VIRTUAL getPubKey() %s\n", class_name.latin1());
|
||||
printf("ERROR VIRTUAL getPubKey() %s\n", class_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -98,7 +94,7 @@ void pki_x509super::setRefKey(pki_key *ref)
|
||||
// this is our key
|
||||
privkey = ref;
|
||||
ref->incUcount();
|
||||
updateView();
|
||||
//updateView();
|
||||
}
|
||||
delete mk;
|
||||
}
|
||||
@ -108,7 +104,7 @@ void pki_x509super::delRefKey(pki_key *ref)
|
||||
if (ref != privkey || ref == NULL) return;
|
||||
ref->decUcount();
|
||||
privkey = NULL;
|
||||
updateView();
|
||||
//updateView();
|
||||
}
|
||||
|
||||
void pki_x509super::autoIntName()
|
||||
|
||||
@ -35,8 +35,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
|
||||
@ -188,7 +188,7 @@ int x509name::entryCount() const
|
||||
|
||||
int x509name::getNidByName(const QString &nid_name)
|
||||
{
|
||||
return OBJ_txt2nid((char*)nid_name.latin1());
|
||||
return OBJ_txt2nid(nid_name.toAscii());
|
||||
}
|
||||
|
||||
static int fix_data(int nid, int *type)
|
||||
@ -213,13 +213,13 @@ void x509name::addEntryByNid(int nid, const QString entry)
|
||||
// check for a UNICODE-String.
|
||||
bool need_uc=false;
|
||||
|
||||
for (unsigned i=0;i<entry.length();i++)
|
||||
for (int i=0;i<entry.length();i++)
|
||||
if(entry.at(i).unicode()>127) { need_uc=true; break; }
|
||||
|
||||
if (need_uc) {
|
||||
unsigned char *data = (unsigned char *)OPENSSL_malloc(entry.length()*2);
|
||||
|
||||
for (unsigned i=0;i<entry.length();i++) {
|
||||
for (int i=0;i<entry.length();i++) {
|
||||
data[2*i] = entry.at(i).unicode() >> 8;
|
||||
data[2*i+1] = entry.at(i).unicode() & 0xff;
|
||||
}
|
||||
@ -229,13 +229,13 @@ void x509name::addEntryByNid(int nid, const QString entry)
|
||||
OPENSSL_free(data);
|
||||
}
|
||||
else {
|
||||
int type=ASN1_PRINTABLE_type((unsigned char *)entry.latin1(),-1);
|
||||
const char *x = entry.toAscii();
|
||||
int type = ASN1_PRINTABLE_type((const unsigned char*)x,-1);
|
||||
|
||||
if (fix_data(nid, &type) == 0)
|
||||
return;
|
||||
|
||||
X509_NAME_add_entry_by_NID(xn, nid, type,
|
||||
(unsigned char*)entry.latin1(),-1,-1,0);
|
||||
X509_NAME_add_entry_by_NID(xn, nid, type, (unsigned char*)x,-1,-1,0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,7 +254,7 @@ void x509name::write_fp(FILE *fp) const
|
||||
int cnt = entryCount();
|
||||
for (int i=0; i<cnt; i++) {
|
||||
QStringList sl = entryList(i);
|
||||
fprintf(fp, "%s=%s\n",sl[0].latin1(), sl[2].latin1());
|
||||
fprintf(fp, "%s=%s\n",sl[0].data(), sl[2].data());
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,6 +263,6 @@ void x509name::read_fp(FILE *fp)
|
||||
char buf[180];
|
||||
QStringList sl;
|
||||
QString line = fgets(buf, 180, fp);
|
||||
sl.split('=', line),
|
||||
addEntryByNid(OBJ_sn2nid(sl[0].latin1()), sl[1]);
|
||||
sl = line.split('=');
|
||||
addEntryByNid(OBJ_sn2nid(sl[0].toAscii()), sl[1]);
|
||||
}
|
||||
|
||||
@ -52,8 +52,8 @@
|
||||
#ifndef X509NAME_H
|
||||
#define X509NAME_H
|
||||
|
||||
#include <qstring.h>
|
||||
#include <qstringlist.h>
|
||||
#include <Qt/qstring.h>
|
||||
#include <Qt/qstringlist.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
class x509name
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2001 Christian Hohnstaedt.
|
||||
*
|
||||
@ -35,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -50,8 +49,10 @@
|
||||
|
||||
#include "x509rev.h"
|
||||
|
||||
#define X509_REVOKED_dup(x5r) (X509_REVOKED *)ASN1_dup((int (*)())i2d_X509_REVOKED, \
|
||||
(char *(*)())d2i_X509_REVOKED,(char *)x5r)
|
||||
#define X509_REVOKED_dup(x5r) (X509_REVOKED *)ASN1_dup( \
|
||||
(int (*)(void*,unsigned char**))i2d_X509_REVOKED, \
|
||||
(void *(*)(void**, const unsigned char**, long int))d2i_X509_REVOKED, \
|
||||
(char *)x5r)
|
||||
|
||||
x509rev::x509rev()
|
||||
{
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2001 Christian Hohnstaedt.
|
||||
*
|
||||
@ -35,8 +36,6 @@
|
||||
* http://www.openssl.org which includes cryptographic software
|
||||
* written by Eric Young (eay@cryptsoft.com)"
|
||||
*
|
||||
* http://www.sleepycat.com
|
||||
*
|
||||
* http://www.trolltech.com
|
||||
*
|
||||
*
|
||||
@ -51,28 +50,28 @@
|
||||
#ifndef X509REV_H
|
||||
#define X509REV_H
|
||||
|
||||
#include <qstring.h>
|
||||
#include <Qt/qstring.h>
|
||||
#include <openssl/x509.h>
|
||||
#include "asn1time.h"
|
||||
#include "asn1int.h"
|
||||
|
||||
class x509rev
|
||||
{
|
||||
private:
|
||||
X509_REVOKED *rev;
|
||||
public:
|
||||
x509rev();
|
||||
x509rev(const X509_REVOKED *n);
|
||||
x509rev(const x509rev &n);
|
||||
~x509rev();
|
||||
x509rev &set(const X509_REVOKED *n);
|
||||
x509rev &operator = (const x509rev &x);
|
||||
bool operator == (const x509rev &x) const;
|
||||
void setSerial(const a1int &i);
|
||||
void setDate(const a1time &t);
|
||||
a1int getSerial() const;
|
||||
a1time getDate() const;
|
||||
X509_REVOKED *get() const;
|
||||
private:
|
||||
X509_REVOKED *rev;
|
||||
public:
|
||||
x509rev();
|
||||
x509rev(const X509_REVOKED *n);
|
||||
x509rev(const x509rev &n);
|
||||
~x509rev();
|
||||
x509rev &set(const X509_REVOKED *n);
|
||||
x509rev &operator = (const x509rev &x);
|
||||
bool operator == (const x509rev &x) const;
|
||||
void setSerial(const a1int &i);
|
||||
void setDate(const a1time &t);
|
||||
a1int getSerial() const;
|
||||
a1time getDate() const;
|
||||
X509_REVOKED *get() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -52,7 +52,8 @@
|
||||
#include "x509v3ext.h"
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/stack.h>
|
||||
#include <qstringlist.h>
|
||||
#include <Qt/qstringlist.h>
|
||||
#include "base.h"
|
||||
|
||||
x509v3ext::x509v3ext()
|
||||
{
|
||||
@ -90,7 +91,7 @@ x509v3ext &x509v3ext::create(int nid, const QString &et, X509V3_CTX *ctx)
|
||||
ext = NULL;
|
||||
}
|
||||
if (!et.isEmpty()) {
|
||||
ext = X509V3_EXT_conf_nid(NULL, ctx, nid, (char *)et.latin1());
|
||||
ext = X509V3_EXT_conf_nid(NULL, ctx, nid, (char*)CCHAR(et));
|
||||
}
|
||||
if (!ext) ext = X509_EXTENSION_new();
|
||||
return *this;
|
||||
@ -137,11 +138,7 @@ QString x509v3ext::getValue() const
|
||||
int len,cn=0;
|
||||
char buffer[V3_BUF+1];
|
||||
BIO *bio = BIO_new(BIO_s_mem());
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x0090700fL
|
||||
if(!X509V3_EXT_print(bio, ext, X509V3_EXT_PARSE_UNKNOWN, 0))
|
||||
#else
|
||||
if (!X509V3_EXT_print(bio, ext, 0, 0))
|
||||
#endif
|
||||
return text;
|
||||
do {
|
||||
len = BIO_read(bio, buffer, V3_BUF);
|
||||
@ -190,7 +187,7 @@ STACK_OF(X509_EXTENSION) *extList::getStack()
|
||||
{
|
||||
STACK_OF(X509_EXTENSION) *sk;
|
||||
sk = sk_X509_EXTENSION_new_null();
|
||||
for (unsigned int i=0; i< count(); i++) {
|
||||
for (int i=0; i< count(); i++) {
|
||||
sk_X509_EXTENSION_push(sk, operator[](i).get());
|
||||
}
|
||||
return sk;
|
||||
@ -200,7 +197,7 @@ QString extList::getHtml(const QString &sep)
|
||||
{
|
||||
x509v3ext e;
|
||||
QStringList s;
|
||||
for (unsigned int i=0; i< count(); i++)
|
||||
for (int i=0; i< count(); i++)
|
||||
s << operator[](i).getHtml();
|
||||
QString a = s.join(sep);
|
||||
return a;
|
||||
@ -212,7 +209,7 @@ int extList::delByNid(int nid)
|
||||
extList::Iterator it;
|
||||
for( it = begin(); it != end(); ++it ) {
|
||||
if ((*it).nid() == nid) {
|
||||
printf("Removing: %s\n", (*it).getValue().latin1());
|
||||
printf("Removing: %s\n", CCHAR((*it).getValue()));
|
||||
remove(it);
|
||||
it = begin();
|
||||
removed=1;
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
#ifndef X509V3EXT_H
|
||||
#define X509V3EXT_H
|
||||
|
||||
#include <qvaluelist.h>
|
||||
#include <Qt/q3valuelist.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
@ -80,7 +80,7 @@ class x509v3ext
|
||||
void *d2i();
|
||||
};
|
||||
|
||||
class extList : public QValueList<x509v3ext>
|
||||
class extList : public Q3ValueList<x509v3ext>
|
||||
{
|
||||
public:
|
||||
void setStack(STACK_OF(X509_EXTENSION) *st);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user