public static string requestKeyXml(CAInterface ca, String identity) { UnicodeEncoding ByteConverter = new UnicodeEncoding(); Random r = new Random(); int nonce = r.Next(); XElement request = new XElement("Request", new XElement("Identity", identity), new XElement("Nonce", nonce) ); string answerString = ca.requestCertificate(request.ToString()); string messageS = RSAUtils.ReadMessageFromSignPackage(answerString, RSAUtils.LoadPublicKey("CA")); XElement messageX = XElement.Parse(messageS); string status = messageX.Element("Status").Value; string nonceString = messageX.Element("Nonce").Value; if (status == "OK" && nonce +1 == Convert.ToInt32(nonceString)) { string certificate = messageX.Element("Key").Value; return certificate; } else { Console.WriteLine("NOT FOUND"); throw new IdentityNotFoundException(); } }
public static SourceSessionKeyNonce readKeyEncapsulation(CAInterface ca, string receiver, byte[] messageSignBytes) { UnicodeEncoding ByteConverter = new UnicodeEncoding(); string messageSigned = ByteConverter.GetString(messageSignBytes); string source = ""; string establishConnectionString = ""; try { source = SSUtils.getSourceAndVerifyDestination(messageSigned, receiver); string publicKeyXmlString = CAUtils.requestKeyXml(ca, source); RSACryptoServiceProvider publicKey = new RSACryptoServiceProvider(); publicKey.FromXmlString(publicKeyXmlString); establishConnectionString = RSAUtils.ReadMessageFromSignPackage(messageSigned, publicKey); } catch (DestinationOfMessageWrong e) { throw new KeyEncapsulationErrorException(); } catch (MessageNotSignedException e) { throw new KeyEncapsulationErrorException(); } XElement establishConnectionXml = XElement.Parse(establishConnectionString); string sessionKeyEncryptedBase64 = establishConnectionXml.Element("EncryptedSessionKey").Value; byte[] sessionKeyEncrypted = Convert.FromBase64String(sessionKeyEncryptedBase64); string nonceString = establishConnectionXml.Element("Nonce").Value; int nonce = Convert.ToInt32(nonceString); byte[] decryptedKey; using (RSACryptoServiceProvider RSA = RSAUtils.LoadPrivateKey(receiver)) { decryptedKey = RSAUtils.RSADecrypt(sessionKeyEncrypted, RSA.ExportParameters(true), true); } return new SourceSessionKeyNonce(source, decryptedKey, nonce); }
public SchedulerServerServices(CAInterface ca) { this.ca = ca; }
private void connectButton_Click(object sender, EventArgs e) { string port = portBox.Text; email = emailBox.Text; channel = new TcpChannel(Convert.ToInt32(port)); ChannelServices.RegisterChannel(channel, true); ss = (ISchedulerServer)Activator.GetObject(typeof(ISchedulerServer), "tcp://localhost:8086/ISchedulerServer"); ca = (CAInterface)Activator.GetObject(typeof(CAInterface), "tcp://localhost:6969/CA"); cs = new ClientServices(this, ca, email); RemotingServices.Marshal(cs, "ClientServices", typeof(Participant)); url = "tcp://localhost:" + port + "/ClientServices"; service = GoogleCalendarUtils.buildCalendarService(email); connectButton.Enabled = false; portBox.Enabled = false; emailBox.Enabled = false; codeButton.Enabled = true; scheduleButton.Enabled = true; }
public ClientServices(ClientInterface ci, CAInterface ca, string myname) { this.ci = ci; this.email = myname; this.ca = ca; }