576 Enumeration<String> entryNames(CodeSource[] cs) {
577 ensureInitialization();
578 if (jv != null) {
579 return jv.entryNames(this, cs);
580 }
581
582 /*
583 * JAR file has no signed content. Is there a non-signing
584 * code source?
585 */
586 boolean includeUnsigned = false;
587 for (CodeSource c : cs) {
588 if (c.getCodeSigners() == null) {
589 includeUnsigned = true;
590 break;
591 }
592 }
593 if (includeUnsigned) {
594 return unsignedEntryNames();
595 } else {
596 return new Enumeration<String>() {
597
598 public boolean hasMoreElements() {
599 return false;
600 }
601
602 public String nextElement() {
603 throw new NoSuchElementException();
604 }
605 };
606 }
607 }
608
609 /**
610 * Returns an enumeration of the zip file entries
611 * excluding internal JAR mechanism entries and including
612 * signed entries missing from the ZIP directory.
613 */
614 Enumeration<JarEntry> entries2() {
615 ensureInitialization();
616 if (jv != null) {
617 return jv.entries2(this, super.entries());
618 }
619
620 // screen out entries which are never signed
621 final Enumeration<? extends ZipEntry> enum_ = super.entries();
622 return new Enumeration<JarEntry>() {
623
624 ZipEntry entry;
625
626 public boolean hasMoreElements() {
627 if (entry != null) {
628 return true;
629 }
630 while (enum_.hasMoreElements()) {
631 ZipEntry ze = enum_.nextElement();
632 if (JarVerifier.isSigningRelated(ze.getName())) {
633 continue;
634 }
635 entry = ze;
636 return true;
637 }
638 return false;
639 }
640
641 public JarFileEntry nextElement() {
642 if (hasMoreElements()) {
652 CodeSource[] getCodeSources(URL url) {
653 ensureInitialization();
654 if (jv != null) {
655 return jv.getCodeSources(this, url);
656 }
657
658 /*
659 * JAR file has no signed content. Is there a non-signing
660 * code source?
661 */
662 Enumeration<String> unsigned = unsignedEntryNames();
663 if (unsigned.hasMoreElements()) {
664 return new CodeSource[]{JarVerifier.getUnsignedCS(url)};
665 } else {
666 return null;
667 }
668 }
669
670 private Enumeration<String> unsignedEntryNames() {
671 final Enumeration<JarEntry> entries = entries();
672 return new Enumeration<String>() {
673
674 String name;
675
676 /*
677 * Grab entries from ZIP directory but screen out
678 * metadata.
679 */
680 public boolean hasMoreElements() {
681 if (name != null) {
682 return true;
683 }
684 while (entries.hasMoreElements()) {
685 String value;
686 ZipEntry e = entries.nextElement();
687 value = e.getName();
688 if (e.isDirectory() || JarVerifier.isSigningRelated(value)) {
689 continue;
690 }
691 name = value;
692 return true;
|
576 Enumeration<String> entryNames(CodeSource[] cs) {
577 ensureInitialization();
578 if (jv != null) {
579 return jv.entryNames(this, cs);
580 }
581
582 /*
583 * JAR file has no signed content. Is there a non-signing
584 * code source?
585 */
586 boolean includeUnsigned = false;
587 for (CodeSource c : cs) {
588 if (c.getCodeSigners() == null) {
589 includeUnsigned = true;
590 break;
591 }
592 }
593 if (includeUnsigned) {
594 return unsignedEntryNames();
595 } else {
596 return new Enumeration<>() {
597
598 public boolean hasMoreElements() {
599 return false;
600 }
601
602 public String nextElement() {
603 throw new NoSuchElementException();
604 }
605 };
606 }
607 }
608
609 /**
610 * Returns an enumeration of the zip file entries
611 * excluding internal JAR mechanism entries and including
612 * signed entries missing from the ZIP directory.
613 */
614 Enumeration<JarEntry> entries2() {
615 ensureInitialization();
616 if (jv != null) {
617 return jv.entries2(this, super.entries());
618 }
619
620 // screen out entries which are never signed
621 final Enumeration<? extends ZipEntry> enum_ = super.entries();
622 return new Enumeration<>() {
623
624 ZipEntry entry;
625
626 public boolean hasMoreElements() {
627 if (entry != null) {
628 return true;
629 }
630 while (enum_.hasMoreElements()) {
631 ZipEntry ze = enum_.nextElement();
632 if (JarVerifier.isSigningRelated(ze.getName())) {
633 continue;
634 }
635 entry = ze;
636 return true;
637 }
638 return false;
639 }
640
641 public JarFileEntry nextElement() {
642 if (hasMoreElements()) {
652 CodeSource[] getCodeSources(URL url) {
653 ensureInitialization();
654 if (jv != null) {
655 return jv.getCodeSources(this, url);
656 }
657
658 /*
659 * JAR file has no signed content. Is there a non-signing
660 * code source?
661 */
662 Enumeration<String> unsigned = unsignedEntryNames();
663 if (unsigned.hasMoreElements()) {
664 return new CodeSource[]{JarVerifier.getUnsignedCS(url)};
665 } else {
666 return null;
667 }
668 }
669
670 private Enumeration<String> unsignedEntryNames() {
671 final Enumeration<JarEntry> entries = entries();
672 return new Enumeration<>() {
673
674 String name;
675
676 /*
677 * Grab entries from ZIP directory but screen out
678 * metadata.
679 */
680 public boolean hasMoreElements() {
681 if (name != null) {
682 return true;
683 }
684 while (entries.hasMoreElements()) {
685 String value;
686 ZipEntry e = entries.nextElement();
687 value = e.getName();
688 if (e.isDirectory() || JarVerifier.isSigningRelated(value)) {
689 continue;
690 }
691 name = value;
692 return true;
|