perl - Mojo::UserAgent TLS/SSL certificate authentication -
I'm new to Mojolicious and I received a TLS certificate authorization and a both to get Mojo :: UserAgent script Trying to do the TLS certificate file but the certificate file password is protected
I have the following code:
#! Modern Uses / Usr / bin / env perl: Pearl; Mojo :: UserAgent; IO :: Socket :: SSL :: set_defaults (SSL_passwd_cb = & gt; sub {return "password";}); My $ UA = Mojo :: UserAgent- & gt; new; My $ base_dir = '/ path / to / certs /'; $ Ua- & gt; Ca ($ base_dir. 'Ca-cert.crt'); $ Ua- & gt; Certificate ($ base_dir. 'Clientcert.crt'); My $ tx = $ ua- & gt; Build_tx (POST = & gt; '/ POST HTTP / 1.1'); $ Tx-> Req-> Url-> Parse ('https://example.com:12345'); $ UA- & gt; Start ($ TX); If ($ my $ res = $ tx-> success) ($ res-> body; print dumper ($ tx);} and (my ($ mistake, $ code) = $ tx-> error; $ code I have verified the certificate with the following: "$ code response: $ err": "connection error: $ err";} I have verified the certificate with:
< Code> openssl s_client-connected host: port -CApath / path / to / cert-CAfile CA-Cert.crt -cert clientcert.crt
I get a hint with it: Enter the pass phrase for
clientcert.crt: I enter the password and it is in correct way.
How do I get IO :: socket :: SSL?
I got a solution (and reported the problem), so now you can solve it with the following.
Mojo :: In IOLoop:: Customer changed the following Is:
SSL_key = & gt; $ Args- & gt; {tls_key}, #SSL_key_file => $ Args-> {tls_key}, Then, you can authenticate with the following code:
#! Usr / bin / env perl Modern :: Perl; Mojo :: UserAgent; My $ UA = Mojo :: UserAgent- & gt; new; My $ base_dir = '/ path / to / certs /'; $ Ua- & gt; Ca ($ base_dir. 'Ca-cert.crt'); $ Ua- & gt; Certificate ($ base_dir. 'Clientcert.crt'); My $ bio = net :: SSLeay :: BIO_new_file ($ base_dir. 'Clientcert.crt', 'r'); My $ privkey = net :: SSLeay :: PEM_read_bio_PrivateKey ($ bio, unfif, 'password'); $ UA- & gt; Key ($ privkey); My $ tx = $ ua- & gt; Post ('https://example.com:12345'); If ($ my $ res = $ tx-> success) ($ res-> body; print dumper ($ tx);} and (my ($ mistake, $ code) = $ tx-> error; $ code Say "$ code response: $ err": "Connection error: $ err";}
Comments
Post a Comment