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
[])
124 CORBA::ORB_init( argc
, argv
);
126 if (parse_args (argc
, argv
) != 0)
128 else if(which
< 1 || 2 < which
)
131 CORBA::Object_var obj
=
132 orb
->string_to_object( ior
);
135 CORBA::Any protection
;
136 Security::EstablishTrust establish_trust
;
138 CORBA::PolicyList
policy_list (2);
142 qop
= Security::SecQOPNoProtection
;
143 //qop = Security::SecQOPIntegrity;
145 establish_trust
.trust_in_client
= 0;
146 establish_trust
.trust_in_target
= 1;
150 qop
= Security::SecQOPIntegrityAndConfidentiality
;
152 establish_trust
.trust_in_client
= 0;
153 establish_trust
.trust_in_target
= 1;
157 trust
<<= establish_trust
;
159 CORBA::Policy_var policy
=
160 orb
->create_policy (Security::SecQOPPolicy
, protection
);
162 CORBA::Policy_var policy2
=
163 orb
->create_policy (Security::SecEstablishTrustPolicy
, trust
);
165 policy_list
.length (1);
166 policy_list
[0] = CORBA::Policy::_duplicate (policy
.in ());
167 policy_list
.length (2);
168 policy_list
[1] = CORBA::Policy::_duplicate (policy2
.in ());
170 CORBA::Object_var object
=
171 obj
->_set_policy_overrides (policy_list
,
172 CORBA::SET_OVERRIDE
);
174 Messenger_var messenger
=
175 Messenger::_narrow( object
.in() );
177 CORBA::String_var message
=
178 CORBA::string_dup( "Implementing security policy now!" );
180 messenger
->send_message( "Chief of Security",
184 catch(const CORBA::Exception
& ex
) {
185 ex
._tao_print_exception("Client: main block");