public ResponseModel ShareSessionKeys([FromBody] SessionKeyRequestModel _clientInfo)
        {
            if (_clientInfo.IsValid())
            {
                using (SqlProvider sqlOp = new SqlProvider())
                    using (RSAOperations keyOp = new RSAOperations())
                    {
                        KeyModel sessionParameters = sqlOp.GetSessionKeys(new Guid(_clientInfo.SessionId));

                        if (sessionParameters != null && !string.IsNullOrEmpty(sessionParameters.PrivateKey) && !string.IsNullOrEmpty(sessionParameters.EncKey) && !string.IsNullOrEmpty(sessionParameters.IVKey))
                        {
                            string clientPublicKey = string.Empty;

                            foreach (string chunk in _clientInfo.ClientPublic.Split('≡'))
                            {
                                clientPublicKey += keyOp.Decrypt(sessionParameters.PrivateKey, chunk);
                            }

                            if (!string.IsNullOrEmpty(clientPublicKey))
                            {
                                string encryptedEKey = keyOp.Encrypt(clientPublicKey, sessionParameters.EncKey);
                                string encryptedIKey = keyOp.Encrypt(clientPublicKey, sessionParameters.IVKey);

                                return(new ResponseModel()
                                {
                                    EKey = encryptedEKey, IKey = encryptedIKey
                                });
                            }
                        }
                    }
            }

            return(null);
        }
Esempio n. 2
0
 public void WriteToOnionFiles(string dir)
 {
     if (IsPublicOnly)
     {
         throw new NotSupportedException("Cannot create an onion from a public-only key");
     }
     RSAOperations.ToOpenSslFile(key, Path.Combine(dir, KeyFilename));
     File.WriteAllText(Path.Combine(dir, HostFilename), Onion + Extension + "\n");
 }
        public ResponseModel CreateSession([FromBody] KeyRequestModel _clientInfo)
        {
            if (_clientInfo.IsValid())
            {
                using (SqlProvider sqlOp = new SqlProvider())
                    using (RSAOperations keyOp = new RSAOperations())
                    {
                        string clientId = sqlOp.GetClientId(_clientInfo.ClientSecret);

                        if (!string.IsNullOrEmpty(clientId))
                        {
                            Tuple <string, string> asymmetricKeyPair = keyOp.GetNewKeyPair();

                            if (!string.IsNullOrEmpty(asymmetricKeyPair.Item1) && !string.IsNullOrEmpty(asymmetricKeyPair.Item2))
                            {
                                string sessionEncKey = keyOp.GetSecureRandomString(16);
                                string sessionIvKey  = keyOp.GetSecureRandomString(16);

                                while (sessionEncKey.Equals(sessionIvKey))
                                {
                                    sessionIvKey = keyOp.GetSecureRandomString(16);
                                }

                                string newSessionId = sqlOp.CreateClientSession(new Guid(clientId), asymmetricKeyPair.Item2, sessionEncKey, sessionIvKey);

                                if (!string.IsNullOrEmpty(newSessionId))
                                {
                                    return(new ResponseModel()
                                    {
                                        SessionId = newSessionId, PublicKey = asymmetricKeyPair.Item1
                                    });
                                }
                            }
                        }
                    }
            }

            return(null);
        }
Esempio n. 4
0
        public static OnionAddress ReadFromOnionFile(string file)
        {
            RSA pki = RSAOperations.FromOpenSslFile(file);

            return(new OnionAddress(pki));
        }
Esempio n. 5
0
 public string ToOpenSslString()
 {
     return(RSAOperations.ToOpenSslString(key));
 }
Esempio n. 6
0
        public static OnionAddress FromOpenSslString(string ssl)
        {
            RSA pki = RSAOperations.FromOpenSslString(ssl);

            return(new OnionAddress(pki));
        }