mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Refactor OID loading
The OID resolver now finds oids independent of the capitalization
This commit is contained in:
parent
07cd638537
commit
a8f54c82eb
164
lib/oid.cpp
164
lib/oid.cpp
@ -20,90 +20,100 @@
|
||||
int first_additional_oid = 0;
|
||||
|
||||
QMap<QString,const char*> oid_name_clash;
|
||||
QMap<QString,int> oid_lower_map;
|
||||
|
||||
static void addToLowerMap(int nid)
|
||||
{
|
||||
QString n = OBJ_nid2sn(nid);
|
||||
QString l = n.toLower();
|
||||
|
||||
if (n != l)
|
||||
oid_lower_map[l] = nid;
|
||||
n = OBJ_nid2ln(nid);
|
||||
l = n.toLower();
|
||||
if (n != l)
|
||||
oid_lower_map[l] = nid;
|
||||
}
|
||||
|
||||
/* reads additional OIDs from a file: oid, sn, ln */
|
||||
static void insert_new_oid(const QStringList &sl, QString fname, int line)
|
||||
{
|
||||
bool differs = false;
|
||||
QByteArray in_use, oid, sn, ln;
|
||||
|
||||
oid = sl[0].toLatin1();
|
||||
sn = sl[1].toLatin1();
|
||||
ln = sl[2].toLatin1();
|
||||
if (sl.count() != 3) {
|
||||
XCA_WARN(QObject::tr("Error reading config file %1 at line %2")
|
||||
.arg(fname).arg(line));
|
||||
return;
|
||||
}
|
||||
|
||||
int nid = OBJ_txt2nid(oid.constData());
|
||||
if (nid != NID_undef) {
|
||||
/* OID already known by OpenSSL */
|
||||
if (sn != OBJ_nid2sn(nid)) {
|
||||
/* ... but with a different ShortName */
|
||||
qWarning() << "OID: " << oid << "SN differs: " << sn <<
|
||||
" " << OBJ_nid2sn(nid);
|
||||
oid_name_clash[sn] = OBJ_nid2sn(nid);
|
||||
differs = true;
|
||||
}
|
||||
if (ln != OBJ_nid2ln(nid)) {
|
||||
/* ... but with a different LongName */
|
||||
qWarning() << "OID: " << oid << "LN differs: " << ln <<
|
||||
" " << OBJ_nid2ln(nid);
|
||||
oid_name_clash[ln] = OBJ_nid2ln(nid);
|
||||
differs = true;
|
||||
}
|
||||
} else {
|
||||
/* Check whether ShortName or LongName are already in use
|
||||
* for a different OID */
|
||||
if (OBJ_txt2nid(sn.constData()) != NID_undef)
|
||||
in_use = sn;
|
||||
if (OBJ_txt2nid(ln.constData()) != NID_undef)
|
||||
in_use = ln;
|
||||
}
|
||||
ign_openssl_error();
|
||||
if (differs) {
|
||||
/* OID exists with different SN or LN. The differing names
|
||||
* are added as "alias" in "oid_name_clash" used when loading
|
||||
* dn.txt and eku.txt */
|
||||
XCA_WARN(QObject::tr("The Object '%1' from file %2 line %3 is already known as '%4:%5:%6' and should be removed.")
|
||||
.arg(sl.join(":")).arg(fname).arg(line)
|
||||
.arg(OBJ_obj2QString(OBJ_nid2obj(nid), 1))
|
||||
.arg(OBJ_nid2sn(nid)).arg(OBJ_nid2ln(nid))
|
||||
);
|
||||
} else if (!in_use.isEmpty()) {
|
||||
nid = OBJ_txt2nid(in_use.constData());
|
||||
XCA_WARN(QObject::tr("The identifier '%1' for OID %2 from file %3 line %4 is already used for a different OID as '%5:%6:%7' and should be changed to avoid conflicts.")
|
||||
.arg(in_use.constData())
|
||||
.arg(oid.constData())
|
||||
.arg(fname).arg(line)
|
||||
.arg(OBJ_obj2QString(OBJ_nid2obj(nid), 1))
|
||||
.arg(OBJ_nid2sn(nid)).arg(OBJ_nid2ln(nid))
|
||||
);
|
||||
} else {
|
||||
nid=OBJ_create(oid.constData(), sn.constData(), ln.constData());
|
||||
addToLowerMap(nid);
|
||||
}
|
||||
}
|
||||
|
||||
static void readOIDs(QString fname)
|
||||
{
|
||||
char buff[128];
|
||||
QString pb;
|
||||
FILE *fp;
|
||||
int line = 0;
|
||||
QStringList sl;
|
||||
|
||||
fp = fopen_read(fname);
|
||||
if (fp == NULL)
|
||||
return;
|
||||
|
||||
while (fgets(buff, 127, fp)) {
|
||||
QFile file(fname);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return;
|
||||
QTextStream in(&file);
|
||||
while (!in.atEnd()) {
|
||||
QString entry = in.readLine().trimmed();
|
||||
line++;
|
||||
pb = buff;
|
||||
pb = pb.trimmed();
|
||||
if (pb.startsWith('#') || pb.size() == 0)
|
||||
if (entry.startsWith('#') || entry.isEmpty())
|
||||
continue;
|
||||
sl.clear();
|
||||
sl = pb.split(QRegExp("\\s*:\\s*"));
|
||||
if (sl.count() != 3) {
|
||||
XCA_WARN(QObject::tr("Error reading config file %1 at line %2")
|
||||
.arg(fname).arg(line));
|
||||
fclose(fp);
|
||||
return;
|
||||
} else {
|
||||
bool differs = false;
|
||||
QByteArray in_use, oid, sn, ln;
|
||||
|
||||
oid = sl[0].toLatin1();
|
||||
sn = sl[1].toLatin1();
|
||||
ln = sl[2].toLatin1();
|
||||
|
||||
int nid = OBJ_txt2nid(oid.constData());
|
||||
if (nid != NID_undef) {
|
||||
if (sn != OBJ_nid2sn(nid)) {
|
||||
qWarning() << "OID: " << oid <<
|
||||
"SN differs: " << sn <<
|
||||
" " << OBJ_nid2sn(nid);
|
||||
oid_name_clash[sn] = OBJ_nid2sn(nid);
|
||||
differs = true;
|
||||
}
|
||||
if (ln != OBJ_nid2ln(nid)) {
|
||||
printf("%s LN differs: '%s' '%s'\n",
|
||||
oid.constData(), ln.constData(),
|
||||
OBJ_nid2ln(nid));
|
||||
qWarning() << "OID: " << oid <<
|
||||
"LN differs: " << ln <<
|
||||
" " << OBJ_nid2ln(nid);
|
||||
oid_name_clash[ln] = OBJ_nid2ln(nid);
|
||||
differs = true;
|
||||
}
|
||||
} else {
|
||||
if (OBJ_txt2nid(sn.constData()) != NID_undef)
|
||||
in_use = sn;
|
||||
if (OBJ_txt2nid(ln.constData()) != NID_undef)
|
||||
in_use = ln;
|
||||
}
|
||||
ign_openssl_error();
|
||||
if (differs) {
|
||||
XCA_WARN(QObject::tr("The Object '%1' from file %2 line %3 is already known as '%4:%5:%6' and should be removed.")
|
||||
.arg(sl.join(":")).arg(fname).arg(line)
|
||||
.arg(OBJ_obj2QString(OBJ_nid2obj(nid), 1))
|
||||
.arg(OBJ_nid2sn(nid)).arg(OBJ_nid2ln(nid))
|
||||
);
|
||||
} else if (!in_use.isEmpty()) {
|
||||
nid = OBJ_txt2nid(in_use.constData());
|
||||
XCA_WARN(QObject::tr("The identifier '%1' for OID %2 from file %3 line %4 is already used for a different OID as '%5:%6:%7' and should be changed to avoid conflicts.")
|
||||
.arg(in_use.constData())
|
||||
.arg(oid.constData())
|
||||
.arg(fname).arg(line)
|
||||
.arg(OBJ_obj2QString(OBJ_nid2obj(nid), 1))
|
||||
.arg(OBJ_nid2sn(nid)).arg(OBJ_nid2ln(nid))
|
||||
);
|
||||
} else {
|
||||
OBJ_create(oid.constData(), sn.constData(),
|
||||
ln.constData());
|
||||
}
|
||||
}
|
||||
insert_new_oid(entry.split(QRegExp("\\s*:\\s*")), fname, line);
|
||||
}
|
||||
fclose(fp);
|
||||
ign_openssl_error();
|
||||
}
|
||||
|
||||
void initOIDs()
|
||||
@ -112,6 +122,8 @@ void initOIDs()
|
||||
QString dir = getPrefix();
|
||||
|
||||
first_additional_oid = OBJ_new_nid(0);
|
||||
for (int i=0; i<first_additional_oid;i++)
|
||||
addToLowerMap(i);
|
||||
readOIDs(dir + oids);
|
||||
#if !defined(Q_OS_WIN32)
|
||||
#if !defined(Q_OS_MAC)
|
||||
|
||||
@ -14,6 +14,7 @@ class QString;
|
||||
|
||||
extern int first_additional_oid;
|
||||
extern QMap<QString,const char*> oid_name_clash;
|
||||
extern QMap<QString,int> oid_lower_map;
|
||||
|
||||
typedef QList<int> NIDlist;
|
||||
/* reads additional OIDs from a file: oid, sn, ln */
|
||||
|
||||
@ -35,6 +35,11 @@ void OidResolver::searchOid(QString s)
|
||||
if (clash)
|
||||
n = OBJ_txt2nid(clash);
|
||||
}
|
||||
QString lo = s.toLower();
|
||||
if (n == NID_undef && s != lo)
|
||||
n = OBJ_txt2nid(CCHAR(lo));
|
||||
if (n == NID_undef && oid_lower_map.contains(lo))
|
||||
n = oid_lower_map[lo];
|
||||
ign_openssl_error();
|
||||
if (n == NID_undef) {
|
||||
ln->clear();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user