public final ToAsn1Object ( ) : |
||
Результат |
public DerExternal(DerObjectIdentifier directReference, DerInteger indirectReference, Asn1Object dataValueDescriptor, int encoding, Asn1Object externalData) { this.DirectReference = directReference; this.IndirectReference = indirectReference; this.DataValueDescriptor = dataValueDescriptor; this.Encoding = encoding; this.ExternalContent = externalData.ToAsn1Object(); }
/// <summary> /// Questo metodo verifica se l'associazione fra marca e file è valida, verifica inoltre la /// validità del certificato firmatario della marca e la data di scadenza della marca; infine /// restituisce (se le verifiche vanno a buon fine) tutti i dati contenuti nella marca. /// </summary> /// <param name="tsRes"></param> /// <param name="tsReq"></param> /// <returns></returns> protected OutputResponseMarca checkMarca(TimeStampResponse tsRes, TimeStampRequest tsReq) { OutputResponseMarca outTSR = new OutputResponseMarca(); try { tsRes.Validate(tsReq); outTSR.esito = "OK"; outTSR.descrizioneErrore = string.Empty; } catch (TspException e) { outTSR.esito = "KO"; outTSR.descrizioneErrore = "verifica della marca fallita: " + e.Message; logger.Debug("verifica della marca fallita: " + e.Message); //return outTSR; } TimeStampToken tsToken = tsRes.TimeStampToken; //Verifica data scadenza marca secondo l'ora locale Org.BouncyCastle.X509.Store.IX509Store store = tsToken.GetCertificates("Collection"); Org.BouncyCastle.X509.X509Certificate cert = (Org.BouncyCastle.X509.X509Certificate) new ArrayList(store.GetMatches(tsToken.SignerID))[0]; //se la data attuale è maggiore di quella di scadenza del certificato che ha firmato la marca //allora la marca è scaduta!!! if (DateTime.Now.CompareTo(cert.NotAfter.ToLocalTime()) > 0) { //outTSR.esito = "KO"; outTSR.descrizioneErrore = "marca temporale scaduta"; logger.Debug("marca temporale scaduta"); //return outTSR; } try { //estrazione delle informazioni dalla marca outTSR.dsm = cert.NotAfter.ToLocalTime().ToString(); outTSR.sernum = tsToken.TimeStampInfo.SerialNumber.ToString(); outTSR.fhash = byteArrayToHexa(tsToken.TimeStampInfo.TstInfo.MessageImprint.GetHashedMessage()); outTSR.docm = tsToken.TimeStampInfo.TstInfo.GenTime.TimeString; outTSR.docm_date = tsToken.TimeStampInfo.GenTime.ToLocalTime().ToString(); outTSR.marca = Convert.ToBase64String(tsRes.GetEncoded()); outTSR.algCertificato = cert.SigAlgName; outTSR.fromDate = cert.NotBefore.ToLocalTime().ToString(); outTSR.snCertificato = cert.SerialNumber.ToString(); //Algoritmo hash utilizzato per l'impronta string algHashOid = tsToken.TimeStampInfo.MessageImprintAlgOid; if (!string.IsNullOrEmpty(algHashOid)) { System.Security.Cryptography.Oid oidHash = new System.Security.Cryptography.Oid(algHashOid); outTSR.algHash = oidHash.FriendlyName; } outTSR.TSA = new TSARFC2253(); //Con le TSA di test potrebbe non essere valorizzato l'oggetto TSA logger.Debug("Controllo TSA : " + tsToken.TimeStampInfo.Tsa); try { if (tsToken.TimeStampInfo.Tsa != null) { string oid = string.Empty; string oidValue = string.Empty; logger.Debug("TagNo: " + tsToken.TimeStampInfo.Tsa.TagNo); for (int n = 0; n < tsToken.TimeStampInfo.Tsa.TagNo; n++) { logger.Debug("Tag: " + n); Org.BouncyCastle.Asn1.Asn1Sequence seq = (Org.BouncyCastle.Asn1.Asn1Sequence)tsToken.TimeStampInfo.Tsa.Name.ToAsn1Object(); //Obsoleto //Org.BouncyCastle.Asn1.Asn1Object obj = (Org.BouncyCastle.Asn1.Asn1Object)seq.GetObjectAt(n); Org.BouncyCastle.Asn1.Asn1Object obj = (Org.BouncyCastle.Asn1.Asn1Object)seq[n]; Org.BouncyCastle.Asn1.Asn1Set set1 = (Org.BouncyCastle.Asn1.Asn1Set)obj.ToAsn1Object(); //Obsoleto //seq = (Org.BouncyCastle.Asn1.Asn1Sequence)set1.GetObjectAt(0); //obj = (Org.BouncyCastle.Asn1.Asn1Object)seq.GetObjectAt(0); seq = (Org.BouncyCastle.Asn1.Asn1Sequence)set1[0]; obj = (Org.BouncyCastle.Asn1.Asn1Object)seq[0]; oid = obj.ToString(); //Obsoleto //obj = (Org.BouncyCastle.Asn1.Asn1Object)seq.GetObjectAt(1); obj = (Org.BouncyCastle.Asn1.Asn1Object)seq[1]; oidValue = obj.ToString(); System.Security.Cryptography.Oid oid_obj = new System.Security.Cryptography.Oid(oid); string friendly = oid_obj.FriendlyName; logger.Debug("oid: " + oid + " friendly: " + friendly); switch (friendly) { case "CN": outTSR.TSA.CN = oidValue; break; case "OU": outTSR.TSA.OU = oidValue; break; case "O": outTSR.TSA.O = oidValue; break; case "C": outTSR.TSA.C = oidValue; break; } } outTSR.TSA.TSARFC2253Name = "CN=" + outTSR.TSA.CN + ",OU=" + outTSR.TSA.OU + ",O=" + outTSR.TSA.O + ",C=" + outTSR.TSA.C; } } catch (Exception e) { logger.Debug("Eccezione controllo TSA : " + e.Message); } logger.Debug("Fine Controllo TSA"); } catch (Exception eTsp) { outTSR.esito = "KO"; outTSR.descrizioneErrore = "estrazione delle informazioni dalla marca fallita: " + eTsp.Message; logger.Debug("estrazione delle informazioni dalla marca fallita: " + eTsp.Message); //return outTSR; } //verifico l'esistenza del documento al quale è associata la marca temporale //Commentata perchè l'impronta del documento è ancora calcolata con SHA1 invece che SHA256 //DocsPaDB.Query_DocsPAWS.Documenti documento = new DocsPaDB.Query_DocsPAWS.Documenti(); //outTSR.timestampedDoc = documento.GetDocNumberByImpronta(outTSR.fhash); //if (string.IsNullOrEmpty(outTSR.timestampedDoc)) //{ // outTSR.timestampedDoc = "Non esiste alcun documento associato alla marca temporale."; //} //costruisco l'oggetto rappresentante il contenuto in chiaro della marca outTSR.DecryptedTSR = new Marca(); outTSR.DecryptedTSR.content = contentMarca(outTSR); outTSR.DecryptedTSR.contentType = "text/html"; //"application/x-html"; outTSR.DecryptedTSR.length = outTSR.DecryptedTSR.content.Length; return(outTSR); }
/** * Creates a new instance of DerExternal. * See X.690 for more informations about the meaning of these parameters * @param directReference The direct reference or <code>null</code> if not set. * @param indirectReference The indirect reference or <code>null</code> if not set. * @param dataValueDescriptor The data value descriptor or <code>null</code> if not set. * @param encoding The encoding to be used for the external data * @param externalData The external data */ public DerExternal(DerObjectIdentifier directReference, DerInteger indirectReference, Asn1Object dataValueDescriptor, int encoding, Asn1Object externalData) { DirectReference = directReference; IndirectReference = indirectReference; DataValueDescriptor = dataValueDescriptor; Encoding = encoding; ExternalContent = externalData.ToAsn1Object(); }