Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MITM proxy, TLS 1.2 Certificate verification failed

Trying to create my own simple MITM-proxy for the specific app which using TLS 1.2 protocol and connecting to several IP addresses, however got in stuck with the error in the app log "Certificate verify failed". How to solve this problem?

The app using about the following code to check the cert:

X509* cert = SSL_get_peer_certificate( ssl );
X509_STORE_CTX * xCtx = X509_STORE_CTX_new();
X509_STORE_CTX_init( xCtx, (X509_STORE*)Store, cert, NULL );
int res = X509_verify_cert( xCtx );
if( !res ) { /*Certificate verify failed*/ };

I did the following steps to achieve the result:

  1. Created CA root key and self-signed certificate according to this manual. It is a bit outdated, so i have made some changes like md5 to sha256, also I didn't use pass phrase, used different key size and other minor changes.
  2. Created proxy key and certificate using the above Root CA to sign it.
  3. Both certificates have been added to the Local Computer Certificates in Personal and Trusted Root Certification Authorities (not sure if this was necessary). Btw, I'm using Windows 10.
  4. Wrote a simple proxy server using sample code from here. Cert.pem and Key.pem took from the second step.
  5. Changed all IP addresses in the app to 127.0.0.1:443 to see if TLS connection established successfully and we can receive first message with an Application Data.

I believe that connection established properly, because WireShark shows common sequence for establishing a TLS connection: Client/Server hello, Certificate, Client key exchange, two encrypted handshake messages. Moreover, using OpenSSL for testing connection:

openssl s_client -connect localhost:443

allow me to write some message and later successfully receive it using SSL_Read() in proxy server. However, there are some errors:

verify error:num=20:unable to get local issuer certificate
verify return:1
verify error:num=21:unable to verify the first certificate
verify return:1
Verify return code: 21 (unable to verify the first certificate)

Using OpenSSL client to directly connect to the original IP addresses give the same errors, but application works great.

Also the output:

openssl verify -CAfile "signing-ca-1.crt" "cert.crt"
WARNING: can't open config file: /usr/local/ssl/openssl.cnf
e:\MyProg\SSL_serv\Debug\cert.crt: OK

It seems that I missed something important. Could you please tell me how to solve this problem with cert?

like image 278
DBenson Avatar asked Feb 18 '26 02:02

DBenson


1 Answers

One of the very purposes of having certificates, along with certificate authorities, is to prevent MITM. The app you are trying trick does the proper thing and checks the certificate. And it doesn't like your's. Its really that simple.

Is it possible to circumvent it and run MITM on an app anyway? Absolutely! Is it going to be easy? Probably not. What you need to do is to patch the app and remove this certificate check.

like image 155
Boris Lipschitz Avatar answered Feb 19 '26 15:02

Boris Lipschitz