rubysl-openssl 0.0.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/ext/rubysl/openssl/extconf.h +50 -0
- data/ext/rubysl/openssl/extconf.rb +144 -0
- data/ext/rubysl/openssl/openssl_missing.c +343 -0
- data/ext/rubysl/openssl/openssl_missing.h +191 -0
- data/ext/rubysl/openssl/ossl.c +552 -0
- data/ext/rubysl/openssl/ossl.h +233 -0
- data/ext/rubysl/openssl/ossl_asn1.c +1160 -0
- data/ext/rubysl/openssl/ossl_asn1.h +59 -0
- data/ext/rubysl/openssl/ossl_bio.c +86 -0
- data/ext/rubysl/openssl/ossl_bio.h +21 -0
- data/ext/rubysl/openssl/ossl_bn.c +852 -0
- data/ext/rubysl/openssl/ossl_bn.h +25 -0
- data/ext/rubysl/openssl/ossl_cipher.c +569 -0
- data/ext/rubysl/openssl/ossl_cipher.h +22 -0
- data/ext/rubysl/openssl/ossl_config.c +75 -0
- data/ext/rubysl/openssl/ossl_config.h +22 -0
- data/ext/rubysl/openssl/ossl_digest.c +259 -0
- data/ext/rubysl/openssl/ossl_digest.h +22 -0
- data/ext/rubysl/openssl/ossl_engine.c +411 -0
- data/ext/rubysl/openssl/ossl_engine.h +20 -0
- data/ext/rubysl/openssl/ossl_hmac.c +268 -0
- data/ext/rubysl/openssl/ossl_hmac.h +19 -0
- data/ext/rubysl/openssl/ossl_ns_spki.c +257 -0
- data/ext/rubysl/openssl/ossl_ns_spki.h +21 -0
- data/ext/rubysl/openssl/ossl_ocsp.c +769 -0
- data/ext/rubysl/openssl/ossl_ocsp.h +24 -0
- data/ext/rubysl/openssl/ossl_pkcs12.c +210 -0
- data/ext/rubysl/openssl/ossl_pkcs12.h +15 -0
- data/ext/rubysl/openssl/ossl_pkcs5.c +99 -0
- data/ext/rubysl/openssl/ossl_pkcs5.h +6 -0
- data/ext/rubysl/openssl/ossl_pkcs7.c +1039 -0
- data/ext/rubysl/openssl/ossl_pkcs7.h +22 -0
- data/ext/rubysl/openssl/ossl_pkey.c +240 -0
- data/ext/rubysl/openssl/ossl_pkey.h +141 -0
- data/ext/rubysl/openssl/ossl_pkey_dh.c +532 -0
- data/ext/rubysl/openssl/ossl_pkey_dsa.c +484 -0
- data/ext/rubysl/openssl/ossl_pkey_ec.c +1593 -0
- data/ext/rubysl/openssl/ossl_pkey_rsa.c +593 -0
- data/ext/rubysl/openssl/ossl_rand.c +202 -0
- data/ext/rubysl/openssl/ossl_rand.h +20 -0
- data/ext/rubysl/openssl/ossl_ssl.c +1484 -0
- data/ext/rubysl/openssl/ossl_ssl.h +36 -0
- data/ext/rubysl/openssl/ossl_ssl_session.c +307 -0
- data/ext/rubysl/openssl/ossl_version.h +16 -0
- data/ext/rubysl/openssl/ossl_x509.c +104 -0
- data/ext/rubysl/openssl/ossl_x509.h +114 -0
- data/ext/rubysl/openssl/ossl_x509attr.c +274 -0
- data/ext/rubysl/openssl/ossl_x509cert.c +764 -0
- data/ext/rubysl/openssl/ossl_x509crl.c +535 -0
- data/ext/rubysl/openssl/ossl_x509ext.c +458 -0
- data/ext/rubysl/openssl/ossl_x509name.c +399 -0
- data/ext/rubysl/openssl/ossl_x509req.c +466 -0
- data/ext/rubysl/openssl/ossl_x509revoked.c +229 -0
- data/ext/rubysl/openssl/ossl_x509store.c +625 -0
- data/ext/rubysl/openssl/ruby_missing.h +41 -0
- data/lib/openssl.rb +1 -0
- data/lib/openssl/bn.rb +35 -0
- data/lib/openssl/buffering.rb +241 -0
- data/lib/openssl/cipher.rb +65 -0
- data/lib/openssl/config.rb +316 -0
- data/lib/openssl/digest.rb +61 -0
- data/lib/openssl/net/ftptls.rb +53 -0
- data/lib/openssl/net/telnets.rb +251 -0
- data/lib/openssl/pkcs7.rb +25 -0
- data/lib/openssl/ssl-internal.rb +187 -0
- data/lib/openssl/ssl.rb +1 -0
- data/lib/openssl/x509-internal.rb +153 -0
- data/lib/openssl/x509.rb +1 -0
- data/lib/rubysl/openssl.rb +28 -0
- data/lib/rubysl/openssl/version.rb +5 -0
- data/rubysl-openssl.gemspec +19 -18
- data/spec/cipher_spec.rb +16 -0
- data/spec/config/freeze_spec.rb +17 -0
- data/spec/hmac/digest_spec.rb +15 -0
- data/spec/hmac/hexdigest_spec.rb +15 -0
- data/spec/random/pseudo_bytes_spec.rb +5 -0
- data/spec/random/random_bytes_spec.rb +5 -0
- data/spec/random/shared/random_bytes.rb +28 -0
- data/spec/shared/constants.rb +11 -0
- data/spec/x509/name/parse_spec.rb +47 -0
- metadata +153 -89
- data/lib/rubysl-openssl.rb +0 -7
- data/lib/rubysl-openssl/version.rb +0 -5
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 76f5a7a94f60ad0a165b1917125508ceb550786b
|
|
4
|
+
data.tar.gz: 5bbe823de538860a62ad2194bee659aa1ea1d351
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a9a604acb9afc7a04cd9c95553357d056d3b7ffb42b8cfa34f1423de7e3e30d98ba47341de7301f4da1a293215ac7082232249da067fa4e3ed9c7a798ea55e60
|
|
7
|
+
data.tar.gz: ff37c957590fee69b1587d7dbd529d27a695db35ab6ac852d40bb918dede59e4b1b20527b057e955b8bf99aaf23235eb6589c2c5dfcbe19df768bf9ba354486c
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Rubysl::Openssl
|
|
2
2
|
|
|
3
3
|
TODO: Write a gem description
|
|
4
4
|
|
|
@@ -24,6 +24,6 @@ TODO: Write usage instructions here
|
|
|
24
24
|
|
|
25
25
|
1. Fork it
|
|
26
26
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
-
3. Commit your changes (`git commit -am '
|
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
28
28
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
29
|
5. Create new Pull Request
|
data/Rakefile
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#ifndef EXTCONF_H
|
|
2
|
+
#define EXTCONF_H
|
|
3
|
+
#define HAVE_ASSERT_H 1
|
|
4
|
+
#define HAVE_OPENSSL_SSL_H 1
|
|
5
|
+
#define HAVE_OPENSSL_CONF_API_H 1
|
|
6
|
+
#define HAVE_ERR_PEEK_LAST_ERROR 1
|
|
7
|
+
#define HAVE_BN_MOD_ADD 1
|
|
8
|
+
#define HAVE_BN_MOD_SQR 1
|
|
9
|
+
#define HAVE_BN_MOD_SUB 1
|
|
10
|
+
#define HAVE_BN_PSEUDO_RAND_RANGE 1
|
|
11
|
+
#define HAVE_BN_RAND_RANGE 1
|
|
12
|
+
#define HAVE_CONF_GET1_DEFAULT_CONFIG_FILE 1
|
|
13
|
+
#define HAVE_EVP_CIPHER_CTX_SET_PADDING 1
|
|
14
|
+
#define HAVE_EVP_CIPHERFINAL_EX 1
|
|
15
|
+
#define HAVE_EVP_CIPHERINIT_EX 1
|
|
16
|
+
#define HAVE_EVP_DIGESTFINAL_EX 1
|
|
17
|
+
#define HAVE_EVP_DIGESTINIT_EX 1
|
|
18
|
+
#define HAVE_EVP_MD_CTX_CLEANUP 1
|
|
19
|
+
#define HAVE_EVP_MD_CTX_CREATE 1
|
|
20
|
+
#define HAVE_EVP_MD_CTX_DESTROY 1
|
|
21
|
+
#define HAVE_EVP_MD_CTX_INIT 1
|
|
22
|
+
#define HAVE_HMAC_CTX_CLEANUP 1
|
|
23
|
+
#define HAVE_HMAC_CTX_INIT 1
|
|
24
|
+
#define HAVE_PEM_DEF_CALLBACK 1
|
|
25
|
+
#define HAVE_PKCS5_PBKDF2_HMAC_SHA1 1
|
|
26
|
+
#define HAVE_X509V3_SET_NCONF 1
|
|
27
|
+
#define HAVE_X509V3_EXT_NCONF_NID 1
|
|
28
|
+
#define HAVE_X509_CRL_ADD0_REVOKED 1
|
|
29
|
+
#define HAVE_X509_CRL_SET_ISSUER_NAME 1
|
|
30
|
+
#define HAVE_X509_CRL_SET_VERSION 1
|
|
31
|
+
#define HAVE_X509_CRL_SORT 1
|
|
32
|
+
#define HAVE_OBJ_NAME_DO_ALL_SORTED 1
|
|
33
|
+
#define HAVE_SSL_SESSION_GET_ID 1
|
|
34
|
+
#define HAVE_OPENSSL_CLEANSE 1
|
|
35
|
+
#define HAVE_VA_ARGS_MACRO 1
|
|
36
|
+
#define HAVE_SSLV2_METHOD 1
|
|
37
|
+
#define HAVE_SSLV2_SERVER_METHOD 1
|
|
38
|
+
#define HAVE_SSLV2_CLIENT_METHOD 1
|
|
39
|
+
#define HAVE_SSL_SET_TLSEXT_HOST_NAME 1
|
|
40
|
+
#define HAVE_OPENSSL_ENGINE_H 1
|
|
41
|
+
#define HAVE_ENGINE_ADD 1
|
|
42
|
+
#define HAVE_ENGINE_LOAD_BUILTIN_ENGINES 1
|
|
43
|
+
#define HAVE_ENGINE_GET_DIGEST 1
|
|
44
|
+
#define HAVE_ENGINE_GET_CIPHER 1
|
|
45
|
+
#define HAVE_ENGINE_CLEANUP 1
|
|
46
|
+
#define HAVE_OPENSSL_OCSP_H 1
|
|
47
|
+
#define HAVE_ST_FLAGS 1
|
|
48
|
+
#define HAVE_ST_ENGINE 1
|
|
49
|
+
#define HAVE_ST_SINGLE 1
|
|
50
|
+
#endif
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
= $RCSfile$ -- Generator for Makefile
|
|
3
|
+
|
|
4
|
+
= Info
|
|
5
|
+
'OpenSSL for Ruby 2' project
|
|
6
|
+
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
7
|
+
All rights reserved.
|
|
8
|
+
|
|
9
|
+
= Licence
|
|
10
|
+
This program is licenced under the same licence as Ruby.
|
|
11
|
+
(See the file 'LICENCE'.)
|
|
12
|
+
|
|
13
|
+
= Version
|
|
14
|
+
$Id: extconf.rb 32234 2011-06-26 08:58:06Z shyouhei $
|
|
15
|
+
=end
|
|
16
|
+
|
|
17
|
+
require "mkmf"
|
|
18
|
+
|
|
19
|
+
dir_config("openssl")
|
|
20
|
+
dir_config("kerberos")
|
|
21
|
+
|
|
22
|
+
message "=== OpenSSL for Ruby configurator ===\n"
|
|
23
|
+
|
|
24
|
+
##
|
|
25
|
+
# Adds -Wall -DOSSL_DEBUG for compilation and some more targets when GCC is used
|
|
26
|
+
# To turn it on, use: --with-debug or --enable-debug
|
|
27
|
+
#
|
|
28
|
+
if with_config("debug") or enable_config("debug")
|
|
29
|
+
$defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
|
|
30
|
+
|
|
31
|
+
if /gcc/ =~ CONFIG["CC"]
|
|
32
|
+
$CPPFLAGS += " -Wall" unless $CPPFLAGS.split.include? "-Wall"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Nothing we can do about these problems.
|
|
37
|
+
$CPPFLAGS += " -Wno-deprecated-declarations -Wno-pointer-sign"
|
|
38
|
+
|
|
39
|
+
message "=== Checking for system dependent stuff... ===\n"
|
|
40
|
+
have_library("nsl", "t_open")
|
|
41
|
+
have_library("socket", "socket")
|
|
42
|
+
have_header("assert.h")
|
|
43
|
+
|
|
44
|
+
message "=== Checking for required stuff... ===\n"
|
|
45
|
+
if $mingw
|
|
46
|
+
have_library("wsock32")
|
|
47
|
+
have_library("gdi32")
|
|
48
|
+
end
|
|
49
|
+
result = have_header("openssl/ssl.h")
|
|
50
|
+
result &&= %w[crypto libeay32].any? {|lib| have_library(lib, "OpenSSL_add_all_digests")}
|
|
51
|
+
result &&= %w[ssl ssleay32].any? {|lib| have_library(lib, "SSL_library_init")}
|
|
52
|
+
if !result
|
|
53
|
+
unless pkg_config("openssl") and have_header("openssl/ssl.h")
|
|
54
|
+
message "=== Checking for required stuff failed. ===\n"
|
|
55
|
+
message "Makefile wasn't created. Fix the errors above.\n"
|
|
56
|
+
exit 1
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
unless have_header("openssl/conf_api.h")
|
|
61
|
+
message "OpenSSL 0.9.6 or later required.\n"
|
|
62
|
+
exit 1
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
%w"rb_str_set_len rb_block_call".each {|func| have_func(func, "ruby.h")}
|
|
66
|
+
|
|
67
|
+
message "=== Checking for OpenSSL features... ===\n"
|
|
68
|
+
have_func("ERR_peek_last_error")
|
|
69
|
+
have_func("BN_mod_add")
|
|
70
|
+
have_func("BN_mod_sqr")
|
|
71
|
+
have_func("BN_mod_sub")
|
|
72
|
+
have_func("BN_pseudo_rand_range")
|
|
73
|
+
have_func("BN_rand_range")
|
|
74
|
+
have_func("CONF_get1_default_config_file")
|
|
75
|
+
have_func("EVP_CIPHER_CTX_copy")
|
|
76
|
+
have_func("EVP_CIPHER_CTX_set_padding")
|
|
77
|
+
have_func("EVP_CipherFinal_ex")
|
|
78
|
+
have_func("EVP_CipherInit_ex")
|
|
79
|
+
have_func("EVP_DigestFinal_ex")
|
|
80
|
+
have_func("EVP_DigestInit_ex")
|
|
81
|
+
have_func("EVP_MD_CTX_cleanup")
|
|
82
|
+
have_func("EVP_MD_CTX_create")
|
|
83
|
+
have_func("EVP_MD_CTX_destroy")
|
|
84
|
+
have_func("EVP_MD_CTX_init")
|
|
85
|
+
have_func("HMAC_CTX_cleanup")
|
|
86
|
+
have_func("HMAC_CTX_copy")
|
|
87
|
+
have_func("HMAC_CTX_init")
|
|
88
|
+
have_func("PEM_def_callback")
|
|
89
|
+
have_func("PKCS5_PBKDF2_HMAC")
|
|
90
|
+
have_func("PKCS5_PBKDF2_HMAC_SHA1")
|
|
91
|
+
have_func("X509V3_set_nconf")
|
|
92
|
+
have_func("X509V3_EXT_nconf_nid")
|
|
93
|
+
have_func("X509_CRL_add0_revoked")
|
|
94
|
+
have_func("X509_CRL_set_issuer_name")
|
|
95
|
+
have_func("X509_CRL_set_version")
|
|
96
|
+
have_func("X509_CRL_sort")
|
|
97
|
+
have_func("X509_NAME_hash_old")
|
|
98
|
+
have_func("X509_STORE_get_ex_data")
|
|
99
|
+
have_func("X509_STORE_set_ex_data")
|
|
100
|
+
have_func("OBJ_NAME_do_all_sorted")
|
|
101
|
+
have_func("SSL_SESSION_get_id")
|
|
102
|
+
have_func("OPENSSL_cleanse")
|
|
103
|
+
if try_compile("#define FOO(...) foo(__VA_ARGS__)\n int x(){FOO(1);FOO(1,2);FOO(1,2,3);}\n")
|
|
104
|
+
$defs.push("-DHAVE_VA_ARGS_MACRO")
|
|
105
|
+
end
|
|
106
|
+
have_func("SSLv2_method")
|
|
107
|
+
have_func("SSLv2_server_method")
|
|
108
|
+
have_func("SSLv2_client_method")
|
|
109
|
+
unless have_func("SSL_set_tlsext_host_name", ['openssl/ssl.h'])
|
|
110
|
+
have_macro("SSL_set_tlsext_host_name", ['openssl/ssl.h']) && $defs.push("-DHAVE_SSL_SET_TLSEXT_HOST_NAME")
|
|
111
|
+
end
|
|
112
|
+
if have_header("openssl/engine.h")
|
|
113
|
+
have_func("ENGINE_add")
|
|
114
|
+
have_func("ENGINE_load_builtin_engines")
|
|
115
|
+
have_func("ENGINE_load_openbsd_dev_crypto")
|
|
116
|
+
have_func("ENGINE_get_digest")
|
|
117
|
+
have_func("ENGINE_get_cipher")
|
|
118
|
+
have_func("ENGINE_cleanup")
|
|
119
|
+
have_func("ENGINE_load_4758cca")
|
|
120
|
+
have_func("ENGINE_load_aep")
|
|
121
|
+
have_func("ENGINE_load_atalla")
|
|
122
|
+
have_func("ENGINE_load_chil")
|
|
123
|
+
have_func("ENGINE_load_cswift")
|
|
124
|
+
have_func("ENGINE_load_nuron")
|
|
125
|
+
have_func("ENGINE_load_sureware")
|
|
126
|
+
have_func("ENGINE_load_ubsec")
|
|
127
|
+
end
|
|
128
|
+
if try_compile(<<SRC)
|
|
129
|
+
#include <openssl/opensslv.h>
|
|
130
|
+
#if OPENSSL_VERSION_NUMBER < 0x00907000L
|
|
131
|
+
# error "OpenSSL version is less than 0.9.7."
|
|
132
|
+
#endif
|
|
133
|
+
SRC
|
|
134
|
+
have_header("openssl/ocsp.h")
|
|
135
|
+
end
|
|
136
|
+
have_struct_member("EVP_CIPHER_CTX", "flags", "openssl/evp.h")
|
|
137
|
+
have_struct_member("EVP_CIPHER_CTX", "engine", "openssl/evp.h")
|
|
138
|
+
have_struct_member("X509_ATTRIBUTE", "single", "openssl/x509.h")
|
|
139
|
+
|
|
140
|
+
message "=== Checking done. ===\n"
|
|
141
|
+
|
|
142
|
+
create_header
|
|
143
|
+
create_makefile("openssl/openssl")
|
|
144
|
+
message "Done.\n"
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* $Id: openssl_missing.c 16467 2008-05-19 03:00:52Z knu $
|
|
3
|
+
* 'OpenSSL for Ruby' project
|
|
4
|
+
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
5
|
+
* All rights reserved.
|
|
6
|
+
*/
|
|
7
|
+
/*
|
|
8
|
+
* This program is licenced under the same licence as Ruby.
|
|
9
|
+
* (See the file 'LICENCE'.)
|
|
10
|
+
*/
|
|
11
|
+
#include RUBY_EXTCONF_H
|
|
12
|
+
|
|
13
|
+
#if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ST_ENGINE)
|
|
14
|
+
# include <openssl/engine.h>
|
|
15
|
+
#endif
|
|
16
|
+
#include <openssl/x509_vfy.h>
|
|
17
|
+
|
|
18
|
+
#if !defined(OPENSSL_NO_HMAC)
|
|
19
|
+
#include <string.h> /* memcpy() */
|
|
20
|
+
#include <openssl/hmac.h>
|
|
21
|
+
|
|
22
|
+
#include "openssl_missing.h"
|
|
23
|
+
|
|
24
|
+
#if !defined(HAVE_HMAC_CTX_COPY)
|
|
25
|
+
void
|
|
26
|
+
HMAC_CTX_copy(HMAC_CTX *out, HMAC_CTX *in)
|
|
27
|
+
{
|
|
28
|
+
if (!out || !in) return;
|
|
29
|
+
memcpy(out, in, sizeof(HMAC_CTX));
|
|
30
|
+
|
|
31
|
+
EVP_MD_CTX_copy(&out->md_ctx, &in->md_ctx);
|
|
32
|
+
EVP_MD_CTX_copy(&out->i_ctx, &in->i_ctx);
|
|
33
|
+
EVP_MD_CTX_copy(&out->o_ctx, &in->o_ctx);
|
|
34
|
+
}
|
|
35
|
+
#endif /* HAVE_HMAC_CTX_COPY */
|
|
36
|
+
#endif /* NO_HMAC */
|
|
37
|
+
|
|
38
|
+
#if !defined(HAVE_X509_STORE_SET_EX_DATA)
|
|
39
|
+
|
|
40
|
+
int X509_STORE_set_ex_data(X509_STORE *str, int idx, void *data)
|
|
41
|
+
{
|
|
42
|
+
return CRYPTO_set_ex_data(&str->ex_data, idx, data);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void *X509_STORE_get_ex_data(X509_STORE *str, int idx)
|
|
46
|
+
{
|
|
47
|
+
return CRYPTO_get_ex_data(&str->ex_data, idx);
|
|
48
|
+
}
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
#if !defined(HAVE_EVP_MD_CTX_CREATE)
|
|
52
|
+
EVP_MD_CTX *
|
|
53
|
+
EVP_MD_CTX_create(void)
|
|
54
|
+
{
|
|
55
|
+
EVP_MD_CTX *ctx = OPENSSL_malloc(sizeof(EVP_MD_CTX));
|
|
56
|
+
if (!ctx) return NULL;
|
|
57
|
+
|
|
58
|
+
memset(ctx, 0, sizeof(EVP_MD_CTX));
|
|
59
|
+
|
|
60
|
+
return ctx;
|
|
61
|
+
}
|
|
62
|
+
#endif
|
|
63
|
+
|
|
64
|
+
#if !defined(HAVE_EVP_MD_CTX_CLEANUP)
|
|
65
|
+
int
|
|
66
|
+
EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
|
|
67
|
+
{
|
|
68
|
+
/* FIXME!!! */
|
|
69
|
+
memset(ctx, 0, sizeof(EVP_MD_CTX));
|
|
70
|
+
|
|
71
|
+
return 1;
|
|
72
|
+
}
|
|
73
|
+
#endif
|
|
74
|
+
|
|
75
|
+
#if !defined(HAVE_EVP_MD_CTX_DESTROY)
|
|
76
|
+
void
|
|
77
|
+
EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
|
|
78
|
+
{
|
|
79
|
+
EVP_MD_CTX_cleanup(ctx);
|
|
80
|
+
OPENSSL_free(ctx);
|
|
81
|
+
}
|
|
82
|
+
#endif
|
|
83
|
+
|
|
84
|
+
#if !defined(HAVE_EVP_MD_CTX_INIT)
|
|
85
|
+
void
|
|
86
|
+
EVP_MD_CTX_init(EVP_MD_CTX *ctx)
|
|
87
|
+
{
|
|
88
|
+
memset(ctx, 0, sizeof(EVP_MD_CTX));
|
|
89
|
+
}
|
|
90
|
+
#endif
|
|
91
|
+
|
|
92
|
+
#if !defined(HAVE_HMAC_CTX_INIT)
|
|
93
|
+
void
|
|
94
|
+
HMAC_CTX_init(HMAC_CTX *ctx)
|
|
95
|
+
{
|
|
96
|
+
EVP_MD_CTX_init(&ctx->i_ctx);
|
|
97
|
+
EVP_MD_CTX_init(&ctx->o_ctx);
|
|
98
|
+
EVP_MD_CTX_init(&ctx->md_ctx);
|
|
99
|
+
}
|
|
100
|
+
#endif
|
|
101
|
+
|
|
102
|
+
#if !defined(HAVE_HMAC_CTX_CLEANUP)
|
|
103
|
+
void
|
|
104
|
+
HMAC_CTX_cleanup(HMAC_CTX *ctx)
|
|
105
|
+
{
|
|
106
|
+
EVP_MD_CTX_cleanup(&ctx->i_ctx);
|
|
107
|
+
EVP_MD_CTX_cleanup(&ctx->o_ctx);
|
|
108
|
+
EVP_MD_CTX_cleanup(&ctx->md_ctx);
|
|
109
|
+
memset(ctx, 0, sizeof(HMAC_CTX));
|
|
110
|
+
}
|
|
111
|
+
#endif
|
|
112
|
+
|
|
113
|
+
#if !defined(HAVE_EVP_CIPHER_CTX_COPY)
|
|
114
|
+
/*
|
|
115
|
+
* this function does not exist in OpenSSL yet... or ever?.
|
|
116
|
+
* a future version may break this function.
|
|
117
|
+
* tested on 0.9.7d.
|
|
118
|
+
*/
|
|
119
|
+
int
|
|
120
|
+
EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, EVP_CIPHER_CTX *in)
|
|
121
|
+
{
|
|
122
|
+
memcpy(out, in, sizeof(EVP_CIPHER_CTX));
|
|
123
|
+
|
|
124
|
+
#if defined(HAVE_ENGINE_ADD) && defined(HAVE_ST_ENGINE)
|
|
125
|
+
if (in->engine) ENGINE_add(out->engine);
|
|
126
|
+
if (in->cipher_data) {
|
|
127
|
+
out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size);
|
|
128
|
+
memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);
|
|
129
|
+
}
|
|
130
|
+
#endif
|
|
131
|
+
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
#endif
|
|
135
|
+
|
|
136
|
+
#if !defined(HAVE_X509_CRL_SET_VERSION)
|
|
137
|
+
int
|
|
138
|
+
X509_CRL_set_version(X509_CRL *x, long version)
|
|
139
|
+
{
|
|
140
|
+
if (x == NULL || x->crl == NULL) return 0;
|
|
141
|
+
if (x->crl->version == NULL) {
|
|
142
|
+
x->crl->version = M_ASN1_INTEGER_new();
|
|
143
|
+
if (x->crl->version == NULL) return 0;
|
|
144
|
+
}
|
|
145
|
+
return ASN1_INTEGER_set(x->crl->version, version);
|
|
146
|
+
}
|
|
147
|
+
#endif
|
|
148
|
+
|
|
149
|
+
#if !defined(HAVE_X509_CRL_SET_ISSUER_NAME)
|
|
150
|
+
int
|
|
151
|
+
X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name)
|
|
152
|
+
{
|
|
153
|
+
if (x == NULL || x->crl == NULL) return 0;
|
|
154
|
+
return X509_NAME_set(&x->crl->issuer, name);
|
|
155
|
+
}
|
|
156
|
+
#endif
|
|
157
|
+
|
|
158
|
+
#if !defined(HAVE_X509_CRL_SORT)
|
|
159
|
+
int
|
|
160
|
+
X509_CRL_sort(X509_CRL *c)
|
|
161
|
+
{
|
|
162
|
+
int i;
|
|
163
|
+
X509_REVOKED *r;
|
|
164
|
+
/* sort the data so it will be written in serial
|
|
165
|
+
* number order */
|
|
166
|
+
sk_X509_REVOKED_sort(c->crl->revoked);
|
|
167
|
+
for (i=0; i<sk_X509_REVOKED_num(c->crl->revoked); i++) {
|
|
168
|
+
r=sk_X509_REVOKED_value(c->crl->revoked, i);
|
|
169
|
+
r->sequence=i;
|
|
170
|
+
}
|
|
171
|
+
return 1;
|
|
172
|
+
}
|
|
173
|
+
#endif
|
|
174
|
+
|
|
175
|
+
#if !defined(HAVE_X509_CRL_ADD0_REVOKED)
|
|
176
|
+
static int
|
|
177
|
+
OSSL_X509_REVOKED_cmp(const X509_REVOKED * const *a, const X509_REVOKED * const *b)
|
|
178
|
+
{
|
|
179
|
+
return(ASN1_STRING_cmp(
|
|
180
|
+
(ASN1_STRING *)(*a)->serialNumber,
|
|
181
|
+
(ASN1_STRING *)(*b)->serialNumber));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
int
|
|
185
|
+
X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
|
|
186
|
+
{
|
|
187
|
+
X509_CRL_INFO *inf;
|
|
188
|
+
|
|
189
|
+
inf = crl->crl;
|
|
190
|
+
if (!inf->revoked)
|
|
191
|
+
inf->revoked = sk_X509_REVOKED_new(OSSL_X509_REVOKED_cmp);
|
|
192
|
+
if (!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev))
|
|
193
|
+
return 0;
|
|
194
|
+
return 1;
|
|
195
|
+
}
|
|
196
|
+
#endif
|
|
197
|
+
|
|
198
|
+
#if !defined(HAVE_BN_MOD_SQR)
|
|
199
|
+
int
|
|
200
|
+
BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
|
|
201
|
+
{
|
|
202
|
+
if (!BN_sqr(r, (BIGNUM*)a, ctx)) return 0;
|
|
203
|
+
return BN_mod(r, r, m, ctx);
|
|
204
|
+
}
|
|
205
|
+
#endif
|
|
206
|
+
|
|
207
|
+
#if !defined(HAVE_BN_MOD_ADD) || !defined(HAVE_BN_MOD_SUB)
|
|
208
|
+
int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
|
|
209
|
+
{
|
|
210
|
+
if (!BN_mod(r,m,d,ctx)) return 0;
|
|
211
|
+
if (!r->neg) return 1;
|
|
212
|
+
return (d->neg ? BN_sub : BN_add)(r, r, d);
|
|
213
|
+
}
|
|
214
|
+
#endif
|
|
215
|
+
|
|
216
|
+
#if !defined(HAVE_BN_MOD_ADD)
|
|
217
|
+
int
|
|
218
|
+
BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
|
|
219
|
+
{
|
|
220
|
+
if (!BN_add(r, a, b)) return 0;
|
|
221
|
+
return BN_nnmod(r, r, m, ctx);
|
|
222
|
+
}
|
|
223
|
+
#endif
|
|
224
|
+
|
|
225
|
+
#if !defined(HAVE_BN_MOD_SUB)
|
|
226
|
+
int
|
|
227
|
+
BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
|
|
228
|
+
{
|
|
229
|
+
if (!BN_sub(r, a, b)) return 0;
|
|
230
|
+
return BN_nnmod(r, r, m, ctx);
|
|
231
|
+
}
|
|
232
|
+
#endif
|
|
233
|
+
|
|
234
|
+
#if !defined(HAVE_BN_RAND_RANGE) || !defined(HAVE_BN_PSEUDO_RAND_RANGE)
|
|
235
|
+
static int
|
|
236
|
+
bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
|
|
237
|
+
{
|
|
238
|
+
int (*bn_rand)(BIGNUM *, int, int, int) = pseudo ? BN_pseudo_rand : BN_rand;
|
|
239
|
+
int n;
|
|
240
|
+
|
|
241
|
+
if (range->neg || BN_is_zero(range)) return 0;
|
|
242
|
+
|
|
243
|
+
n = BN_num_bits(range);
|
|
244
|
+
|
|
245
|
+
if (n == 1) {
|
|
246
|
+
if (!BN_zero(r)) return 0;
|
|
247
|
+
} else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) {
|
|
248
|
+
do {
|
|
249
|
+
if (!bn_rand(r, n + 1, -1, 0)) return 0;
|
|
250
|
+
if (BN_cmp(r ,range) >= 0) {
|
|
251
|
+
if (!BN_sub(r, r, range)) return 0;
|
|
252
|
+
if (BN_cmp(r, range) >= 0)
|
|
253
|
+
if (!BN_sub(r, r, range)) return 0;
|
|
254
|
+
}
|
|
255
|
+
} while (BN_cmp(r, range) >= 0);
|
|
256
|
+
} else {
|
|
257
|
+
do {
|
|
258
|
+
if (!bn_rand(r, n, -1, 0)) return 0;
|
|
259
|
+
} while (BN_cmp(r, range) >= 0);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return 1;
|
|
263
|
+
}
|
|
264
|
+
#endif
|
|
265
|
+
|
|
266
|
+
#if !defined(HAVE_BN_RAND_RANGE)
|
|
267
|
+
int
|
|
268
|
+
BN_rand_range(BIGNUM *r, BIGNUM *range)
|
|
269
|
+
{
|
|
270
|
+
return bn_rand_range(0, r, range);
|
|
271
|
+
}
|
|
272
|
+
#endif
|
|
273
|
+
|
|
274
|
+
#if !defined(HAVE_BN_PSEUDO_RAND_RANGE)
|
|
275
|
+
int
|
|
276
|
+
BN_pseudo_rand_range(BIGNUM *r, BIGNUM *range)
|
|
277
|
+
{
|
|
278
|
+
return bn_rand_range(1, r, range);
|
|
279
|
+
}
|
|
280
|
+
#endif
|
|
281
|
+
|
|
282
|
+
#if !defined(HAVE_CONF_GET1_DEFAULT_CONFIG_FILE)
|
|
283
|
+
#define OPENSSL_CONF "openssl.cnf"
|
|
284
|
+
char *
|
|
285
|
+
CONF_get1_default_config_file(void)
|
|
286
|
+
{
|
|
287
|
+
char *file;
|
|
288
|
+
int len;
|
|
289
|
+
|
|
290
|
+
file = getenv("OPENSSL_CONF");
|
|
291
|
+
if (file) return BUF_strdup(file);
|
|
292
|
+
len = strlen(X509_get_default_cert_area());
|
|
293
|
+
#ifndef OPENSSL_SYS_VMS
|
|
294
|
+
len++;
|
|
295
|
+
#endif
|
|
296
|
+
len += strlen(OPENSSL_CONF);
|
|
297
|
+
file = OPENSSL_malloc(len + 1);
|
|
298
|
+
if (!file) return NULL;
|
|
299
|
+
strcpy(file,X509_get_default_cert_area());
|
|
300
|
+
#ifndef OPENSSL_SYS_VMS
|
|
301
|
+
strcat(file,"/");
|
|
302
|
+
#endif
|
|
303
|
+
strcat(file,OPENSSL_CONF);
|
|
304
|
+
|
|
305
|
+
return file;
|
|
306
|
+
}
|
|
307
|
+
#endif
|
|
308
|
+
|
|
309
|
+
#if !defined(HAVE_PEM_DEF_CALLBACK)
|
|
310
|
+
#define OSSL_PASS_MIN_LENGTH 4
|
|
311
|
+
int
|
|
312
|
+
PEM_def_callback(char *buf, int num, int w, void *key)
|
|
313
|
+
{
|
|
314
|
+
int i,j;
|
|
315
|
+
const char *prompt;
|
|
316
|
+
|
|
317
|
+
if (key) {
|
|
318
|
+
i = strlen(key);
|
|
319
|
+
i = (i > num) ? num : i;
|
|
320
|
+
memcpy(buf, key, i);
|
|
321
|
+
return i;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
prompt = EVP_get_pw_prompt();
|
|
325
|
+
if (prompt == NULL) prompt = "Enter PEM pass phrase:";
|
|
326
|
+
for (;;) {
|
|
327
|
+
i = EVP_read_pw_string(buf, num, prompt, w);
|
|
328
|
+
if (i != 0) {
|
|
329
|
+
memset(buf, 0, (unsigned int)num);
|
|
330
|
+
return(-1);
|
|
331
|
+
}
|
|
332
|
+
j = strlen(buf);
|
|
333
|
+
if (j < OSSL_PASS_MIN_LENGTH) {
|
|
334
|
+
fprintf(stderr,
|
|
335
|
+
"phrase is too short, needs to be at least %d chars\n",
|
|
336
|
+
OSSL_PASS_MIN_LENGTH);
|
|
337
|
+
}
|
|
338
|
+
else break;
|
|
339
|
+
}
|
|
340
|
+
return j;
|
|
341
|
+
}
|
|
342
|
+
#endif
|
|
343
|
+
|