Пример #1
0
        private EncryptedSharedFolderData Encrypt(RequestedToken requestedToken, SharedFolderData sharedFolderData)
        {
            XmlElement xmlElement;

            try
            {
                xmlElement = sharedFolderData.SerializeToXmlElement();
            }
            catch (InvalidOperationException innerException)
            {
                throw new UnableToGenerateEncryptedSharedFolderDataException(innerException);
            }
            XmlElement encryptedData;

            try
            {
                encryptedData = SymmetricEncryptedXml.Encrypt(xmlElement, requestedToken.ProofToken);
            }
            catch (CryptographicException innerException2)
            {
                throw new UnableToGenerateEncryptedSharedFolderDataException(innerException2);
            }
            return(new EncryptedSharedFolderData
            {
                Token = new EncryptedDataContainer
                {
                    EncryptedData = requestedToken.SecurityToken
                },
                Data = new EncryptedDataContainer
                {
                    EncryptedData = encryptedData
                }
            });
        }
Пример #2
0
        public SharedFolderData TryDecrypt(EncryptedSharedFolderData encryptedSharedFolderData)
        {
            if (encryptedSharedFolderData.Token == null)
            {
                SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption>((long)this.GetHashCode(), "{0}: EncryptedSharedFolderData is missing Token element.", this);
                return(null);
            }
            if (encryptedSharedFolderData.Token.EncryptedData == null)
            {
                SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption>((long)this.GetHashCode(), "{0}: EncryptedSharedFolderData.Token is missing <EncryptedData> element.", this);
                return(null);
            }
            if (encryptedSharedFolderData.Data == null)
            {
                SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption>((long)this.GetHashCode(), "{0}: EncryptedSharedFolderData is missing <Data> element.", this);
                return(null);
            }
            if (encryptedSharedFolderData.Data.EncryptedData == null)
            {
                SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption>((long)this.GetHashCode(), "{0}: EncryptedSharedFolderData.Data is missing <EncryptedData> element.", this);
                return(null);
            }
            TokenValidationResults tokenValidationResults = this.externalAuthentication.TokenValidator.ValidateToken(encryptedSharedFolderData.Token.EncryptedData, Offer.SharingInviteMessage);

            if (tokenValidationResults.Result != TokenValidationResult.Valid)
            {
                SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption, TokenValidationResults>((long)this.GetHashCode(), "{0}: Token is not valid. TokenValidationResults={1}", this, tokenValidationResults);
                return(null);
            }
            SymmetricSecurityKey proofToken = tokenValidationResults.ProofToken;

            if (proofToken == null)
            {
                SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption>((long)this.GetHashCode(), "{0}: Unable to retrieve the security key from the token.", this);
                return(null);
            }
            XmlElement xmlElement;

            try
            {
                xmlElement = SymmetricEncryptedXml.Decrypt(encryptedSharedFolderData.Data.EncryptedData, proofToken);
            }
            catch (CryptographicException arg)
            {
                SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption, CryptographicException>((long)this.GetHashCode(), "{0}: Unable to decrypt the data element. Exception={1}", this, arg);
                return(null);
            }
            SharedFolderData result;

            try
            {
                result = SharedFolderData.DeserializeFromXmlELement(xmlElement);
            }
            catch (InvalidOperationException arg2)
            {
                SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption, InvalidOperationException>((long)this.GetHashCode(), "{0}: Unable to deserialize the data element. InvalidOperationException={1}", this, arg2);
                result = null;
            }
            catch (XmlException arg3)
            {
                SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption, XmlException>((long)this.GetHashCode(), "{0}: Unable to deserialize the data element. XmlException={1}", this, arg3);
                result = null;
            }
            return(result);
        }