DataStore implements DataCacheProvider, RolesProvider { boolean loadAthenzPublicKeys() { final String rootDir = ZTSImpl.getRootDir(); String confFileName = System.getProperty(PROP_ATHENZ_CONF, rootDir + "/conf/athenz/athenz.conf"); Path path = Paths.get(confFileName); AthenzConfig conf; try { conf = JSON.fromBytes(Files.readAllBytes(path), AthenzConfig.class); final ArrayList<com.yahoo.athenz.zms.PublicKeyEntry> zmsPublicKeys = conf.getZmsPublicKeys(); if (zmsPublicKeys == null) { LOGGER.error("Conf file {} has no ZMS Public keys", confFileName); return false; } for (com.yahoo.athenz.zms.PublicKeyEntry publicKey : zmsPublicKeys) { final String id = publicKey.getId(); final String key = publicKey.getKey(); if (key == null || id == null) { LOGGER.error("Missing required zms public key attributes: {}/{}", id, key); continue; } zmsPublicKeyCache.put(id, Crypto.loadPublicKey(Crypto.ybase64DecodeString(key))); } if (zmsPublicKeyCache.size() == 0) { LOGGER.error("No valid public ZMS keys in conf file: {}", confFileName); return false; } final ArrayList<com.yahoo.athenz.zms.PublicKeyEntry> ztsPublicKeys = conf.getZtsPublicKeys(); if (ztsPublicKeys == null) { LOGGER.error("Conf file {} has no ZTS Public keys", confFileName); return false; } final List<JWK> jwkList = new ArrayList<>(); final List<JWK> jwkListStrictRFC = new ArrayList<>(); for (com.yahoo.athenz.zms.PublicKeyEntry publicKey : ztsPublicKeys) { final String id = publicKey.getId(); final String key = publicKey.getKey(); if (key == null || id == null) { LOGGER.error("Missing required zts public key attributes: {}/{}", id, key); continue; } final JWK jwk = getJWK(key, id, false); if (jwk != null) { jwkList.add(jwk); } final JWK jwkRfc = getJWK(key, id, true); if (jwkRfc != null) { jwkListStrictRFC.add(jwkRfc); } } if (jwkList.isEmpty() || jwkListStrictRFC.isEmpty()) { LOGGER.error("No valid public ZTS keys in conf file: {}", confFileName); return false; } ztsJWKList.setKeys(jwkList); ztsJWKListStrictRFC.setKeys(jwkListStrictRFC); } catch (IOException ex) { LOGGER.error("Unable to parse conf file {}, error: {}", confFileName, ex.getMessage()); return false; } return true; } DataStore(ChangeLogStore clogStore, CloudStore cloudStore); JWKList getZtsJWKList(Boolean rfc); void init(); boolean processDomain(SignedDomain signedDomain, boolean saveInStore); boolean processDomainDeletes(); void processDomainChecks(); boolean processDomainUpdates(); DomainData getDomainData(String name); void addDomainToCache(String name, DataCache dataCache); @Override DataCache getDataCache(String domainName); List<GroupMember> getGroupMembers(final String groupName); void getAccessibleRoles(DataCache data, String domainName, String identity,
            String[] requestedRoleList, Set<String> accessibleRoles, boolean keepFullName); String getPublicKey(String domain, String service, String keyId); HostServices getHostServices(String host); CloudStore getCloudStore(); void setCloudStore(CloudStore cloudStore); Cache<String, DataCache> getCacheStore(); Map<String, String> getPublicKeyCache(); @Override List<Role> getRolesByDomain(String domain);  }
@Test public void testLoadZMSPublicKeys() { System.setProperty(PROP_ATHENZ_CONF, "src/test/resources/athenz.conf"); ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); store.loadAthenzPublicKeys(); PublicKey zmsKey = store.zmsPublicKeyCache.getIfPresent("0"); assertNotNull(zmsKey); assertNull(store.zmsPublicKeyCache.getIfPresent("1")); }