I am trying to automate the process of creating a CSR through openSSL and command prompt while using a Java program. I want to input a string such as koo_AH, Kut_Po and uuu_Pl and turn them into CSRs with default parameters. I was able to create the key file, but not the CSR, which I believe has to do with the fact that openSSL will start asking for parameters. What am I doing wrong here? Below is code as well as input/output of command prompt while manually using it in a nonjava process.
while (true) {
input[i] = inputScan.next();
if (input[i].length() < 5) {System.out.println("End of creation"); break;}
common = ("aaa."+ input[i].substring(4)+".aaa.com").toLowerCase();
pass = "aaa"+input[i].substring(4)+year;
rt = Runtime.getRuntime();
pr = rt.exec("cmd.exe");
pr = rt.exec("cmd /c cd "+directory1+" && " //change directory
+ "set OPENSSL_CONF=c:\\OpenSSL-Win32\\bin\\openssl.cfg && " //setup
+ "openssl genrsa -out "+directory2+input[i]+".key 2048 &&" //generate key
+ "openssl req -new -key "+directory2+input[i]+".key -out "+directory2+input[i]+".key.csr &&"
+ countryName + " &&"
+ state + " &&"
+ locality + " &&"
+ organization + " &&"
+ unit + " &&"
+ common + " &&"
+ email + " &&"
+ pass + " &&"
+ company);
i++;
}
C:\OpenSSL-Win32\bin>set OPENSSL_CONF=c:\OpenSSL-Win32\bin\openssl.cfg
C:\OpenSSL-Win32\bin>openssl genrsa -out C:\Keys\rkm_test.key 2048
Loading 'screen' into random state - done
Generating RSA private key, 2048 bit long modulus
........+++
...................+++
e is 65537 (0x10001)
C:\OpenSSL-Win32\bin>openssl req -new -key C:\Keys\rkm_test.key -out C:\keys\rkm
_test.key.csr
Loading 'screen' into random state - done
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:Yonk
Organization Name (eg, company) [Internet Widgits Pty Ltd]:AAA
Organizational Unit Name (eg, section) []:InfoSec
Common Name (e.g. server FQDN or YOUR name) []:aaa
Email Address []:gmail@gmail.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:aaa_123
An optional company name []:aaa
C:\OpenSSL-Win32\bin>