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 # include <openssl/e_os2.h>
00049 # define OSSL_NO_CONF_API 1
00050 # if !defined(OPENSSL_SYS_WIN32)
00051 # define OPENSSL_SYS_WIN32 1
00052 # endif
00053 # include <winsock2.h>
00054 #endif
00055 #include <errno.h>
00056 #include <openssl/err.h>
00057 #include <openssl/asn1_mac.h>
00058 #include <openssl/x509v3.h>
00059 #include <openssl/ssl.h>
00060 #include <openssl/pkcs12.h>
00061 #include <openssl/pkcs7.h>
00062 #include <openssl/hmac.h>
00063 #include <openssl/rand.h>
00064 #include <openssl/conf.h>
00065 #include <openssl/conf_api.h>
00066 #undef X509_NAME
00067 #undef PKCS7_SIGNER_INFO
00068 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ST_ENGINE)
00069 # define OSSL_ENGINE_ENABLED
00070 # include <openssl/engine.h>
00071 #endif
00072 #if defined(HAVE_OPENSSL_OCSP_H)
00073 # define OSSL_OCSP_ENABLED
00074 # include <openssl/ocsp.h>
00075 #endif
00076
00077
00078
00079
00080 extern VALUE mOSSL;
00081
00082
00083
00084
00085 extern VALUE eOSSLError;
00086
00087
00088
00089
00090 #define OSSL_Check_Kind(obj, klass) do {\
00091 if (!rb_obj_is_kind_of((obj), (klass))) {\
00092 ossl_raise(rb_eTypeError, "wrong argument (%"PRIsVALUE")! (Expected kind of %s)",\
00093 RB_OBJ_CLASSNAME(obj), rb_class2name(klass));\
00094 }\
00095 } while (0)
00096
00097 #define OSSL_Check_Instance(obj, klass) do {\
00098 if (!rb_obj_is_instance_of((obj), (klass))) {\
00099 ossl_raise(rb_eTypeError, "wrong argument (%"PRIsVALUE")! (Expected instance of %s)",\
00100 RB_OBJ_CLASSNAME(obj), rb_class2name(klass));\
00101 }\
00102 } while (0)
00103
00104 #define OSSL_Check_Same_Class(obj1, obj2) do {\
00105 if (!rb_obj_is_instance_of((obj1), rb_obj_class(obj2))) {\
00106 ossl_raise(rb_eTypeError, "wrong argument type");\
00107 }\
00108 } while (0)
00109
00110
00111
00112
00113 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
00114 #define STACK _STACK
00115 #endif
00116
00117
00118
00119
00120 int string2hex(const unsigned char *, int, char **, int *);
00121
00122
00123
00124
00125 STACK_OF(X509) *ossl_x509_ary2sk0(VALUE);
00126 STACK_OF(X509) *ossl_x509_ary2sk(VALUE);
00127 STACK_OF(X509) *ossl_protect_x509_ary2sk(VALUE,int*);
00128 VALUE ossl_x509_sk2ary(STACK_OF(X509) *certs);
00129 VALUE ossl_x509crl_sk2ary(STACK_OF(X509_CRL) *crl);
00130 VALUE ossl_x509name_sk2ary(STACK_OF(X509_NAME) *names);
00131 VALUE ossl_buf2str(char *buf, int len);
00132 #define ossl_str_adjust(str, p) \
00133 do{\
00134 int len = RSTRING_LENINT(str);\
00135 int newlen = rb_long2int((p) - (unsigned char*)RSTRING_PTR(str));\
00136 assert(newlen <= len);\
00137 rb_str_set_len((str), newlen);\
00138 }while(0)
00139
00140
00141
00142
00143 int ossl_pem_passwd_cb(char *, int, int, void *);
00144
00145
00146
00147
00148
00149 #define OSSL_BIO_reset(bio) (void)BIO_reset((bio)); \
00150 ERR_clear_error();
00151
00152
00153
00154
00155 #define OSSL_ErrMsg() ERR_reason_error_string(ERR_get_error())
00156 NORETURN(void ossl_raise(VALUE, const char *, ...));
00157 VALUE ossl_exc_new(VALUE, const char *, ...);
00158
00159
00160
00161
00162 extern int ossl_verify_cb_idx;
00163
00164 struct ossl_verify_cb_args {
00165 VALUE proc;
00166 VALUE preverify_ok;
00167 VALUE store_ctx;
00168 };
00169
00170 VALUE ossl_call_verify_cb_proc(struct ossl_verify_cb_args *);
00171 int ossl_verify_cb(int, X509_STORE_CTX *);
00172
00173
00174
00175
00176 extern ID ossl_s_to_der;
00177 VALUE ossl_to_der(VALUE);
00178 VALUE ossl_to_der_if_possible(VALUE);
00179
00180
00181
00182
00183 extern VALUE dOSSL;
00184
00185 #if defined(HAVE_VA_ARGS_MACRO)
00186 #define OSSL_Debug(...) do { \
00187 if (dOSSL == Qtrue) { \
00188 fprintf(stderr, "OSSL_DEBUG: "); \
00189 fprintf(stderr, __VA_ARGS__); \
00190 fprintf(stderr, " [%s:%d]\n", __FILE__, __LINE__); \
00191 } \
00192 } while (0)
00193
00194 #define OSSL_Warning(fmt, ...) do { \
00195 OSSL_Debug((fmt), ##__VA_ARGS__); \
00196 rb_warning((fmt), ##__VA_ARGS__); \
00197 } while (0)
00198
00199 #define OSSL_Warn(fmt, ...) do { \
00200 OSSL_Debug((fmt), ##__VA_ARGS__); \
00201 rb_warn((fmt), ##__VA_ARGS__); \
00202 } while (0)
00203 #else
00204 void ossl_debug(const char *, ...);
00205 #define OSSL_Debug ossl_debug
00206 #define OSSL_Warning rb_warning
00207 #define OSSL_Warn rb_warn
00208 #endif
00209
00210
00211
00212
00213 #include "openssl_missing.h"
00214 #include "ruby_missing.h"
00215 #include "ossl_asn1.h"
00216 #include "ossl_bio.h"
00217 #include "ossl_bn.h"
00218 #include "ossl_cipher.h"
00219 #include "ossl_config.h"
00220 #include "ossl_digest.h"
00221 #include "ossl_hmac.h"
00222 #include "ossl_ns_spki.h"
00223 #include "ossl_ocsp.h"
00224 #include "ossl_pkcs12.h"
00225 #include "ossl_pkcs7.h"
00226 #include "ossl_pkcs5.h"
00227 #include "ossl_pkey.h"
00228 #include "ossl_rand.h"
00229 #include "ossl_ssl.h"
00230 #include "ossl_version.h"
00231 #include "ossl_x509.h"
00232 #include "ossl_engine.h"
00233
00234 void Init_openssl(void);
00235
00236 #if defined(__cplusplus)
00237 }
00238 #endif
00239
00240 #endif
00241
00242