TCP- and SSL-Connection Examples
This commit is contained in:
		| @@ -3,7 +3,7 @@ | ||||
| ##       1         2         3         4         5         6         7         8 | ||||
| ## 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| noinst_PROGRAMS = pcsc-demo cryptoki-demo | ||||
| noinst_PROGRAMS = pcsc-demo cryptoki-demo openssl-tcp-demo openssl-ssl-demo | ||||
|  | ||||
| AM_CPPFLAGS = -I${top_srcdir}/src | ||||
| if !MINGW32 | ||||
| @@ -27,4 +27,20 @@ else | ||||
| cryptoki_demo_LDADD += -ldl -lpthread -lssl | ||||
| endif | ||||
|  | ||||
| openssl_tcp_demo_SOURCES = openssl-tcp-demo.cxx | ||||
| openssl_tcp_demo_LDFLAGS = -L${top_builddir}/src | ||||
| if MINGW32 | ||||
| openssl_tcp_demo_LDADD = -leay32 | ||||
| else | ||||
| openssl_tcp_demo_LDADD = -ldl -lpthread -lssl | ||||
| endif | ||||
|  | ||||
| openssl_ssl_demo_SOURCES = openssl-ssl-demo.cxx | ||||
| openssl_ssl_demo_LDFLAGS = -L${top_builddir}/src | ||||
| if MINGW32 | ||||
| openssl_ssl_demo_LDADD = -leay32 | ||||
| else | ||||
| openssl_ssl_demo_LDADD = -ldl -lpthread -lssl | ||||
| endif | ||||
|  | ||||
| MAINTAINERCLEANFILES = makefile.in | ||||
|   | ||||
							
								
								
									
										28
									
								
								doc/examples/openssl-ssl-demo.cxx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								doc/examples/openssl-ssl-demo.cxx
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| /*! @file | ||||
|  | ||||
|     @id $Id$ | ||||
| */ | ||||
| //       1         2         3         4         5         6         7         8 | ||||
| // 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| #define OPENSSL_LOG(X) | ||||
| #include <openssl.hxx> | ||||
| #include <iostream> | ||||
|  | ||||
| int main(int argc, char** argv) try { | ||||
|   openssl::Init init; | ||||
|   std::string host(argc>1?argv[1]:"dev.swisssign.com"); | ||||
|   std::string port(argc>2?argv[2]:"443"); | ||||
|   std::string path(argc>3?argv[3]:"/"); | ||||
|   std::cout<<"Connect to: "<<host<<':'<<port<<std::endl; | ||||
|   openssl::SSL ssl | ||||
|     (openssl::TrustStore("/usr/lib/ssl/certs/SwissSign_Gold_CA_-_G2.pem")); | ||||
|   ssl.connect(host+':'+port)<<"GET "<<path<<" HTTP/1.1\n" | ||||
|                             <<"Host: "<<host<<"\n" | ||||
|                             <<"Connection: Close\n\n"; | ||||
|   while (ssl) std::cout<<ssl; | ||||
|   return 0; | ||||
|  } catch (const std::exception& x) { | ||||
|   std::cerr<<"**** ERROR: "<<x.what()<<std::endl; | ||||
|   return 1; | ||||
|  } | ||||
							
								
								
									
										25
									
								
								doc/examples/openssl-tcp-demo.cxx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								doc/examples/openssl-tcp-demo.cxx
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| /*! @file | ||||
|  | ||||
|     @id $Id$ | ||||
| */ | ||||
| //       1         2         3         4         5         6         7         8 | ||||
| // 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| //#define OPENSSL_LOG(X) | ||||
| #include <openssl.hxx> | ||||
| #include <iostream> | ||||
|  | ||||
| int main(int argc, char** argv) try { | ||||
|   openssl::Init init; | ||||
|   std::string host(argc>1?argv[1]:"swisssign.com"); | ||||
|   std::string port(argc>2?argv[2]:"80"); | ||||
|   std::cout<<"Connect to: "<<host<<':'<<port<<std::endl; | ||||
|   openssl::TCP ssl(host+':'+port); | ||||
|   ssl<<"GET / HTTP/1.1\x0D\x0AHost: "<<host | ||||
|      <<"\x0D\x0A\x43onnection: Close\x0D\x0A\x0D\x0A"; | ||||
|   while (ssl) std::cout<<ssl; | ||||
|   return 0; | ||||
|  } catch (const std::exception& x) { | ||||
|   std::cerr<<"**** ERROR: "<<x.what()<<std::endl; | ||||
|   return 1; | ||||
|  } | ||||
		Reference in New Issue
	
	Block a user