2 * $Id: ossl.h 11708 2007-02-12 23:01:19Z shyouhei $
3 * 'OpenSSL for Ruby' project
4 * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
8 * This program is licenced under the same licence as Ruby.
9 * (See the file 'LICENCE'.)
11 #if !defined(_OSSL_H_)
14 #include RUBY_EXTCONF_H
16 #if defined(__cplusplus)
21 * OpenSSL has defined RFILE and Ruby has defined RFILE - so undef it!
23 #if defined(RFILE) /*&& !defined(OSSL_DEBUG)*/
30 * Check the OpenSSL version
31 * The only supported are:
34 #include <openssl/opensslv.h>
39 # define assert(condition)
43 # define OpenFile WINAPI_OpenFile
44 # define OSSL_NO_CONF_API 1
47 #include <openssl/err.h>
48 #include <openssl/asn1_mac.h>
49 #include <openssl/x509v3.h>
50 #include <openssl/ssl.h>
51 #include <openssl/pkcs12.h>
52 #include <openssl/pkcs7.h>
53 #include <openssl/hmac.h>
54 #include <openssl/rand.h>
55 #include <openssl/conf.h>
56 #include <openssl/conf_api.h>
58 #undef PKCS7_SIGNER_INFO
59 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ST_ENGINE)
60 # define OSSL_ENGINE_ENABLED
61 # include <openssl/engine.h>
63 #if defined(HAVE_OPENSSL_OCSP_H)
64 # define OSSL_OCSP_ENABLED
65 # include <openssl/ocsp.h>
79 extern VALUE eOSSLError
;
84 #define OSSL_Check_Kind(obj, klass) do {\
85 if (!rb_obj_is_kind_of(obj, klass)) {\
86 ossl_raise(rb_eTypeError, "wrong argument (%s)! (Expected kind of %s)",\
87 rb_obj_classname(obj), rb_class2name(klass));\
91 #define OSSL_Check_Instance(obj, klass) do {\
92 if (!rb_obj_is_instance_of(obj, klass)) {\
93 ossl_raise(rb_eTypeError, "wrong argument (%s)! (Expected instance of %s)",\
94 rb_obj_classname(obj), rb_class2name(klass));\
98 #define OSSL_Check_Same_Class(obj1, obj2) do {\
99 if (!rb_obj_is_instance_of(obj1, rb_obj_class(obj2))) {\
100 ossl_raise(rb_eTypeError, "wrong argument type");\
105 * String to HEXString conversion
107 int string2hex(char *, int, char **, int *);
112 STACK_OF(X509
) *ossl_x509_ary2sk0(VALUE
);
113 STACK_OF(X509
) *ossl_x509_ary2sk(VALUE
);
114 STACK_OF(X509
) *ossl_protect_x509_ary2sk(VALUE
,int*);
115 VALUE
ossl_x509_sk2ary(STACK_OF(X509
) *certs
);
116 VALUE
ossl_x509crl_sk2ary(STACK_OF(X509_CRL
) *crl
);
117 VALUE
ossl_buf2str(char *buf
, int len
);
118 #define ossl_str_adjust(str, p) \
120 int len = RSTRING(str)->len;\
121 int newlen = (p) - (unsigned char*)RSTRING(str)->ptr;\
122 assert(newlen <= len);\
123 RSTRING(str)->len = newlen;\
124 RSTRING(str)->ptr[newlen] = 0;\
128 * our default PEM callback
130 int ossl_pem_passwd_cb(char *, int, int, void *);
135 #define OSSL_ErrMsg() ERR_reason_error_string(ERR_get_error())
136 NORETURN(void ossl_raise(VALUE
, const char *, ...));
141 extern int ossl_verify_cb_idx
;
143 struct ossl_verify_cb_args
{
149 VALUE
ossl_call_verify_cb_proc(struct ossl_verify_cb_args
*);
150 int ossl_verify_cb(int, X509_STORE_CTX
*);
153 * String to DER String
155 extern ID ossl_s_to_der
;
156 VALUE
ossl_to_der(VALUE
);
157 VALUE
ossl_to_der_if_possible(VALUE
);
164 #if defined(HAVE_VA_ARGS_MACRO)
165 #define OSSL_Debug(fmt, ...) do { \
166 if (dOSSL == Qtrue) { \
167 fprintf(stderr, "OSSL_DEBUG: "); \
168 fprintf(stderr, fmt, ##__VA_ARGS__); \
169 fprintf(stderr, " [%s:%d]\n", __FILE__, __LINE__); \
173 #define OSSL_Warning(fmt, ...) do { \
174 OSSL_Debug(fmt, ##__VA_ARGS__); \
175 rb_warning(fmt, ##__VA_ARGS__); \
178 #define OSSL_Warn(fmt, ...) do { \
179 OSSL_Debug(fmt, ##__VA_ARGS__); \
180 rb_warn(fmt, ##__VA_ARGS__); \
183 void ossl_debug(const char *, ...);
184 #define OSSL_Debug ossl_debug
185 #define OSSL_Warning rb_warning
186 #define OSSL_Warn rb_warn
192 #include "openssl_missing.h"
193 #include "ruby_missing.h"
194 #include "ossl_asn1.h"
195 #include "ossl_bio.h"
197 #include "ossl_cipher.h"
198 #include "ossl_config.h"
199 #include "ossl_digest.h"
200 #include "ossl_hmac.h"
201 #include "ossl_ns_spki.h"
202 #include "ossl_ocsp.h"
203 #include "ossl_pkcs12.h"
204 #include "ossl_pkcs7.h"
205 #include "ossl_pkey.h"
206 #include "ossl_rand.h"
207 #include "ossl_ssl.h"
208 #include "ossl_version.h"
209 #include "ossl_x509.h"
210 #include "ossl_engine.h"
212 void Init_openssl(void);
214 #if defined(__cplusplus)
218 #endif /* _OSSL_H_ */