1 17 package com.sun.org.apache.xml.internal.security.keys; 18 19 20 21 import java.security.PublicKey ; 22 import java.security.cert.X509Certificate ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 26 import javax.crypto.SecretKey; 27 28 import com.sun.org.apache.xml.internal.security.encryption.EncryptedKey; 29 import com.sun.org.apache.xml.internal.security.encryption.XMLCipher; 30 import com.sun.org.apache.xml.internal.security.encryption.XMLEncryptionException; 31 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 32 import com.sun.org.apache.xml.internal.security.keys.content.KeyName; 33 import com.sun.org.apache.xml.internal.security.keys.content.KeyValue; 34 import com.sun.org.apache.xml.internal.security.keys.content.MgmtData; 35 import com.sun.org.apache.xml.internal.security.keys.content.PGPData; 36 import com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod; 37 import com.sun.org.apache.xml.internal.security.keys.content.SPKIData; 38 import com.sun.org.apache.xml.internal.security.keys.content.X509Data; 39 import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue; 40 import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue; 41 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolver; 42 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException; 43 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi; 44 import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver; 45 import com.sun.org.apache.xml.internal.security.transforms.Transforms; 46 import com.sun.org.apache.xml.internal.security.utils.EncryptionConstants; 47 import com.sun.org.apache.xml.internal.security.utils.Constants; 48 import com.sun.org.apache.xml.internal.security.utils.IdResolver; 49 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; 50 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 51 import org.w3c.dom.Document ; 52 import org.w3c.dom.Element ; 53 import org.w3c.dom.Node ; 54 import org.w3c.dom.NodeList ; 55 56 57 89 public class KeyInfo extends SignatureElementProxy { 90 91 92 static java.util.logging.Logger log = 93 java.util.logging.Logger.getLogger(KeyInfo.class.getName()); 94 95 96 97 101 public KeyInfo(Document doc) { 102 103 super(doc); 104 105 XMLUtils.addReturnToElement(this._constructionElement); 106 107 108 } 109 110 117 public KeyInfo(Element element, String BaseURI) throws XMLSecurityException { 118 119 super(element, BaseURI); 120 121 } 122 123 128 public void setId(String Id) { 129 130 if ((this._state == MODE_SIGN) && (Id != null)) { 131 this._constructionElement.setAttributeNS(null, Constants._ATT_ID, Id); 132 IdResolver.registerElementById(this._constructionElement, Id); 133 } 134 } 135 136 141 public String getId() { 142 return this._constructionElement.getAttributeNS(null, Constants._ATT_ID); 143 } 144 145 150 public void addKeyName(String keynameString) { 151 this.add(new KeyName(this._doc, keynameString)); 152 } 153 154 159 public void add(KeyName keyname) { 160 161 if (this._state == MODE_SIGN) { 162 this._constructionElement.appendChild(keyname.getElement()); 163 XMLUtils.addReturnToElement(this._constructionElement); 164 } 165 } 166 167 172 public void addKeyValue(PublicKey pk) { 173 this.add(new KeyValue(this._doc, pk)); 174 } 175 176 181 public void addKeyValue(Element unknownKeyValueElement) { 182 this.add(new KeyValue(this._doc, unknownKeyValueElement)); 183 } 184 185 190 public void add(DSAKeyValue dsakeyvalue) { 191 this.add(new KeyValue(this._doc, dsakeyvalue)); 192 } 193 194 199 public void add(RSAKeyValue rsakeyvalue) { 200 this.add(new KeyValue(this._doc, rsakeyvalue)); 201 } 202 203 208 public void add(PublicKey pk) { 209 this.add(new KeyValue(this._doc, pk)); 210 } 211 212 217 public void add(KeyValue keyvalue) { 218 219 if (this._state == MODE_SIGN) { 220 this._constructionElement.appendChild(keyvalue.getElement()); 221 XMLUtils.addReturnToElement(this._constructionElement); 222 } 223 } 224 225 230 public void addMgmtData(String mgmtdata) { 231 this.add(new MgmtData(this._doc, mgmtdata)); 232 } 233 234 239 public void add(MgmtData mgmtdata) { 240 241 if (this._state == MODE_SIGN) { 242 this._constructionElement.appendChild(mgmtdata.getElement()); 243 XMLUtils.addReturnToElement(this._constructionElement); 244 } 245 } 246 247 252 public void add(PGPData pgpdata) { 253 254 if (this._state == MODE_SIGN) { 255 this._constructionElement.appendChild(pgpdata.getElement()); 256 XMLUtils.addReturnToElement(this._constructionElement); 257 } 258 } 259 260 267 public void addRetrievalMethod(String URI, Transforms transforms, 268 String Type) { 269 this.add(new RetrievalMethod(this._doc, URI, transforms, Type)); 270 } 271 272 277 public void add(RetrievalMethod retrievalmethod) { 278 279 if (this._state == MODE_SIGN) { 280 this._constructionElement.appendChild(retrievalmethod.getElement()); 281 XMLUtils.addReturnToElement(this._constructionElement); 282 } 283 } 284 285 290 public void add(SPKIData spkidata) { 291 292 if (this._state == MODE_SIGN) { 293 this._constructionElement.appendChild(spkidata.getElement()); 294 XMLUtils.addReturnToElement(this._constructionElement); 295 } 296 } 297 298 303 public void add(X509Data x509data) { 304 305 if (this._state == MODE_SIGN) { 306 this._constructionElement.appendChild(x509data.getElement()); 307 XMLUtils.addReturnToElement(this._constructionElement); 308 } 309 } 310 311 317 318 public void add(EncryptedKey encryptedKey) 319 throws XMLEncryptionException { 320 321 if (this._state == MODE_SIGN) { 322 XMLCipher cipher = XMLCipher.getInstance(); 323 this._constructionElement.appendChild(cipher.martial(encryptedKey)); 324 } 325 326 } 327 328 333 public void addUnknownElement(Element element) { 334 335 if (this._state == MODE_SIGN) { 336 this._constructionElement.appendChild(element); 337 XMLUtils.addReturnToElement(this._constructionElement); 338 } 339 } 340 341 346 public int lengthKeyName() { 347 return this.length(Constants.SignatureSpecNS, Constants._TAG_KEYNAME); 348 } 349 350 355 public int lengthKeyValue() { 356 return this.length(Constants.SignatureSpecNS, Constants._TAG_KEYVALUE); 357 } 358 359 364 public int lengthMgmtData() { 365 return this.length(Constants.SignatureSpecNS, Constants._TAG_MGMTDATA); 366 } 367 368 373 public int lengthPGPData() { 374 return this.length(Constants.SignatureSpecNS, Constants._TAG_PGPDATA); 375 } 376 377 382 public int lengthRetrievalMethod() { 383 return this.length(Constants.SignatureSpecNS, 384 Constants._TAG_RETRIEVALMETHOD); 385 } 386 387 392 public int lengthSPKIData() { 393 return this.length(Constants.SignatureSpecNS, Constants._TAG_SPKIDATA); 394 } 395 396 401 public int lengthX509Data() { 402 return this.length(Constants.SignatureSpecNS, Constants._TAG_X509DATA); 403 } 404 405 410 public int lengthUnknownElement() { 411 412 int res = 0; 413 NodeList nl = this._constructionElement.getChildNodes(); 414 415 for (int i = 0; i < nl.getLength(); i++) { 416 Node current = nl.item(i); 417 418 422 if ((current.getNodeType() == Node.ELEMENT_NODE) 423 && current.getNamespaceURI() 424 .equals(Constants.SignatureSpecNS)) { 425 res++; 426 } 427 } 428 429 return res; 430 } 431 432 439 public KeyName itemKeyName(int i) throws XMLSecurityException { 440 441 Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), 442 Constants._TAG_KEYNAME,i); 443 444 if (e != null) { 445 return new KeyName(e, this._baseURI); 446 } 447 return null; 448 } 449 450 457 public KeyValue itemKeyValue(int i) throws XMLSecurityException { 458 459 Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), 460 Constants._TAG_KEYVALUE,i); 461 462 if (e != null) { 463 return new KeyValue(e, this._baseURI); 464 } 465 return null; 466 } 467 468 475 public MgmtData itemMgmtData(int i) throws XMLSecurityException { 476 477 Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), 478 Constants._TAG_MGMTDATA,i); 479 480 if (e != null) { 481 return new MgmtData(e, this._baseURI); 482 } 483 return null; 484 } 485 486 493 public PGPData itemPGPData(int i) throws XMLSecurityException { 494 495 Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), 496 Constants._TAG_PGPDATA,i); 497 498 if (e != null) { 499 return new PGPData(e, this._baseURI); 500 } 501 return null; 502 } 503 504 511 public RetrievalMethod itemRetrievalMethod(int i) 512 throws XMLSecurityException { 513 514 Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), 515 Constants._TAG_RETRIEVALMETHOD,i); 516 517 if (e != null) { 518 return new RetrievalMethod(e, this._baseURI); 519 } 520 return null; 521 } 522 523 530 public SPKIData itemSPKIData(int i) throws XMLSecurityException { 531 532 Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), 533 Constants._TAG_SPKIDATA,i); 534 535 if (e != null) { 536 return new SPKIData(e, this._baseURI); 537 } 538 return null; 539 } 540 541 548 public X509Data itemX509Data(int i) throws XMLSecurityException { 549 550 Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), 551 Constants._TAG_X509DATA,i); 552 553 if (e != null) { 554 return new X509Data(e, this._baseURI); 555 } 556 return null; 557 } 558 559 566 567 public EncryptedKey itemEncryptedKey(int i) throws XMLSecurityException { 568 569 Element e = 570 XMLUtils.selectXencNode(this._constructionElement.getFirstChild(), 571 EncryptionConstants._TAG_ENCRYPTEDKEY,i); 572 573 if (e != null) { 574 XMLCipher cipher = XMLCipher.getInstance(); 575 cipher.init(XMLCipher.UNWRAP_MODE, null); 576 return cipher.loadEncryptedKey(e); 577 } 578 return null; 579 } 580 581 587 public Element itemUnknownElement(int i) { 588 589 NodeList nl = this._constructionElement.getChildNodes(); 590 int res = 0; 591 592 for (int j = 0; j < nl.getLength(); j++) { 593 Node current = nl.item(j); 594 595 599 if ((current.getNodeType() == Node.ELEMENT_NODE) 600 && current.getNamespaceURI() 601 .equals(Constants.SignatureSpecNS)) { 602 res++; 603 604 if (res == i) { 605 return (Element ) current; 606 } 607 } 608 } 609 610 return null; 611 } 612 613 618 public boolean isEmpty() { 619 return this._constructionElement.getFirstChild()==null; 620 } 621 622 627 public boolean containsKeyName() { 628 return this.lengthKeyName() > 0; 629 } 630 631 636 public boolean containsKeyValue() { 637 return this.lengthKeyValue() > 0; 638 } 639 640 645 public boolean containsMgmtData() { 646 return this.lengthMgmtData() > 0; 647 } 648 649 654 public boolean containsPGPData() { 655 return this.lengthPGPData() > 0; 656 } 657 658 663 public boolean containsRetrievalMethod() { 664 return this.lengthRetrievalMethod() > 0; 665 } 666 667 672 public boolean containsSPKIData() { 673 return this.lengthSPKIData() > 0; 674 } 675 676 681 public boolean containsUnknownElement() { 682 return this.lengthUnknownElement() > 0; 683 } 684 685 690 public boolean containsX509Data() { 691 return this.lengthX509Data() > 0; 692 } 693 694 700 701 public PublicKey getPublicKey() throws KeyResolverException { 702 703 PublicKey pk = this.getPublicKeyFromInternalResolvers(); 704 705 if (pk != null) { 706 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I could find a key using the per-KeyInfo key resolvers"); 707 708 return pk; 709 } 710 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I couldn't find a key using the per-KeyInfo key resolvers"); 711 712 pk = this.getPublicKeyFromStaticResolvers(); 713 714 if (pk != null) { 715 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I could find a key using the system-wide key resolvers"); 716 717 return pk; 718 } 719 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I couldn't find a key using the system-wide key resolvers"); 720 721 return null; 722 } 723 724 730 PublicKey getPublicKeyFromStaticResolvers() throws KeyResolverException { 731 732 for (int i = 0; i < KeyResolver.length(); i++) { 733 KeyResolver keyResolver = KeyResolver.item(i); 734 Node currentChild=this._constructionElement.getFirstChild(); 735 while (currentChild!=null) { 736 if (currentChild.getNodeType() == Node.ELEMENT_NODE) { 737 if (this._storageResolvers.size() == 0) { 738 739 StorageResolver storage = null; 741 742 if (keyResolver.canResolve((Element ) currentChild, 743 this.getBaseURI(), storage)) { 744 PublicKey pk = 745 keyResolver.resolvePublicKey((Element ) currentChild, 746 this.getBaseURI(), 747 storage); 748 749 if (pk != null) { 750 return pk; 751 } 752 } 753 } else { 754 for (int k = 0; k < this._storageResolvers.size(); k++) { 755 StorageResolver storage = 756 (StorageResolver) this._storageResolvers.get(k); 757 758 if (keyResolver.canResolve((Element ) currentChild, 759 this.getBaseURI(), storage)) { 760 PublicKey pk = 761 keyResolver.resolvePublicKey((Element ) currentChild, 762 this.getBaseURI(), 763 storage); 764 765 if (pk != null) { 766 return pk; 767 } 768 } 769 } 770 } 771 } 772 currentChild=currentChild.getNextSibling(); 773 } 774 } 775 return null; 776 } 777 778 784 PublicKey getPublicKeyFromInternalResolvers() throws KeyResolverException { 785 786 for (int i = 0; i < this.lengthInternalKeyResolver(); i++) { 787 KeyResolverSpi keyResolver = this.itemInternalKeyResolver(i); 788 if (true) 789 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName()); 790 791 Node currentChild=this._constructionElement.getFirstChild(); 792 while (currentChild!=null) { 793 if (currentChild.getNodeType() == Node.ELEMENT_NODE) { 794 if (this._storageResolvers.size() == 0) { 795 796 StorageResolver storage = null; 798 799 if (keyResolver.engineCanResolve((Element ) currentChild, 800 this.getBaseURI(), 801 storage)) { 802 PublicKey pk = 803 keyResolver 804 .engineResolvePublicKey((Element ) currentChild, this 805 .getBaseURI(), storage); 806 807 if (pk != null) { 808 return pk; 809 } 810 } 811 } else { 812 for (int k = 0; k < this._storageResolvers.size(); k++) { 813 StorageResolver storage = 814 (StorageResolver) this._storageResolvers.get(k); 815 816 if (keyResolver.engineCanResolve((Element ) currentChild, 817 this.getBaseURI(), 818 storage)) { 819 PublicKey pk = keyResolver 820 .engineResolvePublicKey((Element ) currentChild, this 821 .getBaseURI(), storage); 822 823 if (pk != null) { 824 return pk; 825 } 826 } 827 } 828 } 829 } 830 currentChild=currentChild.getNextSibling(); 831 } 832 } 833 834 return null; 835 } 836 837 843 public X509Certificate getX509Certificate() throws KeyResolverException { 844 845 X509Certificate cert = this.getX509CertificateFromInternalResolvers(); 847 848 if (cert != null) { 849 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, 850 "I could find a X509Certificate using the per-KeyInfo key resolvers"); 851 852 return cert; 853 } 854 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, 855 "I couldn't find a X509Certificate using the per-KeyInfo key resolvers"); 856 857 858 cert = this.getX509CertificateFromStaticResolvers(); 860 861 if (cert != null) { 862 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, 863 "I could find a X509Certificate using the system-wide key resolvers"); 864 865 return cert; 866 } 867 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, 868 "I couldn't find a X509Certificate using the system-wide key resolvers"); 869 870 871 return null; 872 } 873 874 882 X509Certificate getX509CertificateFromStaticResolvers() 883 throws KeyResolverException { 884 if (true) 885 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Start getX509CertificateFromStaticResolvers() with " 886 + KeyResolver.length() + " resolvers"); 887 888 for (int i = 0; i < KeyResolver.length(); i++) { 889 KeyResolver keyResolver = KeyResolver.item(i); 890 Node currentChild=this._constructionElement.getFirstChild(); 891 while (currentChild!=null) { 892 if (currentChild.getNodeType() == Node.ELEMENT_NODE) { 893 if (this._storageResolvers.size() == 0) { 894 895 StorageResolver storage = null; 897 898 if (keyResolver.canResolve((Element ) currentChild, 899 this.getBaseURI(), storage)) { 900 X509Certificate cert = 901 keyResolver 902 .resolveX509Certificate((Element ) currentChild, this 903 .getBaseURI(), storage); 904 905 if (cert != null) { 906 return cert; 907 } 908 } 909 } else { 910 for (int k = 0; k < this._storageResolvers.size(); k++) { 911 StorageResolver storage = 912 (StorageResolver) this._storageResolvers.get(k); 913 914 if (keyResolver.canResolve((Element ) currentChild, 915 this.getBaseURI(), storage)) { 916 X509Certificate cert = keyResolver 917 .resolveX509Certificate((Element ) currentChild, this 918 .getBaseURI(), storage); 919 920 if (cert != null) { 921 return cert; 922 } 923 } 924 } 925 } 926 } 927 currentChild=currentChild.getNextSibling(); 928 } 929 } 930 return null; 931 } 932 933 939 X509Certificate getX509CertificateFromInternalResolvers() 940 throws KeyResolverException { 941 if (true) 942 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Start getX509CertificateFromInternalResolvers() with " 943 + this.lengthInternalKeyResolver() + " resolvers"); 944 945 for (int i = 0; i < this.lengthInternalKeyResolver(); i++) { 946 KeyResolverSpi keyResolver = this.itemInternalKeyResolver(i); 947 if (true) 948 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName()); 949 950 Node currentChild=this._constructionElement.getFirstChild(); 951 while (currentChild!=null) { 952 if (currentChild.getNodeType() == Node.ELEMENT_NODE) { 953 if (this._storageResolvers.size() == 0) { 954 955 StorageResolver storage = null; 957 958 if (keyResolver.engineCanResolve((Element ) currentChild, 959 this.getBaseURI(), 960 storage)) { 961 X509Certificate cert = 962 keyResolver.engineResolveX509Certificate( 963 (Element ) currentChild, this.getBaseURI(), storage); 964 965 if (cert != null) { 966 return cert; 967 } 968 } 969 } else { 970 for (int k = 0; k < this._storageResolvers.size(); k++) { 971 StorageResolver storage = 972 (StorageResolver) this._storageResolvers.get(k); 973 974 if (keyResolver.engineCanResolve((Element ) currentChild, 975 this.getBaseURI(), 976 storage)) { 977 X509Certificate cert = 978 keyResolver.engineResolveX509Certificate( 979 (Element ) currentChild, this.getBaseURI(), 980 storage); 981 982 if (cert != null) { 983 return cert; 984 } 985 } 986 } 987 } 988 } 989 currentChild=currentChild.getNextSibling(); 990 } 991 } 992 993 return null; 994 } 995 996 1001 public SecretKey getSecretKey() throws KeyResolverException { 1002 SecretKey sk = this.getSecretKeyFromInternalResolvers(); 1003 1004 if (sk != null) { 1005 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I could find a secret key using the per-KeyInfo key resolvers"); 1006 1007 return sk; 1008 } 1009 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I couldn't find a secret key using the per-KeyInfo key resolvers"); 1010 1011 1012 sk = this.getSecretKeyFromStaticResolvers(); 1013 1014 if (sk != null) { 1015 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I could find a secret key using the system-wide key resolvers"); 1016 1017 return sk; 1018 } 1019 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I couldn't find a secret key using the system-wide key resolvers"); 1020 1021 1022 return null; 1023 } 1024 1025 1031 1032 SecretKey getSecretKeyFromStaticResolvers() throws KeyResolverException { 1033 1034 for (int i = 0; i < KeyResolver.length(); i++) { 1035 KeyResolver keyResolver = KeyResolver.item(i); 1036 1037 Node currentChild=this._constructionElement.getFirstChild(); 1038 while (currentChild!=null) { 1039 if (currentChild.getNodeType() == Node.ELEMENT_NODE) { 1040 if (this._storageResolvers.size() == 0) { 1041 1042 StorageResolver storage = null; 1044 1045 if (keyResolver.canResolve((Element ) currentChild, 1046 this.getBaseURI(), storage)) { 1047 SecretKey sk = 1048 keyResolver.resolveSecretKey((Element ) currentChild, 1049 this.getBaseURI(), 1050 storage); 1051 1052 if (sk != null) { 1053 return sk; 1054 } 1055 } 1056 } else { 1057 for (int k = 0; k < this._storageResolvers.size(); k++) { 1058 StorageResolver storage = 1059 (StorageResolver) this._storageResolvers.get(k); 1060 1061 if (keyResolver.canResolve((Element ) currentChild, 1062 this.getBaseURI(), storage)) { 1063 SecretKey sk = 1064 keyResolver.resolveSecretKey((Element ) currentChild, 1065 this.getBaseURI(), 1066 storage); 1067 1068 if (sk != null) { 1069 return sk; 1070 } 1071 } 1072 } 1073 } 1074 } 1075 currentChild=currentChild.getNextSibling(); 1076 } 1077 } 1078 return null; 1079 } 1080 1081 1087 1088 SecretKey getSecretKeyFromInternalResolvers() throws KeyResolverException { 1089 1090 for (int i = 0; i < this.lengthInternalKeyResolver(); i++) { 1091 KeyResolverSpi keyResolver = this.itemInternalKeyResolver(i); 1092 if (true) 1093 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName()); 1094 1095 Node currentChild=this._constructionElement.getFirstChild(); 1096 while (currentChild!=null) { 1097 if (currentChild.getNodeType() == Node.ELEMENT_NODE) { 1098 if (this._storageResolvers.size() == 0) { 1099 1100 StorageResolver storage = null; 1102 1103 if (keyResolver.engineCanResolve((Element ) currentChild, 1104 this.getBaseURI(), 1105 storage)) { 1106 SecretKey sk = 1107 keyResolver 1108 .engineResolveSecretKey((Element ) currentChild, this 1109 .getBaseURI(), storage); 1110 1111 if (sk != null) { 1112 return sk; 1113 } 1114 } 1115 } else { 1116 for (int k = 0; k < this._storageResolvers.size(); k++) { 1117 StorageResolver storage = 1118 (StorageResolver) this._storageResolvers.get(k); 1119 1120 if (keyResolver.engineCanResolve((Element ) currentChild, 1121 this.getBaseURI(), 1122 storage)) { 1123 SecretKey sk = keyResolver 1124 .engineResolveSecretKey((Element ) currentChild, this 1125 .getBaseURI(), storage); 1126 1127 if (sk != null) { 1128 return sk; 1129 } 1130 } 1131 } 1132 } 1133 } 1134 currentChild=currentChild.getNextSibling(); 1135 } 1136 } 1137 1138 return null; 1139 } 1140 1141 1144 List _internalKeyResolvers = new ArrayList (); 1145 1146 1152 public void registerInternalKeyResolver(KeyResolverSpi realKeyResolver) { 1153 this._internalKeyResolvers.add(realKeyResolver); 1154 } 1155 1156 1160 int lengthInternalKeyResolver() { 1161 return this._internalKeyResolvers.size(); 1162 } 1163 1164 1170 KeyResolverSpi itemInternalKeyResolver(int i) { 1171 return (KeyResolverSpi) this._internalKeyResolvers.get(i); 1172 } 1173 1174 1175 List _storageResolvers = new ArrayList (); 1176 1177 1182 public void addStorageResolver(StorageResolver storageResolver) { 1183 1184 if (storageResolver != null) { 1185 this._storageResolvers.add(storageResolver); 1186 } 1187 } 1188 1189 1194 List getStorageResolvers() { 1195 return this._storageResolvers; 1196 } 1197 1198 static boolean _alreadyInitialized = false; 1200 1201 public static void init() { 1202 1203 if (!KeyInfo._alreadyInitialized) { 1204 if (KeyInfo.log == null) { 1205 1206 1210 KeyInfo.log = 1211 java.util.logging.Logger.getLogger(KeyInfo.class.getName()); 1212 1213 log.log(java.util.logging.Level.SEVERE, "Had to assign log in the init() function"); 1214 } 1215 1216 KeyInfo._alreadyInitialized = true; 1218 } 1219 } 1220 1221 1222 public String getBaseLocalName() { 1223 return Constants._TAG_KEYINFO; 1224 } 1225} 1226 | Popular Tags |