SSL: Store x509 name entries that have no short name as their OID.
authorRichard Moore <rich@kde.org>
Mon, 11 Jul 2011 14:15:12 +0000 (16:15 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 11 Jul 2011 15:32:47 +0000 (17:32 +0200)
Previously, x509 name entries that didn't have a shortname would all be
(accidentally) stored with the tag 'UNDEF'. This commit changes things
so that they are stored using the string form of their OID.

Change-Id: I667306cc4f91b1ca84f29b986bc21daadeb089b6
Merge-request: 18
Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
Reviewed-on: http://codereview.qt.nokia.com/1449
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
src/network/ssl/qsslcertificate.cpp
src/network/ssl/qsslsocket_openssl_symbols.cpp
src/network/ssl/qsslsocket_openssl_symbols_p.h

index 7403590..4f7c86e 100644 (file)
@@ -711,12 +711,24 @@ static QMap<QString, QString> _q_mapFromX509Name(X509_NAME *name)
     QMap<QString, QString> info;
     for (int i = 0; i < q_X509_NAME_entry_count(name); ++i) {
         X509_NAME_ENTRY *e = q_X509_NAME_get_entry(name, i);
-        const char *obj = q_OBJ_nid2sn(q_OBJ_obj2nid(q_X509_NAME_ENTRY_get_object(e)));
+
+        int nid = q_OBJ_obj2nid(q_X509_NAME_ENTRY_get_object(e));
+        const char *obj=0;
+        char buf[80];
+        if (nid != NID_undef) {
+            obj = q_OBJ_nid2sn(nid);
+        }
+        else {
+            // This is used for unknown info so we get the OID as text
+            q_i2t_ASN1_OBJECT(buf,sizeof(buf),e->object);
+        }
         unsigned char *data = 0;
         int size = q_ASN1_STRING_to_UTF8(&data, q_X509_NAME_ENTRY_get_data(e));
-        info.insertMulti(QString::fromUtf8(obj), QString::fromUtf8((char*)data, size));
+        info.insertMulti(QString::fromUtf8(obj ? obj : reinterpret_cast<const char *>(&buf)),
+                         QString::fromUtf8((char*)data, size));
         q_CRYPTO_free(data);
     }
+
     return info;
 }
 
index 18a845b..31afab0 100644 (file)
@@ -133,6 +133,10 @@ DEFINEFUNC(EVP_PKEY *, EVP_PKEY_new, DUMMYARG, DUMMYARG, return 0, return)
 DEFINEFUNC(int, EVP_PKEY_type, int a, a, return NID_undef, return)
 DEFINEFUNC2(int, i2d_X509, X509 *a, a, unsigned char **b, b, return -1, return)
 DEFINEFUNC(const char *, OBJ_nid2sn, int a, a, return 0, return)
+DEFINEFUNC(const char *, OBJ_nid2ln, int a, a, return 0, return)
+DEFINEFUNC3(int, i2t_ASN1_OBJECT, char *a, a, int b, b, ASN1_OBJECT *c, c, return -1, return)
+
+
 DEFINEFUNC(int, OBJ_obj2nid, const ASN1_OBJECT *a, a, return NID_undef, return)
 #ifdef SSLEAY_MACROS
 DEFINEFUNC6(void *, PEM_ASN1_read_bio, d2i_of_void *a, a, const char *b, b, BIO *c, c, void **d, d, pem_password_cb *e, e, void *f, f, return 0, return)
@@ -688,6 +692,8 @@ bool q_resolveOpenSslSymbols()
     RESOLVEFUNC(EVP_PKEY_new)
     RESOLVEFUNC(EVP_PKEY_type)
     RESOLVEFUNC(OBJ_nid2sn)
+    RESOLVEFUNC(OBJ_nid2ln)
+    RESOLVEFUNC(i2t_ASN1_OBJECT)
     RESOLVEFUNC(OBJ_obj2nid)
 #ifdef SSLEAY_MACROS // ### verify
     RESOLVEFUNC(PEM_ASN1_read_bio)
index 12b3890..cd3aa07 100644 (file)
@@ -237,6 +237,8 @@ int q_EVP_PKEY_type(int a);
 EVP_PKEY *q_EVP_PKEY_new();
 int q_i2d_X509(X509 *a, unsigned char **b);
 const char *q_OBJ_nid2sn(int a);
+const char *q_OBJ_nid2ln(int a);
+int q_i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *obj);
 int q_OBJ_obj2nid(const ASN1_OBJECT *a);
 #ifdef SSLEAY_MACROS
 // ### verify