org.tizen.common.sign_2.0.0.201310241620

16:49:54.382 INFO  jd.cli.Main - Decompiling org.tizen.common.sign_2.0.0.201310241620.jar
package org.tizen.common.sign;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.tizen.common.CommonPlugin;
import org.tizen.common.core.command.Prompter;

public class Activator
  extends AbstractUIPlugin
{
  public static final String PLUGIN_ID = "org.tizen.common.sign";
  private static Activator plugin;
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    plugin = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    plugin = null;
    super.stop(context);
  }
  
  public static Activator getDefault()
  {
    return plugin;
  }
  
  public static ImageDescriptor getImageDescriptor(String path)
  {
    return imageDescriptorFromPlugin("org.tizen.common.sign", path);
  }
  
  public Prompter getPrompter()
  {
    return CommonPlugin.getDefault().getPrompter();
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.Activator
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign;

import java.util.concurrent.atomic.AtomicBoolean;
import org.tizen.common.sign.exception.SigningErrorDialog;

class SigningPrompter$1
  implements Runnable
{
  SigningPrompter$1(SigningPrompter paramSigningPrompter, String paramString, AtomicBoolean paramAtomicBoolean) {}
  
  public void run()
  {
    SigningErrorDialog dialog = new SigningErrorDialog(val$message);
    if (1 == dialog.open()) {
      val$isCanceled.set(true);
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.SigningPrompter.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign;

import java.util.concurrent.atomic.AtomicBoolean;
import org.tizen.common.core.command.CommandCancelException;
import org.tizen.common.core.command.prompter.SWTPrompter;
import org.tizen.common.sign.exception.SigningErrorDialog;
import org.tizen.common.util.SWTUtil;

public class SigningPrompter
  extends SWTPrompter
{
  public void error(final String message)
  {
    final AtomicBoolean isCanceled = new AtomicBoolean(false);
    
    SWTUtil.syncExec(new Runnable()
    {
      public void run()
      {
        SigningErrorDialog dialog = new SigningErrorDialog(message);
        if (1 == dialog.open()) {
          isCanceled.set(true);
        }
      }
    });
    if (isCanceled.get()) {
      throw new CommandCancelException();
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.SigningPrompter
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign.command;

import org.tizen.common.core.command.InputValidator;
import org.tizen.common.util.StringUtil;

class ReadSigningProfileFileCommand$1
  implements InputValidator
{
  ReadSigningProfileFileCommand$1(ReadSigningProfileFileCommand paramReadSigningProfileFileCommand, String paramString) {}
  
  public String check(Object value)
  {
    if ((value instanceof String)) {
      return StringUtil.isEmpty((String)value) ? val$validatorMsg : null;
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.command.ReadSigningProfileFileCommand.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign.command;

import hashsign.HashingSigning;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tizen.common.core.command.AbstractCommand;
import org.tizen.common.core.command.ExecutionContext;
import org.tizen.common.core.command.Executor;
import org.tizen.common.core.command.InputValidator;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.core.command.UserField;
import org.tizen.common.file.FileHandler;
import org.tizen.common.file.FileHandler.Attribute;
import org.tizen.common.file.FileHandler.Type;
import org.tizen.common.sign.exception.CertificationException;
import org.tizen.common.sign.preferences.SigningProfile;
import org.tizen.common.sign.preferences.SigningProfileContainer;
import org.tizen.common.sign.preferences.SigningProfileItem;
import org.tizen.common.util.Assert;
import org.tizen.common.util.StringUtil;

public class ReadSigningProfileFileCommand
  extends AbstractCommand<Object>
{
  protected final Logger logger = LoggerFactory.getLogger(getClass());
  protected final String path;
  protected final String profileName;
  protected SigningProfileContainer container;
  
  public ReadSigningProfileFileCommand(String path, String profileName)
  {
    Assert.notNull(path);
    Assert.notNull(profileName);
    
    this.path = path;
    this.profileName = profileName;
    
    logger.debug("Read profile[{}] from {}", profileName, path);
  }
  
  /* Error */
  public void run(Executor executor, ExecutionContext context)
    throws Exception
  {
    // Byte code:
    //   0: aload_0
    //   1: aload_2
    //   2: invokevirtual 59	org/tizen/common/sign/command/ReadSigningProfileFileCommand:canRun	(Lorg/tizen/common/core/command/ExecutionContext;)Z
    //   5: ifne +4 -> 9
    //   8: return
    //   9: aload_2
    //   10: invokevirtual 63	org/tizen/common/core/command/ExecutionContext:getFileHandler	()Lorg/tizen/common/file/FileHandler;
    //   13: astore_3
    //   14: aload_3
    //   15: aload_0
    //   16: getfield 38	org/tizen/common/sign/command/ReadSigningProfileFileCommand:path	Ljava/lang/String;
    //   19: invokeinterface 69 2 0
    //   24: astore 4
    //   26: aload_0
    //   27: new 75	org/tizen/common/sign/preferences/SigningProfileContainer
    //   30: dup
    //   31: invokespecial 77	org/tizen/common/sign/preferences/SigningProfileContainer:<init>	()V
    //   34: putfield 78	org/tizen/common/sign/command/ReadSigningProfileFileCommand:container	Lorg/tizen/common/sign/preferences/SigningProfileContainer;
    //   37: aload_0
    //   38: getfield 78	org/tizen/common/sign/command/ReadSigningProfileFileCommand:container	Lorg/tizen/common/sign/preferences/SigningProfileContainer;
    //   41: aload 4
    //   43: invokevirtual 80	org/tizen/common/sign/preferences/SigningProfileContainer:readProfileXML	(Ljava/io/InputStream;)Ljava/lang/String;
    //   46: pop
    //   47: aload_0
    //   48: getfield 78	org/tizen/common/sign/command/ReadSigningProfileFileCommand:container	Lorg/tizen/common/sign/preferences/SigningProfileContainer;
    //   51: invokevirtual 84	org/tizen/common/sign/preferences/SigningProfileContainer:getProfiles	()Ljava/util/List;
    //   54: invokeinterface 88 1 0
    //   59: astore 6
    //   61: goto +97 -> 158
    //   64: aload 6
    //   66: invokeinterface 94 1 0
    //   71: checkcast 100	org/tizen/common/sign/preferences/SigningProfile
    //   74: astore 5
    //   76: aload_0
    //   77: getfield 30	org/tizen/common/sign/command/ReadSigningProfileFileCommand:logger	Lorg/slf4j/Logger;
    //   80: ldc 102
    //   82: aload 5
    //   84: invokevirtual 104	org/tizen/common/sign/preferences/SigningProfile:getProfileName	()Ljava/lang/String;
    //   87: invokeinterface 108 3 0
    //   92: aload_0
    //   93: getfield 30	org/tizen/common/sign/command/ReadSigningProfileFileCommand:logger	Lorg/slf4j/Logger;
    //   96: ldc 112
    //   98: aload 5
    //   100: invokevirtual 114	org/tizen/common/sign/preferences/SigningProfile:getAuthorProfileItem	()Lorg/tizen/common/sign/preferences/SigningProfileItem;
    //   103: invokeinterface 108 3 0
    //   108: aload 5
    //   110: invokevirtual 118	org/tizen/common/sign/preferences/SigningProfile:getDistributorProfileItems	()Ljava/util/List;
    //   113: invokeinterface 88 1 0
    //   118: astore 8
    //   120: goto +28 -> 148
    //   123: aload 8
    //   125: invokeinterface 94 1 0
    //   130: checkcast 121	org/tizen/common/sign/preferences/SigningProfileItem
    //   133: astore 7
    //   135: aload_0
    //   136: getfield 30	org/tizen/common/sign/command/ReadSigningProfileFileCommand:logger	Lorg/slf4j/Logger;
    //   139: ldc 123
    //   141: aload 7
    //   143: invokeinterface 108 3 0
    //   148: aload 8
    //   150: invokeinterface 125 1 0
    //   155: ifne -32 -> 123
    //   158: aload 6
    //   160: invokeinterface 125 1 0
    //   165: ifne -101 -> 64
    //   168: aload_0
    //   169: aload_1
    //   170: aload_2
    //   171: invokevirtual 129	org/tizen/common/sign/command/ReadSigningProfileFileCommand:interactForPassword	(Lorg/tizen/common/core/command/Executor;Lorg/tizen/common/core/command/ExecutionContext;)V
    //   174: aload_0
    //   175: invokevirtual 132	org/tizen/common/sign/command/ReadSigningProfileFileCommand:validateSigningInfo	()V
    //   178: goto +20 -> 198
    //   181: astore 9
    //   183: iconst_1
    //   184: anewarray 19	java/lang/Object
    //   187: dup
    //   188: iconst_0
    //   189: aload 4
    //   191: aastore
    //   192: invokestatic 135	org/tizen/common/util/IOUtil:tryClose	([Ljava/lang/Object;)V
    //   195: aload 9
    //   197: athrow
    //   198: iconst_1
    //   199: anewarray 19	java/lang/Object
    //   202: dup
    //   203: iconst_0
    //   204: aload 4
    //   206: aastore
    //   207: invokestatic 135	org/tizen/common/util/IOUtil:tryClose	([Ljava/lang/Object;)V
    //   210: return
    // Line number table:
    //   Java source line #93	-> byte code offset #0
    //   Java source line #94	-> byte code offset #8
    //   Java source line #97	-> byte code offset #9
    //   Java source line #98	-> byte code offset #14
    //   Java source line #101	-> byte code offset #26
    //   Java source line #102	-> byte code offset #37
    //   Java source line #104	-> byte code offset #47
    //   Java source line #105	-> byte code offset #76
    //   Java source line #106	-> byte code offset #92
    //   Java source line #107	-> byte code offset #108
    //   Java source line #108	-> byte code offset #135
    //   Java source line #107	-> byte code offset #148
    //   Java source line #104	-> byte code offset #158
    //   Java source line #112	-> byte code offset #168
    //   Java source line #113	-> byte code offset #174
    //   Java source line #115	-> byte code offset #181
    //   Java source line #116	-> byte code offset #189
    //   Java source line #117	-> byte code offset #195
    //   Java source line #115	-> byte code offset #198
    //   Java source line #116	-> byte code offset #204
    //   Java source line #118	-> byte code offset #210
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	211	0	this	ReadSigningProfileFileCommand
    //   0	211	1	executor	Executor
    //   0	211	2	context	ExecutionContext
    //   13	2	3	fileHandler	FileHandler
    //   24	181	4	profileInputStream	java.io.InputStream
    //   74	35	5	profile	SigningProfile
    //   59	100	6	localIterator1	java.util.Iterator
    //   133	9	7	item	SigningProfileItem
    //   118	31	8	localIterator2	java.util.Iterator
    //   181	15	9	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   26	181	181	finally
  }
  
  protected void checkPkcs12Password(SigningProfileItem item)
    throws CertificationException
  {
    boolean isCorrectPassword = false;
    try
    {
      char[] pass = item.getPassword();
      String password = pass == null ? "" : new String(pass);
      String path = item.getKeyLocation();
      isCorrectPassword = HashingSigning.CheckPkcs12Password(path, password);
    }
    catch (FileNotFoundException e)
    {
      throw new CertificationException("Certificate file not found", e);
    }
    catch (NoSuchAlgorithmException e)
    {
      throw new CertificationException("Not supported certificate file format", e);
    }
    catch (CertificateException e)
    {
      throw new CertificationException("Could not load a certificate for PKCS12 format", e);
    }
    catch (KeyStoreException e)
    {
      throw new CertificationException("Could not find a keystore", e);
    }
    catch (IOException e)
    {
      throw new CertificationException("Failed to manipulate a certificate", e);
    }
    if (!isCorrectPassword) {
      throw new CertificationException("Invaild password");
    }
  }
  
  protected void validateSigningInfo()
    throws CertificationException
  {
    SigningProfile profile = getProfile();
    if (profile == null) {
      return;
    }
    for (SigningProfileItem item : profile.getProfileItems()) {
      if (isValidItem(item)) {
        checkPkcs12Password(item);
      }
    }
  }
  
  protected void interactForPassword(Executor executor, ExecutionContext context)
    throws Exception
  {
    SigningProfile profile = getProfile();
    if (profile == null) {
      return;
    }
    SigningProfileItem authorItem = profile.getProfileItem(0);
    boolean hasAuthor = isValidItem(authorItem);
    
    SigningProfileItem dist1Item = profile.getProfileItem(1);
    boolean hasDist1 = isValidItem(dist1Item);
    if ((!hasAuthor) || (!hasDist1))
    {
      String msg = "Both an author and a first distributor must be required. Please check your profile infomation.";
      context.getPrompter().notify(msg);
      throw new CertificationException(msg);
    }
    SigningProfileItem dist2Item = profile.getProfileItem(2);
    boolean hasDist2 = isValidItem(dist2Item);
    if ((authorItem.hasPassword()) && (dist1Item.hasPassword()) && (
      (!hasDist2) || (dist2Item.hasPassword()))) {
      return;
    }
    List<UserField> fieldList = new ArrayList();
    
    Object[][] fields = {
      { "author", "Author password: ", Boolean.valueOf(isModifiable(authorItem)), authorItem.getPassword(), "Input author password.", "authorPwdSavable", "Save author password" }, 
      { "distributor1", "Distributor1 password: ", Boolean.valueOf(isModifiable(dist1Item)), dist1Item.getPassword(), "Input distributor1 password.", "dist1PwdSavable", "Save distributor1 password" }, 
      { "distributor2", "Distributor2 password: ", Boolean.valueOf(isModifiable(dist2Item)), hasDist2 ? dist2Item.getPassword() : new char[0], "Input distributor2 password.", "dist2PwdSavable", "Save distributor2 password" } };
    Object[][] arrayOfObject1;
    int j = (arrayOfObject1 = fields).length;
    for (int i = 0; i < j; i++)
    {
      Object[] field = arrayOfObject1[i];
      String textId = (String)field[0];
      String textMsg = (String)field[1];
      boolean modifiable = ((Boolean)field[2]).booleanValue();
      char[] password = (char[])field[3];
      String validatorMsg = (String)field[4];
      String buttonId = (String)field[5];
      String buttonMsg = (String)field[6];
      
      UserField textField = createPasswordField(textId, textMsg, modifiable, password, validatorMsg);
      fieldList.add(textField);
      
      UserField buttonField = createButtonField(buttonId, buttonMsg, modifiable);
      fieldList.add(buttonField);
    }
    Map<String, Object> options = new HashMap();
    options.put("title", "Signing Dialog");
    
    context.getPrompter().batch(fieldList, options);
    
    boolean[] updateFlags = { ((Boolean)fields[0][2]).booleanValue(), ((Boolean)fields[1][2]).booleanValue(), ((Boolean)fields[2][2]).booleanValue() };
    for (int i = 0; i <= 2; i++) {
      updateProfileItem(profile, i, (UserField)fieldList.get(i * 2), (UserField)fieldList.get(i * 2 + 1), updateFlags[i], true);
    }
    writeProfiles(executor, context);
    for (int i = 0; i <= 2; i++) {
      updateProfileItem(profile, i, (UserField)fieldList.get(i * 2), (UserField)fieldList.get(i * 2 + 1), updateFlags[i], false);
    }
  }
  
  protected void updateProfileItem(SigningProfile profile, int ordinal, UserField text, UserField button, boolean modifiable, boolean savable)
  {
    boolean saveValue = getBoolean(button.getValue());
    if (!savable) {
      saveValue = !saveValue;
    }
    if ((modifiable) && (saveValue))
    {
      SigningProfileItem profileItem = profile.removeProfileItem(ordinal);
      if (profileItem != null)
      {
        profileItem.setPassword((char[])text.getValue());
        profile.setProfileItem(ordinal, profileItem);
      }
    }
  }
  
  protected UserField createPasswordField(String id, String message, boolean modifiable, char[] password, final String validatorMsg)
  {
    UserField userField = new UserField(id, message, char[].class);
    if (!modifiable)
    {
      userField.setModify(false);
    }
    else
    {
      userField.setValue(password);
      userField.setValidator(new InputValidator()
      {
        public String check(Object value)
        {
          if ((value instanceof String)) {
            return StringUtil.isEmpty((String)value) ? validatorMsg : null;
          }
          return null;
        }
      });
    }
    return userField;
  }
  
  protected UserField createButtonField(String id, String message, boolean modifiable)
  {
    UserField userField = new UserField(id, message, Boolean.TYPE);
    if (!modifiable) {
      userField.setModify(false);
    }
    return userField;
  }
  
  public SigningProfile getProfile()
  {
    if ((container == null) || (profileName == null)) {
      return null;
    }
    return container.getProfileByName(profileName);
  }
  
  /* Error */
  protected void writeProfiles(Executor executor, ExecutionContext context)
    throws Exception
  {
    // Byte code:
    //   0: aload_2
    //   1: invokevirtual 63	org/tizen/common/core/command/ExecutionContext:getFileHandler	()Lorg/tizen/common/file/FileHandler;
    //   4: astore_3
    //   5: new 428	java/io/ByteArrayOutputStream
    //   8: dup
    //   9: invokespecial 430	java/io/ByteArrayOutputStream:<init>	()V
    //   12: astore 4
    //   14: aload_0
    //   15: getfield 78	org/tizen/common/sign/command/ReadSigningProfileFileCommand:container	Lorg/tizen/common/sign/preferences/SigningProfileContainer;
    //   18: aload 4
    //   20: invokevirtual 431	org/tizen/common/sign/preferences/SigningProfileContainer:writeProfileXML	(Ljava/io/OutputStream;)V
    //   23: new 435	java/io/ByteArrayInputStream
    //   26: dup
    //   27: aload 4
    //   29: invokevirtual 437	java/io/ByteArrayOutputStream:toByteArray	()[B
    //   32: invokespecial 441	java/io/ByteArrayInputStream:<init>	([B)V
    //   35: astore 5
    //   37: aload_3
    //   38: aload_0
    //   39: getfield 38	org/tizen/common/sign/command/ReadSigningProfileFileCommand:path	Ljava/lang/String;
    //   42: aload 5
    //   44: invokeinterface 444 3 0
    //   49: goto +20 -> 69
    //   52: astore 6
    //   54: iconst_1
    //   55: anewarray 19	java/lang/Object
    //   58: dup
    //   59: iconst_0
    //   60: aload 5
    //   62: aastore
    //   63: invokestatic 135	org/tizen/common/util/IOUtil:tryClose	([Ljava/lang/Object;)V
    //   66: aload 6
    //   68: athrow
    //   69: iconst_1
    //   70: anewarray 19	java/lang/Object
    //   73: dup
    //   74: iconst_0
    //   75: aload 5
    //   77: aastore
    //   78: invokestatic 135	org/tizen/common/util/IOUtil:tryClose	([Ljava/lang/Object;)V
    //   81: return
    // Line number table:
    //   Java source line #297	-> byte code offset #0
    //   Java source line #299	-> byte code offset #5
    //   Java source line #300	-> byte code offset #14
    //   Java source line #301	-> byte code offset #23
    //   Java source line #304	-> byte code offset #37
    //   Java source line #305	-> byte code offset #52
    //   Java source line #306	-> byte code offset #60
    //   Java source line #307	-> byte code offset #66
    //   Java source line #305	-> byte code offset #69
    //   Java source line #306	-> byte code offset #75
    //   Java source line #308	-> byte code offset #81
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	82	0	this	ReadSigningProfileFileCommand
    //   0	82	1	executor	Executor
    //   0	82	2	context	ExecutionContext
    //   4	34	3	fileHandler	FileHandler
    //   12	16	4	outStream	java.io.ByteArrayOutputStream
    //   35	41	5	in	java.io.InputStream
    //   52	15	6	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   37	52	52	finally
  }
  
  protected boolean canRun(ExecutionContext context)
    throws IOException
  {
    FileHandler fileHandler = context.getFileHandler();
    if (!fileHandler.is(path, FileHandler.Attribute.EXISTS)) {
      return false;
    }
    if (!fileHandler.is(path, FileHandler.Attribute.READABLE)) {
      return false;
    }
    return FileHandler.Type.FILE.equals(fileHandler.get(path, FileHandler.Attribute.TYPE));
  }
  
  protected boolean isValidItem(SigningProfileItem item)
  {
    return item == null ? false : item.hasKeyLocation();
  }
  
  protected boolean isModifiable(SigningProfileItem item)
  {
    if (!isValidItem(item)) {
      return false;
    }
    char[] password = item.getPassword();
    if ((password != null) && (!StringUtil.isEmpty(new String(password)))) {
      return false;
    }
    return true;
  }
  
  protected boolean getBoolean(Object obj)
  {
    return obj == null ? true : Boolean.parseBoolean(String.valueOf(obj));
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.command.ReadSigningProfileFileCommand
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign.command;

import java.io.IOException;
import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
import org.tizen.common.core.command.ExecutionContext;
import org.tizen.common.core.command.Executor;
import org.tizen.common.core.command.Policy;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.core.command.file.FileHandlingCommand;
import org.tizen.common.core.command.policy.MessagePolicy;
import org.tizen.common.file.FileHandler;
import org.tizen.common.file.FileHandler.Attribute;
import org.tizen.common.file.FileHandler.Type;
import org.tizen.common.sign.exception.CertificationException;
import org.tizen.common.sign.preferences.SigningProfile;
import org.tizen.common.sign.preferences.SigningProfileItem;
import org.tizen.common.sign.signer.TizenSigner;
import org.tizen.common.sign.util.SignatureUtility;
import org.tizen.common.util.Assert;
import org.tizen.common.util.StringUtil;

public class SignCommand
  extends FileHandlingCommand<Object>
{
  protected SigningProfile profile;
  protected boolean bRDS;
  
  public SignCommand(String root, SigningProfile profile)
  {
    this(root, profile, false);
  }
  
  public SignCommand(String root, SigningProfile profile, boolean bRDS)
  {
    path = root;
    this.profile = profile;
    this.bRDS = bRDS;
  }
  
  public void run(Executor executor, ExecutionContext context)
    throws IOException, CertificationException
  {
    FileHandler handler = context.getFileHandler();
    Assert.notNull(handler);
    if (!handler.is(path, FileHandler.Attribute.EXISTS))
    {
      Policy policy = context.getPolicy("nonexist.dir.in.project");
      MessagePolicy messagePolicy = (MessagePolicy)policy.adapt(MessagePolicy.class);
      if (messagePolicy != null) {
        messagePolicy.print(context.getPrompter(), "{0} doesn't exist", new Object[] { path });
      }
      return;
    }
    String appDirPath = (String)handler.get(path, FileHandler.Attribute.PATH);
    for (String child : handler.list(appDirPath))
    {
      Object type = handler.get(child, FileHandler.Attribute.TYPE);
      Object nameObj = handler.get(child, FileHandler.Attribute.NAME);
      if ((FileHandler.Type.FILE.equals(type)) && ((nameObj instanceof String)))
      {
        name = (String)nameObj;
        if (SignatureUtility.isSignatureFile(name)) {
          try
          {
            handler.removeFile(child);
          }
          catch (IOException localIOException)
          {
            logger.warn("Cannot remove a file. Path : {}", child);
          }
        }
      }
    }
    StopWatch stopWatch = new StopWatch();
    label404:
    try
    {
      stopWatch.start();
      
      SigningProfileItem authorItem = profile.getProfileItem(0);
      SigningProfileItem dist1Item = profile.getProfileItem(1);
      SigningProfileItem dist2Item = profile.getProfileItem(2);
      if ((authorItem != null) && (dist1Item != null))
      {
        signAuthor(appDirPath, authorItem);
        signDistributor1(appDirPath, dist1Item);
        if (dist2Item != null)
        {
          signDistributor2(appDirPath, dist2Item);
          break label404;
        }
      }
      else
      {
        logger.error("Profiles is not set. Author : {}, Dist1 : {}", authorItem, dist1Item);
      }
    }
    catch (Exception e)
    {
      context.getPrompter().error(e.getMessage());
      throw new CertificationException("Can't create XML Signature file", e);
    }
    catch (OutOfMemoryError e)
    {
      context.getPrompter().error(e.getMessage());
      throw new CertificationException("Can't create XML Signature file", e);
    }
    finally
    {
      logger.debug("Elapsed time for sign : {}ms", Long.valueOf(stopWatch.getTime()));
    }
  }
  
  private void signAuthor(String appDirPath, SigningProfileItem profileItem)
    throws Exception
  {
    if (bRDS) {
      TizenSigner.authorIncrementalSign(appDirPath, 
        getContentFilePath(profileItem), 
        getContentFilePasswd(profileItem), 
        getCaCertPath(profileItem), 
        getRootCertPath(profileItem));
    } else {
      TizenSigner.authorSign(appDirPath, 
        getContentFilePath(profileItem), 
        getContentFilePasswd(profileItem), 
        getCaCertPath(profileItem), 
        getRootCertPath(profileItem));
    }
  }
  
  private void signDistributor1(String appDirPath, SigningProfileItem profileItem)
    throws Exception
  {
    if (bRDS) {
      TizenSigner.distIncrementalSign(appDirPath, 
        getContentFilePath(profileItem), 
        getContentFilePasswd(profileItem), 
        getCaCertPath(profileItem), 
        getRootCertPath(profileItem), 
        1);
    } else {
      TizenSigner.distSign(appDirPath, 
        getContentFilePath(profileItem), 
        getContentFilePasswd(profileItem), 
        getCaCertPath(profileItem), 
        getRootCertPath(profileItem), 
        1);
    }
  }
  
  private void signDistributor2(String appDirPath, SigningProfileItem profileItem)
    throws Exception
  {
    if (bRDS) {
      TizenSigner.dist2IncrementalSignWithParameterCheck(appDirPath, 
        getContentFilePath(profileItem), 
        getContentFilePasswd(profileItem), 
        getCaCertPath(profileItem), 
        getRootCertPath(profileItem));
    } else {
      TizenSigner.dist2SignWithParameterCheck(appDirPath, 
        getContentFilePath(profileItem), 
        getContentFilePasswd(profileItem), 
        getCaCertPath(profileItem), 
        getRootCertPath(profileItem));
    }
  }
  
  private String filterEmptyString(String msg, String content)
  {
    String trimmedContent = StringUtil.trim(content);
    logger.debug(msg, trimmedContent);
    return (trimmedContent != null) && (trimmedContent.isEmpty()) ? null : trimmedContent;
  }
  
  private String getContentFilePath(SigningProfileItem profileItem)
  {
    return filterEmptyString("profile key path : {}", profileItem.getKeyLocation());
  }
  
  private String getContentFilePasswd(SigningProfileItem profileItem)
  {
    return filterEmptyString("profile key password : {}", new String(profileItem.getPassword()));
  }
  
  private String getCaCertPath(SigningProfileItem profileItem)
  {
    return filterEmptyString("profile CA path : {}", profileItem.getCAPath());
  }
  
  private String getRootCertPath(SigningProfileItem profileItem)
  {
    return filterEmptyString("profile RootCA path : {}", profileItem.getRootCAPath());
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.command.SignCommand
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign.exception;

public class CertificationException
  extends Exception
{
  private static final long serialVersionUID = 7001672806422880543L;
  
  public CertificationException(String msg, Throwable cause)
  {
    super(msg, cause);
  }
  
  public CertificationException(String msg)
  {
    super(msg);
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.exception.CertificationException
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign.exception;

public class ComplicatedCertificationException
  extends CertificationException
{
  private static final long serialVersionUID = -8921261148323181356L;
  
  public ComplicatedCertificationException(String msg)
  {
    super(msg);
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.exception.ComplicatedCertificationException
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign.exception;

import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.ui.dialogs.PreferencesUtil;

class SigningErrorDialog$1
  implements SelectionListener
{
  SigningErrorDialog$1(SigningErrorDialog paramSigningErrorDialog) {}
  
  public void widgetSelected(SelectionEvent e)
  {
    PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(this$0.getShell(), "org.tizen.common.sign.preferences.SigningPreferencePage", new String[] { "org.tizen.common.sign.preferences.SigningPreferencePage" }, null);
    dialog.open();
  }
  
  public void widgetDefaultSelected(SelectionEvent e) {}
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.exception.SigningErrorDialog.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign.exception;

import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.graphics.Image;

class SigningErrorDialog$2
  extends AccessibleAdapter
{
  SigningErrorDialog$2(SigningErrorDialog paramSigningErrorDialog, Image paramImage) {}
  
  public void getName(AccessibleEvent event)
  {
    String accessibleMessage = SigningErrorDialog.access$0(this$0, val$image);
    if (accessibleMessage == null) {
      return;
    }
    result = accessibleMessage;
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.exception.SigningErrorDialog.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign.exception;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IconAndMessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.accessibility.Accessible;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.tizen.common.util.SWTUtil;
import org.tizen.common.util.StringUtil;

public class SigningErrorDialog
  extends IconAndMessageDialog
{
  private String title;
  
  public SigningErrorDialog(String message)
  {
    this(SWTUtil.getActiveShell(), "Signing", message);
  }
  
  public SigningErrorDialog(Shell parentShell, String dialogTitle, String message)
  {
    super(parentShell);
    title = StringUtil.nvl(new String[] { dialogTitle, JFaceResources.getString("Problem_Occurred") });
    this.message = message;
  }
  
  protected void configureShell(Shell shell)
  {
    super.configureShell(shell);
    shell.setText(title);
  }
  
  protected void createButtonsForButtonBar(Composite parent)
  {
    createButton(parent, 1, IDialogConstants.CANCEL_LABEL, true);
    createButton(parent, 0, IDialogConstants.OK_LABEL, true);
  }
  
  protected Control createDialogArea(Composite parent)
  {
    Composite composite = new Composite(parent, 0);
    createMessageArea(composite);
    GridLayout layout = new GridLayout();
    marginHeight = convertVerticalDLUsToPixels(7);
    marginWidth = convertHorizontalDLUsToPixels(7);
    verticalSpacing = convertVerticalDLUsToPixels(4);
    horizontalSpacing = convertHorizontalDLUsToPixels(4);
    numColumns = 2;
    composite.setLayout(layout);
    GridData childData = new GridData(1808);
    horizontalSpan = 2;
    grabExcessVerticalSpace = false;
    composite.setLayoutData(childData);
    composite.setFont(parent.getFont());
    
    return composite;
  }
  
  protected Control createMessageArea(Composite composite)
  {
    Image image = getImage();
    if (image != null)
    {
      imageLabel = new Label(composite, 0);
      image.setBackground(imageLabel.getBackground());
      imageLabel.setImage(image);
      addAccessibleListeners(imageLabel, image);
      GridDataFactory.fillDefaults().align(16777216, 1)
        .applyTo(imageLabel);
    }
    if (message != null)
    {
      Link messageLabel = new Link(composite, getMessageLabelStyle());
      messageLabel.setText(message);
      GridDataFactory.fillDefaults().align(4, 1).grab(true, false).hint(
        convertHorizontalDLUsToPixels(300), 
        -1).applyTo(messageLabel);
      messageLabel.addSelectionListener(new SelectionListener()
      {
        public void widgetSelected(SelectionEvent e)
        {
          PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getShell(), "org.tizen.common.sign.preferences.SigningPreferencePage", new String[] { "org.tizen.common.sign.preferences.SigningPreferencePage" }, null);
          dialog.open();
        }
        
        public void widgetDefaultSelected(SelectionEvent e) {}
      });
    }
    return composite;
  }
  
  private void addAccessibleListeners(Label label, final Image image)
  {
    label.getAccessible().addAccessibleListener(new AccessibleAdapter()
    {
      public void getName(AccessibleEvent event)
      {
        String accessibleMessage = SigningErrorDialog.this.getAccessibleMessageFor(image);
        if (accessibleMessage == null) {
          return;
        }
        result = accessibleMessage;
      }
    });
  }
  
  private String getAccessibleMessageFor(Image image)
  {
    if (image.equals(getErrorImage())) {
      return JFaceResources.getString("error");
    }
    if (image.equals(getWarningImage())) {
      return JFaceResources.getString("warning");
    }
    if (image.equals(getInfoImage())) {
      return JFaceResources.getString("info");
    }
    if (image.equals(getQuestionImage())) {
      return JFaceResources.getString("question");
    }
    return null;
  }
  
  protected void createDialogAndButtonArea(Composite parent)
  {
    super.createDialogAndButtonArea(parent);
    if ((dialogArea instanceof Composite))
    {
      Composite dialogComposite = (Composite)dialogArea;
      if (dialogComposite.getChildren().length == 0) {
        new Label(dialogComposite, 0);
      }
    }
  }
  
  protected Image getImage()
  {
    return getErrorImage();
  }
  
  public static int openError(Shell parent, String dialogTitle, String message, IStatus status)
  {
    return openError(parent, dialogTitle, message, status, 7);
  }
  
  public static int openError(Shell parentShell, String title, String message, IStatus status, int displayMask)
  {
    ErrorDialog dialog = new ErrorDialog(parentShell, title, message, 
      status, displayMask);
    return dialog.open();
  }
  
  protected static boolean shouldDisplay(IStatus status, int mask)
  {
    IStatus[] children = status.getChildren();
    if ((children == null) || (children.length == 0)) {
      return status.matches(mask);
    }
    for (int i = 0; i < children.length; i++) {
      if (children[i].matches(mask)) {
        return true;
      }
    }
    return false;
  }
  
  protected boolean isResizable()
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.exception.SigningErrorDialog
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign.model;

public enum Certification$KeyExtension
{
  p12("PKCS12"),  keystore("JKS");
  
  private String keyType;
  
  private Certification$KeyExtension(String keyType)
  {
    this.keyType = keyType;
  }
  
  public String getKeyType()
  {
    return keyType;
  }
  
  public static boolean hasExtension(String extension)
  {
    KeyExtension[] arrayOfKeyExtension;
    int j = (arrayOfKeyExtension = values()).length;
    for (int i = 0; i < j; i++)
    {
      KeyExtension keyExt = arrayOfKeyExtension[i];
      if (keyExt.name().equalsIgnoreCase(extension)) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.tizen.common.sign.model.Certification.KeyExtension
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.common.sign.model;

import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.sign.exception.CertificationException;
import org.tizen.common.sign.exception.ComplicatedCertificationException;
import org.tizen.common.sign.preferences.SigningProfileItem;
import org.tizen.common.sign.preferences.UIMessages;

public class Certification
{
  protected final Logger logger = LoggerFactory.getLogger(getClass());
  protected Prompter prompter;
  protected KeyStore keyStore;
  protected PrivateKey privateKey;
  protected String privateKeyAlias;
  protected List<X509Certificate> certificationChain;
  protected X509Certificate certificate;
  protected String password;
  
  public static enum KeyExtension
  {
    p12("PKCS12"),  keystore("JKS");
    
    private String keyType;
    
    private KeyExtension(String keyType)
    {
      this.keyType = keyType;
    }
    
    public String getKeyType()
    {
      return keyType;
    }
    
    public static boolean hasExtension(String extension)
    {
      KeyExtension[] arrayOfKeyExtension;
      int j = (arrayOfKeyExtension = values()).length;
      for (int i = 0; i < j; i++)
      {
        KeyExtension keyExt = arrayOfKeyExtension[i];
        if (keyExt.name().equalsIgnoreCase(extension)) {
          return true;
        }
      }
      return false;
    }
  }
  
  public Certification(Prompter prompter)
  {
    this.prompter = prompter;
  }
  
  protected Prompter getPrompter()
  {
    return prompter;
  }
  
  protected char[] inputPassword(String message)
  {
    Prompter prompter = getPrompter();
    return (char[])prompter.password(message);
  }
  
  public String getPassword()
  {
    return password;
  }
  
  public void setPassword(String password)
  {
    this.password = password;
  }
  
  public boolean load(SigningProfileItem profileItem)
    throws CertificationException
  {
    String keyLocation = profileItem.getKeyLocation();
    c
1 2 3 4 5 6

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd