Kaynağa Gözat

Now accepting PUBLIC KEYs, as input to qa.

There is no time to change also tests, I am leaving them as they are.
BTW, now it is possible to operate with openssl just easily, for ex:
openssl genrsa | openssl rsa -pubout | qa
Michele Orrù 11 yıl önce
ebeveyn
işleme
cdbde25f04
2 değiştirilmiş dosya ile 44 ekleme ve 36 silme
  1. 10 34
      src/qa.c
  2. 34 2
      src/questions/allquestions.c

+ 10 - 34
src/qa.c

@@ -70,49 +70,25 @@ get_local_cert(const char *src)
 RSA*
 get_local_rsa(const char *src)
 {
-  RSA *rsa = NULL;
+  EVP_PKEY *pkey = NULL;
   FILE *fp;
 
   if (!strcmp(src, "-")) fp = stdin;
   else if (!(fp = fopen(src, "r")))
     return NULL;
 
-  rsa = PEM_read_RSAPublicKey(fp, &rsa, NULL, NULL);
-  return rsa;
-}
-
-/**
- * \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);
+  pkey = PEM_read_PUBKEY(fp, &pkey, NULL, NULL);
+  if (pkey == NULL)
+    return NULL;
+  if (pkey->type != EVP_PKEY_RSA) {
+    EVP_PKEY_free(pkey);
+    return NULL;
   }
+  return pkey->pkey.rsa;
+  // rsa = PEM_read_RSAPublicKey(fp, &rsa, NULL, NULL);
 }
 
+
 /**
  * \brief Given an initial configuration, stuctures the program flow.
  *

+ 34 - 2
src/questions/allquestions.c

@@ -48,6 +48,38 @@ 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.
@@ -74,8 +106,8 @@ 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);
+    print_rsa_private(priv);
 #endif
     RSA_free(priv);
     return 1;