static int cms_copy_content(BIO *out, BIO *in, unsigned int flags) { unsigned char buf[4096]; int r = 0, i; BIO *tmpout = NULL; if (out == NULL) tmpout = BIO_new(BIO_s_null()); else if (flags & CMS_TEXT) { tmpout = BIO_new(BIO_s_mem()); BIO_set_mem_eof_return(tmpout, 0); } else tmpout = out; if(!tmpout) { CMSerr(CMS_F_CMS_COPY_CONTENT,ERR_R_MALLOC_FAILURE); goto err; } /* Read all content through chain to process digest, decrypt etc */ for (;;) { i=BIO_read(in,buf,sizeof(buf)); if (i <= 0) { if (BIO_method_type(in) == BIO_TYPE_CIPHER) { if (!BIO_get_cipher_status(in)) goto err; } if (i < 0) goto err; break; } if (tmpout && (BIO_write(tmpout, buf, i) != i)) goto err; } if(flags & CMS_TEXT) { if(!SMIME_text(tmpout, out)) { CMSerr(CMS_F_CMS_COPY_CONTENT,CMS_R_SMIME_TEXT_ERROR); goto err; } } r = 1; err: if (tmpout && (tmpout != out)) BIO_free(tmpout); return r; }
void BIO_ssl_shutdown(BIO *b) { BIO_SSL *bdata; for (; b != NULL; b = BIO_next(b)) { if (BIO_method_type(b) != BIO_TYPE_SSL) continue; bdata = BIO_get_data(b); if (bdata != NULL && bdata->ssl != NULL) SSL_shutdown(bdata->ssl); } }
/* mem */ static LUA_FUNCTION(openssl_bio_get_mem) { BIO* bio = CHECK_OBJECT(1, BIO, "openssl.bio"); if (BIO_method_type(bio) == BIO_TYPE_MEM) { BUF_MEM* mem; BIO_get_mem_ptr(bio, &mem); lua_pushlstring(L, mem->data, mem->length); return 1; } luaL_error(L, "#1 BIO must be memory type"); return 0; }
BIO *findBufferedBio(BIO *front) { BIO *ret = front; while (ret) { if (BIO_method_type(ret) == BIO_TYPE_BUFFERED) return ret; ret = ret->next_bio; } return ret; }
void set_blocking(BIO *bio) { if(BIO_method_type(bio) == BIO_TYPE_CONNECT) { BIO_set_nbio(bio, 0); } if(BIO_method_type(bio) == BIO_TYPE_ACCEPT) { BIO_set_nbio_accept(bio, 0); } #ifdef DTLS_IMPLEMENTED if(BIO_method_type(bio) == BIO_TYPE_DGRAM) { int fd, flags; if((fd = BIO_get_fd(bio, NULL))) { flags = fcntl(fd, F_GETFL); flags &= ~O_NONBLOCK; fcntl(fd, F_SETFL, flags); } } #endif }
static LUA_FUNCTION(openssl_bio_fd) { BIO* bio = CHECK_OBJECT(1, BIO, "openssl.bio"); int typ = BIO_method_type(bio); if (typ & BIO_TYPE_FD) { int fd = -1; if (!lua_isnoneornil(L, 2)) { fd = lua_tointeger(L, 2); BIO_set_fd(bio, fd, BIO_NOCLOSE); } else fd = BIO_get_fd(bio, 0); lua_pushinteger(L, fd); } else luaL_error(L, "BIO type miss match"); return 1; }
int BIO_dgram_is_sctp(BIO *bio) { return (BIO_method_type(bio) == BIO_TYPE_DGRAM_SCTP); }