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

📄 signatureutils.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/*
 ********************************************************************
 *
 *	Filename    :   SignatureUtils
 *	Package     :   eclipseme.core.internal.signing
 *	System      :   eclipseme.core
 *	Author      :   Kevin Hunter
 *	Description :   Utility routines for preparing for signing.
 *	                
 * Copyright (c) 2004 Kevin Hunter
 * All Rights Reserved.
 * Licensed under the Eclipse Public License - v 1.0
 * For more information see http://www.eclipse.org/legal/epl-v10.html
 *
 *
 *	CVS
 *	$$Source: /cvsroot/eclipseme/eclipseme.core/src/eclipseme/core/internal/signing/SignatureUtils.java,v $$
 *	$$Author: setera $$
 *	$$Date: 2005/10/29 15:39:29 $$
 *	$$Revision: 1.5 $$
 *
 ********************************************************************
 */

package eclipseme.core.internal.signing;

import java.io.FileInputStream;
import java.io.IOException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

import eclipseme.core.IEclipseMECoreConstants;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.model.IJadSignature;
import eclipseme.core.model.IMidletSuiteProject;
import eclipseme.core.model.ISignatureProperties;
import eclipseme.core.signing.SignaturePasswords;

/**
 * This class is used to construct IJadSignature objects.
 * 
 * @author khunter
 *
 */
public class SignatureUtils
{
	/**
	 * Obtain a signature object for the specified IMidletSuiteProject.  The 
	 * signature properties used will be those found in the project's
	 * persistant properties. 
	 * 
	 * @param project
	 * @return
	 * @throws CoreException
	 */
	public static IJadSignature getSignatureObject(IMidletSuiteProject project)
		throws CoreException
	{
		ISignatureProperties sigProps = project.getSignatureProperties();
		
		return(getSignatureObject(project, sigProps));
	}
	
	public static IJadSignature getSignatureObject(IMidletSuiteProject project, ISignatureProperties sigProps)
		throws CoreException
	{
		if (!sigProps.getSignProject())
		{
			return(null);
		}
		
		JadSignature sigObject = null;
		FileInputStream fis = null;
		String strKeyStorePass = null;
		String strKeyPass = null;
		
		switch(sigProps.getPasswordStorageMethod())
		{
		case ISignatureProperties.PASSMETHOD_IN_KEYRING:
		case ISignatureProperties.PASSMETHOD_IN_PROJECT:
			strKeyStorePass = sigProps.getKeyStorePassword();
			strKeyPass = sigProps.getKeyPassword();
			break;
			
		case ISignatureProperties.PASSMETHOD_PROMPT:
		default:
			if (project != null)
			{
				strKeyStorePass = project.getTempKeystorePassword();
				strKeyPass = project.getTempKeyPassword();
			}
			break;
		}
		
		boolean bPromptedForPasswords = false;
		
		if (strKeyStorePass == null || strKeyPass == null)
		{
			IStatus status = new Status(
					IStatus.INFO, 
					IEclipseMECoreConstants.PLUGIN_ID, 
					IEclipseMECoreConstants.INFO_NEED_SIGNATURE_PASSWORDS, 
					"Need signing passwords", null);
			
			SignaturePasswords passwords =
				(SignaturePasswords)EclipseMECorePlugin.statusPrompt(status, project.getProject());
			
			if (passwords == null)
			{
				return(null);
			}
			
			strKeyStorePass = passwords.getKeystorePassword();
			strKeyPass = passwords.getKeyPassword();
			bPromptedForPasswords = true;
		}
		
		try
		{
			fis = new FileInputStream(sigProps.getAbsoluteKeyStorePath(project.getProject()));
			KeyChainSet set = KeyChainSet.getInstance(	fis,
														sigProps.getKeyStoreType(),
														sigProps.getKeyStoreProvider(),
														strKeyStorePass,
														sigProps.getKeyAlias(),
														strKeyPass);
			sigObject = new JadSignature(set);
			sigObject.checkKeyChainSet();
			
			if (bPromptedForPasswords)
			{
				switch(sigProps.getPasswordStorageMethod())
				{
				case ISignatureProperties.PASSMETHOD_IN_KEYRING:
				case ISignatureProperties.PASSMETHOD_IN_PROJECT:
					sigProps.setKeyPassword(strKeyPass);
					sigProps.setKeyStorePassword(strKeyStorePass);
					if (project != null)
					{
						project.saveMetaData();
					}
					break;
					
				case ISignatureProperties.PASSMETHOD_PROMPT:
				default:
					if (project != null)
					{
						project.setTempKeystorePassword(strKeyStorePass);
						project.setTempKeyPassword(strKeyPass);
					}
					break;
				}
			}
						
		}
		catch(IOException ioe)
		{
			EclipseMECorePlugin.throwCoreException(	IStatus.ERROR,
													99999,
													ioe);
		}
		finally
		{
			if (fis != null)
			{
				try
				{
					fis.close();
				}
				catch(Exception e)
				{
				}
			}
		}
		
		return(sigObject);
	}
}

/*
 ********************************************************************
 *	CVS History:
 *	$$Log: SignatureUtils.java,v $
 *	$Revision 1.5  2005/10/29 15:39:29  setera
 *	$Refactor packaging and signing functionality into their own packages
 *	$Warn user while trying to package a project with an invalid platform definition (Bug 1304273)
 *	$
 *	$Revision 1.4  2004/12/12 20:22:07  kdhunter
 *	$Support for storing passwords in keyring
 *	$
 *	$Revision 1.3  2004/12/07 02:42:54  kdhunter
 *	$Switched from custom exception classes to CoreException
 *	$in signing routines.
 *	$Set up basic error code and error message handling, including
 *	$prep for internationalization
 *	$
 *	$Revision 1.2  2004/12/07 01:11:02  kdhunter
 *	$Changes to allow project-relative or absolute
 *	$keystore paths
 *	$
 *	$Revision 1.1  2004/11/27 21:19:32  kdhunter
 *	$Moved here from the ui project, changed to use
 *	$status handlers to prompt for passwords
 *	$$
 *
 ********************************************************************
 */

⌨️ 快捷键说明

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