openssl-custom 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/BSDL +22 -0
  3. data/CONTRIBUTING.md +132 -0
  4. data/History.md +485 -0
  5. data/LICENSE.txt +56 -0
  6. data/README.md +66 -0
  7. data/ext/openssl/extconf.rb +190 -0
  8. data/ext/openssl/openssl_missing.c +106 -0
  9. data/ext/openssl/openssl_missing.h +257 -0
  10. data/ext/openssl/ossl.c +1282 -0
  11. data/ext/openssl/ossl.h +181 -0
  12. data/ext/openssl/ossl_asn1.c +1878 -0
  13. data/ext/openssl/ossl_asn1.h +62 -0
  14. data/ext/openssl/ossl_bio.c +42 -0
  15. data/ext/openssl/ossl_bio.h +16 -0
  16. data/ext/openssl/ossl_bn.c +1270 -0
  17. data/ext/openssl/ossl_bn.h +26 -0
  18. data/ext/openssl/ossl_cipher.c +1075 -0
  19. data/ext/openssl/ossl_cipher.h +20 -0
  20. data/ext/openssl/ossl_config.c +89 -0
  21. data/ext/openssl/ossl_config.h +19 -0
  22. data/ext/openssl/ossl_digest.c +425 -0
  23. data/ext/openssl/ossl_digest.h +20 -0
  24. data/ext/openssl/ossl_engine.c +567 -0
  25. data/ext/openssl/ossl_engine.h +19 -0
  26. data/ext/openssl/ossl_hmac.c +389 -0
  27. data/ext/openssl/ossl_hmac.h +18 -0
  28. data/ext/openssl/ossl_kdf.c +303 -0
  29. data/ext/openssl/ossl_kdf.h +6 -0
  30. data/ext/openssl/ossl_ns_spki.c +405 -0
  31. data/ext/openssl/ossl_ns_spki.h +19 -0
  32. data/ext/openssl/ossl_ocsp.c +2013 -0
  33. data/ext/openssl/ossl_ocsp.h +23 -0
  34. data/ext/openssl/ossl_pkcs12.c +257 -0
  35. data/ext/openssl/ossl_pkcs12.h +13 -0
  36. data/ext/openssl/ossl_pkcs7.c +1098 -0
  37. data/ext/openssl/ossl_pkcs7.h +36 -0
  38. data/ext/openssl/ossl_pkey.c +673 -0
  39. data/ext/openssl/ossl_pkey.h +241 -0
  40. data/ext/openssl/ossl_pkey_dh.c +650 -0
  41. data/ext/openssl/ossl_pkey_dsa.c +664 -0
  42. data/ext/openssl/ossl_pkey_ec.c +1827 -0
  43. data/ext/openssl/ossl_pkey_rsa.c +966 -0
  44. data/ext/openssl/ossl_rand.c +200 -0
  45. data/ext/openssl/ossl_rand.h +18 -0
  46. data/ext/openssl/ossl_ssl.c +3080 -0
  47. data/ext/openssl/ossl_ssl.h +36 -0
  48. data/ext/openssl/ossl_ssl_session.c +332 -0
  49. data/ext/openssl/ossl_ts.c +1524 -0
  50. data/ext/openssl/ossl_ts.h +16 -0
  51. data/ext/openssl/ossl_x509.c +262 -0
  52. data/ext/openssl/ossl_x509.h +115 -0
  53. data/ext/openssl/ossl_x509attr.c +324 -0
  54. data/ext/openssl/ossl_x509cert.c +846 -0
  55. data/ext/openssl/ossl_x509crl.c +542 -0
  56. data/ext/openssl/ossl_x509ext.c +491 -0
  57. data/ext/openssl/ossl_x509name.c +590 -0
  58. data/ext/openssl/ossl_x509req.c +441 -0
  59. data/ext/openssl/ossl_x509revoked.c +300 -0
  60. data/ext/openssl/ossl_x509store.c +902 -0
  61. data/ext/openssl/ruby_missing.h +24 -0
  62. data/lib/openssl/bn.rb +40 -0
  63. data/lib/openssl/buffering.rb +478 -0
  64. data/lib/openssl/cipher.rb +67 -0
  65. data/lib/openssl/config.rb +501 -0
  66. data/lib/openssl/digest.rb +73 -0
  67. data/lib/openssl/hmac.rb +13 -0
  68. data/lib/openssl/marshal.rb +30 -0
  69. data/lib/openssl/pkcs5.rb +22 -0
  70. data/lib/openssl/pkey.rb +42 -0
  71. data/lib/openssl/ssl.rb +542 -0
  72. data/lib/openssl/version.rb +5 -0
  73. data/lib/openssl/x509.rb +369 -0
  74. data/lib/openssl.rb +38 -0
  75. metadata +196 -0
@@ -0,0 +1,16 @@
1
+ /*
2
+ *
3
+ * Copyright (C) 2010 Martin Bosslet <Martin.Bosslet@googlemail.com>
4
+ * All rights reserved.
5
+ */
6
+ /*
7
+ * This program is licenced under the same licence as Ruby.
8
+ * (See the file 'LICENCE'.)
9
+ */
10
+
11
+ #if !defined(_OSSL_TS_H_)
12
+ #define _OSSL_TS_H_
13
+
14
+ void Init_ossl_ts(void);
15
+
16
+ #endif
@@ -0,0 +1,262 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4
+ * All rights reserved.
5
+ */
6
+ /*
7
+ * This program is licensed under the same licence as Ruby.
8
+ * (See the file 'LICENCE'.)
9
+ */
10
+ #include "ossl.h"
11
+
12
+ VALUE mX509;
13
+
14
+ #define DefX509Const(x) rb_define_const(mX509, #x, INT2NUM(X509_##x))
15
+ #define DefX509Default(x,i) \
16
+ rb_define_const(mX509, "DEFAULT_" #x, rb_str_new2(X509_get_default_##i()))
17
+
18
+ ASN1_TIME *
19
+ ossl_x509_time_adjust(ASN1_TIME *s, VALUE time)
20
+ {
21
+ time_t sec;
22
+
23
+ int off_days;
24
+
25
+ ossl_time_split(time, &sec, &off_days);
26
+ return X509_time_adj_ex(s, off_days, 0, &sec);
27
+ }
28
+
29
+ void
30
+ Init_ossl_x509(void)
31
+ {
32
+ #if 0
33
+ mOSSL = rb_define_module("OpenSSL");
34
+ #endif
35
+
36
+ mX509 = rb_define_module_under(mOSSL, "X509");
37
+
38
+ Init_ossl_x509attr();
39
+ Init_ossl_x509cert();
40
+ Init_ossl_x509crl();
41
+ Init_ossl_x509ext();
42
+ Init_ossl_x509name();
43
+ Init_ossl_x509req();
44
+ Init_ossl_x509revoked();
45
+ Init_ossl_x509store();
46
+
47
+ /* Constants are up-to-date with 1.1.1. */
48
+
49
+ /* Certificate verification error code */
50
+ DefX509Const(V_OK);
51
+ #if defined(X509_V_ERR_UNSPECIFIED) /* 1.0.1r, 1.0.2f, 1.1.0 */
52
+ DefX509Const(V_ERR_UNSPECIFIED);
53
+ #endif
54
+ DefX509Const(V_ERR_UNABLE_TO_GET_ISSUER_CERT);
55
+ DefX509Const(V_ERR_UNABLE_TO_GET_CRL);
56
+ DefX509Const(V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE);
57
+ DefX509Const(V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE);
58
+ DefX509Const(V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY);
59
+ DefX509Const(V_ERR_CERT_SIGNATURE_FAILURE);
60
+ DefX509Const(V_ERR_CRL_SIGNATURE_FAILURE);
61
+ DefX509Const(V_ERR_CERT_NOT_YET_VALID);
62
+ DefX509Const(V_ERR_CERT_HAS_EXPIRED);
63
+ DefX509Const(V_ERR_CRL_NOT_YET_VALID);
64
+ DefX509Const(V_ERR_CRL_HAS_EXPIRED);
65
+ DefX509Const(V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD);
66
+ DefX509Const(V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD);
67
+ DefX509Const(V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD);
68
+ DefX509Const(V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD);
69
+ DefX509Const(V_ERR_OUT_OF_MEM);
70
+ DefX509Const(V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT);
71
+ DefX509Const(V_ERR_SELF_SIGNED_CERT_IN_CHAIN);
72
+ DefX509Const(V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY);
73
+ DefX509Const(V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE);
74
+ DefX509Const(V_ERR_CERT_CHAIN_TOO_LONG);
75
+ DefX509Const(V_ERR_CERT_REVOKED);
76
+ DefX509Const(V_ERR_INVALID_CA);
77
+ DefX509Const(V_ERR_PATH_LENGTH_EXCEEDED);
78
+ DefX509Const(V_ERR_INVALID_PURPOSE);
79
+ DefX509Const(V_ERR_CERT_UNTRUSTED);
80
+ DefX509Const(V_ERR_CERT_REJECTED);
81
+ DefX509Const(V_ERR_SUBJECT_ISSUER_MISMATCH);
82
+ DefX509Const(V_ERR_AKID_SKID_MISMATCH);
83
+ DefX509Const(V_ERR_AKID_ISSUER_SERIAL_MISMATCH);
84
+ DefX509Const(V_ERR_KEYUSAGE_NO_CERTSIGN);
85
+ DefX509Const(V_ERR_UNABLE_TO_GET_CRL_ISSUER);
86
+ DefX509Const(V_ERR_UNHANDLED_CRITICAL_EXTENSION);
87
+ DefX509Const(V_ERR_KEYUSAGE_NO_CRL_SIGN);
88
+ DefX509Const(V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION);
89
+ DefX509Const(V_ERR_INVALID_NON_CA);
90
+ DefX509Const(V_ERR_PROXY_PATH_LENGTH_EXCEEDED);
91
+ DefX509Const(V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE);
92
+ DefX509Const(V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED);
93
+ DefX509Const(V_ERR_INVALID_EXTENSION);
94
+ DefX509Const(V_ERR_INVALID_POLICY_EXTENSION);
95
+ DefX509Const(V_ERR_NO_EXPLICIT_POLICY);
96
+ DefX509Const(V_ERR_DIFFERENT_CRL_SCOPE);
97
+ DefX509Const(V_ERR_UNSUPPORTED_EXTENSION_FEATURE);
98
+ DefX509Const(V_ERR_UNNESTED_RESOURCE);
99
+ DefX509Const(V_ERR_PERMITTED_VIOLATION);
100
+ DefX509Const(V_ERR_EXCLUDED_VIOLATION);
101
+ DefX509Const(V_ERR_SUBTREE_MINMAX);
102
+ DefX509Const(V_ERR_APPLICATION_VERIFICATION);
103
+ DefX509Const(V_ERR_UNSUPPORTED_CONSTRAINT_TYPE);
104
+ DefX509Const(V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX);
105
+ DefX509Const(V_ERR_UNSUPPORTED_NAME_SYNTAX);
106
+ DefX509Const(V_ERR_CRL_PATH_VALIDATION_ERROR);
107
+ #if defined(X509_V_ERR_PATH_LOOP)
108
+ DefX509Const(V_ERR_PATH_LOOP);
109
+ #endif
110
+ #if defined(X509_V_ERR_SUITE_B_INVALID_VERSION)
111
+ DefX509Const(V_ERR_SUITE_B_INVALID_VERSION);
112
+ DefX509Const(V_ERR_SUITE_B_INVALID_ALGORITHM);
113
+ DefX509Const(V_ERR_SUITE_B_INVALID_CURVE);
114
+ DefX509Const(V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM);
115
+ DefX509Const(V_ERR_SUITE_B_LOS_NOT_ALLOWED);
116
+ DefX509Const(V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256);
117
+ #endif
118
+ #if defined(X509_V_ERR_HOSTNAME_MISMATCH)
119
+ DefX509Const(V_ERR_HOSTNAME_MISMATCH);
120
+ DefX509Const(V_ERR_EMAIL_MISMATCH);
121
+ DefX509Const(V_ERR_IP_ADDRESS_MISMATCH);
122
+ #endif
123
+ #if defined(X509_V_ERR_DANE_NO_MATCH)
124
+ DefX509Const(V_ERR_DANE_NO_MATCH);
125
+ #endif
126
+ #if defined(X509_V_ERR_EE_KEY_TOO_SMALL)
127
+ DefX509Const(V_ERR_EE_KEY_TOO_SMALL);
128
+ DefX509Const(V_ERR_CA_KEY_TOO_SMALL);
129
+ DefX509Const(V_ERR_CA_MD_TOO_WEAK);
130
+ #endif
131
+ #if defined(X509_V_ERR_INVALID_CALL)
132
+ DefX509Const(V_ERR_INVALID_CALL);
133
+ #endif
134
+ #if defined(X509_V_ERR_STORE_LOOKUP)
135
+ DefX509Const(V_ERR_STORE_LOOKUP);
136
+ #endif
137
+ #if defined(X509_V_ERR_NO_VALID_SCTS)
138
+ DefX509Const(V_ERR_NO_VALID_SCTS);
139
+ #endif
140
+ #if defined(X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION)
141
+ DefX509Const(V_ERR_PROXY_SUBJECT_NAME_VIOLATION);
142
+ #endif
143
+ #if defined(X509_V_ERR_OCSP_VERIFY_NEEDED)
144
+ DefX509Const(V_ERR_OCSP_VERIFY_NEEDED);
145
+ DefX509Const(V_ERR_OCSP_VERIFY_FAILED);
146
+ DefX509Const(V_ERR_OCSP_CERT_UNKNOWN);
147
+ #endif
148
+
149
+ /* Certificate verify flags */
150
+ /* Set by Store#flags= and StoreContext#flags=. */
151
+ DefX509Const(V_FLAG_USE_CHECK_TIME);
152
+ /* Set by Store#flags= and StoreContext#flags=. Enables CRL checking for the
153
+ * certificate chain leaf. */
154
+ DefX509Const(V_FLAG_CRL_CHECK);
155
+ /* Set by Store#flags= and StoreContext#flags=. Enables CRL checking for all
156
+ * certificates in the certificate chain */
157
+ DefX509Const(V_FLAG_CRL_CHECK_ALL);
158
+ /* Set by Store#flags= and StoreContext#flags=. Disables critical extension
159
+ * checking. */
160
+ DefX509Const(V_FLAG_IGNORE_CRITICAL);
161
+ /* Set by Store#flags= and StoreContext#flags=. Disables workarounds for
162
+ * broken certificates. */
163
+ DefX509Const(V_FLAG_X509_STRICT);
164
+ /* Set by Store#flags= and StoreContext#flags=. Enables proxy certificate
165
+ * verification. */
166
+ DefX509Const(V_FLAG_ALLOW_PROXY_CERTS);
167
+ /* Set by Store#flags= and StoreContext#flags=. Enables certificate policy
168
+ * constraints checking. */
169
+ DefX509Const(V_FLAG_POLICY_CHECK);
170
+ /* Set by Store#flags= and StoreContext#flags=.
171
+ * Implies V_FLAG_POLICY_CHECK */
172
+ DefX509Const(V_FLAG_EXPLICIT_POLICY);
173
+ /* Set by Store#flags= and StoreContext#flags=.
174
+ * Implies V_FLAG_POLICY_CHECK */
175
+ DefX509Const(V_FLAG_INHIBIT_ANY);
176
+ /* Set by Store#flags= and StoreContext#flags=.
177
+ * Implies V_FLAG_POLICY_CHECK */
178
+ DefX509Const(V_FLAG_INHIBIT_MAP);
179
+ /* Set by Store#flags= and StoreContext#flags=. */
180
+ DefX509Const(V_FLAG_NOTIFY_POLICY);
181
+ /* Set by Store#flags= and StoreContext#flags=. Enables some additional
182
+ * features including support for indirect signed CRLs. */
183
+ DefX509Const(V_FLAG_EXTENDED_CRL_SUPPORT);
184
+ /* Set by Store#flags= and StoreContext#flags=. Uses delta CRLs. If not
185
+ * specified, deltas are ignored. */
186
+ DefX509Const(V_FLAG_USE_DELTAS);
187
+ /* Set by Store#flags= and StoreContext#flags=. Enables checking of the
188
+ * signature of the root self-signed CA. */
189
+ DefX509Const(V_FLAG_CHECK_SS_SIGNATURE);
190
+ #if defined(X509_V_FLAG_TRUSTED_FIRST)
191
+ /* Set by Store#flags= and StoreContext#flags=. When constructing a
192
+ * certificate chain, search the Store first for the issuer certificate.
193
+ * Enabled by default in OpenSSL >= 1.1.0. */
194
+ DefX509Const(V_FLAG_TRUSTED_FIRST);
195
+ #endif
196
+ #if defined(X509_V_FLAG_SUITEB_128_LOS_ONLY)
197
+ /* Set by Store#flags= and StoreContext#flags=.
198
+ * Enables Suite B 128 bit only mode. */
199
+ DefX509Const(V_FLAG_SUITEB_128_LOS_ONLY);
200
+ #endif
201
+ #if defined(X509_V_FLAG_SUITEB_192_LOS)
202
+ /* Set by Store#flags= and StoreContext#flags=.
203
+ * Enables Suite B 192 bit only mode. */
204
+ DefX509Const(V_FLAG_SUITEB_192_LOS);
205
+ #endif
206
+ #if defined(X509_V_FLAG_SUITEB_128_LOS)
207
+ /* Set by Store#flags= and StoreContext#flags=.
208
+ * Enables Suite B 128 bit mode allowing 192 bit algorithms. */
209
+ DefX509Const(V_FLAG_SUITEB_128_LOS);
210
+ #endif
211
+ #if defined(X509_V_FLAG_PARTIAL_CHAIN)
212
+ /* Set by Store#flags= and StoreContext#flags=.
213
+ * Allows partial chains if at least one certificate is in trusted store. */
214
+ DefX509Const(V_FLAG_PARTIAL_CHAIN);
215
+ #endif
216
+ #if defined(X509_V_FLAG_NO_ALT_CHAINS)
217
+ /* Set by Store#flags= and StoreContext#flags=. Suppresses searching for
218
+ * a alternative chain. No effect in OpenSSL >= 1.1.0. */
219
+ DefX509Const(V_FLAG_NO_ALT_CHAINS);
220
+ #endif
221
+ #if defined(X509_V_FLAG_NO_CHECK_TIME)
222
+ /* Set by Store#flags= and StoreContext#flags=. Suppresses checking the
223
+ * validity period of certificates and CRLs. No effect when the current
224
+ * time is explicitly set by Store#time= or StoreContext#time=. */
225
+ DefX509Const(V_FLAG_NO_CHECK_TIME);
226
+ #endif
227
+
228
+ /* Set by Store#purpose=. SSL/TLS client. */
229
+ DefX509Const(PURPOSE_SSL_CLIENT);
230
+ /* Set by Store#purpose=. SSL/TLS server. */
231
+ DefX509Const(PURPOSE_SSL_SERVER);
232
+ /* Set by Store#purpose=. Netscape SSL server. */
233
+ DefX509Const(PURPOSE_NS_SSL_SERVER);
234
+ /* Set by Store#purpose=. S/MIME signing. */
235
+ DefX509Const(PURPOSE_SMIME_SIGN);
236
+ /* Set by Store#purpose=. S/MIME encryption. */
237
+ DefX509Const(PURPOSE_SMIME_ENCRYPT);
238
+ /* Set by Store#purpose=. CRL signing */
239
+ DefX509Const(PURPOSE_CRL_SIGN);
240
+ /* Set by Store#purpose=. No checks. */
241
+ DefX509Const(PURPOSE_ANY);
242
+ /* Set by Store#purpose=. OCSP helper. */
243
+ DefX509Const(PURPOSE_OCSP_HELPER);
244
+ /* Set by Store#purpose=. Time stamps signer. */
245
+ DefX509Const(PURPOSE_TIMESTAMP_SIGN);
246
+
247
+ DefX509Const(TRUST_COMPAT);
248
+ DefX509Const(TRUST_SSL_CLIENT);
249
+ DefX509Const(TRUST_SSL_SERVER);
250
+ DefX509Const(TRUST_EMAIL);
251
+ DefX509Const(TRUST_OBJECT_SIGN);
252
+ DefX509Const(TRUST_OCSP_SIGN);
253
+ DefX509Const(TRUST_OCSP_REQUEST);
254
+ DefX509Const(TRUST_TSA);
255
+
256
+ DefX509Default(CERT_AREA, cert_area);
257
+ DefX509Default(CERT_DIR, cert_dir);
258
+ DefX509Default(CERT_FILE, cert_file);
259
+ DefX509Default(CERT_DIR_ENV, cert_dir_env);
260
+ DefX509Default(CERT_FILE_ENV, cert_file_env);
261
+ DefX509Default(PRIVATE_DIR, private_dir);
262
+ }
@@ -0,0 +1,115 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4
+ * All rights reserved.
5
+ */
6
+ /*
7
+ * This program is licensed under the same licence as Ruby.
8
+ * (See the file 'LICENCE'.)
9
+ */
10
+ #if !defined(_OSSL_X509_H_)
11
+ #define _OSSL_X509_H_
12
+
13
+ /*
14
+ * X509 main module
15
+ */
16
+ extern VALUE mX509;
17
+
18
+ /*
19
+ * Converts the VALUE into Integer and set it to the ASN1_TIME. This is a
20
+ * wrapper for X509_time_adj_ex() so passing NULL creates a new ASN1_TIME.
21
+ * Note that the caller must check the NULL return.
22
+ */
23
+ ASN1_TIME *ossl_x509_time_adjust(ASN1_TIME *, VALUE);
24
+
25
+ void Init_ossl_x509(void);
26
+
27
+ /*
28
+ * X509Attr
29
+ */
30
+ extern VALUE cX509Attr;
31
+ extern VALUE eX509AttrError;
32
+
33
+ VALUE ossl_x509attr_new(X509_ATTRIBUTE *);
34
+ X509_ATTRIBUTE *GetX509AttrPtr(VALUE);
35
+ void Init_ossl_x509attr(void);
36
+
37
+ /*
38
+ * X509Cert
39
+ */
40
+ extern VALUE cX509Cert;
41
+ extern VALUE eX509CertError;
42
+
43
+ VALUE ossl_x509_new(X509 *);
44
+ X509 *GetX509CertPtr(VALUE);
45
+ X509 *DupX509CertPtr(VALUE);
46
+ void Init_ossl_x509cert(void);
47
+
48
+ /*
49
+ * X509CRL
50
+ */
51
+ extern VALUE cX509CRL;
52
+ extern VALUE eX509CRLError;
53
+
54
+ VALUE ossl_x509crl_new(X509_CRL *);
55
+ X509_CRL *GetX509CRLPtr(VALUE);
56
+ void Init_ossl_x509crl(void);
57
+
58
+ /*
59
+ * X509Extension
60
+ */
61
+ extern VALUE cX509Ext;
62
+ extern VALUE cX509ExtFactory;
63
+ extern VALUE eX509ExtError;
64
+
65
+ VALUE ossl_x509ext_new(X509_EXTENSION *);
66
+ X509_EXTENSION *GetX509ExtPtr(VALUE);
67
+ void Init_ossl_x509ext(void);
68
+
69
+ /*
70
+ * X509Name
71
+ */
72
+ extern VALUE cX509Name;
73
+ extern VALUE eX509NameError;
74
+
75
+ VALUE ossl_x509name_new(X509_NAME *);
76
+ X509_NAME *GetX509NamePtr(VALUE);
77
+ void Init_ossl_x509name(void);
78
+
79
+ /*
80
+ * X509Request
81
+ */
82
+ extern VALUE cX509Req;
83
+ extern VALUE eX509ReqError;
84
+
85
+ X509_REQ *GetX509ReqPtr(VALUE);
86
+ void Init_ossl_x509req(void);
87
+
88
+ /*
89
+ * X509Revoked
90
+ */
91
+ extern VALUE cX509Rev;
92
+ extern VALUE eX509RevError;
93
+
94
+ VALUE ossl_x509revoked_new(X509_REVOKED *);
95
+ X509_REVOKED *DupX509RevokedPtr(VALUE);
96
+ void Init_ossl_x509revoked(void);
97
+
98
+ /*
99
+ * X509Store and X509StoreContext
100
+ */
101
+ extern VALUE cX509Store;
102
+ extern VALUE cX509StoreContext;
103
+ extern VALUE eX509StoreError;
104
+
105
+ X509_STORE *GetX509StorePtr(VALUE);
106
+
107
+ void Init_ossl_x509store(void);
108
+
109
+ /*
110
+ * Calls the verify callback Proc (the first parameter) with given pre-verify
111
+ * result and the X509_STORE_CTX.
112
+ */
113
+ int ossl_verify_cb_call(VALUE, int, X509_STORE_CTX *);
114
+
115
+ #endif /* _OSSL_X509_H_ */
@@ -0,0 +1,324 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2001 Michal Rokos <m.rokos@sh.cvut.cz>
4
+ * All rights reserved.
5
+ */
6
+ /*
7
+ * This program is licensed under the same licence as Ruby.
8
+ * (See the file 'LICENCE'.)
9
+ */
10
+ #include "ossl.h"
11
+
12
+ #define NewX509Attr(klass) \
13
+ TypedData_Wrap_Struct((klass), &ossl_x509attr_type, 0)
14
+ #define SetX509Attr(obj, attr) do { \
15
+ if (!(attr)) { \
16
+ ossl_raise(rb_eRuntimeError, "ATTR wasn't initialized!"); \
17
+ } \
18
+ RTYPEDDATA_DATA(obj) = (attr); \
19
+ } while (0)
20
+ #define GetX509Attr(obj, attr) do { \
21
+ TypedData_Get_Struct((obj), X509_ATTRIBUTE, &ossl_x509attr_type, (attr)); \
22
+ if (!(attr)) { \
23
+ ossl_raise(rb_eRuntimeError, "ATTR wasn't initialized!"); \
24
+ } \
25
+ } while (0)
26
+
27
+ /*
28
+ * Classes
29
+ */
30
+ VALUE cX509Attr;
31
+ VALUE eX509AttrError;
32
+
33
+ static void
34
+ ossl_x509attr_free(void *ptr)
35
+ {
36
+ X509_ATTRIBUTE_free(ptr);
37
+ }
38
+
39
+ static const rb_data_type_t ossl_x509attr_type = {
40
+ "OpenSSL/X509/ATTRIBUTE",
41
+ {
42
+ 0, ossl_x509attr_free,
43
+ },
44
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
45
+ };
46
+
47
+ /*
48
+ * Public
49
+ */
50
+ VALUE
51
+ ossl_x509attr_new(X509_ATTRIBUTE *attr)
52
+ {
53
+ X509_ATTRIBUTE *new;
54
+ VALUE obj;
55
+
56
+ obj = NewX509Attr(cX509Attr);
57
+ if (!attr) {
58
+ new = X509_ATTRIBUTE_new();
59
+ } else {
60
+ new = X509_ATTRIBUTE_dup(attr);
61
+ }
62
+ if (!new) {
63
+ ossl_raise(eX509AttrError, NULL);
64
+ }
65
+ SetX509Attr(obj, new);
66
+
67
+ return obj;
68
+ }
69
+
70
+ X509_ATTRIBUTE *
71
+ GetX509AttrPtr(VALUE obj)
72
+ {
73
+ X509_ATTRIBUTE *attr;
74
+
75
+ GetX509Attr(obj, attr);
76
+
77
+ return attr;
78
+ }
79
+
80
+ /*
81
+ * Private
82
+ */
83
+ static VALUE
84
+ ossl_x509attr_alloc(VALUE klass)
85
+ {
86
+ X509_ATTRIBUTE *attr;
87
+ VALUE obj;
88
+
89
+ obj = NewX509Attr(klass);
90
+ if (!(attr = X509_ATTRIBUTE_new()))
91
+ ossl_raise(eX509AttrError, NULL);
92
+ SetX509Attr(obj, attr);
93
+
94
+ return obj;
95
+ }
96
+
97
+ /*
98
+ * call-seq:
99
+ * Attribute.new(oid [, value]) => attr
100
+ */
101
+ static VALUE
102
+ ossl_x509attr_initialize(int argc, VALUE *argv, VALUE self)
103
+ {
104
+ VALUE oid, value;
105
+ X509_ATTRIBUTE *attr, *x;
106
+ const unsigned char *p;
107
+
108
+ GetX509Attr(self, attr);
109
+ if(rb_scan_args(argc, argv, "11", &oid, &value) == 1){
110
+ oid = ossl_to_der_if_possible(oid);
111
+ StringValue(oid);
112
+ p = (unsigned char *)RSTRING_PTR(oid);
113
+ x = d2i_X509_ATTRIBUTE(&attr, &p, RSTRING_LEN(oid));
114
+ DATA_PTR(self) = attr;
115
+ if(!x){
116
+ ossl_raise(eX509AttrError, NULL);
117
+ }
118
+ return self;
119
+ }
120
+ rb_funcall(self, rb_intern("oid="), 1, oid);
121
+ rb_funcall(self, rb_intern("value="), 1, value);
122
+
123
+ return self;
124
+ }
125
+
126
+ static VALUE
127
+ ossl_x509attr_initialize_copy(VALUE self, VALUE other)
128
+ {
129
+ X509_ATTRIBUTE *attr, *attr_other, *attr_new;
130
+
131
+ rb_check_frozen(self);
132
+ GetX509Attr(self, attr);
133
+ GetX509Attr(other, attr_other);
134
+
135
+ attr_new = X509_ATTRIBUTE_dup(attr_other);
136
+ if (!attr_new)
137
+ ossl_raise(eX509AttrError, "X509_ATTRIBUTE_dup");
138
+
139
+ SetX509Attr(self, attr_new);
140
+ X509_ATTRIBUTE_free(attr);
141
+
142
+ return self;
143
+ }
144
+
145
+ /*
146
+ * call-seq:
147
+ * attr.oid = string => string
148
+ */
149
+ static VALUE
150
+ ossl_x509attr_set_oid(VALUE self, VALUE oid)
151
+ {
152
+ X509_ATTRIBUTE *attr;
153
+ ASN1_OBJECT *obj;
154
+ char *s;
155
+
156
+ GetX509Attr(self, attr);
157
+ s = StringValueCStr(oid);
158
+ obj = OBJ_txt2obj(s, 0);
159
+ if(!obj) ossl_raise(eX509AttrError, NULL);
160
+ if (!X509_ATTRIBUTE_set1_object(attr, obj)) {
161
+ ASN1_OBJECT_free(obj);
162
+ ossl_raise(eX509AttrError, "X509_ATTRIBUTE_set1_object");
163
+ }
164
+ ASN1_OBJECT_free(obj);
165
+
166
+ return oid;
167
+ }
168
+
169
+ /*
170
+ * call-seq:
171
+ * attr.oid => string
172
+ */
173
+ static VALUE
174
+ ossl_x509attr_get_oid(VALUE self)
175
+ {
176
+ X509_ATTRIBUTE *attr;
177
+ ASN1_OBJECT *oid;
178
+ BIO *out;
179
+ VALUE ret;
180
+ int nid;
181
+
182
+ GetX509Attr(self, attr);
183
+ oid = X509_ATTRIBUTE_get0_object(attr);
184
+ if ((nid = OBJ_obj2nid(oid)) != NID_undef)
185
+ ret = rb_str_new2(OBJ_nid2sn(nid));
186
+ else{
187
+ if (!(out = BIO_new(BIO_s_mem())))
188
+ ossl_raise(eX509AttrError, NULL);
189
+ i2a_ASN1_OBJECT(out, oid);
190
+ ret = ossl_membio2str(out);
191
+ }
192
+
193
+ return ret;
194
+ }
195
+
196
+ /*
197
+ * call-seq:
198
+ * attr.value = asn1 => asn1
199
+ */
200
+ static VALUE
201
+ ossl_x509attr_set_value(VALUE self, VALUE value)
202
+ {
203
+ X509_ATTRIBUTE *attr;
204
+ VALUE asn1_value;
205
+ int i, asn1_tag;
206
+
207
+ OSSL_Check_Kind(value, cASN1Data);
208
+ asn1_tag = NUM2INT(rb_attr_get(value, rb_intern("@tag")));
209
+ asn1_value = rb_attr_get(value, rb_intern("@value"));
210
+ if (asn1_tag != V_ASN1_SET)
211
+ ossl_raise(eASN1Error, "argument must be ASN1::Set");
212
+ if (!RB_TYPE_P(asn1_value, T_ARRAY))
213
+ ossl_raise(eASN1Error, "ASN1::Set has non-array value");
214
+
215
+ GetX509Attr(self, attr);
216
+ if (X509_ATTRIBUTE_count(attr)) { /* populated, reset first */
217
+ ASN1_OBJECT *obj = X509_ATTRIBUTE_get0_object(attr);
218
+ X509_ATTRIBUTE *new_attr = X509_ATTRIBUTE_create_by_OBJ(NULL, obj, 0, NULL, -1);
219
+ if (!new_attr)
220
+ ossl_raise(eX509AttrError, NULL);
221
+ SetX509Attr(self, new_attr);
222
+ X509_ATTRIBUTE_free(attr);
223
+ attr = new_attr;
224
+ }
225
+
226
+ for (i = 0; i < RARRAY_LEN(asn1_value); i++) {
227
+ ASN1_TYPE *a1type = ossl_asn1_get_asn1type(RARRAY_AREF(asn1_value, i));
228
+ if (!X509_ATTRIBUTE_set1_data(attr, ASN1_TYPE_get(a1type),
229
+ a1type->value.ptr, -1)) {
230
+ ASN1_TYPE_free(a1type);
231
+ ossl_raise(eX509AttrError, NULL);
232
+ }
233
+ ASN1_TYPE_free(a1type);
234
+ }
235
+
236
+ return value;
237
+ }
238
+
239
+ /*
240
+ * call-seq:
241
+ * attr.value => asn1
242
+ */
243
+ static VALUE
244
+ ossl_x509attr_get_value(VALUE self)
245
+ {
246
+ X509_ATTRIBUTE *attr;
247
+ STACK_OF(ASN1_TYPE) *sk;
248
+ VALUE str;
249
+ int i, count, len;
250
+ unsigned char *p;
251
+
252
+ GetX509Attr(self, attr);
253
+ /* there is no X509_ATTRIBUTE_get0_set() :( */
254
+ if (!(sk = sk_ASN1_TYPE_new_null()))
255
+ ossl_raise(eX509AttrError, "sk_new");
256
+
257
+ count = X509_ATTRIBUTE_count(attr);
258
+ for (i = 0; i < count; i++)
259
+ sk_ASN1_TYPE_push(sk, X509_ATTRIBUTE_get0_type(attr, i));
260
+
261
+ if ((len = i2d_ASN1_SET_ANY(sk, NULL)) <= 0) {
262
+ sk_ASN1_TYPE_free(sk);
263
+ ossl_raise(eX509AttrError, NULL);
264
+ }
265
+ str = rb_str_new(0, len);
266
+ p = (unsigned char *)RSTRING_PTR(str);
267
+ if (i2d_ASN1_SET_ANY(sk, &p) <= 0) {
268
+ sk_ASN1_TYPE_free(sk);
269
+ ossl_raise(eX509AttrError, NULL);
270
+ }
271
+ ossl_str_adjust(str, p);
272
+ sk_ASN1_TYPE_free(sk);
273
+
274
+ return rb_funcall(mASN1, rb_intern("decode"), 1, str);
275
+ }
276
+
277
+ /*
278
+ * call-seq:
279
+ * attr.to_der => string
280
+ */
281
+ static VALUE
282
+ ossl_x509attr_to_der(VALUE self)
283
+ {
284
+ X509_ATTRIBUTE *attr;
285
+ VALUE str;
286
+ int len;
287
+ unsigned char *p;
288
+
289
+ GetX509Attr(self, attr);
290
+ if((len = i2d_X509_ATTRIBUTE(attr, NULL)) <= 0)
291
+ ossl_raise(eX509AttrError, NULL);
292
+ str = rb_str_new(0, len);
293
+ p = (unsigned char *)RSTRING_PTR(str);
294
+ if(i2d_X509_ATTRIBUTE(attr, &p) <= 0)
295
+ ossl_raise(eX509AttrError, NULL);
296
+ ossl_str_adjust(str, p);
297
+
298
+ return str;
299
+ }
300
+
301
+ /*
302
+ * X509_ATTRIBUTE init
303
+ */
304
+ void
305
+ Init_ossl_x509attr(void)
306
+ {
307
+ #if 0
308
+ mOSSL = rb_define_module("OpenSSL");
309
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
310
+ mX509 = rb_define_module_under(mOSSL, "X509");
311
+ #endif
312
+
313
+ eX509AttrError = rb_define_class_under(mX509, "AttributeError", eOSSLError);
314
+
315
+ cX509Attr = rb_define_class_under(mX509, "Attribute", rb_cObject);
316
+ rb_define_alloc_func(cX509Attr, ossl_x509attr_alloc);
317
+ rb_define_method(cX509Attr, "initialize", ossl_x509attr_initialize, -1);
318
+ rb_define_method(cX509Attr, "initialize_copy", ossl_x509attr_initialize_copy, 1);
319
+ rb_define_method(cX509Attr, "oid=", ossl_x509attr_set_oid, 1);
320
+ rb_define_method(cX509Attr, "oid", ossl_x509attr_get_oid, 0);
321
+ rb_define_method(cX509Attr, "value=", ossl_x509attr_set_value, 1);
322
+ rb_define_method(cX509Attr, "value", ossl_x509attr_get_value, 0);
323
+ rb_define_method(cX509Attr, "to_der", ossl_x509attr_to_der, 0);
324
+ }