diff options
author | lloyd <[email protected]> | 2006-06-03 06:59:11 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-06-03 06:59:11 +0000 |
commit | 720ef4cd84b5ac9ca127c44d891de11e61e4a584 (patch) | |
tree | f5b89afb6626d001345975d8e786904b4cee3e0c | |
parent | 4b2d4d38ce6e9b96e75b68026eece044d77edc7f (diff) |
Various hacks that get the old CMS code close to compiling under
mainline. Not completely done, getting some of it to work may
require changes to the ASN.1 code.
-rw-r--r-- | misc/cms/Makefile | 9 | ||||
-rw-r--r-- | misc/cms/cms_algo.cpp | 26 | ||||
-rw-r--r-- | misc/cms/cms_comp.cpp | 22 | ||||
-rw-r--r-- | misc/cms/cms_dalg.cpp | 23 | ||||
-rw-r--r-- | misc/cms/cms_dec.cpp | 25 | ||||
-rw-r--r-- | misc/cms/cms_ealg.cpp | 14 | ||||
-rw-r--r-- | misc/cms/cms_enc.cpp | 29 |
7 files changed, 85 insertions, 63 deletions
diff --git a/misc/cms/Makefile b/misc/cms/Makefile new file mode 100644 index 000000000..210ae4ae2 --- /dev/null +++ b/misc/cms/Makefile @@ -0,0 +1,9 @@ + +SRCS=cms_algo.cpp cms_comp.cpp cms_dalg.cpp cms_dec.cpp cms_ealg.cpp cms_enc.cpp +OBJS=cms_algo.o cms_comp.o cms_dalg.o cms_dec.o cms_ealg.o cms_enc.o + +libcms.a: $(OBJS) + ar libcms.a $(OBJS) + +%.o: %.cpp + g++ -I. $(shell botan-config --cflags) -c $? -o $@ diff --git a/misc/cms/cms_algo.cpp b/misc/cms/cms_algo.cpp index daed4af87..ec4d1e5ae 100644 --- a/misc/cms/cms_algo.cpp +++ b/misc/cms/cms_algo.cpp @@ -49,7 +49,7 @@ SecureVector<byte> do_rfc3217_wrap(const std::string& cipher, InitializationVector fixed("4ADDA22C79E82105"); Pipe pipe(get_cipher(cipher + "/CBC/NoPadding", kek, iv, ENCRYPTION), - new Flip_Bytes(iv.copy()), + new Flip_Bytes(iv.bits_of()), get_cipher(cipher + "/CBC/NoPadding", kek, fixed, ENCRYPTION)); pipe.start_msg(); pipe.write(input); @@ -71,7 +71,7 @@ SecureVector<byte> CMS_Encoder::wrap_key(const std::string& cipher, { SymmetricKey cek_parity = cek; cek_parity.set_odd_parity(); - return do_rfc3217_wrap(cipher, kek, cek_parity.copy()); + return do_rfc3217_wrap(cipher, kek, cek_parity.bits_of()); } else if(cipher == "RC2" || cipher == "CAST-128") { @@ -80,9 +80,9 @@ SecureVector<byte> CMS_Encoder::wrap_key(const std::string& cipher, SecureVector<byte> lcekpad; lcekpad.append((byte)cek.length()); - lcekpad.append(cek.copy()); + lcekpad.append(cek.bits_of()); while(lcekpad.size() % 8) - lcekpad.append(Global_RNG::random(Nonce)); + lcekpad.append(Global_RNG::random()); return do_rfc3217_wrap(cipher, kek, lcekpad); } else @@ -100,20 +100,20 @@ SecureVector<byte> CMS_Encoder::encode_params(const std::string& cipher, if(cipher == "RC2") { - encoder.start_sequence(); - DER::encode(encoder, RC2::EKB_code(8*key.length())); - DER::encode(encoder, iv.copy(), OCTET_STRING); - encoder.end_sequence(); + encoder.start_cons(SEQUENCE). + encode((u32bit)RC2::EKB_code(8*key.length())). + encode(iv.bits_of(), OCTET_STRING). + end_cons(); } else if(cipher == "CAST-128") { - encoder.start_sequence(); - DER::encode(encoder, iv.copy(), OCTET_STRING); - DER::encode(encoder, 8*key.length()); - encoder.end_sequence(); + encoder.start_cons(SEQUENCE). + encode(iv.bits_of(), OCTET_STRING). + encode(8*key.length()). + end_cons(); } else - DER::encode(encoder, iv.copy(), OCTET_STRING); + encoder.encode(iv.bits_of(), OCTET_STRING); return encoder.get_contents(); } diff --git a/misc/cms/cms_comp.cpp b/misc/cms/cms_comp.cpp index 8cf6ab292..75497ca8d 100644 --- a/misc/cms/cms_comp.cpp +++ b/misc/cms/cms_comp.cpp @@ -41,11 +41,12 @@ void CMS_Encoder::compress(const std::string& algo) SecureVector<byte> compressed = pipe.read_all(); DER_Encoder encoder; - encoder.start_sequence(); - DER::encode(encoder, 0); - DER::encode(encoder, AlgorithmIdentifier("Compression." + algo, false)); - encoder.add_raw_octets(make_econtent(compressed, type)); - encoder.end_sequence(); + encoder.start_cons(SEQUENCE). + encode((u32bit)0). + encode(AlgorithmIdentifier("Compression." + algo, + MemoryVector<byte>())). + raw_bytes(make_econtent(compressed, type)). + end_cons(); add_layer("CMS.CompressedData", encoder); } @@ -68,17 +69,20 @@ void CMS_Decoder::decompress(BER_Decoder& decoder) u32bit version; AlgorithmIdentifier comp_algo; - BER_Decoder comp_info = BER::get_subsequence(decoder); - BER::decode(comp_info, version); + BER_Decoder comp_info = decoder.start_cons(SEQUENCE); + + comp_info.decode(version); if(version != 0) throw Decoding_Error("CMS: Unknown version for CompressedData"); - BER::decode(comp_info, comp_algo); + + comp_info.decode(comp_algo); read_econtent(comp_info); - comp_info.verify_end(); + comp_info.end_cons(); Filter* decompressor = 0; info = comp_algo.oid.as_string(); + #if HAVE_ZLIB if(comp_algo.oid == OIDS::lookup("Compression.Zlib")) { diff --git a/misc/cms/cms_dalg.cpp b/misc/cms/cms_dalg.cpp index b1c65b4f7..e1bb0f83c 100644 --- a/misc/cms/cms_dalg.cpp +++ b/misc/cms/cms_dalg.cpp @@ -8,6 +8,7 @@ #include <botan/oids.h> #include <botan/lookup.h> #include <botan/look_pk.h> +#include <botan/bigint.h> #include <memory> namespace Botan { @@ -41,8 +42,8 @@ std::vector<X509_Certificate> get_cert(BER_Decoder& signer_info, X509_DN issuer; BigInt serial; BER_Decoder iands(id.value); - BER::decode(iands, issuer); - BER::decode(iands, serial); + iands.decode(issuer); + iands.decode(serial); found = X509_Store_Search::by_iands(store, issuer, BigInt::encode(serial)); @@ -115,19 +116,19 @@ SecureVector<byte> decode_attributes(BER_Decoder& ber, const OID& type, while(attributes.more_items()) { Attribute attr; - BER::decode(attributes, attr); + attributes.decode(attr); BER_Decoder attr_value(attr.parameters); if(attr.oid == OIDS::lookup("PKCS9.MessageDigest")) { got_digest = true; - BER::decode(attr_value, digest, OCTET_STRING); + attr_value.decode(digest, OCTET_STRING); } else if(attr.oid == OIDS::lookup("PKCS9.ContentType")) { got_content_type = true; OID inner_type; - BER::decode(attr_value, inner_type); + attr_value.decode(inner_type); if(inner_type != type) bad_attributes = true; } @@ -171,14 +172,16 @@ void CMS_Decoder::decode_layer() AlgorithmIdentifier hash_algo; SecureVector<byte> digest; - BER_Decoder hash_info = BER::get_subsequence(decoder); - BER::decode(hash_info, version); + BER_Decoder hash_info = decoder.start_cons(SEQUENCE); + + hash_info.decode(version); if(version != 0 && version != 2) throw Decoding_Error("CMS: Unknown version for DigestedData"); - BER::decode(hash_info, hash_algo); + + hash_info.decode(hash_algo); read_econtent(hash_info); - BER::decode(hash_info, digest, OCTET_STRING); - hash_info.verify_end(); + hash_info.decode(digest, OCTET_STRING); + hash_info.end_cons(); if(digest != hash_of(data, hash_algo, info)) status = BAD; diff --git a/misc/cms/cms_dec.cpp b/misc/cms/cms_dec.cpp index 799e20b97..63aab9bd9 100644 --- a/misc/cms/cms_dec.cpp +++ b/misc/cms/cms_dec.cpp @@ -5,6 +5,7 @@ #include <botan/cms_dec.h> #include <botan/ber_dec.h> +#include <botan/asn1_int.h> #include <botan/oids.h> #include <botan/pem.h> @@ -21,7 +22,7 @@ CMS_Decoder::CMS_Decoder(DataSource& in, const X509_Store& x509store, add_key(key); - if(BER::maybe_BER(in) && !PEM_Code::matches(in)) + if(ASN1::maybe_BER(in) && !PEM_Code::matches(in)) initial_read(in); else { @@ -35,11 +36,18 @@ CMS_Decoder::CMS_Decoder(DataSource& in, const X509_Store& x509store, *************************************************/ void CMS_Decoder::initial_read(DataSource& in) { + // FIXME... + + /* BER_Decoder decoder(in); - BER_Decoder content_info = BER::get_subsequence(decoder); - BER::decode(content_info, next_type); + BER_Decoder content_info = decoder.start_cons(SEQUENCE); + + content_info.decode(next_type); + + BER_Decoder content_type = BER::get_subsequence(content_info, ASN1_Tag(0)); data = content_type.get_remaining(); + */ decode_layer(); } @@ -74,7 +82,7 @@ std::string CMS_Decoder::get_data() const { if(layer_type() != DATA) throw Invalid_State("CMS: Cannot retrieve data from non-DATA layer"); - return std::string((const char*)data.ptr(), data.size()); + return std::string((const char*)data.begin(), data.size()); } /************************************************* @@ -104,11 +112,12 @@ std::string CMS_Decoder::layer_info() const *************************************************/ void CMS_Decoder::read_econtent(BER_Decoder& decoder) { - BER_Decoder econtent_info = BER::get_subsequence(decoder); - BER::decode(econtent_info, next_type); + BER_Decoder econtent_info = decoder.start_cons(SEQUENCE); + econtent_info.decode(next_type); - BER_Decoder econtent = BER::get_subsequence(econtent_info, ASN1_Tag(0)); - BER::decode(econtent, data, OCTET_STRING); + // FIXME + //BER_Decoder econtent = BER::get_subsequence(econtent_info, ASN1_Tag(0)); + //econtent.decode(data, OCTET_STRING); } } diff --git a/misc/cms/cms_ealg.cpp b/misc/cms/cms_ealg.cpp index b5e52a68f..d493124e7 100644 --- a/misc/cms/cms_ealg.cpp +++ b/misc/cms/cms_ealg.cpp @@ -29,17 +29,17 @@ std::string choose_algo(const std::string& user_algo, /************************************************* * Encode a SignerIdentifier/RecipientIdentifier * *************************************************/ -void encode_si(DER_Encoder& encoder, const X509_Certificate& cert, +void encode_si(DER_Encoder& der, const X509_Certificate& cert, bool use_skid_encoding = false) { - if(cert.has_SKID() && use_skid_encoding) - DER::encode(encoder, cert.subject_key_id(), OCTET_STRING, ASN1_Tag(0)); + if(cert.subject_key_id().size() && use_skid_encoding) + der.encode(cert.subject_key_id(), OCTET_STRING, ASN1_Tag(0)); else { - encoder.start_sequence(); - DER::encode(encoder, cert.issuer_dn()); - DER::encode(encoder, cert.serial_number_bn()); - encoder.end_sequence(); + der.start_cons(SEQUENCE). + encode(cert.issuer_dn()). + encode(BigInt(cert.serial_number())). + end_cons(); } } diff --git a/misc/cms/cms_enc.cpp b/misc/cms/cms_enc.cpp index 084e7da79..ea6ac4029 100644 --- a/misc/cms/cms_enc.cpp +++ b/misc/cms/cms_enc.cpp @@ -37,12 +37,12 @@ SecureVector<byte> CMS_Encoder::get_contents() { DER_Encoder encoder; - encoder.start_sequence(); - DER::encode(encoder, OIDS::lookup(type)); - encoder.start_explicit(ASN1_Tag(0)); - encoder.add_raw_octets(data); - encoder.end_explicit(ASN1_Tag(0)); - encoder.end_sequence(); + encoder.start_cons(SEQUENCE). + encode(OIDS::lookup(type)). + start_explicit(0). + raw_bytes(data). + end_explicit(). + end_cons(); data.clear(); @@ -72,16 +72,13 @@ std::string CMS_Encoder::PEM_contents() SecureVector<byte> CMS_Encoder::make_econtent(const SecureVector<byte>& data, const std::string& type) { - DER_Encoder encoder; - - encoder.start_sequence(); - DER::encode(encoder, OIDS::lookup(type)); - encoder.start_explicit(ASN1_Tag(0)); - DER::encode(encoder, data, OCTET_STRING); - encoder.end_explicit(ASN1_Tag(0)); - encoder.end_sequence(); - - return encoder.get_contents(); + return DER_Encoder().start_cons(SEQUENCE). + encode(OIDS::lookup(type)). + start_explicit(0). + encode(data, OCTET_STRING). + end_explicit(). + end_cons(). + get_contents(); } } |