public byte[] FirmaFilePADES(byte[] fileDafirmare, string aliasCertificato, string dominioCertificato, string pinCertificato, string otpFirma, bool marcaTemporale, object client) { ArubaSignServiceService wsclient = client as ArubaSignServiceService; if (wsclient == null) { return(null); } ArubaConnector.ArubaSignServices.auth authData = new ArubaConnector.ArubaSignServices.auth { otpPwd = otpFirma, user = aliasCertificato, userPWD = pinCertificato, typeOtpAuth = dominioCertificato, typeHSM = "COSIGN" // come specificato a pagina 9 del manuale ARSS Developer Guide v1.0 }; ArubaConnector.ArubaSignServices.signRequestV2 sr = new ArubaConnector.ArubaSignServices.signRequestV2 { binaryinput = fileDafirmare, transport = ArubaConnector.ArubaSignServices.typeTransport.BYNARYNET, transportSpecified = true, requiredmark = marcaTemporale, identity = authData, certID = "AS0", profile = null }; ArubaConnector.ArubaSignServices.pdfSignApparence pdfsignApp = new ArubaConnector.ArubaSignServices.pdfSignApparence { page = 1 }; ArubaConnector.ArubaSignServices.signReturnV2 retval = wsclient.pdfsignatureV2(sr, pdfsignApp, ArubaSignServices.pdfProfile.PADESBES, false, ""); if (retval.status.Equals("OK")) { return(retval.binaryoutput); } else { string errorCode = retval.return_code; string errorMessage = retval.description; string faultMSG = String.Format("WSFAULT #CODE {0} #MESSAGE {1} #TYPE {2}#", errorCode, errorMessage, "ERROR"); logger.ErrorFormat("Errore in FirmaFilePADES Codice {0} Messaggio {1}", errorCode, errorMessage); throw new Exception(faultMSG); /* * "0001" -> Errore generico nel processo di firma * "0002" -> Parametri non corretti per il tipo di trasporto indicato * "0003" -> Errore in fase di verifica delle credenziali * "0004" -> Errore nel PIN (maggiori dettagli su SignReturnV2.description) * "0005" -> Tipo di trasporto non valido * "0006" -> Tipo di trasporto non autorizzato */ } }
public bool Session_RemoteSign(string SessionToken, string aliasCertificato, string dominioCertificato, string pinCertificato, string otpFirma, object client) { List <byte[]> filesRead = new List <byte[]>(); SessionToken = SessionToken.ToUpper(); ArubaSignServiceService wsclient = client as ArubaSignServiceService; if (wsclient == null) { return(false); } ArubaConnector.ArubaSignServices.auth authData = new ArubaConnector.ArubaSignServices.auth { otpPwd = otpFirma, user = aliasCertificato, userPWD = pinCertificato, typeOtpAuth = dominioCertificato, typeHSM = "COSIGN" // come specificato a pagina 9 del manuale ARSS Developer Guide v1.0 }; ArubaConnector.ArubaSignServices.pdfSignApparence pdfsignApp = new ArubaConnector.ArubaSignServices.pdfSignApparence { page = 1 }; string cacheDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MultiSignWorkDir"); string sessionDir = Path.Combine(cacheDir, SessionToken); if (Directory.Exists(sessionDir)) { string manifestFile = Path.Combine(sessionDir, "Manifest.xml"); if (File.Exists(manifestFile)) { String manifestXML = File.ReadAllText(manifestFile); Manifest.ManifestFile mft = Manifest.ManifestFile.Deserialize(manifestXML); string sessionID = wsclient.opensession(authData); if (sessionID == "KO-0001") { string errMsg = String.Format("WSFAULT #CODE {0} #MESSAGE {1} #TYPE {2}#", sessionID, "Errore generico", "ERROR"); logger.Error(errMsg); throw new Exception(errMsg); } if (sessionID == "KO-0003") { string errMsg = String.Format("WSFAULT #CODE {0} #MESSAGE {1} #TYPE {2}#", sessionID, "Errore in fase di verifica delle credenziali", "ERROR"); logger.Error(errMsg); throw new Exception(errMsg); } if (sessionID == "KO-0004") { string errMsg = String.Format("WSFAULT #CODE {0} #MESSAGE {1} #TYPE {2}#", sessionID, "Errore nel PIN", "ERROR"); logger.Error(errMsg); throw new Exception(errMsg); } foreach (Manifest.MainfestFileInformation FileInformation in mft.FileInformation) { byte[] content = File.ReadAllBytes(Path.Combine(sessionDir, FileInformation.OriginalFullName)); ArubaConnector.ArubaSignServices.signReturnV2 retval = null; ArubaConnector.ArubaSignServices.signRequestV2 sr = new ArubaConnector.ArubaSignServices.signRequestV2 { binaryinput = content, transport = ArubaConnector.ArubaSignServices.typeTransport.BYNARYNET, transportSpecified = true, requiredmark = mft.timestamp, identity = authData, certID = "AS0", profile = null }; if (mft.SignatureType == Manifest.SignType.CADES) { if (mft.cosign) //aggiunta firma parallela. { retval = wsclient.addpkcs7sign(sr, false); } else { retval = wsclient.pkcs7signV2(sr, false, false); } if (retval.status.Equals("OK")) { filesRead.Add(retval.binaryoutput); } else { string errorCode = retval.return_code; string errorMessage = retval.description; string faultMSG = String.Format("WSFAULT #CODE {0} #MESSAGE {1} #TYPE {2}#", errorCode, errorMessage, "ERROR"); logger.ErrorFormat("Errore in pkcs7signV2 o addpkcs7sign / multi Codice {0} Messaggio {1}", errorCode, errorMessage); filesRead.Add(null); } } else { retval = wsclient.pdfsignatureV2(sr, pdfsignApp, ArubaSignServices.pdfProfile.PADESBES, false, ""); if (retval.status.Equals("OK")) { filesRead.Add(retval.binaryoutput); } else { string errorCode = retval.return_code; string errorMessage = retval.description; string faultMSG = String.Format("WSFAULT #CODE {0} #MESSAGE {1} #TYPE {2}#", errorCode, errorMessage, "ERROR"); logger.ErrorFormat("Errore in pdfsignatureV2_multi Codice {0} Messaggio {1}", errorCode, errorMessage); filesRead.Add(null); } } } int index = 0; foreach (Manifest.MainfestFileInformation FileInformation in mft.FileInformation) { byte[] content = filesRead[index++]; string newName = "signed_" + FileInformation.OriginalFullName; File.WriteAllBytes(Path.Combine(sessionDir, newName), content); FileInformation.SignedFullName = newName; } File.WriteAllText(manifestFile, mft.Serialize()); string closeRetval = wsclient.closesession(authData, sessionID); if (closeRetval == "KO-0001") { string errMsg = String.Format("WSFAULT #CODE {0} #MESSAGE {1} #TYPE {2}#", sessionID, "Errore generico", "ERROR"); logger.Error(errMsg); throw new Exception(errMsg); } return(true); } } return(false); }