Changeset 25269 in osm for applications/editors
- Timestamp:
- 2011-02-11T16:58:53+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm
- Files:
-
- 1 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/TrustOSMplugin.java
r24389 r25269 29 29 import org.openstreetmap.josm.plugins.PluginInformation; 30 30 import org.openstreetmap.josm.plugins.trustosm.actions.ExportSigsAction; 31 import org.openstreetmap.josm.plugins.trustosm.data.TrustO SMItem;31 import org.openstreetmap.josm.plugins.trustosm.data.TrustOsmPrimitive; 32 32 import org.openstreetmap.josm.plugins.trustosm.gui.dialogs.TrustDialog; 33 import org.openstreetmap.josm.plugins.trustosm.gui. preferences.TrustPreferenceEditor;33 import org.openstreetmap.josm.plugins.trustosm.gui.dialogs.TrustPreferenceEditor; 34 34 import org.openstreetmap.josm.plugins.trustosm.io.SigExporter; 35 35 import org.openstreetmap.josm.plugins.trustosm.io.SigImporter; … … 46 46 47 47 /** A global list with all OSM-Ids and corresponding TrustOSMItems */ 48 public static final Map<String, TrustO SMItem> signedItems = new HashMap<String, TrustOSMItem>();48 public static final Map<String, TrustOsmPrimitive> signedItems = new HashMap<String, TrustOsmPrimitive>(); 49 49 50 50 /** … … 56 56 // init the plugin 57 57 super(info); 58 // check if the jarlibs are already extracted or not and extract them if not 59 if (!Main.pref.getBoolean("trustosm.jarLibsExtracted")) { 60 Main.pref.put("trustosm.jarLibsExtracted", extractFiles("trustosm","lib")); 61 Main.pref.put("trustosm.jarLibsExtracted", extractFiles("trustosm","resources")); 62 } 63 58 64 refreshMenu(); 59 65 checkForUnrestrictedPolicyFiles(); 60 extractFiles("trustosm","lib");61 66 // register new SigImporter and SigExporter 62 67 ExtensionFileFilter.importers.add(new SigImporter()); … … 89 94 c.doFinal(data); 90 95 } catch (Exception e) { 91 e.printStackTrace();92 System.err.println(" It seems that the Unrestricted Policy Files are not available in this JVM. So high level crypto is not allowed. Problems may occure.");96 //e.printStackTrace(); 97 System.err.println("Warning: It seems that the Unrestricted Policy Files are not available in this JVM. So high level crypto is not allowed. Problems may occure."); 93 98 //extractFiles("trustosm","jce"); 94 99 installUnrestrictedPolicyFiles(); … … 208 213 } 209 214 210 public static voidextractFiles(String pluginname, String extractDir) {215 public static boolean extractFiles(String pluginname, String extractDir) { 211 216 try { 212 217 if (extractDir == null) extractDir = "lib"; … … 232 237 } 233 238 } 239 return true; 234 240 235 241 } catch (IOException e) { 236 242 e.printStackTrace(); 237 243 return false; 238 244 } 239 245 -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/actions/GetMissingDataAction.java
r24389 r25269 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 16 import org.openstreetmap.josm.plugins.trustosm.TrustOSMplugin; 17 import org.openstreetmap.josm.plugins.trustosm.data.TrustO SMItem;17 import org.openstreetmap.josm.plugins.trustosm.data.TrustOsmPrimitive; 18 18 import org.openstreetmap.josm.plugins.trustosm.gui.DownloadSignedOsmDataTask; 19 19 import org.openstreetmap.josm.tools.Shortcut; … … 35 35 public boolean downloadMissing() { 36 36 Collection<OsmPrimitive> missingData = new HashSet<OsmPrimitive>(); 37 Map<String,TrustO SMItem> trustitems = TrustOSMplugin.signedItems;37 Map<String,TrustOsmPrimitive> trustitems = TrustOSMplugin.signedItems; 38 38 getMissing(trustitems, missingData); 39 39 … … 54 54 } 55 55 56 public void getMissing(Map<String,TrustO SMItem> trustitems, Collection<OsmPrimitive> missingData) {56 public void getMissing(Map<String,TrustOsmPrimitive> trustitems, Collection<OsmPrimitive> missingData) { 57 57 Collection<OsmPrimitive> presentData = getCurrentDataSet().allPrimitives(); 58 for (TrustO SMItemt : trustitems.values()) {59 OsmPrimitive osm = t.getOsm Item();58 for (TrustOsmPrimitive t : trustitems.values()) { 59 OsmPrimitive osm = t.getOsmPrimitive(); 60 60 if (!presentData.contains(osm)) 61 61 missingData.add(osm); -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/data/TrustSignatures.java
r24389 r25269 25 25 private final Map<String, List<PGPSignature>> textsigs = new HashMap<String, List<PGPSignature>>(); 26 26 private byte status; 27 private double reputation; 27 28 28 29 public TrustSignatures() { 29 30 this.status = SIG_UNKNOWN; 31 } 32 33 public TrustSignatures(PGPSignature signature, String sigtext, byte status) { 34 this.status = status; 35 addSignature(signature, sigtext); 30 36 } 31 37 … … 40 46 } 41 47 42 public TrustSignatures(PGPSignature signature, String sigtext, byte status) { 43 this.status = status; 44 addSignature(signature, sigtext); 48 public void setReputation(double r) { 49 reputation = r; 50 } 51 52 public double getReputation() { 53 return reputation; 45 54 } 46 55 … … 97 106 } 98 107 */ 108 public String getOnePlainText() { 109 Set<String> texts = getAllPlainTexts(); 110 if (texts.isEmpty()) return ""; 111 else return texts.iterator().next(); 112 } 113 99 114 public Set<String> getAllPlainTexts() { 100 115 return textsigs.keySet(); -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/DownloadSignedOsmDataTask.java
r24389 r25269 20 20 import org.openstreetmap.josm.io.OsmTransferException; 21 21 import org.openstreetmap.josm.plugins.trustosm.TrustOSMplugin; 22 import org.openstreetmap.josm.plugins.trustosm.data.TrustO SMItem;22 import org.openstreetmap.josm.plugins.trustosm.data.TrustOsmPrimitive; 23 23 import org.xml.sax.SAXException; 24 24 … … 112 112 113 113 public boolean updateReferences(DataSet ds) { 114 for (TrustO SMItemt : TrustOSMplugin.signedItems.values()) {115 OsmPrimitive osm = ds.getPrimitiveById(t.getOsm Item().getPrimitiveId());114 for (TrustOsmPrimitive t : TrustOSMplugin.signedItems.values()) { 115 OsmPrimitive osm = ds.getPrimitiveById(t.getOsmPrimitive().getPrimitiveId()); 116 116 if (osm != null) { 117 t.setOsm Item(osm);117 t.setOsmPrimitive(osm); 118 118 return true; 119 119 } else { -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/KeyTreeTableModel.java
r24389 r25269 21 21 22 22 public static String convPGPSignatureToString(PGPSignature s) { 23 if (s==null) return null; 23 24 PGPSignatureSubpacketVector sv = s.getHashedSubPackets(); 24 if (sv .hasSubpacket(SignatureSubpacketTags.SIGNER_USER_ID))25 if (sv != null && sv.hasSubpacket(SignatureSubpacketTags.SIGNER_USER_ID)) 25 26 return sv.getSignerUserID(); 26 27 … … 30 31 if (i.hasNext()) 31 32 return (String)i.next(); 33 32 34 } 33 35 return tr("unknown"); … … 35 37 36 38 private final SignatureTreeNode root; 37 private final String[] allTitle = {tr("UID"),tr("KeyID"),tr("OSM- Cert"),tr("Signed")};39 private final String[] allTitle = {tr("UID"),tr("KeyID"),tr("OSM-Info"),tr("Signed")}; 38 40 private final List<String> columns = new ArrayList<String>(Arrays.asList(allTitle)); 39 41 -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/dialogs/TrustDialog.java
r24389 r25269 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.BasicStroke; 6 7 import java.awt.BorderLayout; 7 8 import java.awt.Color; 8 9 import java.awt.Component; 9 10 import java.awt.Font; 11 import java.awt.Graphics2D; 10 12 import java.awt.GridLayout; 13 import java.awt.Point; 11 14 import java.awt.event.ActionEvent; 12 15 import java.awt.event.ActionListener; 16 import java.awt.event.FocusEvent; 17 import java.awt.event.FocusListener; 13 18 import java.awt.event.KeyEvent; 19 import java.awt.geom.GeneralPath; 20 import java.util.ArrayList; 14 21 import java.util.Collection; 15 22 import java.util.HashMap; 16 23 import java.util.HashSet; 17 import java.util.Iterator;18 24 import java.util.List; 19 25 import java.util.Map; … … 27 33 import javax.swing.JTable; 28 34 import javax.swing.JTree; 35 import javax.swing.event.TreeSelectionEvent; 36 import javax.swing.event.TreeSelectionListener; 29 37 import javax.swing.table.DefaultTableCellRenderer; 30 38 import javax.swing.table.DefaultTableModel; … … 35 43 import javax.swing.tree.TreePath; 36 44 45 import org.openstreetmap.josm.Main; 46 import org.openstreetmap.josm.data.Bounds; 37 47 import org.openstreetmap.josm.data.SelectionChangedListener; 38 48 import org.openstreetmap.josm.data.osm.DataSet; … … 42 52 import org.openstreetmap.josm.data.osm.Relation; 43 53 import org.openstreetmap.josm.data.osm.Way; 54 import org.openstreetmap.josm.data.osm.WaySegment; 55 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 44 56 import org.openstreetmap.josm.gui.DefaultNameFormatter; 57 import org.openstreetmap.josm.gui.MapView; 45 58 import org.openstreetmap.josm.gui.SideButton; 46 59 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 60 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 47 61 import org.openstreetmap.josm.plugins.trustosm.TrustOSMplugin; 48 import org.openstreetmap.josm.plugins.trustosm.data.TrustOSMItem; 62 import org.openstreetmap.josm.plugins.trustosm.data.TrustNode; 63 import org.openstreetmap.josm.plugins.trustosm.data.TrustOsmPrimitive; 49 64 import org.openstreetmap.josm.plugins.trustosm.data.TrustSignatures; 65 import org.openstreetmap.josm.plugins.trustosm.data.TrustWay; 66 import org.openstreetmap.josm.plugins.trustosm.util.TrustAnalyzer; 50 67 import org.openstreetmap.josm.tools.ImageProvider; 51 68 import org.openstreetmap.josm.tools.Shortcut; 52 69 53 public class TrustDialog extends ToggleDialog implements ActionListener, SelectionChangedListener {70 public class TrustDialog extends ToggleDialog implements ActionListener, SelectionChangedListener, MapViewPaintable { 54 71 55 72 /** … … 84 101 private Collection<? extends OsmPrimitive> osmData; 85 102 103 104 private final List<WaySegment> selectedSegments = new ArrayList<WaySegment>(); 105 private final List<OsmPrimitive> selectedPrimitives = new ArrayList<OsmPrimitive>(); 106 107 /** The JTree for showing the geometry */ 86 108 private final JTree geomTree; 109 87 110 88 111 /** … … 122 145 }; 123 146 147 /** The JTable for members of a relation */ 148 private final DefaultTableModel memberData = new DefaultTableModel() { 149 150 /** 151 * 152 */ 153 private static final long serialVersionUID = 1L; 154 @Override public boolean isCellEditable(int row, int column) { 155 return false; 156 } 157 @Override public Class<?> getColumnClass(int columnIndex) { 158 return String.class; 159 } 160 }; 161 private final JTable memberTable = new JTable(memberData) { 162 /** 163 * 164 */ 165 private static final long serialVersionUID = 1L; 166 167 @Override 168 public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { 169 Component c = super.prepareRenderer(renderer, row, column); 170 Byte stat = rowStatus.get(getModel().getValueAt(row, 0)); 171 if (!isRowSelected(row)) 172 switch (stat.byteValue()) { 173 case -2: c.setBackground( BGCOLOR_REMOVED_ITEM ); break; 174 case -1: c.setBackground( BGCOLOR_BROKEN_SIG ); break; 175 case 1: c.setBackground( BGCOLOR_VALID_SIG ); break; 176 default: c.setBackground( BGCOLOR_NO_SIG ); break; 177 } 178 return c; 179 } 180 }; 181 182 124 183 /** 125 184 * Constructor … … 130 189 KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 131 190 191 Main.map.mapView.addTemporaryLayer(this); 132 192 133 193 // setting up the properties table … … 186 246 DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; 187 247 if (node.isRoot()) return this; 188 OsmPrimitive osm = (OsmPrimitive) node.getUserObject(); 189 setIcon(ImageProvider.get(OsmPrimitiveType.from(osm))); 190 setText(osm.getDisplayName(DefaultNameFormatter.getInstance())); 191 192 if (osm instanceof Node) { 193 Node osmNode = (Node) osm; 194 if (((DefaultMutableTreeNode) node.getParent()).getUserObject() instanceof Way) { 195 osm = (OsmPrimitive) ((DefaultMutableTreeNode) node.getParent()).getUserObject(); 196 } 248 setBackgroundNonSelectionColor( BGCOLOR_NO_SIG ); 249 Object o = node.getUserObject(); 250 if (o instanceof OsmPrimitive){ 251 OsmPrimitive osm = (OsmPrimitive) o; 252 setIcon(ImageProvider.get(OsmPrimitiveType.from(osm))); 253 setText(osm.getDisplayName(DefaultNameFormatter.getInstance())); 254 255 256 if (osm instanceof Node) { 257 Node osmNode = (Node) osm; 258 TrustSignatures sigs; 259 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 260 if (TrustOSMplugin.signedItems.containsKey(id) && (sigs = ((TrustNode)TrustOSMplugin.signedItems.get(id)).getNodeSigs()) != null) { 261 byte stat = sigs.getStatus(); 262 switch (stat) { 263 case -2: setBackgroundNonSelectionColor( BGCOLOR_REMOVED_ITEM ); break; 264 case -1: setBackgroundNonSelectionColor( BGCOLOR_BROKEN_SIG ); break; 265 case 1: setBackgroundNonSelectionColor( BGCOLOR_VALID_SIG ); break; 266 default: setBackgroundNonSelectionColor( BGCOLOR_NO_SIG ); break; 267 } 268 } 269 } else if (osm instanceof Way) { 270 //setBackgroundNonSelectionColor( BGCOLOR_NO_SIG ); 271 } 272 273 } else if (o instanceof WaySegment){ 274 WaySegment seg = (WaySegment) o; 275 setIcon(ImageProvider.get("mapmode/addsegment")); 276 setText(seg.getFirstNode().getDisplayName(DefaultNameFormatter.getInstance()) + " ----- " + seg.getSecondNode().getDisplayName(DefaultNameFormatter.getInstance())); 197 277 TrustSignatures sigs; 198 String id = String.valueOf(osm.getUniqueId());199 if (TrustOSMplugin.signedItems.containsKey(id) && (sigs = TrustOSMplugin.signedItems.get(id).getSigsOnNode(osmNode)) != null) {278 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(seg.way); 279 if (TrustOSMplugin.signedItems.containsKey(id) && (sigs = ((TrustWay)TrustOSMplugin.signedItems.get(id)).getSigsOnSegment(seg)) != null) { 200 280 byte stat = sigs.getStatus(); 201 281 switch (stat) { … … 205 285 default: setBackgroundNonSelectionColor( BGCOLOR_NO_SIG ); break; 206 286 } 207 } else { 208 setBackgroundNonSelectionColor( BGCOLOR_NO_SIG ); 209 } 210 } else if (osm instanceof Way) { 211 setBackgroundNonSelectionColor( BGCOLOR_NO_SIG ); 287 } 212 288 } 213 289 return this; … … 217 293 }); 218 294 219 220 295 geomTree.addTreeSelectionListener(new TreeSelectionListener() { 296 public void valueChanged(TreeSelectionEvent e) { 297 // unhighlight everything 298 for (OsmPrimitive p : selectedPrimitives) { 299 p.setHighlighted(false); 300 } 301 selectedPrimitives.clear(); 302 selectedSegments.clear(); 303 if (geomTree.getSelectionPaths()!=null) 304 for (TreePath tp : geomTree.getSelectionPaths()) { 305 Object o = ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject(); 306 if (o instanceof WaySegment) { 307 selectedSegments.add((WaySegment) o); 308 } else if (o instanceof OsmPrimitive) { 309 OsmPrimitive highlight = (OsmPrimitive) o; 310 highlight.setHighlighted(true); 311 selectedPrimitives.add(highlight); 312 } 313 } 314 Main.map.mapView.repaint(); 315 } 316 }); 317 318 propertyTable.addFocusListener(new FocusListener(){ 319 320 @Override 321 public void focusGained(FocusEvent fe) { 322 geomTree.clearSelection(); 323 324 } 325 326 @Override 327 public void focusLost(FocusEvent fe) { 328 329 } 330 331 }); 332 333 geomTree.addFocusListener(new FocusListener(){ 334 335 @Override 336 public void focusGained(FocusEvent fe) { 337 propertyTable.clearSelection(); 338 339 } 340 341 @Override 342 public void focusLost(FocusEvent fe) { 343 344 } 345 346 }); 221 347 222 348 JPanel dataPanel = new JPanel(); … … 253 379 if (actionCommand.equals("Check")) { 254 380 for (OsmPrimitive osm : osmData) { 255 String id = String.valueOf(osm.getUniqueId());381 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 256 382 if (TrustOSMplugin.signedItems.containsKey(id)) 257 Trust OSMplugin.gpg.checkAll(TrustOSMplugin.signedItems.get(id));383 TrustAnalyzer.checkEverything(TrustOSMplugin.signedItems.get(id)); 258 384 //checkedItems.put(osm, TrustOSMplugin.gpg.check(checkedItems.containsKey(osm)? checkedItems.get(osm) : new TrustOSMItem(osm))); 259 385 } … … 265 391 for (OsmPrimitive osm : osmData) { 266 392 if (osm.keySet().contains(key)) { 267 String id = String.valueOf(osm.getUniqueId()); 268 TrustOSMplugin.signedItems.put(id, TrustOSMplugin.gpg.signTag(TrustOSMplugin.signedItems.containsKey(id)? TrustOSMplugin.signedItems.get(id) : new TrustOSMItem(osm), key)); 393 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 394 TrustOsmPrimitive trust = TrustOSMplugin.signedItems.containsKey(id)? TrustOSMplugin.signedItems.get(id) : TrustOsmPrimitive.createTrustOsmPrimitive(osm); 395 if (TrustOSMplugin.gpg.signTag(trust, key)) 396 TrustOSMplugin.signedItems.put(id, trust); 269 397 } 270 398 } … … 272 400 if (geomTree.getSelectionPaths()!=null) 273 401 for (TreePath tp : geomTree.getSelectionPaths()) { 274 OsmPrimitive osm = (OsmPrimitive) ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject(); 275 String id = String.valueOf(osm.getUniqueId()); 276 if (osm instanceof Node) { 402 Object o = ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject(); 403 if (o instanceof OsmPrimitive) { 404 OsmPrimitive osm = (OsmPrimitive) o; 405 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 406 if (osm instanceof Node) { 407 Node osmNode = ((Node) osm); 408 TrustNode trust = TrustOSMplugin.signedItems.containsKey(id)? (TrustNode) TrustOSMplugin.signedItems.get(id) : new TrustNode(osmNode); 409 trust.storeNodeSig(TrustOSMplugin.gpg.signNode(osmNode)); 410 TrustOSMplugin.signedItems.put(id, trust); 411 412 413 /* TreePath parentPath = tp.getParentPath(); 414 if (geomTree.isPathSelected(parentPath)) return; 415 416 Node osmNode = ((Node) osm); 417 if (((DefaultMutableTreeNode) parentPath.getLastPathComponent()).getUserObject() instanceof Way) { 418 osm = (OsmPrimitive) ((DefaultMutableTreeNode) parentPath.getLastPathComponent()).getUserObject(); 419 id = String.valueOf(osm.getUniqueId()); 420 } 421 TrustOsmPrimitive trust = TrustOSMplugin.signedItems.containsKey(id)? TrustOSMplugin.signedItems.get(id) : TrustOsmPrimitive.createTrustOsmPrimitive(osm); 422 trust.storeNodeSig(osmNode, TrustOSMplugin.gpg.signNode(osm,osmNode)); 423 TrustOSMplugin.signedItems.put(id, trust); 424 */ 425 } else if (osm instanceof Way) { 426 TrustOSMplugin.signedItems.put(id, TrustOSMplugin.gpg.signWay(TrustOSMplugin.signedItems.containsKey(id)? (TrustWay)TrustOSMplugin.signedItems.get(id) : new TrustWay(osm))); 427 /*Way osmWay = ((Way) osm); 428 TrustWay trust = TrustOSMplugin.signedItems.containsKey(id)? (TrustWay) TrustOSMplugin.signedItems.get(id) : new TrustWay(osmWay); 429 trust.storeSegmentSig(TrustOSMplugin.gpg.signWay(osmWay)); 430 TrustOSMplugin.signedItems.put(id, trust); 431 */ 432 } 433 } else if (o instanceof WaySegment) { 277 434 TreePath parentPath = tp.getParentPath(); 278 435 if (geomTree.isPathSelected(parentPath)) return; 279 280 Node osmNode = ((Node) osm); 281 if (((DefaultMutableTreeNode) parentPath.getLastPathComponent()).getUserObject() instanceof Way) { 282 osm = (OsmPrimitive) ((DefaultMutableTreeNode) parentPath.getLastPathComponent()).getUserObject(); 283 } 284 TrustOSMItem trust = TrustOSMplugin.signedItems.containsKey(id)? TrustOSMplugin.signedItems.get(id) : new TrustOSMItem(osm); 285 trust.storeNodeSig(osmNode, TrustOSMplugin.gpg.signNode(osm,osmNode)); 436 WaySegment seg = (WaySegment) o; 437 List<Node> nodes = new ArrayList<Node>(); 438 nodes.add(seg.getFirstNode()); 439 nodes.add(seg.getSecondNode()); 440 Way w = seg.way; 441 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(w); 442 TrustWay trust = TrustOSMplugin.signedItems.containsKey(id)? (TrustWay) TrustOSMplugin.signedItems.get(id) : new TrustWay(w); 443 trust.storeSegmentSig(nodes,TrustOSMplugin.gpg.signSegment(trust,nodes)); 286 444 TrustOSMplugin.signedItems.put(id, trust); 287 } else if (osm instanceof Way) {288 TrustOSMplugin.signedItems.put(id, TrustOSMplugin.gpg.signGeometry(TrustOSMplugin.signedItems.containsKey(id)? TrustOSMplugin.signedItems.get(id) : new TrustOSMItem(osm)));289 445 } 290 446 } … … 295 451 String key = (String)propertyTable.getValueAt(i, 0); 296 452 for (OsmPrimitive osm : osmData) { 297 String id = String.valueOf(osm.getUniqueId());453 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 298 454 if (osm.keySet().contains(key) && TrustOSMplugin.signedItems.containsKey(id)) { 299 455 TrustSignaturesDialog.showSignaturesDialog(TrustOSMplugin.signedItems.get(id), key); … … 301 457 } 302 458 } 459 if (geomTree.getSelectionPaths()!=null) 460 for (TreePath tp : geomTree.getSelectionPaths()) { 461 Object o = ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject(); 462 if (o instanceof OsmPrimitive) { 463 OsmPrimitive osm = (OsmPrimitive) o; 464 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 465 if (osm instanceof Node) { 466 if (TrustOSMplugin.signedItems.containsKey(id)) { 467 TrustSignaturesDialog.showSignaturesDialog((TrustNode) TrustOSMplugin.signedItems.get(id)); 468 } 469 } else if (osm instanceof Way) { 470 //TrustOSMplugin.signedItems.put(id, TrustOSMplugin.gpg.signGeometry(TrustOSMplugin.signedItems.containsKey(id)? TrustOSMplugin.signedItems.get(id) : new TrustOSMItem(osm))); 471 } 472 } else if (o instanceof WaySegment) { 473 WaySegment seg = (WaySegment) o; 474 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(seg.way); 475 if (TrustOSMplugin.signedItems.containsKey(id)) { 476 List<Node> nodes = new ArrayList<Node>(); 477 nodes.add(seg.getFirstNode()); 478 nodes.add(seg.getSecondNode()); 479 TrustSignaturesDialog.showSignaturesDialog((TrustWay) TrustOSMplugin.signedItems.get(id),nodes); 480 } 481 } 482 } 483 303 484 } 304 485 } … … 336 517 } 337 518 */ 519 public static List<WaySegment> generateSegmentListFromWay(Way w) { 520 List<WaySegment> segList = new ArrayList<WaySegment>(); 521 for (int i = 0; i < w.getNodesCount()-1; i++) { 522 segList.add(new WaySegment(w,i)); 523 } 524 return segList; 525 } 526 338 527 private DefaultTreeModel createTree(){ 339 528 DefaultMutableTreeNode root = new DefaultMutableTreeNode(); … … 341 530 if (osmData!=null) 342 531 for (OsmPrimitive osm : osmData) { 343 String id = String.valueOf(osm.getUniqueId());532 //String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 344 533 if(osm instanceof Node) { 345 534 root.add(new DefaultMutableTreeNode(osm)); 346 535 } else if(osm instanceof Way) { 536 wayNode = new DefaultMutableTreeNode(osm); 537 List<WaySegment> presentSegments = TrustDialog.generateSegmentListFromWay(((Way)osm)); 538 for (WaySegment seg : presentSegments ) { 539 wayNode.add(new DefaultMutableTreeNode(seg)); 540 } 541 542 /* 347 543 wayNode = new DefaultMutableTreeNode(osm); 348 544 List<Node> presentNodes = ((Way)osm).getNodes(); … … 353 549 354 550 if (TrustOSMplugin.signedItems.containsKey(id)) { 355 TrustO SMItemtrust = TrustOSMplugin.signedItems.get(id);551 TrustOsmPrimitive trust = TrustOSMplugin.signedItems.get(id); 356 552 HashSet<Node> signedNodes = new HashSet<Node>(trust.getGeomSigs().keySet()); 357 553 signedNodes.removeAll(presentNodes); … … 364 560 } 365 561 } 562 */ 366 563 root.add(wayNode); 367 564 } else if(osm instanceof Relation) { … … 381 578 Map<String, Map<String, Integer>> valueCount = new TreeMap<String, Map<String, Integer>>(); 382 579 383 TrustO SMItemtrust;580 TrustOsmPrimitive trust; 384 581 385 582 valueCount.clear(); … … 388 585 389 586 for (OsmPrimitive osm : osmData) { 390 String id = String.valueOf(osm.getUniqueId());587 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 391 588 if (TrustOSMplugin.signedItems.containsKey(id)) { 392 589 trust = TrustOSMplugin.signedItems.get(id); … … 403 600 404 601 } else { 405 trust = new TrustOSMItem(osm);602 trust = TrustOsmPrimitive.createTrustOsmPrimitive(osm); 406 603 sigsAvailable = false; 407 604 } … … 464 661 } 465 662 663 @Override 664 public void paint(Graphics2D g, MapView mv, Bounds bbox) { 665 // if there are no Segments to highlight - return 666 if (selectedSegments.isEmpty()) return; 667 668 // sanity checks 669 if (Main.map.mapView == null) return; 670 671 672 Graphics2D g2 = g; 673 g2.setColor(PaintColors.HIGHLIGHT.get()); 674 g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); 675 676 // highlight all selected WaySegments 677 for (WaySegment seg : selectedSegments) { 678 GeneralPath b = new GeneralPath(); 679 Point p1=mv.getPoint(seg.getFirstNode()); 680 Point p2=mv.getPoint(seg.getSecondNode()); 681 682 b.moveTo(p1.x,p1.y); b.lineTo(p2.x, p2.y); 683 684 g2.draw(b); 685 } 686 g2.setStroke(new BasicStroke(1)); 687 } 688 466 689 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/dialogs/TrustSignaturesDialog.java
r24389 r25269 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Component;6 5 import java.awt.Dimension; 7 6 import java.awt.GridBagLayout; 8 import java.awt.event.ActionEvent;9 import java.awt.event.ActionListener;10 7 import java.awt.event.MouseAdapter; 11 8 import java.awt.event.MouseEvent; 12 9 import java.text.SimpleDateFormat; 13 import java.util.Collection;14 import java.util.Iterator;15 10 import java.util.List; 16 11 17 12 import javax.swing.Box; 18 import javax.swing.JButton;19 13 import javax.swing.JLabel; 20 14 import javax.swing.JOptionPane; … … 22 16 import javax.swing.JScrollPane; 23 17 import javax.swing.JTextArea; 24 import javax.swing.JTree;25 import javax.swing.tree.DefaultMutableTreeNode;26 import javax.swing.tree.DefaultTreeCellRenderer;27 import javax.swing.tree.DefaultTreeModel;28 18 import javax.swing.tree.TreePath; 29 19 30 import org.bouncycastle.bcpg.SignatureSubpacketTags;31 import org.bouncycastle.bcpg.sig.NotationData;32 20 import org.bouncycastle.openpgp.PGPPublicKey; 33 21 import org.bouncycastle.openpgp.PGPSignature; 34 import org.bouncycastle.openpgp.PGPSignatureSubpacketVector;35 22 import org.jdesktop.swingx.JXTreeTable; 36 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.data.osm.Node; 25 import org.openstreetmap.josm.gui.DefaultNameFormatter; 37 26 import org.openstreetmap.josm.gui.ExtendedDialog; 38 27 import org.openstreetmap.josm.plugins.trustosm.TrustOSMplugin; 39 import org.openstreetmap.josm.plugins.trustosm.data.TrustOSMItem; 28 import org.openstreetmap.josm.plugins.trustosm.data.TrustNode; 29 import org.openstreetmap.josm.plugins.trustosm.data.TrustOsmPrimitive; 40 30 import org.openstreetmap.josm.plugins.trustosm.data.TrustSignatures; 31 import org.openstreetmap.josm.plugins.trustosm.data.TrustWay; 41 32 import org.openstreetmap.josm.plugins.trustosm.gui.KeyTreeTableModel; 42 33 import org.openstreetmap.josm.plugins.trustosm.gui.KeyTreeTableModel.SignatureTreeNode; … … 49 40 public class TrustSignaturesDialog { 50 41 51 public static void showSignaturesDialog(TrustOSMItem trust, String key) { 42 43 private static String createLabel(String plain, int type) { 44 if (type == 0) { 45 String[] kv = TrustOsmPrimitive.generateTagsFromSigtext(plain); 46 return tr("Signed key value pair was: {0}={1}", kv[0],kv[1]); 47 } else if (type == 1) { 48 Node node = TrustNode.generateNodeFromSigtext(plain); 49 //return tr("Signed node was: {0}", node.getDisplayName(DefaultNameFormatter.getInstance())); 50 return "ID:"+node.getUniqueId()+" ("+node.getCoor().toString() + ")"; 51 } else if (type == 2) { 52 List<Node> nodes = TrustWay.generateSegmentFromSigtext(plain); 53 return "From:"+nodes.get(0).getUniqueId()+", To:"+nodes.get(nodes.size()-1).getUniqueId(); 54 } 55 return "No known type"; 56 } 57 58 private static void showDialog(TrustSignatures sigs, String label, int type) { 59 JPanel p = new JPanel(new GridBagLayout()); 60 p.add(new JLabel(label),GBC.eol()); 61 62 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd:hh.mm.ss"); 63 64 for (String plain : sigs.getAllPlainTexts()) { 65 JTextArea sigtext = new JTextArea(sigs.getArmoredFulltextSignatureAll(plain)); 66 sigtext.setEditable(false); 67 JPanel textcontent = new JPanel(); 68 textcontent.add(sigtext); 69 70 p.add(new JCollapsiblePanel(createLabel(plain, type),textcontent),GBC.eol()); 71 72 List<PGPSignature> siglist = sigs.getSignaturesByPlaintext(plain); 73 JPanel signerPanel = new JPanel(new GridBagLayout()); 74 //signerPanel.add(createSignerTree(siglist)); 75 KeyTreeTableModel km = new KeyTreeTableModel(siglist); 76 final JXTreeTable t = new JXTreeTable( km ); 77 //t.setHorizontalScrollEnabled(true); 78 //t.setRootVisible(false); 79 t.addMouseListener(new MouseAdapter() { 80 @Override 81 public void mouseClicked(MouseEvent e) { 82 if (e.getClickCount() == 2) { 83 TreePath selPath = t.getPathForLocation(e.getX(), e.getY()); 84 if (selPath == null) 85 return; 86 SignatureTreeNode sn = (SignatureTreeNode)selPath.getLastPathComponent(); 87 PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(sn.getSignature().getKeyID()); 88 TrustGPG.showKeyDetails(pub); 89 } 90 } 91 }); 92 t.setLeafIcon(ImageProvider.get("dialogs/sign")); 93 t.setOpenIcon(ImageProvider.get("dialogs/sign_color")); 94 t.setClosedIcon(ImageProvider.get("dialogs/sign_color")); 95 t.expandAll(); 96 t.packAll(); 97 t.collapseAll(); 98 signerPanel.add(new JScrollPane(t)); 99 100 101 // JTreeTable tt = new JTreeTable(); 102 103 /* for (PGPSignature s : siglist) { 104 signerPanel.add(createKeyButton(tr("Signature created at {0} by User {1}",formatter.format(s.getCreationTime()),s.getHashedSubPackets().getSignerUserID()),s.getKeyID()),GBC.eol()); 105 //signerPanel.add(new JLabel(tr("Signature created at {0} by User {1}",formatter.format(s.getCreationTime()),s.getHashedSubPackets().getSignerUserID())),GBC.eol()); 106 }*/ 107 108 p.add(new JCollapsiblePanel(tr("{0} Signatures found.", siglist.size()),signerPanel),GBC.eol().insets(20,0,0,0)); 109 } 110 p.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH)); 111 JScrollPane scroller = new JScrollPane(p); 112 //JPanel content = new JPanel(); 113 scroller.setPreferredSize(new Dimension(700,500)); 114 //content.add(scroller); 115 //JOptionPane.showMessageDialog(Main.parent,scroller, tr("Clearsigned Signature"), JOptionPane.PLAIN_MESSAGE); 116 String[] buttons = {tr("Ok")}; 117 ExtendedDialog info = new ExtendedDialog(Main.parent, tr("Signature Info"),buttons,false); 118 info.setContent(scroller,false); 119 info.showDialog(); 120 } 121 122 123 public static void showSignaturesDialog(TrustNode trust) { 124 TrustSignatures sigs; 125 if ((sigs = trust.getNodeSigs()) == null) { 126 JOptionPane.showMessageDialog(null,tr("Sorry, there are no Signatures for the selected Node."), tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 127 } else { 128 String nodename = ((Node)trust.getOsmPrimitive()).getDisplayName(DefaultNameFormatter.getInstance()); 129 showDialog(sigs, tr("Selected node was:\n{0}",nodename),1); 130 } 131 } 132 133 public static void showSignaturesDialog(TrustOsmPrimitive trust, String key) { 52 134 TrustSignatures sigs; 53 135 if ((sigs = trust.getSigsOnKey(key)) == null) { 54 136 JOptionPane.showMessageDialog(null,tr("Sorry, there are no Signatures for the selected Attribute."), tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 55 137 } else { 56 JPanel p = new JPanel(new GridBagLayout()); 57 p.add(new JLabel(tr("Selected key value pair was:\n{0}={1}",key,trust.getOsmItem().get(key))),GBC.eol()); 58 59 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd:hh.mm.ss"); 60 61 for (String plain : sigs.getAllPlainTexts()) { 62 JTextArea sigtext = new JTextArea(sigs.getArmoredFulltextSignatureAll(plain)); 63 sigtext.setEditable(false); 64 JPanel textcontent = new JPanel(); 65 textcontent.add(sigtext); 66 String[] kv = TrustGPG.generateTagsFromSigtext(plain); 67 p.add(new JCollapsiblePanel(tr("Signed key value pair was: {0}={1}", kv[0],kv[1]),textcontent),GBC.eol()); 68 69 List<PGPSignature> siglist = sigs.getSignaturesByPlaintext(plain); 70 JPanel signerPanel = new JPanel(new GridBagLayout()); 71 //signerPanel.add(createSignerTree(siglist)); 72 KeyTreeTableModel km = new KeyTreeTableModel(siglist); 73 final JXTreeTable t = new JXTreeTable( km ); 74 //t.setHorizontalScrollEnabled(true); 75 //t.setRootVisible(false); 76 t.addMouseListener(new MouseAdapter() { 77 @Override 78 public void mouseClicked(MouseEvent e) { 79 if (e.getClickCount() == 2) { 80 TreePath selPath = t.getPathForLocation(e.getX(), e.getY()); 81 if (selPath == null) 82 return; 83 SignatureTreeNode sn = (SignatureTreeNode)selPath.getLastPathComponent(); 84 PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(sn.getSignature().getKeyID()); 85 TrustGPG.showKeyDetails(pub); 86 } 87 } 88 }); 89 t.setLeafIcon(ImageProvider.get("dialogs/sign")); 90 t.setOpenIcon(ImageProvider.get("dialogs/sign_color")); 91 t.setClosedIcon(ImageProvider.get("dialogs/sign_color")); 92 t.expandAll(); 93 t.packAll(); 94 t.collapseAll(); 95 signerPanel.add(new JScrollPane(t)); 96 97 98 // JTreeTable tt = new JTreeTable(); 99 100 /* for (PGPSignature s : siglist) { 101 signerPanel.add(createKeyButton(tr("Signature created at {0} by User {1}",formatter.format(s.getCreationTime()),s.getHashedSubPackets().getSignerUserID()),s.getKeyID()),GBC.eol()); 102 //signerPanel.add(new JLabel(tr("Signature created at {0} by User {1}",formatter.format(s.getCreationTime()),s.getHashedSubPackets().getSignerUserID())),GBC.eol()); 103 }*/ 104 105 p.add(new JCollapsiblePanel(tr("{0} Signatures found.", siglist.size()),signerPanel),GBC.eol().insets(20,0,0,0)); 106 } 107 108 /* 109 110 for (PGPSignature s : sigs.getSignatures()) { 111 JTextArea sigtext = new JTextArea(sigs.getArmoredFulltextSignature(s)); 112 sigtext.setEditable(false); 113 sigtext.setAlignmentX(Component.LEFT_ALIGNMENT); 114 p.add(sigtext); 115 JLabel siginfo = new JLabel(tr("Signature created at {0} by User {1}",formatter.format(s.getCreationTime()),s.getHashedSubPackets().getSignerUserID())); 116 siginfo.setAlignmentX(Component.LEFT_ALIGNMENT); 117 p.add(siginfo); 118 p.add(Box.createRigidArea(d)); 119 } 120 */ 121 122 123 p.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH)); 124 JScrollPane scroller = new JScrollPane(p); 125 //JPanel content = new JPanel(); 126 scroller.setPreferredSize(new Dimension(700,500)); 127 //content.add(scroller); 128 //JOptionPane.showMessageDialog(Main.parent,scroller, tr("Clearsigned Signature"), JOptionPane.PLAIN_MESSAGE); 129 String[] buttons = {tr("Ok")}; 130 ExtendedDialog info = new ExtendedDialog(Main.parent, tr("Signature Info"),buttons,false); 131 info.setContent(scroller,false); 132 info.showDialog(); 133 //info.setBounds(200, 200, 300, 200); 134 //info.setVisible(true); 135 } 136 } 137 138 showDialog(sigs, tr("Selected key value pair was:\n{0}={1}",key,trust.getOsmPrimitive().get(key)), 0); 139 } 140 } 141 142 public static void showSignaturesDialog(TrustWay trust, List<Node> nodes) { 143 TrustSignatures sigs; 144 if ((sigs = trust.getSigsOnSegment(nodes)) == null) { 145 JOptionPane.showMessageDialog(null,tr("Sorry, there are no Signatures for the selected Segment."), tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 146 } else { 147 showDialog(sigs, tr("Selected WaySegment was:"), 2); 148 } 149 } 150 151 /* 138 152 public static JButton createKeyButton(String label,final long keyID) { 139 153 JButton detailsButton = new JButton(label); … … 232 246 } 233 247 234 248 */ 235 249 236 250 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigExporter.java
r24389 r25269 24 24 25 25 public SigExporter() { 26 super(new ExtensionFileFilter("t oxm,xml", "tosm", tr("Signature Files") + " (*.tosm*.xml)"));26 super(new ExtensionFileFilter("txml,xml", "txml", tr("Signature Files") + " (*.txml *.xml)")); 27 27 } 28 28 -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigImporter.java
r24389 r25269 20 20 import org.openstreetmap.josm.plugins.trustosm.TrustOSMplugin; 21 21 import org.openstreetmap.josm.plugins.trustosm.actions.GetMissingDataAction; 22 import org.openstreetmap.josm.plugins.trustosm.data.TrustO SMItem;22 import org.openstreetmap.josm.plugins.trustosm.data.TrustOsmPrimitive; 23 23 24 24 public class SigImporter extends FileImporter { 25 25 26 26 public SigImporter() { 27 super(new ExtensionFileFilter("t osm,xml", "tosm", tr("OSM Signature Files") + " (*.tosm*.xml)"));27 super(new ExtensionFileFilter("txml,xml", "txml", tr("OSM Signature Files") + " (*.txml *.xml)")); 28 28 } 29 29 … … 49 49 } 50 50 // Set<OsmPrimitive> missingData = new HashSet<OsmPrimitive>(); 51 Map<String,TrustO SMItem> trustitems = SigReader.parseSignatureXML(in, NullProgressMonitor.INSTANCE);51 Map<String,TrustOsmPrimitive> trustitems = SigReader.parseSignatureXML(in, NullProgressMonitor.INSTANCE); 52 52 53 53 /* -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigReader.java
r24389 r25269 10 10 import java.util.HashMap; 11 11 import java.util.HashSet; 12 import java.util.List; 12 13 import java.util.Map; 13 14 import java.util.Set; … … 24 25 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 25 26 import org.openstreetmap.josm.data.osm.Relation; 27 import org.openstreetmap.josm.data.osm.RelationMember; 26 28 import org.openstreetmap.josm.data.osm.Way; 27 29 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; … … 30 32 import org.openstreetmap.josm.io.OsmDataParsingException; 31 33 import org.openstreetmap.josm.io.UTFInputStreamReader; 32 import org.openstreetmap.josm.plugins.trustosm.data.TrustOSMItem; 34 import org.openstreetmap.josm.plugins.trustosm.data.TrustNode; 35 import org.openstreetmap.josm.plugins.trustosm.data.TrustOsmPrimitive; 36 import org.openstreetmap.josm.plugins.trustosm.data.TrustRelation; 33 37 import org.openstreetmap.josm.plugins.trustosm.data.TrustSignatures; 38 import org.openstreetmap.josm.plugins.trustosm.data.TrustWay; 34 39 import org.openstreetmap.josm.tools.CheckParameterUtil; 35 40 import org.xml.sax.Attributes; … … 42 47 public class SigReader { 43 48 44 private final Map<String,TrustO SMItem> trustitems = new HashMap<String,TrustOSMItem>();49 private final Map<String,TrustOsmPrimitive> trustitems = new HashMap<String,TrustOsmPrimitive>(); 45 50 private final Set<OsmPrimitive> missingData = new HashSet<OsmPrimitive>(); 46 51 47 public Map<String,TrustO SMItem> getTrustItems() {52 public Map<String,TrustOsmPrimitive> getTrustItems() { 48 53 return trustitems; 49 54 } … … 68 73 * The current TrustOSMItem to be read. 69 74 */ 70 private TrustOSMItem trust; 71 72 /** 73 * Signatures of geometry and tags. 74 */ 75 private final Map<String, TrustSignatures> keySig = new HashMap<String, TrustSignatures>(); 76 private final Map<String, TrustSignatures> nodeSig = new HashMap<String, TrustSignatures>(); 75 private TrustOsmPrimitive trust; 76 77 77 78 /** 78 79 * The current Signatures. … … 87 88 88 89 try { 89 if (qName.equals("trust item")) {90 if (qName.equals("trustnode") || qName.equals("trustway") || qName.equals("trustrelation")) { 90 91 if (atts == null) { 91 throwException(tr("Missing mandatory attribute ''{0}'' of XML element {1}.", "osmid", "trustitem"));92 throwException(tr("Missing mandatory attribute ''{0}'' of XML element {1}.", "osmid", qName)); 92 93 } 93 94 … … 100 101 long uid = Long.parseLong(osmid); 101 102 102 String osmtype = atts.getValue("type"); 103 if (osmtype == null){ 104 throwException(tr("Missing mandatory attribute ''{0}''.", "type")); 105 } 106 OsmPrimitiveType t = OsmPrimitiveType.fromApiTypeName(osmtype); 103 OsmPrimitiveType t = OsmPrimitiveType.NODE; 104 if (qName.equals("trustway")) t = OsmPrimitiveType.WAY; 105 else if (qName.equals("trustrelation")) t = OsmPrimitiveType.RELATION; 107 106 108 107 // search corresponding OsmPrimitive … … 116 115 missingData.add(osm); 117 116 } 118 trust = new TrustOSMItem(osm); 119 } else if (qName.equals("key")) { 120 if (atts == null) { 121 throwException(tr("Missing mandatory attribute ''{0}'' of XML element {1}.", "k", "key")); 122 } 123 String key = atts.getValue("k"); 124 if (key == null || key.equals("")){ 125 throwException(tr("Missing mandatory attribute ''{0}''.", "k")); 126 } 117 trust = TrustOsmPrimitive.createTrustOsmPrimitive(osm); 118 119 } else if (qName.equals("key") || qName.equals("node") || qName.equals("segment") || qName.equals("member")) { 127 120 tsigs = new TrustSignatures(); 128 keySig.put(key, tsigs);129 } else if (qName.equals("node")) {130 if (atts == null) {131 throwException(tr("Missing mandatory attribute ''{0}'' of XML element {1}.", "id", "node"));132 }133 String key = atts.getValue("id");134 if (key == null || key.equals("")){135 throwException(tr("Missing mandatory attribute ''{0}''.", "id"));136 }137 tsigs = new TrustSignatures();138 nodeSig.put(key, tsigs);139 121 } else if (qName.equals("openpgp")) { 140 122 tmpbuf = new StringBuffer(); … … 146 128 147 129 @Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException { 148 if (qName.equals("trustitem")) { 149 trust.storeAllTagSigs(keySig); 150 //trust.storeAllNodeSigs; 151 trustitems.put(String.valueOf(trust.getOsmItem().getUniqueId()), trust); 130 if (qName.equals("trustnode") || qName.equals("trustway") || qName.equals("trustrelation")) { 131 trustitems.put(TrustOsmPrimitive.createUniqueObjectIdentifier(trust.getOsmPrimitive()), trust); 152 132 } else if (qName.equals("openpgp")) { 153 133 // System.out.println(tmpbuf.toString()); … … 157 137 throw new OsmDataParsingException(tr("Could not parse OpenPGP message."),e).rememberLocation(locator); 158 138 } 139 } else if (qName.equals("key")) { 140 String[] kv = TrustOsmPrimitive.generateTagsFromSigtext(tsigs.getOnePlainText()); 141 trust.setTagRatings(kv[0], tsigs); 142 } else if (qName.equals("node")) { 143 ((TrustNode)trust).setNodeRatings(tsigs); 144 } else if (qName.equals("segment")) { 145 List<Node> nodes = TrustWay.generateSegmentFromSigtext(tsigs.getOnePlainText()); 146 ((TrustWay)trust).setSegmentRatings(nodes,tsigs); 147 } else if (qName.equals("member")) { 148 RelationMember member = TrustRelation.generateRelationMemberFromSigtext(tsigs.getOnePlainText()); 149 ((TrustRelation)trust).setMemberRating(TrustOsmPrimitive.createUniqueObjectIdentifier(member.getMember()), tsigs); 159 150 } 160 151 } … … 165 156 166 157 public void parseOpenPGP(String clearsigned) throws IOException { 167 System.out.println("Clearsignedtext vorher:\n"+clearsigned);168 158 169 159 // handle different newline characters and match them all to \n … … 188 178 plain = plain.substring(0, plain.length()-1); 189 179 190 System.out.println("Plaintext:\n"+plain+"--------- hier is zu ende");191 180 PGPSignatureList siglist = (PGPSignatureList)pgpFact.nextObject(); 192 181 for (int i=0; i<siglist.size();i++) { … … 211 200 * @throws IllegalArgumentException thrown if source is null 212 201 */ 213 public static Map<String,TrustO SMItem> parseSignatureXML(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException {202 public static Map<String,TrustOsmPrimitive> parseSignatureXML(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException { 214 203 if (progressMonitor == null) { 215 204 progressMonitor = NullProgressMonitor.INSTANCE; -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigWriter.java
r24389 r25269 7 7 import java.io.UnsupportedEncodingException; 8 8 import java.util.Collection; 9 import java.util.List; 9 10 import java.util.Map; 11 import java.util.Set; 10 12 11 13 import org.openstreetmap.josm.data.osm.Node; 12 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 15 import org.openstreetmap.josm.io.XmlWriter; 14 import org.openstreetmap.josm.plugins.trustosm.data.TrustOSMItem; 16 import org.openstreetmap.josm.plugins.trustosm.data.TrustNode; 17 import org.openstreetmap.josm.plugins.trustosm.data.TrustOsmPrimitive; 18 import org.openstreetmap.josm.plugins.trustosm.data.TrustRelation; 15 19 import org.openstreetmap.josm.plugins.trustosm.data.TrustSignatures; 20 import org.openstreetmap.josm.plugins.trustosm.data.TrustWay; 16 21 17 22 public class SigWriter extends XmlWriter { … … 27 32 } 28 33 29 public void write(Collection<TrustO SMItem> items) {34 public void write(Collection<TrustOsmPrimitive> items) { 30 35 writeHeader(); 31 36 indent = " "; … … 37 42 private void writeDTD() { 38 43 out.println("<!DOCTYPE trustXML ["); 39 out.println(" <!ELEMENT trustcollection (trustitem)*>"); 40 out.println(" <!ATTLIST trustcollection version CDATA #IMPLIED creator CDATA #IMPLIED >"); 41 out.println(" <!ELEMENT trustitem (signatures)*>"); 42 out.println(" <!ATTLIST trustitem osmid CDATA #REQUIRED type CDATA #REQUIRED >"); 43 out.println(" <!ELEMENT signatures (tags|geometry)*>"); 44 out.println(" <!ELEMENT tags (key)*>"); 45 out.println(" <!ELEMENT key (openpgp)*>"); 46 out.println(" <!ATTLIST key k CDATA #REQUIRED >"); 47 out.println(" <!ELEMENT geometry (node)*>"); 48 out.println(" <!ELEMENT node (openpgp)*>"); 49 out.println(" <!ATTLIST node id CDATA #REQUIRED >"); 44 out.println(" <!ELEMENT trustXML (trustnode|trustway|trustrelation)*>"); 45 out.println(" <!ATTLIST trustXML version CDATA #IMPLIED creator CDATA #IMPLIED >"); 46 out.println(" <!ELEMENT trustnode (tags?,node?)>"); 47 out.println(" <!ELEMENT trustway (tags?,segmentlist?)>"); 48 out.println(" <!ELEMENT trustrelation (tags?,memberlist?)>"); 49 out.println(" <!ATTLIST trustnode osmid CDATA #IMPLIED >"); 50 out.println(" <!ATTLIST trustway osmid CDATA #IMPLIED >"); 51 out.println(" <!ATTLIST trustrelation osmid CDATA #IMPLIED >"); 52 out.println(" <!ELEMENT tags (key)+>"); 53 out.println(" <!ELEMENT key (openpgp)+>"); 54 out.println(" <!ATTLIST key k CDATA #IMPLIED >"); 55 out.println(" <!ELEMENT node (openpgp)>"); 56 // out.println(" <!ATTLIST node id CDATA #REQUIRED >"); 57 out.println(" <!ELEMENT segmentlist (segment)*>"); 58 out.println(" <!ELEMENT segment (openpgp)+>"); 59 out.println(" <!ELEMENT memberlist (member)*>"); 60 out.println(" <!ELEMENT member (openpgp)+>"); 50 61 out.println(" <!ELEMENT openpgp (#PCDATA)*>"); 51 62 out.println("]>"); … … 55 66 out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); 56 67 writeDTD(); 57 out.println("<trust collectionversion=\"0.1\" creator=\"JOSM Signature export\">");68 out.println("<trustXML version=\"0.1\" creator=\"JOSM Signature export\">"); 58 69 } 59 70 60 71 private void writeFooter() { 61 out.println("</trust collection>");72 out.println("</trustXML>"); 62 73 } 63 74 … … 69 80 } 70 81 71 private void writeItems(Collection<TrustOSMItem> items) { 72 Map<String, TrustSignatures> tagsigs; 73 Map<Node, TrustSignatures> nodesigs; 74 75 for (TrustOSMItem item : items){ 76 OsmPrimitive osm = item.getOsmItem(); 77 78 openAtt("trustitem", "osmid=\""+String.valueOf(osm.getUniqueId())+"\" type=\""+osm.getType().getAPIName()+"\""); 79 openln("signatures"); 80 81 tagsigs = item.getTagSigs(); 82 openln("tags"); 83 for (String key : tagsigs.keySet()) { 84 openAtt("key","k=\""+key+"\""); 85 86 writeSigs(tagsigs.get(key)); 87 88 closeln("key"); 82 private void writeTags(TrustOsmPrimitive trust) { 83 Map<String, TrustSignatures> tagsigs = trust.getTagSigs(); 84 Set<String> signedKeys = tagsigs.keySet(); 85 if (signedKeys.isEmpty()) return; 86 openln("tags"); 87 for (String key : signedKeys) { 88 openAtt("key","k=\""+key+"\""); 89 90 writeSigs(tagsigs.get(key)); 91 92 closeln("key"); 93 } 94 closeln("tags"); 95 } 96 97 private void writeNode(TrustNode tn) { 98 TrustSignatures tsigs = tn.getNodeSigs(); 99 if (tsigs == null) return; 100 openln("node"); 101 writeSigs(tsigs); 102 closeln("node"); 103 } 104 105 private void writeSegments(TrustWay tw) { 106 Map<List<Node>, TrustSignatures> segmentSig = tw.getSegmentSigs(); 107 Set<List<Node>> signedSegments = segmentSig.keySet(); 108 if (signedSegments.isEmpty()) return; 109 openln("segmentlist"); 110 for (List<Node> segment : signedSegments) { 111 openln("segment"); 112 writeSigs(segmentSig.get(segment)); 113 closeln("segment"); 114 } 115 closeln("segmentlist"); 116 } 117 118 private void writeMembers(TrustRelation tr) { 119 Map<String, TrustSignatures> memberSig = tr.getMemberSigs(); 120 Set<String> signedMembers = memberSig.keySet(); 121 if (signedMembers.isEmpty()) return; 122 openln("memberlist"); 123 for (String member : signedMembers) { 124 openln("member"); 125 writeSigs(memberSig.get(member)); 126 closeln("member"); 127 } 128 closeln("memberlist"); 129 } 130 131 private void writeItems(Collection<TrustOsmPrimitive> items) { 132 133 for (TrustOsmPrimitive trust : items){ 134 OsmPrimitive osm = trust.getOsmPrimitive(); 135 if (trust instanceof TrustNode) { 136 TrustNode tn = (TrustNode) trust; 137 openAtt("trustnode", "osmid=\""+String.valueOf(osm.getUniqueId())+"\""); 138 writeTags(tn); 139 writeNode(tn); 140 closeln("trustnode"); 141 } else if (trust instanceof TrustWay) { 142 TrustWay tw = (TrustWay) trust; 143 openAtt("trustway", "osmid=\""+String.valueOf(osm.getUniqueId())+"\""); 144 writeTags(tw); 145 writeSegments(tw); 146 closeln("trustway"); 147 } else if (trust instanceof TrustRelation) { 148 TrustRelation tr = (TrustRelation) trust; 149 openAtt("trustrelation", "osmid=\""+String.valueOf(osm.getUniqueId())+"\""); 150 writeTags(tr); 151 writeMembers(tr); 152 closeln("trustrelation"); 89 153 } 90 closeln("tags"); 91 92 nodesigs = item.getGeomSigs(); 93 openln("geometry"); 94 for (Node node : nodesigs.keySet()) { 95 openAtt("node","id=\""+String.valueOf(node.getUniqueId())+"\""); 96 97 writeSigs(nodesigs.get(node)); 98 99 closeln("node"); 100 } 101 closeln("geometry"); 102 closeln("signatures"); 103 closeln("trustitem"); 154 155 // openAtt("trustitem", "osmid=\""+String.valueOf(osm.getUniqueId())+"\" type=\""+osm.getType().getAPIName()+"\""); 156 104 157 } 105 158 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/TrustGPG.java
r24389 r25269 5 5 import java.awt.Component; 6 6 import java.awt.Dimension; 7 import java.awt.GridBagLayout; 7 8 import java.awt.event.ActionEvent; 8 9 import java.awt.event.ActionListener; … … 20 21 import java.security.SecureRandom; 21 22 import java.security.Security; 23 import java.text.NumberFormat; 22 24 import java.text.SimpleDateFormat; 23 25 import java.util.ArrayList; 24 26 import java.util.Date; 25 import java.util.HashMap;26 27 import java.util.Iterator; 27 import java.util. Map;28 import java.util.List; 28 29 import java.util.Random; 29 30 import java.util.Vector; 31 import java.util.regex.Matcher; 32 import java.util.regex.Pattern; 30 33 31 34 import javax.swing.Box; … … 36 39 import javax.swing.JComponent; 37 40 import javax.swing.JDialog; 41 import javax.swing.JFormattedTextField; 38 42 import javax.swing.JLabel; 39 43 import javax.swing.JOptionPane; … … 43 47 import javax.swing.SpringLayout; 44 48 45 import org.bouncycastle.bcpg.ArmoredOutputStream; 46 import org.bouncycastle.bcpg.BCPGOutputStream; 49 import org.bouncycastle.bcpg.sig.NotationData; 47 50 import org.bouncycastle.jce.provider.BouncyCastleProvider; 48 51 import org.bouncycastle.openpgp.PGPEncryptedData; … … 64 67 import org.bouncycastle.util.encoders.Hex; 65 68 import org.openstreetmap.josm.Main; 66 import org.openstreetmap.josm.data.coor.CoordinateFormat;67 import org.openstreetmap.josm.data.coor.LatLon;68 69 import org.openstreetmap.josm.data.osm.Node; 69 70 import org.openstreetmap.josm.data.osm.OsmPrimitive; 70 import org.openstreetmap.josm.data.osm.Relation;71 71 import org.openstreetmap.josm.data.osm.Way; 72 import org.openstreetmap.josm.plugins.trustosm.data.TrustOSMItem; 73 import org.openstreetmap.josm.plugins.trustosm.data.TrustSignatures; 72 import org.openstreetmap.josm.plugins.trustosm.data.TrustNode; 73 import org.openstreetmap.josm.plugins.trustosm.data.TrustOsmPrimitive; 74 import org.openstreetmap.josm.plugins.trustosm.data.TrustWay; 75 import org.openstreetmap.josm.tools.GBC; 74 76 import org.openstreetmap.josm.tools.ImageProvider; 75 76 import tools.NameGenerator;77 import tools.SpringUtilities;78 77 79 78 import com.toedter.calendar.JDateChooser; … … 88 87 private static int digest = PGPUtil.SHA1; 89 88 private PGPSecretKey pgpSecKey; 90 public boolean keepkey = true; 89 public boolean keepkey = false; 90 91 public static final String NOTATION_DATA_KEY = "trustosm@openstreetmap.org"; 91 92 92 93 public TrustGPG() { … … 130 131 private void readSecretKey() { 131 132 133 // if there is no KeyRingCollection we have to create a new one 134 if (pgpSec == null) { 135 try { 136 generateKey(); 137 } catch (Exception e) { 138 System.err.println("GPG Key Ring File could not be created in: "+Main.pref.getPluginsDirectory().getPath() + "/trustosm/gnupg/secring.gpg"); 139 } 140 } 132 141 // 133 142 // we just loop through the collection till we find a key suitable for encryption, in the real 134 143 // world you would probably want to be a bit smarter about this. 135 144 // 136 if (keepkey && pgpSecKey != null) return;145 if (keepkey) return; 137 146 138 147 final ArrayList<PGPSecretKey> sigKeys = new ArrayList<PGPSecretKey>(); … … 243 252 pgpSecKey = sigKeys.get(keyBox.getSelectedIndex()); 244 253 } 254 } else { 255 pgpSecKey = null; 245 256 } 246 257 //String selection = (String) JOptionPane.showInputDialog(null, tr("Select a Key to sign"),tr("Secret Key Choice"), JOptionPane.OK_CANCEL_OPTION, null, keys, keys[0]); … … 263 274 } catch (FileNotFoundException e) { 264 275 System.err.println("No gpg files found in "+Main.pref.getPluginsDirectory().getPath() + "/trustosm/gnupg/secring.gpg"); 265 System.err.println("Creating new...");266 276 pgpSec = null; 267 277 pgpPub = null; 268 generateKey();269 278 } 270 279 … … 282 291 } 283 292 284 public static String[] generateTagsFromSigtext(String sigtext) { 285 String[] keyValue = sigtext.substring(sigtext.indexOf('\n')).split("="); 286 return keyValue; 287 } 288 289 public static String generateTagSigtext(OsmPrimitive osm, String key) { 290 String sigtext = "ID=" + osm.getUniqueId() + "\n"; 291 sigtext += key + "=" + osm.get(key); 292 return sigtext; 293 } 294 295 public static String generateNodeSigtext(OsmPrimitive osm, Node node) { 296 LatLon point = node.getCoor(); 297 String sigtext = "ID=" + osm.getUniqueId() + "\n"; 298 sigtext += "Lat:" + point.latToString(CoordinateFormat.DECIMAL_DEGREES) + "\n"; 299 sigtext += "Lon:" + point.lonToString(CoordinateFormat.DECIMAL_DEGREES); 300 return sigtext; 301 } 293 302 294 303 295 public void getPasswordfromUser() { … … 325 317 */ 326 318 } 327 328 public void checkTag(TrustO SMItemtrust, String key) {329 String sigtext = generateTagSigtext(trust.getOsmItem(),key);319 /* 320 public void checkTag(TrustOsmPrimitive trust, String key) { 321 String sigtext = TrustOsmPrimitive.generateTagSigtext(trust.getOsmPrimitive(),key); 330 322 TrustSignatures sigs; 331 323 if ((sigs = trust.getSigsOnKey(key))!=null) … … 335 327 } 336 328 337 public void checkNode(TrustOSMItem trust, Node node) { 338 String sigtext = generateNodeSigtext(trust.getOsmItem(),node); 339 TrustSignatures sigs; 340 if ((sigs = trust.getSigsOnNode(node))!=null) 341 for (PGPSignature sig : sigs.getSignatures()) { 342 trust.updateNodeSigStatus(node, verify(sigtext,sig)? TrustSignatures.SIG_VALID : TrustSignatures.SIG_BROKEN); 343 } 344 } 345 346 public void checkAll(TrustOSMItem trust) { 347 OsmPrimitive osm = trust.getOsmItem(); 329 330 331 /* public void checkAll(TrustOsmPrimitive trust) { 332 OsmPrimitive osm = trust.getOsmPrimitive(); 348 333 for (String key : osm.keySet()) { 349 334 checkTag(trust, key); … … 351 336 352 337 if(osm instanceof Node) { 353 checkNode( trust, (Node)osm);338 checkNode((TrustNode) trust); 354 339 } else if(osm instanceof Way) { 355 Iterator<Node> iter = ((Way)osm).getNodes().iterator();340 /* Iterator<Node> iter = ((Way)osm).getNodes().iterator(); 356 341 while (iter.hasNext()) { 357 342 checkNode(trust, iter.next()); 358 } 343 }/ 359 344 } else if(osm instanceof Relation) { 360 345 361 346 } 362 347 } 348 */ 363 349 364 350 public void invalidIDWarning(OsmPrimitive osm) { 365 351 JOptionPane.showMessageDialog(Main.parent, tr("The object with the ID \"{0}\" ({1}) is newly created.\nYou can not sign it, because the signature would lose the ID-Reference after uploading it to the OSM-server.",osm.getUniqueId(),osm.toString()), tr("Signing canceled!"), JOptionPane.ERROR_MESSAGE); 366 352 } 367 368 public TrustOSMItem signGeometry(TrustOSMItem trust) { 353 /* 354 public TrustOsmPrimitive signGeometry(TrustOsmPrimitive trust) { 355 PGPSignatureSubpacketGenerator spGen = chooseAccuracy(); 369 356 PGPSignature s; 370 357 Node node; 371 OsmPrimitive osm = trust.getOsm Item();358 OsmPrimitive osm = trust.getOsmPrimitive(); 372 359 if (osm.isNew()) { 373 360 invalidIDWarning(osm); … … 375 362 } 376 363 if(osm instanceof Node) { 377 s = signNode(osm,(Node)osm );378 if (s != null) trust.storeNodeSig((Node)osm,s);364 s = signNode(osm,(Node)osm, spGen); 365 if (s != null) ((TrustNode)trust).storeNodeSig(s); 379 366 } else if(osm instanceof Way) { 380 367 Iterator<Node> iter = ((Way)osm).getNodes().iterator(); 381 368 while (iter.hasNext()) { 382 369 node = iter.next(); 383 s = signNode(osm,node );384 if (s != null) trust.storeNodeSig(node,s);370 s = signNode(osm,node,spGen); 371 if (s != null) ((TrustNode)trust).storeNodeSig(s); 385 372 } 386 373 } else if(osm instanceof Relation) { … … 388 375 } 389 376 return trust; 390 } 391 392 public PGPSignature signNode(OsmPrimitive osm, Node node) { 377 }*/ 378 379 public TrustWay signWay(TrustWay trust) { 380 PGPSignature s; 381 Way w = (Way) trust.getOsmPrimitive(); 382 if (w.isNew()) { 383 invalidIDWarning(w); 384 return trust; 385 } 386 /* 387 List<Node> nodes = w.getNodes(); 388 s = signSegment(trust,nodes); 389 if (s != null) trust.storeSegmentSig(nodes,s); 390 */ 391 List<Node> wayNodes = w.getNodes(); 392 for (int i=0; i<wayNodes.size()-1; i++) { 393 List<Node> nodes = new ArrayList<Node>(); 394 nodes.add(wayNodes.get(i)); 395 nodes.add(wayNodes.get(i+1)); 396 s = signSegment(trust,nodes); 397 if (s != null) trust.storeSegmentSig(nodes,s); 398 } 399 400 return trust; 401 } 402 403 public PGPSignature signSegment(TrustWay trust, List<Node> nodes) { 404 Way w = (Way) trust.getOsmPrimitive(); 405 if (w.isNew()) { 406 invalidIDWarning(w); 407 return null; 408 } 409 String tosign = TrustWay.generateSegmentSigtext(trust,nodes); 410 PGPSignatureSubpacketGenerator spGen = chooseAccuracy(); 411 return sign(tosign,spGen); 412 } 413 414 public PGPSignature signNode(Node node) { 415 PGPSignatureSubpacketGenerator spGen = chooseAccuracy(); 416 return signNode(node,spGen); 417 } 418 419 public PGPSignature signNode(Node node, PGPSignatureSubpacketGenerator spGen) { 420 if (node.isNew()) { 421 invalidIDWarning(node); 422 return null; 423 } 424 String tosign = TrustNode.generateNodeSigtext(node); 425 return sign(tosign,spGen); 426 } 427 428 public boolean signTag(TrustOsmPrimitive trust, String key) { 429 OsmPrimitive osm = trust.getOsmPrimitive(); 393 430 if (osm.isNew()) { 394 431 invalidIDWarning(osm); 395 return null; 396 } 397 String tosign = generateNodeSigtext(osm,node); 398 return sign(tosign); 399 } 400 401 public TrustOSMItem signTag(TrustOSMItem trust, String key) { 402 OsmPrimitive osm = trust.getOsmItem(); 403 if (osm.isNew()) { 404 invalidIDWarning(osm); 405 return trust; 432 return false; 406 433 } 407 434 PGPSignature s; 408 String tosign = generateTagSigtext(osm,key); 409 s = sign(tosign); 410 if (s != null) 435 String tosign = TrustOsmPrimitive.generateTagSigtext(osm,key); 436 //s = sign(tosign); 437 s = sign(tosign,chooseInformationSource()); 438 if (s != null) { 411 439 trust.storeTagSig(key, s); 412 return trust; 440 return true; 441 } 442 return false; 443 } 444 445 /** 446 * Search in a given Signature for Tolerance information. 447 * @param sig 448 * @return found tolerance as double or 0 if no Tolerance is given 449 */ 450 451 public static double searchTolerance(PGPSignature sig) { 452 /** Take the first NotationData packet that seems to have Tolerance information */ 453 for (NotationData nd : sig.getHashedSubPackets().getNotationDataOccurences()){ 454 if (nd.getNotationName().equals(TrustGPG.NOTATION_DATA_KEY)) { 455 String notation = nd.getNotationValue(); 456 Pattern p = Pattern.compile("^Tolerance:(\\d*\\.?\\d*)m"); 457 Matcher m = p.matcher(notation); 458 if (m.matches()) { // we found a valid Tolerance 459 return Double.parseDouble(m.group(1)); 460 } 461 } 462 } 463 return 0; 464 } 465 466 public PGPSignatureSubpacketGenerator chooseAccuracy() { 467 PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); 468 JPanel p = new JPanel(new GridBagLayout()); 469 p.add(new JLabel(tr("Please give a tolerance in meters")),GBC.eol()); 470 471 JFormattedTextField meters = new JFormattedTextField(NumberFormat.getNumberInstance()); 472 meters.setValue(new Double(10)); 473 meters.setColumns(5); 474 475 p.add(meters,GBC.std()); 476 p.add(new JLabel(tr("meters")),GBC.eol()); 477 478 int n = JOptionPane.showOptionDialog(Main.parent, p, tr("Accuracy"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 479 480 if (n == JOptionPane.OK_OPTION) { 481 spGen.setNotationData(false, true, TrustGPG.NOTATION_DATA_KEY, "Tolerance:"+meters.getValue()+"m"); 482 return spGen; 483 } 484 return null; 485 } 486 487 public PGPSignatureSubpacketGenerator chooseInformationSource() { 488 PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); 489 JPanel p = new JPanel(new GridBagLayout()); 490 p.add(new JLabel(tr("Select as much as you like:")),GBC.eol()); 491 492 JCheckBox survey = new JCheckBox(tr("Survey")); 493 p.add(survey,GBC.eol()); 494 495 JCheckBox aerial = new JCheckBox(tr("Aerial Photography")); 496 p.add(aerial,GBC.eol()); 497 498 JCheckBox web = new JCheckBox(tr("Web Recherche")); 499 p.add(web,GBC.eol()); 500 501 JCheckBox trusted = new JCheckBox(tr("Trusted persons told me")); 502 p.add(trusted,GBC.eol()); 503 504 int n = JOptionPane.showOptionDialog(Main.parent, p, tr("Which source did you use?"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 505 506 if (n == JOptionPane.OK_OPTION) { 507 String sources = "Sources:"; 508 if (survey.isSelected()) sources += ":survey"; 509 if (aerial.isSelected()) sources += ":aerial"; 510 if (web.isSelected()) sources += ":web"; 511 if (trusted.isSelected()) sources += ":trusted"; 512 spGen.setNotationData(false, true, TrustGPG.NOTATION_DATA_KEY, sources); 513 return spGen; 514 } 515 return null; 413 516 } 414 517 415 518 public PGPSignature sign(String tosign) { 416 519 PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); 520 return sign(tosign,spGen); 521 } 522 523 public PGPSignature sign(String tosign, PGPSignatureSubpacketGenerator spGen) { 524 525 if (spGen == null) return null; 417 526 PGPSignature sig; 418 527 try{ … … 428 537 PGPSignatureGenerator sGen = new PGPSignatureGenerator(pgpSecKey.getPublicKey().getAlgorithm(), digest, "BC"); 429 538 sGen.initSign(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey); 539 430 540 Iterator it = pgpSecKey.getPublicKey().getUserIDs(); 431 if (it.hasNext()) 432 { 433 PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); 434 541 if (it.hasNext()) { 435 542 spGen.setSignerUserID(false, (String)it.next()); 436 sGen.setHashedSubpackets(spGen.generate());437 }543 } 544 sGen.setHashedSubpackets(spGen.generate()); 438 545 sGen.update(tosign.getBytes(Charset.forName("UTF-8"))); 439 546 sig = sGen.generate(); 547 //System.out.println(new String(sGen.generateOnePassVersion(false).getEncoded(),Charset.forName("UTF-8"))); 440 548 //writeSignatureToFile(sig, tosign, new FileOutputStream("/tmp/sigtest.asc")); 441 549 //sig.encode(new BCPGOutputStream(new ArmoredOutputStream(new FileOutputStream("/tmp/sigtest.asc")))); 442 550 return sig; 443 551 }catch (Exception e){//Catch exception if any 444 System.err.println(" Error: " + e.getMessage());552 System.err.println("PGP Signing Error: " + e.getMessage()); 445 553 } 446 554 … … 471 579 return sig.verify(); 472 580 }catch (Exception e){//Catch exception if any 473 System.err.println(" Error: " + e.getMessage());581 System.err.println("PGP Verification Error: " + e.getMessage()); 474 582 } 475 583 return false; … … 477 585 478 586 479 public static void writeSignatureToFile(PGPSignature sig, String clearText, FileOutputStream fout) throws Exception {480 ArmoredOutputStream aOut = new ArmoredOutputStream(fout);481 aOut.beginClearText(digest);482 aOut.write(clearText.getBytes(Charset.forName("UTF-8")));483 aOut.write('\n');484 aOut.endClearText();485 486 BCPGOutputStream bOut = new BCPGOutputStream(aOut);487 sig.encode(bOut);488 aOut.close();489 bOut.close();490 }491 492 public Map<String, String> getKeyValueFromSignature(PGPSignature sig) {493 Map<String, String> tags = new HashMap<String, String>();494 try {495 String sigtext = new String(sig.getEncoded(), Charset.forName("UTF-8"));496 String[] kv =generateTagsFromSigtext(sigtext);497 tags.put(kv[0],kv[1]);498 } catch (IOException e) {499 // TODO Auto-generated catch block500 e.printStackTrace();501 }502 return tags;503 }587 // public static void writeSignatureToFile(PGPSignature sig, String clearText, FileOutputStream fout) throws Exception { 588 // ArmoredOutputStream aOut = new ArmoredOutputStream(fout); 589 // aOut.beginClearText(digest); 590 // aOut.write(clearText.getBytes(Charset.forName("UTF-8"))); 591 // aOut.write('\n'); 592 // aOut.endClearText(); 593 // 594 // BCPGOutputStream bOut = new BCPGOutputStream(aOut); 595 // sig.encode(bOut); 596 // aOut.close(); 597 // bOut.close(); 598 // } 599 // 600 // public Map<String, String> getKeyValueFromSignature(PGPSignature sig) { 601 // Map<String, String> tags = new HashMap<String, String>(); 602 // try { 603 // String sigtext = new String(sig.getEncoded(), Charset.forName("UTF-8")); 604 // String[] kv = TrustOsmPrimitive.generateTagsFromSigtext(sigtext); 605 // tags.put(kv[0],kv[1]); 606 // } catch (IOException e) { 607 // // TODO Auto-generated catch block 608 // e.printStackTrace(); 609 // } 610 // return tags; 611 // } 504 612 505 613 public static void showKeyDetails(PGPPublicKey key) { … … 738 846 739 847 740 //writeGpgFiles();848 writeGpgFiles(); 741 849 742 850 return secRing.getSecretKey();
Note:
See TracChangeset
for help on using the changeset viewer.