Пример #1
0
  @Override
  public ShareMetaData acceptInvitation(
      PublicKey ownerPubSigKey,
      String alias,
      PublicKey masterPubSigKey,
      PrivateKey masterPrivSigKey,
      String deviceAlias,
      PublicKey newDevicePubKey,
      PublicKey masterPubEncKey,
      PrivateKey masterPrivEncKey)
      throws ShareMetaDataException {

    loadShareMetaData(ownerPubSigKey);
    addDevice(
        alias,
        masterPubSigKey,
        masterPrivSigKey,
        deviceAlias,
        newDevicePubKey,
        masterPubEncKey,
        masterPrivEncKey);
    return this.shareMetaData;
  }
Пример #2
0
  @Test
  public void test() throws SymmetricKeyDecryptionException, SymmetricKeyEncryptionException {
    // Precondition:
    // Owner has pw-protected MasterKeystore containig MKey_sig and MKey_enc
    // Owner hat lesser protected DeviceKeystore containing at least one
    // DeviceKey DevKey_1_enc

    // Create Empty SharePartList
    assertNotNull(volume);

    // ShareMetaData shareMetaData = volume.createShareMetaData(alias,
    // mKey_sig_pub, mKey_sig, deviceAlias, devKey1_enc);
    ShareMetaData shareMetaData = null;
    try {
      shareMetaData =
          new ShareMetaData(
              new JDBCHelperNonRevokeable("jdbc:sqlite:" + dbName + File.separator), mKey_sig_pub);
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
    try {
      Field smdField = Volume.class.getDeclaredField("shareMetaData");
      smdField.setAccessible(true);
      smdField.set(volume, shareMetaData);
    } catch (Exception e) {
      fail(e.getMessage());
    }
    assertNotNull(shareMetaData);

    SharePartList spl = shareMetaData.initSharePartList();
    assertEquals("SharePartList is not empty, although it should be", 0, spl.size());
    // Sign SharePartList
    try {
      spl.sign(mKey_sig);
      assertTrue(CryptCore.verifySignature(spl, spl.getSignature(), mKey_sig_pub));
    } catch (SignatureException e2) {
      fail(e2.getMessage());
    }

    spl.add(mKey_sig_pub, alias);
    assertEquals("SharePartList is not empty, although it should be", 1, spl.size());
    try {
      spl.sign(mKey_sig);
      assertTrue(CryptCore.verifySignature(spl, spl.getSignature(), mKey_sig_pub));
    } catch (SignatureException e2) {
      fail(e2.getMessage());
    }

    // get DevKeys for the Devices that the owner wants to enable for this
    // Volume
    // Put keys in dkList
    dkList.put(deviceAlias, devKey1_enc);
    assertEquals("DeviceKeyList should have 1 element", 1, dkList.size());

    // Create and sign devicelist
    DeviceList dl = shareMetaData.createDeviceList(mKey_sig_pub, dkList);
    assertEquals(
        "ShareMetaData should have 1 DeviceList",
        1,
        shareMetaData.getDeviceLists().values().size());

    // Create symmetric ShareKey
    SecretKey sk = CryptCore.generateSymmetricKey();
    assertNotNull(sk);

    // Encrypt sk for all deviceLists
    Collection<DeviceList> deviceLists = shareMetaData.getDeviceLists().values();
    Collection<PublicKey> pubKeys = new LinkedList<PublicKey>();
    for (DeviceList devList : deviceLists) {
      pubKeys.addAll(devList.getPublicKeys());
    }
    assertEquals(1, pubKeys.size());
    // fetch ShareKeyDB
    ShareKeyDB db = shareMetaData.getShareKeys();
    assertNotNull(db);
    // add Encrypted Keys to db
    try {
      db.add(sk, pubKeys);
    } catch (SymmetricKeyEncryptionException e1) {
      fail(e1.getMessage());
    }
    assertEquals(1, db.size());
    try {
      db.sign(mKey_sig, alias);
    } catch (SignatureException e1) {
      fail(e1.getMessage());
    }

    // Encrypt skOb for all deviceLists
    shareMetaData.addObfuscationKey(devKey1_enc, null, null);

    System.out.println("Making ShareMetaData persistent...");

    try {
      dl.sign(mKey_sig, shareMetaData.shareKeys, shareMetaData.obfuscationKeys);
      assertTrue(
          SignatureHelper.verify(
              dl.getSignature(),
              mKey_sig_pub,
              dl,
              shareMetaData.shareKeys.get(dl.getPublicKeys()),
              shareMetaData.obfuscationKeys.get(dl.getPublicKeys())));

    } catch (SignatureException
        | InvalidKeyException
        | NoSuchAlgorithmException
        | SerializationException e2) {
      fail(e2.getMessage());
    }

    // make sharemetadata persistent
    try {
      shareMetaData.persist();
      shareMetaData.persist(dl);
    } catch (Exception e) {
      fail(e.getMessage());
    }

    System.out.println("Loading Volume...");

    // load volume with sharemetadata
    try {
      Volume loadedVol = new Volume(dbName);
      ShareMetaData loadedSMD = loadedVol.loadShareMetaData(mKey_sig_pub);

      assertArrayEquals(shareMetaData.getSignature(), loadedSMD.getSignature());

      System.out.println("DONE");
    } catch (Exception e) {
      e.printStackTrace(System.err);
      fail(e.getMessage());
    }
  }
Пример #3
0
  @SuppressWarnings("unchecked")
  @Test
  public void testNewAPI()
      throws NoSuchFieldException, SecurityException, IllegalArgumentException,
          IllegalAccessException {
    VolumeParamsFactory pf = VolumeParamsFactory.getFactory();
    assertNotNull(volume);
    ShareMetaData smd = null;
    Volume volume2 = null;
    ShareMetaData smd2 = null;

    try {
      VolumeParams p =
          pf.createVolumeParams()
              .setOwnerAlias(alias)
              .setPublicSignatureKey(mKey_sig_pub)
              .setPrivateSignatureKey(mKey_sig)
              .setPublicEncryptionKey(mKey_enc_pub)
              .setPrivateEncryptionKey(mKey_enc)
              .setDeviceAlias(deviceAlias)
              .setPublicDeviceKey(devKey1_enc);

      smd = volume.createShareMetaData(p);
      assertNotNull(smd);
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
    try {
      ObfuscationKeyDB okdb = smd.obfuscationKeys;
      Field f = ObfuscationKeyDB.class.getDeclaredField("obfuscationKeys");
      f.setAccessible(true);
      int size = ((TreeMap<PublicKey, byte[]>) f.get(okdb)).size();
      assertEquals(2, size);
    } catch (Exception e) {
      fail(e.getMessage());
    }
    try {
      volume2 = new Volume(dbName);
      smd2 = volume2.loadShareMetaData(mKey_sig_pub);
      assertNotNull(smd2);
    } catch (Exception e) {
      fail(e.getMessage());
    }
    assertEquals(smd, smd2);

    try {
      volume.addDevice(
          alias, mKey_sig_pub, mKey_sig, deviceAlias2, devKey2_enc, mKey_enc_pub, mKey_enc);
    } catch (ShareMetaDataException e) {
      fail(e.getMessage());
    }

    try {
      ObfuscationKeyDB okdb = smd.obfuscationKeys;
      Field f = ObfuscationKeyDB.class.getDeclaredField("obfuscationKeys");
      f.setAccessible(true);
      int size = ((TreeMap<PublicKey, byte[]>) f.get(okdb)).size();
      assertEquals(3, size);
    } catch (Exception e) {
      fail(e.getMessage());
    }
    // try {
    // volume.removeDevice(alias, mKey_sig_pub, mKey_sig, deviceAlias);
    // } catch (Exception e) {
    // fail(e.getMessage());
    // }
    //
    // try {
    // ObfuscationKeyDB okdb = smd.obfuscationKeys;
    // Field f = ObfuscationKeyDB.class
    // .getDeclaredField("obfuscationKeys");
    // f.setAccessible(true);
    // int size = ((TreeMap<PublicKey, byte[]>) f.get(okdb)).size();
    // assertEquals(2, size);
    // } catch (Exception e) {
    // fail(e.getMessage());
    // }
    //
    // try {
    // volume.removeDevice(alias, mKey_sig_pub, mKey_sig, deviceAlias);
    // } catch (Exception e) {
    // fail(e.getMessage());
    // }
    //
    // try {
    // ObfuscationKeyDB okdb = smd.obfuscationKeys;
    // Field f = ObfuscationKeyDB.class
    // .getDeclaredField("obfuscationKeys");
    // f.setAccessible(true);
    // int size = ((TreeMap<PublicKey, byte[]>) f.get(okdb)).size();
    // assertEquals(2, size);
    // } catch (Exception e) {
    // fail(e.getMessage());
    // }
    //
    // try {
    // volume.removeDevice(alias, mKey_sig_pub, mKey_sig, deviceAlias2);
    // } catch (Exception e) {
    // fail(e.getMessage());
    // }
    //
    // try {
    // ObfuscationKeyDB okdb = smd.obfuscationKeys;
    // Field f = ObfuscationKeyDB.class
    // .getDeclaredField("obfuscationKeys");
    // f.setAccessible(true);
    // int size = ((TreeMap<PublicKey, byte[]>) f.get(okdb)).size();
    // assertEquals(1, size);
    // } catch (Exception e) {
    // fail(e.getMessage());
    // }
    //
    // try {
    // volume.addDevice(alias, mKey_sig_pub, mKey_sig, deviceAlias2,
    // devKey2_enc, mKey_enc_pub, mKey_enc);
    // } catch (ShareMetaDataException e) {
    // fail(e.getMessage());
    // }
    //
    // try {
    // ObfuscationKeyDB okdb = smd.obfuscationKeys;
    // Field f = ObfuscationKeyDB.class
    // .getDeclaredField("obfuscationKeys");
    // f.setAccessible(true);
    // int size = ((TreeMap<PublicKey, byte[]>) f.get(okdb)).size();
    // assertEquals(2, size);
    // } catch (Exception e) {
    // fail(e.getMessage());
    // }

  }