< prev index next >

src/java.base/share/classes/sun/security/util/SignatureFileVerifier.java

Print this page




 186                 }
 187                 // then check chars, must be in [a-zA-Z0-9] per the jar spec
 188                 for (int index = 0; index < ext.length(); index++) {
 189                     char cc = ext.charAt(index);
 190                     // chars are promoted to uppercase so skip lowercase checks
 191                     if ((cc < 'A' || cc > 'Z') && (cc < '0' || cc > '9')) {
 192                         return false;
 193                     }
 194                 }
 195             }
 196             return true; // no extension is OK
 197         }
 198         return false;
 199     }
 200 
 201     /** get digest from cache */
 202 
 203     private MessageDigest getDigest(String algorithm)
 204     {
 205         if (createdDigests == null)
 206             createdDigests = new HashMap<String, MessageDigest>();
 207 
 208         MessageDigest digest = createdDigests.get(algorithm);
 209 
 210         if (digest == null) {
 211             try {
 212                 digest = MessageDigest.getInstance(algorithm);
 213                 createdDigests.put(algorithm, digest);
 214             } catch (NoSuchAlgorithmException nsae) {
 215                 // ignore
 216             }
 217         }
 218         return digest;
 219     }
 220 
 221     /**
 222      * process the signature block file. Goes through the .SF file
 223      * and adds code signers for each section where the .SF section
 224      * hash was verified against the Manifest section.
 225      *
 226      *


 506         return oneDigestVerified;
 507     }
 508 
 509     /**
 510      * Given the PKCS7 block and SignerInfo[], create an array of
 511      * CodeSigner objects. We do this only *once* for a given
 512      * signature block file.
 513      */
 514     private CodeSigner[] getSigners(SignerInfo infos[], PKCS7 block)
 515         throws IOException, NoSuchAlgorithmException, SignatureException,
 516             CertificateException {
 517 
 518         ArrayList<CodeSigner> signers = null;
 519 
 520         for (int i = 0; i < infos.length; i++) {
 521 
 522             SignerInfo info = infos[i];
 523             ArrayList<X509Certificate> chain = info.getCertificateChain(block);
 524             CertPath certChain = certificateFactory.generateCertPath(chain);
 525             if (signers == null) {
 526                 signers = new ArrayList<CodeSigner>();
 527             }
 528             // Append the new code signer
 529             signers.add(new CodeSigner(certChain, info.getTimestamp()));
 530 
 531             if (debug != null) {
 532                 debug.println("Signature Block Certificate: " +
 533                     chain.get(0));
 534             }
 535         }
 536 
 537         if (signers != null) {
 538             return signers.toArray(new CodeSigner[signers.size()]);
 539         } else {
 540             return null;
 541         }
 542     }
 543 
 544     // for the toHex function
 545     private static final char[] hexc =
 546             {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};




 186                 }
 187                 // then check chars, must be in [a-zA-Z0-9] per the jar spec
 188                 for (int index = 0; index < ext.length(); index++) {
 189                     char cc = ext.charAt(index);
 190                     // chars are promoted to uppercase so skip lowercase checks
 191                     if ((cc < 'A' || cc > 'Z') && (cc < '0' || cc > '9')) {
 192                         return false;
 193                     }
 194                 }
 195             }
 196             return true; // no extension is OK
 197         }
 198         return false;
 199     }
 200 
 201     /** get digest from cache */
 202 
 203     private MessageDigest getDigest(String algorithm)
 204     {
 205         if (createdDigests == null)
 206             createdDigests = new HashMap<>();
 207 
 208         MessageDigest digest = createdDigests.get(algorithm);
 209 
 210         if (digest == null) {
 211             try {
 212                 digest = MessageDigest.getInstance(algorithm);
 213                 createdDigests.put(algorithm, digest);
 214             } catch (NoSuchAlgorithmException nsae) {
 215                 // ignore
 216             }
 217         }
 218         return digest;
 219     }
 220 
 221     /**
 222      * process the signature block file. Goes through the .SF file
 223      * and adds code signers for each section where the .SF section
 224      * hash was verified against the Manifest section.
 225      *
 226      *


 506         return oneDigestVerified;
 507     }
 508 
 509     /**
 510      * Given the PKCS7 block and SignerInfo[], create an array of
 511      * CodeSigner objects. We do this only *once* for a given
 512      * signature block file.
 513      */
 514     private CodeSigner[] getSigners(SignerInfo infos[], PKCS7 block)
 515         throws IOException, NoSuchAlgorithmException, SignatureException,
 516             CertificateException {
 517 
 518         ArrayList<CodeSigner> signers = null;
 519 
 520         for (int i = 0; i < infos.length; i++) {
 521 
 522             SignerInfo info = infos[i];
 523             ArrayList<X509Certificate> chain = info.getCertificateChain(block);
 524             CertPath certChain = certificateFactory.generateCertPath(chain);
 525             if (signers == null) {
 526                 signers = new ArrayList<>();
 527             }
 528             // Append the new code signer
 529             signers.add(new CodeSigner(certChain, info.getTimestamp()));
 530 
 531             if (debug != null) {
 532                 debug.println("Signature Block Certificate: " +
 533                     chain.get(0));
 534             }
 535         }
 536 
 537         if (signers != null) {
 538             return signers.toArray(new CodeSigner[signers.size()]);
 539         } else {
 540             return null;
 541         }
 542     }
 543 
 544     // for the toHex function
 545     private static final char[] hexc =
 546             {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};


< prev index next >