Example #1
0
        /// <summary>
        /// Call the certificate check callback
        /// </summary>
        /// <param name="cert">The certificate to send</param>
        /// <param name="valid">Whether we consider the certificate to be valid</param>
        /// <param name="hostname">The hostname we connected to</param>
        public int CertificateCheck(Certificate cert, bool valid, string hostname)
        {
            CertificateSsh  sshCert  = cert as CertificateSsh;
            CertificateX509 x509Cert = cert as CertificateX509;

            if (sshCert == null && x509Cert == null)
            {
                throw new InvalidOperationException("Unsupported certificate type");
            }

            int ret;

            if (sshCert != null)
            {
                var certPtr = sshCert.ToPointer();
                ret = NativeMethods.git_transport_smart_certificate_check(Transport, certPtr, valid ? 1 : 0, hostname);
                Marshal.FreeHGlobal(certPtr);
            }
            else
            {
                IntPtr certPtr, dataPtr;
                certPtr = x509Cert.ToPointers(out dataPtr);
                ret     = NativeMethods.git_transport_smart_certificate_check(Transport, certPtr, valid ? 1 : 0, hostname);
                Marshal.FreeHGlobal(dataPtr);
                Marshal.FreeHGlobal(certPtr);
            }

            return(ret);
        }
Example #2
0
        private unsafe int GitCertificateCheck(git_certificate *certPtr, int valid, IntPtr cHostname, IntPtr payload)
        {
            string      hostname = LaxUtf8Marshaler.FromNative(cHostname);
            Certificate cert     = null;

            switch (certPtr->type)
            {
            case GitCertificateType.X509:
                cert = new CertificateX509((git_certificate_x509 *)certPtr);
                break;

            case GitCertificateType.Hostkey:
                cert = new CertificateSsh((git_certificate_ssh *)certPtr);
                break;
            }

            bool result = false;

            try
            {
                result = CertificateCheck(cert, valid != 0, hostname);
            }
            catch (Exception exception)
            {
                Proxy.giterr_set_str(GitErrorCategory.Callback, exception);
            }

            return(Proxy.ConvertResultToCancelFlag(result));
        }
Example #3
0
        private unsafe int GitCertificateCheck(git_certificate* certPtr, int valid, IntPtr cHostname, IntPtr payload)
        {
            string hostname = LaxUtf8Marshaler.FromNative(cHostname);
            Certificate cert = null;

            switch (certPtr->type)
            {
                case GitCertificateType.X509:
                    cert = new CertificateX509((git_certificate_x509*) certPtr);
                    break;
                case GitCertificateType.Hostkey:
                    cert = new CertificateSsh((git_certificate_ssh*) certPtr);
                    break;
            }

            bool result = false;
            try
            {
                result = CertificateCheck(cert, valid != 0, hostname);
            }
            catch (Exception exception)
            {
                Proxy.giterr_set_str(GitErrorCategory.Callback, exception);
            }

            return Proxy.ConvertResultToCancelFlag(result);
        }