휴. 드디어 됐다.

먼저 간단하게 GPG에 대해 알아보자

GPG = The GNU Privacy Guard =GnuPG 의약자로 '전자서명'과 '암호화' 의 일종이다. 공개키와 비밀키로 구성되어 있으며 공개키는 모든 사람에게 공개하여 다른이가 공개자에게 메세지를 보낼 때, 공개키를 이용하여 암호화 하여 보내면 공개자는 메일을 받아 자신의 비밀키로 메세지를 해독하여 볼 수 있다. 또한 메세지를 보내는 사람은 자신의 비밀키를 '전자 서명'으로 사용하여 메일을 보내고 받는 사람은 보내는 사람의 공개키로 보낸 사람과 본문의 내용이 일치하는 지 확인 할 수 있다.


이외에 내가 지금 사용하는 목적인 리눅스 패키지 배포에도 사용된다. 이것은 오픈소스(누구나 사용하고 누구나 개발할 수 있는)기반인 리눅스에 누군가 악의적인 목적으로 악성코드나 트로이얀이 포함된 프로그램을 배포하게 될 경우를 대비하여 인증(검증)된 프로그램을 사용하기 위하여 사용한다. gpg키를 통하여 프로그램 제작자(단체)를 확인할 수 있으니까

여기서는 패키지를 배포하기 위해 Launchpad에 가입하고 GPG를 생성하고 키를 활성화(Activation)하는 것에 대해 설명하겠다.

1. Launchpad.net에 회원가입
회원가입시 사용할 이메일 주소를 신중하게 고르자. 앞으로 PPA사용과 GPG키 생성에 동일하게 사용하게 되므로, 기존 메일중에 좀 비중있는(?) 메일주소로..

2. GPG 생성
먼저 생성되어 있는 키가 있는지 확인해 본다. 터미널을 열고, gpg --list-keys 명령으로 확인할 수 있다.
readytoact-dev@ubuntu9:~/Desktop$ gpg --list-keys
/home/readytoact-dev/.gnupg/pubring.gpg
---------------------------------------
pub   1024D/9A30EC52 2009-06-20
uid                  Lee won-hee (readytoact, #ubuntu@irc.hanirc.org) <a********@paran.com>
sub   2048g/75D558D5 2009-06-20
특정 배포자의 키를 확인하려면 뒤에 e-mail을 입력하면 확인 가능하다

gpg --list-keys your@e-mail.address
이미 생성해 놓은 키가 하나 존재 한다. 다른 키를 생성해 보겠다.

readytoact-dev@ubuntu9:~/Desktop$ gpg --gen-key
gpg (GnuPG) 1.4.9; Copyright (C) 2008 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:   // 암호화 방식 선택
   (1) DSA and Elgamal (default)
   (2) DSA (sign only)
   (5) RSA (sign only)
Your selection?                                    // 엔터 (1, default)
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)            // 암호화 키 사이즈 선택. 엔터(기본값, (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)                                // 키의 유효기간 설정
Key does not expire at all                        // 설정 내역확인 y선택
Is this correct? (y/N) y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"

Real name: Ubuntu.or.kr                          // 서명에 사용될 이름
Email address: tester@ubuntu.or.kr            // 이메일
Comment: PGP key generation test           // 코멘트 (옵션)
You selected this USER-ID:
    "Ubuntu.or.kr (PGP key generation test) <tester@ubuntu.or.kr>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o       // 수정여부확인 없으면 'o'입력후엔터
You need a Passphrase to protect your secret key.

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
+++++++++++++++++++++++++.+++++.+++++++++++++++.+++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++.++++++++++>++++++++++......+++++
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
+++++.++++++++++..++++++++++++++++++++++++++++++.++++++++++...++++++++++..+++++.++++++++++...++++++++++.++++++++++.++++++++++++++++++++++++++++++++++++++++.+++++>.+++++..+++++>+++++.>+++++...........................................<+++++..............>.+++++...........................<+++++.........................>+++++...............<+++++........>+++++...........................+++++^^^^
gpg: key 752485E5 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
pub   1024D/752485E5 2009-06-21
      Key fingerprint = A7B8 9302 1174 9594 C8B9  52D1 CF11 6397 7524 85E5
uid                  Ubuntu.or.kr (PGP key generation test) <tester@ubuntu.or.kr>
sub   2048g/76412845 2009-06-21
생성된 키를 확인해보자
readytoact-dev@ubuntu9:~/Desktop$ gpg --list-keys
/home/readytoact-dev/.gnupg/pubring.gpg
---------------------------------------
pub   1024D/9A***C52 2009-06-20
uid                  Lee won-hee (readytoact, #ubuntu@irc.hanirc.org) <a********@paran.com>
sub   2048g/75***8D5 2009-06-20

pub   1024D/752***E5 2009-06-21
uid                  Ubuntu.or.kr (PGP key generation test) <tester@ubuntu.or.kr>
sub   2048g/76***845 2009-06-21

생성된 키를 키서버와 동기화 한다.
gpg --send-keys --keyserver keyserver  key-id
키서버 : keyserver.ubuntu.com
키ID : 생성된 키 pub   1024D/75***5E5 2009-06-21
                                      Key ID
readytoact-dev@ubuntu9:~/Desktop$ gpg --send-keys --keyserver keyserver.ubuntu.com  75***5E5
gpg: sending key 75***5E5 to hkp server keyserver.ubuntu.com

핑거프린트 추출
readytoact-dev@ubuntu9:~/Desktop$ gpg --fingerprint 752485E5
pub   1024D/75***5E5 2009-06-21
      Key fingerprint = A7B8 9302 **** **** C8B9  52D1 CF11 6397 7524 85E5
uid                  Ubuntu.or.kr (PGP key generation test) <tester@ubuntu.or.kr>
sub   2048g/76***845 2009-06-21
3. 런치패드(Launchpad.net)에 키 등록
로그인하여 화면 좌측 자신의 id를 클릭하여 프로파일 페이지로 이동
사용자 삽입 이미지
화면 아랫쪽으로 이동하면
사용자 삽입 이미지
'Ubuntero : No' 옆의 화살표를 클릭하여 1.Register an OpenPGP Key. 를 선택하여 진행
사용자 삽입 이미지


 Importign OpenPGP Key - 3. Enter your key fingerprint Use 에 아까 2번 과정에서 생성된 키의 Fingerprint입력
사용자 삽입 이미지

키 import후 암호화 된 키를 등록된 이메일로 보냈다는 안내메세지를 받을 수 있다.
사용자 삽입 이미지

메일을 확인하면 다음과 같은 제목의 메일이 도착하며 내용은 아래와 같다.
사용자 삽입 이미지

사용자 삽입 이미지

중요한 부분은 --BEGIN PGP MESSAGE--에서 -END PGP MESSAGE-- 까지이다. 이 암호화 키부분을 아래와 같이 드래그하여 복사한다.
사용자 삽입 이미지

이제 터미널을 열고 pgp라는 이름으로 파일을 생성하고 위 내용을 붙여넣는다.

readytoact-dev@ubuntu9:~/Desktop$ vi gpg

----BEGIN PGP MESSAGE----- Version: GnuPG v1.4.6 (GNU/Linux) hQIOAwJbz7l2QShFEAgAv9SyK/Qd6mTfon4q9xYyYuxjjm68FtjtguG2AsV7YnTf kn5nMuqB1Zr8kgbR6vneR6RHwCLpjDAx3ndgthH+Tz6xyKot3JxqKvgpddq4fvxE ffuZuU/bmHS/TmKtQaApGU9LniF6XIyKU9MPhgeev5C9+GAcPpSTGsK3lXRaBtY7 3zsq0qt29eMhGMre5IsXRSy062VY7nX5MkpejOmgLWXpnffCMKRZ7jUODHR8V2Sq SKmkzrnL2+I+lqXbRohPq7Qw/21M97D9Ns8Mo3ke3b6IHZZA0pC3ysmMWVB6fgrg 5rkP/9gwKtetdp3iTRGlyuTv2nG69nu85eKYIfN/IggA2o8elA1JJTldVt32cuwH AKIHHiJi1rRlzehpM+HzlH3PaqnW9EZb0A41aD9auCNwjwLAQAqO/4ucHvmjeou6 CoDRMReSLhqTA0M4wefkV3c2w0xHKt17aqaDIDdzcR34udPG8j1XfKQ/Jhtqizsx z5rYzjM/ACv3tT44sIjtHO8TUC1Wy87bpK6Zzz0JH9pIiJpHls6nJlzojxxyRGAr vfdP8wW3BmVBZcsZ3nu30Qxobw10oGhnFwpfn313JH1T1VYnz2Hfye09LlNpHt// 6rPUhM2cEGp8oWT2bRir9PPvTuv2rs2rEgwHDlqSJcdVk4GfZE6OjXR9YMiairNC LdLAvQGUBYReBdALajYsu9t6wi+Tidj6hNJLQSMJTxV0ty6ozOfTLclBfMopOL5k SpKt120civi0uPLw+/ppNEMo2l5HHjOoj+ywKA3JYbDR8Q/8opajk0rE5NPUGG/b MYuB1L5WMi1o5U4HlS1WeoY5aj0phOEAvWkYd3LKgiOZBovHsRFwFS6DJ5OcLhF1 B/jTx9MJ5mYk8/uZR4HzhXzFi9q+k7Zc7OOVbZx+O7fzXFeEfDXR1134wfhPbpiq 0d27ujcujXrk7mCp8eeSg9Lhg5E4e30jSBdxwg41H34XxDogc99RXOdvGosPau+C GjPaMtJ77s/eAukntyIACd7p48WNrX6dqrGUhxqUv6XLZwrt4w91Z9/7CqCuFLW6 iYIv3Pf/2yDADSwdm4CEG1orDwIsUYpjGPXOwMCqEXjJ5I23GMbBPPZHjmhGtfi7 9mxg4q9Dlxu4WsFTaWVuCPz9PGWwypGT+drsMwag5qPvSVg0LiXDzTSkONTyglgD 8A== =grvt -----END PGP MESSAGE-----
파일을 저장하고,
readytoact-dev@ubuntu9:~/Desktop$ gpg --decrypt pgp

You need a passphrase to unlock the secret key for
user: "Lee won-hee (readytoact, #ubuntu@irc.hanirc.org) <a*******@paran.com>"
2048-bit ELG-E key, ID 75***8D5, created 2009-06-20 (main key ID 9A30EC52)

gpg: encrypted with 2048-bit ELG-E key, ID 75***8D5, created 2009-06-20
      "Lee won-hee (readytoact, #ubuntu@irc.hanirc.org) <a********@paran.com>"

Here are the instructions for confirming the OpenPGP key registration that we
received for use in Launchpad.

Requester details:

    User name    : readytoact
    Email address: a*********@paran.com

Key details:

    Fingerprint : 166885BF********9B8E97B10D36A3789A30EC52
    Key type/ID : 1024D/9A***C52

UIDs:
    a*******@paran.com

Please go here to finish adding the key to your Launchpad account:

    https://launchpad.net/token/xnLxgmtHKpf2j5zCbQzm
readytoact-dev@ubuntu9:~/Desktop$
정상적으로 진행되면 등록완료를 위한 링크 주소가 보인다.

본인은 여기서 고생을 했다. 이후에 암호키를 복호화(decryption) 해야하는데 이런 메세지가 자꾸 나왔다..무려 두시간이 넘도록..
readytoact-dev@ubuntu9:~/Desktop$ gpg --decrypt pgp
gpg: no valid OpenPGP data found.
gpg: decrypt_message failed: eof
이렇게 되는 원인은 붙여넣기 할 때, 암호화 메세지의 포멧이 변경되어 gpg가 암호화 파일을 해독할 수 없어 이렇게 된다. 내 위 그림에서 보면 메일로 수신된 메세지는 총 5줄로 구성되어 있는데,

1. ---- BEGIN PGP MESSAGE ----
2. Version: GnuPG v1.4.6 (GNU/Linux)
3. 공백라인
4. 암호키(길지만 한줄이다
5. ---- END PGP MESSAGE ----

그런데 어쩐지 붙여넣기를 하면 이게 한 줄로 몰려버리니.. 그래서 포멧을 위와 같이 맞춰 주었다. 이 때, 4번줄 암호키는 공백없이 정확하게 한줄로 자르는게 좋은듯하다. 공백문자등으로 킷값이 변하면 안될테니까(추정일뿐. 테스트하기도 힘들다;;)

위와 같이 작업하면 다음과정으로 진행한다.

위에 보여진 링크를 브라우저 주소창에 붙여넣기 하면 Confirm 페이지가 나타난다
사용자 삽입 이미지
Continue 하면 다시 개인정보 페이지로 이동한다.
사용자 삽입 이미지

화면 아랫쪽 Ubuntero : No 옆 느낌표를 다시한번 클릭하면 Ubuntu Codes of Conduct페이지로 이동한다.
사용자 삽입 이미지

'2. Donwload the Code of Conduct'를 선택하면 'UbuntuCodeofConduct-1.0.1.txt파일을 다운받는다

다운받은 파일을 아래와 같이 실행

readytoact-dev@ubuntu9:~/Desktop$ gpg --clearsign UbuntuCodeofConduct-1.0.1.txt

You need a passphrase to unlock the secret key for
user: "Ubuntu.or.kr (PGP key generation test) <tester@ubuntu.or.kr>"
1024-bit DSA key, ID 752485E5, created 2009-06-21

gpg: problem with the agent - disabling agent use
readytoact-dev@ubuntu9:~/Desktop$ ls
UbuntuCodeofConduct-1.0.1.txt     
UbuntuCodeofConduct-1.0.1.txt.asc
'3. Sing it' 을 클릭하고 보여지는 폼에 생성된 .asc 파일을 에디터로 열고 내용을 복사하여 붙여넣기
사용자 삽입 이미지

서명이 활성화 되었다.
사용자 삽입 이미지


자 이제, 조금 쉽게 가보자. 위 2. PGP 생성과정을 터미널에서 CUI로 진행하지 말고 쉽게 하는 방법을 알려주겠다.
프로그램 -> 보조 프로그램 -> 암호 및 암호화 키 를 실행한다.
사용자 삽입 이미지

기존에 생성된 키가 보인다. 새로운 키를 생성해 보자. 파일-새로 만들기 또는 Ctrl + N
사용자 삽입 이미지

사용자 삽입 이미지

암호를 입력하면 암호를 생성한 뒤 새로운 키가 생성된다.
사용자 삽입 이미지

훨씬 쉽지 않은가?

왜 이걸 이제 갈켜줬냐면.. :p 알지 않는가.. 훗-