public string VisualizzaCertificatoHSM(string aliasCertificato, string dominioCertificato, FirmaRemota.FirmaRemotaPortTypeClient client) { if (string.IsNullOrEmpty(dominioCertificato)) { dominioCertificato = ConfigurationManager.AppSettings["HSMCERTDOMAIN"]; } DateTime dataVerifica = DateTime.Now; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Ssl3; try { ClrVerificationService.FirmaRemota.CertificatoType ct = client.VisualizzaCertificato(aliasCertificato, dominioCertificato, out dataVerifica); return(GetCertificateListAsJsonFormat(ct)); } catch (FaultException <FirmaRemota.WSFault> f) { string errMsg = componiErroreWSFault(f.Detail); logger.Error(errMsg); throw new Exception(errMsg); } catch (Exception e) { string errMsg = componiErrore(e, "VisualizzaCertificatoHSM"); logger.Error(errMsg); throw new Exception(errMsg); } }
private string GetCertificateListAsJsonFormat(ClrVerificationService.FirmaRemota.CertificatoType ct) { string jsonCertificateList = ""; string DettaglioB64 = Convert.ToBase64String(System.Text.ASCIIEncoding.Default.GetBytes(ct.dettaglioCertificato)); jsonCertificateList = "["; jsonCertificateList = jsonCertificateList + "{"; jsonCertificateList = jsonCertificateList + "\"Archived\": \"" + "" + "\", "; jsonCertificateList = jsonCertificateList + "\"DigestAlgorithm\": \"" + "" + "\", "; jsonCertificateList = jsonCertificateList + "\"IssuerName\": \"" + ct.issuer.Replace("\"", "\\\"") + "\", "; jsonCertificateList = jsonCertificateList + "\"SerialNumber\": \"" + ct.serialNumber.Replace("\"", "\\\"") + "\", "; jsonCertificateList = jsonCertificateList + "\"SubjectName\": \"" + ct.subject.Replace("\"", "\\\"") + "\", "; jsonCertificateList = jsonCertificateList + "\"ThumbPrint\": \"" + DettaglioB64.Replace("\"", "\\\"") + "\", "; jsonCertificateList = jsonCertificateList + "\"ValidFromDate\": \"" + ct.dataInizioValidita + "\", "; jsonCertificateList = jsonCertificateList + "\"ValidToDate\": \"" + ct.dataFineValidita + "\", "; jsonCertificateList = jsonCertificateList + "\"Version\": \"" + "" + "\""; jsonCertificateList = jsonCertificateList + "} "; jsonCertificateList = jsonCertificateList + "]"; return(jsonCertificateList); }