⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.cc

📁 MICO2.3.13 corba 环境平台
💻 CC
📖 第 1 页 / 共 2 页
字号:
  securitymanager = orb->resolve_initial_references ("SecurityManager");  assert (!CORBA::is_nil (securitymanager));  secman = SecurityLevel2::SecurityManager::_narrow(securitymanager);  assert (!CORBA::is_nil (secman));  Security::AuthenticationMethod our_method = (Security::AuthenticationMethod)SecurityLevel2::KeyCertCAPass;    Security::SSLKeyCertCAPass method_struct;    CORBA::Any* any_struct = secman -> get_method_data(our_method);  *any_struct >>= method_struct;  method_struct.key = "ServerKey.pem";  method_struct.cert = "ServerCert.pem";  method_struct.CAfile = "list.pem";  method_struct.CAdir = "";  method_struct.pass = "";  CORBA::Any* out_any_struct;  out_any_struct = new CORBA::Any;  *out_any_struct <<= method_struct;	  SecurityLevel2::PrincipalAuthenticator_ptr pa = secman -> principal_authenticator();    //	 const char* mechanism = "IDEA-CBC-SHA";   const char* mechanism = "";   const char* security_name = "ssl";   Security::AttributeList privileges;   SecurityLevel2::Credentials_ptr creds;   CORBA::Any* continuation_data;   CORBA::Any* auth_specific_data;  try	{		pa -> authenticate( our_method, mechanism, security_name, *out_any_struct,privileges, creds,continuation_data,auth_specific_data);		}	catch (...)	{		cout << "authentication failed" <<endl;		delete out_any_struct;		return 0;	}  // Test  pa->get_supported_authen_methods//getting of own credentials (first from own credentials list)	   SecurityLevel2::Credentials_ptr own_cred;  own_cred = (*(secman -> own_credentials()))[0];	  Security::AuthenticationStatus auth_state = own_cred -> authentication_state();    cout << "Authentication State= ";  if ( auth_state == Security::SecAuthSuccess )	 cout << "SecAuthSuccess\n";  if ( auth_state == Security::SecAuthFailure )	 cout << "SecAuthFailure\n";  if ( auth_state == Security::SecAuthContinue )	 cout << "SecAuthContinue\n";  if ( auth_state == Security::SecAuthExpired )	 cout << "SecAuthExpired\n";  Security::CredentialsType cred_type = own_cred->credentials_type();  if ( cred_type == Security::SecOwnCredentials )    cout << "SecOwnCredentials\n";  if ( cred_type == Security::SecReceivedCredentials )    cout << "SecReceivedCredentials\n";  if ( cred_type ==  Security::SecTargetCredentials )    cout << "SecTargetCredentials\n";  cout << "Mechanism Type= " << own_cred->mechanism() << endl;//we can request own credentials attributes 	Security::ExtensibleFamily fam1;  fam1.family_definer = 0;  fam1.family = 1;  Security::AttributeType at1;  at1.attribute_family = fam1;  at1.attribute_type = Security::AccessId;  Security::AttributeTypeList atl1;    atl1.length(1);  atl1[0]=at1;  // Destroy Credential, OK  //  own_cred->destroy();   // Copy Credential, OK  //  SecurityLevel2::Credentials_ptr copied_cred = own_cred->copy();  //  Security::AttributeList_out al1 = copied_cred->get_attributes(atl1);  // Get Security Features  cout << "Security Features:\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecNoDelegation ))    cout << "SecNoDelegation\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecSimpleDelegation ))    cout << "SecSimpleDelegation\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecCompositeDelegation ))    cout << "SecCompositeDelegation\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecNoProtection ))    cout << "SecNoProtection\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecIntegrity))    cout << "SecIntegrity\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecConfidentiality))    cout << "SecConfidentiality\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecIntegrityAndConfidentiality))    cout << "SecIntegrityAndConfidentiality\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecDetectReplay))    cout << "SecDetectReplay\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecDetectMisordering))    cout << "SecDetectMisordering\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecEstablishTrustInTarget))    cout << "SecEstablishTrustInTarget\n";  if (own_cred->get_security_feature(Security::SecDirectionBoth,Security::SecEstablishTrustInClient))    cout << "SecEstablishTrustInClient\n";  //getting  the attributes from the Credentials  Security::AttributeList_var al1 = own_cred->get_attributes(atl1);//output	 cout << "Own credentials"        << (*al1).length() << " attributes\n";  for (CORBA::ULong ctr = 0; ctr < (*al1).length(); ctr++)     {      cout  			<< "family = "	<< (*al1)[ctr].attribute_type.attribute_family.family << " "	<< "type = "	<< (*al1)[ctr].attribute_type.attribute_type << " "	<<  &(*al1)[ctr].value[0] << " "	<< &(*al1)[ctr].defining_authority[0]	<< endl;    }  cout << "///////////////////////////////////////////////////////////////////////////\n";  /////////////////////////////////////////////////////////////////////////////////////////   CORBA::Object_var policy_current_obj = orb->resolve_initial_references ("PolicyCurrent");  SecurityLevel2::PolicyCurrent_var policy_current = SecurityLevel2::PolicyCurrent::_narrow(policy_current_obj);  assert (!CORBA::is_nil (policy_current));  //PolicyCurrent output    CORBA::PolicyTypeSeq policy_types;  policy_types.length(0);   CORBA::PolicyList * policies = policy_current -> get_policy_overrides(policy_types);    for (CORBA::ULong i=0; i < policies -> length(); i++) {    CORBA::Policy_ptr policy = (*policies)[i];    CORBA::PolicyType type = policy -> policy_type();    if (type == Security::SecMechanismPolicy) {      cout << "MechanismPolicy" << endl;      SecurityLevel2::MechanismPolicy_ptr mp  = SecurityLevel2::MechanismPolicy::_narrow(policy);      Security::MechanismTypeList* mech = mp -> mechanisms();      for (CORBA::ULong j=0; j < mech -> length(); j++) 	  cout << (char *)((*mech)[j]) << endl;      continue;    }     if (type == Security::SecInvocationCredentialsPolicy){	cout << "InvocationCredentialsPolicy" << endl;      SecurityLevel2::InvocationCredentialsPolicy_ptr icp  = SecurityLevel2::InvocationCredentialsPolicy::_narrow(policy);      SecurityLevel2::CredentialsList* cred =  icp -> creds();      int len = cred -> length();      for (int i = 0; i < len; i++) {	SecurityLevel2::Credentials_ptr own_cred;	own_cred = (*cred)[i];		Security::ExtensibleFamily fam1;	fam1.family_definer = 0;	fam1.family = 1;	Security::AttributeType at1;	at1.attribute_family = fam1;	at1.attribute_type = Security::AccessId;	Security::AttributeTypeList atl1;	atl1.length(1);	atl1[0]=at1;	Security::AttributeList_var al1 = own_cred->get_attributes(atl1);	cout << "Own " 	     << (*al1).length() << " attributes\n";		for (CORBA::ULong ctr = 0; ctr < (*al1).length(); ctr++) {	  cout  	    << (*al1)[ctr].attribute_type.attribute_family.family << " "	    << (*al1)[ctr].attribute_type.attribute_type << " "	    <<  &(*al1)[ctr].value[0] << " "	    << &(*al1)[ctr].defining_authority[0]	    << endl;	}      }      continue;    }	if (type == Security::SecQOPPolicy) {		cout << "QOPPolicy" << endl;      continue;    }     if (type == Security::SecDelegationDirectivePolicy) {	cout << "DelegationDirectivePolicy" << endl;      continue;    }     if (type == Security::SecEstablishTrustPolicy) {      SecurityLevel2::EstablishTrustPolicy_ptr etp  = SecurityLevel2::EstablishTrustPolicy::_narrow(policy);      if (etp -> trust().trust_in_client)	  cout << "EstablishTrustPolicy - trust in client" << endl;      else 	  cout << "EstablishTrustPolicy - trust in target" << endl;      continue;    }     cout << "Invalid type!!" << endl;  }	cout << "///////////////////////////////////////////////////////////////////////////\n";  /*   * Create a Bank   */	Bank_impl * micocash = new Bank_impl;  /*   * Activate the Bank   */  PortableServer::ObjectId_var oid = poa->activate_object (micocash); /*   * Write reference to file   */  ofstream of ("Bank.ref");  CORBA::Object_var ref = poa->id_to_reference (oid.in());  CORBA::String_var str = orb->object_to_string (ref.in());  of << str.in() << endl;  of.close ();  /*   * Activate the POA and start serving requests   */cout << "Running." << endl;  mgr->activate ();  orb->run();  /*   * Shutdown (never reached)   */  poa->destroy (TRUE, TRUE);  delete micocash;  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -