예제 #1
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
  public void createUser(
      String login, String password, int backupNbr, Captcha captcha, String answer)
      throws Exception {
    LOG.info("creating user: "******", " + password + ", " + backupNbr + ", answer=" + answer);
    LOG.info("captcha=" + captcha);
    OCPUser user = new OCPUser(this, login, backupNbr);
    UserPublicInfo upi = user.getPublicInfo(this);

    ContactMap contactMap = ds().getComponent(ContactMap.class);
    Contact contact = contactMap.getContact(captcha.contactId);

    // 1) create the public part of the user.
    // catpcha is required in order to avoid massive fake user creation
    Data publicUserData = new Data(this, user, ds().serializer.serialize(upi));
    Link publicUserDataLink =
        new Link(user, this, UserPublicInfo.getKey(this, login), publicUserData.getKey(this));

    getClient().createUser(contact, publicUserData, publicUserDataLink, captcha, answer);

    // 2) create the private part of the user.
    // no need captcha because creation of object is checked by the user
    // public info
    Key key = new Key(hash(ucrypt(password, (login + password).getBytes())));
    byte[] content = ucrypt(password, ds().serializer.serialize(user));
    Content privateUserData = new Data(this, user, content);
    Link privateUserDataLink = new Link(user, this, key, privateUserData.getKey(this));

    setWithLink(user, privateUserData, privateUserDataLink);
  }
예제 #2
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
  public void readConfig() throws Exception {

    // debugging aspect
    if (ds().getProperty("debug", "false").equalsIgnoreCase("true")) {
      LOG.debug_on();
      LOG.info("working directory = " + System.getProperty("user.dir"));
    }

    Iterator<String> it = ds().iterator();
    while (it.hasNext()) {
      String key = it.next();
      String value = ds().getProperty(key);
      LOG.info(key + "=" + value);
    }
    name = ds().getProperty("name", "anonymous");

    // each agent has its own symmetric key cipher
    // TODO: test with other algo than AES
    KeyGenerator keyGen = KeyGenerator.getInstance(this.ds().getProperty("cypher.algo", "AES"));
    keyGen.init(Integer.parseInt(this.ds().getProperty("cipher.keysize", "128")));
    secretKey = keyGen.generateKey();
    cipher = Cipher.getInstance(this.ds().getProperty("cipher.algo", "AES"));

    // user cipher
    byte[] salt = {1, 1, 1, 2, 2, 2, 3, 3};
    int count = 20;
    userParamSpec = new PBEParameterSpec(salt, count);
  }
예제 #3
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
 public Captcha wantToCreateUser(String login, String password) throws Exception {
   // TODO check if user already exists ?
   LOG.info("want to create a user");
   Id key = hash(ucrypt(password, (login + password).getBytes()));
   LOG.info("key = " + key);
   Queue<Contact> contactQueue = makeContactQueue(key);
   LOG.info("contact queue established.");
   return getClient().askCaptcha(contactQueue);
 }
예제 #4
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
 public boolean isResponsible(Address address) throws Exception {
   LOG.info("address = " + address);
   Id nodeId = getNodeId(address);
   LOG.info("nodeId = " + nodeId);
   OCPContact contact = getContactFromNodeId(nodeId);
   LOG.info("contact = " + contact);
   LOG.info("is responsible: " + contact.getName().equals(id.toString()));
   return contact.getName().equals(id.toString());
   // return true;
 }
예제 #5
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
 public void addContact(Contact contact) throws Exception {
   LOG.info("adding contact: " + contact);
   ds().contactMap.add(contact);
   OCPContact c = (OCPContact) contact;
   if (c.nodeIdSet.size() == 0) {
     throw new Exception("contact without node.");
   }
   Iterator<Id> it = c.nodeIdSet.iterator();
   while (it.hasNext()) {
     Id id = it.next();
     LOG.info("adding node to nodeMap");
     nodeMap.put(id, c);
   }
 }
예제 #6
0
파일: HTTPListener.java 프로젝트: ccbon/ocp
 @Override
 public void stop() {
   LOG.info("stopping http server");
   if (usesComponent(NATTraversal.class)) {
     getComponent(NATTraversal.class).unmap();
   }
   httpServer.stop(t);
 }
예제 #7
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
  public void connect() throws Exception {

    String sId = ds().getProperty("id");
    if (sId == null) {
      id = generateId();
      ds().setProperty("id", id.toString());
    } else {
      id = new Id(sId);
    }
    LOG.info("agent id = " + id);

    try {
      backupNbr = (byte) Integer.parseInt(ds().network.getProperty("backupNbr", "5"));
    } catch (NumberFormatException e) {
      throw new Exception(
          "network property error: backupNbr must be an integer between 1 and 255.");
    }
    if (backupNbr < 1) {
      throw new Exception(
          "network property error: backupNbr must be an integer between 1 and 255.");
    }

    // message digest for hash
    md = MessageDigest.getInstance(ds().network.getProperty("hash", "SHA-1"));

    // all agent must have a PKI
    keyPair = generateKeyPair();
    signatureAlgorithm = ds().network.getProperty("SignatureAlgo", "SHA1withDSA");

    // all users use the same algo for symmetric encryption
    userSecretKeyFactory =
        SecretKeyFactory.getInstance(
            ds().network.getProperty("user.cipher.algo", "PBEWithMD5AndDES"));
    userCipher =
        Cipher.getInstance(ds().network.getProperty("user.cipher.algo", "PBEWithMD5AndDES"));

    if (ds().getProperty("server", "yes").equals("yes")) {
      storage = new Storage(ds());
      storage.attach();
    }
    LOG.info("end");
  }
예제 #8
0
파일: BFSDataModel.java 프로젝트: ccbon/ocp
  @Override
  public synchronized void rm(String existingParentDir, String name) throws Exception {
    LOG.info("existingParentDir = " + existingParentDir);
    String[] dirnames = existingParentDir.split("/");
    if (existingParentDir.equals("/")) {
      dirnames = new String[] {""};
    }
    LOG.info("dirnames.length = " + dirnames.length);
    Tree[] trees = getTreeStack(dirnames);

    Tree tree = trees[trees.length - 1];
    tree.removeEntry(name);
    Pointer p = createRemoteTree(tree);
    for (int i = dirnames.length - 2; i >= 0; i--) {
      tree = trees[i];
      tree.addTree(dirnames[i + 1], p);
      p = createRemoteTree(tree);
    }
    setRootPointer(p);
  }
예제 #9
0
파일: BFSDataModel.java 프로젝트: ccbon/ocp
 private Pointer commit(File file) throws Exception {
   LOG.info("about to commit " + file.getName());
   Pointer result = null;
   if (file.isDirectory()) {
     Tree tree = new Tree();
     for (File child : file.listFiles()) {
       LOG.info("child: " + child.getName());
       Pointer p = commit(child);
       if (child.isDirectory()) {
         tree.addTree(child.getName(), p);
       } else {
         tree.addFile(child.getName(), p, child.length());
       }
     }
     result = createRemoteTree(tree);
   } else { // file
     result = createRemoteFile(file);
   }
   return result;
 }
예제 #10
0
파일: AboutAction.java 프로젝트: ccbon/ocp
  @Override
  public void run() {
    LOG.info("About");
    Display display = window.getShell().getDisplay();
    MessageBox messageBox = new MessageBox(new Shell(display), SWT.ICON_INFORMATION | SWT.OK);
    String message = "Remote Storage Agent Prototype v1\n";
    message += "Jean-Louis GUENEGO - JLG Consulting\n";
    message += "Supelec Alcatel Lucent Chair on Flexible Radio @ 2011-2012\n";

    messageBox.setMessage(message);
    messageBox.setText("About");
    messageBox.open();
    window.getShell().setFocus();
  }
예제 #11
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
 void store(Address address, Content content) throws Exception {
   if (isResponsible(address)) {
     // local (even if this should be store elsewhere, store this for
     // cache purpose.
     // JLG.debug("local store");
     storage.put(address, content);
   } else {
     // transfer the order to another agent
     LOG.info("transfert the order");
     Id nodeId = getNodeId(address);
     Queue<Contact> contactQueue = makeContactQueue(nodeId);
     getClient().store(contactQueue, address, content);
   }
 }
예제 #12
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
 public Id getNodeId(Address address) throws Exception {
   if (nodeMap.size() == 0) {
     throw new Exception("nodeMap is not populated.");
   }
   LOG.info("nodeMap=" + nodeMap);
   Id nodeId = nodeMap.floorKey(address);
   if (nodeId == null) {
     nodeId = nodeMap.lastKey();
   }
   // if (nodeId == null) {
   // throw new Exception("nodeMap is not populated at all");
   // }
   return nodeId;
 }
예제 #13
0
파일: BFSDataModel.java 프로젝트: ccbon/ocp
 @Override
 public synchronized void commit(String remoteDir, File file) throws Exception {
   LOG.info("path = " + remoteDir);
   String[] dirnames = remoteDir.split("/");
   if (remoteDir.equals("/")) {
     dirnames = new String[] {""};
   }
   LOG.info("dirnames.length = " + dirnames.length);
   Tree[] trees = getTreeStack(dirnames);
   Pointer p = commit(file);
   Tree tree = trees[trees.length - 1];
   if (file.isDirectory()) {
     tree.addTree(file.getName(), p);
   } else {
     tree.addFile(file.getName(), p, file.length());
   }
   p = createRemoteTree(tree);
   for (int i = dirnames.length - 2; i >= 0; i--) {
     tree = trees[i];
     tree.addTree(dirnames[i + 1], p);
     p = createRemoteTree(tree);
   }
   setRootPointer(p);
 }
예제 #14
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
 public Contact removeContact(Contact contact) {
   ContactMap contactMap = ds().getComponent(ContactMap.class);
   OCPContact c = (OCPContact) contactMap.remove(contact);
   try {
     Iterator<Id> it = c.nodeIdSet.iterator();
     while (it.hasNext()) {
       Id id = it.next();
       LOG.info("removing node to nodeMap");
       nodeMap.remove(id);
     }
     return c;
   } catch (Exception e) {
     return null;
   }
 }
예제 #15
0
파일: HTTPListener.java 프로젝트: ccbon/ocp
  @Override
  public void start() {
    try {

      int port = url.getPort();
      if (usesComponent(NATTraversal.class)) {
        getComponent(NATTraversal.class).setPort(port);
        getComponent(NATTraversal.class).map();
      }

      httpServer.setPort(port);
      httpServer.setHandler(handler);

      t = new Thread(httpServer, "HTTPServer");
      t.start();

    } catch (Exception e) {
      LOG.error(e);
    }
  }
예제 #16
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
 public Pointer set(OCPUser user, Serializable serializable) throws Exception {
   LOG.info("set serializable: " + serializable.getClass());
   return set(user, ds().serializer.serialize(serializable));
 }
예제 #17
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
 public void disconnect() throws Exception {
   LOG.info("disconnect");
   if (getServer() != null) {
     getServer().stop();
   }
 }