/** * Decrypts an encrypted value into a string using an alternative secret. * * @return {String} Decrypted string value * @memberOf EcEncryptedValue * @method decryptIntoString */ public String decryptIntoStringUsingSecret(EbacEncryptedSecret decryptSecret) { if (decryptSecret != null) { return EcAesCtr.decrypt(payload, decryptSecret.secret, decryptSecret.iv); } return null; }
public void setAgent(EcPk pk) { agent = (EcEncryptedValue) (Object) pk.toPem(); }
public EcPk getSubject() { return EcPk.fromPem((String) (Object) subject); }
/** * Helper function to encrypt a contact into an encrypted contact (storable * version of a contact) * * @param {String} secret * AES secret used to encrypt the contact. * @return {EbacContact} * Encrypted contact object. * @memberOf EcContact * @method toEncryptedContact */ public EbacContact toEncryptedContact(String secret) { EbacContact c = new EbacContact(); c.iv = EcAes.newIv(32); c.pk = EcAesCtr.encrypt(pk.toPem(), secret, c.iv); c.displayNameIv = EcAes.newIv(16); c.displayName = EcAesCtr.encrypt(displayName, secret, c.iv); c.sourceIv = EcAes.newIv(16); c.source = EcAesCtr.encrypt(source, secret, c.iv); return c; } }
/** * 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; }
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; }
private static void insertSecret(String pk, final Callback0 success, String newIv, String newSecret, final EcEncryptedValue v, Callback1<String> failure) { EbacEncryptedSecret eSecret = new EbacEncryptedSecret(); eSecret.iv = newIv; eSecret.secret = newSecret; if (v.secret == null) { v.secret = new Array<String>(); } EcRsaOaepAsync.encrypt(EcPk.fromPem(pk), eSecret.toEncryptableJson(), new Callback1<String>() { @Override public void $invoke(String encryptedSecret) { v.secret.push(encryptedSecret); success.$invoke(); } }, failure); }
/** * 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; }
/** * 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; }
/** * 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; }
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; } }
@Override public void $invoke(String decryptionSecret, final Callback0 decrement) { EcRsaOaepAsync.decrypt(decryptionKey, decryptionSecret, new Callback1<String>() { @Override public void $invoke(String decryptedSecret) { if (helper.counter == -1) { return; } if (!EcLinkedData.isProbablyJson(decryptedSecret)) { decrement.$invoke(); } else { helper.stop(); success.$invoke(EbacEncryptedSecret.fromEncryptableJson(JSGlobal.JSON.parse(decryptedSecret))); } } }, new Callback1<String>() { @Override public void $invoke(String arg0) { decrement.$invoke(); } }); } }, new Callback1<Array<String>>() {
public EcPk getAgent() { return EcPk.fromPem((String) (Object) agent); }
@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); } } },
/** * Decrypts an encrypted value into a string * * @return {String} Decrypted string value * @memberOf EcEncryptedValue * @method decryptIntoString */ public String decryptIntoString() { EbacEncryptedSecret decryptSecret = decryptSecret(); if (decryptSecret != null) { return EcAesCtr.decrypt(payload, decryptSecret.secret, decryptSecret.iv); } return null; }
public void getAgentAsync(final Callback1<EcPk> success, final Callback1<String> failure) { success.$invoke(EcPk.fromPem((String) (Object) agent)); }
public void setAgent(EcPk pk) { agent = EcEncryptedValue.encryptValue(pk.toPem(), id, subject.owner, subject.reader); }
public void getSubjectAsync(final Callback1<EcPk> success, final Callback1<String> failure) { success.$invoke(EcPk.fromPem((String) (Object) subject)); }
@Override public void $invoke(String decryptedString) { if (decryptedString == null) failure.$invoke("Could not decrypt subject."); else success.$invoke(EcPk.fromPem(decryptedString)); } };
@Override public void $invoke(String decryptedString) { if (decryptedString == null) failure.$invoke("Could not decrypt agent."); else success.$invoke(EcPk.fromPem(decryptedString)); } };