⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trustedservercertificateimporttype.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 *  SSL-Explorer
 *
 *  Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
			
package com.sslexplorer.keystore.wizards.types;

import java.io.File;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.sslexplorer.boot.ContextHolder;
import com.sslexplorer.boot.KeyStoreManager;
import com.sslexplorer.core.CoreAttributeConstants;
import com.sslexplorer.core.CoreEvent;
import com.sslexplorer.core.CoreEventConstants;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType;
import com.sslexplorer.security.PublicKeyStore;
import com.sslexplorer.security.pki.SshPrivateKey;
import com.sslexplorer.wizard.AbstractWizardSequence;


/**
 * Implementation of a {@link com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType}
 * that imports a trusted server certificate.
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.7 $
 */
public class TrustedServerCertificateImportType extends AbstractKeyStoreImportType {
    

    /**
     * Constant for importing server certificates that SSL-Explorer should trust
     */
    public final static String TRUSTED_SERVER_CERTIFICATE = "trustedServerCertificate";

    /**
     * Constructor.
     */
    public TrustedServerCertificateImportType() {
        super(TRUSTED_SERVER_CERTIFICATE, "keystore", false, true, 30);
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType#validate(org.apache.struts.action.ActionErrors, java.lang.String, java.lang.String, com.sslexplorer.wizard.AbstractWizardSequence)
     */
    public void validate(ActionMessages errs, String alias, String passphrase, AbstractWizardSequence seq) {
        super.validate(errs, alias, passphrase, seq);
        if(alias==null || alias.equals("")) {
            errs.add(Globals.ERROR_KEY, new ActionMessage("keyStoreImportWizard.keyStoreImportFile.noNameProvided"));                        
        }
        else {
            KeyStoreManager mgr = KeyStoreManager.getInstance(KeyStoreManager.TRUSTED_SERVER_CERTIFICATES_KEY_STORE);
            if(mgr.getCertificate(alias.toLowerCase()) != null) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("keyStoreImportWizard.keyStoreImportFile.duplicateName", alias.toLowerCase()));                            
            }
        }
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType#doInstall(java.io.File, java.lang.String, java.lang.String, com.sslexplorer.wizard.AbstractWizardSequence)
     */
    public void doInstall(File file, String alias, String passphrase, AbstractWizardSequence seq) throws Exception {
        KeyStoreManager mgr = KeyStoreManager.getInstance(KeyStoreManager.TRUSTED_SERVER_CERTIFICATES_KEY_STORE);
        mgr.importCert(alias, file, null);
        mgr.reloadKeystore();
        Certificate certif = mgr.getCertificate(alias);

        CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.KEYSTORE_TRUSTED_CERTIFICATE_IMPORTED, ContextHolder.getContext().getContextProperty("webServer.alias"), seq.getSession())
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_ALIAS, alias)
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_TYPE, certif.getType())
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_HOSTNAME, KeyStoreManager.getX509CertificateEntity((X509Certificate)certif, "cn"))
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_ORGANISATIONAL_UNIT, KeyStoreManager.getX509CertificateEntity((X509Certificate)certif, "ou"))
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_COMPANY, KeyStoreManager.getX509CertificateEntity((X509Certificate)certif, "o"))
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_STATE, KeyStoreManager.getX509CertificateEntity((X509Certificate)certif, "st"))
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_LOCATION, KeyStoreManager.getX509CertificateEntity((X509Certificate)certif, "l"))
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_COUNTRY_CODE, KeyStoreManager.getX509CertificateEntity((X509Certificate)certif, "c"));
        
        CoreServlet.getServlet().fireCoreEvent(coreEvent);
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType#init(javax.servlet.http.HttpServletRequest)
     */
    public void init(HttpServletRequest request) {
        super.init(request);
        ActionMessages messages =
            (ActionMessages) request.getAttribute(Globals.MESSAGE_KEY);
        if (messages == null) {
            messages = new ActionMessages();
        }
        messages.add(Globals.MESSAGE_KEY, new ActionMessage("keyStoreImportWizard.keyStoreImportFile.caseWarnimg"));
        request.setAttribute(Globals.MESSAGE_KEY, messages);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -