/// <summary> /// torna l'elenco dei certificati di firma e il certificato con la scadenza più vicina /// </summary> /// <param name="fileName">nome del file</param> /// <param name="Content">contenuto</param> /// <param name="FirstCertificate">ritorna il primo certificato in scadenza</param> /// <returns>elenco dei certificati di firma</returns> public BindingList <DocumentCertificate> GetAllExpireDates(string fileName, DocumentContent Content, out DocumentCertificate FirstCertificate) { BindingList <DocumentCertificate> result = new BindingList <DocumentCertificate>(); using (CompEdLib p7m = new CompEdLib()) { SimplyCert firstExp = new SimplyCert(); Hashtable SimCrtLst; String rt = p7m.GetAllExpiryDate(Content.Blob, out firstExp, out SimCrtLst); if (rt.Length > 0) { throw new Exception(rt); } FirstCertificate = new DocumentCertificate(firstExp.Level, firstExp.Type, firstExp.FiscalCode, firstExp.Role, firstExp.Description, firstExp.Issuer, firstExp.eMail, firstExp.Expiry, firstExp.ValidFrom); DocumentCertificate certificate; foreach (System.Collections.DictionaryEntry obj in SimCrtLst) { SimplyCert crtlo = (SimplyCert)obj.Value; certificate = new DocumentCertificate(crtlo.Level, crtlo.Type, crtlo.FiscalCode, crtlo.Role, crtlo.Description, crtlo.Issuer, crtlo.eMail, crtlo.Expiry, crtlo.ValidFrom); certificate.HeaderInfo = crtlo.HeaderInfo; result.Add(certificate); } } return(result); }
/// <summary> /// torna /// </summary> /// <param name="fileName"></param> /// <param name="p7m"></param> /// <param name="firstExp">il primo certificato che scade</param> /// <param name="SimCrtLst">elenco dei certificati di firma</param> /// <returns></returns> /// <remarks>supporta PAdES</remarks> public String GetExpiryDate(string fileName, byte[] p7m, out SimplyCert firstExp, out SimplyCert[] SimCrtLst) { firstExp = new SimplyCert(); Hashtable HSimCrtLst = new Hashtable(); string result = RecGetAllExpiryDate(1, p7m, ref firstExp, ref HSimCrtLst); SimCrtLst = new SimplyCert[HSimCrtLst.Count]; HSimCrtLst.Values.CopyTo(SimCrtLst, 0); return(result); }
public List <DocumentCertificate> GetDocumentCertificates(byte[] blob) { // usa la List <DocumentCertificate> result = new List <DocumentCertificate>(); using (CompEdLib p7m = new CompEdLib()) { SimplyCert firstExp = new SimplyCert(); Hashtable SimCrtLst; String rt = p7m.GetAllExpiryDate(blob, out firstExp, out SimCrtLst); foreach (SimplyCert thisCert in SimCrtLst.Values) { DocumentCertificate thisDocCert = new DocumentCertificate(); thisDocCert.DateExpiration = thisCert.Expiry; thisDocCert.DateValidFrom = thisCert.ValidFrom; thisDocCert.Description = thisCert.Description; thisDocCert.Email = thisCert.eMail; thisDocCert.FiscalCode = thisCert.FiscalCode; thisDocCert.HeaderInfo = thisCert.HeaderInfo; thisDocCert.IsOnDisk = false; thisDocCert.Issuer = thisCert.Issuer; thisDocCert.Level = thisCert.Level; thisDocCert.Loaded = false; thisDocCert.Role = thisCert.Role; thisDocCert.Type = thisCert.Type; thisDocCert.Id = thisCert.Id; thisDocCert.CertificateVersion = thisCert.Version; thisDocCert.SerialNumber = thisCert.SerialNumber; result.Add(thisDocCert); } } return(result); }
public String RecGetAllExpiryDate(int lev, byte[] p7m, ref SimplyCert firstExp, ref Hashtable SimCrtLst) { string LastErr = ""; try { int nHandle = 0, nCountSignature = 0, nCountTimeStamp = 0, nCountSignaturePDF = 0; int nHandlePDF = 0, nP7KHandle = 0; oDigest.PADES_OpenFromBuf(p7m, out nHandlePDF); if (nHandlePDF > 0) { nCountSignaturePDF = oDigest.PADES_GetSignatureCount(nHandlePDF); for (int j = 0; j < nCountSignature; j++) { int nHandleX509 = 0; Object vtCertBuf = null; oDigest.PADES_GetSignatureObject(nHandlePDF, j, out nP7KHandle); CCypher.enumHashType nEnumHashType = CCypher.enumHashType.HTC_SHA1; CCypher.enumASN1Type cct; object obj; oDigest.P7kGetSignAttribute(nP7KHandle, 0, j, "unstructuredName", out cct, out obj); string tmpHeader = obj as string; oDigest.P7kGetSignerInfo(nP7KHandle, j, out nEnumHashType, out vtCertBuf); oDigest.x509LoadFromBuf(vtCertBuf, out nHandleX509); string sRetInfo = "", Name = "", fc = "", des = "", role = "", iss = "", org = "", email = "", serial = "", vers = "", id = ""; oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_GENERAL, CCypher.enumCertInfoItem.CI_VALID_TO, out sRetInfo); DateTime dt = new DateTime(int.Parse(sRetInfo.Substring(6, 4)), int.Parse(sRetInfo.Substring(3, 2)), int.Parse(sRetInfo.Substring(0, 2))); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_GENERAL, CCypher.enumCertInfoItem.CI_VALID_FROM, out sRetInfo); DateTime dtvf = new DateTime(int.Parse(sRetInfo.Substring(6, 4)), int.Parse(sRetInfo.Substring(3, 2)), int.Parse(sRetInfo.Substring(0, 2))); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_SUBJECT, CCypher.enumCertInfoItem.CI_NAME, out Name); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_SUBJECT, CCypher.enumCertInfoItem.CI_FISCALCODE, out fc); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_ISSUER, CCypher.enumCertInfoItem.CI_NAME, out iss); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_ALL, CCypher.enumCertInfoItem.CI_DESCRIPTION, out des); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_SUBJECT, CCypher.enumCertInfoItem.CI_ROLE, out role); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_SUBJECT, CCypher.enumCertInfoItem.CI_EMAIL, out email); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_GENERAL, CCypher.enumCertInfoItem.CI_SERIALNUMBER, out serial); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_GENERAL, CCypher.enumCertInfoItem.CI_VERSION, out vers); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_GENERAL, CCypher.enumCertInfoItem.CI_ID, out id); if ((DateTime.Compare(firstExp.Expiry, dt) > 0 || j == 0) && firstExp.Type != TOK_TypeTS) { firstExp.Level = lev; firstExp.Type = TOK_TypeSign; firstExp.Name = Name; firstExp.Expiry = dt; firstExp.FiscalCode = fc; firstExp.Role = role; firstExp.Description = des; firstExp.Issuer = iss; firstExp.eMail = email; firstExp.ValidFrom = dtvf; firstExp.HeaderInfo = tmpHeader; firstExp.SerialNumber = serial; firstExp.Version = vers; firstExp.Id = id; } SimplyCert sc = new SimplyCert(); sc.Level = lev; sc.Type = TOK_TypeSign; sc.Name = Name; sc.Expiry = dt; sc.FiscalCode = fc; sc.ValidFrom = dtvf; sc.Description = des; sc.Issuer = iss; sc.Role = role; sc.eMail = email; sc.HeaderInfo = tmpHeader; sc.SerialNumber = serial; sc.Version = vers; sc.Id = id; SimCrtLst.Add((ele++).ToString(), (object)sc); oDigest.x509Free(nHandleX509); oDigest.P7kFree(nP7KHandle); // nei PDF non c'è ricorsione sui contenuti } if (nHandlePDF != 0) { oDigest.PADES_Free(nHandlePDF); } } // Inizio CAdES oDigest.P7kLoadFromBuf(p7m, 1, out nHandle); if (nHandle > 0) { oDigest.P7kGetSignatureCount(nHandle, out nCountSignature); for (int j = 0; j < nCountSignature; j++) { int nHandleX509 = 0; Object vtCertBuf = null; CCypher.enumHashType nEnumHashType = CCypher.enumHashType.HTC_SHA1; CCypher.enumASN1Type cct; object obj; oDigest.P7kGetSignAttribute(nHandle, 0, j, "unstructuredName", out cct, out obj); string tmpHeader = obj as string; oDigest.P7kGetSignerInfo(nHandle, j, out nEnumHashType, out vtCertBuf); oDigest.x509LoadFromBuf(vtCertBuf, out nHandleX509); string sRetInfo = "", Name = "", fc = "", des = "", role = "", iss = "", org = "", email = "", serial = "", vers = "", id = ""; oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_GENERAL, CCypher.enumCertInfoItem.CI_VALID_TO, out sRetInfo); DateTime dt = new DateTime(int.Parse(sRetInfo.Substring(6, 4)), int.Parse(sRetInfo.Substring(3, 2)), int.Parse(sRetInfo.Substring(0, 2))); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_GENERAL, CCypher.enumCertInfoItem.CI_VALID_FROM, out sRetInfo); DateTime dtvf = new DateTime(int.Parse(sRetInfo.Substring(6, 4)), int.Parse(sRetInfo.Substring(3, 2)), int.Parse(sRetInfo.Substring(0, 2))); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_SUBJECT, CCypher.enumCertInfoItem.CI_NAME, out Name); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_SUBJECT, CCypher.enumCertInfoItem.CI_FISCALCODE, out fc); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_ISSUER, CCypher.enumCertInfoItem.CI_NAME, out iss); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_ALL, CCypher.enumCertInfoItem.CI_DESCRIPTION, out des); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_SUBJECT, CCypher.enumCertInfoItem.CI_ROLE, out role); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_SUBJECT, CCypher.enumCertInfoItem.CI_EMAIL, out email); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_GENERAL, CCypher.enumCertInfoItem.CI_SERIALNUMBER, out serial); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_GENERAL, CCypher.enumCertInfoItem.CI_VERSION, out vers); oDigest.x509GetInfo(nHandleX509, CCypher.enumCertInfoCategory.CC_GENERAL, CCypher.enumCertInfoItem.CI_ID, out id); if ((DateTime.Compare(firstExp.Expiry, dt) > 0 || j == 0) && firstExp.Type != TOK_TypeTS) { firstExp.Level = lev; firstExp.Type = TOK_TypeSign; firstExp.Name = Name; firstExp.Expiry = dt; firstExp.FiscalCode = fc; firstExp.Role = role; firstExp.Description = des; firstExp.Issuer = iss; firstExp.eMail = email; firstExp.ValidFrom = dtvf; firstExp.HeaderInfo = tmpHeader; firstExp.SerialNumber = serial; firstExp.Version = vers; firstExp.Id = id; } SimplyCert sc = new SimplyCert(); sc.Level = lev; sc.Type = TOK_TypeSign; sc.Name = Name; sc.Expiry = dt; sc.FiscalCode = fc; sc.ValidFrom = dtvf; sc.Description = des; sc.Issuer = iss; sc.Role = role; sc.eMail = email; sc.HeaderInfo = tmpHeader; sc.SerialNumber = serial; sc.Version = vers; sc.Id = id; SimCrtLst.Add((ele++).ToString(), (object)sc); oDigest.x509Free(nHandleX509); } object OutBuf; oDigest.P7kContentReadToBuf(nHandle, out OutBuf, 0); oDigest.P7kFree(nHandle); RecGetAllExpiryDate(lev + 1, (byte[])OutBuf, ref firstExp, ref SimCrtLst); } // marche temporali oDigest.P7xLoadFromBuf(p7m, out nHandle); if (nHandle > 0) { oDigest.P7xGetTSCount(nHandle, out nCountTimeStamp); //SimCrtLst=new SimplyCert[nCountTimeStamp]; for (int j = 0; j < nCountTimeStamp && LastErr.Length == 0; j++) { int nHandleTS = 0; oDigest.P7xGetTS(nHandle, j, out nHandleTS); if (nHandleTS == 0) { int ErrCode; CCypher.enumErrorClass ErrClass; oDigest.GetLastError(out ErrClass, out ErrCode, out LastErr); } else { object DaT; oDigest.tsGetDateAndTime(nHandleTS, out DaT); DateTime dt = (DateTime)DaT; oDigest.tsGetExpieryDateAndTime(nHandleTS, out DaT); DateTime dte = (DateTime)DaT; if ((DateTime.Compare(firstExp.Expiry, dte) > 0 || j == 0) && firstExp.Type != TOK_TypeTS) { firstExp.Level = lev; firstExp.Type = TOK_TypeTS; firstExp.Name = (j + 1).ToString(); firstExp.Expiry = dte; } SimplyCert sc = new SimplyCert(); sc.Level = lev; sc.Type = TOK_TypeTS; oDigest.tsGetTSPInfo(nHandleTS, CCypher.enumCertInfoCategory.CC_SUBJECT, CCypher.enumCertInfoItem.CI_NAME, out sc.Name); oDigest.tsGetTSPInfo(nHandleTS, CCypher.enumCertInfoCategory.CC_ISSUER, CCypher.enumCertInfoItem.CI_NAME, out sc.Issuer); oDigest.tsGetTSPInfo(nHandleTS, CCypher.enumCertInfoCategory.CC_ALL, CCypher.enumCertInfoItem.CI_NAME, out sc.Description); //sc.Name=(j+1).ToString(); sc.Expiry = dte; sc.ValidFrom = dt; SimCrtLst.Add((ele++).ToString(), (object)sc); oDigest.tsFree(nHandleTS); } } object OutBuf; oDigest.P7xContentReadToBuf(nHandle, out OutBuf, 0); oDigest.P7xFree(nHandle); RecGetAllExpiryDate(lev + 1, (byte[])OutBuf, ref firstExp, ref SimCrtLst); } } catch (Exception e) { LastErr = e.Message; } return(LastErr); }
public String GetAllExpiryDate(byte[] p7m, out SimplyCert firstExp, out Hashtable SimCrtLst) { firstExp = new SimplyCert(); SimCrtLst = new Hashtable(); return(RecGetAllExpiryDate(1, p7m, ref firstExp, ref SimCrtLst)); }
public void GetExpiryDates(string fileName, string encObj, out SimplyCert firstExpCertificate) { Service.GetExpiryDates(fileName, encObj, out firstExpCertificate); }