Beispiel #1
0
 public void ProvisionThaliClient()
 {
     var clientCert          = ThaliClientToDeviceHubUtilities.ProvisionThaliClient(Host, Port, tempDirectory);
     var serverKey           = ThaliClientToDeviceHubUtilities.GetServersRootPublicKey(Host, Port, clientCert);
     var couchClient         = ThaliClientToDeviceHubUtilities.GetCouchClient(serverKey, Host, Port, clientCert);
     var myPrincipalDatabase = couchClient.GetDatabase(ThaliCryptoUtilities.KeyDatabaseName);
     var keyId        = BogusAuthorizeCouchDocument.GenerateRsaKeyId(new BigIntegerRSAPublicKey(clientCert));
     var clientKeyDoc = myPrincipalDatabase.GetDocument <BogusAuthorizeCouchDocument>(keyId);
 }
Beispiel #2
0
        public void GetServersRootPublicKeyTest()
        {
            var keyPair      = ThaliCryptoUtilities.GenerateThaliAcceptablePublicPrivateKeyPair();
            var pkcs12Stream = ThaliCryptoUtilities.CreatePKCS12KeyStoreWithPublicPrivateKeyPair(
                keyPair,
                ThaliCryptoUtilities.DefaultPassPhrase);
            var cert      = ThaliCryptoUtilities.GetX509Certificate(pkcs12Stream, ThaliCryptoUtilities.DefaultPassPhrase);
            var serverKey = ThaliClientToDeviceHubUtilities.GetServersRootPublicKey(Host, Port, cert);

            Assert.IsNotNull(serverKey);
        }
Beispiel #3
0
        public void ThaliWebRequestTest()
        {
            var keyPair      = ThaliCryptoUtilities.GenerateThaliAcceptablePublicPrivateKeyPair();
            var pkcs12Stream = ThaliCryptoUtilities.CreatePKCS12KeyStoreWithPublicPrivateKeyPair(
                keyPair,
                ThaliCryptoUtilities.DefaultPassPhrase);
            var cert             = ThaliCryptoUtilities.GetX509Certificate(pkcs12Stream, ThaliCryptoUtilities.DefaultPassPhrase);
            var serverKey        = ThaliClientToDeviceHubUtilities.GetServersRootPublicKey(Host, Port, cert);
            var serverHttpKeyUri = HttpKeyUri.BuildHttpKeyUri(serverKey, Host, Port, null, null);
            var thaliWebRequest  = ThaliClientToDeviceHubUtilities.CreateThaliWebRequest(serverHttpKeyUri, cert);

            thaliWebRequest.Method = "GET";
            thaliWebRequest.GetResponse().Close();
        }
Beispiel #4
0
        public void Setup()
        {
            var tempDirectoryForSetupPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            tempDirectoryForSetup = Directory.CreateDirectory(tempDirectoryForSetupPath);
            var clientCert      = ThaliClientToDeviceHubUtilities.GetLocalClientCertificate(tempDirectoryForSetup);
            var serverPublicKey = ThaliClientToDeviceHubUtilities.GetServersRootPublicKey(Host, Port, clientCert);

            ThaliClientToDeviceHubUtilities.ProvisionThaliClient(serverPublicKey, Host, Port, clientCert);
            var couchClient = ThaliClientToDeviceHubUtilities.GetCouchClient(serverPublicKey, Host, Port, clientCert);

            var response = couchClient.DeleteDatabase(TestDatabaseName);

            var tempDirectoryPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            tempDirectory = Directory.CreateDirectory(tempDirectoryPath);
        }
Beispiel #5
0
        /// <summary>
        /// TODO: This whole method is just wrong, what happens if the server at the address changes its key?!?!?!
        /// TODO: Once we have a real discovery framework this whole 0.0 mechanism needs to go away.
        /// </summary>
        /// <param name="httpKeyUri"></param>
        /// <param name="clientCert"></param>
        /// <returns></returns>
        private static HttpKeyUri DiscoverRootCertIfNeeded(HttpKeyUri httpKeyUri, X509Certificate2 clientCert)
        {
            if (httpKeyUri.ServerPublicKey.Exponent.Equals(BigInteger.Zero)
                && httpKeyUri.ServerPublicKey.Modulus.Equals(BigInteger.Zero))
            {
                var host = httpKeyUri.Host;
                var port = httpKeyUri.Port;
                var hostPortTuple = new Tuple<string, int>(host, port);

                var serverPublicKey = HttpKeyStore.GetOrAdd(
                    hostPortTuple,
                    keyTuple => ThaliClientToDeviceHubUtilities.GetServersRootPublicKey(host, port, clientCert));

                var serverHttpKey = HttpKeyUri.BuildHttpKeyUri(
                    serverPublicKey,
                    host,
                    port,
                    httpKeyUri.PathWithoutPublicKey,
                    httpKeyUri.Query);
                return serverHttpKey;
            }

            return httpKeyUri;
        }