Command line support for RSAPublicKey format.
authorDr. Stephen Henson <steve@openssl.org>
Sun, 21 Aug 2005 00:18:26 +0000 (00:18 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sun, 21 Aug 2005 00:18:26 +0000 (00:18 +0000)
CHANGES
apps/apps.c
apps/apps.h
apps/rsa.c

diff --git a/CHANGES b/CHANGES
index c9058ff939c4b147df6e3d524fc5ded349b64e26..c58c811f4002dd7dcec9c10c0e4a4c92001444e0 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,9 +4,13 @@
 
  Changes between 0.9.8 and 0.9.9  [xx XXX xxxx]
 
+  *) Support for PKCS#1 RSAPublicKey format on rsa utility command line.
+     [Steve Henson]
+
   *) Remove the ancient ASN1_METHOD code. This was only ever used in one
      place for the (very old) "NETSCAPE" format certificates which are now
      handled using new ASN1 code equivalents.
+     [Steve Henson]
 
   *) Let the TLSv1_method() etc. functions return a 'const' SSL_METHOD
      pointer and make the SSL_METHOD parameter in SSL_CTX_new,
index 20d3488a1689fe055ace7d762344740c87a45e4c..59867cc3338bd184d70032e3e82d6106a7ef8c30 100644 (file)
@@ -940,6 +940,36 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
                {
                pkey=d2i_PUBKEY_bio(key, NULL);
                }
+       else if (format == FORMAT_ASN1RSA)
+               {
+               RSA *rsa;
+               rsa = d2i_RSAPublicKey_bio(key, NULL);
+               if (rsa)
+                       {
+                       pkey = EVP_PKEY_new();
+                       if (pkey)
+                               EVP_PKEY_set1_RSA(pkey, rsa);
+                       RSA_free(rsa);
+                       }
+               else
+                       pkey = NULL;
+               }
+       else if (format == FORMAT_PEMRSA)
+               {
+               RSA *rsa;
+               rsa = PEM_read_bio_RSAPublicKey(key, NULL, 
+                       (pem_password_cb *)password_callback, &cb_data);
+               if (rsa)
+                       {
+                       pkey = EVP_PKEY_new();
+                       if (pkey)
+                               EVP_PKEY_set1_RSA(pkey, rsa);
+                       RSA_free(rsa);
+                       }
+               else
+                       pkey = NULL;
+               }
+
        else if (format == FORMAT_PEM)
                {
                pkey=PEM_read_bio_PUBKEY(key,NULL,
index 26dcbc5771d5ca1888830468e6d8c66fbcf8fd18..6444477172dc5cbd1c43630e66d1552b03e914d8 100644 (file)
@@ -331,6 +331,8 @@ void policies_print(BIO *out, X509_STORE_CTX *ctx);
 #define FORMAT_ENGINE   7
 #define FORMAT_IISSGC  8       /* XXX this stupid macro helps us to avoid
                                 * adding yet another param to load_*key() */
+#define FORMAT_PEMRSA  9       /* PEM RSAPubicKey format */
+#define FORMAT_ASN1RSA 10      /* DER RSAPubicKey format */
 
 #define EXT_COPY_NONE  0
 #define EXT_COPY_ADD   1
index d5cb7b7212939bb0ec8d885e1b121abb460163d3..9709489b13d051adb7e64f2158acf55df06380f0 100644 (file)
@@ -173,6 +173,10 @@ int MAIN(int argc, char **argv)
                        pubin=1;
                else if (strcmp(*argv,"-pubout") == 0)
                        pubout=1;
+               else if (strcmp(*argv,"-RSAPublicKey_in") == 0)
+                       pubin = 2;
+               else if (strcmp(*argv,"-RSAPublicKey_out") == 0)
+                       pubout = 2;
                else if (strcmp(*argv,"-noout") == 0)
                        noout=1;
                else if (strcmp(*argv,"-text") == 0)
@@ -246,10 +250,23 @@ bad:
                EVP_PKEY        *pkey;
 
                if (pubin)
-                       pkey = load_pubkey(bio_err, infile,
-                               (informat == FORMAT_NETSCAPE && sgckey ?
-                                       FORMAT_IISSGC : informat), 1,
+                       {
+                       int tmpformat;
+                       if (pubin == 2)
+                               {
+                               if (informat == FORMAT_PEM)
+                                       tmpformat = FORMAT_PEMRSA;
+                               else if (informat == FORMAT_ASN1)
+                                       tmpformat = FORMAT_ASN1RSA;
+                               }
+                       else if (informat == FORMAT_NETSCAPE && sgckey)
+                               tmpformat = FORMAT_IISSGC;
+                       else
+                               tmpformat = informat;
+                                       
+                       pkey = load_pubkey(bio_err, infile, tmpformat, 1,
                                passin, e, "Public Key");
+                       }
                else
                        pkey = load_key(bio_err, infile,
                                (informat == FORMAT_NETSCAPE && sgckey ?
@@ -335,7 +352,13 @@ bad:
                }
        BIO_printf(bio_err,"writing RSA key\n");
        if      (outformat == FORMAT_ASN1) {
-               if(pubout || pubin) i=i2d_RSA_PUBKEY_bio(out,rsa);
+               if(pubout || pubin) 
+                       {
+                       if (pubout == 2)
+                               i=i2d_RSAPublicKey_bio(out,rsa);
+                       else
+                               i=i2d_RSA_PUBKEY_bio(out,rsa);
+                       }
                else i=i2d_RSAPrivateKey_bio(out,rsa);
        }
 #ifndef OPENSSL_NO_RC4
@@ -359,7 +382,12 @@ bad:
 #endif
        else if (outformat == FORMAT_PEM) {
                if(pubout || pubin)
-                   i=PEM_write_bio_RSA_PUBKEY(out,rsa);
+                       {
+                       if (pubout == 2)
+                               i=PEM_write_bio_RSAPublicKey(out,rsa);
+                       else
+                               i=PEM_write_bio_RSA_PUBKEY(out,rsa);
+                       }
                else i=PEM_write_bio_RSAPrivateKey(out,rsa,
                                                enc,NULL,0,NULL,passout);
        } else  {