LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-22-2016, 01:43 PM   #1
Thomas Groman
LQ Newbie
 
Registered: Aug 2014
Posts: 8

Rep: Reputation: Disabled
Question Trouble specifying host as variable to OpenSSL in Bash


I have been at this for hours trying all kinds of different syntax and structures. The documentation says this should work but for some reason its not liking it. i tried trimming the output from the domain list with xargs with no different effect.

Code:
cat domains.lst | sort | uniq | while IFS= read -r HOST ; do
#       sanip=$(echo -n "$ip" | xargs)
#       echo $sanip
#       echo -n $ip | xargs | export $HOST
        echo "$HOST"
        echo "x" | openssl s_client -connect "$HOST":443 2>/dev/null | openssl x509 -noout -dates
done
Does anybody have any idea why this doesn't work?
it keeps giving me lib errors saying it expected a trusted certificate. i tried manually specifying my CA dir. what is weird is that it runs fine if you just put the host name in their statically
 
Old 12-23-2016, 12:22 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Have you tried putting set -xv prior to the loop and see what bash thinks it is using?
 
Old 12-23-2016, 01:43 AM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
I am not entirely sure what you are expecting, but I suspect the error is not due to specifying the host as a variable, but rather due to having a host name in the file which does not return a certificate or is not listening on port 443.

I set up a domains.lst with two host names - one with a certificate and one without, and received this result (domain names chanaged to protect the innocent):

Code:
nocertificate.com
unable to load certificate 
3073422984:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:696:Expecting: TRUSTED CERTIFICATE
goodcertificate.com
notBefore=Jan 30 21:47:43 2015 GMT
notAfter=Jan 31 21:47:43 2025 GMT
Is this the error that you are seeing? If not, please post the exact error message you are seeing.

This error results because you do not test whether the openssl s_client... command actually returns a certificate, but blindly pipe it through to openssl x509..., which generates the error if no certificate is received.
 
  


Reply

Tags
automation, bash, bash scripting, openssl



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
Bash: pass host variable to traceroute slugman Programming 4 08-13-2015 04:35 PM
[SOLVED] Bash script: How to assign variable to an sqlite3 command with variable embedded? ninja6o4 Linux - Software 10 02-15-2015 04:43 PM
Compiled openssl, now how to set env. variable? peng12 Linux - Newbie 3 09-30-2012 03:30 PM
host: dst_lib_init: openssl failure in chroot jail when executing host binary golden_boy615 Linux - General 0 09-10-2012 07:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:41 AM.

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