Exemple #1
0
        private static async Task <int> OnExecuteAsync(Options options)
        {
            if (!options.ListKeys && !options.Sign && !options.VerifySignature)
            {
                throw new Exception(Resources.ValidCommandAction);
            }

            GpgOutputHelper.FileDescriptor = options.StatusFileDescriptor;

            try
            {
                int result = 1;
                if (options.ListKeys)
                {
                    result = await ListKeysAction.Do().ConfigureAwait(false);
                }

                if (options.Sign)
                {
                    result = await SignAction.Do(options.FileNames.FirstOrDefault(), options.LocalUser, options.GetTimestampAuthorityUri(), options.DetachedSign, options.Armor, options.IncludeOption).ConfigureAwait(false);
                }

                if (options.VerifySignature)
                {
                    result = VerifyAction.Do(options.FileNames.ToArray());
                }

                if (result == 1)
                {
                    throw new Exception(Resources.ValidCommandAction);
                }

                return(result);
            }
            catch (SignClientException ex)
            {
                InfoOutputHelper.WriteLine(ex.ToString());
                TelemetryHelper.Client?.TrackException(ex);
            }
            catch (Exception ex)
            {
                InfoOutputHelper.WriteLine(ex.ToString());

                // Don't pass the exception in the generic case, due to it might contain personal information.
                TelemetryHelper.Client?.TrackTrace(ex.GetType().FullName, SeverityLevel.Critical);
            }

            return(1);
        }
Exemple #2
0
        /**
         *  创建草稿
         **/
        private SdkResponse <Contract> Draft(SDKClient client)
        {
            ContractDraftRequest request  = new ContractDraftRequest();
            Contract             contract = new Contract();

            contract.Subject = "合同主题名称";
            //添加平台方签署方
            Signatory platformSignatory = new Signatory("COMPANY", new User("张忱昊", "17621699044", "MOBILE"), 1);

            platformSignatory.TenantName = "大头橙橙汁公司";//平台方公司名称
            //添加平台方签署流程,可根据需要调整
            //目前平台方签署流程为: (1)公章签署(2)法人章签署
            // 公章签署流程,并设置签署公章ID
            SignAction sealAction = new SignAction("COMPANY", 1);

            sealAction.SealId = "2490828768980361630";
            platformSignatory.AddAction(sealAction);
            contract.AddSignatory(platformSignatory);

            //添加个人签署方,并设置个人签署方需要上传的附件内容
            Signatory personalSignatory = new Signatory("PERSONAL", new User("邓茜茜", "15021504325", "MOBILE"), 2);

            personalSignatory.TenantName = "邓茜茜";//接收方名称
            contract.AddSignatory(personalSignatory);

            //设置合同基本信息
            contract.ExpireTime = "2020-07-28 23:59:59"; //设置合同过期时间,合同过期时间需要晚于发起时间
            contract.Send       = false;                 //合同不发起
            request.Contract    = contract;

            string response = null;

            try
            {
                response = client.Service(request);
            }
            catch (Exception e)
            {
                throw new Exception("创建合同草稿请求服务器失败,失败原因" + e.Message);
            }

            SdkResponse <Contract> sdkResponse = HttpJsonConvert.DeserializeResponse <Contract>(response);

            if (!sdkResponse.Code.Equals(0))
            {
                throw new Exception("创建合同草稿失败,失败原因:" + sdkResponse.Message);
            }
            return(sdkResponse);
        }
        public async Task TestSignAndVerifyPemDetached()
        {
            var(outputStream, gpgStream) = GetOutputStreams();
            var certificate = Generate();
            var bytes       = Encoding.UTF8.GetBytes("Hello World");
            var result      = await SignAction.PerformSign(certificate, bytes, null, true, true, X509IncludeOption.WholeChain).ConfigureAwait(false);

            Assert.Equal(0, result);

            var output = GetStreamContents(outputStream).Replace("\r\n", string.Empty).Replace("\n", string.Empty).Replace("\r", string.Empty);
            var gpg    = GetStreamContents(gpgStream);

            output.Should().Be("[GitSMimeSign:] Finished signing");
            gpg.Should().NotBeEmpty();
        }
Exemple #4
0
        private static async Task <int> OnExecuteAsync(Options options)
        {
            if (!options.ListKeys && !options.Sign && !options.VerifySignature)
            {
                throw new Exception(Resources.ValidCommandAction);
            }

            GpgOutputHelper.FileDescriptor = options.StatusFileDescriptor;

            try
            {
                int result = 1;
                if (options.ListKeys)
                {
                    result = await ListKeysAction.Do().ConfigureAwait(false);
                }

                if (options.Sign)
                {
                    result = await SignAction.Do(options.FileNames.FirstOrDefault(), options.LocalUser, options.GetTimestampAuthorityUri(), options.DetachedSign, options.Armor, options.IncludeOption).ConfigureAwait(false);
                }

                if (options.VerifySignature)
                {
                    result = VerifyAction.Do(options.FileNames.ToArray());
                }

                if (result == 1)
                {
                    throw new Exception(Resources.ValidCommandAction);
                }

                return(result);
            }
            catch (SignClientException ex)
            {
                InfoOutputHelper.WriteLine(ex.ToString());
            }
            catch (Exception ex)
            {
                InfoOutputHelper.WriteLine(ex.ToString());
            }

            return(1);
        }
Exemple #5
0
        public async Task TestSignAndVerifyPemDetached()
        {
            var(outputStream, gpgStream) = GetOutputStreams();
            var certificate = Generate();
            var bytes       = Encoding.UTF8.GetBytes("Hello World");
            var result      = await SignAction.PerformSign(certificate, bytes, null, true, true, X509IncludeOption.WholeChain).ConfigureAwait(false);

            Assert.Equal(0, result);

            var output = GetStreamContents(outputStream);
            var gpg    = GetStreamContents(gpgStream);

            output.ShouldBeEmpty();
            gpg.ShouldNotBeEmpty();

            var signature = gpg.Substring(gpg.IndexOf("-----BEGIN SIGNED MESSAGE-----", StringComparison.InvariantCulture));

            var signatureBytes = Encoding.Default.GetBytes(signature);

            Should.NotThrow(() => VerifyAction.VerifyDetached(signatureBytes, bytes, true));
        }