Errore marcatura temporale TSA

8/20/2015 1:22:28 PM
Gravatar
Total Posts 1

Errore marcatura temporale TSA

Visual Studio 2005 - .NET 2.0
NCryptoki.dll <span data-scayt_word="versione" data-scaytid="873" style="background-color: rgb(255, 255, 255);">versione 1.5.3.1
NDigitSign.dll <span data-scayt_word="versione" data-scaytid="976" style="background-color: rgb(255, 255, 255);">versione 1.3.1.1
NCryptoMngd.dll <span data-scayt_word="versione" data-scaytid="1079" style="background-color: rgb(255, 255, 255);">versione 1.1.2.1
NSCAPI.dll <span data-scayt_word="versione" data-scaytid="1168" style="background-color: rgb(255, 255, 255);">versione 1.2.1.2
itextsharp.dll <span data-scayt_word="versione" data-scaytid="1275" style="background-color: rgb(255, 255, 255);">versione 5.0.5.0
BouncyCastle.Crypto.dll <span data-scayt_word="versione" data-scaytid="1367" style="background-color: rgb(255, 255, 255);">versione 1.7.4675.27319

 

La <span data-scayt_word="sola" data-scaytid="1570">sola firma <span data-scayt_word="dei" data-scaytid="1594">dei <span data-scayt_word="documenti" data-scaytid="1595">documenti <span data-scayt_word="funziona" data-scaytid="1622">funziona <span data-scayt_word="correttamente" data-scaytid="1651">correttamente. <span data-scayt_word="Quando" data-scaytid="1551">Quando <span data-scayt_word="invece" data-scaytid="1683">invece <span data-scayt_word="tento" data-scaytid="705" style="background-color: rgb(255, 255, 255);">tento <span data-scayt_word="di" data-scaytid="727" style="background-color: rgb(255, 255, 255);">di <span data-scayt_word="firmare" data-scaytid="821" style="background-color: rgb(255, 255, 255);">firmare e <span data-scayt_word="marcare" data-scaytid="783" style="background-color: rgb(255, 255, 255);">marcare <span data-scayt_word="temporalmente" data-scaytid="1753">temporalmente <span data-scayt_word="ottengo" data-scaytid="21" style="background-color: rgb(255, 255, 255);">ottengo <span data-scayt_word="il" data-scaytid="858" style="background-color: rgb(255, 255, 255);">il <span data-scayt_word="seguente" data-scaytid="859" style="background-color: rgb(255, 255, 255);">seguente <span data-scayt_word="errore" data-scaytid="860" style="background-color: rgb(255, 255, 255);">errore:

 

malformed timestamp response: System.ArgumentException: Unknown object in '<span data-scayt_word="TimeStampResp" data-scaytid="2" style="background-color: rgb(255, 255, 255);">TimeStampResp' factory: Org.BouncyCastle.Asn1.DerUnknownTag

   in Org.BouncyCastle.Asn1.Tsp.TimeStampResp.GetInstance(Object o)
   in Org.BouncyCastle.Tsp.TimeStampResponse.readTimeStampResp(<span data-scayt_word="Asn1InputStream" data-scaytid="3">Asn1InputStream input)

 

<span data-scayt_word="Questo" data-scaytid="395">Questo <span data-scayt_word="è" data-scaytid="422">è <span data-scayt_word="il" data-scaytid="1487">il <span data-scayt_word="codice" data-scaytid="423">codice <span data-scayt_word="di" data-scaytid="1461">di <span data-scayt_word="esempio" data-scaytid="424">esempio <span data-scayt_word="che" data-scaytid="425">che <span data-scayt_word="uso" data-scaytid="426">uso per <span data-scayt_word="firmare" data-scaytid="427">firmare e <span data-scayt_word="marcare" data-scaytid="428">marcare un <span data-scayt_word="documento" data-scaytid="429">documento:

 

    Dim <span data-scayt_word="cfgInput" data-scaytid="626">cfgInput as string = "prova.pdf"
    Dim <span data-scayt_word="cfgOutput" data-scaytid="627">cfgOutput as string = "prova.pdf.p7m.m7m"
    Dim <span data-scayt_word="cfgPKCS" data-scaytid="628">cfgPKCS as string = "bit4ipki.dll"
    Dim <span data-scayt_word="iSlotSel" data-scaytid="629">iSlotSel as integer = 0
    Dim <span data-scayt_word="cfgPIN" data-scaytid="630">cfgPIN as string = "12345678"
    ' Test <span data-scayt_word="TS" data-scaytid="631">TS
    Dim <span data-scayt_word="cfgTSUrl" data-scaytid="632">cfgTSUrl as string = "https://portal.actalis.it/<span data-scayt_word="tsa" data-scaytid="633">tsa<span data-scayt_word="/FrontEnd" data-scaytid="1013">/<span data-scayt_word="FrontEnd" data-scaytid="634">FrontEnd"
    Dim <span data-scayt_word="cfgTSuser" data-scaytid="635">cfgTSuser as string = "<span data-scayt_word="xxxx" data-scaytid="636">xxxx"
    Dim <span data-scayt_word="cfgTSpwd" data-scaytid="637">cfgTSpwd as string = "<span data-scayt_word="yyyy" data-scaytid="638">yyyy"
    ' Test <span data-scayt_word="TS" data-scaytid="639">TS con proxy
    Dim <span data-scayt_word="cfgProxyHost" data-scaytid="640">cfgProxyHost as string = "proxy-server"
    Dim <span data-scayt_word="cfgProxyPort" data-scaytid="641">cfgProxyPort as integer = 3128
    Dim <span data-scayt_word="cfgProxyUser" data-scaytid="642">cfgProxyUser as string = "<span data-scayt_word="aaaa" data-scaytid="643">aaaa"
    Dim <span data-scayt_word="cfgProxyPwd" data-scaytid="644">cfgProxyPwd as string = "<span data-scayt_word="bbbb" data-scaytid="645">bbbb"

    <span data-scayt_word="dsign" data-scaytid="576">dsign = New <span data-scayt_word="DigitalSigner" data-scaytid="577">DigitalSigner(<span data-scayt_word="cfgPKCS" data-scaytid="578">cfgPKCS)
    dsign.OpenSession(<span data-scayt_word="iSlotSel" data-scaytid="579">iSlotSel)
    dsign.Login(<span data-scayt_word="cfgPIN" data-scaytid="580">cfgPIN)
    Dim <span data-scayt_word="sel" data-scaytid="581">sel = New <span data-scayt_word="QualifiedCertificateSelector" data-scaytid="583">QualifiedCertificateSelector
    Dim <span data-scayt_word="tsa" data-scaytid="584">tsa As <span data-scayt_word="TSAClient" data-scaytid="588">TSAClient = Nothing
    If <span data-scayt_word="cfgTSurl" data-scaytid="591">cfgTSurl <> "" Then
        If <span data-scayt_word="cfgProxyHost" data-scaytid="594">cfgProxyHost <> "" And <span data-scayt_word="cfgProxyPort" data-scaytid="596">cfgProxyPort > 0 Then
            Dim pr As New <span data-scayt_word="WebProxy" data-scaytid="598">WebProxy(<span data-scayt_word="cfgProxyHost" data-scaytid="595">cfgProxyHost, <span data-scayt_word="cfgProxyPort" data-scaytid="597">cfgProxyPort)
            If <span data-scayt_word="cfgProxyUser" data-scaytid="599">cfgProxyUser <> "" Then pr.Credentials = New <span data-scayt_word="NetworkCredential" data-scaytid="601">NetworkCredential(<span data-scayt_word="cfgProxyUser" data-scaytid="600">cfgProxyUser, <span data-scayt_word="cfgProxyPwd" data-scaytid="602">cfgProxyPwd)
            TSAClient.Proxy = pr
        End If
        If <span data-scayt_word="cfgTSuser" data-scaytid="603">cfgTSuser = "" Then
            <span data-scayt_word="tsa" data-scaytid="585">tsa = New <span data-scayt_word="TSAClient" data-scaytid="589">TSAClient(<span data-scayt_word="cfgTSurl" data-scaytid="592">cfgTSurl)
        Else
            <span data-scayt_word="tsa" data-scaytid="586">tsa = New <span data-scayt_word="TSAClient" data-scaytid="590">TSAClient(<span data-scayt_word="cfgTSurl" data-scaytid="593">cfgTSurl, <span data-scayt_word="cfgTSuser" data-scaytid="604">cfgTSuser, <span data-scayt_word="cfgTSpwd" data-scaytid="605">cfgTSpwd)
        End If
    End If
    dsign.CAdES = True
    dsign.Multisignature = false
    dsign.AddCACertificate = True
    dsign.Detached = False
    dsign.TsaClient = <span data-scayt_word="tsa" data-scaytid="587">tsa
    Dim <span data-scayt_word="sd" data-scaytid="606">sd As <span data-scayt_word="SignedDocument" data-scaytid="607">SignedDocument = dsign.Sign(data, <span data-scayt_word="sel" data-scaytid="582">sel)
    Dim <span data-scayt_word="signedData" data-scaytid="608">signedData(sd.ToByteArray().Length) As Byte
    <span data-scayt_word="signedData" data-scaytid="609">signedData = sd.ToByteArray
    dsign.Logout()
    dsign.CloseSession()
    dsign.Finalize()
    File.Delete(<span data-scayt_word="cfgOutput" data-scaytid="611">cfgOutput)
    Dim <span data-scayt_word="fso" data-scaytid="613">fso As New <span data-scayt_word="FileStream" data-scaytid="614">FileStream(<span data-scayt_word="cfgOutput" data-scaytid="612">cfgOutput, FileMode.CreateNew)
    fso.Write(<span data-scayt_word="signedData" data-scaytid="610">signedData, 0, <span data-scayt_word="CInt" data-scaytid="615">CInt(signedData.Length))
    fso.Close()

6/22/2016 12:32:16 PM
Gravatar
Total Posts 5

Re: Errore marcatura temporale TSA

Hi,

 

To me, works with this code :

<span data-scayt_word="var" data-scaytid="15">var selector = new <span data-scayt_word="ByIdCertificateSelector" data-scaytid="16">ByIdCertificateSelector(<span data-scayt_word="certificateId" data-scaytid="17">certificateId);
<span data-scayt_word="var" data-scaytid="19">var <span data-scayt_word="pdfSigner" data-scaytid="22">pdfSigner = new <span data-scayt_word="PDFDigitalSigner" data-scaytid="23">PDFDigitalSigner(<span data-scayt_word="digitalSigner" data-scaytid="24">digitalSigner);

pdfSigner.AddCACertificate = true;

if (timestamp)
{

       pdfSigner.TsaClient = new <span data-scayt_word="TSAClient" data-scaytid="3">TSAClient(Configuration.TSAClientUrl,Configuration.TSAClientUserName,Configuration.TSAClientPassword);
}
try
{
    pdfSigner.SignPDFFile(<span data-scayt_word="inFileName" data-scaytid="55">inFileName, selector, <span data-scayt_word="outFileName" data-scaytid="56">outFileName);
}
catch (<span data-scayt_word="DigitalSignatureException" data-scaytid="57">DigitalSignatureException ex)
{
    Logger.Log.Error(() => "error code -> " + ex.ErrorCode.ToString("x"));
    Logger.Log.Error(() => "error string -> " + ex.ErrorString);

    throw;
}

 

But timestamp is generated without ca subordinated and some tools show a error, like certificate is not associated to timestamp.

 

Regards

6/30/2016 10:54:18 AM
Gravatar
Total Posts 30

Re: Errore marcatura temporale TSA

<span data-scayt_word="Considerando" data-scaytid="5">Considerando lo <span data-scayt_word="stacktrace" data-scaytid="6">stacktrace <span data-scayt_word="che" data-scaytid="11">che <span data-scayt_word="ci" data-scaytid="12">ci <span data-scayt_word="hai" data-scaytid="13">hai <span data-scayt_word="inviato" data-scaytid="14">inviato <span data-scayt_word="sembrerebbe" data-scaytid="34">sembrerebbe un <span data-scayt_word="problema" data-scaytid="35">problema <span data-scayt_word="dovuto" data-scaytid="52">dovuto al <span data-scayt_word="formato" data-scaytid="143">formato del response <span data-scayt_word="della" data-scaytid="71">della <span data-scayt_word="timestamping" data-scaytid="82">timestamping authority <span data-scayt_word="di" data-scaytid="94">di <span data-scayt_word="actalis" data-scaytid="107">actalis.

<span data-scayt_word="Difatti" data-scaytid="228">Difatti <span data-scayt_word="fallisce" data-scaytid="229">fallisce <span data-scayt_word="il" data-scaytid="230">il parsing del TSA response. 

<span data-scayt_word="Sei" data-scaytid="241">Sei <span data-scayt_word="sicuro" data-scaytid="152">sicuro <span data-scayt_word="che" data-scaytid="150">che la TSA <span data-scayt_word="abbia" data-scaytid="160">abbia <span data-scayt_word="risposto" data-scaytid="169">risposto con un timestamp e non con un <span data-scayt_word="errore" data-scaytid="185">errore (<span data-scayt_word="es" data-scaytid="198">es password errata o <span data-scayt_word="qualcos'altro" data-scaytid="220">qualcos'altro)?