From 10c73156d654bc1ada7afbc3cd7f81b2091057f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 4 Feb 2013 12:10:50 +0100 Subject: asn1_SUITE: Mend broken test_modified_x420/1 The test_modified_x420/1 test case had several problems that prevented it to detect the bugs it was supposed to find: 1) There was a 'catch' at the top-level so that it could never fail. 2) There was a call to the now non-existing ssl_base64 module. 3) It did not test all options for the BER backend. While at it, also clean way the remaining ?line macros and some out-commented code. --- lib/asn1/test/asn1_SUITE.erl | 7 +++++-- lib/asn1/test/test_modified_x420.erl | 22 ++++++++-------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/asn1/test/asn1_SUITE.erl b/lib/asn1/test/asn1_SUITE.erl index 9a6201455d..0654d1c918 100644 --- a/lib/asn1/test/asn1_SUITE.erl +++ b/lib/asn1/test/asn1_SUITE.erl @@ -1054,11 +1054,14 @@ testDoubleEllipses(Config, Rule, Opts) -> testDoubleEllipses:main(Rule). test_modified_x420(Config) -> + test(Config, fun test_modified_x420/3, + [ber,ber_bin,ber_bin_v2,{ber_bin_v2,[nif]}]). +test_modified_x420(Config, Rule, Opts) -> Files = [filename:join(modified_x420, F) || F <- ["PKCS7", "InformationFramework", "AuthenticationFramework"]], - asn1_test_lib:compile_all(Files, Config, [der]), - test_modified_x420:test_io(Config). + asn1_test_lib:compile_all(Files, Config, [Rule,der|Opts]), + test_modified_x420:test(Config). testX420() -> diff --git a/lib/asn1/test/test_modified_x420.erl b/lib/asn1/test/test_modified_x420.erl index 2e9dfeee87..ae9d1989fb 100644 --- a/lib/asn1/test/test_modified_x420.erl +++ b/lib/asn1/test/test_modified_x420.erl @@ -18,27 +18,21 @@ %% %% -module(test_modified_x420). - -%-compile(export_all). --export([test_io/1]). +-export([test/1]). -include_lib("test_server/include/test_server.hrl"). -test_io(Config) -> - io:format("~p~n~n", [catch test(Config)]). - test(Config) -> - ?line DataDir = ?config(data_dir,Config), -% ?line OutDir = ?config(priv_dir,Config), + DataDir = ?config(data_dir,Config), - ?line Der = read_pem(filename:join([DataDir,modified_x420,"p7_signed_data.pem"])), - ?line {ok, {_,_,SignedData}} = 'PKCS7':decode('ContentInfo', Der), - ?line {ok,_} = 'PKCS7':decode('SignedData', SignedData). + Der = read_pem(filename:join([DataDir,modified_x420,"p7_signed_data.pem"])), + {ok,{_,_,SignedData}} = asn1_wrapper:decode('PKCS7', 'ContentInfo', Der), + {ok,_} = asn1_wrapper:decode('PKCS7', 'SignedData', SignedData). read_pem(File) -> - ?line {ok, Bin} = file:read_file(File), - ?line ssl_base64:join_decode(lists:flatten(extract_base64(Bin))). - + {ok,Bin} = file:read_file(File), + Der = base64:mime_decode(lists:flatten(extract_base64(Bin))), + binary_to_list(Der). extract_base64(Binary) -> -- cgit v1.2.3 From 0fd671609f7b31a9313d1575434e7273f3f2cd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 4 Feb 2013 11:06:43 +0100 Subject: asn1_erl_nif: Correct broken length encoding The ber_bin_v2 backend calls a NIF function to decode all tags and lengths. Even open types that should not be decoded will also be decoded, which makes it necessary to later re-encode the data using a NIF function. The NIF function incorrectly encoded lengths. --- lib/asn1/c_src/asn1_erl_nif.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/asn1/c_src/asn1_erl_nif.c b/lib/asn1/c_src/asn1_erl_nif.c index dbff14f9b3..26803a25a4 100644 --- a/lib/asn1/c_src/asn1_erl_nif.c +++ b/lib/asn1/c_src/asn1_erl_nif.c @@ -1134,8 +1134,8 @@ int ber_encode_length(size_t size, mem_chunk_t **curr, unsigned int *count) { (*curr)->curr -= 1; (*count)++; } else { - int chunks = size / 256 + 1; - if (ber_check_memory(curr, chunks + 1)) + int chunks = 0; + if (ber_check_memory(curr, 8)) return ASN1_ERROR; while (size > 0) @@ -1144,6 +1144,7 @@ int ber_encode_length(size_t size, mem_chunk_t **curr, unsigned int *count) { size >>= 8; (*curr)->curr -= 1; (*count)++; + chunks++; } *(*curr)->curr = chunks | 0x80; -- cgit v1.2.3