subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject svn commit: r1617095 - in /subversion/branches/svn-auth-x509/subversion: include/svn_x509.h libsvn_subr/x509info.c svn/auth-cmd.c tests/libsvn_subr/x509-test.c
Date Sun, 10 Aug 2014 11:26:13 GMT
Author: ivan
Date: Sun Aug 10 11:26:12 2014
New Revision: 1617095

URL: http://svn.apache.org/r1617095
Log:
On svn-auth-x509 branch: format cert fingerprints in the traditional style.
I.E. upper-case hex digits, colon separated every 2 bytes of the hex output.

* subversion/include/svn_x509.h
* subversion/libsvn_subr/x509info.c
  (): Include <apr_md5.h>, <apr_sha1.h> and <svn_string.h>
  (svn_x509_fingerprint_to_display): New function for formatting certificate
   fingerprints.

* subversion/svn/auth-cmd.c
  (show_cert): Use svn_x509_fingerprint_to_display() instead of 
   svn_checksum_to_cstring_display().

* subversion/tests/libsvn_subr/x509-test.c
  (test_svn_x509_fingerprint_to_display): New test for 
   svn_x509_fingerprint_to_display().
  (test_funcs): Add test_svn_x509_fingerprint_to_display to test list.

Modified:
    subversion/branches/svn-auth-x509/subversion/include/svn_x509.h
    subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509info.c
    subversion/branches/svn-auth-x509/subversion/svn/auth-cmd.c
    subversion/branches/svn-auth-x509/subversion/tests/libsvn_subr/x509-test.c

Modified: subversion/branches/svn-auth-x509/subversion/include/svn_x509.h
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/include/svn_x509.h?rev=1617095&r1=1617094&r2=1617095&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/include/svn_x509.h (original)
+++ subversion/branches/svn-auth-x509/subversion/include/svn_x509.h Sun Aug 10 11:26:12 2014
@@ -123,6 +123,15 @@ svn_x509_certinfo_get_digest(const svn_x
 const apr_array_header_t *
 svn_x509_certinfo_get_hostnames(const svn_x509_certinfo_t *certinfo);
 
+/** Return the properly formatted representation of a certificate
+ * @a fingerprint, allocating the string in @a pool.
+ *
+ * @since New in 1.9.
+ */
+const char *
+svn_x509_fingerprint_to_display(const svn_checksum_t *fingerprint,
+                                apr_pool_t *pool);
+
 #ifdef __cplusplus
 }
 #endif

Modified: subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509info.c
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509info.c?rev=1617095&r1=1617094&r2=1617095&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509info.c (original)
+++ subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509info.c Sun Aug 10 11:26:12
2014
@@ -27,6 +27,9 @@
 
 #include <apr_pools.h>
 #include <apr_tables.h>
+#include <apr_md5.h>
+#include <apr_sha1.h>
+#include <svn_string.h>
 
 #include "svn_x509.h"
 #include "x509.h"
@@ -97,3 +100,33 @@ svn_x509_certinfo_get_hostnames(const sv
 {
   return certinfo->hostnames;
 }
+
+const char *
+svn_x509_fingerprint_to_display(const svn_checksum_t *fingerprint,
+                                apr_pool_t *pool)
+{
+  static const char *hex = "0123456789ABCDEF";
+  apr_size_t digest_size;
+  apr_size_t i;
+  svn_stringbuf_t *buf;
+
+  if (fingerprint->kind == svn_checksum_md5)
+    digest_size = APR_MD5_DIGESTSIZE;
+  else if(fingerprint->kind == svn_checksum_sha1)
+    digest_size = APR_SHA1_DIGESTSIZE;
+  else
+    return NULL;
+
+  buf = svn_stringbuf_create_ensure(digest_size * 3, pool);
+
+  for (i = 0; i < digest_size; i++)
+    {
+      if (i > 0)
+        svn_stringbuf_appendbyte(buf, ':');
+
+      svn_stringbuf_appendbyte(buf, hex[fingerprint->digest[i] >> 4]);
+      svn_stringbuf_appendbyte(buf, hex[fingerprint->digest[i] & 0x0f]);
+    }
+
+  return buf->data;
+}

Modified: subversion/branches/svn-auth-x509/subversion/svn/auth-cmd.c
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/svn/auth-cmd.c?rev=1617095&r1=1617094&r2=1617095&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/svn/auth-cmd.c (original)
+++ subversion/branches/svn-auth-x509/subversion/svn/auth-cmd.c Sun Aug 10 11:26:12 2014
@@ -193,7 +193,7 @@ show_cert(const svn_string_t *pem_cert, 
   SVN_ERR(svn_cmdline_printf(scratch_pool, _("Issuer: %s\n"),
                              svn_x509_certinfo_get_issuer(certinfo)));
   SVN_ERR(svn_cmdline_printf(scratch_pool, _("Fingerprint: %s\n"),
-                             svn_checksum_to_cstring_display(
+                             svn_x509_fingerprint_to_display(
                                  svn_x509_certinfo_get_digest(certinfo),
                                  scratch_pool)));
 

Modified: subversion/branches/svn-auth-x509/subversion/tests/libsvn_subr/x509-test.c
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/tests/libsvn_subr/x509-test.c?rev=1617095&r1=1617094&r2=1617095&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/tests/libsvn_subr/x509-test.c (original)
+++ subversion/branches/svn-auth-x509/subversion/tests/libsvn_subr/x509-test.c Sun Aug 10
11:26:12 2014
@@ -515,7 +515,27 @@ test_x509_parse_cert(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
-
+static svn_error_t *
+test_svn_x509_fingerprint_to_display(apr_pool_t *pool)
+{
+  svn_checksum_t *md5_fingerprint;
+  svn_checksum_t *sha1_fingerprint;
+
+  SVN_ERR(svn_checksum_parse_hex(&md5_fingerprint, svn_checksum_md5,
+                                 "8518b76f7a45fe4de2d0955085b41f98", pool));
+  SVN_ERR(svn_checksum_parse_hex(&sha1_fingerprint, svn_checksum_sha1,
+                                 "74d82379bcc6771454377db03b912c2b62704139", pool));
+
+  SVN_TEST_STRING_ASSERT(
+    svn_x509_fingerprint_to_display(md5_fingerprint, pool),
+    "85:18:B7:6F:7A:45:FE:4D:E2:D0:95:50:85:B4:1F:98");
+
+  SVN_TEST_STRING_ASSERT(
+    svn_x509_fingerprint_to_display(sha1_fingerprint, pool),
+    "74:D8:23:79:BC:C6:77:14:54:37:7D:B0:3B:91:2C:2B:62:70:41:39");
+
+  return SVN_NO_ERROR;
+}
 /* The test table.  */
 
 static int max_threads = 1;
@@ -525,6 +545,8 @@ static struct svn_test_descriptor_t test
     SVN_TEST_NULL,
     SVN_TEST_PASS2(test_x509_parse_cert,
                    "test svn_x509_parse_cert"),
+    SVN_TEST_PASS2(test_svn_x509_fingerprint_to_display,
+                   "test svn_x509_fingerprint_to_display"),
     SVN_TEST_NULL
   };
 



Mime
View raw message