Changeset 10083 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2016-03-30T18:38:06+02:00 (9 years ago)
Author:
wiktorn
Message:

Check for certificate SHA-2 fingerprint instead of SHA-2 of PEM file.

Fixes problems due to different line endings on different systems / builds on Windows

Closes: #12264

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/CertificateAmendment.java

    r10079 r10083  
    4848
    4949    private static final String[] SHA_HASHES = {
    50         "139a5e4a4e0fa505378c72c5f700934ce8333f4e6b1b508886c4b0eb14f4be99",
    51         "916a8f9232328192968c81c8edb672fa539f726861dfe379ca722050e19962cd"
     50        "0687260331a72403d909f105e69bcf0d32e1bd2493ffc6d9206d11bcd6770739",
     51        "c766a9bef2d4071c863a31aa4920e813b2d198608cb7b7cfe21143b836df09ea"
    5252    };
    5353
     
    8787        for (int i = 0; i < CERT_AMEND.length; i++) {
    8888            CachedFile certCF = new CachedFile(CERT_AMEND[i]);
    89             MessageDigest md;
     89            byte[] certBytes = certCF.getByteContent();
     90            ByteArrayInputStream certIS = new ByteArrayInputStream(certBytes);
     91            X509Certificate cert;
     92
    9093            try {
    91                 md = MessageDigest.getInstance("SHA-256");
     94                cert = (X509Certificate) cf.generateCertificate(certIS);
     95                MessageDigest md = MessageDigest.getInstance("SHA-256");
     96                String sha1 = Utils.toHexString(md.digest(cert.getEncoded()));
     97                if (!SHA_HASHES[i].equals(sha1)) {
     98                    throw new RuntimeException(tr("Error adding certificate {0} - certificate fingerprint mismatch. Expected {1}, was {2}",
     99                            CERT_AMEND[i],
     100                            SHA_HASHES[i],
     101                            sha1
     102                            ));
     103                }
     104            } catch (CertificateException ex) {
     105                throw new IOException(ex);
    92106            } catch (NoSuchAlgorithmException ex) {
    93107                throw new RuntimeException(ex);
    94             }
    95             byte[] certBytes = certCF.getByteContent();
    96             byte[] sha = md.digest(certBytes);
    97             if (!SHA_HASHES[i].equals(Utils.toHexString(sha)))
    98                 throw new RuntimeException(tr("Error adding certificate {0} - hash mismatch. Expected {1}, was {2}",
    99                         CERT_AMEND[i], SHA_HASHES[i], Utils.toHexString(sha)));
    100 
    101             ByteArrayInputStream certIS = new ByteArrayInputStream(certBytes);
    102             X509Certificate cert;
    103             try {
    104                 cert = (X509Certificate) cf.generateCertificate(certIS);
    105             } catch (CertificateException ex) {
    106                 throw new IOException(ex);
    107108            }
    108109            if (certificateIsMissing(keyStore, cert)) {
Note: See TracChangeset for help on using the changeset viewer.