Search in sources :

Example 1 with ZpmSecurity

use of io.aklivity.zilla.manager.internal.settings.ZpmSecurity in project zilla by aklivity.

the class ZpmInstall method readSettings.

private void readSettings(Path settingsDir) throws IOException, PlexusCipherException {
    Path settingsFile = settingsDir.resolve("settings.json");
    ZpmSettings settings = new ZpmSettings();
    settings.credentials = emptyList();
    Jsonb builder = JsonbBuilder.newBuilder().withConfig(new JsonbConfig().withFormatting(true)).build();
    if (Files.exists(settingsFile)) {
        try (InputStream in = newInputStream(settingsFile)) {
            settings = builder.fromJson(in, ZpmSettings.class);
        }
    }
    if (settings.credentials.size() > 0) {
        Path securityFile = settingsDir.resolve("security.json");
        ZpmSecurity security = new ZpmSecurity();
        if (Files.exists(securityFile)) {
            try (InputStream in = newInputStream(securityFile)) {
                security = builder.fromJson(in, ZpmSecurity.class);
            }
        }
        security.secret = decryptSecret(security.secret, SYSTEM_PROPERTY_SEC_LOCATION);
        for (ZpmCredentials credentials : settings.credentials) {
            String realm = defaultRealmIfNecessary(credentials);
            String host = credentials.host;
            String username = credentials.username;
            String password = ZpmSecrets.decryptSecret(credentials.password, security.secret);
            CredentialsStore.INSTANCE.addCredentials(realm, host, username, password);
        }
    }
}
Also used : Path(java.nio.file.Path) ZpmSettings(io.aklivity.zilla.manager.internal.settings.ZpmSettings) Jsonb(jakarta.json.bind.Jsonb) JsonbConfig(jakarta.json.bind.JsonbConfig) ZpmCredentials(io.aklivity.zilla.manager.internal.settings.ZpmCredentials) Files.newInputStream(java.nio.file.Files.newInputStream) InputStream(java.io.InputStream) ZpmSecurity(io.aklivity.zilla.manager.internal.settings.ZpmSecurity)

Example 2 with ZpmSecurity

use of io.aklivity.zilla.manager.internal.settings.ZpmSecurity in project zilla by aklivity.

the class ZpmEncrypt method readSecurity.

private ZpmSecurity readSecurity(Path settingsDir) throws IOException, PlexusCipherException {
    Path securityFile = settingsDir.resolve("security.json");
    ZpmSecurity security = new ZpmSecurity();
    Jsonb builder = JsonbBuilder.newBuilder().withConfig(new JsonbConfig().withFormatting(true)).build();
    if (Files.exists(securityFile)) {
        try (InputStream in = newInputStream(securityFile)) {
            security = builder.fromJson(in, ZpmSecurity.class);
        }
    }
    return security;
}
Also used : Path(java.nio.file.Path) Jsonb(jakarta.json.bind.Jsonb) JsonbConfig(jakarta.json.bind.JsonbConfig) Files.newInputStream(java.nio.file.Files.newInputStream) InputStream(java.io.InputStream) ZpmSecurity(io.aklivity.zilla.manager.internal.settings.ZpmSecurity)

Example 3 with ZpmSecurity

use of io.aklivity.zilla.manager.internal.settings.ZpmSecurity in project zilla by aklivity.

the class ZpmEncrypt method invoke.

@Override
public void invoke() {
    try {
        ZpmSecurity security = readSecurity(settingsDir);
        if (security.secret == null) {
            final String secret = generateSecret(32);
            security.secret = encryptSecret(secret, SYSTEM_PROPERTY_SEC_LOCATION);
            writeSecurity(security);
        }
        assert security.secret != null;
        final String secret = decryptSecret(security.secret, SYSTEM_PROPERTY_SEC_LOCATION);
        try (Scanner scanner = new Scanner(System.in)) {
            String password = scanner.nextLine().trim();
            String encrypted = encryptSecret(password, secret);
            System.out.println(encrypted);
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : Scanner(java.util.Scanner) IOException(java.io.IOException) PlexusCipherException(org.sonatype.plexus.components.cipher.PlexusCipherException) ZpmSecurity(io.aklivity.zilla.manager.internal.settings.ZpmSecurity)

Aggregations

ZpmSecurity (io.aklivity.zilla.manager.internal.settings.ZpmSecurity)3 Jsonb (jakarta.json.bind.Jsonb)2 JsonbConfig (jakarta.json.bind.JsonbConfig)2 InputStream (java.io.InputStream)2 Files.newInputStream (java.nio.file.Files.newInputStream)2 Path (java.nio.file.Path)2 ZpmCredentials (io.aklivity.zilla.manager.internal.settings.ZpmCredentials)1 ZpmSettings (io.aklivity.zilla.manager.internal.settings.ZpmSettings)1 IOException (java.io.IOException)1 Scanner (java.util.Scanner)1 PlexusCipherException (org.sonatype.plexus.components.cipher.PlexusCipherException)1