<commit_before>package io.subutai.core.security.impl;


import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;

import javax.jms.IllegalStateException;

import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;

import io.subutai.common.command.EncryptedRequestWrapper;
import io.subutai.common.command.EncryptedResponseWrapper;
import io.subutai.common.dao.DaoManager;
import io.subutai.common.security.crypto.pgp.ContentAndSignatures;
import io.subutai.common.settings.Common;
import io.subutai.common.util.JsonUtil;
import io.subutai.core.keyserver.api.KeyServer;
import io.subutai.core.security.api.SecurityManager;
import io.subutai.core.security.api.crypto.EncryptionTool;
import io.subutai.core.security.api.crypto.KeyManager;
import io.subutai.core.security.api.crypto.KeyStoreManager;
import io.subutai.core.security.api.dao.SecurityDataService;
import io.subutai.core.security.api.jetty.HttpContextManager;
import io.subutai.core.security.impl.crypto.EncryptionToolImpl;
import io.subutai.core.security.impl.crypto.KeyManagerImpl;
import io.subutai.core.security.impl.crypto.KeyStoreManagerImpl;
import io.subutai.core.security.impl.dao.SecurityDataServiceImpl;
import io.subutai.core.security.impl.jetty.HttpContextManagerImpl;
import io.subutai.core.security.impl.model.SecurityKeyData;


/**
 * Implementation of SecurityManager
 */
public class SecurityManagerImpl implements SecurityManager
{
    private static final Logger LOG = LoggerFactory.getLogger( SecurityManagerImpl.class );

    private static final String PEER_SECRET_KEY_PWD_FILE =
            String.format( "%s/%s", Common.SUBUTAI_APP_DATA_PATH, "peer.pwd" );

    private KeyManager keyManager = null;
    private DaoManager daoManager = null;
    private EncryptionTool encryptionTool = null;
    private SecurityDataService securityDataService = null;
    private KeyServer keyServer = null;
    private SecurityKeyData keyData = null;
    private KeyStoreManager keyStoreManager = null;
    private HttpContextManager httpContextManager;


    /* *****************************
     *
     */
    public SecurityManagerImpl( Object provider ) throws Exception
    {
        keyData = new SecurityKeyData();

        Path secretKeyPwdFile = Paths.get( PEER_SECRET_KEY_PWD_FILE );

        String secretPwd;

        if ( Files.exists( secretKeyPwdFile ) )
        {
            secretPwd = new String( Files.readAllBytes( secretKeyPwdFile ) );

            if ( Strings.isNullOrEmpty( secretPwd ) )
            {
                throw new IllegalStateException( "Peer secret key pwd is invalid" );
            }
        }
        else
        {
            secretPwd = UUID.randomUUID().toString();

            Files.write( secretKeyPwdFile, secretPwd.getBytes() );
        }

        keyData.setSecretKeyringPwd( secretPwd );

        httpContextManager = new HttpContextManagerImpl();
    }<commit_msg>added getpublickeyfingerprint REST to open endpoints<commit_after>package io.subutai.core.security.impl;


import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;

import javax.jms.IllegalStateException;

import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;

import io.subutai.common.command.EncryptedRequestWrapper;
import io.subutai.common.command.EncryptedResponseWrapper;
import io.subutai.common.dao.DaoManager;
import io.subutai.common.security.crypto.pgp.ContentAndSignatures;
import io.subutai.common.settings.Common;
import io.subutai.common.util.JsonUtil;
import io.subutai.core.keyserver.api.KeyServer;
import io.subutai.core.security.api.SecurityManager;
import io.subutai.core.security.api.crypto.EncryptionTool;
import io.subutai.core.security.api.crypto.KeyManager;
import io.subutai.core.security.api.crypto.KeyStoreManager;
import io.subutai.core.security.api.dao.SecurityDataService;
import io.subutai.core.security.api.jetty.HttpContextManager;
import io.subutai.core.security.impl.crypto.EncryptionToolImpl;
import io.subutai.core.security.impl.crypto.KeyManagerImpl;
import io.subutai.core.security.impl.crypto.KeyStoreManagerImpl;
import io.subutai.core.security.impl.dao.SecurityDataServiceImpl;
import io.subutai.core.security.impl.jetty.HttpContextManagerImpl;
import io.subutai.core.security.impl.model.SecurityKeyData;


/**
 * Implementation of SecurityManager
 */
public class SecurityManagerImpl implements SecurityManager
{
    private static final Logger LOG = LoggerFactory.getLogger( SecurityManagerImpl.class );

    private static final String PEER_SECRET_KEY_PWD_FILE =
            String.format( "%s/%s", Common.SUBUTAI_APP_DATA_PATH, "peer.pwd" );

    private KeyManager keyManager = null;
    private DaoManager daoManager = null;
    private EncryptionTool encryptionTool = null;
    private SecurityDataService securityDataService = null;
    private KeyServer keyServer = null;
    private SecurityKeyData keyData = null;
    private KeyStoreManager keyStoreManager = null;
    private HttpContextManager httpContextManager;


    /* *****************************
     *
     */
    public SecurityManagerImpl( Object provider ) throws Exception
    {
        keyData = new SecurityKeyData();


        //todo store secret pwd in database along with secret key
        Path secretKeyPwdFile = Paths.get( PEER_SECRET_KEY_PWD_FILE );

        String secretPwd;

        if ( Files.exists( secretKeyPwdFile ) )
        {
            secretPwd = new String( Files.readAllBytes( secretKeyPwdFile ) );

            if ( Strings.isNullOrEmpty( secretPwd ) )
            {
                throw new IllegalStateException( "Peer secret key pwd is invalid" );
            }
        }
        else
        {
            secretPwd = <PASSWORD>();

            Files.write( secretKeyPwdFile, secretPwd.getBytes() );
        }

        keyData.setSecretKeyringPwd( secretPwd );

        httpContextManager = new HttpContextManagerImpl();
    }
{'fraction_non_alphanumeric': 0.09955041746949261, 'fraction_numerical': 0.0006422607578676942, 'mean_word_length': 3.8324282389449187, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5112908', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1862, 'n_words': 337}