svn rev #24194: branches/krb5-1-8/src/plugins/preauth/pkinit/

tlyu@MIT.EDU tlyu at MIT.EDU
Tue Jul 20 18:28:36 EDT 2010


http://src.mit.edu/fisheye/changelog/krb5/?cs=24194
Commit By: tlyu
Log Message:
ticket: 6738
version_fixed: 1.8.3
status: resolved

pull up r24137 from trunk

 ------------------------------------------------------------------------
 r24137 | ghudson | 2010-06-14 16:46:27 -0400 (Mon, 14 Jun 2010) | 7 lines

 ticket: 6738
 target_version: 1.8.3
 tags: pullup

 In PKINIT, notice if DH_compute_key() returns a value less than the
 buffer size, and pad it on the left if so.


Changed Files:
U   branches/krb5-1-8/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
Modified: branches/krb5-1-8/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
===================================================================
--- branches/krb5-1-8/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c	2010-07-20 08:52:41 UTC (rev 24193)
+++ branches/krb5-1-8/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c	2010-07-20 22:28:35 UTC (rev 24194)
@@ -2092,6 +2092,22 @@
     return retval;
 }
 
+/* Call DH_compute_key() and ensure that we left-pad short results instead of
+ * leaving junk bytes at the end of the buffer. */
+static void
+compute_dh(unsigned char *buf, int size, BIGNUM *server_pub_key, DH *dh)
+{
+    int len, pad;
+
+    len = DH_compute_key(buf, server_pub_key, dh);
+    assert(len >= 0 && len <= size);
+    if (len < size) {
+        pad = size - len;
+        memmove(buf + pad, buf, len);
+        memset(buf, 0, pad);
+    }
+}
+
 krb5_error_code
 client_create_dh(krb5_context context,
                  pkinit_plg_crypto_context plg_cryptoctx,
@@ -2243,7 +2259,7 @@
     if ((server_pub_key = ASN1_INTEGER_to_BN(pub_key, NULL)) == NULL)
         goto cleanup;
 
-    DH_compute_key(*client_key, server_pub_key, cryptoctx->dh);
+    compute_dh(*client_key, *client_key_len, server_pub_key, cryptoctx->dh);
 #ifdef DEBUG_DH
     print_pubkey(server_pub_key, "server's pub_key=");
     pkiDebug("client secret key (%d)= ", *client_key_len);
@@ -2378,7 +2394,7 @@
     *server_key_len = DH_size(dh_server);
     if ((*server_key = malloc(*server_key_len)) == NULL)
         goto cleanup;
-    DH_compute_key(*server_key, dh->pub_key, dh_server);
+    compute_dh(*server_key, *server_key_len, dh->pub_key, dh_server);
 
 #ifdef DEBUG_DH
     print_dh(dh_server, "client&server's DH params\n");




More information about the cvs-krb5 mailing list