public void setAgent(EcPk pk) { agent = (EcEncryptedValue) (Object) pk.toPem(); }
/** * Comparison method that checks if the key is the same as another EcContact * * @param {Object} obj * Contact to compare if same key * @return {boolean} * true if the key is the same, false if not * @memberOf EcContact * @method equals */ @Override public boolean equals(Object obj) { if (obj instanceof EcContact) { if (pk == null) return false; if (((EcContact) obj).pk == null) return false; return pk.toPem().equals(((EcContact) obj).pk.toPem()); } return super.equals(obj); }
@Override public void $invoke(EcPk sub) { //if assertion subject is null or assertion subject is not a requested subject if (sub == null || !cgb.isASubject(sub)) { cgb.assertionsFilledIn++; cgb.checkAssertionDetailsFetched(); } else { sa.setSubjectPem(sub.toPem()); cgb.fetchAssertionDetailsAssertionDate(a, sa); } } },
public void setAgent(EcPk pk) { agent = EcEncryptedValue.encryptValue(pk.toPem(), id, subject.owner, subject.reader); }
/** * Determines if the object has a reader identified by pk. * Homogenizes the PEM strings for comparison. * Homogenization is necessary for comparing PKCS#1 and PKCS#8 or PKs with Certificates, etc. * * @param {EcPk} pk Public Key of the owner. * @return {boolean} True if owner is represented by the PK, false otherwise. * @method hasOwner */ public boolean hasReader(EcPk pk) { if (reader == null) return false; String pkPem = pk.toPem(); for (int i = 0; i < reader.$length(); i++) if (pkPem == EcPk.fromPem(reader.$get(i)).toPem()) return true; return false; }
/** * Determines if the object has an owner identified by pk. * Homogenizes the PEM strings for comparison. * Homogenization is necessary for comparing PKCS#1 and PKCS#8 or PKs with Certificates, etc. * * @param {EcPk} pk Public Key of the owner. * @return {boolean} True if owner is represented by the PK, false otherwise. * @method hasOwner */ public boolean hasOwner(EcPk pk) { if (owner == null) return false; String pkPem = pk.toPem(); for (int i = 0; i < owner.$length(); i++) if (pkPem == EcPk.fromPem(owner.$get(i)).toPem()) return true; return false; }
/** * Adds a reader to the object, if the reader does not exist. * Note that this method invalidates all signatures. * * @param {EcPk} newReader PK of the new reader. * @method addReader */ public void addReader(EcPk newReader) { String pem = newReader.toPem(); if (reader == null) reader = new Array<String>(); EcArray.setAdd(reader,pem); // Changing an owner invalidates the signatures in order to prevent // server admins from injecting owners or readers into the object. signature = 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; }
/** * Removes a reader from the object, if the reader does exist. * Note that this method invalidates all signatures. * * @param {EcPk} oldReader PK of the old reader. * @method removeReader */ public void removeReader(EcPk oldReader) { String pem = oldReader.toPem(); if (reader == null) reader = new Array<String>(); EcArray.setRemove(reader,pem); // Changing an owner invalidates the signatures in order to prevent // server admins from injecting owners or readers into the object. signature = null; }
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; }
protected String buildAssertionSearchQuery(InquiryPacket ip, EcCompetency competency) { String result = null; if (IPType.ROLLUPRULE.equals(ip.type)) { if (ip.rule.indexOf("AND ") == 0) ip.rule = ip.rule.replace("AND ",""); result = "(" + new EcAssertion().getSearchStringByType() + ") AND (" + ip.rule + ")"; } else if (IPType.COMPETENCY.equals(ip.type)) result = new EcAssertion().getSearchStringByTypeAndCompetency(competency); for (int i = 0; i < ip.subject.$length(); i++) result += " AND (\\*@reader:\"" + ip.subject.$get(i).toPem() + "\")"; log(ip, "Search Query: " + result); if (result != null) return result; throw new RuntimeException("Trying to build an assertion search query on an unsupported type: " + ip.type); }
/** * Adds an owner to the object, if the owner does not exist. * Note that this method invalidates all signatures. * * @param {EcPk} newOwner PK of the new owner. * @method addOwner */ public void addOwner(EcPk newOwner) { String pem = newOwner.toPem(); if (owner == null) owner = new Array<String>(); for (int i = 0; i < owner.$length(); i++) if (owner.$get(i) == pem) return; owner.push(pem); // Changing an owner invalidates the signatures in order to prevent // server admins from injecting owners or readers into the object. signature = null; }
/** * Removes an owner from the object, if the owner does exist. * Note that this method invalidates all signatures. * * @param {EcPk} oldOwner PK to remove. * @method removeOwner */ public void removeOwner(EcPk oldOwner) { String pem = oldOwner.toPem(); if (owner == null) owner = new Array<String>(); for (int i = 0; i < owner.$length(); i++) if (owner.$get(i) == pem) owner.splice(i, 1); // Changing an owner invalidates the signatures in order to prevent // server admins from injecting owners or readers into the object. signature = null; }
protected String buildAssertionsSearchQuery(InquiryPacket ip, Array<String> competencies) { String result = null; if (IPType.ROLLUPRULE.equals(ip.type)) { ip.failure.$invoke("NOT SUPPOSED TO BE HERE."); throw new RuntimeException("Collecting assertions when root node is a rollup rule. Not supported."); } else if (IPType.COMPETENCY.equals(ip.type)) { result = "("; for (int i = 0; i < competencies.$length(); i++) { if (i != 0) result += " OR "; result += "competency:\"" + competencies.$get(i) + "\""; } result += ")"; } for (int i = 0; i < ip.subject.$length(); i++) result += " AND (\\*@reader:\"" + ip.subject.$get(i).toPem() + "\")"; if (result != null) return result; throw new RuntimeException("Trying to build an assertion search query on an unsupported type: " + ip.type); }
public void mutateAssertions(InquiryPacket ip, Array<String> listOfCompetencies, Callback0 success) { Array<String> keys = EcObject.keys(this.assertionProcessor.assertions); for (int keyIndex = 0; keyIndex < keys.$length(); keyIndex++) { Array<EcAssertion> ary = (Array) JSObjectAdapter.$get(this.assertionProcessor.assertions, keys.$get(keyIndex)); for (int i = 0; i < ary.$length(); i++) { EcAssertion a = ary.$get(i); if (a.getAgent().toPem() == agent.toPem()) { a.confidence = a.confidence * multiplier; if (removeNoConfidence && a.confidence == 0.0) ary.splice(i--, 1); } } } success.$invoke(); } }
private String buildAssertionSearchQuery() { String query = "("; for (int i = 0; i < competencyGraph.getNodes().$length(); i++) { if (i != 0) query += " OR "; query += "competency:\"" + competencyGraph.getNodes().$get(i) + "\""; } query += ")"; if (subjects != null) { for (int i = 0; i < subjects.$length(); i++) { query += " AND (\\*@reader:\"" + subjects.$get(i).toPem() + "\")"; } } return query; }
/** * 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; }
/** * Writes contact data to localstorage. * * @memberOf EcIdentityManager * @method saveContacts * @static */ private static void saveContacts() { Array<Object> c = new Array<Object>(); for (int i = 0; i < contacts.$length(); i++) { Object o = new Object(); Map<String, Object> props = JSObjectAdapter.$properties(o); EcContact contact = contacts.$get(i); props.$put("displayName", contact.displayName); props.$put("pk", contact.pk.toPem()); props.$put("source", contact.source); c.push(o); } Global.localStorage.$put("contacts", JSGlobal.JSON.stringify(c)); }
private void writeContactFile(String folderId, final EcContact contact) { File file = BlobHelper.stringToFile(contact.pk.toPem(), contact.displayName + ".pem", "text/plain"); Object o = new Object(); JSObjectAdapter.$put(o, "id", JSObjectAdapter.$get(contact, "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(contact, "id") == Global.undefined ? "post" : "put", o).then(new Callback1<Object>() { @Override public void $invoke(Object r) { JSObjectAdapter.$put(contact, "id", JSObjectAdapter.$get(r, "id")); } }); }