public static BkmInitialize Create(CreateBkmInitializeRequest request, Options options)
        {
            BkmInitialize response = RestHttpClient.Instance.Post <BkmInitialize>(options.BaseUrl + BkmInitializeUrl, GetHttpHeaders(request, options), request);

            if (response != null)
            {
                response.HtmlContent = DigestHelper.DecodeString(response.HtmlContent);
            }
            return(response);
        }
Beispiel #2
0
        public static async Task <ThreedsInitialize> CreateAsync(CreatePaymentRequest request, Options options)
        {
            ThreedsInitialize response = await RestHttpClient.Instance.PostAsync <ThreedsInitialize>(options.BaseUrl + ThreedsInitializeUrl, GetHttpHeaders(request, options), request);

            if (response != null)
            {
                response.HtmlContent = DigestHelper.DecodeString(response.HtmlContent);
            }
            return(response);
        }
Beispiel #3
0
        public static ThreedsInitializePreAuth Create(CreatePaymentRequest request, Options options)
        {
            ThreedsInitializePreAuth response = RestHttpClient.Create().Post <ThreedsInitializePreAuth>(options.BaseUrl + "/payment/3dsecure/initialize/preauth", GetHttpHeaders(request, options), request);

            if (response != null)
            {
                response.HtmlContent = DigestHelper.decodeString(response.HtmlContent);
            }
            return(response);
        }
        public static ThreeDSInitialize Create(CreateThreeDSInitializeRequest request, Options options)
        {
            ThreeDSInitialize response = RestHttpClient.Create().Post <ThreeDSInitialize>(options.BaseUrl + "/payment/iyzipos/initialize3ds/ecom", GetHttpHeaders(request, options), request);

            if (response != null)
            {
                response.HtmlContent = DigestHelper.decodeString(response.HtmlContent);
            }
            return(response);
        }
        // Async
        public static async Task <BkmInitialize> CreateAsync(CreateBkmInitializeRequest request, Options options)
        {
            BkmInitialize response = await RestHttpClient.Create().PostAsync <BkmInitialize>(options.BaseUrl + "/payment/bkm/initialize", GetHttpHeaders(request, options), request);

            if (response != null)
            {
                response.HtmlContent = DigestHelper.DecodeString(response.HtmlContent);
            }
            return(response);
        }
Beispiel #6
0
        public static ConnectBKMInitialize Create(CreateConnectBKMInitializeRequest request, Options options)
        {
            ConnectBKMInitialize response = RestHttpClient.Create().Post <ConnectBKMInitialize>(options.BaseUrl + "/payment/iyziconnect/bkm/initialize", GetHttpHeaders(request, options), request);

            if (response != null)
            {
                response.HtmlContent = DigestHelper.decodeString(response.HtmlContent);
            }
            return(response);
        }
Beispiel #7
0
        public static BasicBkmInitialize Create(CreateBasicBkmInitializeRequest request, Options options)
        {
            BasicBkmInitialize response = RestHttpClient.Create().Post <BasicBkmInitialize>(options.BaseUrl + "/payment/bkm/initialize/basic", request, options);

            if (response != null)
            {
                response.HtmlContent = DigestHelper.decodeString(response.HtmlContent);
            }
            return(response);
        }
        public static BasicThreedsInitialize Create(CreateBasicPaymentRequest request, Options options)
        {
            BasicThreedsInitialize response = RestHttpClient.Create().Post <BasicThreedsInitialize>(options.BaseUrl + "/payment/3dsecure/initialize/basic", GetHttpHeaders(request, options), request);

            if (response != null)
            {
                response.HtmlContent = DigestHelper.DecodeString(response.HtmlContent);
            }
            return(response);
        }
        // Async
        public static async Task <BasicThreedsInitializePreAuth> CreateAsync(CreateBasicPaymentRequest request, Options options)
        {
            BasicThreedsInitializePreAuth response = await RestHttpClient.Create().PostAsync <BasicThreedsInitializePreAuth>(options.BaseUrl + "/payment/3dsecure/initialize/preauth/basic", GetHttpHeaders(request, options), request);

            if (response != null)
            {
                response.HtmlContent = DigestHelper.DecodeString(response.HtmlContent);
            }
            return(response);
        }
        public static ThreedsInitializePreAuth Create(CreatePaymentRequest request, Options options)
        {
            ThreedsInitializePreAuth response = RestHttpClient.Instance.Post <ThreedsInitializePreAuth>(options.BaseUrl + ThreedsInitializePreAuthUrl, GetHttpHeaders(request, options), request);

            if (response != null)
            {
                response.HtmlContent = DigestHelper.DecodeString(response.HtmlContent);
            }
            return(response);
        }
Beispiel #11
0
        public virtual async Task <Response <UploadManifestResult> > UploadManifestAsync(Stream stream, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
        {
            options ??= new UploadManifestOptions();

            string reference = options.Tag ?? DigestHelper.ComputeDigest(DigestHelper.AlgorithmIdentifierSha256, stream);

            stream.Position = 0;
            ResponseWithHeaders <ContainerRegistryCreateManifestHeaders> response = await _restClient.CreateManifestAsync(_repositoryName, reference, options.MediaType, stream, cancellationToken).ConfigureAwait(false);

            return(Response.FromValue(new UploadManifestResult(), response.GetRawResponse()));
        }
Beispiel #12
0
 /// <summary>
 /// 解密cookie
 /// </summary>
 /// <typeparam name="T">用户信息</typeparam>
 /// <param name="des">加密字符串</param>
 public static T GetDesDecrypt <T>(string des)
 {
     try
     {
         string code = DigestHelper.DesDecrypt(des);
         return(JsonConvert.DeserializeObject <T>(code));
     }
     catch
     {
         return(default(T));
     }
 }
Beispiel #13
0
        private static void ValidateManifestResponse(Response <DownloadManifestResult> manifestResponse)
        {
            var digestFromRegistry = manifestResponse.Value.Digest;

            var stream = manifestResponse.Value.Content;

            stream.Position = 0;

            // TODO: The registry may use a different digest algorithm - we need to handle that
            string digestFromContent = DigestHelper.ComputeDigest(DigestHelper.AlgorithmIdentifierSha256, stream);

            if (!string.Equals(digestFromRegistry, digestFromContent, DigestComparison))
            {
                throw new OciModuleRegistryException($"There is a mismatch in the manifest digests. Received content digest = {digestFromContent}, Digest in registry response = {digestFromRegistry}");
            }
        }
Beispiel #14
0
        public virtual async Task <Response <UploadBlobResult> > UploadBlobAsync(Stream stream, CancellationToken cancellationToken = default)
        {
            string digest = DigestHelper.ComputeDigest(DigestHelper.AlgorithmIdentifierSha256, stream);

            ResponseWithHeaders <ContainerRegistryBlobStartUploadHeaders> startUploadResult =
                await _blobRestClient.StartUploadAsync(_repositoryName, cancellationToken).ConfigureAwait(false);

            stream.Position = 0;
            ResponseWithHeaders <ContainerRegistryBlobUploadChunkHeaders> uploadChunkResult =
                await _blobRestClient.UploadChunkAsync(startUploadResult.Headers.Location, stream, cancellationToken).ConfigureAwait(false);

            ResponseWithHeaders <ContainerRegistryBlobCompleteUploadHeaders> completeUploadResult =
                await _blobRestClient.CompleteUploadAsync(digest, uploadChunkResult.Headers.Location, null, cancellationToken).ConfigureAwait(false);

            return(Response.FromValue(new UploadBlobResult(), completeUploadResult.GetRawResponse()));
        }
 public static bool ThreadSafeBaseValidateCertificate(RequestDigestSet requestDigestSet, X509Certificate certificate, SslPolicyErrors sslPolicyError)
 {
     if (certificate != null)
     {
         DigestSet digestSet   = new DigestSet();
         byte[]    rawCertData = certificate.GetRawCertData();
         digestSet.setSha1(DigestHelper.sha1(rawCertData));
         digestSet.setSha256(DigestHelper.sha256(rawCertData));
         requestDigestSet.CertificateDigest = digestSet;
         digestSet   = new DigestSet();
         rawCertData = certificate.GetPublicKey();
         digestSet.setSha1(DigestHelper.sha1(rawCertData));
         digestSet.setSha256(DigestHelper.sha256(rawCertData));
         requestDigestSet.SubjectDigest = digestSet;
         return(true);
     }
     return(false);
 }
Beispiel #16
0
 public virtual bool validateCertificate(X509Certificate certificate, SslPolicyErrors sslPolicyError)
 {
     if (certificate != null)
     {
         DigestSet digestSet   = new DigestSet();
         byte[]    rawCertData = certificate.GetRawCertData();
         digestSet.setSha1(DigestHelper.sha1(rawCertData));
         digestSet.setSha256(DigestHelper.sha256(rawCertData));
         setCertificateDigest(digestSet);
         digestSet   = new DigestSet();
         rawCertData = certificate.GetPublicKey();
         digestSet.setSha1(DigestHelper.sha1(rawCertData));
         digestSet.setSha256(DigestHelper.sha256(rawCertData));
         setSubjectDigest(digestSet);
         return(true);
     }
     return(false);
 }
Beispiel #17
0
        private static void ValidateBlobResponse(Response <DownloadBlobResult> blobResponse, OciDescriptor descriptor)
        {
            var stream = blobResponse.Value.Content;

            if (descriptor.Size != stream.Length)
            {
                throw new InvalidModuleException($"Expected blob size of {descriptor.Size} bytes but received {stream.Length} bytes from the registry.");
            }

            stream.Position = 0;
            string digestFromContents = DigestHelper.ComputeDigest(DigestHelper.AlgorithmIdentifierSha256, stream);

            stream.Position = 0;

            if (!string.Equals(descriptor.Digest, digestFromContents, DigestComparison))
            {
                throw new InvalidModuleException($"There is a mismatch in the layer digests. Received content digest = {digestFromContents}, Requested digest = {descriptor.Digest}");
            }
        }
Beispiel #18
0
        private async Task Announce()
        {
            HttpWebRequest request = GetWebRequest(this.RegistryEndpoint + $"/registrar/{this.SessionId}/manifest");

            string manifest = await this.GetManifest(new NAMEContext()).ConfigureAwait(false);

            string digest = DigestHelper.GetDigestForMessage(manifest);

            if (this.CurrentDigest != digest && this.settings.RunningMode < SupportedNAMEBehaviours.AnnounceDisabled)
            {
                var announceObj = new SendManifestDTO
                {
                    Manifest = manifest
                };

                var serializer = new DataContractJsonSerializer(typeof(SendManifestDTO));

                using (Stream stream = await request.GetRequestStreamAsync().ConfigureAwait(false))
                {
                    serializer.WriteObject(stream, announceObj);
                }

                HttpWebResponse response = await request.GetResponseAsync().ConfigureAwait(false) as HttpWebResponse;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    var msg = "Unable to send new manifest to the registry. Status code = " + response.StatusCode;
                    LogWarning(msg, true);
                    throw new NAMEException(msg);
                }
                else
                {
                    this.CurrentDigest = digest;
                }
            }
            else
            {
                await this.Ping().ConfigureAwait(false);
            }
        }
Beispiel #19
0
 /// <summary>
 /// 加密用户信息
 /// </summary>
 public static string GetDesEncrypt <T>(T info)
 {
     return(DigestHelper.DesEncrypt(JsonConvert.SerializeObject(info)));
 }
        private static byte[] GetBytesSHA256(byte[] inputBytes)
        {
            Sha256Digest sha256 = new Sha256Digest();

            return(DigestHelper.ComputeHash(sha256, inputBytes));
        }
        protected override bool LoadBackground(IDocumentContainer container, SrmDocument document, SrmDocument docCurrent)
        {
            // Only allow one background proteome to load at a time.  This can
            // get tricky, if the user performs an undo and then a redo across
            // a change in background proteome.
            // Our first priority is doing the digestions, the second is accessing web
            // services to add missing protein metadata.
            lock (_lockLoadBackgroundProteome)
            {
                BackgroundProteome originalBackgroundProteome = GetBackgroundProteome(docCurrent);
                // Check to see whether the Digestion already exists but has not been queried yet.
                BackgroundProteome backgroundProteomeWithDigestions = new BackgroundProteome(originalBackgroundProteome, true);
                if (IsNotLoadedExplained(docCurrent, backgroundProteomeWithDigestions, true) == null)
                {
                    // digest is ready, and protein metdata is resolved
                    CompleteProcessing(container, backgroundProteomeWithDigestions);
                    return(true);
                }
                // are we here to do the digest, or to resolve the protein metadata?
                bool getMetadata = (IsNotLoadedExplained(docCurrent, backgroundProteomeWithDigestions, false) == null) &&
                                   backgroundProteomeWithDigestions.NeedsProteinMetadataSearch;

                string         name           = originalBackgroundProteome.Name;
                ProgressStatus progressStatus =
                    new ProgressStatus(string.Format(getMetadata?Resources.BackgroundProteomeManager_LoadBackground_Resolving_protein_details_for__0__proteome:Resources.BackgroundProteomeManager_LoadBackground_Digesting__0__proteome, name));
                try
                {
                    using (FileSaver fs = new FileSaver(originalBackgroundProteome.DatabasePath, StreamManager))
                    {
                        File.Copy(originalBackgroundProteome.DatabasePath, fs.SafeName, true);
                        var  digestHelper = new DigestHelper(this, container, docCurrent, name, fs.SafeName, true);
                        bool success;
                        if (getMetadata)
                        {
                            success = digestHelper.LookupProteinMetadata(ref progressStatus);
                        }
                        else
                        {
                            success = (digestHelper.Digest(ref progressStatus) != null);
                        }

                        if (!success)
                        {
                            // Processing was canceled
                            EndProcessing(docCurrent);
                            UpdateProgress(progressStatus.Cancel());
                            return(false);
                        }
                        using (var proteomeDb = ProteomeDb.OpenProteomeDb(originalBackgroundProteome.DatabasePath))
                        {
                            proteomeDb.DatabaseLock.AcquireWriterLock(int.MaxValue);
                            try
                            {
                                if (!fs.Commit())
                                {
                                    EndProcessing(docCurrent);
                                    throw new IOException(
                                              string.Format(
                                                  Resources
                                                  .BackgroundProteomeManager_LoadBackground_Unable_to_rename_temporary_file_to__0__,
                                                  fs.RealName));
                                }
                            }
                            finally
                            {
                                proteomeDb.DatabaseLock.ReleaseWriterLock();
                            }
                        }


                        CompleteProcessing(container, new BackgroundProteome(originalBackgroundProteome, true));
                        UpdateProgress(progressStatus.Complete());
                        return(true);
                    }
                }
                catch (Exception x)
                {
                    var message = new StringBuilder();
                    message.AppendLine(
                        string.Format(Resources.BackgroundProteomeManager_LoadBackground_Failed_updating_background_proteome__0__,
                                      name));
                    message.Append(x.Message);
                    UpdateProgress(progressStatus.ChangeErrorException(new IOException(message.ToString(), x)));
                    return(false);
                }
            }
        }
Beispiel #22
0
        private BackgroundProteome Load(IDocumentContainer container, PeptideSettings settings, SrmDocument docCurrent, bool isBackgroundLoad)
        {
            // Only allow one background proteome to load at a time.  This can
            // get tricky, if the user performs an undo and then a redo across
            // a change in background proteome.
            // Our only priority is accessing web services to add missing protein metadata.
            // There may also be a load initiation by the Peptide Settings dialog as foreground task,
            // it takes priority over the background task.

            lock (_lockLoadBackgroundProteome)
            {
                BackgroundProteome originalBackgroundProteome = settings.BackgroundProteome;
                BackgroundProteome validatedBackgroundProtome = originalBackgroundProteome.DatabaseValidated
                    ? originalBackgroundProteome
                    : new BackgroundProteome(originalBackgroundProteome.BackgroundProteomeSpec);
                if (IsNotLoadedExplained(settings, validatedBackgroundProtome, true) == null)
                {
                    // protein metadata is resolved
                    CompleteProcessing(container, validatedBackgroundProtome);
                    Helpers.AssignIfEquals(ref validatedBackgroundProtome, originalBackgroundProteome);
                    return(validatedBackgroundProtome); // No change needed
                }
                // we are here to resolve the protein metadata
                string          name           = originalBackgroundProteome.Name;
                IProgressStatus progressStatus =
                    new ProgressStatus(string.Format(Resources.BackgroundProteomeManager_LoadBackground_Resolving_protein_details_for__0__proteome, name));
                try
                {
                    // The transaction commit for writing the digestion info can be very lengthy, avoid lock timeouts
                    // by doing that work in a tempfile that no other thread knows aboout
                    using (FileSaver fs = new FileSaver(originalBackgroundProteome.DatabasePath, StreamManager))
                    {
                        File.Copy(originalBackgroundProteome.DatabasePath, fs.SafeName, true);
                        var digestHelper = new DigestHelper(this, container, docCurrent, name, fs.SafeName, true);

                        bool success = digestHelper.LookupProteinMetadata(ref progressStatus);
                        if (digestHelper.IsCanceled || !success)
                        {
                            // Processing was canceled
                            if (docCurrent != null)
                            {
                                EndProcessing(docCurrent);
                            }
                            UpdateProgress(progressStatus.Cancel());
                            return(null);
                        }
                        using (var proteomeDb = ProteomeDb.OpenProteomeDb(originalBackgroundProteome.DatabasePath))
                        {
                            proteomeDb.DatabaseLock.AcquireWriterLock(int.MaxValue); // Wait for any existing readers to complete, prevent any new ones
                            try
                            {
                                if (File.GetLastWriteTime(fs.RealName) <= File.GetLastWriteTime(fs.SafeName)) // Don't overwrite if foreground task has already updated
                                {
                                    proteomeDb.CloseDbConnection();                                           // Get rid of any file handles
                                    if (!fs.Commit())
                                    {
                                        if (docCurrent != null)
                                        {
                                            EndProcessing(docCurrent);
                                        }
                                        throw new IOException(string.Format(Resources.BackgroundProteomeManager_LoadBackground_Unable_to_rename_temporary_file_to__0__,
                                                                            fs.RealName));
                                    }
                                }
                            }
                            finally
                            {
                                proteomeDb.DatabaseLock.ReleaseWriterLock();
                            }
                        }

                        var updatedProteome = new BackgroundProteome(originalBackgroundProteome);
                        using (var proteomeDb = originalBackgroundProteome.OpenProteomeDb())
                        {
                            proteomeDb.AnalyzeDb(); // Now it's safe to start this potentially lengthy indexing operation
                        }
                        CompleteProcessing(container, updatedProteome);
                        UpdateProgress(progressStatus.Complete());
                        return(updatedProteome);
                    }
                }
                catch (Exception x)
                {
                    var message = new StringBuilder();
                    message.AppendLine(
                        string.Format(Resources.BackgroundProteomeManager_LoadBackground_Failed_updating_background_proteome__0__,
                                      name));
                    message.Append(x.Message);
                    UpdateProgress(progressStatus.ChangeErrorException(new IOException(message.ToString(), x)));
                    return(null);
                }
            }
        }
        protected override bool LoadBackground(IDocumentContainer container, SrmDocument document, SrmDocument docCurrent)
        {
            // Only allow one background proteome to load at a time.  This can
            // get tricky, if the user performs an undo and then a redo across
            // a change in background proteome.
            // Our first priority is doing the digestions, the second is accessing web
            // services to add missing protein metadata.
            lock (_lockLoadBackgroundProteome)
            {
                BackgroundProteome originalBackgroundProteome = GetBackgroundProteome(docCurrent);
                // Check to see whether the Digestion already exists but has not been queried yet.
                BackgroundProteome backgroundProteomeWithDigestions = new BackgroundProteome(originalBackgroundProteome, true);
                if (IsNotLoadedExplained(docCurrent, backgroundProteomeWithDigestions, true) == null)
                {
                    // digest is ready, and protein metdata is resolved
                    CompleteProcessing(container, backgroundProteomeWithDigestions);
                    return true;
                }
                // are we here to do the digest, or to resolve the protein metadata?
                bool getMetadata = (IsNotLoadedExplained(docCurrent, backgroundProteomeWithDigestions, false) == null) &&
                    backgroundProteomeWithDigestions.NeedsProteinMetadataSearch;

                string name = originalBackgroundProteome.Name;
                ProgressStatus progressStatus =
                    new ProgressStatus(string.Format(getMetadata?Resources.BackgroundProteomeManager_LoadBackground_Resolving_protein_details_for__0__proteome:Resources.BackgroundProteomeManager_LoadBackground_Digesting__0__proteome, name));
                try
                {
                    using (FileSaver fs = new FileSaver(originalBackgroundProteome.DatabasePath, StreamManager))
                    {
                        File.Copy(originalBackgroundProteome.DatabasePath, fs.SafeName, true);
                        var digestHelper = new DigestHelper(this, container, docCurrent, name, fs.SafeName, true);
                        bool success;
                        if (getMetadata)
                            success = digestHelper.LookupProteinMetadata(ref progressStatus);
                        else
                            success = (digestHelper.Digest(ref progressStatus) != null);

                        if (!success)
                        {
                            // Processing was canceled
                            EndProcessing(docCurrent);
                            UpdateProgress(progressStatus.Cancel());
                            return false;
                        }
                        using (var proteomeDb = ProteomeDb.OpenProteomeDb(originalBackgroundProteome.DatabasePath))
                        {
                            proteomeDb.DatabaseLock.AcquireWriterLock(int.MaxValue);
                            try
                            {
                                if (!fs.Commit())
                                {
                                    EndProcessing(docCurrent);
                                    throw new IOException(
                                        string.Format(
                                            Resources
                                                .BackgroundProteomeManager_LoadBackground_Unable_to_rename_temporary_file_to__0__,
                                            fs.RealName));
                                }
                            }
                            finally
                            {
                                proteomeDb.DatabaseLock.ReleaseWriterLock();
                            }
                        }

                        CompleteProcessing(container, new BackgroundProteome(originalBackgroundProteome, true));
                        UpdateProgress(progressStatus.Complete());
                        return true;
                    }
                }
                catch (Exception x)
                {
                    var message = new StringBuilder();
                    message.AppendLine(
                        string.Format(Resources.BackgroundProteomeManager_LoadBackground_Failed_updating_background_proteome__0__,
                                      name));
                    message.Append(x.Message);
                    UpdateProgress(progressStatus.ChangeErrorException(new IOException(message.ToString(), x)));
                    return false;
                }
            }
        }