Search in sources :

Example 26 with OptionsParameter

use of org.nhindirect.stagent.options.OptionsParameter in project nhin-d by DirectProject.

the class CryptoExtensions method setJCEProviderName.

/**
	 * Overrides the configured JCE crypto provider string.  If the name is empty or null, the default string "BC" (BouncyCastle provider)
	 * is used.
	 * <P>
	 * The provider name may be a comma delimited list of provider strings.  The first string in the list will be the default provider string
     * and returned when using {@link #getJCEProviderName()}; however, the {@link #getJCEProviderNameForTypeAndAlgorithm(String, String)} will search
     * through the provider string until a valid provider that supports the requested type and algorithm is found.  In this case, the first matching
     * provider string will be used.
	 * @param name The name of the JCE provider.
	 */
public static void setJCEProviderName(String name) {
    OptionsParameter param;
    if (name == null || name.isEmpty())
        param = new OptionsParameter(OptionsParameter.JCE_PROVIDER, DEFAULT_JCE_PROVIDER_STRING);
    else
        param = new OptionsParameter(OptionsParameter.JCE_PROVIDER, name);
    OptionsManager.getInstance().setOptionsParameter(param);
}
Also used : OptionsParameter(org.nhindirect.stagent.options.OptionsParameter)

Example 27 with OptionsParameter

use of org.nhindirect.stagent.options.OptionsParameter in project nhin-d by DirectProject.

the class CryptoExtensions method getJCEProviderName.

/**
	 * Gets the configured JCE crypto provider string for crypto operations.  This is configured using the
	 * -Dorg.nhindirect.stagent.cryptography.JCEProviderName JVM parameters.  If the parameter is not set or is empty,
	 * then the default string "BC" (BouncyCastle provider) is returned.  By default the agent installs the BouncyCastle provider.
	 * @return The name of the JCE provider string.
	 */
public static String getJCEProviderName() {
    String retVal = "";
    OptionsParameter param = OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER);
    if (param == null || param.getParamValue() == null || param.getParamValue().isEmpty())
        retVal = DEFAULT_JCE_PROVIDER_STRING;
    else {
        final String[] JCEString = param.getParamValue().split(",");
        retVal = JCEString[0];
    }
    return retVal;
}
Also used : OptionsParameter(org.nhindirect.stagent.options.OptionsParameter)

Example 28 with OptionsParameter

use of org.nhindirect.stagent.options.OptionsParameter in project nhin-d by DirectProject.

the class CryptoExtensions method getJCEProviderNameForTypeAndAlgorithm.

/**
	 * Gets the configured JCE crypto provider that supports the combination of the requested type and algorithm.  If a custom set of 
	 * providers has not been configured, this method will always return the default BouncyCatle provider string regardless if it matches
	 * the request type/algorithm pair.
	 * @param type The crypto type such as CertStore or CertPathValidator
	 * @param algorithm The algorithm such as PKIX or MAC.
	 * @return The name of the JCE provider string supporting the type/algorithm pair.
	 */
public static String getJCEProviderNameForTypeAndAlgorithm(String type, String algorithm) {
    String[] JCEString = null;
    String retVal = "";
    final OptionsParameter param = OptionsManager.getInstance().getParameter(OptionsParameter.JCE_PROVIDER);
    if (param == null || param.getParamValue() == null || param.getParamValue().isEmpty())
        JCEString = new String[] { DEFAULT_JCE_PROVIDER_STRING };
    else {
        final String configuredJCEString = param.getParamValue();
        JCEString = configuredJCEString.split(",");
    }
    for (String provierString : JCEString) {
        final Provider provider = Security.getProvider(provierString);
        if (provider != null) {
            if (provider.getService(type, algorithm) != null) {
                retVal = provierString;
                break;
            }
        }
    }
    return retVal;
}
Also used : OptionsParameter(org.nhindirect.stagent.options.OptionsParameter) Provider(java.security.Provider) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 29 with OptionsParameter

use of org.nhindirect.stagent.options.OptionsParameter in project nhin-d by DirectProject.

the class CryptoExtensions method getJCESensitiveProviderName.

/**
	 * Gets the configured JCE sensitive crypto provider string for crypto operations that need access to sensitive cryptogrophy information
	 * such as secret and private keys.  This is configured using the
	 * -Dorg.nhindirect.stagent.cryptography.JCESensitiveProviderName JVM parameters.  If the parameter is not set or is empty,
	 * then the default string "BC" (BouncyCastle provider) is returned.  By default the agent installs the BouncyCastle provider.
	 * @return The name of the JCE provider string.
	 */
public static String getJCESensitiveProviderName() {
    String retVal = "";
    OptionsParameter param = OptionsManager.getInstance().getParameter(OptionsParameter.JCE_SENTITIVE_PROVIDER);
    if (param == null || param.getParamValue() == null || param.getParamValue().isEmpty())
        retVal = DEFAULT_SENSITIVE_JCE_PROVIDER_STRING;
    else {
        final String[] JCEString = param.getParamValue().split(",");
        retVal = JCEString[0];
    }
    return retVal;
}
Also used : OptionsParameter(org.nhindirect.stagent.options.OptionsParameter)

Example 30 with OptionsParameter

use of org.nhindirect.stagent.options.OptionsParameter in project nhin-d by DirectProject.

the class CRLRevocationManager_initCRLCacheLocationTest method setUp.

@Override
public void setUp() {
    CryptoExtensions.registerJCEProviders();
    CRLRevocationManager.initCRLCacheLocation();
    CRLRevocationManager.getInstance().flush();
    CRLRevocationManager.crlCacheLocation = null;
    OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.CRL_CACHE_LOCATION, ""));
}
Also used : OptionsParameter(org.nhindirect.stagent.options.OptionsParameter)

Aggregations

OptionsParameter (org.nhindirect.stagent.options.OptionsParameter)30 DefaultNHINDAgent (org.nhindirect.stagent.DefaultNHINDAgent)5 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)4 DefaultTrustAnchorResolver (org.nhindirect.stagent.trust.DefaultTrustAnchorResolver)4 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Provider (java.security.Provider)2 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)2 Module (com.google.inject.Module)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 CertificateException (java.security.cert.CertificateException)1 CertificateParsingException (java.security.cert.CertificateParsingException)1 MessagingException (javax.mail.MessagingException)1 MimeMessage (javax.mail.internet.MimeMessage)1 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 KeyStoreProtectionManager (org.nhindirect.common.crypto.KeyStoreProtectionManager)1 ServiceSecurityManager (org.nhindirect.common.rest.ServiceSecurityManager)1 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)1