Changeset 833:3ef15811b6c1
- Timestamp:
- 08/10/08 16:23:57
(4 months ago)
- Author:
- Bastian Doetsch <bastian.doetsch@gmx.de>
- branch:
- default
- Message:
Added signature verification for signed changesets in history view.
Green background = valid
Red background = invalid / unknown key
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r428 |
r833 |
|
| 17 | 17 | import java.util.List; |
|---|
| 18 | 18 | |
|---|
| 19 | | import org.eclipse.core.resources.IProject; |
|---|
| 20 | 19 | import org.eclipse.core.resources.ResourcesPlugin; |
|---|
| 21 | 20 | |
|---|
| … | … | |
| 33 | 32 | public class HgSignClient { |
|---|
| 34 | 33 | |
|---|
| | 34 | |
|---|
| | 35 | |
|---|
| 35 | 36 | /** |
|---|
| 36 | 37 | * Calls hg sign. add a signature for the current or given revision If no |
|---|
| … | … | |
| 38 | 39 | * no revision is checked out. |
|---|
| 39 | 40 | * |
|---|
| 40 | | * @param project |
|---|
| | 41 | * @param directory |
|---|
| 41 | 42 | * the current project (working directory) |
|---|
| 42 | 43 | * @param cs |
|---|
| … | … | |
| 61 | 62 | * |
|---|
| 62 | 63 | */ |
|---|
| 63 | | public static String sign(IProject project, ChangeSet cs, String key, |
|---|
| | 64 | public static String sign(File directory, ChangeSet cs, String key, |
|---|
| 64 | 65 | String message, String user, boolean local, boolean force, |
|---|
| 65 | 66 | boolean noCommit, String passphrase) throws HgException { |
|---|
| 66 | | HgCommand command = new HgCommand("sign", project, true); |
|---|
| | 67 | HgCommand command = new HgCommand("sign", directory, true); |
|---|
| 67 | 68 | File file = new File("me.gpg.tmp"); |
|---|
| 68 | 69 | String cmd = "gpg.cmd=".concat( |
|---|
| r777 |
r833 |
|
| 20 | 20 | |
|---|
| 21 | 21 | import com.vectrace.MercurialEclipse.MercurialEclipsePlugin; |
|---|
| | 22 | import com.vectrace.MercurialEclipse.exception.HgException; |
|---|
| 22 | 23 | import com.vectrace.MercurialEclipse.model.GChangeSet; |
|---|
| | 24 | import com.vectrace.MercurialEclipse.model.Signature; |
|---|
| 23 | 25 | import com.vectrace.MercurialEclipse.model.GChangeSet.Edge; |
|---|
| 24 | 26 | import com.vectrace.MercurialEclipse.model.GChangeSet.EdgeList; |
|---|
| … | … | |
| 72 | 74 | refreshJob.join(); |
|---|
| 73 | 75 | } catch (InterruptedException e) { |
|---|
| | 76 | MercurialEclipsePlugin.logError(e); |
|---|
| | 77 | } |
|---|
| | 78 | } |
|---|
| | 79 | |
|---|
| | 80 | // validate signed changesets |
|---|
| | 81 | Signature sig = rev.getSignature(); |
|---|
| | 82 | if (sig != null) { |
|---|
| | 83 | try { |
|---|
| | 84 | if (sig.validate()) { |
|---|
| | 85 | tableItem.setBackground(colours.get(0)); |
|---|
| | 86 | } else { |
|---|
| | 87 | tableItem.setBackground(colours.get(2)); |
|---|
| | 88 | } |
|---|
| | 89 | } catch (HgException e) { |
|---|
| 74 | 90 | MercurialEclipsePlugin.logError(e); |
|---|
| 75 | 91 | } |
|---|
| r784 |
r833 |
|
| 13 | 13 | package com.vectrace.MercurialEclipse.history; |
|---|
| 14 | 14 | |
|---|
| | 15 | import java.io.File; |
|---|
| 15 | 16 | import java.util.Comparator; |
|---|
| 16 | 17 | import java.util.HashMap; |
|---|
| … | … | |
| 30 | 31 | import com.vectrace.MercurialEclipse.commands.HgGLogClient; |
|---|
| 31 | 32 | import com.vectrace.MercurialEclipse.commands.HgLogClient; |
|---|
| | 33 | import com.vectrace.MercurialEclipse.commands.HgSigsClient; |
|---|
| 32 | 34 | import com.vectrace.MercurialEclipse.model.ChangeSet; |
|---|
| 33 | 35 | import com.vectrace.MercurialEclipse.model.GChangeSet; |
|---|
| | 36 | import com.vectrace.MercurialEclipse.model.Signature; |
|---|
| 34 | 37 | import com.vectrace.MercurialEclipse.preferences.MercurialPreferenceConstants; |
|---|
| 35 | 38 | import com.vectrace.MercurialEclipse.team.MercurialTeamProvider; |
|---|
| … | … | |
| 184 | 187 | .getLocation()); |
|---|
| 185 | 188 | if (localChangeSets != null) { |
|---|
| | 189 | // get signatures |
|---|
| | 190 | File file = resource.getLocation().toFile(); |
|---|
| | 191 | List<Signature> sigs = HgSigsClient.getSigs(file); |
|---|
| | 192 | Map<String, Signature> sigMap = new HashMap<String, Signature>(); |
|---|
| | 193 | for (Signature signature : sigs) { |
|---|
| | 194 | sigMap.put(signature.getNodeId(), signature); |
|---|
| | 195 | } |
|---|
| | 196 | |
|---|
| 186 | 197 | changeSets.addAll(localChangeSets); |
|---|
| 187 | 198 | |
|---|
| … | … | |
| 202 | 213 | } |
|---|
| 203 | 214 | for (ChangeSet cs : changeSets) { |
|---|
| | 215 | Signature sig = sigMap.get(cs.getChangeset()); |
|---|
| 204 | 216 | revisions.add(new MercurialRevision(cs, gChangeSets |
|---|
| 205 | 217 | .get(Integer.valueOf(cs.getChangesetIndex())), |
|---|
| 206 | | resource)); |
|---|
| | 218 | resource, sig)); |
|---|
| 207 | 219 | } |
|---|
| 208 | 220 | } |
|---|
| r773 |
r833 |
|
| 22 | 22 | import com.vectrace.MercurialEclipse.model.ChangeSet; |
|---|
| 23 | 23 | import com.vectrace.MercurialEclipse.model.GChangeSet; |
|---|
| | 24 | import com.vectrace.MercurialEclipse.model.Signature; |
|---|
| 24 | 25 | import com.vectrace.MercurialEclipse.team.IStorageMercurialRevision; |
|---|
| 25 | 26 | |
|---|
| 26 | 27 | /** |
|---|
| 27 | 28 | * @author zingo |
|---|
| 28 | | * |
|---|
| | 29 | * |
|---|
| 29 | 30 | */ |
|---|
| 30 | | public class MercurialRevision extends FileRevision |
|---|
| 31 | | { |
|---|
| 32 | | @Override |
|---|
| | 31 | public class MercurialRevision extends FileRevision { |
|---|
| | 32 | |
|---|
| | 33 | |
|---|
| | 34 | public Signature getSignature() { |
|---|
| | 35 | return signature; |
|---|
| | 36 | } |
|---|
| | 37 | |
|---|
| | 38 | @Override |
|---|
| 33 | 39 | public int hashCode() { |
|---|
| 34 | 40 | final int prime = 31; |
|---|
| … | … | |
| 70 | 76 | } |
|---|
| 71 | 77 | |
|---|
| 72 | | private IResource resource; |
|---|
| 73 | | private ChangeSet changeSet; |
|---|
| 74 | | private IStorageMercurialRevision iStorageMercurialRevision; //Cached data |
|---|
| 75 | | private final GChangeSet gChangeSet; |
|---|
| 76 | | private String revision; |
|---|
| 77 | | private String hash; |
|---|
| | 78 | private IResource resource; |
|---|
| | 79 | private ChangeSet changeSet; |
|---|
| | 80 | private IStorageMercurialRevision iStorageMercurialRevision; // Cached data |
|---|
| | 81 | private final GChangeSet gChangeSet; |
|---|
| | 82 | private String revision; |
|---|
| | 83 | private String hash; |
|---|
| | 84 | private Signature signature; |
|---|
| | 85 | |
|---|
| | 86 | public MercurialRevision(ChangeSet changeSet, GChangeSet gChangeSet, |
|---|
| | 87 | IResource resource, Signature sig) { |
|---|
| | 88 | super(); |
|---|
| | 89 | this.changeSet = changeSet; |
|---|
| | 90 | this.gChangeSet = gChangeSet; |
|---|
| 78 | 91 | |
|---|
| 79 | | public MercurialRevision(ChangeSet changeSet, GChangeSet gChangeSet, IResource resource) |
|---|
| 80 | | { |
|---|
| 81 | | super(); |
|---|
| 82 | | this.changeSet = changeSet; |
|---|
| 83 | | this.gChangeSet = gChangeSet; |
|---|
| 84 | | |
|---|
| 85 | | this.revision = changeSet.getChangesetIndex()+""; |
|---|
| 86 | | this.hash = changeSet.getChangeset(); |
|---|
| 87 | | this.resource=resource; |
|---|
| 88 | | } |
|---|
| 89 | | |
|---|
| 90 | | public ChangeSet getChangeSet() |
|---|
| 91 | | { |
|---|
| 92 | | return changeSet; |
|---|
| 93 | | } |
|---|
| | 92 | this.revision = changeSet.getChangesetIndex() + ""; |
|---|
| | 93 | this.hash = changeSet.getChangeset(); |
|---|
| | 94 | this.resource = resource; |
|---|
| | 95 | this.signature = sig; |
|---|
| | 96 | } |
|---|
| 94 | 97 | |
|---|
| 95 | | public GChangeSet getGChangeSet() |
|---|
| 96 | | { |
|---|
| 97 | | return gChangeSet; |
|---|
| 98 | | } |
|---|
| | 98 | public ChangeSet getChangeSet() { |
|---|
| | 99 | return changeSet; |
|---|
| | 100 | } |
|---|
| 99 | 101 | |
|---|
| 100 | | /* (non-Javadoc) |
|---|
| 101 | | * @see org.eclipse.team.core.history.IFileRevision#getName() |
|---|
| 102 | | */ |
|---|
| 103 | | public String getName() |
|---|
| 104 | | { |
|---|
| 105 | | return resource.getName(); |
|---|
| 106 | | } |
|---|
| | 102 | public GChangeSet getGChangeSet() { |
|---|
| | 103 | return gChangeSet; |
|---|
| | 104 | } |
|---|
| 107 | 105 | |
|---|
| 108 | | @Override |
|---|
| 109 | | public String getContentIdentifier() |
|---|
| 110 | | { |
|---|
| 111 | | return changeSet.getChangeset(); |
|---|
| 112 | | } |
|---|
| 113 | | |
|---|
| 114 | | /* (non-Javadoc) |
|---|
| 115 | | * @see org.eclipse.team.core.history.IFileRevision#getStorage(org.eclipse.core.runtime.IProgressMonitor) |
|---|
| 116 | | */ |
|---|
| 117 | | public IStorage getStorage(IProgressMonitor monitor) throws CoreException { |
|---|
| 118 | | if (iStorageMercurialRevision == null) { |
|---|
| 119 | | iStorageMercurialRevision = new IStorageMercurialRevision(resource, |
|---|
| 120 | | revision, hash, changeSet); |
|---|
| 121 | | } |
|---|
| 122 | | return iStorageMercurialRevision; |
|---|
| 123 | | } |
|---|
| | 106 | /* |
|---|
| | 107 | * (non-Javadoc) |
|---|
| | 108 | * |
|---|
| | 109 | * @see org.eclipse.team.core.history.IFileRevision#getName() |
|---|
| | 110 | */ |
|---|
| | 111 | public String getName() { |
|---|
| | 112 | return resource.getName(); |
|---|
| | 113 | } |
|---|
| 124 | 114 | |
|---|
| 125 | | /* |
|---|
| 126 | | * (non-Javadoc) |
|---|
| 127 | | * |
|---|
| 128 | | * @see org.eclipse.team.core.history.IFileRevision#isPropertyMissing() |
|---|
| 129 | | */ |
|---|
| 130 | | public boolean isPropertyMissing() |
|---|
| 131 | | { |
|---|
| 132 | | return false; |
|---|
| 133 | | } |
|---|
| | 115 | @Override |
|---|
| | 116 | public String getContentIdentifier() { |
|---|
| | 117 | return changeSet.getChangeset(); |
|---|
| | 118 | } |
|---|
| 134 | 119 | |
|---|
| 135 | | /* (non-Javadoc) |
|---|
| 136 | | * @see org.eclipse.team.core.history.IFileRevision#withAllProperties(org.eclipse.core.runtime.IProgressMonitor) |
|---|
| 137 | | */ |
|---|
| 138 | | public IFileRevision withAllProperties(IProgressMonitor monitor) throws CoreException |
|---|
| 139 | | { |
|---|
| 140 | | return null; |
|---|
| 141 | | } |
|---|
| | 120 | /* |
|---|
| | 121 | * (non-Javadoc) |
|---|
| | 122 | * |
|---|
| | 123 | * @see |
|---|
| | 124 | * org.eclipse.team.core.history.IFileRevision#getStorage(org.eclipse.core |
|---|
| | 125 | * .runtime.IProgressMonitor) |
|---|
| | 126 | */ |
|---|
| | 127 | public IStorage getStorage(IProgressMonitor monitor) throws CoreException { |
|---|
| | 128 | if (iStorageMercurialRevision == null) { |
|---|
| | 129 | iStorageMercurialRevision = new IStorageMercurialRevision(resource, |
|---|
| | 130 | revision, hash, changeSet); |
|---|
| | 131 | } |
|---|
| | 132 | return iStorageMercurialRevision; |
|---|
| | 133 | } |
|---|
| 142 | 134 | |
|---|
| | 135 | /* |
|---|
| | 136 | * (non-Javadoc) |
|---|
| | 137 | * |
|---|
| | 138 | * @see org.eclipse.team.core.history.IFileRevision#isPropertyMissing() |
|---|
| | 139 | */ |
|---|
| | 140 | public boolean isPropertyMissing() { |
|---|
| | 141 | return false; |
|---|
| | 142 | } |
|---|
| 143 | 143 | |
|---|
| | 144 | /* |
|---|
| | 145 | * (non-Javadoc) |
|---|
| | 146 | * |
|---|
| | 147 | * @see |
|---|
| | 148 | * org.eclipse.team.core.history.IFileRevision#withAllProperties(org.eclipse |
|---|
| | 149 | * .core.runtime.IProgressMonitor) |
|---|
| | 150 | */ |
|---|
| | 151 | public IFileRevision withAllProperties(IProgressMonitor monitor) |
|---|
| | 152 | throws CoreException { |
|---|
| | 153 | return null; |
|---|
| | 154 | } |
|---|
| 144 | 155 | |
|---|
| 145 | | /** |
|---|
| 146 | | * @return the revision |
|---|
| 147 | | */ |
|---|
| 148 | | public String getRevision() { |
|---|
| 149 | | return revision; |
|---|
| 150 | | } |
|---|
| | 156 | /** |
|---|
| | 157 | * @return the revision |
|---|
| | 158 | */ |
|---|
| | 159 | public String getRevision() { |
|---|
| | 160 | return revision; |
|---|
| | 161 | } |
|---|
| 151 | 162 | |
|---|
| | 163 | /** |
|---|
| | 164 | * @param revision |
|---|
| | 165 | * the revision to set |
|---|
| | 166 | */ |
|---|
| | 167 | public void setRevision(String revision) { |
|---|
| | 168 | this.revision = revision; |
|---|
| | 169 | } |
|---|
| 152 | 170 | |
|---|
| | 171 | /** |
|---|
| | 172 | * @return the hash |
|---|
| | 173 | */ |
|---|
| | 174 | public String getHash() { |
|---|
| | 175 | return hash; |
|---|
| | 176 | } |
|---|
| 153 | 177 | |
|---|
| 154 | | /** |
|---|
| 155 | | * @param revision the revision to set |
|---|
| 156 | | */ |
|---|
| 157 | | public void setRevision(String revision) { |
|---|
| 158 | | this.revision = revision; |
|---|
| 159 | | } |
|---|
| | 178 | /** |
|---|
| | 179 | * @param hash |
|---|
| | 180 | * the hash to set |
|---|
| | 181 | */ |
|---|
| | 182 | public void setHash(String hash) { |
|---|
| | 183 | this.hash = hash; |
|---|
| | 184 | } |
|---|
| 160 | 185 | |
|---|
| 161 | | |
|---|
| 162 | | |
|---|
| 163 | | /** |
|---|
| 164 | | * @return the hash |
|---|
| 165 | | */ |
|---|
| 166 | | public String getHash() { |
|---|
| 167 | | return hash; |
|---|
| 168 | | } |
|---|
| 169 | | |
|---|
| 170 | | |
|---|
| 171 | | |
|---|
| 172 | | /** |
|---|
| 173 | | * @param hash the hash to set |
|---|
| 174 | | */ |
|---|
| 175 | | public void setHash(String hash) { |
|---|
| 176 | | this.hash = hash; |
|---|
| 177 | | } |
|---|
| 178 | | |
|---|
| 179 | | public IResource getResource() { |
|---|
| 180 | | return resource; |
|---|
| 181 | | } |
|---|
| | 186 | public IResource getResource() { |
|---|
| | 187 | return resource; |
|---|
| | 188 | } |
|---|
| 182 | 189 | |
|---|
| 183 | 190 | } |
|---|
| r819 |
r833 |
|
| 150 | 150 | * |
|---|
| 151 | 151 | * @param changeSet |
|---|
| 152 | | * string in format rev:nodeshort |
|---|
| | 152 | * string in format rev:nodeshort or rev:node |
|---|
| 153 | 153 | * @return |
|---|
| 154 | 154 | */ |
|---|
| r774 |
r833 |
|
| 166 | 166 | boolean noCommit = noCommitCheckBox.getSelection(); |
|---|
| 167 | 167 | try { |
|---|
| 168 | | HgSignClient.sign(project, cs, key, msg, user, local, force, |
|---|
| | 168 | HgSignClient.sign(project.getLocation().toFile(), cs, key, msg, |
|---|
| | 169 | user, local, force, |
|---|
| 169 | 170 | noCommit, pass); |
|---|
| 170 | 171 | } catch (HgException e) { |
|---|
| r802 |
r833 |
|
| 120 | 120 | } |
|---|
| 121 | 121 | |
|---|
| | 122 | protected void addToRepository(File newFile) throws InterruptedException, |
|---|
| | 123 | IOException { |
|---|
| | 124 | Runtime runtime = Runtime.getRuntime(); |
|---|
| | 125 | runtime.exec("hg add " + newFile.getAbsolutePath(), null, getRepository()).waitFor(); |
|---|
| | 126 | } |
|---|
| | 127 | |
|---|
| 122 | 128 | } |
|---|
| r801 |
r833 |
|
| 12 | 12 | |
|---|
| 13 | 13 | import java.io.File; |
|---|
| 14 | | import java.io.IOException; |
|---|
| 15 | 14 | import java.util.ArrayList; |
|---|
| 16 | 15 | import java.util.List; |
|---|
| … | … | |
| 53 | 52 | HgCommitClient.commit(hgroot, files, "Simple", "the message"); |
|---|
| 54 | 53 | } |
|---|
| 55 | | private void addToRepository(File newFile) throws InterruptedException, IOException { |
|---|
| 56 | | Runtime runtime = Runtime.getRuntime(); |
|---|
| 57 | | runtime.exec("hg add " + newFile.getAbsolutePath(), null, getRepository()).waitFor(); |
|---|
| 58 | | } |
|---|
| 59 | 54 | } |
|---|