29
Fri, Nov
0 New Articles

TechTip: Let's Encrypt, Together

Security - Other
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Automation and security are top priorities. IBM i is a first class citizen if we let it be. If we take the effort to get more open source on the platform. This article does that.

If you haven't noticed, security is regularly in the news and generally has been a hot topic the past couple years. Most recently, there was the Kemuri Water Company breach, which unfortunately was against their "AS/400." The quote still ringing in my ears from that article is the following:

"The facts in the report do speak for themselves and it’s readily apparent the specific affected water utility was trapped in a past decade (or even two decades ago) in a time when they had little reason to expect their company, business operations or water control systems would ever become the desired target for a sophisticated cyber attack,"

It's easy to think you’re immune to security threats. It might be tempting to operate under the premise of "hoping for the best," but that stance can be generally classified as security ignorance. It's time we not only replace our ignorance but also start pursuing "ethical hacking," as MC Press author Steve Pitcher has done with excellence.

Not only do we need security in place, but it needs to be automated so we become less hesitant to implement it. The point on automation was made by Steve Will, Chief IBM i Architect at IBM, in this blog post. I think we need to heed Steve’s advice.

It's the combination of security and automation that brings me to the subject matter of this article. Last year, a co-worker told me about a new initiative called LetsEncrypt.org. The aim is to make SSL certificates free, automatic, secure, transparent, open, and cooperative. You can learn more about each on the LetsEncrypt.org About page.

One of the interesting limitations of LetsEncrypt.org is that certificates signed by them are valid only for a max of 90 days. It would be a major pain in the butt to renew keys every 90 days. That's why there are many open-source projects in a variety of programming languages that automate the process. Click here to see them all. I scanned through the list and hoped to find one that was not specific to an existing language because I am hoping many IBM i websites will make use of this approach. Lo and behold, there are a couple for bash (Bourne Again Shell), which I have on IBM i because I've installed 5733OPS option 3. Specifically, it is this project: https://github.com/Neilpang/le

To install that GitHub project on the IBM i, you can either download the source and FTP it to the IFS or use git clone, as shown below.

$ git clone This email address is being protected from spambots. You need JavaScript enabled to view it.:Neilpang/le.git

Cloning into 'le'...

remote: Counting objects: 793, done.

remote: Compressing objects: 100% (12/12), done.

remote: Total 793 (delta 4), reused 0 (delta 0), pack-reused 781

Receiving objects: 100% (793/793), 183.52 KiB | 0 bytes/s, done.

Resolving deltas: 100% (318/318), done.

Checking connectivity... done.

Now go into the directory that was created.

$ cd le

The project install instructions tell us to run the following command.

$ ./le.sh install

Please install crontab first.

try to install 'cron, crontab, crontabs or vixie-cron'.

We need to set cron job to renew the certs automatically.

Pre-check failed, can not install.

Hmm…errors. What to do?

Remember the "Drivers, Start your Nginx!" article I previously wrote where I included the painful steps of how I was able to get Nginx installed? In that article, I asked whether people like to see the specific details of how to troubleshoot within PASE. Well, I am still getting positive responses from that article with encouragement to do more. So, are you ready for some more blood, sweat, and tears? Time to see if we can get this open-source project ported to IBM i.

Going back to the error, IBM i doesn't have crontab by default. First, go to perzl.org to see if it exists in the list of packages. It doesn't. But, remembering that list isn't comprehensive, I went to the "everything RPMS" link. Using Ctrl+F on the web page, I didn't find anything relating to "cron".

I then searched the github.com source and found the following lines:

if ! _exists "crontab" ; then

   _err "Please install crontab first.

    try to install 'cron, crontab, crontabs or vixie-cron'."

   _err "We need to set cron job to renew the certs automatically."

   return 1

fi

Since I don't intend on auto-updating (yet), I will comment out those lines by placing a # character in front of each line, as shown below.

# if ! _exists "crontab" ; then

#   _err "Please install crontab first.

     try to install 'cron, crontab, crontabs or vixie-cron'."

#   _err "We need to set cron job to renew the certs automatically."

#   return 1

# fi

Now I will run it again.

$ ./le.sh install

It is recommended to install nc first, try to install 'nc' or 'netcat'.

We use nc for standalone server if you use standalone mode.

If you don't use standalone mode, just ignore this warning.

Installing to /home/AARON/.le

Installed to /home/AARON/.le/le.sh

OK, Close and reopen your terminal to start using le

Installing cron job

./le.sh: line 1372: crontab: command not found

./le.sh: line 1379: crontab: command not found

./le.sh: line 1379: crontab: command not found

Install cron job failed. You need to manually renew your certs.

Or you can add cronjob by yourself:

LE_WORKING_DIR="/home/AARON/.le" "/home/AARON/.le"/le.sh cron > /dev/null

OK

OK, it got past my commented lines, although it still attempted to install crontab. I don't believe that will be an issue. As the message above notes, I can simply manually renew my certs.

Next, I exit the PASE shell per the directions on the Github page.

$ exit

Log back in and cd into the location where you did the git clone.

$ cd /home/aaron/git/le

Now it's time to have a certificate issued for a domain. This involves many steps that happen under the covers. One of the steps involves verifying you actually own the domain. There are a handful of ways to verify the domain. One of them is to have a predefined and generated file be hosted on your domain. Then, letsencrypt.org will attempt to access that file. They figure if you can get a file served from the domain, then you must own it. This means we need to tell the script where it should generate the file. In my case, I've created a directory named /www/mysite/htdocs/letsencrypt.

I am using Nginx on IBM i instead of Apache. Below is the location mapping necessary to receive a request from letsencrypt.org and route it to my newly created htdocs/letsencrypt directory.

---/www/mysite/conf/nginx.conf---

. . .

   location /.well-known/acme-challenge {

     root /www/mysite/htdocs/letsencrypt;

   }

. . .

What's up with the weird URL of /.well-known/acme-challenge? I'm not sure. I just know that's what LetsEncrypt.org uses. The next step on the GitHub instructions is to "issue" a certificate using the following syntax.

 

$ le issue /www/mysite/htdocs/letsencrypt mysite.com

First, we see the le command, which is aliased to le.sh. We can confirm this by running the which command.

$ which le

le: aliased to /home/AARON/.le/le.sh

After le, we see three parameters. The first declares the action"issue" in this case. The second is the web-accessible directory we created earlier. The third is the domain needing a new certificate.

At this point, I hit Enter. Everything was going good until I received the following error.

$ le issue /www/mysite/htdocs/letsencrypt mysite.com

Creating account key

Use default length 2048

Registering account

Registered

Creating domain key

Use length 2048

Creating csr

Single domain=mysite.com

Verify each domain

Getting token for domain=mysite.com

printf: usage: printf [-v var] format [arguments]

Verifying:mysite.com

/home/AARON/.le/le.sh: line 1115:

/www/mysite/htdocs/letsencrypt/.well-known/acme-challenge/:

Is a directory

chown: /www/mysite/htdocs/letsencrypt/ is an unknown username.

curl: no URL specified!

curl: try 'curl --help' or 'curl --manual' for more information

mysite.com:Verify error:

I guessed that the printf and chown command failures might have to do with an issue with curl. How do I know that? Well, curl is a program used to return the results of a web request. If that fails, and if error trapping isn't adequate, then a subsequent printf or chown might fail because of blank variables.

At this point, I dug further into le.sh and noticed there are debugging capabilities. In the case of this project, debugging means you set the DEBUG environment variable to true (i.e., DEBUG=1) and it will generate various logs to the console for review. I ran the command again as shown below.

$ DEBUG=1 le issue /www/mysite/htdocs/letsencrypt mysite.com

When you only want an environment variable to be set for the duration of a program invocation, you can put it right before the command, as I did above. The other approach to make the value stay put for the duration of this shell session is to instead use "export DEBUG=1".

I am not going to post the entire debug results as they were quite long (and full of secret keys I don't want shared). I did find that a dump would occur if the curl request wasn't successful on this line, so I used the cat command to display the contents.

$ cat /home/AARON/.le/curl.dump

== Info: TLSv1.2, TLS alert, Server hello (2):

=> Send SSL data, 2 bytes (0x2)

0000: .0

== Info: SSL certificate problem: unable to get local issuer certificate

== Info: Closing connection 0

== Info: TLSv1.2, TLS alert, Client hello (1):

=> Send SSL data, 2 bytes (0x2)

 

The above error means the certificates installed on the machine aren't adequate to do the SSL handshake. This is a relatively common error I come across on IBM i. An adequate cacerts.pem file can be obtained from the following URL: https://curl.haxx.se/docs/caextract.html. Download and place in a directory on your IBM i. I put it in /home/aaron/certs.

Now set the CURL_CA_BUNDLE environment variable to that path the next time you invoke the le script, as shown below.

$ CURL_CA_BUNDLE=~/certs/cacert.pem le issue /www/mysite/htdocs/letsencrypt mysite.com

Creating account key

Use default length 2048

Registering account

grep: illegal option -- o

usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu]

       [-p[parasep]] -e pattern_list...

       [-f pattern_file...] [file...]

usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]]

       [-e pattern_list...]

       -f pattern_file... [file...]

usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwyu]

       [-p[parasep]] pattern_list [file...]

(23) Failed writing body

Register account Error: {"type":"urn:acme:error:badNonce","detail":

"JWS has no anti-replay nonce","status":400}

Snap! Another error.

The PASE version of grep isn't quite the same as Linux. No worries, perzl.org to the rescue! If you need the perzl.org version of grep, first download and install IBM i Chroot (or install 5733OPS option 3). Then run the following commands.

$ cd /dir/where/ibm-i-chroot/exists

$ ./pkg_setup.sh pkg_perzl_utils.lst

That will install various programs in /opt/freeware/bin. We now need to make sure the /opt/freeware/bin directory is searched when we run commands. Modify the PATH environment to have that directory first, as shown below. The PATH environment works much like a library list. It contains a list of delimited directories that should be searched for commands and programs.

$ export PATH=/opt/freeware/bin:$PATH

At this point, I was getting an error every subsequent time I ran the script. It recommended I set FORCE=1 if I wanted to rerun the process. I've added that environment variable to the call, as shown below.

% CURL_CA_BUNDLE=~/certs/cacert.pem FORCE=1 le issue

/www/mysite/htdocs/letsencrypt mysite.com

Creating account key

Use default length 2048

Account key exists, skip

Skip register account key

Creating domain key

Use length 2048

Creating csr

Single domain=mysite.com

Verify each domain

Getting token for domain=mysite.com

Verifying:mysite.com

chown: /www/mysite/htdocs/letsencrypt/ is an unknown username.

mysite.com:Verify error:{"type":"http-01","status":"valid","uri":

"https://acme-v01.api.letsencrypt.org/acme/challenge/Na7sxxxxxxxs_3ReHuXxxxxxxxYY/99999999",

"token":

"iPMnxxxxxxxxxxxxxxbP8_n6gs","keyAuthorization":

"iPMnxxxxxxxxxxxxxbP8_n6gs.CP2SxxxxxxxxxxEPF0","validationRecord":[{"url":

"http://mysite.com/.well-known/acme-challenge/iPMnxxxxxxxxxxxxP8_n6gs",

"hostname":"spaces.litmis.com",

"port":"80","addressesResolved":["69.99.99.144"],"addressUsed":"69.99.99.144"},{"url":

"https://mysite.com/.well-known/acme-challenge/iPMnxxxxxxxxxxTRbP8_n6gs","hostname":"mysite.com","port":"443","addressesResolved":["69.99.99.144"],"addressUsed":"69.99.99.144"}]}

OK, we've made progress. However, the script stops on this "Verify error," as shown above. This one took me awhile to resolve. I had to add many echo statements to le.sh to learn why it was failing. It turns out there was an issue with how the regular expression on the egrep command was written. Once I figured that out, I went ahead and forked the GitHub project, made my change, and issued a pull request. You can see my changes here. My pull request was accepted by the author of the parent repository and further questions were asked to learn if there was more they could do to facilitate this running on IBM i. You can see the full transcript here.

Now that the fix for egrep is in place, it's time to run the command again.

$ CURL_CA_BUNDLE=~/certs/cacert.pem FORCE=1 le issue /www/mysite/htdocs/letsencrypt mysite.com

Creating account key

Use default length 2048

Account key exists, skip

Registering account

Registered

Creating domain key

Use length 2048

Creating csr

Single domain=mysite.com

Verify each domain

Getting token for domain=mysite.com

Verifying:mysite.com

chown: /www/mysite/htdocs/letsencrypt/ is an unknown username.

Success

Verify finished, start to sign.

Cert success.

-----BEGIN CERTIFICATE-----

.....contents omitted for privacy...

-----END CERTIFICATE-----

Your cert is in /home/AARON/.le/mysite.com/mysite.com.cer

The intermediate CA cert is in /home/AARON/.le/mysite.com/ca.cer

And the full chain certs is there: /home/AARON/.le/mysite.com/fullchain.cer

Victory! The certificate has been issued and is on my IBM i. The last step is to setup Nginx for SSL. The word count of this article is already getting long, so that will be a topic for another day!

In conclusion, I'll comment on what you'd need to do to use this open-source project. Since my pull requests were accepted by the parent repo, you shouldn't have the cron or egrep issues to contend with. Instead, you will just need to obtain the Github source, obtain necessary programs from perzl.org (i.e., grep), and obtain the cacerts.pem file.

If you have any specific questions, please let me know in the comments.

Aaron Bartell

Aaron Bartell is Director of IBM i Innovation for Krengel Technology, Inc. Aaron facilitates adoption of open-source technologies on IBM i through professional services, staff training, speaking engagements, and the authoring of best practices within industry publications andwww.litmis.comWith a strong background in RPG application development, Aaron covers topics that enable IBM i shops to embrace today's leading technologies, including Ruby on Rails, Node.js, Git for RPG source change management, and RSpec for unit testing RPG. Aaron is a passionate advocate of vibrant technology communities and the corresponding benefits available for today's modern application developers. Connect with Aaron via email atThis email address is being protected from spambots. You need JavaScript enabled to view it..

Aaron lives with his wife and five children in southern Minnesota. He enjoys the vast amounts of laughter that having a young family brings, along with camping and music. He believes there's no greater purpose than to give of our life and time to help others.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: