Ejemplo n.º 1
0
 @Override
 public CryptoRecord getPayload() {
   CryptoRecord rec = new CryptoRecord(this);
   rec.payload = new ExtendedJSONObject();
   Log.d(
       LOG_TAG,
       "Getting payload for history record " + this.guid + " (" + this.guid.length() + ").");
   rec.payload.put("id", this.guid);
   rec.payload.put("title", this.title);
   rec.payload.put("histUri", this.histURI); // TODO: encoding?
   rec.payload.put("visits", this.visits);
   return rec;
 }
Ejemplo n.º 2
0
  @Test
  public void testSetKeysFromWBO()
      throws IOException, ParseException, NonObjectJSONException, CryptoException,
          NoCollectionKeysSetException {
    String json =
        "{\"default\":[\"3fI6k1exImMgAKjilmMaAWxGqEIzFX/9K5EjEgH99vc=\",\"/AMaoCX4hzic28WY94XtokNi7N4T0nv+moS1y5wlbug=\"],\"collections\":{},\"collection\":\"crypto\",\"id\":\"keys\"}";
    CryptoRecord rec = new CryptoRecord(json);

    KeyBundle syncKeyBundle =
        new KeyBundle("slyjcrjednxd6rf4cr63vqilmkus6zbe", "6m8mv8ex2brqnrmsb9fjuvfg7y");
    rec.keyBundle = syncKeyBundle;

    rec.encrypt();
    CollectionKeys ck = new CollectionKeys();
    ck.setKeyPairsFromWBO(rec, syncKeyBundle);
    byte[] input = "3fI6k1exImMgAKjilmMaAWxGqEIzFX/9K5EjEgH99vc=".getBytes("UTF-8");
    byte[] expected = Base64.decodeBase64(input);
    assertSame(expected, ck.defaultKeyBundle().getEncryptionKey());
  }
Ejemplo n.º 3
0
  @Test
  public void testCreateKeysBundle()
      throws CryptoException, NonObjectJSONException, IOException, ParseException,
          NoCollectionKeysSetException {
    String username = "******";
    String friendlyBase32SyncKey = "basuxv2426eqj7frhvpcwkavdi";

    KeyBundle syncKeyBundle = new KeyBundle(username, friendlyBase32SyncKey);

    CollectionKeys ck = CollectionKeys.generateCollectionKeys();
    CryptoRecord unencrypted = ck.asCryptoRecord();
    unencrypted.keyBundle = syncKeyBundle;
    CryptoRecord encrypted = unencrypted.encrypt();

    CollectionKeys ckDecrypted = new CollectionKeys();
    ckDecrypted.setKeyPairsFromWBO(encrypted, syncKeyBundle);

    // Compare decrypted keys to the keys that were set upon creation
    assertArrayEquals(
        ck.defaultKeyBundle().getEncryptionKey(),
        ckDecrypted.defaultKeyBundle().getEncryptionKey());
    assertArrayEquals(
        ck.defaultKeyBundle().getHMACKey(), ckDecrypted.defaultKeyBundle().getHMACKey());
  }