zig_example 0.3.2 → 0.3.3.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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/ext/mkmf.rb +6 -1
  3. data/lib/zig_example/version.rb +1 -1
  4. metadata +2 -55
  5. data/ext/openssl/openssl_missing.c +0 -40
  6. data/ext/openssl/openssl_missing.h +0 -238
  7. data/ext/openssl/ossl.c +0 -1295
  8. data/ext/openssl/ossl.h +0 -201
  9. data/ext/openssl/ossl_asn1.c +0 -1891
  10. data/ext/openssl/ossl_asn1.h +0 -62
  11. data/ext/openssl/ossl_bio.c +0 -42
  12. data/ext/openssl/ossl_bio.h +0 -16
  13. data/ext/openssl/ossl_bn.c +0 -1344
  14. data/ext/openssl/ossl_bn.h +0 -26
  15. data/ext/openssl/ossl_cipher.c +0 -1074
  16. data/ext/openssl/ossl_cipher.h +0 -20
  17. data/ext/openssl/ossl_config.c +0 -460
  18. data/ext/openssl/ossl_config.h +0 -16
  19. data/ext/openssl/ossl_digest.c +0 -425
  20. data/ext/openssl/ossl_digest.h +0 -20
  21. data/ext/openssl/ossl_engine.c +0 -568
  22. data/ext/openssl/ossl_engine.h +0 -19
  23. data/ext/openssl/ossl_hmac.c +0 -310
  24. data/ext/openssl/ossl_hmac.h +0 -18
  25. data/ext/openssl/ossl_kdf.c +0 -311
  26. data/ext/openssl/ossl_kdf.h +0 -6
  27. data/ext/openssl/ossl_ns_spki.c +0 -405
  28. data/ext/openssl/ossl_ns_spki.h +0 -19
  29. data/ext/openssl/ossl_ocsp.c +0 -1965
  30. data/ext/openssl/ossl_ocsp.h +0 -23
  31. data/ext/openssl/ossl_pkcs12.c +0 -275
  32. data/ext/openssl/ossl_pkcs12.h +0 -13
  33. data/ext/openssl/ossl_pkcs7.c +0 -1081
  34. data/ext/openssl/ossl_pkcs7.h +0 -36
  35. data/ext/openssl/ossl_pkey.c +0 -1624
  36. data/ext/openssl/ossl_pkey.h +0 -204
  37. data/ext/openssl/ossl_pkey_dh.c +0 -440
  38. data/ext/openssl/ossl_pkey_dsa.c +0 -359
  39. data/ext/openssl/ossl_pkey_ec.c +0 -1655
  40. data/ext/openssl/ossl_pkey_rsa.c +0 -579
  41. data/ext/openssl/ossl_rand.c +0 -200
  42. data/ext/openssl/ossl_rand.h +0 -18
  43. data/ext/openssl/ossl_ssl.c +0 -3142
  44. data/ext/openssl/ossl_ssl.h +0 -36
  45. data/ext/openssl/ossl_ssl_session.c +0 -331
  46. data/ext/openssl/ossl_ts.c +0 -1539
  47. data/ext/openssl/ossl_ts.h +0 -16
  48. data/ext/openssl/ossl_x509.c +0 -256
  49. data/ext/openssl/ossl_x509.h +0 -115
  50. data/ext/openssl/ossl_x509attr.c +0 -324
  51. data/ext/openssl/ossl_x509cert.c +0 -1002
  52. data/ext/openssl/ossl_x509crl.c +0 -545
  53. data/ext/openssl/ossl_x509ext.c +0 -490
  54. data/ext/openssl/ossl_x509name.c +0 -597
  55. data/ext/openssl/ossl_x509req.c +0 -444
  56. data/ext/openssl/ossl_x509revoked.c +0 -300
  57. data/ext/openssl/ossl_x509store.c +0 -986
@@ -1,16 +0,0 @@
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
@@ -1,256 +0,0 @@
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
- DefX509Const(V_ERR_HOSTNAME_MISMATCH);
119
- DefX509Const(V_ERR_EMAIL_MISMATCH);
120
- DefX509Const(V_ERR_IP_ADDRESS_MISMATCH);
121
- #if defined(X509_V_ERR_DANE_NO_MATCH)
122
- DefX509Const(V_ERR_DANE_NO_MATCH);
123
- #endif
124
- #if defined(X509_V_ERR_EE_KEY_TOO_SMALL)
125
- DefX509Const(V_ERR_EE_KEY_TOO_SMALL);
126
- DefX509Const(V_ERR_CA_KEY_TOO_SMALL);
127
- DefX509Const(V_ERR_CA_MD_TOO_WEAK);
128
- #endif
129
- #if defined(X509_V_ERR_INVALID_CALL)
130
- DefX509Const(V_ERR_INVALID_CALL);
131
- #endif
132
- #if defined(X509_V_ERR_STORE_LOOKUP)
133
- DefX509Const(V_ERR_STORE_LOOKUP);
134
- #endif
135
- #if defined(X509_V_ERR_NO_VALID_SCTS)
136
- DefX509Const(V_ERR_NO_VALID_SCTS);
137
- #endif
138
- #if defined(X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION)
139
- DefX509Const(V_ERR_PROXY_SUBJECT_NAME_VIOLATION);
140
- #endif
141
- #if defined(X509_V_ERR_OCSP_VERIFY_NEEDED)
142
- DefX509Const(V_ERR_OCSP_VERIFY_NEEDED);
143
- DefX509Const(V_ERR_OCSP_VERIFY_FAILED);
144
- DefX509Const(V_ERR_OCSP_CERT_UNKNOWN);
145
- #endif
146
-
147
- /* Certificate verify flags */
148
- /* Set by Store#flags= and StoreContext#flags=. */
149
- DefX509Const(V_FLAG_USE_CHECK_TIME);
150
- /* Set by Store#flags= and StoreContext#flags=. Enables CRL checking for the
151
- * certificate chain leaf. */
152
- DefX509Const(V_FLAG_CRL_CHECK);
153
- /* Set by Store#flags= and StoreContext#flags=. Enables CRL checking for all
154
- * certificates in the certificate chain */
155
- DefX509Const(V_FLAG_CRL_CHECK_ALL);
156
- /* Set by Store#flags= and StoreContext#flags=. Disables critical extension
157
- * checking. */
158
- DefX509Const(V_FLAG_IGNORE_CRITICAL);
159
- /* Set by Store#flags= and StoreContext#flags=. Disables workarounds for
160
- * broken certificates. */
161
- DefX509Const(V_FLAG_X509_STRICT);
162
- /* Set by Store#flags= and StoreContext#flags=. Enables proxy certificate
163
- * verification. */
164
- DefX509Const(V_FLAG_ALLOW_PROXY_CERTS);
165
- /* Set by Store#flags= and StoreContext#flags=. Enables certificate policy
166
- * constraints checking. */
167
- DefX509Const(V_FLAG_POLICY_CHECK);
168
- /* Set by Store#flags= and StoreContext#flags=.
169
- * Implies V_FLAG_POLICY_CHECK */
170
- DefX509Const(V_FLAG_EXPLICIT_POLICY);
171
- /* Set by Store#flags= and StoreContext#flags=.
172
- * Implies V_FLAG_POLICY_CHECK */
173
- DefX509Const(V_FLAG_INHIBIT_ANY);
174
- /* Set by Store#flags= and StoreContext#flags=.
175
- * Implies V_FLAG_POLICY_CHECK */
176
- DefX509Const(V_FLAG_INHIBIT_MAP);
177
- /* Set by Store#flags= and StoreContext#flags=. */
178
- DefX509Const(V_FLAG_NOTIFY_POLICY);
179
- /* Set by Store#flags= and StoreContext#flags=. Enables some additional
180
- * features including support for indirect signed CRLs. */
181
- DefX509Const(V_FLAG_EXTENDED_CRL_SUPPORT);
182
- /* Set by Store#flags= and StoreContext#flags=. Uses delta CRLs. If not
183
- * specified, deltas are ignored. */
184
- DefX509Const(V_FLAG_USE_DELTAS);
185
- /* Set by Store#flags= and StoreContext#flags=. Enables checking of the
186
- * signature of the root self-signed CA. */
187
- DefX509Const(V_FLAG_CHECK_SS_SIGNATURE);
188
- /* Set by Store#flags= and StoreContext#flags=. When constructing a
189
- * certificate chain, search the Store first for the issuer certificate.
190
- * Enabled by default in OpenSSL >= 1.1.0. */
191
- DefX509Const(V_FLAG_TRUSTED_FIRST);
192
- #if defined(X509_V_FLAG_SUITEB_128_LOS_ONLY)
193
- /* Set by Store#flags= and StoreContext#flags=.
194
- * Enables Suite B 128 bit only mode. */
195
- DefX509Const(V_FLAG_SUITEB_128_LOS_ONLY);
196
- #endif
197
- #if defined(X509_V_FLAG_SUITEB_192_LOS)
198
- /* Set by Store#flags= and StoreContext#flags=.
199
- * Enables Suite B 192 bit only mode. */
200
- DefX509Const(V_FLAG_SUITEB_192_LOS);
201
- #endif
202
- #if defined(X509_V_FLAG_SUITEB_128_LOS)
203
- /* Set by Store#flags= and StoreContext#flags=.
204
- * Enables Suite B 128 bit mode allowing 192 bit algorithms. */
205
- DefX509Const(V_FLAG_SUITEB_128_LOS);
206
- #endif
207
- /* Set by Store#flags= and StoreContext#flags=.
208
- * Allows partial chains if at least one certificate is in trusted store. */
209
- DefX509Const(V_FLAG_PARTIAL_CHAIN);
210
- #if defined(X509_V_FLAG_NO_ALT_CHAINS)
211
- /* Set by Store#flags= and StoreContext#flags=. Suppresses searching for
212
- * a alternative chain. No effect in OpenSSL >= 1.1.0. */
213
- DefX509Const(V_FLAG_NO_ALT_CHAINS);
214
- #endif
215
- #if defined(X509_V_FLAG_NO_CHECK_TIME)
216
- /* Set by Store#flags= and StoreContext#flags=. Suppresses checking the
217
- * validity period of certificates and CRLs. No effect when the current
218
- * time is explicitly set by Store#time= or StoreContext#time=. */
219
- DefX509Const(V_FLAG_NO_CHECK_TIME);
220
- #endif
221
-
222
- /* Set by Store#purpose=. SSL/TLS client. */
223
- DefX509Const(PURPOSE_SSL_CLIENT);
224
- /* Set by Store#purpose=. SSL/TLS server. */
225
- DefX509Const(PURPOSE_SSL_SERVER);
226
- /* Set by Store#purpose=. Netscape SSL server. */
227
- DefX509Const(PURPOSE_NS_SSL_SERVER);
228
- /* Set by Store#purpose=. S/MIME signing. */
229
- DefX509Const(PURPOSE_SMIME_SIGN);
230
- /* Set by Store#purpose=. S/MIME encryption. */
231
- DefX509Const(PURPOSE_SMIME_ENCRYPT);
232
- /* Set by Store#purpose=. CRL signing */
233
- DefX509Const(PURPOSE_CRL_SIGN);
234
- /* Set by Store#purpose=. No checks. */
235
- DefX509Const(PURPOSE_ANY);
236
- /* Set by Store#purpose=. OCSP helper. */
237
- DefX509Const(PURPOSE_OCSP_HELPER);
238
- /* Set by Store#purpose=. Time stamps signer. */
239
- DefX509Const(PURPOSE_TIMESTAMP_SIGN);
240
-
241
- DefX509Const(TRUST_COMPAT);
242
- DefX509Const(TRUST_SSL_CLIENT);
243
- DefX509Const(TRUST_SSL_SERVER);
244
- DefX509Const(TRUST_EMAIL);
245
- DefX509Const(TRUST_OBJECT_SIGN);
246
- DefX509Const(TRUST_OCSP_SIGN);
247
- DefX509Const(TRUST_OCSP_REQUEST);
248
- DefX509Const(TRUST_TSA);
249
-
250
- DefX509Default(CERT_AREA, cert_area);
251
- DefX509Default(CERT_DIR, cert_dir);
252
- DefX509Default(CERT_FILE, cert_file);
253
- DefX509Default(CERT_DIR_ENV, cert_dir_env);
254
- DefX509Default(CERT_FILE_ENV, cert_file_env);
255
- DefX509Default(PRIVATE_DIR, private_dir);
256
- }
@@ -1,115 +0,0 @@
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_ */
@@ -1,324 +0,0 @@
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
- }