InstanceCertManager { boolean loadAllowedIPAddresses(List<IPBlock> ipBlocks, final String ipAddressFileName) { if (ipAddressFileName == null || ipAddressFileName.isEmpty()) { return true; } byte[] data = readFileContents(ipAddressFileName); if (data == null) { return false; } IPPrefixes prefixes = null; try { prefixes = jsonMapper.readValue(data, IPPrefixes.class); } catch (Exception ex) { LOGGER.error("Unable to parse IP file: {} - {}", ipAddressFileName, ex.getMessage()); } if (prefixes == null) { return false; } List<IPPrefix> prefixList = prefixes.getPrefixes(); if (prefixList == null || prefixList.isEmpty()) { LOGGER.error("No prefix entries available in the IP file: {}", ipAddressFileName); return false; } for (IPPrefix prefix : prefixList) { final String ipEntry = prefix.getIpv4Prefix(); if (ipEntry == null) { continue; } try { ipBlocks.add(new IPBlock(ipEntry)); } catch (Exception ex) { LOGGER.error("Skipping invalid ip block entry: {}, error: {}", ipEntry, ex.getMessage()); return false; } } return true; } InstanceCertManager(final PrivateKeyStore keyStore, Authorizer authorizer, HostnameResolver hostnameResolver,
            boolean readOnlyMode); void setCertStore(CertRecordStore certStore); void setSSHStore(SSHRecordStore sshStore); CertificateAuthorityBundle getCertificateAuthorityBundle(final String name); List<X509CertRecord> getUnrefreshedCertsNotifications(String serverHostName, String provider); X509CertRecord getX509CertRecord(final String provider, X509Certificate cert); X509CertRecord getX509CertRecord(final String provider, final String instanceId,
            final String service); boolean updateX509CertRecord(X509CertRecord certRecord); boolean deleteX509CertRecord(final String provider, final String instanceId,
            final String service); boolean insertX509CertRecord(X509CertRecord certRecord); String generateX509Certificate(final String csr, final String keyUsage, int expiryTime); String getCACertificate(); InstanceIdentity generateIdentity(String csr, String cn, String keyUsage,
            int expiryTime); String getX509CertificateSigner(); SSHCertificates generateSSHCertificates(Principal principal, SSHCertRequest certRequest); boolean generateSSHIdentity(Principal principal, InstanceIdentity identity, final String hostname,
            final String csr, SSHCertRecord sshCertRecord, final String certType); boolean authorizeLaunch(Principal providerService, String domain, String service,
            StringBuilder errorMsg); boolean verifyCertRefreshIPAddress(final String ipAddress); boolean verifyInstanceCertIPAddress(final String provider, final String ipAddress); boolean validPrincipals(final String hostname, SSHCertRecord sshCertRecord, SshHostCsr sshHostCsr); void logX509Cert(final Principal principal, final String ip, final String provider,
            final String instanceId, final X509Certificate x509Cert); SSHCertRecord getSSHCertRecord(final String instanceId, final String service); boolean updateSSHCertRecord(SSHCertRecord certRecord, boolean refresh); boolean enableCertStoreNotifications(NotificationManager notificationManager, RolesProvider rolesProvider, String serverName); boolean enableSSHStoreNotifications(NotificationManager notificationManager, RolesProvider rolesProvider, String serverName);  }
@Test public void testLoadAllowedIPAddresses() { List<IPBlock> ipBlocks = new ArrayList<>(); InstanceCertManager instance = new InstanceCertManager(null, null, null, true); instance.setCertSigner(null); assertTrue(instance.loadAllowedIPAddresses(ipBlocks, null)); assertTrue(instance.loadAllowedIPAddresses(ipBlocks, "")); assertFalse(instance.loadAllowedIPAddresses(ipBlocks, "some-invalid-filename")); assertFalse(instance.loadAllowedIPAddresses(ipBlocks, "src/test/resources/invalid_ipblocks.txt")); assertFalse(instance.loadAllowedIPAddresses(ipBlocks, "src/test/resources/empty_ipblocks.txt")); instance.shutdown(); }