/** * 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; } }
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; }
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; } }
/** * 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; }
/** * 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; }
@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());
/** * Asynchronously create a signature for a specific identity * * @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 * @param success Callback triggered once the signature sheet has been * created, returns the signature * @memberOf EcIdentityManager * @method createSignatureAsync * @static */ private static void createSignatureAsync(long duration, String server, EcPpk ppk, final Callback1<EbacSignature> success, final Callback1<String> failure) { final EbacSignature s = new EbacSignature(); s.owner = ppk.toPk().toPem(); s.expiry = new Date().getTime() + duration; s.server = server; EcRsaOaepAsync.sign(ppk, s.toJson(), new Callback1<String>() { @Override public void $invoke(String p1) { s.signature = p1; success.$invoke(s); } }, failure); }
/** * Adds a contact to the identity manager. Checks for duplicates. Does not trigger * events. * * @param {EcContact} contact Contact to add. * @memberOf EcIdentityManager * @method addContactQuietly * @static */ public static void addContactQuietly(EcContact contact) { for (int i = 0; i < ids.$length(); i++) { if (ids.$get(i).ppk.toPk().toPem().equals(contact.pk.toPem())) { ids.$get(i).displayName = contact.displayName; } } for (int i = 0; i < contacts.$length(); i++) { if (contacts.$get(i).pk.toPem().equals(contact.pk.toPem())) { contacts.$get(i).displayName = contact.displayName; } } for (int i = 0; i < contacts.$length(); i++) { if (contacts.$get(i).equals(contact)) { return; } } contacts.push(contact); }
/** * Create a signature sheet, authorizing movement of data outside of our * control. * * @param {String[]} identityPksinPem Which identities to create signatures * for. * @param {long} duration Length of time in milliseconds to authorize * control. * @param {String} server Server that we are authorizing. * @return {String} JSON Array containing signatures. * @memberOf EcIdentityManager * @method signatureSheetFor * @static */ public static String signatureSheetFor(Array<String> identityPksinPem, long duration, String server) { Array<Object> signatures = new Array<Object>(); for (int j = 0; j < ids.$length(); j++) { EcPpk ppk = ids.$get(j).ppk; EcPk pk = ppk.toPk(); if (identityPksinPem != null) { for (int i = 0; i < identityPksinPem.$length(); i++) { EcPk ownerPpk = EcPk.fromPem(identityPksinPem.$get(i).trim()); if (pk.equals(ownerPpk)) { signatures.push(createSignature(duration, server, ppk).atIfy()); } } } } return JSGlobal.JSON.stringify(signatures); }
/** * Adds a contact to the identity manager. Checks for duplicates. Triggers * events. * * @param {EcContact} contact Contact to add. * @memberOf EcIdentityManager * @method addContact * @static */ public static void addContact(EcContact contact) { for (int i = 0; i < ids.$length(); i++) { if (ids.$get(i).ppk.toPk().toPem().equals(contact.pk.toPem())) { ids.$get(i).displayName = contact.displayName; identityChanged(ids.$get(i)); } } for (int i = 0; i < contacts.$length(); i++) { if (contacts.$get(i).pk.toPem().equals(contact.pk.toPem())) { contacts.$get(i).displayName = contact.displayName; contactChanged(contacts.$get(i)); } } for (int i = 0; i < contacts.$length(); i++) { if (contacts.$get(i).equals(contact)) { return; } } contacts.push(contact); contactChanged(contact); }
query += "@owner:\"" + id.ppk.toPk().toPem() + "\"";