'암호화'에 해당되는 글 32건

  1. 2015.11.17 Using OpenSSL to encrypt messages and files on Linux (1)
  2. 2015.06.16 OpenSSL 다중 취약점 보안업데이트
  3. 2015.06.01 시스템 개발·운영자를 위한 개인정보보호 가이드라인
2015.11.17 13:55

Using OpenSSL to encrypt messages and files on Linux

1. Introduction

OpenSSL is a powerful cryptography toolkit. Many of us have already used OpenSSL for creating RSA Private Keys or CSR (Certificate Signing Request). However, did you know that you can use OpenSSL to benchmark your computer speed or that you can also encrypt files or messages? This article will provide you with some simple to follow tips on how to encrypt messages and files using OpenSSL.

2. Encrypt and Decrypt Messages

First we can start by encrypting simple messages. The following command will encrypt a message "Welcome to LinuxCareer.com" using Base64 Encoding:

$ echo "Welcome to LinuxCareer.com" | openssl enc -base64
V2VsY29tZSB0byBMaW51eENhcmVlci5jb20K

The output of the above command is an encrypted string containing encoded message "Welcome to LinuxCareer.com". To decrypt encoded string back to its original message we need to reverse the order and attach -d option for decryption:

$ echo "V2VsY29tZSB0byBMaW51eENhcmVlci5jb20K" | openssl enc -base64 -d
Welcome to LinuxCareer.com

The above encryption is simple to use, however, it lacks an important feature of a password, which should be used for encryption. For example, try to decrypt the following string with a password "pass":

U2FsdGVkX181xscMhkpIA6J0qd76N/nSjjTc9NrDUC0CBSLpZQxQ2Db7ipd7kexj

To do that use OpenSSL again with -d option and encoding method aes-256-cbc:

echo "U2FsdGVkX181xscMhkpIA6J0qd76N/nSjjTc9NrDUC0CBSLpZQxQ2Db7ipd7kexj" | openssl 
enc -aes-256-cbc -d -a

 As you have probably already guessed, to create an encrypted message with a password as the one above you can use the following command:

 $ echo "OpenSSL" | openssl enc -aes-256-cbc -a enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
U2FsdGVkX185E3H2me2D+qmCfkEsXDTn8nCn/4sblr8=

If you wish to store OpenSSL's output to a file instead of STDOUT simply use STDOUT redirection ">". When storing encrypted output to a file you can also omit -a option as you no longer need the output to be ASCII text based:

$ echo "OpenSSL" | openssl enc -aes-256-cbc > openssl.dat
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
$ file openssl.dat
openssl.dat: data

To decrypt the openssl.dat file back to its original message use:

$ openssl enc -aes-256-cbc -d -in openssl.dat 
enter aes-256-cbc decryption password:
OpenSSL

3. Encrypt and Decrypt File

 To encrypt files with OpenSSL is as simple as encrypting messages. The only difference is that instead of the echo command we use the -in option with the actual file we would like to encrypt and -out option, which will instruct OpenSSL to store the encrypted file under a given name:

$ openssl enc -aes-256-cbc -in /etc/services -out services.dat

To decrypt back our services file use:

$ openssl enc -aes-256-cbc -d -in services.dat > services.txt
enter aes-256-cbc decryption password:

4. Encrypt and Decrypt Directory

In case that you needed to use OpenSSL to encrypt an entire directory you would, firs,t need to create gzip tarball and then encrypt the tarball with the above method or you can do both at the same time by using pipe:

# tar cz /etc | openssl enc -aes-256-cbc -out etc.tar.gz.dat
tar: Removing leading `/' from member names
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:

To decrypt and extract the entire etc/ directory to you current working directory use:

# openssl enc -aes-256-cbc -d -in etc.tar.gz.dat | tar xz
enter aes-256-cbc decryption password:

The above method can be quite useful for automated encrypted backups.

5. Using Public and Private keys

In this section we will show how to encrypt and decrypt files using public and private keys. First we need to generate private and public keys. This can simply be done by:

$ openssl genrsa -out private_key.pem 1024
Generating RSA private key, 1024 bit long modulus
............................++++++
..........++++++
e is 65537 (0x10001)

From the private key we can then generate public key:

$ openssl rsa -in private_key.pem -out public_key.pem -outform PEM -pubout
writing RSA key

At this point yo should have both private and public key available in your current working directory.

$ ls
private_key.pem  public_key.pem

Next, we create some sample file called encrypt.txt with any arbitrary text:

$ echo "Welcome to LinuxCareer.com" > encrypt.txt
$ cat encrypt.txt
Welcome to LinuxCareer.com

Now we are ready to encrypt this file with public key:

$ openssl rsautl -encrypt -inkey public_key.pem -pubin -in encrypt.txt -out encrypt.dat 
$ ls
encrypt.dat  encrypt.txt  private_key.pem  public_key.pem
$ file encrypt.dat
encrypt.dat: data

As you can see our new encrypt.dat file is no longer text files. To decrypt this file we need to use private key:

$ openssl rsautl -decrypt -inkey private_key.pem -in encrypt.dat -out new_encrypt.txt 
$ cat new_encrypt.txt
Welcome to LinuxCareer.com

The above syntax is quite intuitive. As you can see we have decrypted a file encrypt.dat to its original form and save it as new_encrypt.txt. You can for example combine this syntax with encrypting directories example above to create automated encrypted backup script.

6. Conclusion

What you have just read was a basic introduction to OpenSSL encryption. When it comes to OpenSSL as an encryption toolkit it literally has no limit on what you can do. To see how to use different encoding methods see OpenSSL manual page: man openssl



출처 : how-to.linuxcareer.com


Trackback 0 Comment 1
  1. 2015.11.17 13:59 address edit & del reply

    비밀댓글입니다

2015.06.16 19:31

OpenSSL 다중 취약점 보안업데이트

개요

  • 취약한 OpenSSL 버전을 사용하는 서버와 클라이언트 사이에서 공격자가 암호화된 데이터를 복호화할 수 있는 취약점, 서비스 거부 취약점 등 7개의 취약점을 보완한 보안업데이트를 발표[1]


설명

  • TLS 프로토콜에서 Diffie-Hellman 키 교환 처리 중 512비트로 다운그레이드 시키는 취약점(CVE-2015-4000)
  • ECParameters 구조 처리 중 발생하는 서비스 거부 취약점 (CVE-2015-1788)
  • X509_cmp_time 함수에서 발생하는 서비스 거부 공격 취약점 (CVE-2015-1789)
  • ASN.1 인코딩 된 PKCS#7 데이터 처리 중 발생하는 Out-of-bounds 읽기 가능 취약점(CVE-2015-1790)
  • 알 수 없는 해쉬 함수를 사용하는 암호화 메시지 처리 중 발생하는 무한 루프 취약점 (CVE-2015-1792)
  • NewSessionTicket 처리 중 발생하는 Race condition 취약점 (CVE-2015-1791)
  • ChangeCipherSpec 메시지와 완료 메시지 사이에 데이터 처리 중 발생하는 Double Free 취약점 (CVE-2014-8176)


해당 시스템

  • 영향 받는 제품 및 버전
    - OpenSSL 1.0.2 대 버전
    - OpenSSL 1.0.1 대 버전
    - OpenSSL 1.0.0 대 버전
    - OpenSSL 0.9.8 대 버전


해결 방안

  • 해당 취약점에 영향 받는 버전의 사용자는 아래 버전으로 업데이트[2]
    - OpenSSL 1.0.2 사용자 : 1.0.2b로 업데이트
    - OpenSSL 1.0.1 사용자 : 1.0.1n로 업데이트
    - OpenSSL 1.0.0 사용자 : 1.0.0s로 업데이트
    - OpenSSL 0.9.8 사용자 : 0.9.8zg로 업데이트
    ※ CVE-2015-4000은 OpenSSL 1.0.2b, 1.0.1n에서만 수정


용어 설명

  • Diffie-Hellman 키 교환 : 암호화 되지 않은 통신망에서의 공통의 비밀 키 공유를 위한 알고리즘
  • PKCS#7 : RSA사가 제시한 공개 키 암호 표준의 하나로 암호학적 메시지 구문 표준


추가사항

  • Open SSL 0.9.8, OpenSSL 1.0.0 버전은 2015년 12월 31일부로 서비스 종료 예정으로 해당 버전을 사용중인 사용자는 업데이트 검토 요망


기타 문의사항

  • 한국인터넷진흥원 인터넷침해대응센터: 국번없이 118


[참고사이트]

  1. http://openssl.org/news/secadv_20150611.txt
  2. https://www.openssl.org



Trackback 0 Comment 0
2015.06.01 20:12

시스템 개발·운영자를 위한 개인정보보호 가이드라인

시스템_개발.운영자를_위한_개인정보보호_가이드라인(최종).pdf




출처 : 개인정보보호 종합포털


Trackback 0 Comment 0