Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-2610 use SSL keystore passwords from command line for Micro #2593

Merged
merged 3 commits into from Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -37,26 +37,18 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright 2016 Payara Foundation
// Portions Copyright [2018] [Payara Foundation and/or its affiliates]

package com.sun.enterprise.v3.admin;

import com.sun.enterprise.glassfish.bootstrap.StartupContextUtil;
import com.sun.enterprise.module.bootstrap.StartupContext;
import com.sun.enterprise.security.store.IdentityManagement;
import com.sun.enterprise.security.store.PasswordAdapter;
import org.glassfish.hk2.runlevel.RunLevel;
import org.glassfish.internal.api.InitRunLevel;
import org.glassfish.security.common.MasterPassword;
import org.glassfish.server.ServerEnvironmentImpl;
import javax.inject.Inject;
import javax.inject.Named;

import org.jvnet.hk2.annotations.Optional;

import org.jvnet.hk2.annotations.Service;
import org.glassfish.hk2.api.PostConstruct;
import javax.inject.Singleton;

import java.io.*;
import java.util.Arrays;
Expand Down Expand Up @@ -105,8 +97,14 @@ public void postConstruct() {
if (!success) {
masterPassword = "changeit".toCharArray(); //the default;
}
System.setProperty("javax.net.ssl.keyStorePassword",new String(masterPassword));
System.setProperty("javax.net.ssl.trustStorePassword",new String(masterPassword));

if (System.getProperty("javax.net.ssl.keyStorePassword") == null) {
System.setProperty("javax.net.ssl.keyStorePassword", new String(masterPassword));
}

if (System.getProperty("javax.net.ssl.trustStorePassword") == null) {
System.setProperty("javax.net.ssl.trustStorePassword", new String(masterPassword));
}
}

@Override
Expand Down
Expand Up @@ -37,6 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2018] [Payara Foundation and/or its affiliates]"
package com.sun.enterprise.security.ssl.impl;

import com.sun.enterprise.security.ssl.manager.UnifiedX509KeyManager;
Expand Down Expand Up @@ -87,6 +88,8 @@
import org.jvnet.hk2.annotations.Service;

import javax.inject.Singleton;
import org.glassfish.api.admin.ServerEnvironment;
import org.jvnet.hk2.annotations.Optional;

/**
* This implements SecuritySupport used in PluggableFeatureFactory.
Expand Down Expand Up @@ -129,6 +132,9 @@ public class SecuritySupportImpl extends SecuritySupport {
private ServiceLocator habitat;
@Inject
private ProcessEnvironment penv;

@Inject @Optional
private ServerEnvironment senv;

public SecuritySupportImpl() {
this(true);
Expand Down Expand Up @@ -164,12 +170,16 @@ private void initJKS() {
if (penv == null && habitat != null) {
penv = habitat.getService(ProcessEnvironment.class);
}

if (senv == null && habitat != null) {
senv = habitat.getService(ServerEnvironment.class);
}
/*
* If we don't have a keystore password yet check the properties.
* Always do so for the app client case whether the passwords have been
* found from master password helper or not.
*/
if (keyStorePass == null || isACC()) {
if (keyStorePass == null || isACC() || (senv != null && senv.isMicro())) {
final String keyStorePassOverride = System.getProperty(KEYSTORE_PASS_PROP, DEFAULT_KEYSTORE_PASS);
if (keyStorePassOverride != null) {
keyStorePass = keyStorePassOverride.toCharArray();
Expand Down