1 23 package com.sun.enterprise.iiop; 24 25 import java.util.*; 26 import java.io.*; 27 28 import org.omg.CORBA.ORB ; 29 import org.omg.IOP.TaggedComponent ; 30 31 import com.sun.enterprise.util.Utility; 32 import com.sun.enterprise.util.ORBManager; 33 import com.sun.enterprise.iiop.security.GSSUtils; 34 import com.sun.enterprise.deployment.*; 35 import java.util.logging.*; 36 import com.sun.logging.*; 37 38 import com.sun.corba.ee.spi.ior.iiop.IIOPProfile; 41 import com.sun.corba.ee.spi.ior.iiop.IIOPProfileTemplate; 42 import com.sun.corba.ee.spi.ior.IOR; 43 import com.sun.corba.ee.impl.encoding.CDRInputStream; 44 import com.sun.corba.ee.impl.encoding.CDROutputStream; 45 import com.sun.corba.ee.impl.encoding.EncapsInputStream; 46 47 import com.sun.corba.ee.org.omg.CSI.*; 48 import com.sun.corba.ee.org.omg.CSIIOP.*; 49 50 56 57 public final class CSIV2TaggedComponentInfo 58 { 59 private static Logger _logger=null; 60 static{ 61 _logger=LogDomains.getLogger(LogDomains.CORBA_LOGGER); 62 } 63 private String _realm_name = null; 68 private byte[] _realm_name_bytes = null; 69 private final static String DEFAULT_REALM = "default"; 70 71 public static final int SUPPORTED_IDENTITY_TOKEN_TYPES = 15; 72 73 private ORB orb; 74 private int sslMutualAuthPort; 75 76 77 80 public CSIV2TaggedComponentInfo(ORB orb) { 81 this.orb = orb; 82 } 83 84 89 public TaggedComponent createSecurityTaggedComponent(int sslPort, 90 EjbDescriptor desc) 91 { 92 TaggedComponent tc = null; 93 try { 94 if(_logger.isLoggable(Level.FINE)){ 95 _logger.log(Level.FINE, "IIOP: Creating a Security Tagged Component"); 96 } 97 _realm_name = desc.getApplication().getRealm(); 99 CompoundSecMech[] mechList = createCompoundSecMechs(sslPort, desc); 100 tc = createTaggedComponent(mechList); 101 102 } catch(Exception e) { 103 _logger.log(Level.SEVERE,"iiop.createcompund_exception",e); 104 } 105 return tc; 106 } 107 108 111 public TaggedComponent createSecurityTaggedComponent(int sslPort) 112 { 113 TaggedComponent tc = null; 114 try { 115 boolean sslRequired = false; 116 String sslReq = 117 (String )(ORBManager.getCSIv2Props()).get(ORBManager.ORB_SSL_SERVER_REQUIRED); 118 if ( sslReq != null && sslReq.equals("true") ) { 119 sslRequired = true; 120 } 121 122 boolean clientAuthReqd = false; 123 String clientAuthReq = 124 (String )(ORBManager.getCSIv2Props()).get(ORBManager.ORB_CLIENT_AUTH_REQUIRED); 125 if ( clientAuthReq != null && clientAuthReq.equals("true") ) { 126 clientAuthReqd = true; 127 } 128 129 CompoundSecMech[] mechList = new CompoundSecMech[1]; 130 TaggedComponent transportMech = createSSLInfo(sslPort, null, 131 sslRequired); 132 AS_ContextSec asContext = createASContextSec(null); 134 135 SAS_ContextSec sasContext = createSASContextSec(null); 137 138 short targetRequires = 139 (clientAuthReqd ? EstablishTrustInClient.value : 0); 140 141 mechList[0] = new CompoundSecMech(targetRequires, 143 transportMech, asContext, sasContext); 144 145 tc = createTaggedComponent(mechList); 146 } catch(Exception e) { 147 _logger.log(Level.SEVERE,"iiop.createcompund_exception",e); 148 } 149 return tc; 150 } 151 public TaggedComponent createSecurityTaggedComponent(java.util.List <com.sun.corba.ee.spi.folb.SocketInfo> scoketInfos) 152 { 153 TaggedComponent tc = null; 154 try { 155 boolean sslRequired = false; 156 String sslReq = 157 (String )(ORBManager.getCSIv2Props()).get(ORBManager.ORB_SSL_SERVER_REQUIRED); 158 if ( sslReq != null && sslReq.equals("true") ) { 159 sslRequired = true; 160 } 161 162 boolean clientAuthReqd = false; 163 String clientAuthReq = 164 (String )(ORBManager.getCSIv2Props()).get(ORBManager.ORB_CLIENT_AUTH_REQUIRED); 165 if ( clientAuthReq != null && clientAuthReq.equals("true") ) { 166 clientAuthReqd = true; 167 } 168 169 CompoundSecMech[] mechList = new CompoundSecMech[1]; 170 TaggedComponent transportMech = createSSLInfo(scoketInfos, null, 171 sslRequired); 172 AS_ContextSec asContext = createASContextSec(null); 174 175 SAS_ContextSec sasContext = createSASContextSec(null); 177 178 short targetRequires = 179 (clientAuthReqd ? EstablishTrustInClient.value : 0); 180 181 mechList[0] = new CompoundSecMech(targetRequires, 183 transportMech, asContext, sasContext); 184 185 tc = createTaggedComponent(mechList); 186 } catch(Exception e) { 187 _logger.log(Level.SEVERE,"iiop.createcompund_exception",e); 188 } 189 return tc; 190 } 191 235 236 private TaggedComponent createTaggedComponent(CompoundSecMech[] mechList) 237 { 238 CDROutputStream out = (CDROutputStream) orb.create_output_stream(); 239 out.putEndian(); 240 241 boolean stateful = false; 242 CompoundSecMechList list = new CompoundSecMechList(stateful, 243 mechList); 244 CompoundSecMechListHelper.write(out, list); 245 byte[] buf = out.toByteArray(); 246 TaggedComponent tc = new TaggedComponent ( 247 TAG_CSI_SEC_MECH_LIST.value, buf ) ; 248 return tc; 249 } 250 251 public void setSSLMutualAuthPort(int port) { 252 sslMutualAuthPort = port; 253 } 254 255 private int getSSLMutualAuthPort() { 256 return sslMutualAuthPort; 257 } 258 259 264 private CompoundSecMech[] createCompoundSecMechs(int sslPort, 265 EjbDescriptor desc) 266 throws IOException 267 { 268 if(_logger.isLoggable(Level.FINE)){ 269 _logger.log(Level.FINE, "IIOP: Creating CompoundSecMech"); 270 } 271 272 Set iorDescSet = desc.getIORConfigurationDescriptors(); 273 int size = iorDescSet.size(); 274 if(size == 0) { 275 278 EjbIORConfigurationDescriptor eDesc = 280 new EjbIORConfigurationDescriptor(); 281 eDesc.setIntegrity(EjbIORConfigurationDescriptor.SUPPORTED); 282 eDesc.setConfidentiality(EjbIORConfigurationDescriptor.SUPPORTED); 283 eDesc.setEstablishTrustInClient 284 (EjbIORConfigurationDescriptor.SUPPORTED); 285 iorDescSet.add(eDesc); 286 size = 1; 287 288 Set permissions = desc.getPermissionedRoles(); 291 if(permissions.size() > 0) { 292 if(_logger.isLoggable(Level.FINE)){ 293 _logger.log(Level.FINE,"IIOP:Application has protected methods"); 294 } 295 eDesc.setAuthMethodRequired(true); 296 } 297 } 298 CompoundSecMech[] mechList = new CompoundSecMech[size]; 299 Iterator itr = iorDescSet.iterator(); 300 if(_logger.isLoggable(Level.FINE)){ 301 _logger.log(Level.FINE,"IORDescriptor SIZE:" + size); 302 } 303 for(int i = 0; i < size; i++) { 304 EjbIORConfigurationDescriptor iorDesc = 305 (EjbIORConfigurationDescriptor) itr.next(); 306 int target_requires = getTargetRequires(iorDesc); 307 TaggedComponent comp = createSSLInfo(sslPort, iorDesc, false); 308 AS_ContextSec asContext = createASContextSec(iorDesc); 310 SAS_ContextSec sasContext = createSASContextSec(iorDesc); 312 int targ_req = target_requires | asContext.target_requires 314 | sasContext.target_requires; 315 TaggedComponent transportMech = comp; 317 mechList[i] = new CompoundSecMech((short)targ_req, 318 transportMech, asContext, sasContext); 319 } 320 return mechList; 321 } 322 323 328 public boolean allMechanismsRequireSSL(Set iorDescSet) { 329 int size = iorDescSet.size(); 330 if(size == 0) { 331 return false; 332 } 333 Iterator itr = iorDescSet.iterator(); 334 for(int i = 0; i < size; i++) { 335 EjbIORConfigurationDescriptor iorDesc = 336 (EjbIORConfigurationDescriptor) itr.next(); 337 int target_requires = getTargetRequires(iorDesc); 338 if(target_requires == 0) { 339 return false; 340 } 341 } 342 return true; 343 } 344 345 348 public AS_ContextSec createASContextSec( 349 EjbIORConfigurationDescriptor iorDesc) 350 throws IOException 351 { 352 AS_ContextSec asContext = null; 353 int target_supports = 0; 354 int target_requires = 0; 355 byte[] client_authentication_mechanism = {}; 356 byte[] target_name = {} ; 357 String authMethod = null; 358 boolean authMethodRequired = false; 359 360 if(_logger.isLoggable(Level.FINE)){ 361 _logger.log(Level.FINE, "IIOP: Creating AS_Context"); 362 } 363 364 368 if (iorDesc != null) { 369 authMethod = iorDesc.getAuthenticationMethod(); 370 authMethodRequired = iorDesc.isAuthMethodRequired(); 371 } 372 373 if ( (authMethod != null) && (authMethod.equalsIgnoreCase(EjbIORConfigurationDescriptor.NONE))) { 374 375 asContext = new AS_ContextSec((short)target_supports, 376 (short)target_requires, 377 client_authentication_mechanism, 378 target_name); 379 return asContext; 380 } 381 382 385 if(_realm_name == null){ if(iorDesc != null){ 387 _realm_name = iorDesc.getRealmName(); 388 } 389 if(_realm_name == null){ 390 _realm_name = DEFAULT_REALM; 391 if(_logger.isLoggable(Level.FINE)){ 392 _logger.log(Level.FINE, "IIOP:AS_Context: Realm Name = null," 393 + " setting default realm for logging in"); 394 } 395 } 396 } 397 if(_logger.isLoggable(Level.FINE)){ 398 _logger.log(Level.FINE, "IIOP:AS_Context: Realm Name for login = "+ 399 _realm_name); 400 } 401 _realm_name_bytes = _realm_name.getBytes(); 402 403 target_name = GSSUtils.createExportedName( 404 GSSUtils.GSSUP_MECH_OID, 405 _realm_name_bytes); 406 407 target_supports = EstablishTrustInClient.value; 408 409 if (authMethodRequired){ 410 target_requires = EstablishTrustInClient.value; 411 } 412 413 client_authentication_mechanism = getMechanism(); 414 415 asContext = new AS_ContextSec((short)target_supports, 416 (short)target_requires, 417 client_authentication_mechanism, 418 target_name); 419 420 return asContext; 421 } 422 423 426 public SAS_ContextSec createSASContextSec( 427 EjbIORConfigurationDescriptor iorDesc) 428 throws IOException 429 { 430 SAS_ContextSec sasContext = null; 431 int target_supports = 0; 433 int target_requires = 0; 434 ServiceConfiguration[] priv = new ServiceConfiguration[0]; 435 String callerPropagation = null; 436 byte[][] mechanisms = {}; 437 438 if(_logger.isLoggable(Level.FINE)){ 439 _logger.log(Level.FINE, "IIOP: Creating SAS_Context"); 440 } 441 442 443 int supported_identity_token_type = 0; 445 446 if (iorDesc != null) { 447 callerPropagation = iorDesc.getCallerPropagation(); 448 } 449 450 if ((callerPropagation != null) 451 && (callerPropagation.equalsIgnoreCase(EjbIORConfigurationDescriptor.NONE))){ 452 sasContext = new SAS_ContextSec((short)target_supports, 453 (short)target_requires, 454 priv, mechanisms, 455 supported_identity_token_type); 456 return sasContext; 457 } 458 459 target_supports = IdentityAssertion.value; 460 461 byte[] upm = getMechanism(); mechanisms = new byte[1][upm.length]; 463 for(int i = 0; i < upm.length; i++) { 464 mechanisms[0][i] = upm[i]; 465 } 466 467 if (target_supports != 0){ 471 supported_identity_token_type = SUPPORTED_IDENTITY_TOKEN_TYPES; 472 } 473 474 sasContext = new SAS_ContextSec((short)target_supports, 475 (short)target_requires, 476 priv, mechanisms, 477 supported_identity_token_type); 478 479 return sasContext; 480 } 481 482 486 private TaggedComponent createSSLInfo(int sslport, 487 EjbIORConfigurationDescriptor iorDesc, 488 boolean sslRequired ) 489 { 490 int targetSupports = 0; 491 int targetRequires = 0; 492 int ssl_port = sslport; if(_logger.isLoggable(Level.FINE)){ 494 _logger.log(Level.FINE, "IIOP: Creating Transport Mechanism"); 495 } 496 497 if ( iorDesc == null ) { 498 targetSupports = Integrity.value | Confidentiality.value 500 | EstablishTrustInClient.value 501 | EstablishTrustInTarget.value; 502 if ( sslRequired ) { 503 targetRequires = Integrity.value | Confidentiality.value 504 | EstablishTrustInClient.value; 505 } 506 } 507 else { 508 targetSupports = getTargetSupports(iorDesc); 509 targetRequires = getTargetRequires(iorDesc); 510 if((targetRequires & EstablishTrustInClient.value) 511 == EstablishTrustInClient.value) { 512 ssl_port = getSSLMutualAuthPort(); 514 if(_logger.isLoggable(Level.FINE)){ 515 _logger.log(Level.FINE,"MUTUAL AUTH PORT=" + sslport); 516 } 517 } 518 } 519 524 525 if ( (targetSupports | targetRequires) == 0 || ssl_port == -1) { 526 byte[] b = {} ; 527 TaggedComponent tc = new TaggedComponent (TAG_NULL_TAG.value, b); 528 return tc; 529 } 530 String host_name = ""; 531 host_name = Utility.getLocalAddress(); 532 TransportAddress[] listTa = generateTransportAddresses(host_name, 533 ssl_port); 534 TLS_SEC_TRANS tls_sec = new TLS_SEC_TRANS((short)targetSupports, 535 (short)targetRequires, 536 listTa); 537 538 CDROutputStream out = (CDROutputStream) orb.create_output_stream(); 539 out.putEndian() ; 540 TLS_SEC_TRANSHelper.write((org.omg.CORBA.portable.OutputStream )out, tls_sec); 541 542 byte[] buf = out.toByteArray() ; 543 TaggedComponent tc = new TaggedComponent ( 545 TAG_TLS_SEC_TRANS.value, buf ) ; 546 return tc; 547 548 } 549 private TransportAddress[] generateTransportAddresses(String host, 550 int sslport){ 551 short short_port = Utility.intToShort(sslport); 552 TransportAddress ta = new TransportAddress(host, short_port); 553 TransportAddress[] listTa = new TransportAddress[1]; 554 listTa[0] = ta; 555 return listTa; 556 } 557 private TaggedComponent createSSLInfo(java.util.List <com.sun.corba.ee.spi.folb.SocketInfo> scoketInfos, 558 EjbIORConfigurationDescriptor iorDesc, 559 boolean sslRequired ) 560 { 561 int targetSupports = 0; 562 int targetRequires = 0; 563 if(_logger.isLoggable(Level.FINE)){ 565 _logger.log(Level.FINE, "IIOP: Creating Transport Mechanism"); 566 } 567 568 if ( iorDesc == null ) { 569 targetSupports = Integrity.value | Confidentiality.value 571 | EstablishTrustInClient.value 572 | EstablishTrustInTarget.value; 573 if ( sslRequired ) { 574 targetRequires = Integrity.value | Confidentiality.value 575 | EstablishTrustInClient.value; 576 } 577 } 578 else { 579 targetSupports = getTargetSupports(iorDesc); 580 targetRequires = getTargetRequires(iorDesc); 581 if((targetRequires & EstablishTrustInClient.value) 582 == EstablishTrustInClient.value) { 583 if(_logger.isLoggable(Level.FINE)){ 586 } 588 } 589 } 590 595 596 if ( (targetSupports | targetRequires) == 0 ) { 598 byte[] b = {} ; 599 TaggedComponent tc = new TaggedComponent (TAG_NULL_TAG.value, b); 600 return tc; 601 } 602 TransportAddress[] listTa = generateTransportAddresses(scoketInfos); 603 TLS_SEC_TRANS tls_sec = new TLS_SEC_TRANS((short)targetSupports, 604 (short)targetRequires, 605 listTa); 606 607 CDROutputStream out = (CDROutputStream) orb.create_output_stream(); 608 out.putEndian() ; 609 TLS_SEC_TRANSHelper.write((org.omg.CORBA.portable.OutputStream )out, tls_sec); 610 611 byte[] buf = out.toByteArray() ; 612 TaggedComponent tc = new TaggedComponent ( 614 TAG_TLS_SEC_TRANS.value, buf ) ; 615 return tc; 616 617 } 618 private TransportAddress[] generateTransportAddresses(java.util.List <com.sun.corba.ee.spi.folb.SocketInfo> socketInfos){ 619 TransportAddress[] listTa = new TransportAddress[socketInfos.size()]; 620 for(int i=0; i< socketInfos.size(); i++){ 621 com.sun.corba.ee.spi.folb.SocketInfo socketInfo = socketInfos.get(i); 622 int sslport = socketInfo.port; 623 String host = socketInfo.host; 624 short short_port = Utility.intToShort(sslport); 625 TransportAddress ta = new TransportAddress(host, short_port); 626 listTa[i] = ta; 627 } 628 return listTa; 629 } 630 635 public CompoundSecMech[] getSecurityMechanisms(IOR ior) { 636 IIOPProfile prof = ior.getProfile(); 637 IIOPProfileTemplate ptemp = (IIOPProfileTemplate)prof. 638 getTaggedProfileTemplate(); 639 Iterator itr = ptemp.iteratorById(TAG_CSI_SEC_MECH_LIST.value); 640 if(!itr.hasNext()) { 641 if(_logger.isLoggable(Level.FINE)){ 642 String msg = "IIOP:TAG_CSI_SEC_MECH_LIST tagged component not found"; 643 _logger.log(Level.FINE, msg); 644 } 645 return null; 646 } 647 Object o = itr.next(); 648 if(_logger.isLoggable(Level.FINE)){ 649 _logger.log(Level.FINE,"Component:" + o); 650 } 651 if(itr.hasNext()) { 652 String msg = "More than one TAG_CSI_SEC_MECH_LIST tagged " + 653 "component found "; 654 _logger.log(Level.SEVERE,"iiop.many_tagged_component"); 655 throw new RuntimeException (msg); 656 } 657 com.sun.corba.ee.spi.ior.TaggedComponent tcomp = 658 (com.sun.corba.ee.spi.ior.TaggedComponent) o; 659 TaggedComponent comp = tcomp.getIOPComponent(orb); 660 byte[] b = comp.component_data; 661 CDRInputStream in = (CDRInputStream) new EncapsInputStream(orb, b, b.length); 662 in.consumeEndian(); 663 CompoundSecMechList l = CompoundSecMechListHelper.read(in); 664 CompoundSecMech[] list = l.mechanism_list; 665 666 return list; 667 } 668 669 673 public TLS_SEC_TRANS getSSLInformation(CompoundSecMech mech){ 674 TaggedComponent pcomp = mech.transport_mech; 675 TLS_SEC_TRANS ssl = getSSLComponent(pcomp); 676 return ssl; 677 678 } 679 private TLS_SEC_TRANS getSSLComponent(TaggedComponent comp) 680 { 681 TLS_SEC_TRANS ssl = null; 682 if (comp.tag == TAG_NULL_TAG.value){ 684 ssl = null; 685 } else { 686 byte[] b = comp.component_data; 687 CDRInputStream in = (CDRInputStream) new EncapsInputStream(orb, b, b.length); 688 in.consumeEndian(); 689 ssl = TLS_SEC_TRANSHelper.read(in); 690 } 691 return ssl; 692 } 693 694 695 698 public int getTargetSupports(EjbIORConfigurationDescriptor iorDesc) 699 { 700 if ( iorDesc == null ) { 701 return 0; 702 } 703 int supports = 0; 704 String integrity = iorDesc.getIntegrity(); 705 if(!integrity.equalsIgnoreCase(EjbIORConfigurationDescriptor.NONE)) { 706 supports = supports | Integrity.value; 707 } 708 String confidentiality = iorDesc.getConfidentiality(); 709 if(!confidentiality.equalsIgnoreCase(EjbIORConfigurationDescriptor.NONE)) { 710 supports = supports | Confidentiality.value; 711 } 712 String establishTrustInTarget = iorDesc.getEstablishTrustInTarget(); 713 if(!establishTrustInTarget.equalsIgnoreCase(EjbIORConfigurationDescriptor.NONE)) { 714 supports = supports | EstablishTrustInTarget.value; 715 } 716 String establishTrustInClient = iorDesc.getEstablishTrustInClient(); 717 if(!establishTrustInClient.equalsIgnoreCase(EjbIORConfigurationDescriptor.NONE)) { 718 supports = supports | EstablishTrustInClient.value; 719 } 720 return supports; 721 } 722 723 726 public int getTargetRequires(EjbIORConfigurationDescriptor iorDesc) 727 { 728 if ( iorDesc == null ) { 729 return 0; 730 } 731 int requires = 0; 732 String integrity = iorDesc.getIntegrity(); 733 if(integrity.equalsIgnoreCase(EjbIORConfigurationDescriptor.REQUIRED)) { 734 requires = requires | Integrity.value; 735 } 736 String confidentiality = iorDesc.getConfidentiality(); 737 if(confidentiality.equalsIgnoreCase(EjbIORConfigurationDescriptor.REQUIRED)) { 738 requires = requires | Confidentiality.value; 739 } 740 String establishTrustInTarget = iorDesc.getEstablishTrustInTarget(); 741 if(establishTrustInTarget.equalsIgnoreCase(EjbIORConfigurationDescriptor.REQUIRED)) { 742 requires = requires | EstablishTrustInTarget.value; 743 } 744 String establishTrustInClient = iorDesc.getEstablishTrustInClient(); 745 if(establishTrustInClient.equalsIgnoreCase(EjbIORConfigurationDescriptor.REQUIRED)) { 746 requires = requires | EstablishTrustInClient.value; 747 } 748 return requires; 749 } 750 751 755 private byte[] getMechanism() 756 throws IOException{ 757 return GSSUtils.getDER(GSSUtils.GSSUP_MECH_OID); 758 } 759 } 760 | Popular Tags |