aboutsummaryrefslogtreecommitdiff
path: root/openssl/MacOS/GetHTTPS.src/GetHTTPS.cpp
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2009-06-28 22:07:26 +0000
committermarha <marha@users.sourceforge.net>2009-06-28 22:07:26 +0000
commit3562e78743202e43aec8727005182a2558117eca (patch)
tree8f9113a77d12470c5c851a2a8e4cb02e89df7d43 /openssl/MacOS/GetHTTPS.src/GetHTTPS.cpp
downloadvcxsrv-3562e78743202e43aec8727005182a2558117eca.tar.gz
vcxsrv-3562e78743202e43aec8727005182a2558117eca.tar.bz2
vcxsrv-3562e78743202e43aec8727005182a2558117eca.zip
Checked in the following released items:
xkeyboard-config-1.4.tar.gz ttf-bitstream-vera-1.10.tar.gz font-alias-1.0.1.tar.gz font-sun-misc-1.0.0.tar.gz font-sun-misc-1.0.0.tar.gz font-sony-misc-1.0.0.tar.gz font-schumacher-misc-1.0.0.tar.gz font-mutt-misc-1.0.0.tar.gz font-misc-misc-1.0.0.tar.gz font-misc-meltho-1.0.0.tar.gz font-micro-misc-1.0.0.tar.gz font-jis-misc-1.0.0.tar.gz font-isas-misc-1.0.0.tar.gz font-dec-misc-1.0.0.tar.gz font-daewoo-misc-1.0.0.tar.gz font-cursor-misc-1.0.0.tar.gz font-arabic-misc-1.0.0.tar.gz font-winitzki-cyrillic-1.0.0.tar.gz font-misc-cyrillic-1.0.0.tar.gz font-cronyx-cyrillic-1.0.0.tar.gz font-screen-cyrillic-1.0.1.tar.gz font-xfree86-type1-1.0.1.tar.gz font-adobe-utopia-type1-1.0.1.tar.gz font-ibm-type1-1.0.0.tar.gz font-bitstream-type1-1.0.0.tar.gz font-bitstream-speedo-1.0.0.tar.gz font-bh-ttf-1.0.0.tar.gz font-bh-type1-1.0.0.tar.gz font-bitstream-100dpi-1.0.0.tar.gz font-bh-lucidatypewriter-100dpi-1.0.0.tar.gz font-bh-100dpi-1.0.0.tar.gz font-adobe-utopia-100dpi-1.0.1.tar.gz font-adobe-100dpi-1.0.0.tar.gz font-util-1.0.1.tar.gz font-bitstream-75dpi-1.0.0.tar.gz font-bh-lucidatypewriter-75dpi-1.0.0.tar.gz font-adobe-utopia-75dpi-1.0.1.tar.gz font-bh-75dpi-1.0.0.tar.gz bdftopcf-1.0.1.tar.gz font-adobe-75dpi-1.0.0.tar.gz mkfontscale-1.0.6.tar.gz openssl-0.9.8k.tar.gz bigreqsproto-1.0.2.tar.gz xtrans-1.2.2.tar.gz resourceproto-1.0.2.tar.gz inputproto-1.4.4.tar.gz compositeproto-0.4.tar.gz damageproto-1.1.0.tar.gz zlib-1.2.3.tar.gz xkbcomp-1.0.5.tar.gz freetype-2.3.9.tar.gz pthreads-w32-2-8-0-release.tar.gz pixman-0.12.0.tar.gz kbproto-1.0.3.tar.gz evieext-1.0.2.tar.gz fixesproto-4.0.tar.gz recordproto-1.13.2.tar.gz randrproto-1.2.2.tar.gz scrnsaverproto-1.1.0.tar.gz renderproto-0.9.3.tar.gz xcmiscproto-1.1.2.tar.gz fontsproto-2.0.2.tar.gz xextproto-7.0.3.tar.gz xproto-7.0.14.tar.gz libXdmcp-1.0.2.tar.gz libxkbfile-1.0.5.tar.gz libfontenc-1.0.4.tar.gz libXfont-1.3.4.tar.gz libX11-1.1.5.tar.gz libXau-1.0.4.tar.gz libxcb-1.1.tar.gz xorg-server-1.5.3.tar.gz
Diffstat (limited to 'openssl/MacOS/GetHTTPS.src/GetHTTPS.cpp')
-rw-r--r--openssl/MacOS/GetHTTPS.src/GetHTTPS.cpp209
1 files changed, 209 insertions, 0 deletions
diff --git a/openssl/MacOS/GetHTTPS.src/GetHTTPS.cpp b/openssl/MacOS/GetHTTPS.src/GetHTTPS.cpp
new file mode 100644
index 000000000..3a5e3f018
--- /dev/null
+++ b/openssl/MacOS/GetHTTPS.src/GetHTTPS.cpp
@@ -0,0 +1,209 @@
+/*
+ * An demo illustrating how to retrieve a URI from a secure HTTP server.
+ *
+ * Author: Roy Wood
+ * Date: September 7, 1999
+ * Comments: This relies heavily on my MacSockets library.
+ * This project is also set up so that it expects the OpenSSL source folder (0.9.4 as I write this)
+ * to live in a folder called "OpenSSL-0.9.4" in this project's parent folder. For example:
+ *
+ * Macintosh HD:
+ * Development:
+ * OpenSSL-0.9.4:
+ * (OpenSSL sources here)
+ * OpenSSL Example:
+ * (OpenSSL example junk here)
+ *
+ *
+ * Also-- before attempting to compile this, make sure the aliases in "OpenSSL-0.9.4:include:openssl"
+ * are installed! Use the AppleScript applet in the "openssl-0.9.4" folder to do this!
+ */
+/* modified to seed the PRNG */
+/* modified to use CRandomizer for seeding */
+
+
+// Include some funky libs I've developed over time
+
+#include "CPStringUtils.hpp"
+#include "ErrorHandling.hpp"
+#include "MacSocket.h"
+#include "Randomizer.h"
+
+// We use the OpenSSL implementation of SSL....
+// This was a lot of work to finally get going, though you wouldn't know it by the results!
+
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+
+#include <timer.h>
+
+// Let's try grabbing some data from here:
+
+#define kHTTPS_DNS "www.apache-ssl.org"
+#define kHTTPS_Port 443
+#define kHTTPS_URI "/"
+
+
+// Forward-declare this
+
+OSErr MyMacSocket_IdleWaitCallback(void *inUserRefPtr);
+
+// My idle-wait callback. Doesn't do much, does it? Silly cooperative multitasking.
+
+OSErr MyMacSocket_IdleWaitCallback(void *inUserRefPtr)
+{
+#pragma unused(inUserRefPtr)
+
+EventRecord theEvent;
+ ::EventAvail(everyEvent,&theEvent);
+
+ CRandomizer *randomizer = (CRandomizer*)inUserRefPtr;
+ if (randomizer)
+ randomizer->PeriodicAction();
+
+ return(noErr);
+}
+
+
+// Finally!
+
+void main(void)
+{
+ OSErr errCode;
+ int theSocket = -1;
+ int theTimeout = 30;
+
+ SSL_CTX *ssl_ctx = nil;
+ SSL *ssl = nil;
+
+ char tempString[256];
+ UnsignedWide microTickCount;
+
+
+ CRandomizer randomizer;
+
+ printf("OpenSSL Demo by Roy Wood, roy@centricsystems.ca\n\n");
+
+ BailIfError(errCode = MacSocket_Startup());
+
+
+
+ // Create a socket-like object
+
+ BailIfError(errCode = MacSocket_socket(&theSocket,false,theTimeout * 60,MyMacSocket_IdleWaitCallback,&randomizer));
+
+
+ // Set up the connect string and try to connect
+
+ CopyCStrAndInsertCStrLongIntIntoCStr("%s:%ld",kHTTPS_DNS,kHTTPS_Port,tempString,sizeof(tempString));
+
+ printf("Connecting to %s....\n",tempString);
+
+ BailIfError(errCode = MacSocket_connect(theSocket,tempString));
+
+
+ // Init SSL stuff
+
+ SSL_load_error_strings();
+
+ SSLeay_add_ssl_algorithms();
+
+
+ // Pick the SSL method
+
+// ssl_ctx = SSL_CTX_new(SSLv2_client_method());
+ ssl_ctx = SSL_CTX_new(SSLv23_client_method());
+// ssl_ctx = SSL_CTX_new(SSLv3_client_method());
+
+
+ // Create an SSL thingey and try to negotiate the connection
+
+ ssl = SSL_new(ssl_ctx);
+
+ SSL_set_fd(ssl,theSocket);
+
+ errCode = SSL_connect(ssl);
+
+ if (errCode < 0)
+ {
+ SetErrorMessageAndLongIntAndBail("OpenSSL: Can't initiate SSL connection, SSL_connect() = ",errCode);
+ }
+
+ // Request the URI from the host
+
+ CopyCStrToCStr("GET ",tempString,sizeof(tempString));
+ ConcatCStrToCStr(kHTTPS_URI,tempString,sizeof(tempString));
+ ConcatCStrToCStr(" HTTP/1.0\r\n\r\n",tempString,sizeof(tempString));
+
+
+ errCode = SSL_write(ssl,tempString,CStrLength(tempString));
+
+ if (errCode < 0)
+ {
+ SetErrorMessageAndLongIntAndBail("OpenSSL: Error writing data via ssl, SSL_write() = ",errCode);
+ }
+
+
+ for (;;)
+ {
+ char tempString[256];
+ int bytesRead;
+
+
+ // Read some bytes and dump them to the console
+
+ bytesRead = SSL_read(ssl,tempString,sizeof(tempString) - 1);
+
+ if (bytesRead == 0 && MacSocket_RemoteEndIsClosing(theSocket))
+ {
+ break;
+ }
+
+ else if (bytesRead < 0)
+ {
+ SetErrorMessageAndLongIntAndBail("OpenSSL: Error reading data via ssl, SSL_read() = ",bytesRead);
+ }
+
+
+ tempString[bytesRead] = '\0';
+
+ printf("%s", tempString);
+ }
+
+ printf("\n\n\n");
+
+ // All done!
+
+ errCode = noErr;
+
+
+EXITPOINT:
+
+ // Clean up and go home
+
+ if (theSocket >= 0)
+ {
+ MacSocket_close(theSocket);
+ }
+
+ if (ssl != nil)
+ {
+ SSL_free(ssl);
+ }
+
+ if (ssl_ctx != nil)
+ {
+ SSL_CTX_free(ssl_ctx);
+ }
+
+
+ if (errCode != noErr)
+ {
+ printf("An error occurred:\n");
+
+ printf("%s",GetErrorMessage());
+ }
+
+
+ MacSocket_Shutdown();
+}