Use hx509_cms_{,un}wrap_ContentInfo

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@17116 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2006-04-20 19:37:32 +00:00
parent d1e9d70d7c
commit cb1f6e5345

View File

@@ -115,28 +115,22 @@ cms_verify_sd(struct cms_verify_sd_options *opt, int argc, char **argv)
opt->certificate_strings.strings[i], ret); opt->certificate_strings.strings[i], ret);
} }
co.data = p;
co.length = sz;
if (opt->content_info_flag) { if (opt->content_info_flag) {
ContentInfo ci; heim_octet_string uwco;
size_t size; heim_oid oid;
ret = decode_ContentInfo(p, sz, &ci, &size); ret = hx509_cms_unwrap_ContentInfo(&co, &oid, &uwco, NULL);
if (ret) if (ret)
errx(1, "decode_ContentInfo: %d", ret); errx(1, "hx509_cms_unwrap_ContentInfo: %d", ret);
if (heim_oid_cmp(&ci.contentType, oid_id_pkcs7_signedData()) != 0) if (heim_oid_cmp(&oid, oid_id_pkcs7_signedData()) != 0)
errx(1, "Content is not SignedData"); errx(1, "Content is not SignedData");
free_oid(&oid);
if (ci.content == NULL) co = uwco;
errx(1, "ContentInfo missing content");
ret = copy_octet_string(ci.content, &co);
if (ret)
errx(1, "copy_octet_string: %d", ret);
free_ContentInfo(&ci);
} else {
co.data = p;
co.length = sz;
} }
hx509_verify_attach_anchors(ctx, anchors); hx509_verify_attach_anchors(ctx, anchors);
@@ -237,26 +231,14 @@ cms_create_sd(struct cms_create_sd_options *opt, int argc, char **argv)
hx509_lock_free(lock); hx509_lock_free(lock);
if (opt->content_info_flag) { if (opt->content_info_flag) {
ContentInfo ci; heim_octet_string wo;
size_t size;
ret = hx509_cms_wrap_ContentInfo(oid_id_pkcs7_signedData(), ret = hx509_cms_wrap_ContentInfo(oid_id_pkcs7_signedData(), &o, &wo);
&o,
&ci);
if (ret) if (ret)
errx(1, "hx509_cms_wrap_ContentInfo: %d", ret); errx(1, "hx509_cms_wrap_ContentInfo: %d", ret);
free_octet_string(&o); free_octet_string(&o);
o = wo;
ASN1_MALLOC_ENCODE(ContentInfo, o.data, o.length, &ci,
&size, ret);
if (ret)
errx(1, "encode ContentInfo");
if (o.length != size)
_hx509_abort("internal ASN.1 encoder error");
free_ContentInfo(&ci);
} }
ret = _hx509_write_file(argv[1], o.data, o.length); ret = _hx509_write_file(argv[1], o.data, o.length);
@@ -284,28 +266,22 @@ cms_unenvelope(struct cms_unenvelope_options *opt, int argc, char **argv)
if (ret) if (ret)
err(1, "map_file: %s: %d", argv[0], ret); err(1, "map_file: %s: %d", argv[0], ret);
co.data = p;
co.length = sz;
if (opt->content_info_flag) { if (opt->content_info_flag) {
ContentInfo ci; heim_octet_string uwco;
size_t size; heim_oid oid;
ret = decode_ContentInfo(p, sz, &ci, &size); ret = hx509_cms_unwrap_ContentInfo(&co, &oid, &uwco, NULL);
if (ret) if (ret)
errx(1, "decode_ContentInfo: %d", ret); errx(1, "hx509_cms_unwrap_ContentInfo: %d", ret);
if (heim_oid_cmp(&ci.contentType, oid_id_pkcs7_envelopedData()) != 0) if (heim_oid_cmp(&oid, oid_id_pkcs7_envelopedData()) != 0)
errx(1, "Content is not SignedData"); errx(1, "Content is not SignedData");
free_oid(&oid);
if (ci.content == NULL) co = uwco;
errx(1, "ContentInfo missing content");
ret = copy_octet_string(ci.content, &co);
if (ret)
errx(1, "copy_octet_string: %d", ret);
free_ContentInfo(&ci);
} else {
co.data = p;
co.length = sz;
} }
ret = hx509_certs_init(context, "MEMORY:cert-store", 0, NULL, &certs); ret = hx509_certs_init(context, "MEMORY:cert-store", 0, NULL, &certs);
@@ -382,26 +358,14 @@ cms_create_enveloped(struct cms_envelope_options *opt, int argc, char **argv)
_hx509_unmap_file(p, sz); _hx509_unmap_file(p, sz);
if (opt->content_info_flag) { if (opt->content_info_flag) {
ContentInfo ci; heim_octet_string wo;
size_t size;
ret = hx509_cms_wrap_ContentInfo(oid_id_pkcs7_envelopedData(), ret = hx509_cms_wrap_ContentInfo(oid_id_pkcs7_envelopedData(), &o, &wo);
&o,
&ci);
if (ret) if (ret)
errx(1, "hx509_cms_wrap_ContentInfo: %d", ret); errx(1, "hx509_cms_wrap_ContentInfo: %d", ret);
free_octet_string(&o); free_octet_string(&o);
o = wo;
ASN1_MALLOC_ENCODE(ContentInfo, o.data, o.length, &ci,
&size, ret);
if (ret)
errx(1, "encode ContentInfo");
if (o.length != size)
_hx509_abort("internal ASN.1 encoder error");
free_ContentInfo(&ci);
} }
hx509_lock_free(lock); hx509_lock_free(lock);