| 252 |
|
ssl_handshake(int fd, struct Client *client_p) |
| 253 |
|
{ |
| 254 |
|
X509 *cert = NULL; |
| 255 |
< |
int ret = SSL_accept(client_p->localClient->fd.ssl); |
| 256 |
< |
int err = SSL_get_error(client_p->localClient->fd.ssl, ret); |
| 255 |
> |
int ret = 0; |
| 256 |
|
|
| 257 |
< |
ilog(LOG_TYPE_IRCD, "SSL Error %d %s", err, ERR_error_string(err, NULL)); |
| 257 |
> |
if ((ret = SSL_accept(client_p->localClient->fd.ssl)) <= 0) |
| 258 |
> |
{ |
| 259 |
> |
switch (SSL_get_error(client_p->localClient->fd.ssl, ret)) |
| 260 |
> |
{ |
| 261 |
> |
case SSL_ERROR_WANT_WRITE: |
| 262 |
> |
comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE, |
| 263 |
> |
(PF *) ssl_handshake, client_p, 0); |
| 264 |
> |
return; |
| 265 |
> |
|
| 266 |
> |
case SSL_ERROR_WANT_READ: |
| 267 |
> |
comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ, |
| 268 |
> |
(PF *) ssl_handshake, client_p, 0); |
| 269 |
> |
return; |
| 270 |
> |
|
| 271 |
> |
default: |
| 272 |
> |
exit_client(client_p, client_p, "Error during SSL handshake"); |
| 273 |
> |
return; |
| 274 |
> |
} |
| 275 |
> |
} |
| 276 |
|
|
| 277 |
|
if ((cert = SSL_get_peer_certificate(client_p->localClient->fd.ssl))) |
| 278 |
|
{ |
| 279 |
|
int res = SSL_get_verify_result(client_p->localClient->fd.ssl); |
| 280 |
|
char buf[EVP_MAX_MD_SIZE * 2 + 1] = { '\0' }; |
| 281 |
< |
unsigned char md[EVP_MAX_MD_SIZE * 2 + 1] = { '\0' }; |
| 281 |
> |
unsigned char md[EVP_MAX_MD_SIZE] = { '\0' }; |
| 282 |
|
|
| 283 |
|
if (res == X509_V_OK || res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN || |
| 284 |
|
res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE || |
| 299 |
|
X509_free(cert); |
| 300 |
|
} |
| 301 |
|
|
| 285 |
– |
if (ret <= 0) |
| 286 |
– |
{ |
| 287 |
– |
switch (SSL_get_error(client_p->localClient->fd.ssl, ret)) |
| 288 |
– |
{ |
| 289 |
– |
case SSL_ERROR_WANT_WRITE: |
| 290 |
– |
comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE, |
| 291 |
– |
(PF *) ssl_handshake, client_p, 0); |
| 292 |
– |
return; |
| 293 |
– |
|
| 294 |
– |
case SSL_ERROR_WANT_READ: |
| 295 |
– |
comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ, |
| 296 |
– |
(PF *) ssl_handshake, client_p, 0); |
| 297 |
– |
return; |
| 298 |
– |
|
| 299 |
– |
default: |
| 300 |
– |
exit_client(client_p, client_p, "Error during SSL handshake"); |
| 301 |
– |
return; |
| 302 |
– |
} |
| 303 |
– |
} |
| 304 |
– |
|
| 302 |
|
start_auth(client_p); |
| 303 |
|
} |
| 304 |
|
#endif |
| 365 |
|
return; |
| 366 |
|
} |
| 367 |
|
|
| 368 |
+ |
AddFlag(new_client, FLAGS_SSL); |
| 369 |
|
SSL_set_fd(new_client->localClient->fd.ssl, fd); |
| 370 |
|
ssl_handshake(0, new_client); |
| 371 |
|
} |