/[resiprocate]/main/resip/stack/test/testIdentity.cxx
ViewVC logotype

Diff of /main/resip/stack/test/testIdentity.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5295 by jason, Mon Aug 22 00:30:05 2005 UTC revision 5739 by fluffy, Tue Dec 13 04:23:06 2005 UTC
# Line 6  Line 6 
6  #include "rutil/Logger.hxx"  #include "rutil/Logger.hxx"
7  #include "resip/stack/Security.hxx"  #include "resip/stack/Security.hxx"
8    
9    #include "TestSupport.hxx"
10    
11    
12  using namespace resip;  using namespace resip;
13  using namespace std;  using namespace std;
# Line 28  Line 30 
30     {     {
31        security = 0;        security = 0;
32        ErrLog( << "Got a exception setting up Security" );        ErrLog( << "Got a exception setting up Security" );
33          return -1;
34     }     }
35    
36     try     try
# Line 38  Line 41 
41     catch( ... )     catch( ... )
42     {     {
43        ErrLog( << "Got a exception loading certificates" );        ErrLog( << "Got a exception loading certificates" );
44          return -1;
45     }     }
46    
47     assert( security );     assert( security );
48    
49     Data in("sip:alice@atlanta.example.com"  #if 0
50             ":a84b4c76e66710"     Data in1("sip:alice@atlanta.example.com"
51             ":314159 INVITE"              "|sip:bob@biloxi.example.org"
52             ":Thu, 21 Feb 2002 13:02:03 GMT"              "|a84b4c76e66710"
53             ":sip:alice@pc33.atlanta.example.com"              "|314159 INVITE"
54             ":v=0\r\n"              //":314159 INVITE"
55                "|Thu, 21 Feb 2002 13:02:03 GMT"
56                "|sip:alice@pc33.atlanta.example.com"
57                "|v=0\r\n"
58             "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"             "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"
59             "s=Session SDP\r\n"             "s=Session SDP\r\n"
60             "c=IN IP4 pc33.atlanta.example.com\r\n"             "c=IN IP4 pc33.atlanta.example.com\r\n"
# Line 55  Line 62 
62             "m=audio 49172 RTP/AVP 0\r\n"             "m=audio 49172 RTP/AVP 0\r\n"
63             "a=rtpmap:0 PCMU/8000\r\n");             "a=rtpmap:0 PCMU/8000\r\n");
64                
65     ofstream strm("identiy-in", std::ios_base::trunc);     Data in2("sip:bob@biloxi.example.org"
66                "|sip:alice@atlanta.example.com"
67                "|a84b4c76e66710"
68                "|231 BYE"
69                "|Thu, 21 Feb 2002 14:19:51 GMT"
70                "|"
71                "|"
72                //"|\r\n"
73          );
74    
75       Data& in=in1;
76      
77       ofstream strm("identity-in", std::ios_base::trunc);
78     strm.write( in.data(), in.size() );     strm.write( in.data(), in.size() );
79     strm.flush();     strm.flush();
80        
81     Data res = security->computeIdentity( Data("localhost"), in );     Data res = security->computeIdentity( Data("atlanta.example.com"), in );
82    
83     //ErrLog( << "input is encoded " << in.charEncoded()  );     ErrLog( << "input is encoded " << in.charEncoded()  );
84     //ErrLog( << "input is hex " << in.hex() );     ErrLog( << "input is hex " << in.hex() );
85     //ErrLog( << "input is  " << in );     ErrLog( << "input is  " << in );
86     //ErrLog( << "identity is " << res  );     ErrLog( << "identity is " << res  );
87    
88     bool c  = security->checkIdentity( Data("localhost"), in , res );     if (true)
89       {
90          bool c  = security->checkIdentity( Data("atlanta.example.com"), in , res );
91        
92     if ( !c )     if ( !c )
93     {     {
94        ErrLog( << "Identity check failed" << res  );        ErrLog( << "Identity check failed" << res  );
95             return -1;
96          }
97     }     }
98    #endif
99    
100       // start the second test
101         Data txt1 =
102            "INVITE sip:bob@biloxi.exmple.org SIP/2.0\r\n"
103            "Via: SIP/2.0/TLS pc33.atlanta.example.com;branch=z9hG4bKnashds8\r\n"
104            "To: Bob <sip:bob@biloxi.example.org>\r\n"
105            "From: Alice <sip:alice@atlanta.example.com>;tag=1928301774\r\n"
106            "Call-ID: a84b4c76e66710\r\n"
107            "CSeq: 314159 INVITE\r\n"
108            "Max-Forwards: 70\r\n"
109            "Date: Thu, 21 Feb 2002 13:02:03 GMT\r\n"
110            "Contact: <sip:alice@pc33.atlanta.example.com>\r\n"
111            "Content-Type: application/sdp\r\n"
112            "Content-Length: 147\r\n"
113            "\r\n"
114            "v=0\r\n"
115            "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"
116            "s=Session SDP\r\n"
117            "c=IN IP4 pc33.atlanta.example.com\r\n"
118            "t=0 0\r\n"
119            "m=audio 49172 RTP/AVP 0\r\n"
120            "a=rtpmap:0 PCMU/8000\r\n";
121        
122         Data txt2 =
123            "BYE sip:alice@pc33.atlanta.example.com SIP/2.0\r\n"
124            "Via: SIP/2.0/TLS 192.0.2.4;branch=z9hG4bKnashds10\r\n"
125            "Max-Forwards: 70\r\n"
126            "From: Bob <sip:bob@biloxi.example.org>;tag=a6c85cf\r\n"
127            "To: Alice <sip:alice@atlanta.example.com>;tag=1928301774\r\n"
128            "Date: Thu, 21 Feb 2002 14:19:51 GMT\r\n"
129            "Call-ID: a84b4c76e66710\r\n"
130            "CSeq: 231 BYE\r\n"
131            "Content-Length: 0\r\n"
132            "\r\n";
133        
134          auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt1));
135    
136          try
137          {
138             const Data& domain = msg->header(h_From).uri().host();
139             msg->header(h_Identity).value() = security->computeIdentity( domain,
140                                                                           msg->getCanonicalIdentityString());
141          }
142          catch (Security::Exception& e)
143          {
144             ErrLog (<< "Couldn't add identity header: " << e);
145             msg->remove(h_Identity);
146          }
147        
148          ErrLog( << "identity is " <<  msg->header(h_Identity).value() );
149  #endif // use_ssl  #endif // use_ssl
150    
151     return 0;     return 0;

Legend:
Removed from v.5295  
changed lines
  Added in v.5739

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27