Changeset 14431 in josm for trunk/src/org
- Timestamp:
- 2018-11-19T23:13:30+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r14389 r14431 94 94 */ 95 95 public class PlatformHookWindows implements PlatformHook { 96 97 /** 98 * Pattern of Microsoft .NET and Powershell version numbers in registry. 99 */ 100 private static final Pattern MS_VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)(\\.\\d+.*)?"); 96 101 97 102 /** … … 468 473 public X509Certificate getX509Certificate(NativeCertAmend certAmend) 469 474 throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { 470 // Make a web request to target site to force Windows to update if needed its trust root store from its certificate trust list471 // A better, but a lot more complex method might be to get certificate list from Windows Registry with PowerShell472 // using (Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\SystemCertificates\\AuthRoot\\AutoUpdate').EncodedCtl)473 // then decode it using CertUtil -dump or calling CertCreateCTLContext API using JNI, and finally find and decode the certificate474 Logging.trace(webRequest(certAmend.getWebSite()));475 475 // Get Windows Trust Root Store 476 476 KeyStore ks = getRootKeystore(); 477 477 // Search by alias (fast) 478 478 Certificate result = ks.getCertificate(certAmend.getWinAlias()); 479 if (result == null) { 480 // Make a web request to target site to force Windows to update if needed its trust root store from its certificate trust list 481 // A better, but a lot more complex method might be to get certificate list from Windows Registry with PowerShell 482 // using (Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\SystemCertificates\\AuthRoot\\AutoUpdate').EncodedCtl) 483 // then decode it using CertUtil -dump or calling CertCreateCTLContext API using JNI, and finally find and decode the certificate 484 Logging.trace(webRequest(certAmend.getWebSite())); 485 // Reload Windows Trust Root Store and search again by alias (fast) 486 ks = getRootKeystore(); 487 result = ks.getCertificate(certAmend.getWinAlias()); 488 } 479 489 if (result instanceof X509Certificate) { 480 490 return (X509Certificate) result; … … 730 740 String version = WinRegistry.readString(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", "Version"); 731 741 if (version != null) { 732 Matcher m = Pattern.compile("(\\d+)\\.(\\d+)(\\.\\d+.*)?").matcher(version);742 Matcher m = MS_VERSION_PATTERN.matcher(version); 733 743 if (m.matches()) { 734 744 int maj = Integer.parseInt(m.group(1)); … … 750 760 public static int getPowerShellVersion() { 751 761 try { 752 return Integer.parseInt(Utils.execOutput(Arrays.asList( 753 "powershell", "-Command", "$PSVersionTable.PSVersion.Major"), 2, TimeUnit.SECONDS)); 754 } catch (ExecutionException e) { 755 // PowerShell 2.0 (included in Windows 7) does not even support this 756 Logging.debug(e); 757 return -1; 758 } catch (NumberFormatException | IOException | InterruptedException e) { 762 String version = WinRegistry.readString( 763 HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Powershell\\3\\PowershellEngine", "PowershellVersion"); 764 if (version != null) { 765 Matcher m = MS_VERSION_PATTERN.matcher(version); 766 if (m.matches()) { 767 return Integer.parseInt(m.group(1)); 768 } 769 } 770 } catch (NumberFormatException | IllegalAccessException | InvocationTargetException e) { 759 771 Logging.error(e); 760 return -1;761 }772 } 773 return -1; 762 774 } 763 775
Note:
See TracChangeset
for help on using the changeset viewer.