예제 #1
0
 public static Calendar getUpdateDate(Calendar serverDate, Calendar localDate) {
   String lDate = Util.getGeneralizedTime();
   Calendar newLocalDate = Util.getCalendar(lDate);
   long timeMil = 0;
   if (serverDate.compareTo(localDate) == 1)
     timeMil = serverDate.getTimeInMillis() - localDate.getTimeInMillis();
   if (DEBUG) System.out.println("Time def btw server and client: " + timeMil);
   return Util.incCalendar(newLocalDate, (int) timeMil);
 }
예제 #2
0
 private void init(ArrayList<Object> d, D_DirectoryEntry _parent) {
   parent = _parent;
   this.registered_ID = Util.lval(d.get(table.registered.REG_ID));
   // this.addresses =
   // TypedAddress.parseStringAddresses(Util.getString(d.get(table.registered.REG_ADDR)));
   this.addresses = Address.getAddresses(Util.getString(d.get(table.registered.REG_ADDR)));
   this.certificate =
       Util.byteSignatureFromString(Util.getString(d.get(table.registered.REG_CERT)));
   this.globalID = Util.getString(d.get(table.registered.REG_GID));
   this.globalIDhash = Util.getString(d.get(table.registered.REG_GID_HASH));
   this.instance = Util.getString(d.get(table.registered.REG_INSTANCE));
   this.signature =
       Util.byteSignatureFromString(Util.getString(d.get(table.registered.REG_SIGN)));
   this.timestamp = Util.getCalendar(Util.getString(d.get(table.registered.REG_TIME)));
   if (timestamp == null) timestamp = Util.CalendargetInstance();
 }
예제 #3
0
	private void handleChoiceEvent(Object source) {
		//boolean DEBUG = true;
		if(DEBUG) out.println("JustificationEditor:handleFieldEvent: start");
		/*
		String creationTime;
		if(vote_date_field != null) {
			creationTime = vote_date_field.getText();
		}else{
			creationTime = Util.getGeneralizedTime();
		}
		*/
		if((this.vote_date_field==source)||(this.vote_date_field.getDocument()==source)) {
			if(DEBUG) out.println("JustificationEditor:handleFieldEvent: date title");
			String new_text = this.vote_date_field.getText();
			Calendar cal = Util.getCalendar(new_text);
			if(cal == null) return;
			this.signature.creation_date = cal;
			this.signature.setEditable();
			try {
				this.signature.storeVerified();
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}
			return;			
		}
		if(this.vote_dategen_field==source) {
			this.signature.creation_date = Util.CalendargetInstance();
			this.vote_date_field.setText(Encoder.getGeneralizedTime(this.signature.creation_date));
			this.signature.setEditable();
			try {
				this.signature.storeVerified();
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}
			return;			
		}
		if(this.vote_newjust_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice newjust_radio");
			this.just_old_just_field.setEnabled(false);
			//setChoiceOldJustification(creationTime);
			//enable_just();
			if(motionEditor!=null){
				if(_DEBUG) out.println("VoteEditor:handleFieldEvent: choice newjust_radio, in motioneditor");
				motionEditor.enableNewJustification(true);
				signature.justification_ID = motionEditor.getNewJustificationID();
				signature.global_justification_ID = null;
			}else{
				if(_DEBUG) out.println("VoteEditor:handleFieldEvent: choice newjust_radio, in justeditor");
				this.justificationEditor.make_new();
				this.enable_just();
				signature.justification_ID = justification.justification_ID;
				signature.global_justification_ID = null;
			}
			return;
		}
		if(this.vote_oldjust_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice oldjust_radio");
			this.just_old_just_field.setEnabled(true);
			setChoiceOldJustification();
			if(motionEditor!=null){
				motionEditor.enableNewJustification(false);
			}else{
				this.disable_just();
			}
			return;
		}
		if(this.vote_nojust_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice nojust_radio");
			this.just_old_just_field.setEnabled(false);
			if(motionEditor!=null){
				motionEditor.enableNewJustification(false);
			}else{
				this.disable_just();
			}
			try{
				signature.justification_ID = null;
				signature.global_justification_ID = null;
				//this.signature.creation_date = Util.getCalendar(creationTime);
				this.signature.setEditable();
				this.signature.storeVerified();
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}	
		}
		if(just_old_just_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice old_just_combo");
			//if(DEBUG) Util.printCallPath("Linux tracing");
			setChoiceOldJustification();
			return;
		}
		if(this.vote_choice_field == source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice vote_choice_field combo");
			setChoice();
			return;
		}
		if((just_submit_field == source)) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: submit");
			try {
				long j_id=-1;
				D_Justification justification =null;
				if(signature.choice==null){
					Application.warning(_("No voting choice made.\nPlease return and make a voting choice."), _("No Choice Made"));
					return;
				}
				if(vote_newjust_field.isSelected()) {
					if(DEBUG) out.println("VoteEditor:handleFieldEvent: new justification");
					justification = justificationEditor.just;
					if(motionEditor!=null){
						justification = motionEditor.getNewJustification();
						if(DEBUG) out.println("VoteEditor:handleFieldEvent: new justification from motionEditor="+justification);
					}else{
						if(DEBUG) out.println("VoteEditor:handleFieldEvent: new justification from justEditor="+justification);						
					}
					
					if(justification.global_constituent_ID==null){
						if(DEBUG) out.println("VoteEditor:handleFieldEvent: reget justification");
						justification.global_constituent_ID = Application.constituents.tree.getModel().getConstituentGIDMyself();
						justification.constituent_ID = Util.getStringID(Application.constituents.tree.getModel().getConstituentIDMyself());
						if(justification.global_constituent_ID==null) {
							Application.warning(_("You should first select a constituent identity for this organization!"), _("No Constituent ID for this org!"));
							return;
						}
					}

					
					justification.global_justificationID = justification.make_ID();
					justification.sign();
					j_id = justification.storeVerified(DEBUG);
					if(j_id<=0){
						if(_DEBUG) out.println("VoteEditor:handleFieldEvent: failed saving no new justif");
						return;					
					}
				}else{
					if(DEBUG) out.println("VoteEditor:handleFieldEvent: no new justification selected");
				}
				
				//signature = signature;
				//signature.global_motion_ID = null;
				//signature.motion_ID = justificationEditor.just.motion_ID;
				if(vote_newjust_field.isSelected()) {
					signature.global_justification_ID = justification.global_justificationID;
					signature.justification_ID = Util.getStringID(j_id);//justificationEditor.just.justification_ID;
				}
				signature.global_vote_ID = signature.make_ID();
				
				D_Vote old = new D_Vote(signature.global_vote_ID);
				if(old.vote_ID!=null){
					String old_date = Encoder.getGeneralizedTime(old.creation_date);
					String new_date = Encoder.getGeneralizedTime(signature.creation_date);
					if(old_date.equals(new_date)){
						int attack = Application.ask(
								_("Are you sure you want to create a new vote \n" +
								"with the same date as your previous vote? \n" +
								"This can amount to an attack where you give different people different votes!\n" +
								"Except if they order such votes by signature (to be implemented)\n" +
								"On selecting NO, we will update the creation date to now."),
								_("Votes from you on the same issue and with same date!"), JOptionPane.YES_NO_CANCEL_OPTION);
						switch(attack) {
						case 0: //YES
							break;
						case 1: // NO
							signature.creation_date = Util.CalendargetInstance();
							this.vote_date_field.setText(Encoder.getGeneralizedTime(this.signature.creation_date));
							break;
						case 2: // CANCEL
						default:
							return;
						}
					}
				}
				
				signature.sign();
				long v_id = this.signature.storeVerified();
				if(v_id<=0){
					if(_DEBUG) out.println("VoteEditor:handleFieldEvent: submit sign got no local ID");
					return;
				}
				
				/*
				justificationEditor.just.global_justificationID = justificationEditor.just.make_ID();
				justificationEditor.just.sign();
				long id = justificationEditor.just.storeVerified();
				if(id<=0) return;
				*/
				disable_it();
				justificationEditor.disable_it();
				try{
					D_Motion m = new D_Motion(Util.lval(signature.motion_ID));
					m.broadcasted = true;
					m.storeVerified();
				}catch(Exception e){e.printStackTrace();}
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}
		}
	}
예제 #4
0
  public static updates.VersionInfo getWSVersionInfo(
      URL url, String GID, SK myPeerSK, Hashtable<Object, Object> context) {
    if (DEBUG_) System.out.println("call getWSVersionInfo on URL " + url);
    int i = url.toString().indexOf("&");
    if (i == -1) {
      if (DEBUG_) System.out.println("URL " + url + " has no PK hash");
      return null;
    }
    String PK_hex = url.toString().substring(i + 1);
    try {
      url = new URL(url.toString().substring(0, i));
    } catch (MalformedURLException ex) {
      System.out.println("error in url: " + url);
      return null;
    }
    if (DEBUG_) System.out.println("pk= " + PK_hex + "  url= " + url);
    DdWS service = new DdWS(url);
    if (DEBUG_) if (service == null) System.out.println("service=null");

    // service.getHandlerResolver().getHandlerChain(service.getDdWSPort()).add(new Handler());
    DdWSPortType DDver = service.getDdWSPort();
    // System.out.println("part: "+ service);

    BindingProvider bindingProvider = ((BindingProvider) DDver);

    List<javax.xml.ws.handler.Handler> handlerChain =
        bindingProvider.getBinding().getHandlerChain();
    Handler handler = new Handler();
    handler.setPK_Hex(PK_hex);
    handlerChain.add(handler);
    bindingProvider.getBinding().setHandlerChain(handlerChain);

    if (DEBUG_) if (DDver == null) System.out.println("DDver=null");
    // build history object
    Map<String, Object> c = bindingProvider.getRequestContext();
    Object URLloc = c.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
    /* To change the location address
    *context.put(
      BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
      newAddress);
    */
    // System.out.println("loc: "+URLloc.toString());
    DateInfo d;
    if ((d = (DateInfo) context.get(url.toString())) == null) {
      if (ClientUpdates.DEBUG || DEBUG) System.out.println(" Context = null");
      d = new DateInfo();
    } else {
      if (ClientUpdates.DEBUG || DEBUG) System.out.println("localtime: " + d.LocalDate.getTime());
      if (ClientUpdates.DEBUG || DEBUG)
        System.out.println("Caltime: " + d.CalculatedDate.getTime());
      if (ClientUpdates.DEBUG || DEBUG)
        if (d.ServerDate != null) System.out.println("Servertime: " + d.ServerDate.getTime());
    }
    if (d.ServerDate != null) // server date set only with error
    d.CalculatedDate = getUpdateDate(d.ServerDate, d.LocalDate);
    d.ServerDate = null;
    String lDate = Util.getGeneralizedTime();
    d.LocalDate = Util.getCalendar(lDate);
    if (d.CalculatedDate == null) d.CalculatedDate = d.LocalDate;
    Request rq = new Request(GID, URLloc.toString(), d.CalculatedDate);
    String signature = Util.stringSignatureFromByte(rq.sign(myPeerSK));
    History h = new History();
    h.setGID(rq.peerGID);
    h.setUrl(rq.url);
    h.setDate(Encoder.getGeneralizedTime(rq.date)); // date as generalized for server side
    h.setSignature(signature);
    VersionInfo response = null;
    context.put(url.toString(), d);
    try {
      response = DDver.getVersionInfo(h);
    } catch (SOAPFaultException e) {
      if (DEBUG)
        System.err.println(
            "WSUpdate:HandleService:Code: "
                + e.getFault().getFaultCode()
                + ", Actor: "
                + e.getFault().getFaultActor()
                + ", String: "
                + e.getFault().getFaultString());
      if (e.getFault().getFaultActor().trim().equals("date")) {
        statusCode = INVALID_DATE;
        errorString = e.getFault().getFaultString();
        d = (DateInfo) context.get(url.toString());
        d.ServerDate = Util.getCalendar(errorString + ".000Z"); // Calendar.getInstance();
        context.remove(url.toString());
        context.put(url.toString(), d);
        // d.ServerDate.setTime(new Date(Long.parseLong(errorString)));
        if (DEBUG)
          System.out.println(
              "WSUpdate:HandleService:Server: "
                  + d.ServerDate.getTime()
                  + "  Client: "
                  + d.LocalDate.getTime());
      } else if (e.getFault().getFaultActor().trim().equals("url")) {
        statusCode = INVALID_URL;
        errorString = e.getFault().getFaultString();
      }
      return null;
    }
    statusCode = handler.isValidSignature();
    if (statusCode == INVALID_SIGNATURE) {
      return null;
    }
    updates.VersionInfo v = new updates.VersionInfo();
    v.version = response.getVersion();
    v.script = response.getScript();
    v.date = Util.getCalendar(response.getDate());
    // v.signature = Util.byteSignatureFromString(response.getSignature());
    v.data = new updates.Downloadable[response.getData().size()];
    Downloadable downloadable = null;
    for (i = 0; i < v.data.length; i++) {
      v.data[i] = new updates.Downloadable();
      downloadable = (Downloadable) response.getData().get(i);
      v.data[i].filename = downloadable.getFileName();
      v.data[i].url = downloadable.getUrl();
      v.data[i].digest = Util.byteSignatureFromString(downloadable.getDigest());
    }
    v.releaseQD = new data.D_ReleaseQuality[response.getQOTD().size()];
    TestDef testDef = null;
    for (i = 0; i < v.releaseQD.length; i++) {
      testDef = (TestDef) response.getQOTD().get(i);
      //	int index = testDef.getRef().intValue() - 1;
      int index = testDef.getRef().intValue();
      v.releaseQD[index] = new data.D_ReleaseQuality();

      v.releaseQD[index]._quality = new String[testDef.getQualityStructure().size()];
      for (int j = 0; j < v.releaseQD[index]._quality.length; j++) {
        v.releaseQD[index]._quality[j] = testDef.getQualityStructure().get(j);
      }
      v.releaseQD[index].description = testDef.getDesc();
    }

    v.testers_data = new data.D_SoftwareUpdatesReleaseInfoByTester[response.getTesters().size()];
    TesterInfo testerInfo = null;
    for (i = 0; i < v.testers_data.length; i++) {
      testerInfo = (TesterInfo) response.getTesters().get(i);
      v.testers_data[i] = new data.D_SoftwareUpdatesReleaseInfoByTester();
      v.testers_data[i].name = testerInfo.getName();
      v.testers_data[i].public_key_hash = testerInfo.getDigestPK();
      v.testers_data[i].tester_QoT =
          new float[response.getQOTD().size()]; // not all array elements are used
      v.testers_data[i].tester_RoT =
          new float[response.getQOTD().size()]; // not all array elements are used
      for (int j = 0; j < testerInfo.getTests().size(); j++) {
        // int index = ((Test)testerInfo.getTests().get(j)).getQualityRef().intValue() - 1;
        int index = ((Test) testerInfo.getTests().get(j)).getQualityRef().intValue();
        v.testers_data[i].tester_QoT[index] =
            ((Test) testerInfo.getTests().get(j)).getQoT().floatValue();
        v.testers_data[i].tester_RoT[index] =
            ((Test) testerInfo.getTests().get(j)).getRoT().floatValue();
      }
      v.testers_data[i].signature = Util.byteSignatureFromString(testerInfo.getSignature());
    }

    return v;
  }