Ignore:
Timestamp:
2017-04-17T14:07:04+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #14649 - load Dutch Government (G2 & G3) certificates from Windows keystore if not found in Java keystore

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/PlatformHook.java

    r11642 r11943  
    99import java.security.NoSuchAlgorithmException;
    1010import java.security.cert.CertificateException;
     11import java.security.cert.X509Certificate;
    1112import java.util.List;
     13
     14import org.openstreetmap.josm.io.CertificateAmendment.CertAmend;
    1215
    1316/**
     
    154157
    155158    /**
     159     * Returns the {@code X509Certificate} matching the given certificate amendment information.
     160     * @param certAmend certificate amendment
     161     * @return the {@code X509Certificate} matching the given certificate amendment information, or {@code null}
     162     * @throws KeyStoreException in case of error
     163     * @throws IOException in case of error
     164     * @throws CertificateException in case of error
     165     * @throws NoSuchAlgorithmException in case of error
     166     * @since 11940
     167     */
     168    default X509Certificate getX509Certificate(CertAmend certAmend)
     169            throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
     170        return null;
     171    }
     172
     173    /**
    156174     * Returns the platform-dependent default cache directory.
    157175     * @return the platform-dependent default cache directory
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java

    r11939 r11943  
    4545import java.security.KeyStore;
    4646import java.security.KeyStoreException;
     47import java.security.MessageDigest;
    4748import java.security.NoSuchAlgorithmException;
    4849import java.security.NoSuchProviderException;
    4950import java.security.PublicKey;
    5051import java.security.SignatureException;
     52import java.security.cert.Certificate;
    5153import java.security.cert.CertificateException;
     54import java.security.cert.X509Certificate;
    5255import java.security.spec.InvalidKeySpecException;
    5356import java.security.spec.X509EncodedKeySpec;
     
    6467import org.openstreetmap.josm.Main;
    6568import org.openstreetmap.josm.data.Preferences;
     69import org.openstreetmap.josm.io.CertificateAmendment.CertAmend;
    6670
    6771/**
    68   * {@code PlatformHook} implementation for Microsoft Windows systems.
    69   * @since 1023
    70   */
     72 * {@code PlatformHook} implementation for Microsoft Windows systems.
     73 * @since 1023
     74 */
    7175public class PlatformHookWindows implements PlatformHook {
    7276
     
    351355        ks.setEntry(entryAlias, trustedCert, null);
    352356        return true;
     357    }
     358
     359    @Override
     360    public X509Certificate getX509Certificate(CertAmend certAmend)
     361            throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
     362        KeyStore ks = getRootKeystore();
     363        // Search by alias (fast)
     364        Certificate result = ks.getCertificate(certAmend.getId());
     365        if (result instanceof X509Certificate) {
     366            return (X509Certificate) result;
     367        }
     368        // If not found, search by SHA-256 (slower)
     369        MessageDigest md = MessageDigest.getInstance("SHA-256");
     370        for (Enumeration<String> aliases = ks.aliases(); aliases.hasMoreElements();) {
     371            result = ks.getCertificate(aliases.nextElement());
     372            if (result instanceof X509Certificate
     373                    && certAmend.getSha256().equalsIgnoreCase(Utils.toHexString(md.digest(result.getEncoded())))) {
     374                return (X509Certificate) result;
     375            }
     376        }
     377        // Not found
     378        return null;
    353379    }
    354380
Note: See TracChangeset for help on using the changeset viewer.