Selaa lähdekoodia

Back to printing the RSA private key in PEM when in debug mode.

Try it!
$ ./src/qa -f ./src/questions/tests/pollard.pem | openssl rsa -text
Michele Orrù 11 vuotta sitten
vanhempi
commit
8605e44394
3 muutettua tiedostoa jossa 5 lisäystä ja 35 poistoa
  1. 1 1
      src/qa.c
  2. 1 34
      src/questions/allquestions.c
  3. 3 0
      src/questions/qarith.c

+ 1 - 1
src/qa.c

@@ -85,7 +85,7 @@ get_local_rsa(const char *src)
     return NULL;
   }
   return pkey->pkey.rsa;
-  // rsa = PEM_read_RSAPublicKey(fp, &rsa, NULL, NULL);
+  /* rsa = PEM_read_RSAPublicKey(fp, &rsa, NULL, NULL); */
 }
 
 

+ 1 - 34
src/questions/allquestions.c

@@ -48,38 +48,6 @@ void select_question(const char *sq)
 }
 
 
-/**
- * \brief Print out a valid RSA Private Key.
- *
- */
-static void
-print_rsa_private(RSA *rsa)
-{
-  size_t i;
-  char *dec, *hex;
-  const struct {
-    const char *desc;
-    BIGNUM *n;
-  } items[5] = {
-    {"Public Modulus", rsa->n},
-    {"Prime Factor p", rsa->p},
-    {"Prime Factor q", rsa->q},
-    {"Public Exponent", rsa->e},
-    {"Private Exponent", rsa->d},
-  };
-
-
-  assert(rsa); /* && rsa->p && rsa->q && rsa->e); */
-  for (i=0; i!=5; i++) {
-    if (!items[i].n) continue;
-    dec = BN_bn2dec(items[i].n);
-    hex = BN_bn2hex(items[i].n);
-    fprintf(stdout, "\t%-22s : %-15s (0x%s)\n", items[i].desc, dec, hex);
-    OPENSSL_free(dec);
-    OPENSSL_free(hex);
-  }
-}
-
 /**
  * \brief Run a specific question, returning the measure of security probed.
  * \return -1 if the question `q` is not suited for attacking the certificate.
@@ -106,8 +74,7 @@ int run_question(qa_question_t *q, X509 *crt, RSA *pub)
   if (q->ask_rsa &&
       (priv = q->ask_rsa(pub))) {
 #ifdef DEBUG
-    //PEM_write_RSAPrivateKey(stdout, priv, NULL, NULL, 0, NULL, NULL);
-    print_rsa_private(priv);
+    PEM_write_RSAPrivateKey(stdout, priv, NULL, NULL, 0, NULL, NULL);
 #endif
     RSA_free(priv);
     return 1;

+ 3 - 0
src/questions/qarith.c

@@ -234,8 +234,11 @@ RSA* qa_RSA_recover(const RSA *rsapub,
   rsapriv->d = BN_new();
   BN_mod_inverse(rsapriv->d, rsapriv->e, phi, ctx);
   /* some other openssl shit */
+  rsapriv->dmq1 = BN_new();
   BN_mod(rsapriv->dmq1, rsapriv->d, q1, ctx);
+  rsapriv->dmp1 = BN_new();
   BN_mod(rsapriv->dmp1, rsapriv->d, p1, ctx);
+  rsapriv->iqmp = BN_new();
   BN_mod_inverse(rsapriv->iqmp, rsapriv->q, rsapriv->p, ctx);
 
  end: