summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/isakmpd/dyn.c82
-rw-r--r--sbin/isakmpd/dyn.h54
-rw-r--r--sbin/isakmpd/libcrypto.c160
-rw-r--r--sbin/isakmpd/libcrypto.h137
4 files changed, 433 insertions, 0 deletions
diff --git a/sbin/isakmpd/dyn.c b/sbin/isakmpd/dyn.c
new file mode 100644
index 00000000000..a189c4d138d
--- /dev/null
+++ b/sbin/isakmpd/dyn.c
@@ -0,0 +1,82 @@
+/* $OpenBSD: dyn.c,v 1.1 1999/08/28 11:54:55 niklas Exp $ */
+/* $EOM: dyn.c,v 1.2 1999/08/26 11:13:36 niklas Exp $ */
+
+/*
+ * Copyright (c) 1999 Niklas Hallqvist. 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 acknowledgement:
+ * This product includes software developed by Ericsson Radio Systems.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 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 AUTHOR 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 code was written under funding by Ericsson Radio Systems.
+ */
+
+#include <dlfcn.h>
+
+#include "sysdep.h"
+
+#include "dyn.h"
+#include "log.h"
+
+int
+dyn_load (struct dynload_script *scr)
+{
+ int i;
+ void **desc = 0;
+
+ for (i = 0; scr[i].op != EOS; i++)
+ switch (scr[i].op)
+ {
+ case LOAD:
+ desc = scr[i].ptr;
+ *desc = dlopen (scr[i].name, DL_LAZY);
+ if (!*desc)
+ {
+ log_print ("dyn_load: dlopen (\"%s\", DL_LAZY) failed: %s",
+ scr[i].name, dlerror ());
+ return 0;
+ }
+ break;
+
+ case SYM:
+ if (!desc || !*desc)
+ continue;
+ *scr[i].ptr = dlsym (*desc, scr[i].name);
+ if (!*scr[i].ptr)
+ {
+ log_print ("dyn_load: dlsym (\"%s\") failed: %s", scr[i].name,
+ dlerror ());
+ *desc = 0;
+ return 0;
+ }
+ break;
+
+ default:
+ log_print ("dyn_load: bad operation (%d) on entry %d, ignoring",
+ scr[i].op, i);
+ }
+ return 1;
+}
diff --git a/sbin/isakmpd/dyn.h b/sbin/isakmpd/dyn.h
new file mode 100644
index 00000000000..dbfeb70e9a4
--- /dev/null
+++ b/sbin/isakmpd/dyn.h
@@ -0,0 +1,54 @@
+/* $OpenBSD: dyn.h,v 1.1 1999/08/28 11:54:55 niklas Exp $ */
+/* $EOM: dyn.h,v 1.1 1999/08/12 22:34:27 niklas Exp $ */
+
+/*
+ * Copyright (c) 1999 Niklas Hallqvist. 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 acknowledgement:
+ * This product includes software developed by Ericsson Radio Systems.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 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 AUTHOR 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 code was written under funding by Ericsson Radio Systems.
+ */
+
+#ifndef _DYN_H_
+#define _DYN_H_
+
+#ifdef SYMBOL_PREFIX
+#define SYM(x) SYMBOL_PREFIX #x
+#else
+#define SYM(x) #x
+#endif
+
+struct dynload_script {
+ enum { LOAD, SYM, EOS } op;
+ char *name;
+ void **ptr;
+};
+
+int dyn_load (struct dynload_script *);
+
+#endif /* _DYN_H_ */
diff --git a/sbin/isakmpd/libcrypto.c b/sbin/isakmpd/libcrypto.c
new file mode 100644
index 00000000000..35f5b922d94
--- /dev/null
+++ b/sbin/isakmpd/libcrypto.c
@@ -0,0 +1,160 @@
+/* $OpenBSD: libcrypto.c,v 1.1 1999/08/28 11:54:55 niklas Exp $ */
+/* $EOM: libcrypto.c,v 1.5 1999/08/26 11:16:48 niklas Exp $ */
+
+/*
+ * Copyright (c) 1999 Niklas Hallqvist. 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 acknowledgement:
+ * This product includes software developed by Ericsson Radio Systems.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 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 AUTHOR 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 code was written under funding by Ericsson Radio Systems.
+ */
+
+#include "sysdep.h"
+
+#include "dyn.h"
+#include "libcrypto.h"
+
+void *libcrypto = 0;
+
+#ifdef HAVE_DLOPEN
+
+/*
+ * These prototypes matches SSLeay version 0.9.0b, if you try to load
+ * a different version than that, you are on your own.
+ */
+char *(*lc_ASN1_d2i_bio) (char *(*) (), char *(*) (), BIO *bp,
+ unsigned char **);
+char *(*lc_ASN1_dup) (int (*) (), char *(*) (), char *);
+long (*lc_BIO_ctrl) (BIO *bp, int, long, char *);
+int (*lc_BIO_free) (BIO *a);
+BIO *(*lc_BIO_new) (BIO_METHOD *type);
+int (*lc_BIO_write) (BIO *, char *, int);
+BIO_METHOD *(*lc_BIO_s_file) (void);
+BIO_METHOD *(*lc_BIO_s_mem) (void);
+int (*lc_BN_print_fp) (FILE *, BIGNUM *);
+char *(*lc_PEM_ASN1_read_bio) (char *(*) (), char *, BIO *, char **,
+ int (*) ());
+void (*lc_RSA_free) (RSA *);
+RSA *(*lc_RSA_generate_key) (int, unsigned long, void (*) (int, int, char *),
+ char *);
+int (*lc_RSA_private_encrypt) (int, unsigned char *, unsigned char *, RSA *,
+ int);
+int (*lc_RSA_public_decrypt) (int, unsigned char *, unsigned char *, RSA *,
+ int);
+int (*lc_RSA_size) (RSA *);
+void (*lc_SSLeay_add_all_algorithms) (void);
+int (*lc_X509_NAME_cmp) (X509_NAME *, X509_NAME *);
+void (*lc_X509_STORE_CTX_cleanup) (X509_STORE_CTX *);
+void (*lc_X509_STORE_CTX_init) (X509_STORE_CTX *, X509_STORE *, X509 *,
+ STACK *);
+int (*lc_X509_STORE_add_cert) (X509_STORE *, X509 *);
+X509_STORE *(*lc_X509_STORE_new) (void);
+X509 *(*lc_X509_dup) (X509 *);
+void (*lc_X509_free) (X509 *);
+X509_EXTENSION *(*lc_X509_get_ext) (X509 *, int);
+int (*lc_X509_get_ext_by_NID) (X509 *, int, int);
+X509_NAME *(*lc_X509_get_issuer_name) (X509 *);
+EVP_PKEY *(*lc_X509_get_pubkey) (X509 *);
+X509_NAME *(*lc_X509_get_subject_name) (X509 *);
+X509 *(*lc_X509_new) (void);
+int (*lc_X509_verify) (X509 *, EVP_PKEY *);
+int (*lc_X509_verify_cert) (X509_STORE_CTX *);
+RSA *(*lc_d2i_RSAPrivateKey) (RSA **, unsigned char **, long);
+RSA *(*lc_d2i_RSAPublicKey) (RSA **, unsigned char **, long);
+X509 *(*lc_d2i_X509) (X509 **, unsigned char **, long);
+int (*lc_i2d_RSAPublicKey) (RSA *, unsigned char **);
+int (*lc_i2d_RSAPrivateKey) (RSA *, unsigned char **);
+int (*lc_i2d_X509) (X509 *, unsigned char **);
+X509 *(*lc_X509_find_by_subject) (STACK *, X509_NAME *);
+#define SYMENTRY(x) { SYM, SYM (x), (void **)&lc_ ## x }
+
+static struct dynload_script libcrypto_script[] = {
+ { LOAD, "libc.so", &libcrypto },
+ { LOAD, "libcrypto.so", &libcrypto },
+ SYMENTRY (ASN1_d2i_bio),
+ SYMENTRY (ASN1_dup),
+ SYMENTRY (BIO_ctrl),
+ SYMENTRY (BIO_free),
+ SYMENTRY (BIO_new),
+ SYMENTRY (BIO_write),
+ SYMENTRY (BIO_s_file),
+ SYMENTRY (BIO_s_mem),
+ SYMENTRY (BN_print_fp),
+ SYMENTRY (PEM_ASN1_read_bio),
+ SYMENTRY (RSA_generate_key),
+ SYMENTRY (RSA_free),
+ SYMENTRY (RSA_private_encrypt),
+ SYMENTRY (RSA_public_decrypt),
+ SYMENTRY (RSA_size),
+ SYMENTRY (SSLeay_add_all_algorithms),
+ SYMENTRY (X509_NAME_cmp),
+ SYMENTRY (X509_STORE_CTX_cleanup),
+ SYMENTRY (X509_STORE_CTX_init),
+ SYMENTRY (X509_STORE_add_cert),
+ SYMENTRY (X509_STORE_new),
+ SYMENTRY (X509_dup),
+ SYMENTRY (X509_find_by_subject),
+ SYMENTRY (X509_free),
+ SYMENTRY (X509_get_ext),
+ SYMENTRY (X509_get_ext_by_NID),
+ SYMENTRY (X509_get_issuer_name),
+ SYMENTRY (X509_get_pubkey),
+ SYMENTRY (X509_get_subject_name),
+ SYMENTRY (X509_new),
+ SYMENTRY (X509_verify),
+ SYMENTRY (X509_verify_cert),
+ SYMENTRY (d2i_RSAPrivateKey),
+ SYMENTRY (d2i_RSAPublicKey),
+ SYMENTRY (d2i_X509),
+ SYMENTRY (i2d_RSAPublicKey),
+ SYMENTRY (i2d_RSAPrivateKey),
+ SYMENTRY (i2d_X509),
+ { EOS }
+};
+#endif
+
+void
+libcrypto_init (void)
+{
+#ifdef HAVE_DLOPEN
+ dyn_load (libcrypto_script);
+#elif !defined (USE_LIBCRYPTO)
+ return;
+#endif
+
+ /*
+ * XXX Do something imaginative with libcrypto here. The problem is if
+ * the dynload fails libcrypto will be 0 which is good for the macros but
+ * not the tests for support.
+ */
+
+#if defined (USE_LIBCRYPTO)
+ /* Add all algorithms known by SSL */
+ LC (SSLeay_add_all_algorithms, ());
+#endif
+}
diff --git a/sbin/isakmpd/libcrypto.h b/sbin/isakmpd/libcrypto.h
new file mode 100644
index 00000000000..5617d0a5c63
--- /dev/null
+++ b/sbin/isakmpd/libcrypto.h
@@ -0,0 +1,137 @@
+/* $OpenBSD: libcrypto.h,v 1.1 1999/08/28 11:54:55 niklas Exp $ */
+/* $EOM: libcrypto.h,v 1.3 1999/08/18 00:44:56 angelos Exp $ */
+
+/*
+ * Copyright (c) 1999 Niklas Hallqvist. 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 acknowledgement:
+ * This product includes software developed by Ericsson Radio Systems.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 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 AUTHOR 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 code was written under funding by Ericsson Radio Systems.
+ */
+
+#ifndef _LIBCRYPTO_H_
+#define _LIBCRYPTO_H_
+
+#include <stdio.h>
+/* XXX I want #include <ssl/cryptall.h> but we appear to not install meth.h */
+#include <ssl/bio.h>
+#include <ssl/pem.h>
+#include <ssl/x509_vfy.h>
+#include <ssl/x509.h>
+
+extern void *libcrypto;
+
+#if defined (USE_LIBCRYPTO)
+#if defined (HAVE_DLOPEN)
+#define LC(sym, args) (libcrypto ? lc_ ## sym args : sym args)
+#else
+#define LC(sym, args) sym args
+#endif
+#elif defined (HAVE_DLOPEN)
+#define LC(sym, args) lc_ ## sym args
+#else
+#define LC(sym, args) !!libcrypto called but no USE_LIBCRYPTO nor HAVE_DLOPEN!!
+#endif
+
+#ifdef HAVE_DLOPEN
+
+/*
+ * These prototypes matches SSLeay version 0.9.0b, if you try to load
+ * a different version than that, you are on your own.
+ */
+extern char *(*lc_ASN1_d2i_bio) (char *(*) (), char *(*) (), BIO *bp,
+ unsigned char **);
+extern char *(*lc_ASN1_dup) (int (*) (), char *(*) (), char *);
+extern long (*lc_BIO_ctrl) (BIO *bp, int, long, char *);
+extern int (*lc_BIO_free) (BIO *a);
+extern BIO *(*lc_BIO_new) (BIO_METHOD *type);
+extern int (*lc_BIO_write) (BIO *, char *, int);
+extern BIO_METHOD *(*lc_BIO_s_file) (void);
+extern BIO_METHOD *(*lc_BIO_s_mem) (void);
+extern int (*lc_BN_print_fp) (FILE *, BIGNUM *);
+extern char *(*lc_PEM_ASN1_read_bio) (char *(*) (), char *, BIO *, char **,
+ int (*) ());
+extern void (*lc_RSA_free) (RSA *);
+extern RSA *(*lc_RSA_generate_key) (int, unsigned long,
+ void (*) (int, int, char *), char *);
+extern int (*lc_RSA_private_encrypt) (int, unsigned char *, unsigned char *,
+ RSA *, int);
+extern int (*lc_RSA_public_decrypt) (int, unsigned char *, unsigned char *,
+ RSA *, int);
+extern int (*lc_RSA_size) (RSA *);
+extern void (*lc_SSLeay_add_all_algorithms) (void);
+extern int (*lc_X509_NAME_cmp) (X509_NAME *, X509_NAME *);
+extern void (*lc_X509_STORE_CTX_cleanup) (X509_STORE_CTX *);
+extern void (*lc_X509_STORE_CTX_init) (X509_STORE_CTX *, X509_STORE *, X509 *,
+ STACK *);
+extern int (*lc_X509_STORE_add_cert) (X509_STORE *, X509 *);
+extern X509_STORE *(*lc_X509_STORE_new) (void);
+extern X509 *(*lc_X509_dup) (X509 *);
+extern X509 *(*lc_X509_find_by_subject) (STACK *, X509_NAME *);
+extern void (*lc_X509_free) (X509 *);
+extern X509_EXTENSION *(*lc_X509_get_ext) (X509 *, int);
+extern int (*lc_X509_get_ext_by_NID) (X509 *, int, int);
+extern X509_NAME *(*lc_X509_get_issuer_name) (X509 *);
+extern EVP_PKEY *(*lc_X509_get_pubkey) (X509 *);
+extern X509_NAME *(*lc_X509_get_subject_name) (X509 *);
+extern X509 *(*lc_X509_new) (void);
+extern int (*lc_X509_verify) (X509 *, EVP_PKEY *);
+extern int (*lc_X509_verify_cert) (X509_STORE_CTX *);
+extern RSA *(*lc_d2i_RSAPrivateKey) (RSA **, unsigned char **, long);
+extern RSA *(*lc_d2i_RSAPublicKey) (RSA **, unsigned char **, long);
+extern X509 *(*lc_d2i_X509) (X509 **, unsigned char **, long);
+extern int (*lc_i2d_RSAPublicKey) (RSA *, unsigned char **);
+extern int (*lc_i2d_RSAPrivateKey) (RSA *, unsigned char **);
+extern int (*lc_i2d_X509) (X509 *, unsigned char **);
+
+#define lc_BIO_read_filename(b, name) \
+ lc_BIO_ctrl (b, BIO_C_SET_FILENAME, BIO_CLOSE | BIO_FP_READ, name)
+
+#define lc_PEM_read_bio_RSAPrivateKey(bp, x, cb) \
+ (RSA *)lc_PEM_ASN1_read_bio ((char *(*) ())lc_d2i_RSAPrivateKey, \
+ PEM_STRING_RSA, bp, (char **)x, cb)
+
+#define lc_PEM_read_bio_X509(bp, x, cb) \
+ (X509 *)lc_PEM_ASN1_read_bio ((char *(*) ())lc_d2i_X509, PEM_STRING_X509, \
+ bp, (char **)x, cb)
+
+#define lc_X509_name_cmp(a, b) lc_X509_NAME_cmp ((a), (b))
+
+#define lc_d2i_X509_bio(bp, x509) \
+ (X509 *)lc_ASN1_d2i_bio ((char *(*) ())lc_X509_new, \
+ (char *(*) ())lc_d2i_X509, (bp), \
+ (unsigned char **)(x509))
+
+#define lc_RSAPublicKey_dup(rsa) \
+ (RSA *)lc_ASN1_dup ((int (*) ())lc_i2d_RSAPublicKey, \
+ (char *(*) ())lc_d2i_RSAPublicKey, (char *)rsa)
+#endif
+
+extern void libcrypto_init (void);
+
+#endif /* _LIBCRYPTO_H_ */