3 #include "Messenger_i.h"
4 #include "ace/OS_NS_string.h"
7 Messenger_i::Messenger_i (
9 SSLIOP::Current_ptr ssliop_current
11 : orb_(CORBA::ORB::_duplicate(orb
)),
12 ssliop_current_(SSLIOP::Current::_duplicate(ssliop_current
))
16 Messenger_i::~Messenger_i (void)
20 CORBA::Boolean
Messenger_i::send_message (
21 const char * user_name
,
26 if (ssliop_current_
->no_context())
27 std::cout
<< "Message from: " << user_name
<< std::endl
;
29 std::cout
<< "SECURE message from: " << user_name
<< std::endl
;
31 std::cout
<< "Subject: " << subject
<< std::endl
;
32 std::cout
<< "Message: " << message
<< std::endl
;
33 std::cout
<< std::endl
;
38 void Messenger_i::shutdown (
39 const char * user_name
42 if ( ! (ssliop_current_
->no_context()) )
44 // requestor is authentic, go ahead and
45 // shut the server down. Report access
46 // ID of requestor prior to shutdown.
48 std::cout
<< "Shutdown command from: " << user_name
<< std::endl
;
49 std::cout
<< "Status: User authenticated." << std::endl
;
50 std::cout
<< "Action: Sever shutdown in progress..." << std::endl
;
51 std::cout
<< std::endl
;
54 char name_buf
[BUFSIZ
];
57 // Populate an attribute type list
58 // to request the initiating principal's
61 Security::AttributeTypeList requested_attributes
;
62 requested_attributes
.length(0);
63 Security::AttributeType desired_attribute
;
64 desired_attribute
.attribute_family
.family_definer
= 0; // OMG
65 desired_attribute
.attribute_family
.family
= 1; // Privilege
67 desired_attribute
.attribute_type
= Security::AccessId
;
68 requested_attributes
.length(1);
69 requested_attributes
[0] = desired_attribute
;
71 // Request the attribtue
73 Security::AttributeList_var attrib_list
=
74 this->current_
->get_attributes(requested_attributes
);
76 if(attrib_list
->length() > 0)
79 // Copy the values out
81 Security::SecAttribute attribute_returned
;
83 attribute_returned
.defining_authority
=
84 (attrib_list
.in())[0].defining_authority
;
85 attribute_returned
.value
=
86 (attrib_list
.in())[0].value
;
88 // Certificates are returned in
91 const char x509
[] = "x509";
93 // Setup a Security::OID (sequence<octet>)
94 // to hold the attribute's defining authority.
96 Security::OID x509_defining_authority
;
97 x509_defining_authority
.length(sizeof (x509
));
99 // Populate the defining authority value.
102 x509_defining_authority
.get_buffer();
103 ACE_OS::memcpy( buf
, x509
, sizeof(x509
));
105 // Confirm the defining authority is "x509".
107 if(attribute_returned
.defining_authority
==
108 x509_defining_authority
)
111 // Get the buffer holding the certificate
113 CORBA::Octet
*der_cert
=
114 attribute_returned
.value
.get_buffer();
116 // Convert the DER encoded certificate into
117 // OpenSSL's internal format.
119 X509
*peer
= ::d2i_X509 (0,
121 attribute_returned
.value
.length());
123 ::X509_NAME_oneline(::X509_get_subject_name (peer
),
131 // Report the certificate's subject name
132 // and terminate the server
134 std::cout
<< "Shutdown commanded by: "
137 std::cout
<< std::endl
;
144 // requestor is not secure,
145 // ignore shutdown command
146 std::cout
<< "Shutdown command from: " << user_name
<< std::endl
;
147 std::cout
<< "Status: User *NOT* authenticated." << std::endl
;
148 std::cout
<< "Action: Ignored." << std::endl
;
149 std::cout
<< std::endl
;