~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/asn1/test/testSSLspecs.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%%
 
4
%% Copyright Ericsson AB 2004-2010. All Rights Reserved.
 
5
%%
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%%
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%%
 
17
%% %CopyrightEnd%
 
18
%%
 
19
%%
 
20
 
 
21
-module(testSSLspecs).
 
22
 
 
23
-export([compile/3,run/1,compile_inline/2,run_inline/1]).
 
24
 
 
25
-include_lib("test_server/include/test_server.hrl").
 
26
 
 
27
 
 
28
compile(Config,Rules,Options) ->
 
29
 
 
30
    ?line DataDir = ?config(data_dir,Config),
 
31
    ?line OutDir = ?config(priv_dir,Config),
 
32
    ?line true = code:add_patha(?config(priv_dir,Config)),
 
33
 
 
34
    ?line ok = asn1ct:compile(DataDir ++ 
 
35
                              "SSL-PKIX",[Rules,{outdir,OutDir},{i,DataDir},
 
36
                                          {i,OutDir}]++Options),
 
37
    ?line ok = asn1ct:compile(DataDir ++ "PKIXAttributeCertificate",
 
38
                              [Rules,{outdir,OutDir},{i,DataDir},
 
39
                               {i,OutDir}]++Options),
 
40
    %% test case for OTP-4792 optional open type
 
41
    ?line ok = asn1ct:compile(DataDir ++ "PKIX1Algorithms88",
 
42
                              [Rules,{outdir,OutDir},{i,DataDir},
 
43
                               {i,OutDir}]++Options),
 
44
    ?line ok = asn1ct:compile(DataDir ++ "PKIX1Explicit88",
 
45
                              [Rules,{outdir,OutDir},{i,DataDir},
 
46
                               {i,OutDir}]++Options),
 
47
    ?line ok = asn1ct:compile(DataDir ++ "PKIX1Implicit88",
 
48
                              [Rules,{outdir,OutDir},{i,DataDir},
 
49
                               {i,OutDir}]++Options),
 
50
    %% OTP-6698, OTP-6702
 
51
    ?line ok = remove_db_files(OutDir),
 
52
    ?line ok = asn1ct:compile(DataDir ++ "PKIX1Explicit93",
 
53
                              [Rules,{outdir,OutDir},{i,DataDir},
 
54
                               {i,OutDir}]++Options),
 
55
    ?line ok = asn1ct:compile(DataDir ++ "PKIX1Implicit93",
 
56
                              [Rules,{outdir,OutDir},{i,DataDir},
 
57
                               {i,OutDir}]++Options).
 
58
 
 
59
compile_inline(Config,Rule) ->
 
60
    ?line DataDir = ?config(data_dir,Config),
 
61
    ?line OutDir = ?config(priv_dir,Config),
 
62
    ?line true = code:add_patha(?config(priv_dir,Config)),
 
63
 
 
64
    case Rule of
 
65
        BER when BER==ber_bin;BER==ber_bin_v2 ->
 
66
            Options = [der,compact_bit_string,optimize,
 
67
                       asn1config,inline],
 
68
            ?line ok = remove_db_file_inline(OutDir),
 
69
            ?line ok = asn1ct:compile(DataDir ++ "OTP-PKIX.set.asn",
 
70
                                      [Rule,{outdir,OutDir},{i,DataDir},
 
71
                                       {i,OutDir}]++Options);
 
72
        _ ->
 
73
            ok
 
74
    end.
 
75
 
 
76
remove_db_files(Dir) ->
 
77
    ?line ok = remove_db_file(Dir ++ "PKIX1Explicit93.asn1db"),
 
78
    ?line ok = remove_db_file(Dir ++ "PKIX1Implicit93.asn1db").
 
79
remove_db_file(File) ->
 
80
    case file:delete(File) of
 
81
        ok ->
 
82
            ok;
 
83
        {error,enoent} ->
 
84
            ok;
 
85
        Err ->
 
86
            Err
 
87
    end.
 
88
 
 
89
remove_db_file_inline(Dir) ->
 
90
    ?line ok = remove_db_file(Dir ++ "OTP-PKIX.asn1db"),
 
91
    ?line ok = remove_db_file(Dir ++ "SSL-PKIX.asn1db"),
 
92
    ?line ok = remove_db_file(Dir ++ "PKIXAttributeCertificate.asn1db"),
 
93
    ?line ok = remove_db_file(Dir ++ "PKIX1Algorithms88.asn1db"),
 
94
    ?line ok = remove_db_file(Dir ++ "PKIX1Explicit88.asn1db"),
 
95
    ?line ok = remove_db_file(Dir ++ "PKIX1Implicit88.asn1db").
 
96
 
 
97
run(BER) when BER==ber_bin;BER==ber_bin_v2 ->
 
98
    run1(1);
 
99
run(_) ->
 
100
    ok.
 
101
 
 
102
run1(6) ->
 
103
    ?line f1(6),
 
104
    ?line f2(6),
 
105
%%    ?line transform3(ex(7)),
 
106
    ?line transform4(ex(7));
 
107
run1(N) ->
 
108
    ?line f1(N),
 
109
    ?line f2(N),
 
110
    run1(N+1).
 
111
 
 
112
 
 
113
f1(N) ->
 
114
    transform1(ex(N)).
 
115
 
 
116
f2(N) ->
 
117
    transform2(ex(N)).
 
118
 
 
119
 
 
120
transform1(ATAV) ->
 
121
    ?line {ok, ATAVEnc} = 'PKIX1Explicit88':encode('AttributeTypeAndValue',
 
122
ATAV),
 
123
    ?line {ok, _ATAVDec} = 'SSL-PKIX':decode('AttributeTypeAndValue',
 
124
                                      list_to_binary(ATAVEnc)).
 
125
 
 
126
transform2(ATAV) ->
 
127
    ?line {ok, ATAVEnc} = 'PKIX1Explicit88':encode('AttributeTypeAndValue',
 
128
ATAV),
 
129
    ?line {ok, _ATAVDec} = 'PKIX1Explicit88':decode('AttributeTypeAndValue',
 
130
                                             list_to_binary(ATAVEnc)).
 
131
 
 
132
 
 
133
transform4(ATAV) ->
 
134
    ?line {ok, ATAVEnc} = 'PKIX1Explicit88':encode('Attribute',
 
135
ATAV),
 
136
    ?line {ok, _ATAVDec} = 'PKIX1Explicit88':decode('Attribute',
 
137
                                             list_to_binary(ATAVEnc)).
 
138
 
 
139
 
 
140
ex(1) ->
 
141
    {'AttributeTypeAndValue',
 
142
     {2,5,4,3},
 
143
     <<19,5,111,116,112,67,65>>};
 
144
ex(2) ->
 
145
    {'AttributeTypeAndValue',
 
146
     {2,5,4,11},
 
147
     <<19,10,69,114,108,97,110,103,32,79,84,80>>};
 
148
ex(3) ->
 
149
    {'AttributeTypeAndValue',
 
150
     {2,5,4,10},
 
151
     <<19,11,69,114,105,99,115,115,111,110,32,65,66>>};
 
152
ex(4) ->
 
153
    {'AttributeTypeAndValue',
 
154
     {2,5,4,6},
 
155
     <<19,2,83,69>>};
 
156
ex(5) ->
 
157
    {'AttributeTypeAndValue',
 
158
     {2,5,4,7},
 
159
     <<19,9,83,116,111,99,107,104,111,108,109>>};
 
160
ex(6) ->
 
161
    {'AttributeTypeAndValue',
 
162
     {1,2,840,113549,1,9,1},
 
163
     <<22,22,112,101,116,101,114,64,101,114,105,120,
 
164
      46,101,114,105,99,115,115,111,110,46,115,101>>};
 
165
ex(7) ->
 
166
    {'Attribute',
 
167
     {1,2,840,113549,1,9,1},
 
168
     [[19,5,111,116,112,67,65]]}.
 
169
 
 
170
run_inline(Rule) when Rule==ber_bin;Rule==ber_bin_v2 ->
 
171
    Cert = cert(),
 
172
    ?line {ok,{'CertificatePKIX1Explicit88',{Type,UnDec},_,_}} = 'OTP-PKIX':decode_TBSCert_exclusive(Cert),
 
173
    ?line {ok,_} = 'OTP-PKIX':decode_part(Type,UnDec),
 
174
    ok;
 
175
run_inline(_) ->
 
176
    ok.
 
177
 
 
178
cert() ->
 
179
    <<48,130,3,200,48,130,3,49,160,3,2,1,2,2,1,1,48,13,6,9,42,134,72,134,247,13,1,1,5,5,0,48,129,134,49,17,48,15,6,3,85,4,3,19,8,101,114,108,97,110,103,67,65,49,19,48,17,6,3,85,4,11,19,10,69,114,108,97,110,103,32,79,84,80,49,20,48,18,6,3,85,4,10,19,11,69,114,105,99,115,115,111,110,32,65,66,49,18,48,16,6,3,85,4,7,19,9,83,116,111,99,107,104,111,108,109,49,11,48,9,6,3,85,4,6,19,2,83,69,49,37,48,35,6,9,42,134,72,134,247,13,1,9,1,22,22,112,101,116,101,114,64,101,114,105,120,46,101,114,105,99,115,115,111,110,46,115,101,48,30,23,13,48,55,48,53,48,57,49,50,51,52,48,57,90,23,13,49,55,48,51,49,55,49,50,51,52,48,57,90,48,129,131,49,14,48,12,6,3,85,4,3,19,5,111,116,112,67,65,49,19,48,17,6,3,85,4,11,19,10,69,114,108,97,110,103,32,79,84,80,49,20,48,18,6,3,85,4,10,19,11,69,114,105,99,115,115,111,110,32,65,66,49,11,48,9,6,3,85,4,6,19,2,83,69,49,18,48,16,6,3,85,4,7,19,9,83,116,111,99,107,104,111,108,109,49,37,48,35,6,9,42,134,72,134,247,13,1,9,1,22,22,112,101,116,101,114,64,101,114,105,120,46,101,114,105,99,115,115,111,110,46,115,101,48,129,159,48,13,6,9,42,134,72,134,247,13,1,1,1,5,0,3,129,141,0,48,129,137,2,129,129,0,157,223,214,78,61,218,253,253,143,253,54,171,133,60,170,135,118,35,37,238,208,160,209,6,115,228,99,139,202,32,226,243,181,251,216,20,154,56,18,225,158,17,46,210,88,80,0,60,121,125,159,116,98,206,192,243,95,213,5,117,140,217,211,69,105,70,208,53,132,33,120,233,97,86,136,39,245,36,220,204,187,171,125,193,169,250,123,3,63,220,240,216,136,151,176,255,7,53,55,204,234,104,24,222,232,46,29,88,7,239,183,95,210,202,244,125,106,169,225,181,128,13,22,216,15,150,203,147,2,3,1,0,1,163,130,1,69,48,130,1,65,48,15,6,3,85,29,19,1,1,255,4,5,48,3,1,1,255,48,11,6,3,85,29,15,4,4,3,2,1,6,48,29,6,3,85,29,14,4,22,4,20,59,42,225,69,198,245,160,224,205,23,100,154,109,139,92,188,255,177,162,7,48,129,187,6,3,85,29,35,4,129,179,48,129,176,128,20,138,222,66,214,242,39,254,232,217,84,224,143,206,167,0,167,118,166,219,135,161,129,140,164,129,137,48,129,134,49,17,48,15,6,3,85,4,3,19,8,101,114,108,97,110,103,67,65,49,19,48,17,6,3,85,4,11,19,10,69,114,108,97,110,103,32,79,84,80,49,20,48,18,6,3,85,4,10,19,11,69,114,105,99,115,115,111,110,32,65,66,49,18,48,16,6,3,85,4,7,19,9,83,116,111,99,107,104,111,108,109,49,11,48,9,6,3,85,4,6,19,2,83,69,49,37,48,35,6,9,42,134,72,134,247,13,1,9,1,22,22,112,101,116,101,114,64,101,114,105,120,46,101,114,105,99,115,115,111,110,46,115,101,130,9,0,217,241,90,207,3,129,188,250,48,33,6,3,85,29,17,4,26,48,24,129,22,112,101,116,101,114,64,101,114,105,120,46,101,114,105,99,115,115,111,110,46,115,101,48,33,6,3,85,29,18,4,26,48,24,129,22,112,101,116,101,114,64,101,114,105,120,46,101,114,105,99,115,115,111,110,46,115,101,48,13,6,9,42,134,72,134,247,13,1,1,5,5,0,3,129,129,0,0,193,166,44,175,85,39,236,34,138,64,208,1,244,50,147,73,0,236,172,244,6,127,14,70,113,79,176,212,170,65,159,232,153,234,253,158,17,92,249,196,102,83,116,186,67,168,95,132,65,228,190,78,11,64,75,215,73,156,223,193,46,166,11,227,106,39,133,232,175,223,75,14,232,178,210,122,70,245,18,164,65,151,44,129,3,10,20,92,251,69,230,208,30,203,65,238,140,95,48,130,202,173,28,84,253,42,18,56,47,248,152,156,171,214,37,41,155,205,230,251,98,118,164,239,246,216,66>>.