openssl_state_machine.c revision 9359bd100badb53fd8a465cb3a0a90b218b30c4c
867N/A/* This is adapted from the OpenSSL state_machine demo */ 369N/A/* ==================================================================== 369N/A * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 369N/A * Redistribution and use in source and binary forms, with or without 369N/A * modification, are permitted provided that the following conditions 369N/A * 1. Redistributions of source code must retain the above copyright 369N/A * notice, this list of conditions and the following disclaimer. 369N/A * 2. Redistributions in binary form must reproduce the above copyright 369N/A * notice, this list of conditions and the following disclaimer in 369N/A * the documentation and/or other materials provided with the 369N/A * 3. All advertising materials mentioning features or use of this 369N/A * software must display the following acknowledgment: 369N/A * "This product includes software developed by the OpenSSL Project 3817N/A * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 3817N/A * endorse or promote products derived from this software without 4659N/A * prior written permission. For written permission, please contact 3817N/A * openssl-core@openssl.org. 369N/A * 5. Products derived from this software may not be called "OpenSSL" 369N/A * nor may "OpenSSL" appear in their names without prior written 369N/A * permission of the OpenSSL Project. 369N/A * 6. Redistributions of any form whatsoever must retain the following 844N/A * "This product includes software developed by the OpenSSL Project 3817N/A * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 3817N/A * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 369N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 369N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 867N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 867N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1368N/A * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 1368N/A * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1368N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 867N/A * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3817N/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 867N/A * OF THE POSSIBILITY OF SUCH DAMAGE. 369N/A * ==================================================================== 369N/A * This product includes cryptographic software written by Eric Young 369N/A * (eay@cryptsoft.com). This product includes software written by Tim 369N/A * Hudson (tjh@cryptsoft.com). 369N/A * Nuron, a leader in hardware encryption technology, generously 369N/A * sponsored the development of this demo by Ben Laurie. 369N/A * the aim of this demo is to provide a fully working state-machine 369N/A * style SSL implementation, i.e. one where the main loop acquires 369N/A * some data, then converts it from or to SSL by feeding it into the 4659N/A * SSL state machine. It then does any I/O required by the state machine 369N/A * In order to keep things as simple as possible, this implementation 369N/A * listens on a TCP socket, which it expects to get an SSL connection 369N/A * on (for example, from s_client) and from then on writes decrypted 369N/A * data to stdout and encrypts anything arriving on stdin. Verbose 369N/A * commentary is written to stderr. 369N/A * This implementation acts as a server, but it can also be done for a client. */ 4337N/A/* die_unless is intended to work like assert, except that it happens 4337N/A always, even if NDEBUG is defined. Use assert as a stopgap. */ /* If it turns out this assert fails, then buffer the data here * and just feed it in in churn instead. Seems to me that it * should be guaranteed to succeed, though. fprintf(
stderr,
"%d bytes of encrypted data fed to state machine\n",n);
fprintf(
stderr,
"%d bytes of decrypted data read from state machine\n",n);
fprintf(
stderr,
"There is no encrypted data available to write\n");
fprintf(
stderr,
"%d bytes of encrypted data read from state machine\n",n);
/* If it turns out this assert fails, then buffer the data here * and just feed it in in churn instead. Seems to me that it * should be guaranteed to succeed, though. fprintf(
stderr,
"%d bytes of unencrypted data fed to state machine\n",n);