/** * Converts an identity to a contact. * * @return {EcContact} * Contact object. * @memberOf EcIdentity * @method toContact */ public EcContact toContact() { EcContact c = new EcContact(); c.displayName = displayName; c.pk = ppk.toPk(); c.source = source; return c; } }
@Override public void $invoke(EcPpk decryptionKey, final Callback0 countdown) { int estimatedIndex = -1; for (int i = 0; i < ppks.$length(); i++) if (ppks.$get(i).equals(decryptionKey)) estimatedIndex = estimatedIndices.$get(i); me.decryptSecretByKeyAsync(decryptionKey, estimatedIndex, new Callback1<EbacEncryptedSecret>() { @Override public void $invoke(EbacEncryptedSecret p1) { if (helper.counter == -1) { return; } helper.stop(); success.$invoke(p1); } }, new Callback1<String>() { @Override public void $invoke(String arg0) { countdown.$invoke(); } }); } }, new Callback1<Array<EcPpk>>() {
/** * Helper function to decrypt a credential (storable version of an identity) * into an identity) * * @param {EbacCredential} credential * Credential to decrypt. * @param {String} secret * AES secret used to decrypt the credential. * @param {String} source * Source of the credential, used to track where a credential * came from. * @return {EcIdentity} * Decrypted identity object, ready for use. * @memberOf EcIdentity * @method fromCredential * @static */ public static EcIdentity fromCredential(EbacCredential credential, String secret, String source) { EcIdentity i = new EcIdentity(); i.ppk = EcPpk.fromPem(EcAesCtr.decrypt(credential.ppk, secret, credential.iv)); i.source = source; if (credential.displayName != null && credential.displayNameIv != null) i.displayName = EcAesCtr.decrypt(credential.displayName, secret, credential.iv); return i; }
EcPpk decryptionKey = EcIdentityManager.getPpk(EcPk.fromPem(owner.$get(i))); if (decryptionKey != null) { if (!decryptionKey.inArray(ppks)) { ppks.push(decryptionKey); estimatedIndices.push(i); EcPpk decryptionKey = EcIdentityManager.getPpk(EcPk.fromPem(reader.$get(i))); if (decryptionKey != null) { if (!decryptionKey.inArray(ppks)) { ppks.push(decryptionKey); estimatedIndices.push(i + owner.$length());
/** * Helper function to encrypt an identity into a credential (storable * version of an identity) * * @param {String} secret * AES secret used to encrypt the credential. * @return {EbacCredential} * Encrypted credential object. * @memberOf EcIdentity * @method toCredential */ public EbacCredential toCredential(String secret) { EbacCredential c = new EbacCredential(); c.iv = EcAes.newIv(16); c.ppk = EcAesCtr.encrypt(ppk.toPem(), secret, c.iv); c.displayNameIv = EcAes.newIv(16); c.displayName = EcAesCtr.encrypt(displayName, secret, c.iv); return c; }
public static String myIdentitiesSearchString() { String searchString = ""; for (int i = 0; i < ids.$length(); i++) { if (i > 0) { searchString += " OR "; } searchString += "@reader:\"" + ids.$get(i).ppk.toPk().toPem() + "\""; searchString += " OR "; searchString += "@owner:\"" + ids.$get(i).ppk.toPk().toPem() + "\""; } return searchString; }
/** * Writes contact data to localstorage. * * @memberOf EcIdentityManager * @method saveIdentities * @static */ public static void saveIdentities() { Array<Object> c = new Array<Object>(); for (int i = 0; i < ids.$length(); i++) { Object o = new Object(); Map<String, Object> props = JSObjectAdapter.$properties(o); EcIdentity identity = ids.$get(i); props.$put("displayName", identity.displayName); props.$put("ppk", identity.ppk.toPem()); props.$put("source", identity.source); c.push(o); } Global.localStorage.$put("identities", JSGlobal.JSON.stringify(c)); }
public static Array<EcPk> getMyPks(){ Array<EcPk> pks = new Array<EcPk>(); if (ids == null) return pks; for (int i = 0;i < ids.$length();i++) pks.push(ids.$get(i).ppk.toPk()); return pks; } }
private void writeIdentityFile(String folderId, final EcIdentity identity, final Callback0 finished) { File file = BlobHelper.stringToFile(identity.ppk.toPem(), identity.displayName + ".pem", "text/plain"); Object o = new Object(); JSObjectAdapter.$put(o, "id", JSObjectAdapter.$get(identity, "id")); if (JSObjectAdapter.$get(o, "id") == Global.undefined) JSObjectAdapter.$put(o, "parent", folderId); JSObjectAdapter.$put(o, "name", file.name); Array<File> files = new Array<>(); files.push(file); JSObjectAdapter.$put(o, "file", files); hello.api(network + "/" + "me/files", JSObjectAdapter.$get(identity, "id") == Global.undefined ? "post" : "put", o).then(new Callback1<Object>() { @Override public void $invoke(Object r) { JSObjectAdapter.$put(identity, "id", JSObjectAdapter.$get(r, "id")); if (finished != null) finished.$invoke(); } }); }
/** * Get Identity from PK (if we have it) * * @param {EcPk} pk PK to use to look up PPK * @return {EcIdentity} identity or null. * @memberOf EcIdentityManager * @method getIdentity * @static */ public static EcIdentity getIdentity(EcPk pk) { for (int i = 0; i < ids.$length(); i++) { if (pk.equals(ids.$get(i).ppk.toPk())) { return ids.$get(i); } } return null; }
/** * Get PPK from PK (if we have it) * * @param {EcPk} fromPem PK to use to look up PPK * @return {EcPpk} PPK or null. * @memberOf EcIdentityManager * @method getPpk * @static */ public static EcPpk getPpk(EcPk fromPem) { String pem = fromPem.toPem(); for (int i = 0; i < ids.$length(); i++) { if (pem.equals(ids.$get(i).ppk.toPk().toPem())) { return ids.$get(i).ppk; } } return null; }
@Override public void $invoke(EcIdentity p1, final Callback0 incrementalSuccess) { EcPpk ppk = p1.ppk; EcPk pk = ppk.toPk(); boolean found = false; if (identityPksinPem != null) { for (int j = 0; j < identityPksinPem.$length(); j++) { EcPk ownerPpk = EcPk.fromPem(identityPksinPem.$get(j).trim()); if (pk.equals(ownerPpk)) { found = true; createSignatureAsync(duration, server, ppk, new Callback1<EbacSignature>() { @Override public void $invoke(EbacSignature p1) { signatures.push(p1.atIfy()); incrementalSuccess.$invoke(); } },failure); } } } if (!found) { incrementalSuccess.$invoke(); } } }, new Callback1<Array<EcIdentity>>() {
/** * Verifies that the contact grant is valid * * @return {boolean} * true if valid, false if not */ public boolean valid() { if (!verify()) return false; if (invalid()) return false; boolean found = false; for (int i = 0; i < EcIdentityManager.ids.$length(); i++) { if (EcRsaOaep.verify(EcIdentityManager.ids.$get(i).ppk.toPk(), responseToken, responseSignature)) found = true; } return found; }
/** * Adds a relationship between this level and a target level to define * how they correspond to one another * * @param {EcLevel} targetLevel * Target level of the relationship * @param {String} alignmentType * Type of relationship * @param {EcPpk} identity * Private key that will own the new relationship * @param {String} server * URL Prefix of the new relationship ID (Server it will be saved on) * @memberOf EcLevel * @method addRelationship */ public void addRelationship(EcLevel targetLevel, String alignmentType, final EcPpk identity, final String serverUrl, Callback1<String> success, Callback1<String> failure, final EcRepository repo) { final EcAlignment a = new EcAlignment(); a.source = id; a.target = targetLevel.id; a.relationType = alignmentType; a.addOwner(identity.toPk()); if (repo == null || repo.selectedServer.indexOf(serverUrl) != -1) a.generateId(serverUrl); else a.generateShortId(serverUrl); a.signWith(identity); a.save(success, failure, repo); }
l.description = description; l.name = name; l.addOwner(owner.toPk());
r.description = description; r.name = name; r.addOwner(owner.toPk());
/** * Create a signature for a specific identity, authorizing movement of data * outside of our control. * * @param {long} duration Length of time in milliseconds to authorize * control. * @param {String} server Server that we are authorizing. * @param {EcPpk} ppk Key of the identity to create a signature for * @return {Ebac Signature} Signature created * @memberOf EcIdentityManager * @method createSignature * @static */ public static EbacSignature createSignature(long duration, String server, EcPpk ppk) { EbacSignature s = new EbacSignature(); s.owner = ppk.toPk().toPem(); s.expiry = new Date().getTime() + duration; s.server = server; s.signature = EcRsaOaep.sign(ppk, s.toJson()); return s; }
a.target = target.shortId(); a.relationType = alignmentType; a.addOwner(owner.toPk());