Search in sources :

Example 1 with IdentityKeyStoreWrapper

use of org.wso2.securevault.keystore.IdentityKeyStoreWrapper in project wso2-synapse by wso2.

the class CryptoUtil method init.

/**
 * Method to initialise crypto util. which will generate the required chiper etc.
 *
 * @param secureVaultProperties
 * @throws org.apache.axis2.AxisFault
 */
public void init(Properties secureVaultProperties) throws AxisFault {
    // Create a KeyStore Information  for private key entry KeyStore
    IdentityKeyStoreInformation identityInformation = KeyStoreInformationFactory.createIdentityKeyStoreInformation(secureVaultProperties);
    String identityKeyPass = null;
    String identityStorePass = null;
    if (identityInformation != null) {
        identityKeyPass = identityInformation.getKeyPasswordProvider().getResolvedSecret();
        identityStorePass = identityInformation.getKeyStorePasswordProvider().getResolvedSecret();
    }
    if (!Util.validatePasswords(identityStorePass, identityKeyPass)) {
        if (log.isDebugEnabled()) {
            log.info("Either Identity or Trust keystore password is mandatory" + " in order to initialized secret manager.");
        }
        throw new AxisFault("Error inititialising cryptoutil, required parameters not provided");
    }
    IdentityKeyStoreWrapper identityKeyStoreWrapper = new IdentityKeyStoreWrapper();
    identityKeyStoreWrapper.init(identityInformation, identityKeyPass);
    algorithm = MiscellaneousUtil.getProperty(secureVaultProperties, CryptoConstants.CIPHER_ALGORITHM, CryptoConstants.CIPHER_ALGORITHM_DEFAULT);
    String provider = MiscellaneousUtil.getProperty(secureVaultProperties, CryptoConstants.SECURITY_PROVIDER, null);
    String cipherType = MiscellaneousUtil.getProperty(secureVaultProperties, CryptoConstants.CIPHER_TYPE, null);
    String inTypeString = MiscellaneousUtil.getProperty(secureVaultProperties, CryptoConstants.INPUT_ENCODE_TYPE, null);
    inType = Util.getEncodeDecodeType(inTypeString, EncodeDecodeTypes.BASE64);
    String outTypeString = MiscellaneousUtil.getProperty(secureVaultProperties, CryptoConstants.OUTPUT_ENCODE_TYPE, null);
    outType = Util.getEncodeDecodeType(outTypeString, null);
    CipherInformation cipherInformation = new CipherInformation();
    cipherInformation.setAlgorithm(algorithm);
    cipherInformation.setCipherOperationMode(CipherOperationMode.DECRYPT);
    cipherInformation.setType(cipherType);
    // skipping decoding encoding in securevault
    cipherInformation.setInType(null);
    // skipping decoding encoding in securevault
    cipherInformation.setOutType(null);
    if (provider != null && !provider.isEmpty()) {
        if (CryptoConstants.BOUNCY_CASTLE_PROVIDER.equals(provider)) {
            Security.addProvider(new BouncyCastleProvider());
            cipherInformation.setProvider(provider);
        }
    // todo need to add other providers if there are any.
    }
    baseCipher = CipherFactory.createCipher(cipherInformation, identityKeyStoreWrapper);
    isInitialized = true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) IdentityKeyStoreWrapper(org.wso2.securevault.keystore.IdentityKeyStoreWrapper) IdentityKeyStoreInformation(org.wso2.securevault.definition.IdentityKeyStoreInformation) CipherInformation(org.wso2.securevault.definition.CipherInformation) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Aggregations

AxisFault (org.apache.axis2.AxisFault)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 CipherInformation (org.wso2.securevault.definition.CipherInformation)1 IdentityKeyStoreInformation (org.wso2.securevault.definition.IdentityKeyStoreInformation)1 IdentityKeyStoreWrapper (org.wso2.securevault.keystore.IdentityKeyStoreWrapper)1