From 130e2c3f3976d0d5eb43aad42b9e814dab7a37f9 Mon Sep 17 00:00:00 2001 From: "kh5325.kim" Date: Mon, 24 Jun 2013 19:06:24 +0900 Subject: Upload tizen_2.2 source Change-Id: Idfb0240f7b27fad93e6fd95f40fda1e64eed997b --- .../ui/TizenRemoteFileLabelProvider.java | 2 +- .../src/org/tizen/sdblib/Device.java | 4 +- .../tizen/sdblib/receiver/FileEntryFactory.java | 2 +- .../tizen/sdblib/service/CrashReportService.java | 6 + .../src/org/tizen/sdblib/service/FileEntry.java | 6 +- .../src/org/tizen/sdblib/service/SyncService.java | 96 +- .../src/org/tizen/sdblib/util/FileEntryUtil.java | 2 +- org.tizen.common.sign/.classpath | 1 + org.tizen.common.sign/META-INF/MANIFEST.MF | 7 +- .../OSGI-INF/l10n/bundle.properties | 2 +- org.tizen.common.sign/build.properties | 3 +- .../certificates/developer/conf.ini | 1 + .../developer/tizen-developer-ca-privatekey.pem | 18 + .../certificates/developer/tizen-developer-ca.cer | 17 + org.tizen.common.sign/lib/KeyCertGeneratorApi.jar | Bin 0 -> 2641022 bytes .../command/ReadSigningProfileFileCommand.java | 254 ++-- .../org/tizen/common/sign/command/SignCommand.java | 63 +- .../common/sign/model/SignatureConstants.java | 26 +- .../common/sign/preferences/Messages.properties | 4 +- .../sign/preferences/ProfileCellModifier.java | 111 +- .../preferences/ProfileItemContentProvider.java | 32 +- .../sign/preferences/ProfileItemLabelProvider.java | 70 +- .../sign/preferences/SigningPreferencePage.java | 1471 ++++++++++---------- .../common/sign/preferences/SigningProfile.java | 324 ++++- .../sign/preferences/SigningProfileContainer.java | 338 +++++ .../common/sign/preferences/UIMessages.properties | 4 +- .../common/sign/signer/SignatureGenerator.java | 56 +- .../tizen/common/sign/ui/CertGenerationDialog.java | 170 +++ .../tizen/common/sign/ui/ProfileItemDialog.java | 203 +++ .../tizen/common/sign/ui/TizenSigningDialog.java | 356 ----- .../tizen/common/sign/util/SigningProfileUtil.java | 552 +------- .../src/org/tizen/common/sign/util/XMLUtil.java | 7 + .../rds/ui/preference/RdsPreferencePage.java | 29 +- .../org/tizen/common/util/DefferedTaskManager.java | 8 +- .../src/org/tizen/common/util/SWTUtil.java | 21 +- package/changelog | 18 + package/pkginfo.manifest | 2 +- 37 files changed, 2337 insertions(+), 1949 deletions(-) create mode 100644 org.tizen.common.sign/certificates/developer/conf.ini create mode 100644 org.tizen.common.sign/certificates/developer/tizen-developer-ca-privatekey.pem create mode 100644 org.tizen.common.sign/certificates/developer/tizen-developer-ca.cer create mode 100644 org.tizen.common.sign/lib/KeyCertGeneratorApi.jar create mode 100644 org.tizen.common.sign/src/org/tizen/common/sign/preferences/SigningProfileContainer.java create mode 100644 org.tizen.common.sign/src/org/tizen/common/sign/ui/CertGenerationDialog.java create mode 100644 org.tizen.common.sign/src/org/tizen/common/sign/ui/ProfileItemDialog.java delete mode 100644 org.tizen.common.sign/src/org/tizen/common/sign/ui/TizenSigningDialog.java diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileLabelProvider.java b/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileLabelProvider.java index 4bc18f588..7e3f0aeaa 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileLabelProvider.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileLabelProvider.java @@ -95,7 +95,7 @@ public class TizenRemoteFileLabelProvider implements ITableLabelProvider { { switch(index) { case 0: - return Integer.toString( entry.getSize() ); + return entry.getSize(); case 1: return entry.getDate(); case 2: diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java index 73c53f7da..97c01e51e 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java @@ -236,7 +236,7 @@ implements IDevice FileEntry getRoot() { - return new FileEntry(this, null, getDeviceName(), isEmulator()?FileEntryType.RootEmulator:FileEntryType.RootDevice, null, null, null, 0, null, null, null, null ); + return new FileEntry(this, null, getDeviceName(), isEmulator()?FileEntryType.RootEmulator:FileEntryType.RootDevice, null, null, null, null, null, null, null, null ); } /* (non-Javadoc) @@ -266,7 +266,7 @@ implements IDevice } if ( ! bFound ) { - iter = new FileEntry( null, iter, fragment, FileEntryType.Unknown, null, null, null, 0, null, null, null, null ); + iter = new FileEntry( null, iter, fragment, FileEntryType.Unknown, null, null, null, null, null, null, null, null ); } } return iter; diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/FileEntryFactory.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/FileEntryFactory.java index bd9555098..b30292751 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/FileEntryFactory.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/FileEntryFactory.java @@ -198,6 +198,6 @@ FileEntryFactory name = trimTrailingCharacter( name, '*' ); } - return new FileEntry( null, parent, name, objectType, permissions, owner, group, parseInt( size, 0 ), date, time, info, linkTo ); + return new FileEntry( null, parent, name, objectType, permissions, owner, group, size, date, time, info, linkTo ); } } diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/CrashReportService.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/CrashReportService.java index fe341fb34..d454beb64 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/CrashReportService.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/CrashReportService.java @@ -168,6 +168,11 @@ implements IDeviceChangeListener reply.flip(); notifyAllListeners( (IDevice) key.attachment(), UTF_CHARSET.decode( reply ).toString() ); } + else if ( len < 0 ) + { + key.cancel(); + tryClose( sc ); + } } catch ( final IOException e ) { @@ -322,6 +327,7 @@ implements IDeviceChangeListener while ( iter.hasNext() ) { final SelectionKey key = iter.next(); + Log.d( "crash", "Iteration: " + key.interestOps() ); if ( key.isConnectable() ) { final SocketChannel sc = (SocketChannel) key.channel(); diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntry.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntry.java index 226f44d28..dc427e173 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntry.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntry.java @@ -125,7 +125,7 @@ implements Comparable /** * File size */ - protected final int size; + protected final String size; /** * File modified date @@ -184,7 +184,7 @@ implements Comparable final String permission, final String owner, final String group, - final int size, + final String size, final String date, final String time, final String info, @@ -264,7 +264,7 @@ implements Comparable * @return size of the entry */ public - int + String getSize() { return size; diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java index 86af582f7..493401949 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java @@ -434,7 +434,7 @@ implements Closeable * @param time out value while push the files * @return a {@link SyncResult} object with a code and an optional message. * - * @see #doPush(InputStream, FileEntry, ISyncProgressMonitor, int) + * @see #push(File[], FileEntry, ISyncProgressMonitor, int) */ public SyncResult @@ -455,17 +455,56 @@ implements Closeable monitor.startSubTask(MESSAGE_SIZECHECKING); + SyncResult result; + try { // get the total count of the bytes to transfer long total = getTotalLocalFileSizeLong( locals, monitor ); monitor.startSubTask( MESSAGE_PUSH_FILES ); monitor.stop(); + //start the monitor monitor.start( total ); + result = doPush(locals, remote, monitor, timeOut); + } + catch ( final InterruptedException e ) + { + return new SyncResult( RESULT_CANCELED ); + } + finally + { + monitor.stop(); + } + + return result; + } + + /** + * Push several files. + * @param locals An array of loca files to push + * @param remote the remote {@link FileEntry} representing a directory. + * @param monitor The progress monitor. Cannot be null. + * @param time out value while push the files + * @return a {@link SyncResult} object with a code and an optional message. + * + * @see #doPush(File[], FileEntry, ISyncProgressMonitor, int) + */ + public + SyncResult + doPush( + final File[] locals, + final FileEntry remote, + ISyncProgressMonitor monitor, + final int timeOut + ) + { + monitor = nvl( monitor, NullSyncProgressMonitor.getInstance() ); + + try { + final String remotePath = remote.getFullPath(); - - + for ( final File f : locals ) { // check if we're canceled @@ -475,7 +514,7 @@ implements Closeable if ( !f.exists() ) { - continue; + continue; } final String path = addTailingPath( remotePath, f.getName() ); @@ -484,27 +523,27 @@ implements Closeable monitor.startSubTask( String.format("%s\t%s", f.getAbsolutePath(), path ) ); if ( f.isDirectory() ) { - SyncResult result = push( f.listFiles(), remoteFile, monitor, timeOut); - - if (result.getCode() != RESULT_OK) - { - return result; - } + SyncResult result = doPush( f.listFiles(), remoteFile, monitor, timeOut); + + if (result.getCode() != RESULT_OK) + { + return result; + } } - else if (f.isFile() ) + else if ( f.isFile() ) { - FileInputStream fileIn = new FileInputStream( f ); - try - { - SyncResult result = doPush( fileIn, remoteFile, monitor, timeOut); - if (result.getCode() != RESULT_OK) { - return result; - } - } - finally - { - tryClose( fileIn ); - } + FileInputStream fileIn = new FileInputStream( f ); + try + { + SyncResult result = doPush( fileIn, remoteFile, monitor, timeOut); + if (result.getCode() != RESULT_OK) { + return result; + } + } + finally + { + tryClose( fileIn ); + } } } @@ -512,17 +551,8 @@ implements Closeable } catch ( final IOException e ) { - return new SyncResult( RESULT_FILE_READ_ERROR ); - } - catch ( final InterruptedException e ) - { - return new SyncResult(RESULT_CANCELED); + return new SyncResult( RESULT_FILE_READ_ERROR, e ); } - finally - { - monitor.stop(); - } - } /** diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/util/FileEntryUtil.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/FileEntryUtil.java index 9302f1609..4a415b246 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/util/FileEntryUtil.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/FileEntryUtil.java @@ -70,7 +70,7 @@ FileEntryUtil } else if (type == FileEntryType.File) { - count += e.getSize(); + count += ParsingUtil.parseLong( e.getSize(), 0 ); } } diff --git a/org.tizen.common.sign/.classpath b/org.tizen.common.sign/.classpath index 575478c5f..7589ba486 100644 --- a/org.tizen.common.sign/.classpath +++ b/org.tizen.common.sign/.classpath @@ -1,5 +1,6 @@ + diff --git a/org.tizen.common.sign/META-INF/MANIFEST.MF b/org.tizen.common.sign/META-INF/MANIFEST.MF index c30b2adef..fc402fef2 100644 --- a/org.tizen.common.sign/META-INF/MANIFEST.MF +++ b/org.tizen.common.sign/META-INF/MANIFEST.MF @@ -21,8 +21,9 @@ Export-Package: hashsign, org.tizen.common.sign.signer, org.tizen.common.sign.ui, org.tizen.common.sign.util -Bundle-ClassPath: lib/CertificateGenerator.jar, - ., +Bundle-ClassPath: lib/KeyCertGeneratorApi.jar, + lib/CertificateGenerator.jar, lib/HashSign.jar, lib/xmlsec-1.5.3.jar, - lib/commons-codec-1.4.jar + lib/commons-codec-1.4.jar, + . diff --git a/org.tizen.common.sign/OSGI-INF/l10n/bundle.properties b/org.tizen.common.sign/OSGI-INF/l10n/bundle.properties index 4b038856d..c6366b73a 100644 --- a/org.tizen.common.sign/OSGI-INF/l10n/bundle.properties +++ b/org.tizen.common.sign/OSGI-INF/l10n/bundle.properties @@ -1,4 +1,4 @@ #Properties file for org.tizen.common.sign Bundle-Vendor = The Linux Foundation Bundle-Name = Tizen Common Sign -page.name = Secure Profiles \ No newline at end of file +page.name = Security Profiles \ No newline at end of file diff --git a/org.tizen.common.sign/build.properties b/org.tizen.common.sign/build.properties index 95c3a8588..18f9a37b8 100644 --- a/org.tizen.common.sign/build.properties +++ b/org.tizen.common.sign/build.properties @@ -10,4 +10,5 @@ bin.includes = plugin.xml,\ lib/xmlsec-1.5.3.jar,\ about_files/,\ about.html,\ - lib/commons-codec-1.4.jar + lib/commons-codec-1.4.jar,\ + lib/KeyCertGeneratorApi.jar diff --git a/org.tizen.common.sign/certificates/developer/conf.ini b/org.tizen.common.sign/certificates/developer/conf.ini new file mode 100644 index 000000000..fe782eaff --- /dev/null +++ b/org.tizen.common.sign/certificates/developer/conf.ini @@ -0,0 +1 @@ +PASSWD_OF_ISSUER_FOR_DEV=tizencertificatefordevelopercaroqkfwk diff --git a/org.tizen.common.sign/certificates/developer/tizen-developer-ca-privatekey.pem b/org.tizen.common.sign/certificates/developer/tizen-developer-ca-privatekey.pem new file mode 100644 index 000000000..47e13555e --- /dev/null +++ b/org.tizen.common.sign/certificates/developer/tizen-developer-ca-privatekey.pem @@ -0,0 +1,18 @@ +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-128-CBC,231BF253A4AA10E1F1A450D5AB3385F2 + +McTL9+jm/Fuu3pHC6zm/epNhCqgSXswlZVc59zi9Rx+9SSOCNjHm2VChPsWmTU7G +Q4Fwerq/95/s5B2/nnO9LXgn/hMZbsFtva3awzcSDWLImwvBmn9Kzc9wym3G4GC0 +cpDzT3/i+EdR1qLLfLiEZ81sHWbEui1ywtraJMfhmz07rwLTQ7UrXT63YdsgbRUN +sk/ESxgc223Dc9SbPF94lwmOeDQTbM3hIuNmizUJTPVzQGGARFqiXiPjjechJ7NS +0ds8M7Bb3tF+blyTZmS53ymBE30PXwnWuZ2nv1eC05E0jK/XwgSqTY0hekMeGcB7 +b07eELzcyEtovG1N+F+vDkEdZkhhjui7OgPoXMPZfuv+Bi8LK1lpsbiSz/BRNTP0 +6QKsJy0xxKSlGjsX3lA+XpXi/jfDW0yaxubpzNPM5XW0vhuNcyK/rUw0KKQCD3DO +rjoe67RUJYfQKEVgsmJEo69Hf1Jbk7kShP72FehEQ/fMONZMULTEleWY1tchOeEd +QNXElFqXCiCvTw2rMT/mLDuhXolv6M/mmV4A/L1RboBpsG8wSKJ+4cavtXDMll3o +5dMKrXqkCzKajZFASgVcr7CW2XJQjTpx2/bolc+4K4WyUJ+IcrqF+8igfmiDCzic +LhDOsYhiyNcw8fmW95tudH+9tg4IGbA3R6VZFejM8vxvNmO1lNXruiNVVcrvLUSk +k65JAkWn12rV/P4eCBsg9b/dNV7GKydxO4B1a7gindC950sjwc6X+0+waysbp7zk +QUOaDGBJGgSQe0UL55oRHqUe2t7ZM7rmqdxsApwH5xDGnPRQQ0zecA6t6AmrDmAH +-----END RSA PRIVATE KEY----- diff --git a/org.tizen.common.sign/certificates/developer/tizen-developer-ca.cer b/org.tizen.common.sign/certificates/developer/tizen-developer-ca.cer new file mode 100644 index 000000000..780396974 --- /dev/null +++ b/org.tizen.common.sign/certificates/developer/tizen-developer-ca.cer @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICpzCCAhCgAwIBAgIJAKzDjmEF+1OXMA0GCSqGSIb3DQEBBQUAMIGTMQswCQYD +VQQGEwJLUjEOMAwGA1UECAwFU3V3b24xDjAMBgNVBAcMBVN1d29uMRYwFAYDVQQK +DA1UaXplbiBUZXN0IENBMSUwIwYDVQQLDBxUaXplbiBUZXN0IERldmVsb3BlciBS +b290IENBMSUwIwYDVQQDDBxUaXplbiBUZXN0IERldmVsb3BlciBSb290IENBMB4X +DTEyMTAyOTEzMDEyMloXDTIyMTAyNzEzMDEyMlowgYQxCzAJBgNVBAYTAktSMQ4w +DAYDVQQIDAVTdXdvbjEOMAwGA1UEBwwFU3V3b24xFjAUBgNVBAoMDVRpemVuIFRl +c3QgQ0ExIDAeBgNVBAsMF1RpemVuIERldmVsb3BlciBUZXN0IENBMRswGQYDVQQD +DBJUaXplbiBEZXZlbG9wZXIgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB +AMyG0DSTHBgalQo1seDKxpCU61gji+QQlxQkPQOvBrmuF6Z90zFCprTtg2sRjTLC +NoRd75+VCCHuKGcrD27t7hwAekusPrpzdsq5QoBMvNjGDM22lC45PJ4d86DEDY4e +rxeJ5aSQxqbfXK4pKe9NwxdkKuA8dTYZM1UcmhXs7YALAgMBAAGjEDAOMAwGA1Ud +EwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEACbr/OPNMJ+Ejrxfm/YjCiRPpjJLn +wXS2IDtitbxot6bEdZkZvOFXOC0Ca4GT+jtvOcSlU7tM3Mdd1MrKe1kkoVd1vhCV +8V4CK3/DPj8aN3rxfMfQitA6XMDcxzhsyMWz56OdifX50dvS/G/ad+kGhNhOOEKS +E8zUyEDCGwqkfXk= +-----END CERTIFICATE----- diff --git a/org.tizen.common.sign/lib/KeyCertGeneratorApi.jar b/org.tizen.common.sign/lib/KeyCertGeneratorApi.jar new file mode 100644 index 000000000..5b3b82e8a Binary files /dev/null and b/org.tizen.common.sign/lib/KeyCertGeneratorApi.jar differ diff --git a/org.tizen.common.sign/src/org/tizen/common/sign/command/ReadSigningProfileFileCommand.java b/org.tizen.common.sign/src/org/tizen/common/sign/command/ReadSigningProfileFileCommand.java index 658520ebe..4ecefcd09 100755 --- a/org.tizen.common.sign/src/org/tizen/common/sign/command/ReadSigningProfileFileCommand.java +++ b/org.tizen.common.sign/src/org/tizen/common/sign/command/ReadSigningProfileFileCommand.java @@ -29,6 +29,7 @@ import static org.tizen.common.util.IOUtil.tryClose; import hashsign.HashingSigning; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -53,9 +54,10 @@ 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.model.SignatureConstants; +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.sign.util.SigningProfileUtil; -import org.tizen.common.util.IOUtil; +import org.tizen.common.util.Assert; import org.tizen.common.util.StringUtil; public class @@ -68,12 +70,14 @@ extends AbstractCommand protected final String profileName; - protected InputStream profileInputStream; - - protected List profileItems = new ArrayList(); - + protected SigningProfileContainer container; + + public ReadSigningProfileFileCommand( final String path, final String profileName ) { + Assert.notNull( path ); + Assert.notNull( profileName ); + this.path = path; this.profileName = profileName; @@ -86,24 +90,22 @@ extends AbstractCommand ) throws Exception { - if ( !canRun( context ) ) - { + if ( ! canRun( context ) ) { return ; } final FileHandler fileHandler = context.getFileHandler(); - byte[] bytes = IOUtil.getBytes( fileHandler.read( this.path ) , true); - this.profileInputStream = new ByteArrayInputStream( bytes ); + InputStream profileInputStream = fileHandler.read( this.path ); try { - this.profileItems = SigningProfileUtil.parseProfileFile( this.profileInputStream, this.profileName ); + this.container = new SigningProfileContainer(); + this.container.readProfileXML( profileInputStream ); interactForPassword( executor, context ); validateSigningInfo(); } finally { - tryClose( this.profileInputStream ); - this.profileInputStream = null; + tryClose( profileInputStream ); } } @@ -138,128 +140,151 @@ extends AbstractCommand } } - /* + /** * validate password, if inputed wrong password then throw CertificationException */ protected void validateSigningInfo() throws CertificationException { - SigningProfileItem authorItem = getItem( true ); - SigningProfileItem distributorItem = getItem( false ); - - boolean hasAuthor = isValidItem( authorItem ); - boolean hasDistributor = isValidItem( distributorItem ); - - if ( hasAuthor ) { - // author password validating - checkPkcs12Password( authorItem ); + SigningProfile profile = getProfile(); + if ( profile == null ) { + return; } - - if ( hasDistributor ) { - // distributor password validating - checkPkcs12Password( distributorItem ); + + for (SigningProfileItem item : profile.getProfileItems() ) { + if ( isValidItem( item ) ) { + checkPkcs12Password( item ); + } } } protected void interactForPassword(final Executor executor, final ExecutionContext context) throws Exception { - SigningProfileItem authorItem = getItem( true ); - SigningProfileItem distributorItem = getItem( false ); - + // get specified profile + SigningProfile profile = getProfile(); + if ( profile == null ) { + return; + } + + // get required profile items. + SigningProfileItem authorItem = profile.getProfileItem( SigningProfile.AUTHOR_ORDINAL ); boolean hasAuthor = isValidItem( authorItem ); - boolean hasDistributor = isValidItem( distributorItem ); - if ( !hasAuthor ) { + SigningProfileItem dist1Item = profile.getProfileItem( 1 ); + boolean hasDist1 = isValidItem( dist1Item ); + + if ( ! hasAuthor || ! hasDist1 ) { // If don't have author certificate, no interact. return; } - if ( ! authorItem.hasPassword() || - ( hasDistributor && ! distributorItem.hasPassword() ) ) { - - ArrayList fieldList = new ArrayList(); - - // Author password text - UserField authorText = new UserField( SignatureConstants.AUTHOR, "Author password : ", char[].class ); - authorText.setValue( authorItem.getPassword() ); - authorText.setValidator( new InputValidator() { + // get an optional profile item + SigningProfileItem dist2Item = profile.getProfileItem( 2 ); + boolean hasDist2 = isValidItem( dist2Item ); + + // If not need to input password, skip + if ( authorItem.hasPassword() && dist1Item.hasPassword() && + ( !hasDist2 || dist2Item.hasPassword() ) ) { + return; + } + + // generate fields + List fieldList = new ArrayList(); + Object[][] fields = new Object[][] { + new Object[] { SignatureConstants.AUTHOR, "Author password: ", true, authorItem.getPassword(), "Input author password.", "authorPwdSavable", "Save author password" }, + new Object[] { SignatureConstants.DISTRIBUTOR_1ST, "Distributor1 password: ", true, dist1Item.getPassword(), "Input distributor1 password.", "dist1PwdSavable", "Save distributor1 password" }, + new Object[] { SignatureConstants.DISTRIBUTOR_2ND, "Distributor2 password: ", hasDist2, dist2Item.getPassword(), "Input distributor2 password.", "dist2PwdSavable", "Save distributor2 password" }, + }; + for (Object[] field : fields ) { + final String textId = (String) field[0]; + final String textMsg = (String) field[1]; + final boolean modifiable = (Boolean) field[2]; + final char[] password = (char[]) field[3]; + final String validatorMsg = (String) field[4]; + final String buttonId = (String) field[5]; + final 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 ); + } + + // options + Map options = new HashMap(); + options.put( PrompterConstants.OPTION_TITLE, "Signing Dialog" ); // title + + // Interact passwords + context.getPrompter().batch( fieldList, options ); + + // write savable profile items + boolean[] updateFlags = { true, true, hasDist2 }; + for ( int i = SigningProfile.AUTHOR_ORDINAL; i <= SigningProfile.MAX_DISTRIBUTOR; i++ ) { + updateProfileItem( profile, i, fieldList.get( i * 2 ), fieldList.get( i * 2 + 1), updateFlags[ i ], true ); + } + writeProfiles( executor, context ); + + // synchronize unsavable profile items + for ( int i = SigningProfile.AUTHOR_ORDINAL; i <= SigningProfile.MAX_DISTRIBUTOR; i++ ) { + updateProfileItem( profile, i, fieldList.get( i * 2 ), 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 ); + 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() { @Override public String check(Object value) { if ( value instanceof String ) { - return StringUtil.isEmpty( (String) value ) ? "Input author password." : null; + return StringUtil.isEmpty( (String) value ) ? validatorMsg : null; } return null; } } ); - fieldList.add( authorText ); - - // Savable author password button - UserField authorButton = new UserField( "authorPwdSavable", "Save author password", boolean.class ); - fieldList.add( authorButton ); - - // Distributor password text - UserField distributor2Text = new UserField( SignatureConstants.DISTRIBUTOR_2ND, "Distributor password : ", char[].class ); - if ( !hasDistributor ) { - distributor2Text.setModify( false ); - } else { - distributor2Text.setValue( distributorItem.getPassword() ); - distributor2Text.setValidator( new InputValidator() { - @Override - public String check(Object value) { - if ( value instanceof String ) { - return StringUtil.isEmpty( (String) value ) ? "Input distributor password." : null; - } - return null; - } - } ); - } - fieldList.add( distributor2Text ); - - // Savable distributor2 password button - UserField distributor2Button = new UserField( "distributorPwdSavable", "Save distributor password", boolean.class ); - if ( !hasDistributor ) { - distributor2Button.setModify( false ); - } - fieldList.add( distributor2Button ); - - // options - Map options = new HashMap(); - options.put( PrompterConstants.OPTION_TITLE, "Signing Dialog" ); // title - - // Interact passwords - context.getPrompter().batch( fieldList, options ); - - // save profiles - boolean saveAuthor = getBoolean( authorButton.getValue() ); - boolean saveDistributor = hasDistributor ? getBoolean( distributor2Button.getValue() ) : false; - - if ( saveAuthor ) { - authorItem.setPassword( (char[]) authorText.getValue() ); - } - if ( hasDistributor && saveDistributor ) { - distributorItem.setPassword( (char[]) distributor2Text.getValue() ); - } - - writeProfiles( executor, context ); - - // synchronize profile password - if ( !saveAuthor ) { - authorItem.setPassword( (char[]) authorText.getValue() ); - } - if ( hasDistributor && !saveDistributor ) { - distributorItem.setPassword( (char[]) distributor2Text.getValue() ); - } } + + return userField; + } + + protected UserField createButtonField(String id, String message, boolean modifiable ) { + UserField userField = new UserField( id, message, boolean.class ); + if ( ! modifiable ) { + userField.setModify( false ); + } + + return userField; + } + + public SigningProfile getProfile() { + if ( this.container == null || this.profileName == null ) { + return null; + } + return this.container.getProfileByName( this.profileName ); } protected void writeProfiles(final Executor executor, final ExecutionContext context) throws Exception { final FileHandler fileHandler = context.getFileHandler(); - this.profileInputStream.reset(); - final InputStream in = SigningProfileUtil.updateProfiles( this.profileInputStream, this.profileName, this.profileItems ); - if ( in == null ) { - logger.warn( "Cannot update profiles" ); - return; - } + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + this.container.writeProfileXML( outStream ); + InputStream in = new ByteArrayInputStream( outStream.toByteArray() ); try { fileHandler.write( this.path, in ); @@ -286,26 +311,11 @@ extends AbstractCommand } return ( Type.FILE.equals( fileHandler.get( path, Attribute.TYPE ) ) ); } - - public List getProfileItems() - { - return this.profileItems; - } - + protected boolean isValidItem(SigningProfileItem item) { return item == null ? false : item.hasKeyLocation(); } - protected SigningProfileItem getItem(boolean author) { - for ( SigningProfileItem item : this.profileItems ) { - if ( item.isAuthor() == author ) { - return item; - } - } - - return null; - } - protected boolean getBoolean(Object obj) { return ( obj == null ) ? true : Boolean.parseBoolean( String.valueOf( obj ) ); } diff --git a/org.tizen.common.sign/src/org/tizen/common/sign/command/SignCommand.java b/org.tizen.common.sign/src/org/tizen/common/sign/command/SignCommand.java index 168ef9dbe..39ce1a2f0 100755 --- a/org.tizen.common.sign/src/org/tizen/common/sign/command/SignCommand.java +++ b/org.tizen.common.sign/src/org/tizen/common/sign/command/SignCommand.java @@ -25,7 +25,6 @@ package org.tizen.common.sign.command; import java.io.IOException; -import java.util.List; import org.apache.commons.lang3.time.StopWatch; import org.tizen.common.core.command.ExecutionContext; @@ -37,6 +36,7 @@ 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; @@ -46,35 +46,22 @@ import org.tizen.common.util.StringUtil; public class SignCommand extends FileHandlingCommand { - // active profile name - protected String profileName; - - protected List profileItems; - - // categorized profiles - protected SigningProfileItem authorProfile = null; - protected SigningProfileItem distributor1Profile = null; - protected SigningProfileItem distributor2Profile = null; + protected SigningProfile profile; protected boolean bRDS; // Constructor - public SignCommand(final String root, final String profileName, final List profileItems) { - this( root, profileName, profileItems, false ); + public SignCommand(final String root, final SigningProfile profile) { + this( root, profile, false ); } - public SignCommand(final String root, final String profileName, final List profileItems, boolean bRDS) { + public SignCommand(final String root, final SigningProfile profile, boolean bRDS) { this.path = root; - this.profileName = profileName; - this.profileItems = profileItems; + this.profile = profile; this.bRDS = bRDS; } - protected String getActiveProfileName() { - return this.profileName; - } - public void run(final Executor executor, final ExecutionContext context) throws IOException, CertificationException { final FileHandler handler = context.getFileHandler(); Assert.notNull( handler ); @@ -89,9 +76,6 @@ public class SignCommand extends FileHandlingCommand { final String appDirPath = (String) handler.get( this.path, Attribute.PATH ); - // categorize profile - categorizeProfiles(); - // remove old signatures for ( String child : handler.list( appDirPath ) ) { Object type = handler.get( child, Attribute.TYPE ); @@ -113,17 +97,18 @@ public class SignCommand extends FileHandlingCommand { stopWatch.start(); // If option for launch is false, must have author profile. - if ( this.authorProfile != null ) { - signAuthor( appDirPath, this.authorProfile ); - signDistributor1( appDirPath, this.distributor1Profile ); - if ( this.distributor2Profile != null ) { - signDistributor2( appDirPath, this.distributor2Profile ); + SigningProfileItem authorItem = this.profile.getProfileItem( SigningProfile.AUTHOR_ORDINAL ); + SigningProfileItem dist1Item = this.profile.getProfileItem( 1 ); + SigningProfileItem dist2Item = this.profile.getProfileItem( 2 ); + + if ( authorItem != null && dist1Item != null ) { + signAuthor( appDirPath, authorItem ); + signDistributor1( appDirPath, dist1Item ); + if ( dist2Item != null ) { + signDistributor2( appDirPath, dist2Item ); } - } else if ( this.distributor1Profile != null ) { - // sign developer profile only, no check - signDistributor1( appDirPath, this.distributor1Profile ); } else { - logger.error( "Profiles is not set. Author : {}, Dist1 : {}", this.authorProfile, this.distributor1Profile ); + logger.error( "Profiles is not set. Author : {}, Dist1 : {}", authorItem, dist1Item ); } } catch (Exception e) { context.getPrompter().error( e.getMessage() ); @@ -136,22 +121,6 @@ public class SignCommand extends FileHandlingCommand { } } - private void categorizeProfiles() { - for ( SigningProfileItem profileItem : this.profileItems ) { - if ( !StringUtil.isEmpty( profileItem.getKeyLocation() ) ) { - if ( profileItem.isAuthor() && this.authorProfile == null ) { - this.authorProfile = profileItem; - } else if ( this.distributor1Profile == null ) { - this.distributor1Profile = profileItem; - } else if ( this.distributor2Profile == null ) { - this.distributor2Profile = profileItem; - } else { - break; - } - } - } - } - private void signAuthor(String appDirPath, SigningProfileItem profileItem) throws Exception { if ( this.bRDS ) { TizenSigner.authorIncrementalSign( appDirPath, diff --git a/org.tizen.common.sign/src/org/tizen/common/sign/model/SignatureConstants.java b/org.tizen.common.sign/src/org/tizen/common/sign/model/SignatureConstants.java index ab33600e7..cd431acb3 100755 --- a/org.tizen.common.sign/src/org/tizen/common/sign/model/SignatureConstants.java +++ b/org.tizen.common.sign/src/org/tizen/common/sign/model/SignatureConstants.java @@ -28,11 +28,29 @@ package org.tizen.common.sign.model; public interface SignatureConstants { - String AUTHOR = "author"; - String DISTRIBUTOR = "distributor"; - String DISTRIBUTOR_1ST = DISTRIBUTOR + "1"; - String DISTRIBUTOR_2ND = DISTRIBUTOR + "2"; + public static final String AUTHOR = "author"; + public static final String DISTRIBUTOR = "distributor"; + public static final String DISTRIBUTOR_1ST = DISTRIBUTOR + "1"; + public static final String DISTRIBUTOR_2ND = DISTRIBUTOR + "2"; public static final String SIGNATURE_META_FILE = ".manifest.tmp"; + // for preference store + public static final String DEFAULT_PROFILE_KEY = "defaultprofile"; + + public static final String PROFILES_FILE = "profiles.xml"; + + // for XML parser + public static final String ROOT_ELEMENT = "profiles"; + public static final String ROOT_ATTR_VER = "version"; + public static final String PROFILE_ELEMENT = "profile"; + public static final String PROFILE_ATTR_NAME = "name"; + public static final String PROFILEITEM_ELEMENT = "profileitem"; + public static final String PROFILEITEM_ATTR_KEY = "key"; + public static final String PROFILEITEM_ATTR_AUTHOR = "author"; + public static final String PROFILEITEM_ATTR_DISTRIBUTOR = "distributor"; + public static final String PROFILEITEM_ATTR_CA = "ca"; + public static final String PROFILEITEM_ATTR_ROOTCA = "rootca"; + public static final String PROFILEITEM_ATTR_PASS = "password"; + } diff --git a/org.tizen.common.sign/src/org/tizen/common/sign/preferences/Messages.properties b/org.tizen.common.sign/src/org/tizen/common/sign/preferences/Messages.properties index 4ddde00a6..eee995393 100644 --- a/org.tizen.common.sign/src/org/tizen/common/sign/preferences/Messages.properties +++ b/org.tizen.common.sign/src/org/tizen/common/sign/preferences/Messages.properties @@ -3,8 +3,8 @@ AUTOINSERT_BTN=Insert signature at launching PROFILES_COLUMN1=Certificate path PROFILES_COLUMN2=Password -PROFILES_COLUMN3=CA path(Optional) -PROFILES_COLUMN4=Root CA path(Optional) +PROFILES_COLUMN3=CA path (Optional) +PROFILES_COLUMN4=Root CA path (Optional) PROFILES_ADD_BTN=Add PROFILES_ADD_TOOLTIP=Add Profile diff --git a/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileCellModifier.java b/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileCellModifier.java index 0c0a9ee9a..442d00e53 100644 --- a/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileCellModifier.java +++ b/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileCellModifier.java @@ -29,65 +29,68 @@ package org.tizen.common.sign.preferences; import org.eclipse.jface.viewers.ICellModifier; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.widgets.TableItem; -import org.tizen.common.sign.util.SigningProfileUtil; +import org.tizen.common.sign.model.SignatureConstants; + public class ProfileCellModifier implements ICellModifier { - private TableViewer viewer; - private SigningPreferencePage page; - + private TableViewer viewer; + private SigningPreferencePage page; + - public ProfileCellModifier(TableViewer viewer, SigningPreferencePage signingPreferencePage) { - this.viewer = viewer; - this.page = signingPreferencePage; - } - - @Override - public boolean canModify(Object element, String property) { - return true; - } + public ProfileCellModifier(TableViewer viewer, SigningPreferencePage signingPreferencePage) { + this.viewer = viewer; + this.page = signingPreferencePage; + } + + @Override + public boolean canModify(Object element, String property) { + return false; + } - @Override - public Object getValue(Object element, String property) { - - if (element instanceof SigningProfileItem) { - if (property.equals(SigningProfileUtil.ITEM_ATTR_PASS)) { - return ((SigningProfileItem)element).getPassword(); - } else if (property.equals(SigningProfileUtil.ITEM_ATTR_KEY)) { - return ((SigningProfileItem)element).getKeyLocation(); - } - else if (property.equals(SigningProfileUtil.ITEM_ATTR_CA)) { - return ((SigningProfileItem)element).getCAPath(); - } - else if (property.equals(SigningProfileUtil.ITEM_ATTR_ROOTCA)) { - return ((SigningProfileItem)element).getRootCAPath(); + @Override + public Object getValue(Object element, String property) { + if ( element instanceof SigningProfileItem ) { + SigningProfileItem item = (SigningProfileItem) element; + + if ( property.equals( SignatureConstants.PROFILEITEM_ATTR_PASS ) ) { + return item.getPassword(); + } else if ( property.equals( SignatureConstants.PROFILEITEM_ATTR_KEY ) ) { + return item.getKeyLocation(); + } else if ( property.equals( SignatureConstants.PROFILEITEM_ATTR_CA ) ) { + return item.getCAPath(); + } else if ( property.equals( SignatureConstants.PROFILEITEM_ATTR_ROOTCA ) ) { + return item.getRootCAPath(); } - } - return null; - } + } + + return null; + } - @Override - public void modify(Object element, String property, Object value) { - if (element instanceof TableItem) { - Object data = ((TableItem)element).getData(); - SigningProfileItem profileItem = (SigningProfileItem)data; - String _value = (String) value; - if (data instanceof SigningProfileItem) { - if (property.equals(SigningProfileUtil.ITEM_ATTR_PASS)) { - profileItem.setPassword(_value.toCharArray()); - } - else if (property.equals(SigningProfileUtil.ITEM_ATTR_KEY)) { - profileItem.setKeyLocation(_value); - } - else if(property.equals(SigningProfileUtil.ITEM_ATTR_CA)) { - profileItem.setCAPath(_value); - } - else if(property.equals(SigningProfileUtil.ITEM_ATTR_ROOTCA)) { - profileItem.setRootCAPath(_value); - } - } - viewer.update(data, null); - page.validatePreferencePage(); - } - } + @Override + public void modify(Object element, String property, Object value) { + Object data = null; + + if ( element instanceof TableItem ) { + data = ((TableItem) element).getData(); + } + + if ( data instanceof SigningProfileItem ) { + SigningProfileItem item = (SigningProfileItem) data; + String _value = (String) value; + + if ( property.equals( SignatureConstants.PROFILEITEM_ATTR_PASS ) ) { + item.setPassword( _value.toCharArray() ); + } else if ( property.equals( SignatureConstants.PROFILEITEM_ATTR_KEY ) ) { + item.setKeyLocation( _value ); + } else if ( property.equals( SignatureConstants.PROFILEITEM_ATTR_CA ) ) { + item.setCAPath( _value ); + } else if ( property.equals( SignatureConstants.PROFILEITEM_ATTR_ROOTCA ) ) { + item.setRootCAPath( _value ); + } + + viewer.update( data, null ); + page.validatePreferencePage(); + } + } } diff --git a/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileItemContentProvider.java b/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileItemContentProvider.java index 40251b8c7..898f6244a 100644 --- a/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileItemContentProvider.java +++ b/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileItemContentProvider.java @@ -26,28 +26,26 @@ package org.tizen.common.sign.preferences; -import java.util.List; - import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; public class ProfileItemContentProvider implements IStructuredContentProvider { - - @Override - public Object[] getElements(Object inputElement) { - if (inputElement instanceof SigningProfile) { - List profileItemList = ((SigningProfile)inputElement).getProfileItemList(); - return profileItemList.toArray(); - } - return null; - } + + @Override + public Object[] getElements(Object inputElement) { + if ( inputElement instanceof SigningProfileItem[] ) { + return (SigningProfileItem[]) inputElement; + } + + return null; + } - @Override - public void dispose() { - } + @Override + public void dispose() { + } - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } } diff --git a/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileItemLabelProvider.java b/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileItemLabelProvider.java index b8e545b58..c9a0acb32 100644 --- a/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileItemLabelProvider.java +++ b/org.tizen.common.sign/src/org/tizen/common/sign/preferences/ProfileItemLabelProvider.java @@ -36,40 +36,42 @@ extends LabelProvider implements ITableLabelProvider { - @Override - public Image getColumnImage(Object element, int columnIndex) { - return null; - } + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } - @Override - public String getColumnText(Object element, int columnIndex) { - if (columnIndex == 0) { - if (element instanceof SigningProfileItem) { - return ((SigningProfileItem)element).getKeyLocation(); - } - } else if (columnIndex == 1) { - if (element instanceof SigningProfileItem) { - char[] identifier = ((SigningProfileItem)element).getPassword(); - if(identifier == null) { - return null; - } - int passLength = identifier.length; - StringBuffer result = new StringBuffer(); - for(int i=0; i profileList; - private TableViewer authorTableViewer; - private TableViewer distributorTableViewer; - private TableViewer listViewer; - public static String defaultProfileKey = "defaultprofile"; //$NON-NLS-1$ - public String defaultProfileString; - private Button addButton, removeButton; - private Button clearButton; - private Button distClearButton; - - private IPreferenceStore preferenceStore; + protected TableViewer listViewer; + protected TableViewer authorTableViewer; + protected TableViewer distributorTableViewer; + + protected List