Changeset 16120 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2020-03-14T15:03:18+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r15716 r16120 53 53 import java.security.NoSuchAlgorithmException; 54 54 import java.security.cert.Certificate; 55 import java.security.cert.CertificateEncodingException; 55 56 import java.security.cert.CertificateException; 56 57 import java.security.cert.X509Certificate; … … 340 341 public X509Certificate getX509Certificate(NativeCertAmend certAmend) 341 342 throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { 343 MessageDigest md = MessageDigest.getInstance("SHA-256"); 342 344 // Get Windows Trust Root Store 343 345 KeyStore ks = getRootKeystore(); … … 345 347 for (String winAlias : certAmend.getNativeAliases()) { 346 348 Certificate result = ks.getCertificate(winAlias); 349 // Check for SHA-256 signature, as sometimes Microsoft can ship several certificates with the same alias, for example: 350 // AC RAIZ FNMT-RCM: EBC5570C29018C4D67B1AA127BAF12F703B4611EBC17B7DAB5573894179B93FA (SHA256) 351 // AC RAIZ FNMT-RCM: 4D9EBB28825C9643AB15D54E5F9614F13CB3E95DE3CF4EAC971301F320F9226E (SHA1) 352 if (!sha256matches(result, certAmend, md)) { 353 Logging.trace("Ignoring {0} as SHA-256 signature does not match", result); 354 result = null; 355 } 347 356 if (result == null && !NetworkManager.isOffline(OnlineResource.CERTIFICATES)) { 348 357 // Make a web request to target site to force Windows to update if needed its trust root store from its certificate trust list … … 360 369 } 361 370 // If not found, search by SHA-256 (slower) 362 MessageDigest md = MessageDigest.getInstance("SHA-256");363 371 for (Enumeration<String> aliases = ks.aliases(); aliases.hasMoreElements();) { 364 372 String alias = aliases.nextElement(); 365 373 Certificate result = ks.getCertificate(alias); 366 if (result instanceof X509Certificate 367 && certAmend.getSha256().equalsIgnoreCase(Utils.toHexString(md.digest(result.getEncoded())))) { 374 if (sha256matches(result, certAmend, md)) { 368 375 Logging.warn("Certificate not found for alias ''{0}'' but found for alias ''{1}''", certAmend.getNativeAliases(), alias); 369 376 return (X509Certificate) result; … … 372 379 // Not found 373 380 return null; 381 } 382 383 private static boolean sha256matches(Certificate result, NativeCertAmend certAmend, MessageDigest md) throws CertificateEncodingException { 384 return result instanceof X509Certificate 385 && certAmend.getSha256().equalsIgnoreCase(Utils.toHexString(md.digest(result.getEncoded()))); 374 386 } 375 387
Note:
See TracChangeset
for help on using the changeset viewer.
