Buscar este blog

domingo, 13 de agosto de 2017

Documentum - Oracle query to find file path

This is a small tweak of this useful post: https://msroth.wordpress.com/2011/09/04/finding-an-objects-content-file/

It was tested with Documentum 6.7 and Oracle database 11g.
select
    CR.parent_id AS OID,
    L.file_system_path AS Base_Path,
    CS.data_ticket AS Ticket,   
    TRIM(TO_CHAR(TO_NUMBER(CS.data_ticket) + 4294967296, 'XXXXXXXX')) AS Ticket_HEX,
    '/' ||
    SUBSTR(TRIM(TO_CHAR(TO_NUMBER(CS.data_ticket) + 4294967296, 'XXXXXXXX')), 1, 2) || '/' ||
    SUBSTR(TRIM(TO_CHAR(TO_NUMBER(CS.data_ticket) + 4294967296, 'XXXXXXXX')), 3, 2) || '/' ||
    SUBSTR(TRIM(TO_CHAR(TO_NUMBER(CS.data_ticket) + 4294967296, 'XXXXXXXX')), 5, 2) || '/'  AS DIRECTORY,       
    SUBSTR(TRIM(TO_CHAR(TO_NUMBER(CS.data_ticket) + 4294967296, 'XXXXXXXX')), 7, 2) || '.' || CS.full_format AS FILE_NAME,
    CS.full_format AS FILE_EXTENSION,
    CS.full_content_size AS FILE_SIZE   
from 
    DMR_CONTENT_S CS, 
    DMR_CONTENT_R CR, 
    DM_FILESTORE_S F, 
    DM_LOCATION_S L, 
    DM_SYSOBJECT_S S 
where 
    CS.r_object_id = CR.r_object_id 
    AND CR.parent_id = '0898968180000ada'
    AND CS.storage_id = F.r_object_id
    AND F.root = S.object_name 
    AND S.r_object_id = L.r_object_id;

Result:

Note: As the was stated in the referenced post, 4294967296 is 2^32, and is used to convert the negative number of the ticket to hexadecimal.

viernes, 11 de agosto de 2017

JBoss - Vault utility outside JBoss

JBoss Password Vault is tool to store and retrive encrypted passwords. It´s based in a keystore (which contains a private key) used to encrypt passwords, and a data file to store them. Check JBoss development guide for more info.

When working with JBoss, you can configure your Vault with a tool also provided, and the you only need to reference a set of configuration from standalone.xml/domain.xml files. Then, you can store new passwords in the Vault, being each of them referenced by a string in the format "Vault::XXXX:YYYY:n". Any time you need to use these passwords you can place them in JBoss config files (with ${}) or inside your EAR/WARs and by decrypting them manually with SecurityVault. JBoss uses picketbox in order to encrypt/decrypt these passwords.

When you configure JBoss Vault you begin with a keystore file, specify some configuration values, and obtains an store data file. All these stuff are then referenced in JBoss by an xml snippet, as described in the development guide.

I put here the steps in order to create the keystore, configure the Vault, and store a new password in it:
1) Create the keystore:
keytool -genseckey -alias jboss -storetype jceks -keyalg AES -keysize 128 -storepass 123456 -keypass 123456 -validity 999 -keystore vault(123456).keystore

2) Configure the Vault:
Please enter a Digit::   0: Start Interactive Session  1: Remove Interactive Session  2: Exit
0
Starting an interactive session
Enter directory to store encrypted files:C:/Servers/jboss-eap-6.4/VAULT/
Enter Keystore URL:C:/Servers/jboss-eap-6.4/VAULT/vault(123456).keystore
Enter Keystore password:
Enter Keystore password again:
Values match
Enter 8 character salt:1234abcd
Enter iteration count as a number (Eg: 44):100
Enter Keystore Alias:jboss
Initializing Vault
ago 11, 2017 12:56:53 PM org.jboss.security.vault.SecurityVaultFactory secondVaultInfo
WARN: PBOX000378: Attempt to create the second Security Vault [org.picketbox.plugins.vault.PicketBoxSecurityVault] is invalid. Only one Security Vault is supported. Change your configuration, please.
ago 11, 2017 12:56:53 PM org.picketbox.plugins.vault.PicketBoxSecurityVault init
INFO: PBOX000361: Default Security Vault Implementation Initialized and Ready
Vault Configuration in configuration file:
********************************************
...
</extensions>
<vault>
  <vault-option name="KEYSTORE_URL" value="C:/Servers/jboss-eap-6.4/VAULT/vault(123456).keystore"/>
  <vault-option name="KEYSTORE_PASSWORD" value="MASK-AwOVVL6T7qb"/>
  <vault-option name="KEYSTORE_ALIAS" value="jboss"/>
  <vault-option name="SALT" value="1234abcd"/>
  <vault-option name="ITERATION_COUNT" value="100"/>
  <vault-option name="ENC_FILE_DIR" value="C:/Servers/jboss-eap-6.4/VAULT/"/>
</vault><management> ...
********************************************
Vault is initialized and ready for use
Handshake with Vault complete
Please enter a Digit::  0: Store a secured attribute  1: Check whether a secured attribute exists  2: Remove secured attribute  3: Exit

3) Store a new password:
Please enter a Digit::  0: Store a secured attribute  1: Check whether a secured attribute exists  2: Remove secured attribute  3: Exit
0
Task: Store a secured attribute
Please enter secured attribute value (such as password):
Please enter secured attribute value (such as password) again:
Values match
Enter Vault Block:Pruebas
Enter Attribute Name:pass1
Secured attribute value has been stored in vault.
Please make note of the following:
********************************************
Vault Block:Pruebas
Attribute Name:pass1
Configuration should be done as follows:
VAULT::Pruebas::pass1::1
********************************************
Please enter a Digit::  0: Store a secured attribute  1: Check whether a secured attribute exists  2: Remove secured attribute  3: Exit


The question here is how to use JBoss Vault outside JBoss. I mean, I have a JBoss Vault used by a JBoss Domain, and I also have an standalone java application which needs to use enrypted passwods. By customer requirements, this application must use JBoss Vault in order to retrive these passwords values.

In order to do that, you can use the following java utility:
import java.util.HashMap;
import java.util.Map;

import org.jboss.security.vault.SecurityVault;
import org.jboss.security.vault.SecurityVaultException;
import org.jboss.security.vault.SecurityVaultFactory;
import org.jboss.security.vault.SecurityVaultUtil;
import org.picketbox.plugins.vault.PicketBoxSecurityVault;

public class Main {
    public static void main(final String[] args) throws SecurityVaultException {

        final SecurityVault vault = SecurityVaultFactory.get();
        if (!vault.isInitialized()) {
            final Map<String, Object> optionsInitVault = new HashMap<String, Object>();
            optionsInitVault.put(PicketBoxSecurityVault.KEYSTORE_URL, "C:/Servers/jboss-eap-6.4/VAULT/vault(123456).keystore");
            optionsInitVault.put(PicketBoxSecurityVault.KEYSTORE_PASSWORD, "MASK-AwOVVL6T7qb");
            optionsInitVault.put(PicketBoxSecurityVault.KEYSTORE_ALIAS, "jboss");
            optionsInitVault.put(PicketBoxSecurityVault.KEYSTORE_TYPE, "jceks");
            optionsInitVault.put(PicketBoxSecurityVault.SALT, "1234abcd");
            optionsInitVault.put(PicketBoxSecurityVault.ITERATION_COUNT, "100");
            optionsInitVault.put(PicketBoxSecurityVault.ENC_FILE_DIR, "C:/Servers/jboss-eap-6.4/VAULT/");
            vault.init(optionsInitVault);
        }


        final String textoCifrado = "VAULT::Pruebas::pass1::1";
        if (!SecurityVaultUtil.isVaultFormat(textoCifrado)) {
            System.out.println("La cadena no está cifrada. Se ha introducido un valor en claro");
        }
        else {
            System.out.println(SecurityVaultUtil.getValueAsString(textoCifrado));
        }
    }
}

As you see, the standalone application will need to know the parameters used to create the Vault, and also will need access to the keystore and data store file.

Maven dependencies, assuming JBoss EAP 6.4, are as follow:
<dependency>
 <groupId>org.picketbox</groupId>
 <artifactId>picketbox</artifactId>
 <version>4.1.1.Final</version>
</dependency>

<dependency>
 <groupId>org.jboss.logging</groupId>
 <artifactId>jboss-logging</artifactId>
 <version>3.1.4.GA</version>
</dependency>

jueves, 10 de agosto de 2017

OpenSSL - Certificate and private key cheat sheet

We start with a PKCS12 file called sisifo.pfx, which password is "1234".

A PKCS12 file contains:
  • Certificate
    • Certificate, information about the owner. If it is a certificate chain, it also contains information about the CAs.
    • Public key
  • Private key


Extract certificate and private key from a PKCS12 file (check here):
openssl pkcs12 -in sisifo.pfx -nocerts -out sisifo-key.pem -nodes
openssl rsa -in sisifo-key.pem -out sisifo.key

openssl pkcs12 -in sisifo.pfx -nokeys -out sisifo.cer


Merge certificate and private key files in a PKCS12 file (check here):
openssl pkcs12 -export -in sisifo.cer -inkey sisifo.key -name sisifo -out sisifo-2.pfx

If everything went fine, both files should be the same (or very similar ;)).

domingo, 6 de agosto de 2017

Tomcat Manager - Commands cheat sheet

Tomcat rest commands: https://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Supported_Manager_Commands


First, you need to create a user with the manager-script role. The complete list of available roles can be found in $TOMCAT_HOME/webapps/manager/WEB-INF/web.xml:
  • manager-gui — Access to the HTML interface.
  • manager-status — Access to the "Server Status" page only.
  • manager-script — Access to the tools-friendly plain text interface that is described in this document, and to the "Server Status" page.
  • manager-jmx — Access to JMX proxy interface and to the "Server Status" page.

Then, you need to assign this role to a user. Users are configured en $TOMCAT_HOME/conf/tomcat-users.xml:
<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-status"/>
  <role rolename="manager-jmx"/>
    
  <user username="admin"  password="admin"  roles="manager-gui"/>
  <user username="admins" password="admins" roles="manager-script"/>
</tomcat-users>

Finally, use curl tool:
curl -u admins:admins http://localhost:8080/manager/text/serverinfo

curl -u admins:admins http://localhost:8080/manager/text/list

curl -u admins:admins http://localhost:8080/manager/text/sessions?path=/examples
curl -u admins:admins http://localhost:8080/manager/text/start?path=/examples
curl -u admins:admins http://localhost:8080/manager/text/stop?path=/examples
curl -u admins:admins http://localhost:8080/manager/text/reload?path=/examples