3 #include "ace/Get_Opt.h"
5 #include "MessengerC.h"
6 #include "orbsvcs/SecurityC.h"
11 // Example of a client that downgrades
12 // from message protection to no message
13 // protection and upgrades from no
14 // peer authentication to authentication
15 // of targets, i.e., authentication of
18 // The server's service configuration file
19 // for this example is
22 // dynamic SSLIOP_Factory Service_Object *
23 // TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory()
25 // -SSLAuthenticate SERVER_AND_CLIENT
26 // -SSLPrivateKey PEM:server_key.pem
27 // -SSLCertificate PEM:server_cert.pem"
29 // static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory"
31 // The clients service configuration file
32 // for this example is:
35 // dynamic SSLIOP_Factory Service_Object *
36 // TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory()
37 // "-SSLAuthenticate NONE
38 // -SSLPrivateKey PEM:client_key.pem
39 // -SSLCertificate PEM:client_cert.pem"
41 // static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory"
46 // Example of client upgrading from
47 // no message protection and no
48 // no authentication to message
49 // protection and authentication
50 // of targets, i.e., authentication
53 // The server's service configuration file for this example is
56 // dynamic SSLIOP_Factory Service_Object *
57 // TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory()
58 // "-SSLAuthenticate SERVER_AND_CLIENT
59 // -SSLPrivateKey PEM:serverkey.pem
60 // -SSLCertificate PEM:servercert.pem"
62 // static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory"
64 // The client's service configuration file
65 // for this example is:
68 // dynamic SSLIOP_Factory Service_Object *
69 // TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory()
71 // -SSLAuthenticate NONE
72 // -SSLPrivateKey PEM:clientkey.pem
73 // -SSLCertificate PEM:clientcert.pem"
75 // static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory"
78 const ACE_TCHAR
*ior
= ACE_TEXT("file://Messenger.ior");
83 parse_args (int argc
, ACE_TCHAR
*argv
[])
85 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("e:k:"));
88 while ((c
= get_opts ()) != -1)
92 ior
= get_opts
.opt_arg ();
95 which
= ACE_OS::atoi(get_opts
.optarg
);
96 if(which
< 1 || 2 < which
)
97 ACE_ERROR_RETURN ((LM_ERROR
,
107 ACE_ERROR_RETURN ((LM_ERROR
,
115 // Indicates successful parsing of the command line
120 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
125 CORBA::ORB_init( argc
, argv
);
127 if (parse_args (argc
, argv
) != 0)
129 else if(which
< 1 || 2 < which
)
132 CORBA::Object_var obj
=
133 orb
->string_to_object( ior
);
136 CORBA::Any protection
;
137 Security::EstablishTrust establish_trust
;
139 CORBA::PolicyList
policy_list (2);
143 qop
= Security::SecQOPNoProtection
;
144 //qop = Security::SecQOPIntegrity;
146 establish_trust
.trust_in_client
= 0;
147 establish_trust
.trust_in_target
= 1;
151 qop
= Security::SecQOPIntegrityAndConfidentiality
;
153 establish_trust
.trust_in_client
= 0;
154 establish_trust
.trust_in_target
= 1;
158 trust
<<= establish_trust
;
160 CORBA::Policy_var policy
=
161 orb
->create_policy (Security::SecQOPPolicy
, protection
);
163 CORBA::Policy_var policy2
=
164 orb
->create_policy (Security::SecEstablishTrustPolicy
, trust
);
166 policy_list
.length (1);
167 policy_list
[0] = CORBA::Policy::_duplicate (policy
.in ());
168 policy_list
.length (2);
169 policy_list
[1] = CORBA::Policy::_duplicate (policy2
.in ());
171 CORBA::Object_var object
=
172 obj
->_set_policy_overrides (policy_list
,
173 CORBA::SET_OVERRIDE
);
175 Messenger_var messenger
=
176 Messenger::_narrow( object
.in() );
178 CORBA::String_var message
=
179 CORBA::string_dup( "Implementing security policy now!" );
181 messenger
->send_message( "Chief of Security",
185 catch(const CORBA::Exception
& ex
) {
186 ex
._tao_print_exception("Client: main block");