| 281 | #endif |
| 282 | |
| 283 | bool polarssl_io::open(ACL_VSTREAM* s) |
| 284 | { |
| 285 | if (s == NULL) { |
| 286 | logger_error("s null"); |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | #ifdef HAS_POLARSSL |
| 291 | // ��ֹ�ظ����� open ���� |
| 292 | if (ssl_ != NULL) { |
| 293 | // �����ͬһ�������� true |
| 294 | if (stream_ == s) { |
| 295 | return true; |
| 296 | } else if (ACL_VSTREAM_SOCK(stream_) == ACL_VSTREAM_SOCK(s)) { |
| 297 | long long n = ++(*refers_); |
| 298 | logger_warn("used by multiple stream, refers=%lld", n); |
| 299 | return true; |
| 300 | } |
| 301 | |
| 302 | // ����ֹͬһ�� SSL IO �����ڲ�ͬ���������� |
| 303 | logger_error("open again, stream_ changed!"); |
| 304 | return false; |
| 305 | } |
| 306 | |
| 307 | stream_ = s; |
| 308 | ++(*refers_); |
| 309 | |
| 310 | ssl_ = acl_mycalloc(1, sizeof(ssl_context)); |
| 311 | |
| 312 | int ret; |
| 313 | |
| 314 | // ��ʼ�� SSL ���� |
| 315 | if ((ret = __ssl_init((ssl_context*) ssl_)) != 0) { |
| 316 | logger_error("failed, ssl_init error: -0x%04x\n", -ret); |
| 317 | acl_myfree(ssl_); |
| 318 | ssl_ = NULL; |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | // ��Ҫ���� SSL �����ǿͻ���ģʽ���Ƿ�����ģʽ |
| 323 | if (server_side_) { |
| 324 | __ssl_set_endpoint((ssl_context*) ssl_, SSL_IS_SERVER); |
| 325 | } else { |
| 326 | __ssl_set_endpoint((ssl_context*) ssl_, SSL_IS_CLIENT); |
| 327 | } |
| 328 | |
| 329 | // ��ʼ����������ɹ��� |
| 330 | |
| 331 | # ifdef HAS_HAVEGE |
| 332 | rnd_ = acl_mymalloc(sizeof(havege_state)); |
| 333 | __havege_init((havege_state*) rnd_); |
| 334 | |
| 335 | // ��������������� |
| 336 | __ssl_set_rng((ssl_context*) ssl_, __havege_random, rnd_); |
| 337 | # else |
| 338 | rnd_ = acl_mymalloc(sizeof(ctr_drbg_context)); |
| 339 | |
| 340 | char pers[50]; |
nothing calls this directly
no test coverage detected