LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-09-2016, 12:26 PM   #1
Defested
LQ Newbie
 
Registered: Mar 2015
Posts: 9

Rep: Reputation: Disabled
Scripting openssl commands


hey all,

I am trying to write a script for generating a CA and having it sign a new key. but there are menus. which are standing in the way of scripting it. Could you help me script it out?

The steps that I am trying to script are:

[12:19 username@kennel03 mir]$ openssl genrsa -out rootCA.key 2048
Generating RSA private key, 2048 bit long modulus
............................+++
............................+++
e is 65537 (0x10001)
[12:19 username@kennel03 mir]$ openssl req -x509 -new -nodes -key rootCA.key -days 3650 -sha256 -out rootCA.pemYou 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) [XX]:US
State or Province Name (full name) []:Wisconsin
Locality Name (eg, city) [Default City]:Madison
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:kennel03
Email Address []:
[12:20 username@kennel03 mir]$ ls
rootCA.key rootCA.pem
[12:20 username@kennel03 mir]$ openssl genrsa -aes256 -out kennel03.key 2048
Generating RSA private key, 2048 bit long modulus
.....................+++
...................................................................................+++
e is 65537 (0x10001)
Enter pass phrase for kennel03.key:
Verifying - Enter pass phrase for kennel03.key:
[12:21 username@kennel03 mir]$ openssl req -new -key kennel03.key -out kennel03.csr
Enter pass phrase for kennel03.key:
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) [XX]:US
State or Province Name (full name) []:Wisconsin
Locality Name (eg, city) [Default City]:Madison
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:Kennel03
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[12:22 username@kennel03 mir]$ ls
kennel03.csr kennel03.key rootCA.key rootCA.pem
[12:22 username@kennel03 mir]$ openssl x509 -req -in kennel03.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out kennel03.crt -days 3650 -sha256
Signature ok
subject=/C=US/ST=Wisconsin/L=Madison/O=Default Company Ltd/CN=Kennel03
Getting CA Private Key
 
Old 03-09-2016, 01:17 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
I haven't done it myself but it appears you can disable prompt so it takes values from the configuration files.

If you do "man openssl" and go to "SEE ALSO" section you'll see that many of the things you do have their own man pages. This includes the "req" you're doing in your second command. If you do "man req" you'll see where it talks about prompt being set to no and has a discussion of the distinguished name.

Alternatively you could install "expect" and use it to wait for the prompts and provide answers. (Expect can be used with most interactive sessions.) However, were it me I'd investigate the no prompt facility of openssl first.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Commands on shell scripting tanmoy123 Linux - Newbie 7 07-03-2013 02:06 PM
[SOLVED] Scripting ssh commands Linux_Kidd Linux - Security 13 07-08-2012 08:37 PM
LXer: The Most Common OpenSSL Commands LXer Syndicated Linux News 0 12-18-2011 01:40 AM
reversing openssl commands prushik Linux - Security 2 03-19-2011 09:20 PM
Pause between commands when scripting jwijesundra Linux - General 1 07-03-2004 02:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration