Changeset View
Changeset View
Standalone View
Standalone View
protocols/jabber/libjingle/talk/base/openssladapter.cc
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | |||||
79 | 79 | | |||
80 | static int socket_write(BIO* h, const char* buf, int num); | 80 | static int socket_write(BIO* h, const char* buf, int num); | ||
81 | static int socket_read(BIO* h, char* buf, int size); | 81 | static int socket_read(BIO* h, char* buf, int size); | ||
82 | static int socket_puts(BIO* h, const char* str); | 82 | static int socket_puts(BIO* h, const char* str); | ||
83 | static long socket_ctrl(BIO* h, int cmd, long arg1, void* arg2); | 83 | static long socket_ctrl(BIO* h, int cmd, long arg1, void* arg2); | ||
84 | static int socket_new(BIO* h); | 84 | static int socket_new(BIO* h); | ||
85 | static int socket_free(BIO* data); | 85 | static int socket_free(BIO* data); | ||
86 | 86 | | |||
87 | #if OPENSSL_VERSION_NUMBER < 0x10100000L | ||||
87 | static BIO_METHOD methods_socket = { | 88 | static BIO_METHOD methods_socket = { | ||
88 | BIO_TYPE_BIO, | 89 | BIO_TYPE_BIO, | ||
89 | "socket", | 90 | "socket", | ||
90 | socket_write, | 91 | socket_write, | ||
91 | socket_read, | 92 | socket_read, | ||
92 | socket_puts, | 93 | socket_puts, | ||
93 | 0, | 94 | 0, | ||
94 | socket_ctrl, | 95 | socket_ctrl, | ||
95 | socket_new, | 96 | socket_new, | ||
96 | socket_free, | 97 | socket_free, | ||
97 | NULL, | 98 | NULL, | ||
98 | }; | 99 | }; | ||
99 | 100 | | |||
100 | BIO_METHOD* BIO_s_socket2() { return(&methods_socket); } | 101 | BIO_METHOD* BIO_s_socket2() { return(&methods_socket); } | ||
102 | #else | ||||
103 | static BIO_METHOD *methods_socket = NULL; | ||||
104 | | ||||
105 | static const BIO_METHOD * BIO_s_socket2(void) { | ||||
106 | if (methods_socket == NULL) { | ||||
107 | methods_socket = BIO_meth_new (BIO_TYPE_BIO | BIO_get_new_index (), "socket"); | ||||
108 | if (methods_socket == NULL || | ||||
109 | BIO_meth_set_write (methods_socket, socket_write) || | ||||
110 | BIO_meth_set_read (methods_socket, socket_read) || | ||||
111 | BIO_meth_set_puts (methods_socket, socket_puts) || | ||||
112 | BIO_meth_set_gets (methods_socket, 0) || | ||||
113 | BIO_meth_set_ctrl (methods_socket, socket_ctrl) || | ||||
114 | BIO_meth_set_create (methods_socket, socket_new) || | ||||
115 | BIO_meth_set_destroy (methods_socket, socket_free)) | ||||
116 | return NULL; | ||||
117 | } | ||||
118 | return methods_socket; | ||||
119 | } | ||||
120 | #endif | ||||
101 | 121 | | |||
102 | BIO* BIO_new_socket(talk_base::AsyncSocket* socket) { | 122 | BIO* BIO_new_socket(talk_base::AsyncSocket* socket) { | ||
103 | BIO* ret = BIO_new(BIO_s_socket2()); | 123 | const BIO_METHOD *socket2 = BIO_s_socket2(); | ||
124 | if (socket2 == NULL) { | ||||
125 | return NULL; | ||||
126 | } | ||||
127 | BIO* ret = BIO_new(socket2); | ||||
104 | if (ret == NULL) { | 128 | if (ret == NULL) { | ||
105 | return NULL; | 129 | return NULL; | ||
106 | } | 130 | } | ||
107 | ret->ptr = socket; | 131 | BIO_set_data(ret, socket); | ||
108 | return ret; | 132 | return ret; | ||
109 | } | 133 | } | ||
110 | 134 | | |||
135 | #if OPENSSL_VERSION_NUMBER < 0x10100000L | ||||
111 | static int socket_new(BIO* b) { | 136 | static int socket_new(BIO* b) { | ||
112 | b->shutdown = 0; | 137 | b->shutdown = 0; | ||
113 | b->init = 1; | 138 | b->init = 1; | ||
114 | b->num = 0; // 1 means socket closed | 139 | b->num = 0; // 1 means socket closed | ||
115 | b->ptr = 0; | 140 | b->ptr = 0; | ||
116 | return 1; | 141 | return 1; | ||
117 | } | 142 | } | ||
143 | #else | ||||
144 | static int socket_new(BIO* b) { | ||||
145 | BIO_set_shutdown(b, 0); | ||||
146 | BIO_set_init(b, 1); | ||||
147 | BIO_set_data(b, 0); | ||||
148 | return 1; | ||||
149 | } | ||||
150 | #endif | ||||
118 | 151 | | |||
119 | static int socket_free(BIO* b) { | 152 | static int socket_free(BIO* b) { | ||
120 | if (b == NULL) | 153 | if (b == NULL) | ||
121 | return 0; | 154 | return 0; | ||
122 | return 1; | 155 | return 1; | ||
123 | } | 156 | } | ||
124 | 157 | | |||
125 | static int socket_read(BIO* b, char* out, int outl) { | 158 | static int socket_read(BIO* b, char* out, int outl) { | ||
126 | if (!out) | 159 | if (!out) | ||
127 | return -1; | 160 | return -1; | ||
128 | talk_base::AsyncSocket* socket = static_cast<talk_base::AsyncSocket*>(b->ptr); | 161 | talk_base::AsyncSocket* socket = static_cast<talk_base::AsyncSocket*>(BIO_get_data(b)); | ||
129 | BIO_clear_retry_flags(b); | 162 | BIO_clear_retry_flags(b); | ||
130 | int result = socket->Recv(out, outl); | 163 | int result = socket->Recv(out, outl); | ||
131 | if (result > 0) { | 164 | if (result > 0) { | ||
132 | return result; | 165 | return result; | ||
133 | } else if (result == 0) { | | |||
134 | b->num = 1; | | |||
135 | } else if (socket->IsBlocking()) { | 166 | } else if (socket->IsBlocking()) { | ||
136 | BIO_set_retry_read(b); | 167 | BIO_set_retry_read(b); | ||
137 | } | 168 | } | ||
138 | return -1; | 169 | return -1; | ||
139 | } | 170 | } | ||
140 | 171 | | |||
141 | static int socket_write(BIO* b, const char* in, int inl) { | 172 | static int socket_write(BIO* b, const char* in, int inl) { | ||
142 | if (!in) | 173 | if (!in) | ||
143 | return -1; | 174 | return -1; | ||
144 | talk_base::AsyncSocket* socket = static_cast<talk_base::AsyncSocket*>(b->ptr); | 175 | talk_base::AsyncSocket* socket = static_cast<talk_base::AsyncSocket*>(BIO_get_data(b)); | ||
145 | BIO_clear_retry_flags(b); | 176 | BIO_clear_retry_flags(b); | ||
146 | int result = socket->Send(in, inl); | 177 | int result = socket->Send(in, inl); | ||
147 | if (result > 0) { | 178 | if (result > 0) { | ||
148 | return result; | 179 | return result; | ||
149 | } else if (socket->IsBlocking()) { | 180 | } else if (socket->IsBlocking()) { | ||
150 | BIO_set_retry_write(b); | 181 | BIO_set_retry_write(b); | ||
151 | } | 182 | } | ||
152 | return -1; | 183 | return -1; | ||
153 | } | 184 | } | ||
154 | 185 | | |||
155 | static int socket_puts(BIO* b, const char* str) { | 186 | static int socket_puts(BIO* b, const char* str) { | ||
156 | return socket_write(b, str, strlen(str)); | 187 | return socket_write(b, str, strlen(str)); | ||
157 | } | 188 | } | ||
158 | 189 | | |||
159 | static long socket_ctrl(BIO* b, int cmd, long num, void* ptr) { | 190 | static long socket_ctrl(BIO* b, int cmd, long num, void* ptr) { | ||
160 | UNUSED(num); | 191 | UNUSED(num); | ||
161 | UNUSED(ptr); | 192 | UNUSED(ptr); | ||
162 | 193 | | |||
163 | switch (cmd) { | 194 | switch (cmd) { | ||
164 | case BIO_CTRL_RESET: | 195 | case BIO_CTRL_RESET: | ||
165 | return 0; | 196 | return 0; | ||
166 | case BIO_CTRL_EOF: | 197 | case BIO_CTRL_EOF: | ||
167 | return b->num; | | |||
168 | case BIO_CTRL_WPENDING: | 198 | case BIO_CTRL_WPENDING: | ||
169 | case BIO_CTRL_PENDING: | 199 | case BIO_CTRL_PENDING: | ||
170 | return 0; | 200 | return 0; | ||
171 | case BIO_CTRL_FLUSH: | 201 | case BIO_CTRL_FLUSH: | ||
172 | return 1; | 202 | return 1; | ||
173 | default: | 203 | default: | ||
174 | return 0; | 204 | return 0; | ||
175 | } | 205 | } | ||
▲ Show 20 Lines • Show All 515 Lines • ▼ Show 20 Line(s) | 720 | #endif | |||
691 | if (!meth) | 721 | if (!meth) | ||
692 | break; | 722 | break; | ||
693 | 723 | | |||
694 | void* ext_str = NULL; | 724 | void* ext_str = NULL; | ||
695 | 725 | | |||
696 | // We assign this to a local variable, instead of passing the address | 726 | // We assign this to a local variable, instead of passing the address | ||
697 | // directly to ASN1_item_d2i. | 727 | // directly to ASN1_item_d2i. | ||
698 | // See http://readlist.com/lists/openssl.org/openssl-users/0/4761.html. | 728 | // See http://readlist.com/lists/openssl.org/openssl-users/0/4761.html. | ||
699 | unsigned char* ext_value_data = extension->value->data; | 729 | ASN1_OCTET_STRING *extension_data = X509_EXTENSION_get_data(extension); | ||
730 | unsigned char* ext_value_data = extension_data->data; | ||||
731 | long length = extension_data->length; | ||||
700 | 732 | | |||
701 | #if OPENSSL_VERSION_NUMBER >= 0x0090800fL | 733 | #if OPENSSL_VERSION_NUMBER >= 0x0090800fL | ||
702 | const unsigned char **ext_value_data_ptr = | 734 | const unsigned char **ext_value_data_ptr = | ||
703 | (const_cast<const unsigned char **>(&ext_value_data)); | 735 | (const_cast<const unsigned char **>(&ext_value_data)); | ||
704 | #else | 736 | #else | ||
705 | unsigned char **ext_value_data_ptr = &ext_value_data; | 737 | unsigned char **ext_value_data_ptr = &ext_value_data; | ||
706 | #endif | 738 | #endif | ||
707 | 739 | | |||
708 | if (meth->it) { | 740 | if (meth->it) { | ||
709 | ext_str = ASN1_item_d2i(NULL, ext_value_data_ptr, | 741 | ext_str = ASN1_item_d2i(NULL, ext_value_data_ptr, | ||
710 | extension->value->length, | 742 | length, | ||
711 | ASN1_ITEM_ptr(meth->it)); | 743 | ASN1_ITEM_ptr(meth->it)); | ||
712 | } else { | 744 | } else { | ||
713 | ext_str = meth->d2i(NULL, ext_value_data_ptr, extension->value->length); | 745 | ext_str = meth->d2i(NULL, ext_value_data_ptr, length); | ||
714 | } | 746 | } | ||
715 | 747 | | |||
716 | STACK_OF(CONF_VALUE)* value = meth->i2v(meth, ext_str, NULL); | 748 | STACK_OF(CONF_VALUE)* value = meth->i2v(meth, ext_str, NULL); | ||
717 | for (int j = 0; j < sk_CONF_VALUE_num(value); ++j) { | 749 | for (int j = 0; j < sk_CONF_VALUE_num(value); ++j) { | ||
718 | CONF_VALUE* nval = sk_CONF_VALUE_value(value, j); | 750 | CONF_VALUE* nval = sk_CONF_VALUE_value(value, j); | ||
719 | // The value for nval can contain wildcards | 751 | // The value for nval can contain wildcards | ||
720 | if (!strcmp(nval->name, "DNS") && string_match(host, nval->value)) { | 752 | if (!strcmp(nval->name, "DNS") && string_match(host, nval->value)) { | ||
721 | ok = true; | 753 | ok = true; | ||
▲ Show 20 Lines • Show All 176 Lines • Show Last 20 Lines |