public IActionResult RequestStoreKeys(InfoClients infoClients) { //Write Event var jsonObj = JsonConvert.SerializeObject(infoClients); FileWriter.WriteOnEvents(EventLevel.Info, "Request en RequestStoreKeys ObjKeyService recibido " + string.Join(", ", jsonObj)); //Store partner's public key FileWriter.WriteOnFile(parameters.Value.FilesOutput, parameters.Value.PubKeyFile + infoClients.userNameOrigin + infoClients.userNameDestination, infoClients.keyEncrypt); FileWriter.WriteOnEvents(EventLevel.Info, "Llave publica de " + infoClients.userNameOrigin + infoClients.userNameDestination + " almacenada."); //Delete and generate the own RSA Keys infoClients.keyEncrypt = ""; RSAEncryption rsaEncryption = new RSAEncryption(); string filePublicKey = parameters.Value.FilesOutput + parameters.Value.PubKeyFile + infoClients.userNameOrigin + infoClients.userNameDestination; infoClients.keyEncrypt = rsaEncryption.GeneratePubPrivKeys(infoClients.userNameOrigin + infoClients.userNameDestination, filePublicKey); //Inverting usernames origin-destination string auxUserName = infoClients.userNameOrigin; infoClients.userNameOrigin = infoClients.userNameDestination; infoClients.userNameDestination = auxUserName; if (infoClients.keyEncrypt != "") { FileWriter.WriteOnEvents(EventLevel.Info, "Devolviendo llaves generadas."); return(Ok(infoClients)); } else { FileWriter.WriteOnEvents(EventLevel.Error, "Error generando llaves."); return(BadRequest(infoClients)); } }
public bool SendMyPublicKey(InfoClients infoClients) { bool result = false; FileWriter.WriteOnEvents(EventLevel.Info, "Llamado al servidor para entrega de llave privada."); try { ServerRequest callPartner = new ServerRequest(parameters.Value.EndpointServer, parameters.Value.RequestKeyPartner, parameters.Value.GetRequest); HttpStatusCode resultCode = new HttpStatusCode(); Task <HttpStatusCode> response = callPartner.RequestPartnerKey(infoClients); response.ContinueWith(task => { resultCode = task.Result; }, TaskContinuationOptions.OnlyOnRanToCompletion); //Check the response values, if isn´t success set false if (resultCode.Equals(HttpStatusCode.NotFound)) { FileWriter.WriteOnEvents(EventLevel.Atention, "Respuesta no satisfactoria. resultCode:" + resultCode); result = false; } else { FileWriter.WriteOnEvents(EventLevel.Info, "Llave enviada de forma satisfactoria. resultCode:" + resultCode); result = true; } } catch (System.Exception ex) { FileWriter.WriteOnEvents(EventLevel.Exception, "Excepcion en GeneratekeyEncrypts. " + ex.Message); result = false; } return(result); }
public static void set() { List <object[]> S = new ClassDB(null).queryResonse("SELECT * FROM InfoClients WHERE TypeClient ='2'"); foreach (object[] s in S) { InfoClients ic = new InfoClients(); ic.custumerId = (Guid)s[0]; ic.TypeClient = (int)s[1]; ic.Sex = (int)s[2]; ic.Name = s[3].ToString(); ic.Surname = s[4].ToString(); ic.NameCompany = s[5].ToString(); ic.SIRET = s[6].ToString(); ic.FRTVA = s[7].ToString(); ic.OfficeAddress = s[8].ToString(); ic.OfficeZipCode = s[9].ToString(); ic.OfficeCity = s[10].ToString(); ic.HomeAddress = s[11].ToString(); ic.HomeZipCode = s[12].ToString(); ic.HomeCity = s[13].ToString(); ic.Telephone = s[14].ToString(); ic.Mail = s[15].ToString(); ic.Password = s[16].ToString(); ic.Countrys_CustomerId = (Guid)s[17]; ic.FavoritesProductAutoCustomerId = (Guid)s[18]; ic.Nclient = s[19].ToString(); list.Add(ic); } }
public IActionResult GeneratekeyEncrypts(InfoClients infoclient) { //Serialize and store the request info var jsonObj = JsonConvert.SerializeObject(infoclient); FileWriter.WriteOnEvents(EventLevel.Info, "Request en GeneratekeyEncrypts ObjKeyService recibido " + string.Join(", ", jsonObj)); //Generate the own RSA Keys RSAEncryption rsaEncryption = new RSAEncryption(); string filePublicKey = parameters.Value.FilesOutput + parameters.Value.PubKeyFile + infoclient.userNameDestination + infoclient.userNameOrigin + ".xml"; infoclient.keyEncrypt = rsaEncryption.GeneratePubPrivKeys(infoclient.userNameDestination + infoclient.userNameOrigin, filePublicKey); //Call the server service to send my public key to my partner if (SendMyPublicKey(infoclient)) { FileWriter.WriteOnEvents(EventLevel.Info, "Proceso de generacion y envio de llaves realizado de forma correcta."); return(Ok("Proceso de generacion y envio de llaves realizado de forma correcta.")); } FileWriter.WriteOnEvents(EventLevel.Atention, "Ocurrieron errores en el proceso, verifique e intente nuevamente."); return(BadRequest("Ocurrieron errores en el proceso, verifique el log e intente nuevamente.")); }
public IActionResult StoreKey(InfoClients infoClients) { //Write Event var jsonObj = JsonConvert.SerializeObject(infoClients); FileWriter.WriteOnEvents(EventLevel.Info, "Request en StoreKey ObjKeyService recibido " + string.Join(", ", jsonObj)); //Check data if (infoClients.keyEncrypt == "") { FileWriter.WriteOnEvents(EventLevel.Error, "Llave recibida vacia, no se puede almacenar."); return(Ok(new { mensaje = "Llave vacia." })); } //Store partner's public key FileWriter.WriteOnFile(parameters.Value.FilesOutput, parameters.Value.PubKeyFile + infoClients.userNameOrigin + infoClients.userNameDestination, infoClients.keyEncrypt); FileWriter.WriteOnEvents(EventLevel.Info, "Llave publica " + infoClients.userNameOrigin + infoClients.userNameDestination + " almacenada."); return(Ok()); }
public IActionResult ValidateUserKey(InfoClients infoClients) { //Write Event var jsonObj = JsonConvert.SerializeObject(infoClients); FileWriter.WriteOnEvents(EventLevel.Info, "Request en ValidateUserKey ObjKeyService recibido " + string.Join(", ", jsonObj)); RSAEncryption RSAencr = new RSAEncryption(); //Check if the key container exist //Take origin as destination, this methos is called for server keys string filePublicKey = parameters.Value.FilesOutput + parameters.Value.PubKeyFile + infoClients.userNameDestination + infoClients.userNameOrigin; if (RSAencr.KeysPartnerExists(infoClients.userNameDestination + infoClients.userNameOrigin, filePublicKey)) { return(Ok(new { Result = true })); } else { return(Ok(new{ Result = false })); } }