Compare commits
122 Commits
OpenSSL-en
...
OpenSSL_0_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
978ac53398 | ||
|
|
9beaae61ec | ||
|
|
53fe8d5be5 | ||
|
|
8c23788dd1 | ||
|
|
ef76e3dbda | ||
|
|
7ba839bfe2 | ||
|
|
d2dcf4f40d | ||
|
|
75a382bd90 | ||
|
|
5b0a0544f2 | ||
|
|
a0ec9cf6d5 | ||
|
|
e9ebf346c4 | ||
|
|
8ca533e378 | ||
|
|
d0c9858914 | ||
|
|
356c06c776 | ||
|
|
ef71cb6daf | ||
|
|
2e7e3d6ce9 | ||
|
|
a269d312da | ||
|
|
a87aa87bcc | ||
|
|
6df3553255 | ||
|
|
2eaad87f36 | ||
|
|
b7af080fb1 | ||
|
|
3a0afe1eed | ||
|
|
086a32d754 | ||
|
|
544ebbceb4 | ||
|
|
6d0dcbedb1 | ||
|
|
88aeb646bd | ||
|
|
46b1b91309 | ||
|
|
be054868a1 | ||
|
|
0acc90e5f7 | ||
|
|
4e20a4e688 | ||
|
|
9ef9e78520 | ||
|
|
393e826ec3 | ||
|
|
c5e8580e7b | ||
|
|
16221173c8 | ||
|
|
0e8f2fdfdd | ||
|
|
fec8c79a7e | ||
|
|
56245be46d | ||
|
|
eb206eb8be | ||
|
|
fda05b2155 | ||
|
|
8c4ab6d5ae | ||
|
|
8fdec3e558 | ||
|
|
69431c2998 | ||
|
|
90d7fc1de4 | ||
|
|
bb28bcdf98 | ||
|
|
d49da3aa5b | ||
|
|
fc55bf3b20 | ||
|
|
03dbae0d20 | ||
|
|
5a5accdd64 | ||
|
|
f1192b7f2e | ||
|
|
dbba890cf1 | ||
|
|
3f8b90c345 | ||
|
|
28a63d3e6f | ||
|
|
318e09356b | ||
|
|
6b3a4ffe36 | ||
|
|
7f6e0a4c09 | ||
|
|
6cffb201f3 | ||
|
|
4b0f00b7ce | ||
|
|
4aa4f333ed | ||
|
|
a04cfb72d5 | ||
|
|
1cbb729fdc | ||
|
|
d176986488 | ||
|
|
c759ddd676 | ||
|
|
9cfab47b18 | ||
|
|
6e3dfc1f3b | ||
|
|
ef63568e94 | ||
|
|
d40898dfab | ||
|
|
422e5a4807 | ||
|
|
6397710486 | ||
|
|
10bb0dbfec | ||
|
|
c19b6c922a | ||
|
|
c5f8bbbc0b | ||
|
|
4759abc5f2 | ||
|
|
e31e385ce3 | ||
|
|
b22bda21a1 | ||
|
|
b38d84d867 | ||
|
|
50b14a38f5 | ||
|
|
edb0d64367 | ||
|
|
33b1a4c218 | ||
|
|
645749ef98 | ||
|
|
9a0c0d3f74 | ||
|
|
7cae5f9fc8 | ||
|
|
18edda0f92 | ||
|
|
89681b183d | ||
|
|
c8973693ab | ||
|
|
4e87e05b25 | ||
|
|
fe03519704 | ||
|
|
b004872c59 | ||
|
|
933f32cc4d | ||
|
|
c6def253b4 | ||
|
|
dd3430a6e9 | ||
|
|
cb1fbf8e6a | ||
|
|
51012a0969 | ||
|
|
a45bd29535 | ||
|
|
688fbf5475 | ||
|
|
f4364e0730 | ||
|
|
fae8762630 | ||
|
|
28178bcf24 | ||
|
|
cec7fe4da6 | ||
|
|
c15602f48e | ||
|
|
3b2cbbcb9a | ||
|
|
c69c47b9fe | ||
|
|
5d1a5ddb65 | ||
|
|
f97cc10372 | ||
|
|
a3829b8650 | ||
|
|
615513ba52 | ||
|
|
2bd8aaefa4 | ||
|
|
252d333fc1 | ||
|
|
2aa4e2e2d4 | ||
|
|
c6cda0bdb7 | ||
|
|
730e37edb6 | ||
|
|
4b6e6ab91c | ||
|
|
24842e0586 | ||
|
|
159cf04e86 | ||
|
|
676432d4e1 | ||
|
|
1e72b77994 | ||
|
|
1cf3bbaea6 | ||
|
|
d448429e52 | ||
|
|
4534fb1c86 | ||
|
|
362f2b69ff | ||
|
|
3c184d8180 | ||
|
|
a440d6636f | ||
|
|
91e8cc6216 |
2
README
2
README
@@ -1,5 +1,5 @@
|
||||
|
||||
OpenSSL 0.9.6-beta1 11 Sep 2000
|
||||
OpenSSL 0.9.6-beta2 17 Sep 2000
|
||||
|
||||
Copyright (c) 1998-2000 The OpenSSL Project
|
||||
Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson
|
||||
|
||||
68
TABLE
68
TABLE
@@ -1162,11 +1162,11 @@ $shared_cflag =
|
||||
|
||||
*** hpux-parisc-cc
|
||||
$cc = cc
|
||||
$cflags = -Ae +O3 +ESlit -z -DB_ENDIAN -DBN_DIV2W -DMD32_XARRAY
|
||||
$cflags = +O3 +Optrs_strongly_typed +Olibcalls -Ae +ESlit -DB_ENDIAN -DBN_DIV2W -DMD32_XARRAY
|
||||
$unistd =
|
||||
$thread_cflag =
|
||||
$lflags = -ldld
|
||||
$bn_ops = BN_LLONG DES_PTR DES_UNROLL DES_RISC1
|
||||
$thread_cflag = -D_REENTRANT
|
||||
$lflags = -ldl
|
||||
$bn_ops = MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT
|
||||
$bn_obj =
|
||||
$des_obj =
|
||||
$bf_obj =
|
||||
@@ -1220,6 +1220,46 @@ $dso_scheme = dl
|
||||
$shared_target=
|
||||
$shared_cflag =
|
||||
|
||||
*** hpux-parisc1_1-cc
|
||||
$cc = cc
|
||||
$cflags = +DA1.1 +DS1.1 +O3 +Optrs_strongly_typed +Olibcalls -Ae +ESlit -DB_ENDIAN -DMD32_XARRAY
|
||||
$unistd =
|
||||
$thread_cflag = -D_REENTRANT
|
||||
$lflags = -ldl
|
||||
$bn_ops = MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT
|
||||
$bn_obj =
|
||||
$des_obj =
|
||||
$bf_obj =
|
||||
$md5_obj =
|
||||
$sha1_obj =
|
||||
$cast_obj =
|
||||
$rc4_obj =
|
||||
$rmd160_obj =
|
||||
$rc5_obj =
|
||||
$dso_scheme = dl
|
||||
$shared_target=
|
||||
$shared_cflag =
|
||||
|
||||
*** hpux-parisc2-cc
|
||||
$cc = cc
|
||||
$cflags = +DA2.0 +DS2.0 +O3 +Optrs_strongly_typed +Olibcalls -Ae +ESlit -DB_ENDIAN -DMD32_XARRAY
|
||||
$unistd =
|
||||
$thread_cflag = -D_REENTRANT
|
||||
$lflags = -ldl
|
||||
$bn_ops = SIXTY_FOUR_BIT MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT
|
||||
$bn_obj = asm/pa-risc2.o
|
||||
$des_obj =
|
||||
$bf_obj =
|
||||
$md5_obj =
|
||||
$sha1_obj =
|
||||
$cast_obj =
|
||||
$rc4_obj =
|
||||
$rmd160_obj =
|
||||
$rc5_obj =
|
||||
$dso_scheme = dl
|
||||
$shared_target=
|
||||
$shared_cflag =
|
||||
|
||||
*** hpux10-brokencc
|
||||
$cc = cc
|
||||
$cflags = -DB_ENDIAN -DBN_DIV2W -Ae +ESlit +O2 -z
|
||||
@@ -1320,6 +1360,26 @@ $dso_scheme = dl
|
||||
$shared_target=
|
||||
$shared_cflag =
|
||||
|
||||
*** hpux64-parisc2-cc
|
||||
$cc = cc
|
||||
$cflags = +DD64 +O3 +Optrs_strongly_typed +Olibcalls -Ae +ESlit -DB_ENDIAN -DMD32_XARRAY
|
||||
$unistd =
|
||||
$thread_cflag = -D_REENTRANT
|
||||
$lflags = -ldl
|
||||
$bn_ops = SIXTY_FOUR_BIT_LONG MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC1 DES_INT
|
||||
$bn_obj = asm/pa-risc2W.o
|
||||
$des_obj =
|
||||
$bf_obj =
|
||||
$md5_obj =
|
||||
$sha1_obj =
|
||||
$cast_obj =
|
||||
$rc4_obj =
|
||||
$rmd160_obj =
|
||||
$rc5_obj =
|
||||
$dso_scheme = dl
|
||||
$shared_target=
|
||||
$shared_cflag =
|
||||
|
||||
*** irix-cc
|
||||
$cc = cc
|
||||
$cflags = -O2 -use_readonly_const -DTERMIOS -DB_ENDIAN
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
* (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
|
||||
* major minor fix final patch/beta)
|
||||
*/
|
||||
#define OPENSSL_VERSION_NUMBER 0x00906001L
|
||||
#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.6-beta1 11 Sep 2000"
|
||||
#define OPENSSL_VERSION_NUMBER 0x00906002L
|
||||
#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.6-beta2 17 Sep 2000"
|
||||
#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
PKCS#12 demo applications
|
||||
|
||||
Written by Steve Henson.
|
||||
@@ -1,61 +0,0 @@
|
||||
/* pkread.c */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/pkcs12.h>
|
||||
|
||||
/* Simple PKCS#12 file reader */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
EVP_PKEY *pkey;
|
||||
X509 *cert;
|
||||
STACK_OF(X509) *ca = NULL;
|
||||
PKCS12 *p12;
|
||||
int i;
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "Usage: pkread p12file password opfile\n");
|
||||
exit (1);
|
||||
}
|
||||
SSLeay_add_all_algorithms();
|
||||
ERR_load_crypto_strings();
|
||||
if (!(fp = fopen(argv[1], "rb"))) {
|
||||
fprintf(stderr, "Error opening file %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
p12 = d2i_PKCS12_fp(fp, NULL);
|
||||
fclose (fp);
|
||||
if (!p12) {
|
||||
fprintf(stderr, "Error reading PKCS#12 file\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
exit (1);
|
||||
}
|
||||
if (!PKCS12_parse(p12, argv[2], &pkey, &cert, &ca)) {
|
||||
fprintf(stderr, "Error parsing PKCS#12 file\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
exit (1);
|
||||
}
|
||||
PKCS12_free(p12);
|
||||
if (!(fp = fopen(argv[3], "w"))) {
|
||||
fprintf(stderr, "Error opening file %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
if (pkey) {
|
||||
fprintf(fp, "***Private Key***\n");
|
||||
PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL);
|
||||
}
|
||||
if (cert) {
|
||||
fprintf(fp, "***User Certificate***\n");
|
||||
PEM_write_X509_AUX(fp, cert);
|
||||
}
|
||||
if (ca && sk_num(ca)) {
|
||||
fprintf(fp, "***Other Certificates***\n");
|
||||
for (i = 0; i < sk_X509_num(ca); i++)
|
||||
PEM_write_X509_AUX(fp, sk_X509_value(ca, i));
|
||||
}
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/* pkwrite.c */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/pkcs12.h>
|
||||
|
||||
/* Simple PKCS#12 file creator */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
EVP_PKEY *pkey;
|
||||
X509 *cert;
|
||||
PKCS12 *p12;
|
||||
if (argc != 5) {
|
||||
fprintf(stderr, "Usage: pkwrite infile password name p12file\n");
|
||||
exit(1);
|
||||
}
|
||||
SSLeay_add_all_algorithms();
|
||||
ERR_load_crypto_strings();
|
||||
if (!(fp = fopen(argv[1], "r"))) {
|
||||
fprintf(stderr, "Error opening file %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
cert = PEM_read_X509(fp, NULL, NULL, NULL);
|
||||
rewind(fp);
|
||||
pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL);
|
||||
fclose(fp);
|
||||
p12 = PKCS12_create(argv[2], argv[3], pkey, cert, NULL, 0,0,0,0,0);
|
||||
if(!p12) {
|
||||
fprintf(stderr, "Error creating PKCS#12 structure\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
exit(1);
|
||||
}
|
||||
if (!(fp = fopen(argv[4], "wb"))) {
|
||||
fprintf(stderr, "Error opening file %s\n", argv[1]);
|
||||
ERR_print_errors_fp(stderr);
|
||||
exit(1);
|
||||
}
|
||||
i2d_PKCS12_fp(fp, p12);
|
||||
PKCS12_free(p12);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
state_machine
|
||||
@@ -1,9 +0,0 @@
|
||||
CFLAGS=-I../../include -Wall -Werror -g
|
||||
|
||||
all: state_machine
|
||||
|
||||
state_machine: state_machine.o
|
||||
$(CC) -o state_machine state_machine.o -L../.. -lssl -lcrypto
|
||||
|
||||
test: state_machine
|
||||
./state_machine 10000 ../../apps/server.pem ../../apps/server.pem
|
||||
@@ -1,395 +0,0 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Nuron, a leader in hardware encryption technology, generously
|
||||
* sponsored the development of this demo by Ben Laurie.
|
||||
*
|
||||
* See http://www.nuron.com/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* the aim of this demo is to provide a fully working state-machine
|
||||
* style SSL implementation, i.e. one where the main loop acquires
|
||||
* some data, then converts it from or to SSL by feeding it into the
|
||||
* SSL state machine. It then does any I/O required by the state machine
|
||||
* and loops.
|
||||
*
|
||||
* In order to keep things as simple as possible, this implementation
|
||||
* listens on a TCP socket, which it expects to get an SSL connection
|
||||
* on (for example, from s_client) and from then on writes decrypted
|
||||
* data to stdout and encrypts anything arriving on stdin. Verbose
|
||||
* commentary is written to stderr.
|
||||
*
|
||||
* This implementation acts as a server, but it can also be done for a client. */
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
/* die_unless is intended to work like assert, except that it happens
|
||||
always, even if NDEBUG is defined. Use assert as a stopgap. */
|
||||
|
||||
#define die_unless(x) assert(x)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SSL_CTX *pCtx;
|
||||
BIO *pbioRead;
|
||||
BIO *pbioWrite;
|
||||
SSL *pSSL;
|
||||
} SSLStateMachine;
|
||||
|
||||
void SSLStateMachine_print_error(SSLStateMachine *pMachine,const char *szErr)
|
||||
{
|
||||
unsigned long l;
|
||||
|
||||
fprintf(stderr,"%s\n",szErr);
|
||||
while((l=ERR_get_error()))
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
ERR_error_string_n(l,buf,sizeof buf);
|
||||
fprintf(stderr,"Error %lx: %s\n",l,buf);
|
||||
}
|
||||
}
|
||||
|
||||
SSLStateMachine *SSLStateMachine_new(const char *szCertificateFile,
|
||||
const char *szKeyFile)
|
||||
{
|
||||
SSLStateMachine *pMachine=malloc(sizeof *pMachine);
|
||||
int n;
|
||||
|
||||
die_unless(pMachine);
|
||||
|
||||
pMachine->pCtx=SSL_CTX_new(SSLv23_server_method());
|
||||
die_unless(pMachine->pCtx);
|
||||
|
||||
n=SSL_CTX_use_certificate_file(pMachine->pCtx,szCertificateFile,
|
||||
SSL_FILETYPE_PEM);
|
||||
die_unless(n > 0);
|
||||
|
||||
n=SSL_CTX_use_PrivateKey_file(pMachine->pCtx,szKeyFile,SSL_FILETYPE_PEM);
|
||||
die_unless(n > 0);
|
||||
|
||||
pMachine->pSSL=SSL_new(pMachine->pCtx);
|
||||
die_unless(pMachine->pSSL);
|
||||
|
||||
pMachine->pbioRead=BIO_new(BIO_s_mem());
|
||||
|
||||
pMachine->pbioWrite=BIO_new(BIO_s_mem());
|
||||
|
||||
SSL_set_bio(pMachine->pSSL,pMachine->pbioRead,pMachine->pbioWrite);
|
||||
|
||||
SSL_set_accept_state(pMachine->pSSL);
|
||||
|
||||
return pMachine;
|
||||
}
|
||||
|
||||
void SSLStateMachine_read_inject(SSLStateMachine *pMachine,
|
||||
const unsigned char *aucBuf,int nBuf)
|
||||
{
|
||||
int n=BIO_write(pMachine->pbioRead,aucBuf,nBuf);
|
||||
/* 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.
|
||||
*/
|
||||
assert(n == nBuf);
|
||||
fprintf(stderr,"%d bytes of encrypted data fed to state machine\n",n);
|
||||
}
|
||||
|
||||
int SSLStateMachine_read_extract(SSLStateMachine *pMachine,
|
||||
unsigned char *aucBuf,int nBuf)
|
||||
{
|
||||
int n;
|
||||
|
||||
if(!SSL_is_init_finished(pMachine->pSSL))
|
||||
{
|
||||
fprintf(stderr,"Doing SSL_accept\n");
|
||||
n=SSL_accept(pMachine->pSSL);
|
||||
if(n == 0)
|
||||
fprintf(stderr,"SSL_accept returned zero\n");
|
||||
if(n < 0)
|
||||
{
|
||||
int err;
|
||||
|
||||
if((err=SSL_get_error(pMachine->pSSL,n)) == SSL_ERROR_WANT_READ)
|
||||
{
|
||||
fprintf(stderr,"SSL_accept wants more data\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SSLStateMachine_print_error(pMachine,"SSL_accept error");
|
||||
exit(7);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
n=SSL_read(pMachine->pSSL,aucBuf,nBuf);
|
||||
if(n < 0)
|
||||
{
|
||||
int err=SSL_get_error(pMachine->pSSL,n);
|
||||
|
||||
if(err == SSL_ERROR_WANT_READ)
|
||||
{
|
||||
fprintf(stderr,"SSL_read wants more data\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr,"%d bytes of decrypted data read from state machine\n",n);
|
||||
return n;
|
||||
}
|
||||
|
||||
int SSLStateMachine_write_can_extract(SSLStateMachine *pMachine)
|
||||
{
|
||||
int n=BIO_pending(pMachine->pbioWrite);
|
||||
if(n)
|
||||
fprintf(stderr,"There is encrypted data available to write\n");
|
||||
else
|
||||
fprintf(stderr,"There is no encrypted data available to write\n");
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int SSLStateMachine_write_extract(SSLStateMachine *pMachine,
|
||||
unsigned char *aucBuf,int nBuf)
|
||||
{
|
||||
int n;
|
||||
|
||||
n=BIO_read(pMachine->pbioWrite,aucBuf,nBuf);
|
||||
fprintf(stderr,"%d bytes of encrypted data read from state machine\n",n);
|
||||
return n;
|
||||
}
|
||||
|
||||
void SSLStateMachine_write_inject(SSLStateMachine *pMachine,
|
||||
const unsigned char *aucBuf,int nBuf)
|
||||
{
|
||||
int n=SSL_write(pMachine->pSSL,aucBuf,nBuf);
|
||||
/* 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.
|
||||
*/
|
||||
assert(n == nBuf);
|
||||
fprintf(stderr,"%d bytes of unencrypted data fed to state machine\n",n);
|
||||
}
|
||||
|
||||
int OpenSocket(int nPort)
|
||||
{
|
||||
int nSocket;
|
||||
struct sockaddr_in saServer;
|
||||
struct sockaddr_in saClient;
|
||||
int one=1;
|
||||
int nSize;
|
||||
int nFD;
|
||||
int nLen;
|
||||
|
||||
nSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
|
||||
if(nSocket < 0)
|
||||
{
|
||||
perror("socket");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(setsockopt(nSocket,SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof one) < 0)
|
||||
{
|
||||
perror("setsockopt");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
memset(&saServer,0,sizeof saServer);
|
||||
saServer.sin_family=AF_INET;
|
||||
saServer.sin_port=htons(nPort);
|
||||
nSize=sizeof saServer;
|
||||
if(bind(nSocket,(struct sockaddr *)&saServer,nSize) < 0)
|
||||
{
|
||||
perror("bind");
|
||||
exit(3);
|
||||
}
|
||||
|
||||
if(listen(nSocket,512) < 0)
|
||||
{
|
||||
perror("listen");
|
||||
exit(4);
|
||||
}
|
||||
|
||||
nLen=sizeof saClient;
|
||||
nFD=accept(nSocket,(struct sockaddr *)&saClient,&nLen);
|
||||
if(nFD < 0)
|
||||
{
|
||||
perror("accept");
|
||||
exit(5);
|
||||
}
|
||||
|
||||
fprintf(stderr,"Incoming accepted on port %d\n",nPort);
|
||||
|
||||
return nFD;
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
SSLStateMachine *pMachine;
|
||||
int nPort;
|
||||
int nFD;
|
||||
const char *szCertificateFile;
|
||||
const char *szKeyFile;
|
||||
|
||||
if(argc != 4)
|
||||
{
|
||||
fprintf(stderr,"%s <port> <certificate file> <key file>\n",argv[0]);
|
||||
exit(6);
|
||||
}
|
||||
|
||||
nPort=atoi(argv[1]);
|
||||
szCertificateFile=argv[2];
|
||||
szKeyFile=argv[3];
|
||||
|
||||
SSL_library_init();
|
||||
OpenSSL_add_ssl_algorithms();
|
||||
SSL_load_error_strings();
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
nFD=OpenSocket(nPort);
|
||||
|
||||
pMachine=SSLStateMachine_new(szCertificateFile,szKeyFile);
|
||||
|
||||
for( ; ; )
|
||||
{
|
||||
fd_set rfds,wfds;
|
||||
unsigned char buf[1024];
|
||||
int n;
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_ZERO(&wfds);
|
||||
|
||||
/* Select socket for input */
|
||||
FD_SET(nFD,&rfds);
|
||||
|
||||
/* Select socket for output */
|
||||
if(SSLStateMachine_write_can_extract(pMachine))
|
||||
FD_SET(nFD,&wfds);
|
||||
|
||||
/* Select stdin for input */
|
||||
FD_SET(0,&rfds);
|
||||
|
||||
/* Wait for something to do something */
|
||||
n=select(nFD+1,&rfds,&wfds,NULL,NULL);
|
||||
assert(n > 0);
|
||||
|
||||
/* Socket is ready for input */
|
||||
if(FD_ISSET(nFD,&rfds))
|
||||
{
|
||||
n=read(nFD,buf,sizeof buf);
|
||||
if(n == 0)
|
||||
{
|
||||
fprintf(stderr,"Got EOF on socket\n");
|
||||
exit(0);
|
||||
}
|
||||
assert(n > 0);
|
||||
|
||||
SSLStateMachine_read_inject(pMachine,buf,n);
|
||||
}
|
||||
|
||||
/* FIXME: we should only extract if stdout is ready */
|
||||
n=SSLStateMachine_read_extract(pMachine,buf,n);
|
||||
if(n < 0)
|
||||
{
|
||||
SSLStateMachine_print_error(pMachine,"read extract failed");
|
||||
break;
|
||||
}
|
||||
assert(n >= 0);
|
||||
if(n > 0)
|
||||
{
|
||||
int w;
|
||||
|
||||
w=write(1,buf,n);
|
||||
/* FIXME: we should push back any unwritten data */
|
||||
assert(w == n);
|
||||
}
|
||||
|
||||
/* Socket is ready for output (and therefore we have output to send) */
|
||||
if(FD_ISSET(nFD,&wfds))
|
||||
{
|
||||
int w;
|
||||
|
||||
n=SSLStateMachine_write_extract(pMachine,buf,sizeof buf);
|
||||
assert(n > 0);
|
||||
|
||||
w=write(nFD,buf,n);
|
||||
/* FIXME: we should push back any unwritten data */
|
||||
assert(w == n);
|
||||
}
|
||||
|
||||
/* Stdin is ready for input */
|
||||
if(FD_ISSET(0,&rfds))
|
||||
{
|
||||
n=read(0,buf,sizeof buf);
|
||||
if(n == 0)
|
||||
{
|
||||
fprintf(stderr,"Got EOF on stdin\n");
|
||||
exit(0);
|
||||
}
|
||||
assert(n > 0);
|
||||
|
||||
SSLStateMachine_write_inject(pMachine,buf,n);
|
||||
}
|
||||
}
|
||||
/* not reached */
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user