• Main Page
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

ext/openssl/ossl.h

Go to the documentation of this file.
00001 /*
00002  * $Id: ossl.h 26781 2010-02-28 02:56:26Z naruse $
00003  * 'OpenSSL for Ruby' project
00004  * Copyright (C) 2001-2002  Michal Rokos <m.rokos@sh.cvut.cz>
00005  * All rights reserved.
00006  */
00007 /*
00008  * This program is licenced under the same licence as Ruby.
00009  * (See the file 'LICENCE'.)
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 * OpenSSL has defined RFILE and Ruby has defined RFILE - so undef it!
00027 */
00028 #if defined(RFILE) /*&& !defined(OSSL_DEBUG)*/
00029 #  undef RFILE
00030 #endif
00031 #include <ruby.h>
00032 #include <ruby/io.h>
00033 
00034 /*
00035  * Check the OpenSSL version
00036  * The only supported are:
00037  *      OpenSSL >= 0.9.7
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 #  include <winsock2.h>
00050 #endif
00051 #include <errno.h>
00052 #include <openssl/err.h>
00053 #include <openssl/asn1_mac.h>
00054 #include <openssl/x509v3.h>
00055 #include <openssl/ssl.h>
00056 #include <openssl/pkcs12.h>
00057 #include <openssl/pkcs7.h>
00058 #include <openssl/hmac.h>
00059 #include <openssl/rand.h>
00060 #include <openssl/conf.h>
00061 #include <openssl/conf_api.h>
00062 #undef X509_NAME
00063 #undef PKCS7_SIGNER_INFO
00064 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ST_ENGINE)
00065 #  define OSSL_ENGINE_ENABLED
00066 #  include <openssl/engine.h>
00067 #endif
00068 #if defined(HAVE_OPENSSL_OCSP_H)
00069 #  define OSSL_OCSP_ENABLED
00070 #  include <openssl/ocsp.h>
00071 #endif
00072 
00073 /*
00074  * Common Module
00075  */
00076 extern VALUE mOSSL;
00077 
00078 /*
00079  * Common Error Class
00080  */
00081 extern VALUE eOSSLError;
00082 
00083 /*
00084  * CheckTypes
00085  */
00086 #define OSSL_Check_Kind(obj, klass) do {\
00087   if (!rb_obj_is_kind_of(obj, klass)) {\
00088     ossl_raise(rb_eTypeError, "wrong argument (%s)! (Expected kind of %s)",\
00089                rb_obj_classname(obj), rb_class2name(klass));\
00090   }\
00091 } while (0)
00092 
00093 #define OSSL_Check_Instance(obj, klass) do {\
00094   if (!rb_obj_is_instance_of(obj, klass)) {\
00095     ossl_raise(rb_eTypeError, "wrong argument (%s)! (Expected instance of %s)",\
00096                rb_obj_classname(obj), rb_class2name(klass));\
00097   }\
00098 } while (0)
00099 
00100 #define OSSL_Check_Same_Class(obj1, obj2) do {\
00101   if (!rb_obj_is_instance_of(obj1, rb_obj_class(obj2))) {\
00102     ossl_raise(rb_eTypeError, "wrong argument type");\
00103   }\
00104 } while (0)
00105 
00106 /*
00107  * Compatibility
00108  */
00109 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
00110 #define STACK _STACK
00111 #endif
00112 
00113 /*
00114  * String to HEXString conversion
00115  */
00116 int string2hex(const unsigned char *, int, char **, int *);
00117 
00118 /*
00119  * Data Conversion
00120  */
00121 STACK_OF(X509) *ossl_x509_ary2sk0(VALUE);
00122 STACK_OF(X509) *ossl_x509_ary2sk(VALUE);
00123 STACK_OF(X509) *ossl_protect_x509_ary2sk(VALUE,int*);
00124 VALUE ossl_x509_sk2ary(STACK_OF(X509) *certs);
00125 VALUE ossl_x509crl_sk2ary(STACK_OF(X509_CRL) *crl);
00126 VALUE ossl_buf2str(char *buf, int len);
00127 #define ossl_str_adjust(str, p) \
00128 do{\
00129     int len = RSTRING_LEN(str);\
00130     int newlen = (p) - (unsigned char*)RSTRING_PTR(str);\
00131     assert(newlen <= len);\
00132     rb_str_set_len(str, newlen);\
00133 }while(0)
00134 
00135 /*
00136  * our default PEM callback
00137  */
00138 int ossl_pem_passwd_cb(char *, int, int, void *);
00139 
00140 /*
00141  * ERRor messages
00142  */
00143 #define OSSL_ErrMsg() ERR_reason_error_string(ERR_get_error())
00144 NORETURN(void ossl_raise(VALUE, const char *, ...));
00145 VALUE ossl_exc_new(VALUE, const char *, ...);
00146 
00147 /*
00148  * Verify callback
00149  */
00150 extern int ossl_verify_cb_idx;
00151 
00152 struct ossl_verify_cb_args {
00153     VALUE proc;
00154     VALUE preverify_ok;
00155     VALUE store_ctx;
00156 };
00157 
00158 VALUE ossl_call_verify_cb_proc(struct ossl_verify_cb_args *);
00159 int ossl_verify_cb(int, X509_STORE_CTX *);
00160 
00161 /*
00162  * String to DER String
00163  */
00164 extern ID ossl_s_to_der;
00165 VALUE ossl_to_der(VALUE);
00166 VALUE ossl_to_der_if_possible(VALUE);
00167 
00168 /*
00169  * Debug
00170  */
00171 extern VALUE dOSSL;
00172 
00173 #if defined(HAVE_VA_ARGS_MACRO)
00174 #define OSSL_Debug(...) do { \
00175   if (dOSSL == Qtrue) { \
00176     fprintf(stderr, "OSSL_DEBUG: "); \
00177     fprintf(stderr, __VA_ARGS__); \
00178     fprintf(stderr, " [%s:%d]\n", __FILE__, __LINE__); \
00179   } \
00180 } while (0)
00181 
00182 #define OSSL_Warning(fmt, ...) do { \
00183   OSSL_Debug(fmt, ##__VA_ARGS__); \
00184   rb_warning(fmt, ##__VA_ARGS__); \
00185 } while (0)
00186 
00187 #define OSSL_Warn(fmt, ...) do { \
00188   OSSL_Debug(fmt, ##__VA_ARGS__); \
00189   rb_warn(fmt, ##__VA_ARGS__); \
00190 } while (0)
00191 #else
00192 void ossl_debug(const char *, ...);
00193 #define OSSL_Debug ossl_debug
00194 #define OSSL_Warning rb_warning
00195 #define OSSL_Warn rb_warn
00196 #endif
00197 
00198 /*
00199  * Include all parts
00200  */
00201 #include "openssl_missing.h"
00202 #include "ruby_missing.h"
00203 #include "ossl_asn1.h"
00204 #include "ossl_bio.h"
00205 #include "ossl_bn.h"
00206 #include "ossl_cipher.h"
00207 #include "ossl_config.h"
00208 #include "ossl_digest.h"
00209 #include "ossl_hmac.h"
00210 #include "ossl_ns_spki.h"
00211 #include "ossl_ocsp.h"
00212 #include "ossl_pkcs12.h"
00213 #include "ossl_pkcs7.h"
00214 #include "ossl_pkcs5.h"
00215 #include "ossl_pkey.h"
00216 #include "ossl_rand.h"
00217 #include "ossl_ssl.h"
00218 #include "ossl_version.h"
00219 #include "ossl_x509.h"
00220 #include "ossl_engine.h"
00221 
00222 void Init_openssl(void);
00223 
00224 #if defined(__cplusplus)
00225 }
00226 #endif
00227 
00228 #endif /* _OSSL_H_ */
00229 
00230 

Generated on Wed Sep 8 2010 09:55:11 for Ruby by  doxygen 1.7.1