output validity of raw public key if available
[strongswan.git] / src / libcharon / plugins / stroke / stroke_list.c
index 987475f..514a91e 100644 (file)
@@ -414,7 +414,6 @@ METHOD(stroke_list_t, status, void,
        if (all)
        {
                peer_cfg_t *peer_cfg;
-               plugin_t *plugin;
                char *pool;
                host_t *host;
                u_int32_t dpd;
@@ -449,14 +448,8 @@ METHOD(stroke_list_t, status, void,
                }
                fprintf(out, ", scheduled: %d\n",
                                lib->scheduler->get_job_load(lib->scheduler));
-               fprintf(out, "  loaded plugins: ");
-               enumerator = lib->plugins->create_plugin_enumerator(lib->plugins);
-               while (enumerator->enumerate(enumerator, &plugin, NULL))
-               {
-                       fprintf(out, "%s ", plugin->get_name(plugin));
-               }
-               enumerator->destroy(enumerator);
-               fprintf(out, "\n");
+               fprintf(out, "  loaded plugins: %s\n",
+                               lib->plugins->loaded_plugins(lib->plugins));
 
                first = TRUE;
                enumerator = this->attribute->create_pool_enumerator(this->attribute);
@@ -706,12 +699,14 @@ static void list_public_key(public_key_t *public, FILE *out)
 static void stroke_list_pubkeys(linked_list_t *list, bool utc, FILE *out)
 {
        bool first = TRUE;
-
-       enumerator_t *enumerator = list->create_enumerator(list);
+       time_t now = time(NULL), notBefore, notAfter;
+       enumerator_t *enumerator;
        certificate_t *cert;
 
+       enumerator = list->create_enumerator(list);
        while (enumerator->enumerate(enumerator, (void**)&cert))
        {
+               identification_t *subject = cert->get_subject(cert);
                public_key_t *public = cert->get_public_key(cert);
 
                if (public)
@@ -724,6 +719,41 @@ static void stroke_list_pubkeys(linked_list_t *list, bool utc, FILE *out)
                        }
                        fprintf(out, "\n");
 
+                       /* list subject if available */
+                       if (subject->get_type(subject) != ID_KEY_ID)
+                       {
+                               fprintf(out, "  subject:   %#Y\n", subject);
+                       }
+
+                       /* list validity if available*/
+                       cert->get_validity(cert, &now, &notBefore, &notAfter);
+                       if (notBefore != UNDEFINED_TIME && notAfter != UNDEFINED_TIME)
+                       {
+                               fprintf(out, "  validity:  not before %T, ", &notBefore, utc);
+                               if (now < notBefore)
+                               {
+                                       fprintf(out, "not valid yet (valid in %V)\n", &now, &notBefore);
+                               }
+                               else
+                               {
+                                       fprintf(out, "ok\n");
+                               }
+                               fprintf(out, "             not after  %T, ", &notAfter, utc);
+                               if (now > notAfter)
+                               {
+                                       fprintf(out, "expired (%V ago)\n", &now, &notAfter);
+                               }
+                               else
+                               {
+                                       fprintf(out, "ok");
+                                       if (now > notAfter - CERT_WARNING_INTERVAL * 60 * 60 * 24)
+                                       {
+                                               fprintf(out, " (expires in %V)", &now, &notAfter);
+                                       }
+                                       fprintf(out, " \n");
+                               }
+                       }
+
                        list_public_key(public, out);
                        public->destroy(public);
                }
@@ -840,7 +870,7 @@ static void stroke_list_certs(linked_list_t *list, char *label,
 
                        fprintf(out, "  subject:  \"%Y\"\n", cert->get_subject(cert));
                        fprintf(out, "  issuer:   \"%Y\"\n", cert->get_issuer(cert));
-                       serial = x509->get_serial(x509);
+                       serial = chunk_skip_zero(x509->get_serial(x509));
                        fprintf(out, "  serial:    %#B\n", &serial);
 
                        /* list validity */
@@ -953,7 +983,7 @@ static void stroke_list_acerts(linked_list_t *list, bool utc, FILE *out)
                {
                        fprintf(out, "  hissuer:  \"%Y\"\n", id);
                }
-               chunk = ac->get_holderSerial(ac);
+               chunk = chunk_skip_zero(ac->get_holderSerial(ac));
                if (chunk.ptr)
                {
                        fprintf(out, "  hserial:   %#B\n", &chunk);
@@ -965,7 +995,7 @@ static void stroke_list_acerts(linked_list_t *list, bool utc, FILE *out)
                        groups->destroy(groups);
                }
                fprintf(out, "  issuer:   \"%Y\"\n", cert->get_issuer(cert));
-               chunk  = ac->get_serial(ac);
+               chunk  = chunk_skip_zero(ac->get_serial(ac));
                fprintf(out, "  serial:    %#B\n", &chunk);
 
                /* list validity */
@@ -1022,13 +1052,14 @@ static void stroke_list_crls(linked_list_t *list, bool utc, FILE *out)
                fprintf(out, "  issuer:   \"%Y\"\n", cert->get_issuer(cert));
 
                /* list optional crlNumber */
-               chunk = crl->get_serial(crl);
+               chunk = chunk_skip_zero(crl->get_serial(crl));
                if (chunk.ptr)
                {
                        fprintf(out, "  serial:    %#B\n", &chunk);
                }
                if (crl->is_delta_crl(crl, &chunk))
                {
+                       chunk = chunk_skip_zero(chunk);         
                        fprintf(out, "  delta for: %#B\n", &chunk);
                }
 
@@ -1220,7 +1251,8 @@ static void list_plugins(FILE *out)
        char *str;
 
        fprintf(out, "\n");
-       fprintf(out, "List of loaded plugins:\n");
+       fprintf(out, "List of loaded Plugins:\n");
+       fprintf(out, "\n");
 
        enumerator = lib->plugins->create_plugin_enumerator(lib->plugins);
        while (enumerator->enumerate(enumerator, &plugin, &list))