Procházet zdrojové kódy

Stupid cleanup, attempting to create a real certificate from gen app.

* Still have to dig deeper inside openssl to understand how to generate x509
  certificates, committing a not-working version of gen.
* Trivial cleanup.
Michele Orrù před 11 roky
rodič
revize
39eddfceee
3 změnil soubory, kde provedl 25 přidání a 6 odebrání
  1. 14 3
      src/apps/gen.c
  2. 2 2
      src/qa.c
  3. 9 1
      src/questions/test/test_wiener.c

+ 14 - 3
src/apps/gen.c

@@ -42,7 +42,7 @@ int main(int argc, char **argv)
     usage();
     return EXIT_FAILURE;
   }
-
+  /* generating RSA key */
   BN_dec2bn(&rsa->e, argv[1]);
   BN_dec2bn(&rsa->d, argv[2]);
   BN_dec2bn(&rsa->p, argv[3]);
@@ -53,13 +53,24 @@ int main(int argc, char **argv)
   BN_mod(rsa->dmq1, rsa->d, q1, ctx);
   BN_mod(rsa->dmp1, rsa->d, p1, ctx);
   BN_mod_inverse(rsa->iqmp, rsa->q, rsa->p, ctx);
-  PEM_write_RSAPrivateKey(stdout, rsa, NULL, NULL, 0, NULL, NULL);
+  /* PEM_write_RSAPrivateKey(stdout, rsa, NULL, NULL, 0, NULL, NULL); */
 
+  /* creating public key */
+  EVP_PKEY *pk;
+  pk = EVP_PKEY_new();
+  EVP_PKEY_set1_RSA(pk, rsa);
 
+  /* creating dummy certificate */
+  X509* crt;
+  crt = X509_new();
+  if (!X509_set_pubkey(crt, pk)) exit(EXIT_FAILURE);
+  PEM_write_X509(stdout, crt);
+  X509_free(crt);
+  EVP_PKEY_free(pk);
   BN_CTX_free(ctx);
   BN_free(q1);
   BN_free(p1);
   RSA_free(rsa);
 
-  return 0;
+  return EXIT_SUCCESS;
 }

+ 2 - 2
src/qa.c

@@ -28,8 +28,8 @@ void qa_abort(const char *reason)
 
 X509* get_local_cert(const char *src)
 {
-  X509* crt;
-  FILE* fp;
+  X509 *crt;
+  FILE *fp;
 
   if (!strcmp(src, "-")) fp = stdin;
   else if (!(fp = fopen(src, "r")))

+ 9 - 1
src/questions/test/test_wiener.c

@@ -1,12 +1,20 @@
 #include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <libgen.h>
 #include <math.h>
+#include <string.h>
+
+#include <openssl/x509.h>
+#include <openssl/pem.h>
 
 #include "questions.h"
 #include "qwiener.h"
 
-
 /**
  * \brief Testing the continued fractions generator.
+ *
+ *
  */
 void test_cf(void)
 {