2/Server

웹 & 인증 & 암호화 통신

berry-hi 2019. 4. 2. 12:04

인증서

개인키와 공개키

암호에 쓰이는 개인키와 공개키는 다음과 같이 쓰인다.

다른 사람이 나에게 평문을 보낼 때, 공개키로 암호화하고 나는 개인키로 복호화한다.

따라서 개인키를 가진 "나"만이 복호화하여 내용을 볼 수 있다.

 

관리

개인키는 서버에 저장하고, 공개키는 인증기관에 저장한다.

누구든 나에게 평문을 보낼 때 인증 기관으로부터 공개키를 받아 암호화하여 보낼 수 있다.

대신 나는 서버에 있는 내 개인키로 평문을 복호화하여 볼 수 있다.

 

생성

keytool 이용하여 인증서와 키 생성

  • keytool 커맨드
    • Key and Certificate Management Tool 
옵션 설명  
-certreq Generates a certificate request   
-changealias Changes an entry's alias  
-delete Deletes an entry  
-exportcert Exports certificate  
-genkeypair Generates a key pair 공개키와 개인키 쌍 생성
-genseckey Generates a secret key  
-gencert Generates certificate from a certificate request  
-importcert Imports a certificate or a certificate chain  
-importpass Imports a password  
-importkeystore Imports a one or all entries from another keysotre  
-keypasswd Changes the key password of an entry  
-list Lists entries in a keystore  
-printcert Prints the content of a certificate  
-printcertreq Prints the content of a certificate request  
-printcrl Prints the content of a CRL file  
-storepasswd Changes the store password of a keystore  
  • keytool -genkeypair
옵션 설명  
-alias <alias> alias name of the entry to process  
-keyalg <keyalg> key algorithm name  
-keysize <keysize> key bit size   
-sigalg <sigalg> signature algorithm name   
-destalias <destalias> destination alias   
-dname <dname>   distinguished name   
-startdate <startdate>    certificate validity start date/time   
-ext <value>   X.509 extension   
-validity <valDays> validity number of days   
-keypass <arg>   key password  
-keystore <keystore>  keystore name  
-storepass <arg>  keystore password   
-storetype <storetype> keystore type   
-providername <providername> provider name   

-addprovider <name>

  [-providerarg <arg> ]  

add security provider by name (e.g. SunPKCS11) configure argument for -addprovider 

 

-providerclass  <class>

[-providerarg <arg> ]

add security provider by fully-qualified class name 
configure argument for -providerclass
 
-providerpath <list> provider classpath  
-v verbose output  
-protected password through protected mechanism   

물론 이 많은 조합 다 안씀! 엄청나게 다양한 조합이 있는데 이를 통해서 원하는 키와 인증서 생성하면 된다.

Apache Tomcat

TLS

  • 웹 서버와 웹 브라우저 간의 통신 암호화
  • 웹 브라우저에서 웹 서버와 통신을 할 때, 암호화된 통신(HTTPS)을 하기 위해서 먼저 TLS 통신부터 적용해보자.
    1. 적당한 위치에 keystore로 생성한 인증서를 둔다.
    2. 인증서의 위치를 알리기 위해 /usr/local/apache/conf/server.xml 파일에서 경로를 수정한다.
    3. HTTS 사용을 위한 TLS 설정 끝
<Connector port="443" //통신 프로토콜 포트
			protocol="~" //통신 프로토콜 이름과 버전
            SSLEnabled="true"
            scheme="https"
            keysotreFile="~" //인증서 위치
            keysotrepass="~" //키 스토어 비밀번호
            clientauth="false" //클라이언트 인증 사용 안한다는 뜻 같쥬?
            sslEnabledProtocols="TLSv1.2"
            sslprotocol="TLS" //ssl 프로토콜 명시
            ciphers"~" //암호화 스펙 나열
            />
  • 여기까지하면 TLS 통신 설정까지밖에 안 한 거. 인증서가 신뢰 기관으로부터 받은 인증서가 아니기 때문에 안전하지 않음으로 접속 가능
  • 다음 게시글에서 PC에 인증서 가져오기 설명해보자