public static ActivityDetails HandleResponse(AsymmetricCipherKeyPair keyPair, string responseContent) { if (string.IsNullOrEmpty(responseContent)) { throw new YotiProfileException(Properties.Resources.NullOrEmptyResponseContent); } ProfileDO parsedResponse = JsonConvert.DeserializeObject <ProfileDO>(responseContent); if (parsedResponse.Receipt == null) { throw new YotiProfileException(Properties.Resources.NullParsedResponse); } else if (parsedResponse.Receipt.SharingOutcome != "SUCCESS") { throw new YotiProfileException( $"The share was not successful, sharing_outcome: '{parsedResponse.Receipt.SharingOutcome}'"); } ReceiptDO receipt = parsedResponse.Receipt; var userProfile = new YotiProfile( ParseProfileContent(keyPair, receipt.WrappedReceiptKey, receipt.OtherPartyProfileContent)); SetAddressToBeFormattedAddressIfNull(userProfile); var applicationProfile = new ApplicationProfile( ParseProfileContent(keyPair, receipt.WrappedReceiptKey, receipt.ProfileContent)); ExtraData extraData = new ExtraData(); if (!string.IsNullOrEmpty(parsedResponse.Receipt.ExtraDataContent)) { extraData = CryptoEngine.DecryptExtraData( receipt.WrappedReceiptKey, parsedResponse.Receipt.ExtraDataContent, keyPair); } DateTime?timestamp = null; if (receipt.Timestamp != null && DateTime.TryParseExact( receipt.Timestamp, "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out DateTime parsedDate)) { timestamp = parsedDate; } return(new ActivityDetails(parsedResponse.Receipt.RememberMeId, parsedResponse.Receipt.ParentRememberMeId, timestamp, userProfile, applicationProfile, parsedResponse.Receipt.ReceiptId, extraData)); }
private AttributeList DecryptCurrentUserReceipt(ReceiptDO receipt, AsymmetricCipherKeyPair keyPair) { byte[] unwrappedKey = UnwrapKey(receipt.wrapped_receipt_key, keyPair); byte[] otherPartyProfileContentBytes = Conversion.Base64ToBytes(receipt.other_party_profile_content); EncryptedData encryptedData = EncryptedData.Parser.ParseFrom(otherPartyProfileContentBytes); byte[] iv = encryptedData.Iv.ToByteArray(); byte[] cipherText = encryptedData.CipherText.ToByteArray(); byte[] decipheredBytes = CryptoEngine.DecipherAes(unwrappedKey, iv, cipherText); return(AttributeList.Parser.ParseFrom(decipheredBytes)); }
public ActivityDetails HandleSuccessfulResponse(AsymmetricCipherKeyPair keyPair, Response response) { ProfileDO parsedResponse = JsonConvert.DeserializeObject <ProfileDO>(response.Content); if (parsedResponse.receipt == null) { return(new ActivityDetails { Outcome = ActivityOutcome.Failure }); } else if (parsedResponse.receipt.sharing_outcome != "SUCCESS") { return(new ActivityDetails { Outcome = ActivityOutcome.SharingFailure }); } else { ReceiptDO receipt = parsedResponse.receipt; AttrpubapiV1.AttributeList attributes = CryptoEngine.DecryptCurrentUserReceipt( parsedResponse.receipt.wrapped_receipt_key, parsedResponse.receipt.other_party_profile_content, keyPair); _yotiUserProfile.Id = parsedResponse.receipt.remember_me_id; _yotiProfile.Id = parsedResponse.receipt.remember_me_id; AddAttributesToProfile(attributes); return(new ActivityDetails { Outcome = ActivityOutcome.Success, UserProfile = _yotiUserProfile, Profile = _yotiProfile }); } }