Sponsored Content
Top Forums Programming Python- Client and server certificate validation Post 303016059 by chandana.hs on Thursday 19th of April 2018 03:40:02 AM
Old 04-19-2018
Python- Client and server certificate validation

Hello Team,

I have to verify the Client server certificate validation in HTTPS request(SSL hand shake before the actual HTTPS post request), And tried various ways and failed to verify it successfully.

here are the trials and errors,
Code:
resp = requests.post(url, req, verify=True, timeout=5, proxies=proxies, headers=headers)
'requests.exceptions.SSLError: HTTPSConnectionPool(host='XX.XX.XX.XX', port=8400): Max retries exceeded with url: /v1.1/registration (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)'),))

Code:
resp = requests.post(url,req, verify=client_ca, timeout=5, proxies=proxies, headers=headers)   

requests.exceptions.SSLError: HTTPSConnectionPool(host='XX.XX.XX.XX', port=8400): Max retries exceeded with url: /v1.1/registration (Caused by SSLError(SSLEOFError(8, u'EOF occurred in violation of protocol (_ssl.c:579)'),))

Code:
resp = requests.post(url,req, verify=True, cert=(client_cert,client_key), timeout=5, proxies=proxies, headers=headers)

requests.exceptions.SSLError: HTTPSConnectionPool(host='XX.XX.XX.XX', port=8400): Max retries exceeded with url: /v1.1/registration (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)'),))

Here url points to HTTPS url to which post request will be sent.
req is the json input data to HTTPS post request.
client_cert is the pem file having client certificate, with out key.
client_key is the client private key PEM file. proxies and headers are set accordingly.

i want a better working solution to verify the client certificate during HTTPS calls in python scripting.
 

6 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

mod_ssl redirect to site if client does not have valid certificate

Hello! I have setup a site to which users authenticate against with openssl certificates. Everything works just fine, be I wish to be able to redirect to a error page with instructions instead of displaying the default error page that firefox displays. How to? I got nothing out of google...... (6 Replies)
Discussion started by: Esaia
6 Replies

2. Programming

Client/Server Socket Application - Preventing Client from quitting on server crash

Problem - Linux Client/Server Socket Application: Preventing Client from quitting on server crash Hi, I am writing a Linux socket Server and Client using TCP protocol on Ubuntu 9.04 x64. I am having problem trying to implement a scenario where the client should keep running even when the... (2 Replies)
Discussion started by: varun.nagpaal
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a webservice and pass a client certificate

Hi, I am trying to call a http soap webservice using curl command , I have tried the below option but I am getting a failure . curl -H "Content-Type: text/xml; charset=utf-8" -H SOAPAction:" -d @Request.xml -X POST... (1 Reply)
Discussion started by: IshuGupta
1 Replies

4. UNIX for Dummies Questions & Answers

Sign Soap Message from client certificate from UNIX

I have to call a webservice , I need to pass the static request from Unix which should have message signing details in the soap header . I am using cURL command for this. I do not have java , I need to do it through Unix only . Below is the kind of Soap envelop I want to wrap around my request .... (0 Replies)
Discussion started by: IshuGupta
0 Replies

5. UNIX for Advanced & Expert Users

Does vsftpd support user access with client certificate with priv/pub key + vsftpd certificate?

:rolleyes:I am trying to setup all certificate based client-server environment in Linux using vsftpd and curl with openssl. I would like to make a user access with vsftpd certificate and user own client certificate (self-signed) with private/public key. I don't see google posts about the my plan... (4 Replies)
Discussion started by: gogogo
4 Replies

6. UNIX for Beginners Questions & Answers

How to install new certificate in HPUX client store?

We have a HPUX server that talks to a web service. We recently updated the web service certificate to a new SHA256 cert that has an updated intermediate cert. The HPUX server is now unable to connect because it cannot validate the cert chain due to it not having the new intermediate CA cert. I... (0 Replies)
Discussion started by: techmattr
0 Replies
TSGET(1SSL)							      OpenSSL							       TSGET(1SSL)

NAME
tsget - Time Stamping HTTP/HTTPS client SYNOPSIS
tsget -h server_url [-e extension] [-o output] [-v] [-d] [-k private_key.pem] [-p key_password] [-c client_cert.pem] [-C CA_certs.pem] [-P CA_path] [-r file:file...] [-g EGD_socket] [request]... DESCRIPTION
The tsget command can be used for sending a time stamp request, as specified in RFC 3161, to a time stamp server over HTTP or HTTPS and storing the time stamp response in a file. This tool cannot be used for creating the requests and verifying responses, you can use the OpenSSL ts(1) command to do that. tsget can send several requests to the server without closing the TCP connection if more than one requests are specified on the command line. The tool sends the following HTTP request for each time stamp request: POST url HTTP/1.1 User-Agent: OpenTSA tsget.pl/<version> Host: <host>:<port> Pragma: no-cache Content-Type: application/timestamp-query Accept: application/timestamp-reply Content-Length: length of body ...binary request specified by the user... tsget expects a response of type application/timestamp-reply, which is written to a file without any interpretation. OPTIONS
-h server_url The URL of the HTTP/HTTPS server listening for time stamp requests. -e extension If the -o option is not given this argument specifies the extension of the output files. The base name of the output file will be the same as those of the input files. Default extension is '.tsr'. (Optional) -o output This option can be specified only when just one request is sent to the server. The time stamp response will be written to the given output file. '-' means standard output. In case of multiple time stamp requests or the absence of this argument the names of the output files will be derived from the names of the input files and the default or specified extension argument. (Optional) -v The name of the currently processed request is printed on standard error. (Optional) -d Switches on verbose mode for the underlying curl library. You can see detailed debug messages for the connection. (Optional) -k private_key.pem (HTTPS) In case of certificate-based client authentication over HTTPS <private_key.pem> must contain the private key of the user. The private key file can optionally be protected by a passphrase. The -c option must also be specified. (Optional) -p key_password (HTTPS) Specifies the passphrase for the private key specified by the -k argument. If this option is omitted and the key is passphrase protected tsget will ask for it. (Optional) -c client_cert.pem (HTTPS) In case of certificate-based client authentication over HTTPS <client_cert.pem> must contain the X.509 certificate of the user. The -k option must also be specified. If this option is not specified no certificate-based client authentication will take place. (Optional) -C CA_certs.pem (HTTPS) The trusted CA certificate store. The certificate chain of the peer's certificate must include one of the CA certificates specified in this file. Either option -C or option -P must be given in case of HTTPS. (Optional) -P CA_path (HTTPS) The path containing the trusted CA certificates to verify the peer's certificate. The directory must be prepared with the c_rehash OpenSSL utility. Either option -C or option -P must be given in case of HTTPS. (Optional) -rand file:file... The files containing random data for seeding the random number generator. Multiple files can be specified, the separator is ; for MS- Windows, , for VMS and : for all other platforms. (Optional) -g EGD_socket The name of an EGD socket to get random data from. (Optional) [request]... List of files containing RFC 3161 DER-encoded time stamp requests. If no requests are specified only one request will be sent to the server and it will be read from the standard input. (Optional) ENVIRONMENT VARIABLES
The TSGET environment variable can optionally contain default arguments. The content of this variable is added to the list of command line arguments. EXAMPLES
The examples below presume that file1.tsq and file2.tsq contain valid time stamp requests, tsa.opentsa.org listens at port 8080 for HTTP requests and at port 8443 for HTTPS requests, the TSA service is available at the /tsa absolute path. Get a time stamp response for file1.tsq over HTTP, output is written to file1.tsr: tsget -h http://tsa.opentsa.org:8080/tsa file1.tsq Get a time stamp response for file1.tsq and file2.tsq over HTTP showing progress, output is written to file1.reply and file2.reply respectively: tsget -h http://tsa.opentsa.org:8080/tsa -v -e .reply file1.tsq file2.tsq Create a time stamp request, write it to file3.tsq, send it to the server and write the response to file3.tsr: openssl ts -query -data file3.txt -cert | tee file3.tsq | tsget -h http://tsa.opentsa.org:8080/tsa -o file3.tsr Get a time stamp response for file1.tsq over HTTPS without client authentication: tsget -h https://tsa.opentsa.org:8443/tsa -C cacerts.pem file1.tsq Get a time stamp response for file1.tsq over HTTPS with certificate-based client authentication (it will ask for the passphrase if client_key.pem is protected): tsget -h https://tsa.opentsa.org:8443/tsa -C cacerts.pem -k client_key.pem -c client_cert.pem file1.tsq You can shorten the previous command line if you make use of the TSGET environment variable. The following commands do the same as the previous example: TSGET='-h https://tsa.opentsa.org:8443/tsa -C cacerts.pem -k client_key.pem -c client_cert.pem' export TSGET tsget file1.tsq AUTHOR
Zoltan Glozik <zglozik@opentsa.org>, OpenTSA project (http://www.opentsa.org) SEE ALSO
openssl(1), ts(1), curl(1), RFC 3161 1.0.0e 2013-02-18 TSGET(1SSL)
All times are GMT -4. The time now is 04:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy