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

Use PKCS12 keystores. #433

Merged
merged 2 commits into from
Feb 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion etc/backend-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<resource>
<directory>${project.basedir}/../resources</directory>
<includes>
<include>wso2carbon.jks</include>
<include>wso2carbon.p12</include>
</includes>
</resource>
</resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class BackendApplication {
private static final Logger logger = LoggerFactory.getLogger(BookingService.class);
private static final Properties properties = new Properties();

// Perform property loading and JKS setup
// Perform property loading and keystore setup
static {
final InputStream resourceAsStream =
BackendApplication.class.getClassLoader().getResourceAsStream("service.properties");
Expand All @@ -50,40 +50,41 @@ public class BackendApplication {
throw new RuntimeException("Service start failed due to configuration loading failure", e);
}

setupJKS();
setupKeystore();
}

private static void setupJKS() {
// First find jks properties
final InputStream jksInputStream = BackendApplication.class.getClassLoader().getResourceAsStream("jks.properties");
private static void setupKeystore() {
// First find keystore properties
final InputStream keystoreInputStream = BackendApplication.class.getClassLoader()
.getResourceAsStream("keystore.properties");

if (jksInputStream == null) {
logger.error("jks.properties not found. Trust store properties will not be set.");
if (keystoreInputStream == null) {
logger.error("keystore.properties not found. Trust store properties will not be set.");
return;
}

// Load properties
final Properties jksProperties = new Properties();
final Properties keystoreProperties = new Properties();

try {
jksProperties.load(jksInputStream);
keystoreProperties.load(keystoreInputStream);
} catch (IOException e) {
logger.error("Error while loading properties.", e);
return;
}

// Find and store JKS required for SSL communication on a temporary location
final InputStream keyStoreAsStream = BackendApplication.class.getClassLoader().getResourceAsStream(jksProperties.getProperty("keystorename"));
// Find and store keystore required for SSL communication on a temporary location
final InputStream keyStoreAsStream = BackendApplication.class.getClassLoader().getResourceAsStream(keystoreProperties.getProperty("keystorename"));

try {
final File keystoreTempFile = File.createTempFile(jksProperties.getProperty("keystorename"), "");
final File keystoreTempFile = File.createTempFile(keystoreProperties.getProperty("keystorename"), "");
keystoreTempFile.deleteOnExit();

Files.copy(keyStoreAsStream, keystoreTempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);

logger.info("Setting trust store path to : " + keystoreTempFile.getPath());
System.setProperty("javax.net.ssl.trustStore", keystoreTempFile.getPath());
System.setProperty("javax.net.ssl.trustStorePassword", jksProperties.getProperty("keystorepassword"));
System.setProperty("javax.net.ssl.trustStorePassword", keystoreProperties.getProperty("keystorepassword"));
} catch (IOException e) {
logger.error("Error while setting trust store", e);
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
keystorename=wso2carbon.jks
keystorename=wso2carbon.p12
keystorepassword=wso2carbon
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</context-param>
<context-param>
<param-name>certificate-file</param-name>
<param-value>wso2carbon.jks</param-value>
<param-value>wso2carbon.p12</param-value>
</context-param>


Expand Down
Binary file removed etc/resources/wso2carbon.jks
Binary file not shown.
Binary file added etc/resources/wso2carbon.p12
Binary file not shown.
4 changes: 2 additions & 2 deletions identity-mgt/info-recovery-sample/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Specify the credentials to access Identity Server with admin privileges for "acc

Specify the captcha validation enable or disable in the webApp using captchaDisable propery.

Specify the trustStore absolute resource path for "trustStorePath". eg. path to wso2carbon.jks of the Identity Server
Specify the trustStore absolute resource path for "trustStorePath". eg. path to wso2carbon.p12 of the Identity Server


2. If you are deploying the sample in tomcat enable the SSL configuration in {tomcat_home}/conf/server.xml
Expand All @@ -32,7 +32,7 @@ Specify the trustStore absolute resource path for "trustStorePath". eg. path to
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="<IS_HOME>/repository/resources/security/wso2carbon.jks" keystorePass="wso2carbon" />
keystoreFile="<IS_HOME>/repository/resources/security/wso2carbon.p12" keystorePass="wso2carbon" />

3. Configure the email confirmation links.

Expand Down
4 changes: 2 additions & 2 deletions identity-mgt/info-recovery-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@
<systemProperties>
<property>
<name>javax.net.ssl.keystore</name>
<value>${basedir}/src/main/resources/keystores/client-truststore.jks
<value>${basedir}/src/main/resources/keystores/client-truststore.p12
</value>
</property>
<property>
<name>javax.net.ssl.trustStoreType</name>
<value>JKS</value>
<value>PKCS12</value>
</property>
<property>
<name>javax.net.ssl.trustStorePassword</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void contextInitialized(ServletContextEvent servletContextEvent) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
SSOAgentConfigs.setKeyStoreStream(servletContextEvent.getServletContext().getClassLoader()
.getResourceAsStream("wso2carbon.jks"));
.getResourceAsStream("wso2carbon.p12"));
}

public void contextDestroyed(ServletContextEvent servletContextEvent) {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
</context-param>
<context-param>
<param-name>trustStorePath</param-name>
<param-value>/client-truststore.jks</param-value>
<param-value>/client-truststore.p12</param-value>
</context-param>
<context-param>
<param-name>accessUsername</param-name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
audiences="li6JMbjW6WDMKTWsRnGcjp5zcGhi"
ignoreApplicationAuthMethod="false">
</mpJwt>
<keyStore id="defaultKeyStore" location="${CARBON_HOME}/repository/resources/security/wso2carbon.jks"
<keyStore id="defaultKeyStore" location="${CARBON_HOME}/repository/resources/security/wso2carbon.p12"
type="JKS" password="wso2carbon" />
</server>
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public static void main(String[] args) {
/**
* Call to Identity Server uses HTTPS protocol.
* Therefore we to validate the server certificate. The server certificate is looked up in the
* trust store. Following code sets what trust-store to look for and its JKs password.
* trust store. Following code sets what trust-store to look for and its PKCS12 password.
* Note : The trust store should have server's certificate.
*/
System.setProperty("javax.net.ssl.trustStore", new File("src/main/resources/wso2carbon.jks").getAbsolutePath());
System.setProperty("javax.net.ssl.trustStore", new File("src/main/resources/wso2carbon.p12").getAbsolutePath());
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");

client = new OAuthServiceClient(IDENTITY_SERVER , configContext, ADMIN_USER_NAME, ADMIN_PASSWORD);
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
keystorename=wso2carbon.jks
keystorename=wso2carbon.p12
keystorepassword=wso2carbon
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
keystorename=wso2carbon.jks
keystorename=wso2carbon.p12
keystorepassword=wso2carbon
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SCIMSamplesUtils {
public static final String IS_HOME = ".." + File.separator + ".." + File.separator;

public static final String TRUST_STORE_PATH = IS_HOME + "repository" + File.separator + "resources" +
File.separator + "security" + File.separator + "wso2carbon.jks";
File.separator + "security" + File.separator + "wso2carbon.p12";

public static final String TRUST_STORE_PASS = "wso2carbon";

Expand Down
4 changes: 2 additions & 2 deletions sso-samples/oidc-sso-sample/pickup-dispatch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</dependency>
<dependency>
<groupId>org.wso2.samples.is</groupId>
<artifactId>oidc-jks-loader</artifactId>
<artifactId>oidc-keystore-loader</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand All @@ -76,7 +76,7 @@
<directory>${project.parent.parent.basedir}/etc/resources/</directory>
<targetPath>WEB-INF/classes</targetPath>
<includes>
<include>wso2carbon.jks</include>
<include>wso2carbon.p12</include>
</includes>
</resource>
</webResources>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
keystorename=wso2carbon.jks
keystorename=wso2carbon.p12
keystorepassword=wso2carbon
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</filter-mapping>

<listener>
<listener-class>org.wso2.sample.identity.jks.JKSLoader</listener-class>
<listener-class>org.wso2.sample.identity.KeystoreLoader</listener-class>
</listener>
<listener>
<listener-class>org.wso2.sample.identity.oauth2.SampleContextEventListener</listener-class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@
<parameter name="non-blocking" locked="false">true</parameter>
<parameter name="keystore" locked="false">
<KeyStore>
<Location>identity.jks</Location>
<Type>JKS</Type>
<Location>identity.p12</Location>
<Type>PKCS12</Type>
<Password>password</Password>
<KeyPassword>password</KeyPassword>
</KeyStore>
</parameter>
<parameter name="truststore" locked="false">
<TrustStore>
<Location>trust.jks</Location>
<Type>JKS</Type>
<Location>trust.p12</Location>
<Type>PKCS12</Type>
<Password>password</Password>
</TrustStore>
</parameter>-->
Expand Down Expand Up @@ -306,16 +306,16 @@
<parameter name="non-blocking" locked="false">true</parameter>
<parameter name="keystore" locked="false">
<KeyStore>
<Location>identity.jks</Location>
<Type>JKS</Type>
<Location>identity.p12</Location>
<Type>PKCS12</Type>
<Password>password</Password>
<KeyPassword>password</KeyPassword>
</KeyStore>
</parameter>
<parameter name="truststore" locked="false">
<TrustStore>
<Location>trust.jks</Location>
<Type>JKS</Type>
<Location>trust.p12</Location>
<Type>PKCS12</Type>
<Password>password</Password>
</TrustStore>
</parameter>-->
Expand Down
4 changes: 2 additions & 2 deletions sso-samples/oidc-sso-sample/pickup-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</dependency>
<dependency>
<groupId>org.wso2.samples.is</groupId>
<artifactId>oidc-jks-loader</artifactId>
<artifactId>oidc-keystore-loader</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand All @@ -81,7 +81,7 @@
<directory>${project.parent.parent.basedir}/etc/resources/</directory>
<targetPath>WEB-INF/classes</targetPath>
<includes>
<include>wso2carbon.jks</include>
<include>wso2carbon.p12</include>
</includes>
</resource>
</webResources>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
keystorename=wso2carbon.12
keystorepassword=wso2carbon
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</servlet-mapping>

<listener>
<listener-class>org.wso2.sample.identity.jks.JKSLoader</listener-class>
<listener-class>org.wso2.sample.identity.KeystoreLoader</listener-class>
</listener>
<listener>
<listener-class>org.wso2.sample.identity.oauth2.SampleContextEventListener</listener-class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@
<parameter name="non-blocking" locked="false">true</parameter>
<parameter name="keystore" locked="false">
<KeyStore>
<Location>identity.jks</Location>
<Type>JKS</Type>
<Location>identity.p12</Location>
<Type>PKCS12</Type>
<Password>password</Password>
<KeyPassword>password</KeyPassword>
</KeyStore>
</parameter>
<parameter name="truststore" locked="false">
<TrustStore>
<Location>trust.jks</Location>
<Type>JKS</Type>
<Location>trust.p12</Location>
<Type>PKCS12</Type>
<Password>password</Password>
</TrustStore>
</parameter>-->
Expand Down Expand Up @@ -306,16 +306,16 @@
<parameter name="non-blocking" locked="false">true</parameter>
<parameter name="keystore" locked="false">
<KeyStore>
<Location>identity.jks</Location>
<Type>JKS</Type>
<Location>identity.p12</Location>
<Type>PKCS12</Type>
<Password>password</Password>
<KeyPassword>password</KeyPassword>
</KeyStore>
</parameter>
<parameter name="truststore" locked="false">
<TrustStore>
<Location>trust.jks</Location>
<Type>JKS</Type>
<Location>trust.p12</Location>
<Type>PKCS12</Type>
<Password>password</Password>
</TrustStore>
</parameter>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<directory>${project.parent.parent.basedir}/etc/resources/</directory>
<targetPath>WEB-INF/classes</targetPath>
<includes>
<include>wso2carbon.jks</include>
<include>wso2carbon.p12</include>
</includes>
</resource>
</webResources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</context-param>
<context-param>
<param-name>certificate-file</param-name>
<param-value>wso2carbon.jks</param-value>
<param-value>wso2carbon.p12</param-value>
</context-param>

<listener>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
<directory>${project.parent.parent.basedir}/etc/resources/</directory>
<targetPath>WEB-INF/classes</targetPath>
<includes>
<include>wso2carbon.jks</include>
<include>wso2carbon.p12</include>
</includes>
</resource>
</webResources>
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</context-param>
<context-param>
<param-name>certificate-file</param-name>
<param-value>wso2carbon.jks</param-value>
<param-value>wso2carbon.p12</param-value>
</context-param>

<listener>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void contextInitialized(ServletContextEvent servletContextEvent) {
}
}
InputStream keyStoreInputStream = servletContextEvent.getServletContext().
getResourceAsStream("/WEB-INF/classes/wso2carbon.jks");
getResourceAsStream("/WEB-INF/classes/wso2carbon.p12");
SSOAgentX509Credential credential =
new SSOAgentX509KeyStoreCredential(keyStoreInputStream,
properties.getProperty("KeyStorePassword").toCharArray(),
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private RampartConfig buildRampartConfig() {

Properties cryptoProperties = new Properties();
cryptoProperties.put(
"org.apache.ws.security.crypto.merlin.keystore.type", "JKS");
"org.apache.ws.security.crypto.merlin.keystore.type", "PKCS12");
cryptoProperties.put("org.apache.ws.security.crypto.merlin.file",
keystorePath);
cryptoProperties.put(
Expand Down
2 changes: 1 addition & 1 deletion sts/sts-client/src/main/resources/client.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ claim.uris=http://wso2.org/claims/givenname,http://wso2.org/claims/emailaddress
relyingParty.message=Hello World

#Following paths start from the resources folder
path.keystore=keystore/wso2carbon.jks
path.keystore=keystore/wso2carbon.P12
path.repo=repo
path.policy.sts=sts-policy-ut.xml
#path.policy.sts=sts-policy-signonly.xml
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion user-mgt/remote-user-mgt/client.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ remote.server.url=https://localhost:9443/services/
user.name=admin
user.password=admin

truststore.path=keystore/client-truststore.jks
truststore.path=keystore/client-truststore.P12
truststore.password=wso2carbon
Binary file not shown.
Binary file not shown.
Loading
Loading