public void setAgent(EcPk pk) { agent = (EcEncryptedValue) (Object) pk.toPem(); }
/** * 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; }
@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>>() {
public EcPk getSubject() { return EcPk.fromPem((String) (Object) subject); }
/** * Get Contact from PK (if we have it) * * @param {EcPk} pk PK to use to look up PPK * @return {EcPpk} PPK or null. * @memberOf EcIdentityManager * @method getContact * @static */ public static EcContact getContact(EcPk pk) { for (int i = 0; i < contacts.$length(); i++) { if (pk.equals(contacts.$get(i).pk)) { return contacts.$get(i); } } return null; }
public static String getNameByPkBlocking(EcPk agentPk) { for (int i = 0; i < EcRepository.repos.$length(); i++) { String url = EcRepository.repos.$get(i).selectedServer; if (url == null) continue; if (url.endsWith("/") == false) url += "/"; url += "data/" + agentPk.fingerprint(); EcRemoteLinkedData personOrOrganization = EcRepository.getBlocking(url); if (personOrOrganization == null) continue; EcEncryptedValue e = new EcEncryptedValue(); if (personOrOrganization.isAny(e.getTypes())) { e.copyFrom(personOrOrganization); EcRemoteLinkedData decryptedPersonOrOrganization = e.decryptIntoObject(); if (decryptedPersonOrOrganization != null) personOrOrganization = decryptedPersonOrOrganization; } String name = Thing.getDisplayStringFrom(JSObjectAdapter.$get(personOrOrganization, "name")); if (name != null) return name; } EcIdentity identity = EcIdentityManager.getIdentity(agentPk); if (identity != null && identity.displayName != null) return identity.displayName + " (You)"; EcContact contact = EcIdentityManager.getContact(agentPk); if (contact != null && contact.displayName != null) return contact.displayName; return null; }
public EcPk getAgent() { return EcPk.fromPem((String) (Object) agent); }
/** * 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; }
/** * 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); }
/** * 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; }
public void getAgentAsync(final Callback1<EcPk> success, final Callback1<String> failure) { success.$invoke(EcPk.fromPem((String) (Object) agent)); }
/** * 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); }
@Override public void $invoke(EcPk sub) { if (sub.equals(currentSubject)) { me.log(ip, "Matching Assertion found."); a.getAssertionDateAsync(new Callback1<Long>() {
@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); } } },
@Override public void $invoke(final EbacEncryptedSecret payloadSecret) { String pem = oldReader.toPem(); if (me.reader != null) { EcArray.setRemove(me.reader, pem); if (me.owner != null) for (int i = 0;i < me.owner.$length();i++) EcArray.setAdd(ary, EcPk.fromPem(me.owner.$get(i))); if (me.reader != null) for (int i = 0;i < me.reader.$length();i++) EcArray.setAdd(ary, EcPk.fromPem(me.reader.$get(i))); me.secret = new Array<>(); EcAsyncHelper<EcPk> eah = new EcAsyncHelper<>();
public void getSubjectAsync(final Callback1<EcPk> success, final Callback1<String> failure) { success.$invoke(EcPk.fromPem((String) (Object) subject)); }
public void setAgent(EcPk pk) { agent = EcEncryptedValue.encryptValue(pk.toPem(), id, subject.owner, subject.reader); }
@Override public void $invoke(String decryptedString) { if (decryptedString == null) failure.$invoke("Could not decrypt subject."); else success.$invoke(EcPk.fromPem(decryptedString)); } };