【问题标题】:Invalid signature when signing an existing signature field with CoSign SAPI使用 CoSign SAPI 签署现有签名字段时签名无效
【发布时间】:2017-07-11 07:09:27
【问题描述】:

我有一个包含多个签名字段的 pdf。我正在使用 iTextSharp 来创建带有签名字段的 pdf,并且我正在尝试使用 CoSign SAPI 对每个签名字段进行签名。当我从调用的响应中附加签名对象时,签名无效。

下面是我使用的代码示例,用于从包含许多(签名字段)的 pdf 文档中对现有签名字段进行签名:

public void SignDocument(string filePath, string fieldName, string username, string password)
        {
            byte[] fileBuffer = File.ReadAllBytes(filePath);
            DocumentType document = new DocumentType()
            {
                Item = new DocumentTypeBase64Data()
                {
                    Value = fileBuffer,
                    MimeType = "application/pdf"
                }
            };
            ClaimedIdentity claimedIdentity = new ClaimedIdentity()
            {
                Name = new NameIdentifierType()
                {
                    Value = username
                },
                SupportingInfo = new CoSignAuthDataType()
                {
                    LogonPassword = password
                }
            };
            SAPISigFieldSettingsType sigFieldSettings = new SAPISigFieldSettingsType()
            {
                Invisible = true,
                InvisibleSpecified = true,
                X = 145,
                XSpecified = true,
                Y = 125,
                YSpecified = true,
                Width = 160,
                WidthSpecified = true,
                Height = 45,
                HeightSpecified = true,
                Page = 1,
                PageSpecified = true,
                AppearanceMask = 11,
                AppearanceMaskSpecified = true,
                TimeFormat = new TimeDateFormatType()
                {
                    TimeFormat = "hh:mm:ss",
                    DateFormat = "dd/MM/yyyy",
                    ExtTimeFormat = ExtendedTimeFormatEnum.GMT,
                    ExtTimeFormatSpecified = true
                }
            };

            SignRequest signRequest = new SignRequest()
            {
                InputDocuments = new RequestBaseTypeInputDocuments()
                {
                    Items = new DocumentType[] { document }
                },
                OptionalInputs = new RequestBaseTypeOptionalInputs()
                {
                    SignatureType = "http://arx.com/SAPIWS/DSS/1.0/signature-field-sign",
                    ClaimedIdentity = claimedIdentity,
                    SAPISigFieldSettings = sigFieldSettings,
                    ReturnPDFTailOnly = true,
                    ReturnPDFTailOnlySpecified = true,
                    SignatureFieldName = fieldName
                }
            };
            DssSignResult response = _client.DssSign(signRequest);

            if (response.Result.ResultMajor.Equals(SIGN_SUCCESS_RESULT_MAJOR))
            {
                byte[] signatureBuffer = ((DssSignResultSignatureObjectBase64Signature)response.SignatureObject.Item).Value;
                using (var fileStream = new FileStream(filePath, FileMode.Append))
                {
                    fileStream.Write(signatureBuffer, 0, signatureBuffer.Length);
                }
            }
            else
            {
                throw new Exception(response.Result.ResultMessage.Value);
            }
        }

file

这是我要签名的文件。我正在尝试签署签名字段“sig2-9”,但签名无效,并显示消息“对此文档进行了更改,导致签名无效”。很抱歉没有发布签名文件,但证书所有者不想分享他的个人信息。

signed file

这是带有无效签名的签名文件。

signed file 2

这是我用另一个 CoSign api 调用签名的文件。此调用创建签名字段并使用与“签名文件”相同的证书对其进行签名。如您所见,此示例中的签名是有效的。在此示例中,我使用了“http://arx.com/SAPIWS/DSS/1.0/signature-field-create-sign”签名类型。

【问题讨论】:

  • 我不认识代码(可能是因为它是 cosign 代码),但是如果您使用 iText 创建 PDF,为什么不使用 iText 签署 PDF?
  • @BrunoLowagie “你为什么不用 iText 签署 PDF” - 我认为问题是关于通过 DocuSign 签署的。有没有一种简单的方法可以将 DocuSign 集成到 iText 签名中? (实际上我还没有玩过 DocuSign,所以我不知道这会是多么复杂或容易......)
  • DocuSign 是 iText 的客户,因此这两种技术应该可以很好地协同工作,但我对 CoSign API 不熟悉。
  • @BrunoLowagie - 我不能使用 iTextSharp 来签署 pdf 文件,因为私钥存储在 CoSign 服务器上。我使用 pdf 文件在 CoSign 服务器上进行 Soap 调用,服务器返回文件的签名哈希。当我完成签名并打开文件时,签名无效。
  • 好吧@mkl,假设 Kostas 是 CoSign/Docusign 的客户,解决此问题的最佳方法是联系 Docusign 的客户支持,并要求他们在 iText 提交支持票。跨度>

标签: itext digital-signature docusignapi cosign-api


【解决方案1】:

布鲁诺和 mkl。

我叫 Aviv Simionovici,是 DocuSign 的 DSA(DocuSign 签名设备)API 专家。

您的代码看起来不错,但您可能忘记了以下内容:

Req.OptionalInputs.ReturnPDFTailOnlySpecified = true;
Req.OptionalInputs.ReturnPDFTailOnly = true;

为方便起见,这里有一个将签名附加到 PDF 的函数:

public bool PDFAttachSignature(string PDFFile, byte[] Signature, bool isDisplayErrorsGUI)
{
   if (Signature == null) return false;
   try
   {
      FileStream f = File.OpenWrite(PDFFile);
      f.Position = f.Length;  //seek to the end of file
      f.Write(Signature, 0, Signature.Length); //write the signature content
      f.Close();
   }
   catch (Exception ex)
   {
      if (isDisplayErrorsGUI)
         MessageBox.Show("Error Attaching the signature\n\nException:\n" + ex.Message, "Error");
         return false;
   }

   return true;
}

带有示例的整个visual studio项目是here

您声明当您使用 PDF 查看器打开 PDF 时签名无效。这也可能是由于证书链中以 DSA 根证书结尾的不受信任的证书而发生的。或者因为无法撤销该链上的证书。请查看签名无效的原因。

【讨论】:

  • 虽然很高兴能与个人联系,但主要收件人应该是问题的原始发帖人 Kostas Patakakis。此外,“请查看为什么签名无效。” - 为了了解这一点,我已经在评论中要求 OP 分享说明该问题的示例 PDF。
  • 感谢 Aviv 的回复,但我对您的解决方案也有同样的问题。我更新了帖子并附上了我要签名的 pdf。
  • @Aviv Kostas 的示例文档包含签名锁定字典。 DSA / Docusign 是否妥善处理它们?
  • @Kostas - 当我打开已签名的文档时,我收到一条错误消息,提示“证书或证书链中的证书之一的吊销状态未知”。此错误与生成签名的代码无关。实际上,最近,prime.cosigntrial.com 信任链上的一个中间证书指向的 CRL 已失效。您应该在使用 prime.cosigntrial.com 的旧帐户执行的每个签名中都期待它。我建议尝试以下方法:1)使用 CoSign 客户端签名 2)删除“仅尾部”3)使用 cosigndemo.arx.com 签名
  • @AvivSimionovici 当我在 Adob​​e Acrobat Reader DC 中打开 OP 的 signed file 时,它显示 these signature properties;问题不是任何撤销或信任问题,而是 Adob​​e 声称“自应用签名以来,文档已被更改或损坏”。正如 Adob​​e 显示的那样,即使在将 PDF 缩减为实际签名的修订版之后,这也不是由于增量更新中的任何添加。 Adobe 确实认为哈希值是错误的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-19
  • 1970-01-01
  • 2014-03-14
  • 1970-01-01
  • 2016-12-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多