Search in sources :

Example 1 with AthenzConfig

use of com.yahoo.athenz.common.config.AthenzConfig in project athenz by yahoo.

the class FilePublicKeyStore method init.

public void init() {
    String rootDir = System.getenv("ROOT");
    if (rootDir == null) {
        rootDir = "/home/athenz";
    }
    String confFileName = System.getProperty(ZpeConsts.ZPE_PROP_ATHENZ_CONF, rootDir + ZPE_ATHENZ_CONFIG);
    try {
        Path path = Paths.get(confFileName);
        AthenzConfig conf = JSON.fromBytes(Files.readAllBytes(path), AthenzConfig.class);
        loadPublicKeys(conf.getZtsPublicKeys(), ztsPublicKeyMap);
        loadPublicKeys(conf.getZmsPublicKeys(), zmsPublicKeyMap);
    } catch (Exception ex) {
        LOG.error("Unable to extract ZMS Url from {} exc: {}", confFileName, ex.getMessage());
        return;
    }
}
Also used : Path(java.nio.file.Path) AthenzConfig(com.yahoo.athenz.common.config.AthenzConfig)

Example 2 with AthenzConfig

use of com.yahoo.athenz.common.config.AthenzConfig in project athenz by yahoo.

the class ZMSClient method lookupZMSUrl.

String lookupZMSUrl() {
    String rootDir = System.getenv(STR_ENV_ROOT);
    if (rootDir == null) {
        rootDir = STR_DEF_ROOT;
    }
    String confFileName = System.getProperty(ZMS_CLIENT_PROP_ATHENZ_CONF, rootDir + "/conf/athenz/athenz.conf");
    String url = null;
    try {
        Path path = Paths.get(confFileName);
        AthenzConfig conf = JSON.fromBytes(Files.readAllBytes(path), AthenzConfig.class);
        url = conf.getZmsUrl();
    } catch (Exception ex) {
        LOGGER.error("Unable to extract ZMS Url from {} exc: {}", confFileName, ex.getMessage());
    }
    return url;
}
Also used : Path(java.nio.file.Path) AthenzConfig(com.yahoo.athenz.common.config.AthenzConfig)

Example 3 with AthenzConfig

use of com.yahoo.athenz.common.config.AthenzConfig in project athenz by yahoo.

the class DataStore method loadZMSPublicKeys.

void loadZMSPublicKeys() {
    final String rootDir = ZTSImpl.getRootDir();
    String confFileName = System.getProperty(ZTSConsts.ZTS_PROP_ATHENZ_CONF, rootDir + "/conf/athenz/athenz.conf");
    Path path = Paths.get(confFileName);
    AthenzConfig conf = null;
    try {
        conf = JSON.fromBytes(Files.readAllBytes(path), AthenzConfig.class);
        ArrayList<com.yahoo.athenz.zms.PublicKeyEntry> publicKeys = conf.getZmsPublicKeys();
        if (publicKeys != null) {
            for (com.yahoo.athenz.zms.PublicKeyEntry publicKey : publicKeys) {
                String id = publicKey.getId();
                String key = publicKey.getKey();
                if (key == null || id == null) {
                    continue;
                }
                PublicKey zmsKey = Crypto.loadPublicKey(Crypto.ybase64DecodeString(key));
                zmsPublicKeyCache.put(id, zmsKey);
            }
        }
    } catch (IOException e) {
        LOGGER.info("Unable to parse conf file " + confFileName);
        return;
    }
}
Also used : Path(java.nio.file.Path) AthenzConfig(com.yahoo.athenz.common.config.AthenzConfig) PublicKey(java.security.PublicKey) IOException(java.io.IOException)

Example 4 with AthenzConfig

use of com.yahoo.athenz.common.config.AthenzConfig in project athenz by yahoo.

the class ZTSClient method lookupZTSUrl.

public static void lookupZTSUrl() {
    String rootDir = System.getenv("ROOT");
    if (rootDir == null) {
        rootDir = "/home/athenz";
    }
    String confFileName = System.getProperty(ZTS_CLIENT_PROP_ATHENZ_CONF, rootDir + "/conf/athenz/athenz.conf");
    try {
        Path path = Paths.get(confFileName);
        AthenzConfig conf = JSON.fromBytes(Files.readAllBytes(path), AthenzConfig.class);
        confZtsUrl = conf.getZtsUrl();
    } catch (Exception ex) {
        // if we have a zts client service specified and we have keys
        // in our service loader cache then we're running within
        // some managed framework (e.g. hadoop) so we're going to
        // report this exception as a warning rather than an error
        // and default to localhost as the url to avoid further
        // warnings from our generated client
        LOG.warn("Unable to extract ZTS Url from conf file {}, exc: {}", confFileName, ex.getMessage());
        if (!svcLoaderCacheKeys.get().isEmpty()) {
            confZtsUrl = "https://localhost:4443/";
        }
    }
}
Also used : Path(java.nio.file.Path) AthenzConfig(com.yahoo.athenz.common.config.AthenzConfig) DERIA5String(org.bouncycastle.asn1.DERIA5String) OperatorCreationException(org.bouncycastle.operator.OperatorCreationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CertificateParsingException(java.security.cert.CertificateParsingException) CryptoException(com.yahoo.athenz.auth.util.CryptoException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException)

Example 5 with AthenzConfig

use of com.yahoo.athenz.common.config.AthenzConfig in project athenz by yahoo.

the class PolicyUpdaterConfiguration method init.

public void init(String pathToAthenzConfigFile, String pathToZPUConfigFile) throws Exception {
    AthenzConfig athenzConfFile = null;
    if (pathToAthenzConfigFile == null) {
        athenzConfFile = readAthenzConfiguration(defaultAthenzConfigFile);
    } else {
        athenzConfFile = readAthenzConfiguration(pathToAthenzConfigFile);
    }
    LOG.info("Policy Updater configuration is set to:");
    LOG.info("policyFileDir: " + policyFileDir);
    List<PublicKeyEntry> publicKeys = athenzConfFile.getZtsPublicKeys();
    if (publicKeys != null) {
        for (PublicKeyEntry publicKey : publicKeys) {
            String keyId = publicKey.getId();
            String key = publicKey.getKey();
            if (key == null || keyId == null) {
                continue;
            }
            addZtsPublicKey(keyId, Crypto.loadPublicKey(Crypto.ybase64DecodeString(key)));
            LOG.info("Loaded ztsPublicKey keyId: " + keyId + " key: " + key);
        }
    }
    publicKeys = athenzConfFile.getZmsPublicKeys();
    if (publicKeys != null) {
        for (PublicKeyEntry publicKey : publicKeys) {
            String keyId = publicKey.getId();
            String key = publicKey.getKey();
            if (key == null || keyId == null) {
                continue;
            }
            addZmsPublicKey(keyId, Crypto.loadPublicKey(Crypto.ybase64DecodeString(key)));
            LOG.info("Loaded zmsPublicKey keyId: " + keyId + " key: " + key);
        }
    }
    Struct zpuConfFile = null;
    if (pathToZPUConfigFile == null) {
        zpuConfFile = readZpuConfiguration(defaultZPUConfigFile);
    } else {
        zpuConfFile = readZpuConfiguration(pathToZPUConfigFile);
    }
    String domains = zpuConfFile.getString(ZPU_CONFIG_DOMAINS);
    if (domains != null && !domains.isEmpty()) {
        domainList = Arrays.asList(domains.split(","));
    }
    zpuDirOwner = zpuConfFile.getString(ZPU_CONFIG_USER);
    if (zpuDirOwner == null || zpuDirOwner.isEmpty()) {
        zpuDirOwner = ZPU_USER_DEFAULT;
    }
    if (isDebugMode()) {
        LOG.debug("config-init: user: " + zpuDirOwner + " file=" + pathToZPUConfigFile);
    }
}
Also used : PublicKeyEntry(com.yahoo.athenz.zms.PublicKeyEntry) AthenzConfig(com.yahoo.athenz.common.config.AthenzConfig) Struct(com.yahoo.rdl.Struct)

Aggregations

AthenzConfig (com.yahoo.athenz.common.config.AthenzConfig)6 Path (java.nio.file.Path)5 IOException (java.io.IOException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 CryptoException (com.yahoo.athenz.auth.util.CryptoException)1 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)1 Struct (com.yahoo.rdl.Struct)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 PublicKey (java.security.PublicKey)1 CertificateParsingException (java.security.cert.CertificateParsingException)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 DERIA5String (org.bouncycastle.asn1.DERIA5String)1 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)1