Exemplo n.º 1
0
 internal static partial int SslRead(SafeSslHandle ssl, ref byte buf, int num, out SslErrorCode error);
Exemplo n.º 2
0
 internal static unsafe partial void SslSetClientCertCallback(SafeSslHandle ssl, int set);
Exemplo n.º 3
0
 internal static partial bool SslAddExtraChainCert(SafeSslHandle ssl, SafeX509Handle x509);
Exemplo n.º 4
0
 internal static partial IntPtr SslGetData(SafeSslHandle ssl);
Exemplo n.º 5
0
 internal static partial int SslUseCertificate(SafeSslHandle ssl, SafeX509Handle certPtr);
Exemplo n.º 6
0
 internal static partial bool SslGetCurrentCipherId(SafeSslHandle ssl, out int cipherId);
Exemplo n.º 7
0
 internal static unsafe partial bool SslSetCiphers(SafeSslHandle ssl, byte *cipherList, byte *cipherSuites);
Exemplo n.º 8
0
 public SslConnectionInfo(SafeSslHandle sslContext)
 {
     throw new NotImplementedException(nameof(SslConnectionInfo));
 }
Exemplo n.º 9
0
 internal static SafeX509Handle GetPeerCertificate(SafeSslHandle context)
 {
     return(Ssl.SslGetPeerCertificate(context));
 }
Exemplo n.º 10
0
        private static SecurityStatusPal HandshakeInternal(
            SecureChannel secureChannel,
            SafeFreeCredentials credential,
            ref SafeDeleteSslContext?context,
            ReadOnlySpan <byte> inputBuffer,
            ref byte[]?outputBuffer,
            SslAuthenticationOptions sslAuthenticationOptions)
        {
            Debug.Assert(!credential.IsInvalid);

            try
            {
                SafeDeleteSslContext?sslContext = ((SafeDeleteSslContext?)context);

                if ((null == context) || context.IsInvalid)
                {
                    sslContext = new SafeDeleteSslContext((credential as SafeFreeSslCredentials) !, sslAuthenticationOptions);
                    context    = sslContext;

                    if (!string.IsNullOrEmpty(sslAuthenticationOptions.TargetHost) && !sslAuthenticationOptions.IsServer)
                    {
                        Interop.AppleCrypto.SslSetTargetName(sslContext.SslContext, sslAuthenticationOptions.TargetHost);
                    }

                    if (sslAuthenticationOptions.CertificateContext == null && sslAuthenticationOptions.CertSelectionDelegate != null)
                    {
                        // certificate was not provided but there is user callback. We can break handshake if server asks for certificate
                        // and we can try to get it based on remote certificate and trusted issuers.
                        Interop.AppleCrypto.SslBreakOnCertRequested(sslContext.SslContext, true);
                    }

                    if (sslAuthenticationOptions.IsServer && sslAuthenticationOptions.RemoteCertRequired)
                    {
                        Interop.AppleCrypto.SslSetAcceptClientCert(sslContext.SslContext);
                    }
                }

                if (inputBuffer.Length > 0)
                {
                    sslContext !.Write(inputBuffer);
                }

                SafeSslHandle     sslHandle = sslContext !.SslContext;
                SecurityStatusPal status    = PerformHandshake(sslHandle);
                if (status.ErrorCode == SecurityStatusPalErrorCode.CredentialsNeeded)
                {
                    X509Certificate2?clientCertificate = secureChannel.SelectClientCertificate(out _);
                    if (clientCertificate != null)
                    {
                        sslAuthenticationOptions.CertificateContext = SslStreamCertificateContext.Create(clientCertificate);
                        SafeDeleteSslContext.SetCertificate(sslContext.SslContext, sslAuthenticationOptions.CertificateContext);
                    }

                    // We either got certificate or we can proceed without it. It is up to the server to decide if either is OK.
                    status = PerformHandshake(sslHandle);
                }

                outputBuffer = sslContext.ReadPendingWrites();
                return(status);
            }
            catch (Exception exc)
            {
                return(new SecurityStatusPal(SecurityStatusPalErrorCode.InternalError, exc));
            }
        }
Exemplo n.º 11
0
        public static SecurityStatusPal EncryptMessage(
            SafeDeleteSslContext securityContext,
            ReadOnlyMemory <byte> input,
            int headerSize,
            int trailerSize,
            ref byte[] output,
            out int resultSize)
        {
            resultSize = 0;

            Debug.Assert(input.Length > 0, $"{nameof(input.Length)} > 0 since {nameof(CanEncryptEmptyMessage)} is false");

            try
            {
                SafeSslHandle sslHandle = securityContext.SslContext;

                unsafe
                {
                    MemoryHandle memHandle = input.Pin();
                    try
                    {
                        PAL_TlsIo status = Interop.AppleCrypto.SslWrite(
                            sslHandle,
                            (byte *)memHandle.Pointer,
                            input.Length,
                            out int written);

                        if (status < 0)
                        {
                            return(new SecurityStatusPal(
                                       SecurityStatusPalErrorCode.InternalError,
                                       Interop.AppleCrypto.CreateExceptionForOSStatus((int)status)));
                        }

                        if (securityContext.BytesReadyForConnection <= output?.Length)
                        {
                            resultSize = securityContext.ReadPendingWrites(output, 0, output.Length);
                        }
                        else
                        {
                            output     = securityContext.ReadPendingWrites() !;
                            resultSize = output.Length;
                        }

                        switch (status)
                        {
                        case PAL_TlsIo.Success:
                            return(new SecurityStatusPal(SecurityStatusPalErrorCode.OK));

                        case PAL_TlsIo.WouldBlock:
                            return(new SecurityStatusPal(SecurityStatusPalErrorCode.ContinueNeeded));

                        default:
                            Debug.Fail($"Unknown status value: {status}");
                            return(new SecurityStatusPal(SecurityStatusPalErrorCode.InternalError));
                        }
                    }
                    finally
                    {
                        memHandle.Dispose();
                    }
                }
            }
            catch (Exception e)
            {
                return(new SecurityStatusPal(SecurityStatusPalErrorCode.InternalError, e));
            }
        }
Exemplo n.º 12
0
 internal static partial int SslShutdown(SafeSslHandle ssl);
Exemplo n.º 13
0
 internal static partial bool IsSslRenegotiatePending(SafeSslHandle ssl);
Exemplo n.º 14
0
 internal static partial int SslRenegotiate(SafeSslHandle ssl, out SslErrorCode error);
Exemplo n.º 15
0
 internal static partial bool SslSessionReused(SafeSslHandle ssl);
Exemplo n.º 16
0
 internal static SafeSharedX509StackHandle GetPeerCertificateChain(SafeSslHandle context)
 {
     return(Ssl.SslGetPeerCertChain(context));
 }
Exemplo n.º 17
0
 private static partial SafeSharedX509NameStackHandle SslGetClientCAList_private(SafeSslHandle ssl);
Exemplo n.º 18
0
 internal static partial void SslSetBio(SafeSslHandle ssl, SafeBioHandle rbio, SafeBioHandle wbio);
Exemplo n.º 19
0
 private static partial IntPtr GetOpenSslCipherSuiteName(SafeSslHandle ssl, int cipherSuite, out int isTls12OrLower);
Exemplo n.º 20
0
 internal static partial int SslDoHandshake(SafeSslHandle ssl, out SslErrorCode error);
Exemplo n.º 21
0
 internal static partial void SslSetVerifyPeer(SafeSslHandle ssl);
Exemplo n.º 22
0
 internal static partial bool IsSslStateOK(SafeSslHandle ssl);
Exemplo n.º 23
0
 internal static partial int SslSetData(SafeSslHandle ssl, IntPtr data);
Exemplo n.º 24
0
 internal static partial SafeX509Handle SslGetPeerCertificate(SafeSslHandle ssl);
Exemplo n.º 25
0
 internal static partial int SslUsePrivateKey(SafeSslHandle ssl, SafeEvpPKeyHandle keyPtr);
Exemplo n.º 26
0
 internal static partial SafeSharedX509StackHandle SslGetPeerCertChain(SafeSslHandle ssl);
Exemplo n.º 27
0
 internal static partial void SslSetPostHandshakeAuth(SafeSslHandle ssl, int value);
Exemplo n.º 28
0
 internal static partial int SslGetFinished(SafeSslHandle ssl, IntPtr buf, int count);
Exemplo n.º 29
0
 private static unsafe partial bool SslAddClientCAs(SafeSslHandle ssl, IntPtr *x509s, int count);
Exemplo n.º 30
0
 internal static partial void SslGetAlpnSelected(SafeSslHandle ssl, out IntPtr protocol, out int len);