Example #1
0
        public void DatagramDefaults()
        {
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 8, throwIfOtherPlatform: false);

#if __MACOS__
            nint dsize = TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 10) ? 1327 : 1387;
#else
            nint dsize = TestRuntime.CheckXcodeVersion(6, 0) ? 1327 : 1387;
#endif
            using (var ssl = new SslContext(SslProtocolSide.Client, SslConnectionType.Datagram)) {
                Assert.That(ssl.BufferedReadSize, Is.EqualTo((nint)0), "BufferedReadSize");
                Assert.Null(ssl.Connection, "Connection");
                Assert.That(ssl.DatagramWriteSize, Is.EqualTo(dsize), "DatagramWriteSize");
                Assert.That(ssl.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                Assert.That(ssl.MaxDatagramRecordSize, Is.EqualTo((nint)1400), "MaxDatagramRecordSize");
                Assert.That(ssl.MaxProtocol, Is.EqualTo(SslProtocol.Dtls_1_0), "MaxProtocol");
                Assert.That(ssl.MinProtocol, Is.EqualTo(SslProtocol.Dtls_1_0), "MinProtocol");
                Assert.That(ssl.NegotiatedCipher, Is.EqualTo(SslCipherSuite.SSL_NULL_WITH_NULL_NULL), "NegotiatedCipher");
                Assert.That(ssl.NegotiatedProtocol, Is.EqualTo(SslProtocol.Unknown), "NegotiatedProtocol");
                Assert.Null(ssl.PeerId, "PeerId");
                Assert.That(ssl.SessionState, Is.EqualTo(SslSessionState.Idle), "SessionState");

                ssl.PeerId = new byte [] { 0xff };
                Assert.That(ssl.PeerId.Length, Is.EqualTo(1), "1");
                // note: SSLSetPeerID (see Apple open source code) does not accept a null/zero-length value
                ssl.PeerId = null;
                Assert.That((int)ssl.GetLastStatus(), Is.EqualTo(errSecParam), "set_PeerId/null");

                Assert.That((int)ssl.SetDatagramHelloCookie(new byte [33]), Is.EqualTo(-50), "cookie to long");
                Assert.That(ssl.SetDatagramHelloCookie(new byte [32]), Is.EqualTo(SslStatus.Success), "tasty cookie");;
                Assert.That(ssl.SetDatagramHelloCookie(new byte [1]), Is.EqualTo(SslStatus.Success), "fat free cookie");
                Assert.That(ssl.SetDatagramHelloCookie(null), Is.EqualTo(SslStatus.Success), "no more cookies");
            }
        }
Example #2
0
        public void StreamDefaults()
        {
            using (var ssl = new SslContext(SslProtocolSide.Client, SslConnectionType.Stream)) {
                Assert.That(ssl.BufferedReadSize, Is.EqualTo((nint)0), "BufferedReadSize");
                Assert.That(ssl.ClientCertificateState, Is.EqualTo(SslClientCertificateState.None), "ClientCertificateState");
                Assert.Null(ssl.Connection, "Connection");
                Assert.That(ssl.DatagramWriteSize, Is.EqualTo((nint)0), "DatagramWriteSize");
                Assert.That(ssl.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                Assert.That(ssl.MaxDatagramRecordSize, Is.EqualTo((nint)0), "MaxDatagramRecordSize");
                Assert.That(ssl.MaxProtocol, Is.EqualTo(SslProtocol.Tls_1_2), "MaxProtocol");
                if (TestRuntime.CheckXcodeVersion(8, 0))
                {
                    Assert.That(ssl.MinProtocol, Is.EqualTo(SslProtocol.Tls_1_0), "MinProtocol");
                }
                else
                {
                    Assert.That(ssl.MinProtocol, Is.EqualTo(SslProtocol.Ssl_3_0), "MinProtocol");
                }
                Assert.That(ssl.NegotiatedCipher, Is.EqualTo(SslCipherSuite.SSL_NULL_WITH_NULL_NULL), "NegotiatedCipher");
                Assert.That(ssl.NegotiatedProtocol, Is.EqualTo(SslProtocol.Unknown), "NegotiatedProtocol");

                Assert.That(ssl.PeerDomainName, Is.Empty, "PeerDomainName");
                ssl.PeerDomainName = "google.ca";
                Assert.That(ssl.PeerDomainName, Is.EqualTo("google.ca"), "PeerDomainName-2");
                ssl.PeerDomainName = null;
                Assert.That(ssl.PeerDomainName, Is.Empty, "PeerDomainName");

                Assert.Null(ssl.PeerId, "PeerId");
                ssl.PeerId = new byte [] { 0xff };
                Assert.That(ssl.PeerId.Length, Is.EqualTo(1), "1a");

                // note: SSLSetPeerID (see Apple open source code) does not accept a null/zero-length value
                ssl.PeerId = new byte [0];
                Assert.That((int)ssl.GetLastStatus(), Is.EqualTo(errSecParam), "set_PeerId/empty");
                Assert.That(ssl.PeerId.Length, Is.EqualTo(1), "1b");

                ssl.PeerId = new byte [] { 0x01, 0x02 };
                Assert.That(ssl.PeerId.Length, Is.EqualTo(2), "2");

                Assert.Null(ssl.PeerTrust, "PeerTrust");
                Assert.That(ssl.SessionState, Is.EqualTo(SslSessionState.Idle), "SessionState");

                Assert.That((int)ssl.SetDatagramHelloCookie(new byte [32]), Is.EqualTo(-50), "no cookie in stream");

                // Assert.Null (ssl.GetDistinguishedNames<string> (), "GetDistinguishedNames");
            }
        }
Example #3
0
        public void StreamDefaults()
        {
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 8, throwIfOtherPlatform: false);

            using (var ssl = new SslContext(SslProtocolSide.Client, SslConnectionType.Stream)) {
                Assert.That(ssl.BufferedReadSize, Is.EqualTo((nint)0), "BufferedReadSize");
                Assert.That(ssl.ClientCertificateState, Is.EqualTo(SslClientCertificateState.None), "ClientCertificateState");
                Assert.Null(ssl.Connection, "Connection");
                Assert.That(ssl.DatagramWriteSize, Is.EqualTo((nint)0), "DatagramWriteSize");
                Assert.That(ssl.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                Assert.That(ssl.MaxDatagramRecordSize, Is.EqualTo((nint)0), "MaxDatagramRecordSize");
                Assert.That(ssl.MaxProtocol, Is.EqualTo(SslProtocol.Tls_1_2), "MaxProtocol");
                if (TestRuntime.CheckXcodeVersion(8, 0))
                {
                    Assert.That(ssl.MinProtocol, Is.EqualTo(SslProtocol.Tls_1_0), "MinProtocol");
                }
                else
                {
                    Assert.That(ssl.MinProtocol, Is.EqualTo(SslProtocol.Ssl_3_0), "MinProtocol");
                }
                Assert.That(ssl.NegotiatedCipher, Is.EqualTo(SslCipherSuite.SSL_NULL_WITH_NULL_NULL), "NegotiatedCipher");
                Assert.That(ssl.NegotiatedProtocol, Is.EqualTo(SslProtocol.Unknown), "NegotiatedProtocol");

                Assert.That(ssl.PeerDomainName, Is.Empty, "PeerDomainName");
                ssl.PeerDomainName = "google.ca";
                Assert.That(ssl.PeerDomainName, Is.EqualTo("google.ca"), "PeerDomainName-2");
                ssl.PeerDomainName = null;
                Assert.That(ssl.PeerDomainName, Is.Empty, "PeerDomainName");

                Assert.Null(ssl.PeerId, "PeerId");
                ssl.PeerId = new byte [] { 0xff };
                Assert.That(ssl.PeerId.Length, Is.EqualTo(1), "1a");

                // note: SSLSetPeerID (see Apple open source code) does not accept a null/zero-length value
                ssl.PeerId = new byte [0];
                Assert.That((int)ssl.GetLastStatus(), Is.EqualTo(errSecParam), "set_PeerId/empty");
                Assert.That(ssl.PeerId.Length, Is.EqualTo(1), "1b");

                ssl.PeerId = new byte [] { 0x01, 0x02 };
                Assert.That(ssl.PeerId.Length, Is.EqualTo(2), "2");

                Assert.Null(ssl.PeerTrust, "PeerTrust");
                Assert.That(ssl.SessionState, Is.EqualTo(SslSessionState.Idle), "SessionState");

                Assert.That((int)ssl.SetDatagramHelloCookie(new byte [32]), Is.EqualTo(-50), "no cookie in stream");

                // Assert.Null (ssl.GetDistinguishedNames<string> (), "GetDistinguishedNames");

                if (TestRuntime.CheckXcodeVersion(9, 0))
                {
                    Assert.That(ssl.SetSessionTickets(false), Is.EqualTo(0), "SetSessionTickets");
                    Assert.That(ssl.SetError(SecStatusCode.Success), Is.EqualTo(0), "SetError");

                    Assert.Throws <ArgumentNullException> (() => ssl.SetOcspResponse(null), "SetOcspResponse/null");
                    using (var data = new NSData())
                        Assert.That(ssl.SetOcspResponse(data), Is.EqualTo(0), "SetOcspResponse/empty");

#if MONOMAC
                    if (TestRuntime.CheckXcodeVersion(9, 3))
                    {
#endif
                    int error;
                    var alpn = ssl.GetAlpnProtocols(out error);
                    Assert.That(alpn, Is.Empty, "alpn");
                    Assert.That(error, Is.EqualTo((int)SecStatusCode.Param), "GetAlpnProtocols");
                    var protocols = new [] { "HTTP/1.1", "SPDY/1" }
                    ;
                    Assert.That(ssl.SetAlpnProtocols(protocols), Is.EqualTo(0), "SetAlpnProtocols");
#if MONOMAC
                }
#endif
                }
            }
        }