Search in sources :

Example 1 with SettingsSecurity

use of org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity in project fabric8 by jboss-fuse.

the class MavenPasswordAction method securityInfo.

private void securityInfo(String settings) {
    System.out.println("  Security settings file: " + settings);
    File securityFile = new File(settings);
    if (!securityFile.isFile()) {
        System.out.println("  Can't read security settings file. File is not readable...");
        return;
    }
    try {
        SettingsSecurity settingsSecurity = SecUtil.read(securityFile.getAbsolutePath(), true);
        if (decrypt) {
            if (command.cipher != null) {
                String decrypted = command.cipher.decryptDecorated(settingsSecurity.getMaster(), DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION);
                System.out.println("  Decrypted Maven master password: " + decrypted);
            } else {
                System.out.println("  Can't decrypt Maven master password: " + command.cipherInitializationProblem);
            }
        } else {
            System.out.println("  Encrypted Maven master password: " + settingsSecurity.getMaster());
        }
    } catch (Exception e) {
        System.err.println("  Problem reading security settings file: " + e.getMessage());
    }
}
Also used : SettingsSecurity(org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity) File(java.io.File) IOException(java.io.IOException) PlexusCipherException(org.sonatype.plexus.components.cipher.PlexusCipherException) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException)

Example 2 with SettingsSecurity

use of org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity in project karaf by apache.

the class PasswordCommand method doAction.

@Override
public void doAction(String prefix, Dictionary<String, Object> config) throws Exception {
    if (ep && emp) {
        System.err.println("Please specify only one of --encrypt-password and --encrypt-master-password");
        return;
    }
    if (ep && persist) {
        System.err.println("Ordinary passwords are not persisted - use the encrypted password in either <proxy> or <server>");
        return;
    }
    if (ep) {
        // encrypt password using master password
        if (masterPassword == null) {
            System.err.println("Master password is not available");
            return;
        }
        String password = session.readLine("Password to encrypt: ", '*');
        System.out.println("Encrypted password: " + cipher.encryptAndDecorate(password, masterPassword));
        System.out.println("You can use this encrypted password when defining repositories and proxies");
        return;
    }
    if (emp) {
        if (persist && !confirm("Maven security settings will be stored in new file. This file will be used in org.ops4j.pax.url.mvn.security property. Continue? (y/N) ")) {
            return;
        }
        // encrypt master password using DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION
        String password = session.readLine("Master password to encrypt: ", '*');
        String encryptedPassword = cipher.encryptAndDecorate(password, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION);
        System.out.println("Encrypted master password: " + encryptedPassword);
        if (persist) {
            SettingsSecurity settingsSecurity = new SettingsSecurity();
            settingsSecurity.setMaster(encryptedPassword);
            File dataDir = context.getDataFile(".");
            if (!dataDir.isDirectory()) {
                System.err.println("Can't access data directory for " + context.getBundle().getSymbolicName() + " bundle");
                return;
            }
            File newSecuritySettingsFile = nextSequenceFile(dataDir, RE_SECURITY_SETTINGS, PATTERN_SECURITY_SETTINGS);
            try (FileWriter fw = new FileWriter(newSecuritySettingsFile)) {
                new SecurityConfigurationXpp3Writer().write(fw, settingsSecurity);
            }
            System.out.println("New security settings stored in \"" + newSecuritySettingsFile.getCanonicalPath() + "\"");
            Configuration cmConfig = cm.getConfiguration(PID);
            config.put(prefix + PROPERTY_SECURITY_FILE, newSecuritySettingsFile.getCanonicalPath());
            cmConfig.update(config);
        }
    }
}
Also used : SettingsSecurity(org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity) Configuration(org.osgi.service.cm.Configuration) FileWriter(java.io.FileWriter) SecurityConfigurationXpp3Writer(org.sonatype.plexus.components.sec.dispatcher.model.io.xpp3.SecurityConfigurationXpp3Writer) File(java.io.File)

Example 3 with SettingsSecurity

use of org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity in project fabric8 by jboss-fuse.

the class MavenPasswordAction method findMasterMavenPassword.

/**
 * Searches for master Maven password configured in <code>settings-security.xml</code>
 * @param securitySettingsInMavenConfig
 * @param securitySettingsInAgentConfig
 * @param securitySettingsInPaxConfig
 * @param securitySettingsInImplicitLocation
 * @return
 */
private String findMasterMavenPassword(String securitySettingsInMavenConfig, String securitySettingsInAgentConfig, String securitySettingsInPaxConfig, String securitySettingsInImplicitLocation) throws SecDispatcherException, PlexusCipherException {
    if (command.cipher == null) {
        System.out.println("Can't decrypt Maven master password: " + command.cipherInitializationProblem);
        return null;
    }
    for (String loc : new String[] { securitySettingsInMavenConfig, securitySettingsInAgentConfig, securitySettingsInPaxConfig, securitySettingsInImplicitLocation }) {
        if (loc == null) {
            continue;
        }
        System.out.print("Looking up master Maven password in " + loc + "...");
        if (new File(loc).isFile()) {
            String decrypted = null;
            try {
                SettingsSecurity settingsSecurity = SecUtil.read(loc, true);
                decrypted = command.cipher.decryptDecorated(settingsSecurity.getMaster(), DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION);
                System.out.println(" Done!");
                return decrypted;
            } catch (Exception e) {
                System.out.println(" Failure! (" + e.getMessage() + ")");
            }
        } else {
            System.out.println(" Not found.");
        }
    }
    return null;
}
Also used : SettingsSecurity(org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity) File(java.io.File) IOException(java.io.IOException) PlexusCipherException(org.sonatype.plexus.components.cipher.PlexusCipherException) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException)

Aggregations

File (java.io.File)3 SettingsSecurity (org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity)3 IOException (java.io.IOException)2 PlexusCipherException (org.sonatype.plexus.components.cipher.PlexusCipherException)2 SecDispatcherException (org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException)2 FileWriter (java.io.FileWriter)1 Configuration (org.osgi.service.cm.Configuration)1 SecurityConfigurationXpp3Writer (org.sonatype.plexus.components.sec.dispatcher.model.io.xpp3.SecurityConfigurationXpp3Writer)1