/* read/write callback that sends the requests and reads the ocsp response */ void ocsp_callback(int fd, short event, void *arg) { struct iked_ocsp *ocsp = arg; struct iked_socket *sock = ocsp->ocsp_sock; OCSP_RESPONSE *resp = NULL; /* * Only call OCSP_sendreq_nbio() if should_read/write is * either not requested or read/write can be called. */ if ((!BIO_should_read(ocsp->ocsp_cbio) || (event & EV_READ)) && (!BIO_should_write(ocsp->ocsp_cbio) || (event & EV_WRITE)) && OCSP_sendreq_nbio(&resp, ocsp->ocsp_req_ctx) != -1 ) { ocsp_parse_response(ocsp, resp); return; } if (BIO_should_read(ocsp->ocsp_cbio)) event_set(&sock->sock_ev, sock->sock_fd, EV_READ, ocsp_callback, ocsp); else if (BIO_should_write(ocsp->ocsp_cbio)) event_set(&sock->sock_ev, sock->sock_fd, EV_WRITE, ocsp_callback, ocsp); event_add(&sock->sock_ev, NULL); }
/** * Receive OCSP response * * @v ocsp OCSP check * @v data Response data * @v len Length of response data * @ret rc Return status code */ int ocsp_response ( struct ocsp_check *ocsp, const void *data, size_t len ) { struct ocsp_response *response = &ocsp->response; struct asn1_cursor cursor; int rc; /* Duplicate data */ x509_put ( response->signer ); response->signer = NULL; free ( response->data ); response->data = malloc ( len ); if ( ! response->data ) return -ENOMEM; memcpy ( response->data, data, len ); cursor.data = response->data; cursor.len = len; /* Parse response */ if ( ( rc = ocsp_parse_response ( ocsp, &cursor ) ) != 0 ) return rc; return 0; }