Git Product home page Git Product logo

ppelleti / https-example Goto Github PK

View Code? Open in Web Editor NEW
176.0 15.0 77.0 20 KB

An example https client and server using OpenSSL and libevent, for the purpose of discussing some issues that came up on the libevent mailing list. This was just a one-off that I'm not maintaining, but I'm happy to accept pull requests.

Home Page: http://permalink.gmane.org/gmane.comp.lib.libevent.user/2791

C 83.32% Shell 0.43% Makefile 1.70% M4 14.56%

https-example's Introduction

This is probably not what you are looking for

Understandably, given that the name of the repository is https-example, I believe that a lot of people are coming here expecting to find an example of how to write an https server and/or client using libevent and OpenSSL.

Instead, this was something I threw together in 2013 as an example of a problem I was having when writing an https client and server using libevent and OpenSSL. I only posted it so I could discuss it on the libevent mailing list. I've kept it up in case it is useful to someone reading the mailing list archives, and because a number of people have starred or forked the repository.

If you're looking for an https client using libevent and OpenSSL, I would recommend checking out the example that comes with libevent. If you're looking for an https server using libevent and OpenSSL, I don't know of one to recommend. You might want to try asking on the libevent mailing list.

If you still want to look at the code in this repository, beware that the client and server are written to work together. The server only responds to a particular POST request generated by the client. (This is because this example is a simplified version of some programs I was writing at the time.) So if you want a general-purpose server, you'll need to modify it to respond to GET requests, at the very least.

Original README

ppelletier@chives:~/src/https-example$ uname -a
Linux chives 2.6.32-34-generic #77-Ubuntu SMP Tue Sep 13 19:39:17 UTC 2011 x86_64 GNU/Linux

start the server:

ppelletier@chives:~/src/https-example$ ./https-server
Using OpenSSL version "OpenSSL 1.0.1c 10 May 2012"
and libevent version "2.1.2-alpha-dev"
Loading certificate chain from 'server-certificate-chain.pem'
and private key from 'server-private-key.pem'
Listening on 0.0.0.0:8421

run the client... it works!

ppelletier@chives:~/src/https-example$ ./https-client
Using OpenSSL version "OpenSSL 1.0.1c 10 May 2012"
and libevent version "2.1.2-alpha-dev"
https server 'localhost' has this certificate, which looks good to me:
/C=US/ST=CA/L=Los Angeles/O=Oblong Industries/OU=Plasma/CN=localhost
server said: Hi 127.0.0.1!  I liked your passcode.

do the same thing with curl instead of with the client:

ppelletier@chives:~/src/https-example$ curl -k -d 'passcode=R23' https://localhost:8421/
Hi 127.0.0.1!  I liked your passcode.

Now, change the "#if 1" on line 214 of https-client.c to "#if 0", to
get rid of the special hack that turns "localhost" into "127.0.0.1",
in order to avoid IPv6.  Here's what happens:

ppelletier@chives:~/src/https-example$ ./https-client
Using OpenSSL version "OpenSSL 1.0.1c 10 May 2012"
and libevent version "2.1.2-alpha-dev"
code=0  POST failed
server said:

Next, change the "#if 0" on line 100 of https-client.c to "#if 1", to
enable retries:

ppelletier@chives:~/src/https-example$ ./https-client
Using OpenSSL version "OpenSSL 1.0.1c 10 May 2012"
and libevent version "2.1.2-alpha-dev"
[warn] Epoll ADD(1) on fd 7 failed.  Old events were 0; read change was 1 (add); write change was 0 (none): Bad file descriptor
[warn] Epoll ADD(4) on fd 7 failed.  Old events were 0; read change was 0 (none); write change was 1 (add): Bad file descriptor
code=0  POST failed
socket error = Bad file descriptor (9)
server said: (null)

https-example's People

Contributors

jhindin avatar ppelleti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

https-example's Issues

Hi,i am new,and i want to ask you some questions,please help me

I read your guid,and used your source code,after a few days debugging,now i can run it.But questions come,when i use whireshark to test,i can not capture SSL or HTTP packet,the only packets that i can capture are TCPs.It confused me a lot.Could you please help me?

Where to find libevent >= 2.1.2?

Patrick, thanks for writing this examples.

I am trying to compile the examples by

git clone https://github.com/ppelleti/https-example.git
./configure

But got error saying:

checking for LIBEVENT... no
configure: error: Package requirements (libevent >= 2.1.2
                               libevent_pthreads >= 2.1.2
                               libevent_openssl >= 2.1.2) were not met:

Requested 'libevent >= 2.1.2' but version of libevent is 2.0.16-stable
Requested 'libevent_pthreads >= 2.1.2' but version of libevent_pthreads is 2.0.16-stable
Requested 'libevent_openssl >= 2.1.2' but version of libevent_openssl is 2.0.16-stable

The official page http://libevent.org/ shows the latest stable build is 2.0.21.
Wonder where to find the libevent 2.1.2. By the way, my PC is ubuntu 12.04.
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.