algo icon indicating copy to clipboard operation
algo copied to clipboard

PLEASE REOPEN - update-users always fails on 'unable to load CA private key' from openssl

Open 01010101001 opened this issue 9 years ago • 11 comments

OS / Environment

Ubuntu 16.04.3 x64 digitalocean

Ansible version

ansible 2.2.0.0

Version of components from requirements.txt

(env) root@algo:~/algo-master# cat requirements.txt | sed -e's/>.//' -e's/=.//' | while read i; do pip show $i | egrep -i 'name|version'; done Name: msrestazure Version: 0.4.14 Name: setuptools Version: 36.5.0 Name: ansible Version: 2.2.0.0 Name: dopy Version: 0.3.5 Name: boto Version: 2.48.0 Name: boto3 Version: 1.4.7 Name: azure Version: 2.0.0rc5 Name: msrest Version: 0.4.1 Name: apache-libcloud Version: 2.2.0 Name: six Version: 1.10.0 Name: pyOpenSSL Version: 17.3.0 License: Apache License, Version 2.0 Name: Jinja2 Version: 2.8

Summary of the problem

creation of the server works fine, but update-users (while having kept CA key) always fails on this step (repeated multiple times, on fresh digitalocean VMs provisionned by Algo) - for each added user, this occurs:

failed: [localhost -> localhost] (item=test) => {"changed": true, "cmd": "openssl req -utf8 -new -newkey ec:ecparams/prime256v1.pem -config openssl.cnf -keyout private/test.key -out reqs/test.req -nodes -passin pass:"XXXXXXXX" -subj "/CN=test" -batch && openssl ca -utf8 -in reqs/test.req -out certs/test.crt -config openssl.cnf -days 3650 -batch -passin pass:"65c2f2c8" -subj "/CN=test" && touch certs/test_crt_generated", "delta": "0:00:00.042535", "end": "2017-09-18 16:02:08.682774", "failed": true, "item": "test", "rc": 1, "start": "2017-09-18 16:02:08.640239", "stderr": "Generating a 256 bit EC private key\nwriting new private key to 'private/test.key'\n-----\nUsing configuration from openssl.cnf\nunable to load CA private key\n139787987179160:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:529:\n139787987179160:error:23077074:PKCS12 routines:PKCS12_pbe_crypt:pkcs12 cipherfinal error:p12_decr.c:108:\n139787987179160:error:2306A075:PKCS12 routines:PKCS12_item_decrypt_d2i:pkcs12 pbe crypt error:p12_decr.c:139:\n139787987179160:error:0907B00D:PEM routines:PEM_READ_BIO_PRIVATEKEY:ASN1 lib:pem_pkey.c:141:", "stdout": "", "stdout_lines": [], "warnings": []}

Steps to reproduce the behavior

provision a fresh new algo instance on digitalocean, keep the CA key. then try to add any user ("test" in the example above). I have the same issue whether I add users to a remote instance or locally.

The way of deployment (cloud or local)

cloud

Expected behavior

new users are added

Actual behavior

openssl step fails so the account is not completely created

Full log

(env) root@algo:~/algo-master# ./algo update-users

Enter the IP address of your server: (or use localhost for local installation) : localhost

What user should we use to login on the server? (note: passwordless login required, or ignore if you're deploying to localhost) [root]:

Do you want each user to have their own account for SSH tunneling? [y/N]: y

Enter the public IP address of your server: (IMPORTANT! This IP is used to verify the certificate) []: A.B.C.D

Enter the password for the private CA key: [pasted values will not be displayed] :

PLAY [localhost] ***************************************************************

TASK [Add the server to the vpn-host group] ************************************ changed: [localhost]

TASK [Wait until SSH becomes ready...] ***************************************** ok: [localhost -> localhost]

PLAY [User management] *********************************************************

TASK [setup] ******************************************************************* ok: [localhost]

TASK [Check the system] ******************************************************** changed: [localhost]

TASK [Ubuntu | Install prerequisites] ****************************************** changed: [localhost]

TASK [Ubuntu | Configure defaults] ********************************************* changed: [localhost]

TASK [FreeBSD / HardenedBSD | Install prerequisites] *************************** skipping: [localhost]

TASK [FreeBSD / HardenedBSD | Configure defaults] ****************************** skipping: [localhost]

TASK [set_fact] **************************************************************** skipping: [localhost]

TASK [Gather Facts] ************************************************************ ok: [localhost]

TASK [Ensure the algo ssh key exist on the server] ***************************** ok: [localhost]

TASK [Enable IPv6] ************************************************************* skipping: [localhost]

TASK [Set facts if the deployment in a cloud] ********************************** ok: [localhost]

TASK [Generate password for the CA key] **************************************** changed: [localhost -> localhost]

TASK [Generate p12 export password] ******************************************** changed: [localhost -> localhost]

TASK [Define password facts] *************************************************** ok: [localhost]

TASK [Define the commonName] *************************************************** ok: [localhost]

TASK [ssh_tunneling : Ensure that the sshd_config file has desired options] **** ok: [localhost]

TASK [ssh_tunneling : Ensure that the algo group exist] ************************ ok: [localhost]

TASK [ssh_tunneling : Ensure that the jail directory exist] ******************** ok: [localhost]

TASK [ssh_tunneling : Ensure that the SSH users exist] ************************* ok: [localhost] => (item=XXX)

TASK [ssh_tunneling : The authorized keys file created] ************************ ok: [localhost] => (item=XXX)

TASK [ssh_tunneling : Generate SSH fingerprints] ******************************* changed: [localhost]

TASK [ssh_tunneling : Fetch users SSH private keys] **************************** ok: [localhost] => (item=XXX)

TASK [ssh_tunneling : Change mode for SSH private keys] ************************ ok: [localhost -> localhost] => (item=XXX)

TASK [ssh_tunneling : Fetch the known_hosts file] ****************************** ok: [localhost -> localhost]

TASK [ssh_tunneling : Build the client ssh config] ***************************** ok: [localhost -> localhost] => (item=XXX)

TASK [ssh_tunneling : SSH | Get active system users] *************************** changed: [localhost]

TASK [ssh_tunneling : SSH | Delete non-existing users] ************************* skipping: [localhost] => (item=XXX)

TASK [vpn : Ensure the pki directory does not exist] *************************** skipping: [localhost]

TASK [vpn : Ensure the pki directories exist] ********************************** ok: [localhost -> localhost] => (item=ecparams) ok: [localhost -> localhost] => (item=certs) ok: [localhost -> localhost] => (item=crl) ok: [localhost -> localhost] => (item=newcerts) ok: [localhost -> localhost] => (item=private) ok: [localhost -> localhost] => (item=reqs)

TASK [vpn : Ensure the files exist] ******************************************** changed: [localhost -> localhost] => (item=.rnd) changed: [localhost -> localhost] => (item=private/.rnd) changed: [localhost -> localhost] => (item=index.txt) changed: [localhost -> localhost] => (item=index.txt.attr) changed: [localhost -> localhost] => (item=serial)

TASK [vpn : Generate the openssl server configs] ******************************* ok: [localhost -> localhost]

TASK [vpn : Build the CA pair] ************************************************* ok: [localhost -> localhost]

TASK [vpn : Copy the CA certificate] ******************************************* ok: [localhost -> localhost]

TASK [vpn : Generate the serial number] **************************************** ok: [localhost -> localhost]

TASK [vpn : Build the server pair] ********************************************* ok: [localhost -> localhost]

TASK [vpn : Build the client's pair] ******************************************* ok: [localhost -> localhost] => (item=XXX) failed: [localhost -> localhost] (item=test) => {"changed": true, "cmd": "openssl req -utf8 -new -newkey ec:ecparams/prime256v1.pem -config openssl.cnf -keyout private/test.key -out reqs/test.req -nodes -passin pass:"XXXXXXXX" -subj "/CN=test" -batch && openssl ca -utf8 -in reqs/test.req -out certs/test.crt -config openssl.cnf -days 3650 -batch -passin pass:"65c2f2c8" -subj "/CN=test" && touch certs/test_crt_generated", "delta": "0:00:00.042535", "end": "2017-09-18 16:02:08.682774", "failed": true, "item": "test", "rc": 1, "start": "2017-09-18 16:02:08.640239", "stderr": "Generating a 256 bit EC private key\nwriting new private key to 'private/test.key'\n-----\nUsing configuration from openssl.cnf\nunable to load CA private key\n139787987179160:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:529:\n139787987179160:error:23077074:PKCS12 routines:PKCS12_pbe_crypt:pkcs12 cipherfinal error:p12_decr.c:108:\n139787987179160:error:2306A075:PKCS12 routines:PKCS12_item_decrypt_d2i:pkcs12 pbe crypt error:p12_decr.c:139:\n139787987179160:error:0907B00D:PEM routines:PEM_READ_BIO_PRIVATEKEY:ASN1 lib:pem_pkey.c:141:", "stdout": "", "stdout_lines": [], "warnings": []}

TASK [vpn : debug] ************************************************************* ok: [localhost] => { "fail_hint": [ "Sorry, but something went wrong!", "Please check the troubleshooting guide.", "https://trailofbits.github.io/algo/troubleshooting.html" ] }

TASK [vpn : fail] ************************************************************** fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed as requested from task"}

PLAY RECAP ********************************************************************* localhost : ok=32 changed=9 unreachable=0 failed=1

01010101001 avatar Sep 18 '17 16:09 01010101001

Same error here

1ca1 avatar Sep 20 '17 23:09 1ca1

You need to save the CA key when you deploy

dguido avatar Sep 22 '17 13:09 dguido

I did save the CA of course

On 22 Sep 2017 15:28, "Dan Guido" [email protected] wrote:

You need to save the CA key when you deploy

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/trailofbits/algo/issues/674#issuecomment-331446223, or mute the thread https://github.com/notifications/unsubscribe-auth/Aele3X5EZl14Bzk8dtrEDsffq6ayApZPks5sk7XGgaJpZM4PbKzQ .

01010101001 avatar Sep 22 '17 13:09 01010101001

Having the same issue on my deployment. Save CA / don't save: same result.

unstatusthequo avatar Oct 03 '17 02:10 unstatusthequo

Dears

I confirm once again that there is a bug here. I have just tested once more, a fresh new DigitalOcean VM, a fresh new install, keeping the CA and then immediately after installation trying to add a user fails. you can find the complete log attached.

algo-pki-bug.txt

here's a file listing after the installation that was supposed to keep the CA key:

root@algotest:~/algo-master/configs# ls -alR .: total 24 drwxr-xr-x 3 root root 4096 Oct 17 09:24 . drwxr-xr-x 10 root root 4096 Oct 17 09:29 .. drwx------ 3 root root 4096 Oct 17 09:34 188.226.129.211 -rw------- 1 root root 1679 Oct 17 09:20 algo.pem -rw-r--r-- 1 root root 390 Oct 17 09:21 algo.pem.pub -rw-r--r-- 1 root root 0 Oct 1 20:40 .gitinit -rw-r--r-- 1 root root 119 Oct 17 09:21 inventory.dynamic

./188.226.129.211: total 108 drwx------ 3 root root 4096 Oct 17 09:34 . drwxr-xr-x 3 root root 4096 Oct 17 09:24 .. -rw------- 1 root root 78 Oct 17 09:25 android_dan_helper.html -rw------- 1 root root 2297 Oct 17 09:25 android_dan.sswan -rw------- 1 root root 80 Oct 17 09:25 android_jack_helper.html -rw------- 1 root root 2301 Oct 17 09:25 android_jack.sswan -rw------- 1 root root 652 Oct 17 09:25 cacert.pem -rw------- 1 root root 8594 Oct 17 09:25 dan.mobileconfig -rw------- 1 root root 1529 Oct 17 09:25 dan.p12 -rw------- 1 root root 142 Oct 17 09:24 dan.ssh_config -rw------- 1 root root 314 Oct 17 09:24 dan.ssh.pem -rw------- 1 root root 431 Oct 17 09:25 ipsec_dan.conf -rw------- 1 root root 32 Oct 17 09:25 ipsec_dan.secrets -rw------- 1 root root 432 Oct 17 09:25 ipsec_jack.conf -rw------- 1 root root 33 Oct 17 09:25 ipsec_jack.secrets -rw------- 1 root root 8601 Oct 17 09:25 jack.mobileconfig -rw------- 1 root root 1531 Oct 17 09:25 jack.p12 -rw------- 1 root root 144 Oct 17 09:24 jack.ssh_config -rw------- 1 root root 314 Oct 17 09:24 jack.ssh.pem -rw-r--r-- 1 root root 274 Oct 17 09:24 known_hosts -rw------- 1 root root 150 Oct 17 09:34 newuser.ssh_config -rw------- 1 root root 314 Oct 17 09:34 newuser.ssh.pem drwxr-xr-x 8 root root 4096 Oct 17 09:25 pki

./188.226.129.211/pki: total 72 drwxr-xr-x 8 root root 4096 Oct 17 09:25 . drwx------ 3 root root 4096 Oct 17 09:34 .. -rw-r--r-- 1 root root 0 Oct 17 09:25 188.226.129.211_ca_generated -rw-r--r-- 1 root root 652 Oct 17 09:25 cacert.pem drwxr-xr-x 2 root root 4096 Oct 17 09:25 certs drwxr-xr-x 2 root root 4096 Oct 17 09:25 crl drwxr-xr-x 2 root root 4096 Oct 17 09:25 ecparams -rw-r--r-- 1 root root 121 Oct 17 09:34 index.txt -rw-r--r-- 1 root root 21 Oct 17 09:34 index.txt.attr -rw-r--r-- 1 root root 21 Oct 17 09:25 index.txt.attr.old -rw-r--r-- 1 root root 84 Oct 17 09:25 index.txt.old drwxr-xr-x 2 root root 4096 Oct 17 09:25 newcerts -rw-r--r-- 1 root root 4479 Oct 17 09:25 openssl.cnf drwxr-xr-x 2 root root 4096 Oct 17 09:34 private drwxr-xr-x 2 root root 4096 Oct 17 09:34 reqs -rw------- 1 root root 1024 Oct 17 09:34 .rnd -rw-r--r-- 1 root root 3 Oct 17 09:34 serial -rw-r--r-- 1 root root 0 Oct 17 09:25 serial_generated -rw-r--r-- 1 root root 3 Oct 17 09:25 serial.old

./188.226.129.211/pki/certs: total 32 drwxr-xr-x 2 root root 4096 Oct 17 09:25 . drwxr-xr-x 8 root root 4096 Oct 17 09:25 .. -rw-r--r-- 1 root root 2620 Oct 17 09:25 01.pem -rw-r--r-- 1 root root 2527 Oct 17 09:25 02.pem -rw-r--r-- 1 root root 2533 Oct 17 09:25 03.pem -rw-r--r-- 1 root root 2620 Oct 17 09:25 188.226.129.211.crt -rw-r--r-- 1 root root 0 Oct 17 09:25 188.226.129.211_crt_generated -rw-r--r-- 1 root root 2527 Oct 17 09:25 dan.crt -rw-r--r-- 1 root root 0 Oct 17 09:25 dan_crt_generated -rw-r--r-- 1 root root 2533 Oct 17 09:25 jack.crt -rw-r--r-- 1 root root 0 Oct 17 09:25 jack_crt_generated

./188.226.129.211/pki/crl: total 8 drwxr-xr-x 2 root root 4096 Oct 17 09:25 . drwxr-xr-x 8 root root 4096 Oct 17 09:25 ..

./188.226.129.211/pki/ecparams: total 12 drwxr-xr-x 2 root root 4096 Oct 17 09:25 . drwxr-xr-x 8 root root 4096 Oct 17 09:25 .. -rw-r--r-- 1 root root 75 Oct 17 09:25 prime256v1.pem

./188.226.129.211/pki/newcerts: total 8 drwxr-xr-x 2 root root 4096 Oct 17 09:25 . drwxr-xr-x 8 root root 4096 Oct 17 09:25 ..

./188.226.129.211/pki/private: total 36 drwxr-xr-x 2 root root 4096 Oct 17 09:34 . drwxr-xr-x 8 root root 4096 Oct 17 09:25 .. -rw-r--r-- 1 root root 241 Oct 17 09:25 188.226.129.211.key -rw-r--r-- 1 root root 367 Oct 17 09:25 cakey.pem -rw-r--r-- 1 root root 241 Oct 17 09:25 dan.key -rw-r--r-- 1 root root 1529 Oct 17 09:25 dan.p12 -rw-r--r-- 1 root root 241 Oct 17 09:25 jack.key -rw-r--r-- 1 root root 1531 Oct 17 09:25 jack.p12 -rw-r--r-- 1 root root 241 Oct 17 09:34 newuser.key -rw-r--r-- 1 root root 0 Oct 17 09:34 .rnd

./188.226.129.211/pki/reqs: total 24 drwxr-xr-x 2 root root 4096 Oct 17 09:34 . drwxr-xr-x 8 root root 4096 Oct 17 09:25 .. -rw-r--r-- 1 root root 363 Oct 17 09:25 188.226.129.211.req -rw-r--r-- 1 root root 347 Oct 17 09:25 dan.req -rw-r--r-- 1 root root 347 Oct 17 09:25 jack.req -rw-r--r-- 1 root root 351 Oct 17 09:34 newuser.req

Thanks & Rgds

01010101001 avatar Oct 17 '17 09:10 01010101001

the same problem

igkuz avatar Nov 27 '17 20:11 igkuz

The update script is given out as a convenience measure. It works for 99% of most user's setups. If it does not work for you, then simply destroy the server and redeploy a new one. We're happy to accept PRs if there are specific bugs or improvements you can point out for the update script. Thanks!

dguido avatar Nov 27 '17 20:11 dguido

This may be really dumb, but I was hitting the same error until I realized I was using the wrong CA key password for the instance. I had a few existing users and was attempting to add one as per the docs and was hitting this error (which has more or less the same stacktrace as your original post):

TASK [vpn : Build the client's pair] *******************************************
ok: [**.**.**.** -> localhost] => (item=*)
ok: [**.**.**.** -> localhost] => (item=**)
ok: [**.**.**.** -> localhost] => (item=***)
ok: [**.**.**.** -> localhost] => (item=****)
ok: [**.**.**.** -> localhost] => (item=*****)
failed: [**.**.**.** -> localhost] (item=******) => {
    "changed": true, 
    "cmd": "openssl req -utf8 -new -newkey ec:ecparams/prime256v1.pem -config openssl.cnf -keyout private/******.key -out reqs/******.req -nodes -passin pass:\"XXXXXXXX\" -subj \"/CN=******\" -batch && openssl ca -utf8 -in reqs/******.req -out certs/******.crt -config openssl.cnf -days 3650 -batch -passin pass:\"XXXXXXXX\" -subj \"/CN=******\" && touch certs/******_crt_generated", 
    "delta": "0:00:00.013804", 
    "end": "2018-01-02 12:19:25.377655", 
    "failed": true, 
    "item": "******", 
    "rc": 1, 
    "start": "2018-01-02 12:19:25.363851", 
    "stderr": "
        Generating an EC private key
        writing new private key to 'private/******.key'
        -----
        Using configuration from openssl.cnf
        unable to load CA private key
        140191327879104:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:crypto/evp/evp_enc.c:541:
        140191327879104:error:23077074:PKCS12 routines:PKCS12_pbe_crypt:pkcs12 cipherfinal error:crypto/pkcs12/p12_decr.c:63:
        140191327879104:error:2306A075:PKCS12 routines:PKCS12_item_decrypt_d2i:pkcs12 pbe crypt error:crypto/pkcs12/p12_decr.c:94:
        140191327879104:error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib:crypto/pem/pem_pkey.c:87:
    ", 
    "stdout": "", 
    "stdout_lines": [], 
    "warnings": []
}

Once I used the right password for the right instance, the ./algo update-users command worked as expected. So, maybe triple check that you are entering the 32-char passphrase for the right instance from that instance's creation when prompted with:

Enter the password for the private CA key:
[pasted values will not be displayed]
:

as taken from...

Congratulations!
Your Algo server is running.

<snip>

The p12 and SSH keys password for new users is: 
********

The CA key password is: 
********************************

hommel avatar Jan 02 '18 21:01 hommel

Because right CA password isn't put. The CA password is made when algo server is created by ./algo Should save the password when algo server is made.

    "#                          Congratulations!                            #"
    "#                     Your Algo server is running.                     #"
    "#    Config files and certificates are in the ./configs/ directory.    #"
    "#              Go to https://whoer.net/ after connecting               #"
    "#        and ensure that all your traffic passes through the VPN.      #"
    "#                     Local DNS resolver 172.16.0.1                    #"
    "#        The p12 and SSH keys password for new users is XXXXXXXX       #"
    "#        The CA key password is XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       #"
    "#      Shell access: ssh -F configs/<server_ip>/ssh_config <hostname>  #"

What should be saved: "# The p12 and SSH keys password for new users is XXXXXXXX #"
"# The CA key password is XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #"

jacobkim9881 avatar May 10 '22 07:05 jacobkim9881

@jacobkim9881 I forgot to save the keys. How can I regenerate keys ?

sobhan-m94 avatar Oct 20 '22 10:10 sobhan-m94

@whoami-idk I want to know how to find the key. I may reinstall the OS on my cloud server.

jacobkim9881 avatar Oct 21 '22 03:10 jacobkim9881