블로그 이미지
SQL Server VS. 석이 minsouk@hotmail.com MSSQL 쿼리성능 관련해 궁금한 사항이 있다면 언제나 누구나 TeamViewer + Line (네이버 japan 메신저) 에 minsouk1 추가 후 연락주세요~ 010-9967-0955 보미아빠

카테고리

보미아빠, 석이 (466)
밥벌이 (16)
싸이클 (1)
일상 (1)
Total257,589
Today1
Yesterday18

달력

« » 2021.6
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      

공지사항

난독화

카테고리 없음 / 2021. 2. 2. 21:46

https://github.com/yck1509/ConfuserEx/releases 무료 난독화 
JetBrain DotPeeker 로 잘 안보임 

Posted by 보미아빠

댓글을 달아 주세요

* 모두삭제
del hostname.*

* private key 와 인증서 및 인증서 암호를 입력한다. 
makecert -r -len 2048 -pe -n "CN=HOSTNAME" -eku 1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2,1.3.6.1.5.5.7.3.3,1.3.6.1.5.5.7.3.4 -sky exchange -sv HOSTNAME.pvk HOSTNAME.cer -b 01/01/2005 -e 01/01/2035

* 암호입력
1234

* 포터블 파일로 변경한다. 
pvk2pfx -pvk HOSTNAME.pvk -spc HOSTNAME.cer -pfx HOSTNAME.pfx -pi 1234 -po 1234 -f

* pfx my, localhost 에 등록
* cer Root, localhost 에 등록 
certlm.mmc 에서 Personal + Trusted Root Certi 저장소에 HOSTNAME pfx 와 cert 파일이 있는지 확인한다. 
* 자동으로 등록하는 클래스 Certification.cs 확인 

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using CsLib; 

namespace WcfHttpsServer
{
    class Certification
    {

        public bool Bind(string path, string pfx, string pfxpassword, string cert, string port)
        {
            try
            {
                string pfxFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path, pfx);
                string certFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path, cert);

                DeleteCertification(pfxFileName
                    , StoreName.My
                    , StoreLocation.LocalMachine
                    , pfxpassword
                    , X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);

                DeleteCertification(certFileName
                    , StoreName.Root
                    , StoreLocation.LocalMachine);

                InstallCertification(pfxFileName
                    , StoreName.My
                    , StoreLocation.LocalMachine
                    , pfxpassword
                    , X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);

                InstallCertification(certFileName
                    , StoreName.Root
                    , StoreLocation.LocalMachine);

                CertificationNetBind(certFileName, port);
            }
            catch (Exception)
            {
                throw;
            }
            return true;
        }

        private void InstallCertification(string certFileName, StoreName storeName, StoreLocation storeLocaion, string password, X509KeyStorageFlags x509KeyStorageFlags)
        {
            X509Store store = new X509Store(storeName, storeLocaion);
            try
            {
                bool Exists = false;
                X509Certificate2 cert = new X509Certificate2(certFileName, TranString.convertToSecureString(password), x509KeyStorageFlags);
                store.Open(OpenFlags.ReadWrite);
                foreach (X509Certificate2 storeCert in store.Certificates)
                {
                    if (storeCert.Thumbprint.Equals(cert.Thumbprint, StringComparison.OrdinalIgnoreCase))
                    {
                        Exists = true;
                        break;
                    }
                }
                if (!Exists)
                {
                    store.Add(cert);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                store.Close();
            }
        }

        private void InstallCertification(string certFileName, StoreName storeName, StoreLocation storeLocaion)
        {
            X509Store store = new X509Store(storeName, storeLocaion);
            try
            {
                bool Exists = false;
                X509Certificate2 cert = new X509Certificate2(certFileName);
                store.Open(OpenFlags.ReadWrite);
                foreach (X509Certificate2 storeCert in store.Certificates)
                {
                    if (storeCert.Thumbprint.Equals(cert.Thumbprint, StringComparison.OrdinalIgnoreCase))
                    {
                        Exists = true;
                        break;
                    }
                }
                if (!Exists)
                {
                    store.Add(cert);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                store.Close();
            }
        }

        private void DeleteCertification(string certFileName, StoreName storeName, StoreLocation storeLocaion, string password, X509KeyStorageFlags x509KeyStorageFlags)
        {
            X509Store store = new X509Store(storeName, storeLocaion);
            try
            {
                X509Certificate2 cert = new X509Certificate2(certFileName, TranString.convertToSecureString(password), x509KeyStorageFlags);
                store.Open(OpenFlags.ReadWrite);
                foreach (X509Certificate2 storeCert in store.Certificates)
                {
                    if (storeCert.Thumbprint.Equals(cert.Thumbprint, StringComparison.OrdinalIgnoreCase))
                    {
                        store.Remove(cert);
                        break;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                store.Close();
            }
        }

        private void DeleteCertification(string certFile, StoreName storeName, StoreLocation storeLocaion)
        {
            X509Store store = new X509Store(storeName, storeLocaion);
            try
            {
                X509Certificate2 cert = new X509Certificate2(certFile);
                store.Open(OpenFlags.ReadWrite);
                foreach (X509Certificate2 storeCert in store.Certificates)
                {
                    if (storeCert.Thumbprint.Equals(cert.Thumbprint, StringComparison.OrdinalIgnoreCase))
                    {
                        store.Remove(cert);
                        break;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                store.Close();
            }
        }



        private string GetCertHash(string certFileName)
        {
            using (X509Certificate2 cert = new X509Certificate2(certFileName))
                return cert.Thumbprint.ToLower();
        }

        private string GetAssemblyGuid()
        {
            var assembly = typeof(Program).Assembly;
            var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
            var id = attribute.Value;
            return id.ToLower();
        }

        private bool CertificationNetBind(string certFileName, string port)
        {
            StringBuilder sbPsiResults = new StringBuilder();
            ProcessStartInfo psi = new ProcessStartInfo() { CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true };
            bool isBounded = false;
                       
            // SHOW
            psi.FileName = "netsh";
            psi.Arguments = $"http show sslcert ipport=0.0.0.0:{port}";
            sbPsiResults.Clear();
            Process procHttpShow = Process.Start(psi);
            while (procHttpShow != null && !procHttpShow.StandardOutput.EndOfStream)
                sbPsiResults.Append(procHttpShow.StandardOutput.ReadLine());
            procHttpShow?.WaitForExit(2000);

            if (sbPsiResults.ToString().ToLower().Contains(GetCertHash(certFileName)) && sbPsiResults.ToString().ToLower().Contains(GetAssemblyGuid()))
            {
                // DELETE
                psi.FileName = "netsh";
                psi.Arguments = $"http delete sslcert ipport=0.0.0.0:{port}";
                sbPsiResults.Clear();
                Process procHttpDelete = Process.Start(psi);
                while (procHttpDelete != null && !procHttpDelete.StandardOutput.EndOfStream)
                    sbPsiResults.Append(procHttpDelete.StandardOutput.ReadLine());
                procHttpDelete?.WaitForExit(2000);

                if (sbPsiResults.ToString().ToLower().Contains("success"))
                    isBounded = false;
                else
                    throw new Exception($"http delete sslcert error : {sbPsiResults.ToString()}");
            }
            else
                isBounded = false;
            
            if (!isBounded)
            {
                // ADD
                psi.FileName = "netsh";
                psi.Arguments = $"http add sslcert ipport=0.0.0.0:{port} certhash={GetCertHash(certFileName).ToLower()} appid={{{GetAssemblyGuid()}}}";
                sbPsiResults.Clear();
                Process procHttpAdd = Process.Start(psi);
                while (procHttpAdd != null && !procHttpAdd.StandardOutput.EndOfStream)
                    sbPsiResults.Append(procHttpAdd.StandardOutput.ReadLine());
                procHttpAdd?.WaitForExit(2000);
                if (sbPsiResults.ToString().ToLower().Contains("error"))
                {
                    isBounded = false;
                    throw new Exception($"http add sslcert error : {sbPsiResults.ToString()}");
                }
                else
                    isBounded = true;
            }
            return isBounded;
        }
    }
}



Posted by 보미아빠

댓글을 달아 주세요

secureString

2019. 11. 4. 16:51
보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

최근에 달린 댓글

최근에 받은 트랙백

글 보관함