TechTip: Let's Encrypt, Together

Security - Other
  • 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 The aim is to make SSL certificates free, automatic, secure, transparent, open, and cooperative. You can learn more about each on the About page.

One of the interesting limitations of 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:

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.

$ ./ 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 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 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


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.

$ ./ 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/

OK, Close and reopen your terminal to start using le

Installing cron job

./ line 1372: crontab: command not found

./ line 1379: crontab: command not found

./ 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"/ cron > /dev/null


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, 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 and route it to my newly created htdocs/letsencrypt directory.


. . .

   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 uses. The next step on the GitHub instructions is to "issue" a certificate using the following syntax.


$ le issue /www/mysite/htdocs/letsencrypt

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

$ which le

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

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

Creating account key

Use default length 2048

Registering account


Creating domain key

Use length 2048

Creating csr


Verify each domain

Getting token for

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

/home/AARON/.le/ line 1115:


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 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 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

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: 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

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, to the rescue! If you need the 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_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


Creating account key

Use default length 2048

Account key exists, skip

Skip register account key

Creating domain key

Use length 2048

Creating csr


Verify each domain

Getting token for

chown: /www/mysite/htdocs/letsencrypt/ is an unknown username. error:{"type":"http-01","status":"valid","uri":









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 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

Creating account key

Use default length 2048

Account key exists, skip

Registering account


Creating domain key

Use length 2048

Creating csr


Verify each domain

Getting token for

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


Verify finished, start to sign.

Cert success.


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


Your cert is in /home/AARON/.le/

The intermediate CA cert is in /home/AARON/.le/

And the full chain certs is there: /home/AARON/.le/

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 (i.e., grep), and obtain the cacerts.pem file.

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