Showing posts with label SSL. Show all posts
Showing posts with label SSL. Show all posts

Monday, December 17, 2012

Configuring two way SSL between Client and Weblogic server with Apache proxying the request.


Configure Apache for SSL
Create the certificates using openssl (present in apache_home\bin) using the below steps:
openssl genrsa -des3 -out server.key 1024
openssl req -config ..\conf\openssl.cnf -new -key server.key -out localhost
openssl x509 -req -days 730 -in localhost -signkey server.key -out server.crt
Add the following in the httpd.conf file
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Listen 443
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile “C:\Program Files\Apache Group\Apache2\conf\server.crt”
SSLCertificateKeyFile “C:\Program Files\Apache Group\Apache2\conf\server.key”
SSLCACertificateFile “C:\Documents and Settings\Administrator\Desktop\cert\IntermediateCA.cer”
#SSLLog “C:\Program Files\Apache Group\Apache2\conf\ssl.log”
#SSLLogLevel debug
</VirtualHost>
Configure SSL between Apache and Weblogic Server
Add the following in the Location Directive
SecureProxy ON
TrustedCAFile C:\bea101\wlserver_10.0\server\lib\CertGenCA.pem
RequireSSLHostMatch false
Configure Apache to Request for Client Certificate
Add the following in the Location Directive
SSLVerifyClient optional_no_ca
SSLOptions +ExportCertData
Configure Weblogic Server for 2-way SSL
mydomain> Servers> myserver>Keystores & SSL > Advanced Options
Hostname Verification: None
Two Way Client Cert Behavior: Client Certs Requested but not enforced
Apache_SSL> Domain Wide Security Settings> Realms> myrealm> Authentication Providers> DefaultIdentityAsserter
Trusted Client Principals: provide CN of the Client Certificate
Types: X509
Details:
Use Default User Name Mapper: Checked
Default User Name Mapper Attribute Type: CN
Base64Decoding Required: Checked
Go the security realm and create a user wih the username as CN of the certificate
Add the following in the config.xml
<Server ClientCertProxyEnabled=”true”
Configure the Web Application
The Web Application should require client cert authentication.
Add the following in the web.xml
<context-param>
<param-name>weblogic.httpd.clientCertProxy</param-name>
<param-value>true</param-value>
</context-param>
Add the following in the weblogic.xml
<principal-name> CN of the certificate</principal-name>

Configure node manager over SSL ( Custom Certifcates )


Below are the steps to configure Node Manager over SSL :
First create custom certificates using the commands below:
1) keytool -genkey -alias mykey -keyalg RSA -keysize 1024 -dname “CN=Puneeth, OU=Oracle, O=BEA, L=Denver, ST=Colorado, C=US” -keypass password -keystore identity.jks -storepass password
2) keytool -selfcert -v -alias mykey -keypass password -keystore identity.jks -storepass password -storetype jks
3) keytool -export -v -alias mykey -file rootCA.der -keystore identity.jks -storepass password
4) keytool -import -v -trustcacerts -alias mykey -file rootCA.der -keystore trust.jks –storepass password
.
Now configure “Custom Identity and Customer Trust “for Admin and managed servers as shown below:
.
.
Now enter the Key Alias and Private Key Passphrase under SSL tab for both the servers:
.
.
Make the following changes in nodemanager.properties file :
  • AuthenticationEnabled=true
  • ListenAddress=   ( Leave it blank if you are using localhost for server Listen Address )
  • ListenPort=5556
  • SecureListener=true
  • StartScriptEnabled=true
  • KeyStores=CustomIdentityAndCustomTrust
  • CustomIdentityKeyStoreFileName=C\:\\bea10.3\\user_projects\\domains\\custom_certificate_nodemanager\\identity.jks
  • CustomIdentityAlias=mykey
  • CustomIdentityPrivateKeyPassPhrase=password
  • CustomTrustKeyStoreFileName=C\:\\bea10.3\\user_projects\\domains\\custom_certificate_nodemanager\\trust.jks
  • .
  • .
Add the following flags in setDomainEnv.cmd:
-Dweblogic.security.IdentityKeyStore=CustomIdentity
-Dweblogic.security.CustomIdentityKeyStoreFileName=filename
-Dweblogic.security.CustomIdentityKeyStorePassPhrase=passphrase
-Dweblogic.security.Identity.KeyStoreType=type
-Dweblogic.security.TrustKeyStore=CustomTrust
-Dweblogic.security.CustomTrustKeyStoreFileName=filename
-Dweblogic.security.CustomTrustKeyStoreType=type
-Dweblogic.security.CustomTrustKeyStorePassPhrase=passphrase
.
.
Add the following flag in startNodeManager.cmd :
set JAVA_OPTIONS=-Dweblogic.nodemanager.sslHostNameVerificationEnabled=false%JAVA_OPTIONS%
.
.
Now check the status of NodeManager. It should be reachable:
.
.
Now start the server..!!
Node manager is now configured over SSL :)

Steps to configure ” Custom Identity and Custom Trust ” on WLS


Custom Identity and Custom Trust ” can be configured using ” self signed certificates ” ,” certificates signed by your internal CA ” OR ” a third party CA like Verisign, GoDaddy ” etc
Below is a link which talks about ” Steps to generate self signed certificates ” :
Click on the link below know more about creating a certificate –> generating a csr ( certificate signing request ) and then getting it signed from verison :
Make sure that all the certificates and keystores are inside the domain folder ( By default Weblogic searches for certificates and keystores in this folder )
Steps to configure SSL on WLS:
Start weblogic and follow the steps below :
.
Check the “ Enable SSL Listen Port “ : Servers –> General tab
Click on the Keystores tab and select “ Customer Identity and Customer Trust “  ( as shown below )
.
.
.
Note :
In Keystore tab –-> password for identity field is –-> password
In Ssl tab –-> password for identiry field is –-> privatepassword ( because here the password is for the private key that we have specified while creating the certificate pair )
Once the configuration is done.
Restart the server and try to open the link : https://localhost:7002/console
If the page comes up fine it means that we have successfully configured..  :)

Setting up a distributed environment over SSL


Consider two physical boxes with weblogic installation on each ( of any required version )

Note :
  • Make sure that the directory structure of WLS on both the physical boxes are identical.
  • Same WLS versions installed on both of them.
  • If you want to set up a distributed environment over SSL with host name verification set as true then make sure that the virtual machine name created on the console should have the fully qualified host name of the respective physical box.
  • Create a domain on both the physical boxes.
  • If the name of the virtual machine is different from the fully qualified host name of the physical box where the remote managed server resides, then set the host name verification to false or you will get BAD_CERTIFICATE errors..!!
.

Configuration that needs to be done on the local machine ( i.e the physical box where the Admin server is running )

  1. Start the Admin server and login to the console.
  2. Create a managed server ( say MS_remote ) and let the listen address of this server be the IP address/DNS name of the remote physical box.
  3. Now create a virtual machine on the console ( say remote_mac )and add the managed server ” MS_remote ” to it. Let the listen address of this machine be the IP address/DNS name of the remote physical box.
  4. Click remote_mac –> ” Nodemanager ” tab. Specify the nodemanager listen address as the the IP address/DNS name of the remote physical box.
  5. Check if the listen port is “5556″ and type is plain. ( or SSL if you want to configure node manager over SSL ).

Below are the configurations that needs to be done on the remote physical box :

  • Edit the nodemanager.properties files located in <bea_home>/<weblogic_home>/common/nodemanager/ and make the folowing changes :
- ListenAddress=<IP address/DNS name of the remote physical box>
- ListenPort=5556
- SecureListener=false
- StartScriptEnabled=false
.
Note : If you want the nodemanager to run on ssl then check for the following in nodemager.properties file :
.
- ListenAddress=<IP address/DNS name of the remote physical box>
- ListenPort=5556
- SecureListener=true
- StartScriptEnabled=false
  • Open a command prompt on the remote physical box and run the following commands :
  • - Run setDomain.env to set the environment. ( located in <bea_home>/user_projects/domains/<domain_name>/bin )
  • - Start WLST using the command below :
- C:\ java weblogic.WLST
Initializing Weblogic Scripting Tool (WLST)…
Welcome to Weblogic Server Administration Scripting Shell
Type help () for help on available commands
wls:/offline>
*************************************************************
- wls:/offline> connect()
Now you will be prompted for the required details as follows
Please enter your username [weblogic]: weblogic
Please enter your password [weblogic]: ********
Please enter your server URL [t3://localhost:7001]: t3://10.10.71.24:7001
Connecting to t3://10.10.71.24:7001 with userid weblogic…
Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘base_domain’.
.
  • Now lets enroll this machine using the command nmEnroll()
Wls: /base_domain/serverConfig> nmEnroll ()
Enrolling this machine with the domain directory at D:/BEA_Home/WLS_Home/com
mon/nodemanager…
Successfully enrolled this machine with the domain directory at D:/BEA_Home/WLS_Home/com
mon/nodemanager
.
Note : Most of the time we get errors while running the nmEnroll command, check out the NOTES at the end of this document to learn more about nmEnroll().
  • Now goto admin console and check the status of the node manger. It should be active –> reachable
  • Start the managed server ‘MS_remote ‘.
  • You can see the folder ‘MS_remote’ created under <weblogic_home>/common/nodemanager/servers in which you can see the logs. ( on the remote physical box ).
Remote managed server is successfully configured now and its status should be running :)

NOTES :

.
nmEnroll :
.
Command Category: Node Manager Commands
Use with WLST: Online
.
Description
.
Enrolls the machine on which WLST is currently running.
WLST must be connected to an Administration Server to run this command;
WLST does not need to be connected to Node Manager.
.
This command downloads the following files from the Administration Server:
.
- Node Manager secret file (nm_password.properties), which contains the encrypted username and password that is used for server authentication
- SerializedSystemIni.dat file
- This command also updates the nodemanager.domains file under the WL_HOME/common/nodemanager directory with the domain information, where WL_HOME refers to the top-level installation directory for WebLogic Server.
You must run this command once per domain per machine unless that domain shares the root directory of the Administration Server.
If the machine is already enrolled when you run this command, the Node Manager secret file (nm_password.properties) is refreshed with the latest information from the Administration Server.
In the event of an error, the command returns a WLSTException.
.
Syntax :
.
nmEnroll([domainDir], [nmHome])
.
Argument – domainDir – Optional.
Path of the domain directory to which you want to save the Node Manager secret file (nm_password.properties) and SerializedSystemIni.dat file.
This argument defaults to the directory in which WLST was started.
.
Argument – nmHome – Optional.
Path to the Node Manager home.
The nodemanager.domains file, containing the domain information, is written to this directory.
This argument defaults to WL_HOME/common/nodemanager, where WL_HOME refers to the top-level installation directory for WebLogic Server.
.
Example :
.
The following example enrolls the current machine with Node Manager and saves the Node Manager secret file (nm_password properties) and SerializedSystemIni.dat file to c:/bea/mydomain/common/nodemanager/nm_password.properties.
The nodemanager.domains file is written to WL_HOME/common/nodemanager by default.
wls:/mydomain/serverConfig> nmEnroll(‘c:/bea/mydomain/common/nodemanager’)
Enrolling this machine with the domain directory at c:\bea\mydomain\common\nodemanager….
Successfully enrolled this machine with the domain directory at C:\bea\mydomain\common\nodemanager
wls:/mydomain/serverConfig>
—————-
Syntax for WLST Commands :
.
Follow this syntax when entering WLST commands or writing them in a script:
Command names and arguments are case sensitive.
Enclose arguments in single or double quotes. For example,
‘newServer’
or
“newServer”.
If you specify a backslash character (\) in a string, either precede the backslash with another backslash or precede the entire string with a lower-case r character.
The \ or r prevents Jython from interpreting the backslash as a special character.
For example when specifying a file pathname that contains a backslash:
readTemplate(‘c:\\userdomains\\mytemplates\\mytemplate.jar’)
or
readTemplate(r’c:\userdomains\mytemplates\mytemplate.jar’)
On Linus Machines you can use the following syntax :
Example :
nmEnroll (‘//opt//app//beaprd//osb//user_projects//domains//amp’)
or
nmEnroll (‘//opt//app//beaprd//osb//user_projects//domains//amp’,'//opt//app//beaprd//osb//wlserver_10.3//common//nodemanager’)
Enrolling this machine with the domain directory at //opt//app//beaprd//osb//user_projects//domains//amp …
Successfully enrolled this machine with the domain directory at /opt/app/beaprd/osb/user_projects/domains/amp.
or
nmEnroll()
—————-
When you configure node manager over SSL i.e when you set the type as SSL ( in machines–>”remote_mac”–> nodemanager–> type then by default the demo identity and deno trust will be used. You can make your SSL connection more secured by using either ” Custom identity custom trust ” , ” Custom Identity JAVA Standard Trust ” :
.

Below are the changes that you need to make to configure ” Custom Identity and Custom Trust ” :

.
- Make the following changes in nodemanager.properties file : ( Custom Identity and Custom Trust )
  • AuthenticationEnabled=true
  • ListenAddress=(Specify the listen address of the managed server. If managed server listen address is localhost then you can leave this blank )
  • ListenPort=5556
  • SecureListener=true
  • StartScriptEnabled=false
  • KeyStores=CustomIdentityAndCustomTrust
  • CustomIdentityKeyStoreFileName=C\:\\bea10.3\\user_projects\\domains\\custom_certificate_nodemanager\\identity.jks
  • CustomIdentityAlias=mykey
  • CustomIdentityPrivateKeyPassPhrase=privatepassword
  • CustomTrustKeyStoreFileName=C\:\\bea10.3\\user_projects\\domains\\custom_certificate_nodemanager\\trust.jks
- Make the following changes in nodemanager.properties file : ( Custom Identity and Java Standard Trust )
  • AuthenticationEnabled=true
  • ListenAddress=(Specify the listen address of the managed server. If managed server listen address is localhost then you can leave this blank )
  • ListenPort=5556
  • SecureListener=true
  • StartScriptEnabled=false
  • KeyStores=CustomIdentityAndJavaStandardTrust
  • CustomIdentityKeyStoreFileName=C\:\\bea10.3\\user_projects\\domains\\custom_certificate_nodemanager\\identity.jks
  • CustomIdentityAlias=mykey
  • CustomIdentityPrivateKeyPassPhrase=privatepassword
For more information have a look at the link below :
—————-
Below are the configurations that has to be done on the ” keystore ” tab under each server :
Configuring Keystores :
By default, WebLogic Server is configured with two keystores:
DemoIdentity.jks—Contains a demonstration private key for WebLogic Server. This keystore contains the identity for WebLogic Server.
DemoTrust.jks—Contains the trusted certificate authorities from the WL_HOME\server\lib\DemoTrust.jks and the JDK cacerts keystores. This keystore establishes trust for WebLogic Server.
—————-

To configure Identity and Trust keystores for WebLogic Server:

.
  • Expand the Servers node.
  • Select the name of the server for which you want to configure keystores (for example, exampleserver).
  • Select the Configuration–>Keystores and SSL tab.
  • The information about the demonstration keystores is displayed in the Keystore Configuration.
  • Click the Change… link in the Keystore Configuration to configure new keystores.
  • Choose the type of keystore configuration being used.
  • The following options are available:
  1. Demo Identity and Demo Trust : The demonstration Identity and Trust keystores located in the WL_HOME\server\lib directory and configured by default and the cacerts file in the JAVA_HOME\jre\lib\security directory.
  2. Custom Identity and Java Standard Trust : An Identity keystore you create and the trusted CAs defined in the cacerts file in the JAVA_HOME\jre\lib\security directory.
  3. Custom Identity and Custom Trust—Identity and Trust keystores you create.
  4. Custom Identity and Command-Line Trust—An Identity keystore you create and command-line arguments that specify the location of the Trust keystore. Use this option in a production environment when the Administration port is enabled and Managed servers are started on the command-line instread of by the Node Manager.
  • Click Continue.
  • Define attributes for the Identity keystore.
  • Custom Identity Keystore File Name : The fully qualified path to the Identity keystore.
  • Custom Identity Keystore Type : The type of the keystore. Generally, this attribute is jks. If this attribute is not specified, the default keystore type defined in the security policy file for the JDK is used.
  • Custom Identity Keystore PassPhrase : The password defined when creating the keystore. This attribute is optional or required depending on the type of keystore. All keystores require the passphrase in order to write to the keystore. Some keystores do not require the passphrase to read from the keystore. Whether or not you define this property depends on the requirements of the keystore. For example, WebLogic Server only reads from the keystore so a passphrase is not required, however, WebLogic Integration writes to keystores and therefore requires a passphrase. Confirm the password.
Note: The passphrase for the Demo Identity keystore is DemoIdentityKeyStorePassPhrase.
  • Define attributes for the Trust keystore.
  • If you choose Java Standard Trust, specify the password defined when creating the keystore. Confirm the password.
  • If you choose Custom Trust, define the following attributes:
  • Custom Trust Keystore File Name : The fully qualified path to the trust keystore.
  • Custom Trust Keystore Type : The type of the keystore. Generally, this attribute is jks. If this attribute is not specified, the default keystore type defined in the security policy file for the JDK is used.
  • Custom Trust Keystore PassPhrase : The password defined when creating the keystore. This attribute is optional or required depending on the type of keystore. All keystores require the passphrase in order to write to the keystore. Some keystores do not require the passphrase to read from the keystore. Whether or not you define this property depends on the requirements of the keystore. For example, WebLogic Server only reads from the keystore so a passphrase is not required, however, WebLogic Integration writes to keystores and therefore requires a passphrase. Confirm the password.
  • Click Continue.
  • Click Finish.
  • Optionally, configure the SSL attributes for WebLogic Server. You do not have to perform this step if you are using keystores for the purpose of digital signing.
  • Reboot WebLogic Server.
——————

Configuring SSL :

.
  • By default, SSL is enabled and configured to use the demonstration Identity and Trust keystores.
To configure SSL:
.
  • Expand the Servers node.
  • Select the name of the server for which you want to configure keystores (for example, exampleserver).
  • Select the Configuration–>Keystores and SSL tab.
  • The Configure SSL page appears.
  • Specify how the identity and trust for WebLogic Server is stored.
  • The following options are available:
  1. Key Stores : Use this option if you created Identity and Trust keystores for WebLogic Server.
  2. Files or Key Store Providers—Use this option if you stored private keys and trusted CA certificates in a file or in a JKS keystore accessed via the WebLogic Keystore provider ( for backward compatibility )( now depricated )
  • Private Key Alias : The alias specified when loading the private key for WebLogic Server from the keystore.
  • Private Key Passphrase : The password specified when loading the private key for WebLogic Server into the keystore.
  • Confirm the password.
  • Note : If you protected the private key file with a password, specify the weblogic.management.pkpassword command-line argument when starting the server.
  • Click Continue.
  • Click Finish.
  • Reboot WebLogic Server.

copy file from one linux to another linux box using SCP


sending a file from one linux box to another linux box.

scp stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.

You can this way copy files from or to a remote server, you can even copy files from one remote server to another remote server, without passing through your PC.

Usage
scp [[user@]from-host:]source-file [[user@]to-host:][destination-file]
Description of options
from-host
Is the name or IP of the host where the source file is, this can be omitted if the from-host is the host where you are actually issuing the command

user
Is the user which have the right to access the file and directory that is supposed to be copied in the cas of the from-host and the user who has the rights to write in the to-host

source-file
Is the file or files that are going to be copied to the destination host, it can be a directory but in that case you need to specify the -r option to copy the contents of the directory

destination-file
Is the name that the copied file is going to take in the to-host, if none is given all copied files are going to maintain its names
Options
-p
Preserves the modification and access times, as well as the permissions of the source-file in the destination-file
-q
Do not display the progress bar
-r
Recursive, so it copies the contents of the source-file (directory in this case) recursively
-v
Displays debugging messages
Examples

scp *.txt user@remote.server.com:/home/user/

This will copy all files with .txt extension to the directory /home/user in the remote.server.com host

scp -r subha@10.1.2.2:/home/subha/ subha@10.1.2.3:/home/subha/

This is going to recursively copy all files from miguel’s Home directory on 10.1.2.2 host to his Home directory in 10.1.2.3 host.