Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_OSSL_H_)
00012 #define _OSSL_H_
00013
00014 #include RUBY_EXTCONF_H
00015
00016 #if defined(__cplusplus)
00017 extern "C" {
00018 #endif
00019
00020 #if 0
00021 mOSSL = rb_define_module("OpenSSL");
00022 mX509 = rb_define_module_under(mOSSL, "X509");
00023 #endif
00024
00025
00026
00027
00028 #if defined(RFILE)
00029 # undef RFILE
00030 #endif
00031 #include <ruby.h>
00032 #include <ruby/io.h>
00033
00034
00035
00036
00037
00038
00039 #include <openssl/opensslv.h>
00040
00041 #ifdef HAVE_ASSERT_H
00042 # include <assert.h>
00043 #else
00044 # define assert(condition)
00045 #endif
00046
00047 #if defined(_WIN32)
00048 # define OSSL_NO_CONF_API 1
00049 # if !defined(OPENSSL_SYS_WIN32)
00050 # define OPENSSL_SYS_WIN32 1
00051 # endif
00052 # include <winsock2.h>
00053 #endif
00054 #include <errno.h>
00055 #include <openssl/err.h>
00056 #include <openssl/asn1_mac.h>
00057 #include <openssl/x509v3.h>
00058 #include <openssl/ssl.h>
00059 #include <openssl/pkcs12.h>
00060 #include <openssl/pkcs7.h>
00061 #include <openssl/hmac.h>
00062 #include <openssl/rand.h>
00063 #include <openssl/conf.h>
00064 #include <openssl/conf_api.h>
00065 #undef X509_NAME
00066 #undef PKCS7_SIGNER_INFO
00067 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ST_ENGINE)
00068 # define OSSL_ENGINE_ENABLED
00069 # include <openssl/engine.h>
00070 #endif
00071 #if defined(HAVE_OPENSSL_OCSP_H)
00072 # define OSSL_OCSP_ENABLED
00073 # include <openssl/ocsp.h>
00074 #endif
00075
00076
00077
00078
00079 extern VALUE mOSSL;
00080
00081
00082
00083
00084 extern VALUE eOSSLError;
00085
00086
00087
00088
00089 #define OSSL_Check_Kind(obj, klass) do {\
00090 if (!rb_obj_is_kind_of(obj, klass)) {\
00091 ossl_raise(rb_eTypeError, "wrong argument (%s)! (Expected kind of %s)",\
00092 rb_obj_classname(obj), rb_class2name(klass));\
00093 }\
00094 } while (0)
00095
00096 #define OSSL_Check_Instance(obj, klass) do {\
00097 if (!rb_obj_is_instance_of(obj, klass)) {\
00098 ossl_raise(rb_eTypeError, "wrong argument (%s)! (Expected instance of %s)",\
00099 rb_obj_classname(obj), rb_class2name(klass));\
00100 }\
00101 } while (0)
00102
00103 #define OSSL_Check_Same_Class(obj1, obj2) do {\
00104 if (!rb_obj_is_instance_of(obj1, rb_obj_class(obj2))) {\
00105 ossl_raise(rb_eTypeError, "wrong argument type");\
00106 }\
00107 } while (0)
00108
00109
00110
00111
00112 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
00113 #define STACK _STACK
00114 #endif
00115
00116
00117
00118
00119 int string2hex(const unsigned char *, int, char **, int *);
00120
00121
00122
00123
00124 STACK_OF(X509) *ossl_x509_ary2sk0(VALUE);
00125 STACK_OF(X509) *ossl_x509_ary2sk(VALUE);
00126 STACK_OF(X509) *ossl_protect_x509_ary2sk(VALUE,int*);
00127 VALUE ossl_x509_sk2ary(STACK_OF(X509) *certs);
00128 VALUE ossl_x509crl_sk2ary(STACK_OF(X509_CRL) *crl);
00129 VALUE ossl_buf2str(char *buf, int len);
00130 #define ossl_str_adjust(str, p) \
00131 do{\
00132 int len = RSTRING_LEN(str);\
00133 int newlen = (p) - (unsigned char*)RSTRING_PTR(str);\
00134 assert(newlen <= len);\
00135 rb_str_set_len(str, newlen);\
00136 }while(0)
00137
00138
00139
00140
00141 int ossl_pem_passwd_cb(char *, int, int, void *);
00142
00143
00144
00145
00146 #define OSSL_ErrMsg() ERR_reason_error_string(ERR_get_error())
00147 NORETURN(void ossl_raise(VALUE, const char *, ...));
00148 VALUE ossl_exc_new(VALUE, const char *, ...);
00149
00150
00151
00152
00153 extern int ossl_verify_cb_idx;
00154
00155 struct ossl_verify_cb_args {
00156 VALUE proc;
00157 VALUE preverify_ok;
00158 VALUE store_ctx;
00159 };
00160
00161 VALUE ossl_call_verify_cb_proc(struct ossl_verify_cb_args *);
00162 int ossl_verify_cb(int, X509_STORE_CTX *);
00163
00164
00165
00166
00167 extern ID ossl_s_to_der;
00168 VALUE ossl_to_der(VALUE);
00169 VALUE ossl_to_der_if_possible(VALUE);
00170
00171
00172
00173
00174 extern VALUE dOSSL;
00175
00176 #if defined(HAVE_VA_ARGS_MACRO)
00177 #define OSSL_Debug(...) do { \
00178 if (dOSSL == Qtrue) { \
00179 fprintf(stderr, "OSSL_DEBUG: "); \
00180 fprintf(stderr, __VA_ARGS__); \
00181 fprintf(stderr, " [%s:%d]\n", __FILE__, __LINE__); \
00182 } \
00183 } while (0)
00184
00185 #define OSSL_Warning(fmt, ...) do { \
00186 OSSL_Debug(fmt, ##__VA_ARGS__); \
00187 rb_warning(fmt, ##__VA_ARGS__); \
00188 } while (0)
00189
00190 #define OSSL_Warn(fmt, ...) do { \
00191 OSSL_Debug(fmt, ##__VA_ARGS__); \
00192 rb_warn(fmt, ##__VA_ARGS__); \
00193 } while (0)
00194 #else
00195 void ossl_debug(const char *, ...);
00196 #define OSSL_Debug ossl_debug
00197 #define OSSL_Warning rb_warning
00198 #define OSSL_Warn rb_warn
00199 #endif
00200
00201
00202
00203
00204 #include "openssl_missing.h"
00205 #include "ruby_missing.h"
00206 #include "ossl_asn1.h"
00207 #include "ossl_bio.h"
00208 #include "ossl_bn.h"
00209 #include "ossl_cipher.h"
00210 #include "ossl_config.h"
00211 #include "ossl_digest.h"
00212 #include "ossl_hmac.h"
00213 #include "ossl_ns_spki.h"
00214 #include "ossl_ocsp.h"
00215 #include "ossl_pkcs12.h"
00216 #include "ossl_pkcs7.h"
00217 #include "ossl_pkcs5.h"
00218 #include "ossl_pkey.h"
00219 #include "ossl_rand.h"
00220 #include "ossl_ssl.h"
00221 #include "ossl_version.h"
00222 #include "ossl_x509.h"
00223 #include "ossl_engine.h"
00224
00225 void Init_openssl(void);
00226
00227 #if defined(__cplusplus)
00228 }
00229 #endif
00230
00231 #endif
00232
00233