Beispiel #1
0
/* CMS streaming support */
static int
cms_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
{
	ASN1_STREAM_ARG *sarg = exarg;
	CMS_ContentInfo *cms = NULL;

	if (pval)
		cms = (CMS_ContentInfo *)*pval;
	else
		return 1;

	switch (operation) {
	case ASN1_OP_STREAM_PRE:
		if (CMS_stream(&sarg->boundary, cms) <= 0)
			return 0;
	case ASN1_OP_DETACHED_PRE:
		sarg->ndef_bio = CMS_dataInit(cms, sarg->out);
		if (!sarg->ndef_bio)
			return 0;
		break;
	case ASN1_OP_STREAM_POST:
	case ASN1_OP_DETACHED_POST:
		if (CMS_dataFinal(cms, sarg->ndef_bio) <= 0)
			return 0;
		break;
	}
	return 1;
}
Beispiel #2
0
static int openssl_cms_datafinal(lua_State *L)
{
  CMS_ContentInfo *cms = CHECK_OBJECT(1, CMS_ContentInfo, "openssl.cms");
  BIO* bio = load_bio_object(L, 2);
  int ret = CMS_dataFinal(cms, bio);
  lua_pushboolean(L, ret);
  return 1;
}
Beispiel #3
0
/* Callback for int_smime_write_ASN1 */
static int cms_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
                           const ASN1_ITEM *it)
{
    CMS_ContentInfo *cms = (CMS_ContentInfo *)val;
    BIO *tmpbio, *cmsbio;
    int r = 0;

    if (!(flags & SMIME_DETACHED)) {
        SMIME_crlf_copy(data, out, flags);
        return 1;
    }

    /* Let CMS code prepend any needed BIOs */

    cmsbio = CMS_dataInit(cms, out);

    if (!cmsbio)
        return 0;

    /* Copy data across, passing through filter BIOs for processing */
    SMIME_crlf_copy(data, cmsbio, flags);

    /* Finalize structure */
    if (CMS_dataFinal(cms, cmsbio) <= 0)
        goto err;

    r = 1;

err:

    /* Now remove any digests prepended to the BIO */

    while (cmsbio != out) {
        tmpbio = BIO_pop(cmsbio);
        BIO_free(cmsbio);
        cmsbio = tmpbio;
    }

    return r;

}