2011年11月22日火曜日

MySQL5.5 SSL(サーバ認証)の設定

MySQLをSSL通信(サーバ認証)できるように設定します。手順としては、以下のステップを踏みます。

①MySQLサーバの鍵ペアと証明書を発行する。
②MySQLの設定ファイル(my.ini)を修正する(サーバ証明書と鍵のパスを指定)。
③MySQLを再起動する。
④MySQLの接続確認する。

(1)現在のMySQLのSSL設定情報を確認します。もちろん、デフォルトでは無効になってます。

mysql> show variables like 'have_ssl';
+---------------+----------+
| Variable_name | Value    |
+---------------+----------+
| have_ssl      | DISABLED |
+---------------+----------+
1 row in set (0.00 sec)

(2)OpenSSLを使用し、MySQLサーバに対する鍵ペアと証明書を発行します。
■CAの鍵ペアと証明書の作成
C:\tomcat>c:\OpenSSL-Win64\bin\openssl.exe req -new -x509 -keyout "ca-key.pem" -
out "ca-cert.pem"
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
.........++++++
..........++++++
writing new private key to 'ca-key.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:.
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:.
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:ca.yasuyasu.com
Email Address []:

■サーバ証明書と鍵ペアの作成
C:\tomcat>c:\OpenSSL-Win64\bin\openssl.exe req -new -keyout "server-key.pem" -ou
t "server-req.pem" -days 3600
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
.............................++++++
.......++++++
writing new private key to 'server-key.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:.
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:.
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:server.yasuyasu.com
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
C:\tomcat>c:\OpenSSL-Win64\bin\openssl.exe  rsa -in "server-key.pem" -out "serve
r-key.pem"
Enter pass phrase for server-key.pem:
writing RSA key

C:\tomcat>c:\OpenSSL-Win64\bin\openssl.exe x509 -req -days 3600 -CA "ca-cert.pem
" -CAkey "ca-key.pem" -CAserial "serial.conf" -in "server-req.pem" -out "server-
cert.pem"
Loading 'screen' into random state - done
Signature ok
subject=/C=JP/CN=server.yasuyasu.com
Getting CA Private Key
Enter pass phrase for ca-key.pem:
unable to write 'random state'

(3)MySQLの設定ファイル(my.ini)を修正します。太字箇所を追加します。
★パスの区切りは、"\"ではなく、"/"であることに注意!
[mysqld]

ssl-ca=C:/tomcat/ca-cert.pem 
ssl-cert=C:/tomcat/server-cert.pem
ssl-key=C:/tomcat/server-key.pem

(4)MySQLを再起動します。

(5)MySQLのSSL設定を確認します。

c:\>mysql -uroot -ppassword --ssl-ca=c:\tomcat\ca-cert.pem
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.14-log MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like 'have_ssl';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_ssl      | YES   |
+---------------+-------+
1 row in set (0.00 sec)

OpenSSL オレオレCA認証局を作成する

OpenSSLを使用し、オレオレCA認証局を作成します。

①CAの鍵ペアと証明書を作成します(cacert.pemにCA証明書が格納され、cakey.pemに秘密鍵が格納されます)。
OpenSSL> req -new -x509 -newkey rsa:2048 -out cacert.pem -keyout cakey.pem
Loading 'screen' into random state - done
Generating a 2048 bit RSA private key
.................+++
................................................................................
........................+++
writing new private key to 'cakey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:jp
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:yasuyasu
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:yasuyasu.test.com
Email Address []:

②CA証明書が作成されているかを確認します。
OpenSSL> x509 -in cacert.pem -text
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            ab:41:63:c6:6b:3a:65:5d
        Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=jp, ST=Some-State, O=yasuyasu, CN=yasuyasu.test.com
        Validity
            Not Before: Nov 21 15:08:40 2011 GMT
            Not After : Dec 21 15:08:40 2011 GMT
        Subject: C=jp, ST=Some-State, O=yasuyasu, CN=yasuyasu.test.com
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:96:13:b7:72:76:df:f0:ad:96:ff:2d:3f:cd:3f:
                    1f:45:7a:7f:e0:30:49:d6:4a:fd:0d:b7:4b:7c:1c:
                    dd:f3:5f:a1:27:70:c9:ed:d4:41:d7:83:6b:24:d5:
                    6a:61:00:2c:92:7c:3b:85:82:53:fb:c5:e5:9b:37:
                    48:c0:1a:43:7c:2b:11:05:3b:d1:74:9b:66:1b:e1:
                    c1:56:b0:97:67:ec:54:8b:df:79:e5:9e:04:39:a7:
                    94:66:5c:d3:89:d5:ad:5a:9f:f4:7f:3c:ee:bf:ec:
                    0e:e0:be:de:22:45:fb:3b:58:cb:06:b3:50:2a:86:
                    15:2e:55:19:59:f0:e7:b2:fc:3c:73:46:97:9c:ee:
                    23:b3:ff:15:2c:f6:c9:4d:32:4c:b0:3d:83:57:60:
                    6d:e5:9b:a3:e1:fc:73:2a:b9:f8:29:38:1a:49:ba:
                    df:66:0b:21:ad:47:e6:ea:88:e2:13:68:47:1b:62:
                    59:75:f1:12:9d:e7:b7:79:96:df:b1:41:0f:82:92:
                    27:d0:6d:c1:d1:ae:fd:13:27:18:a3:15:c2:a5:ca:
                    12:76:91:3e:a0:9d:e3:93:0b:1d:fb:7c:7d:48:d0:
                    c1:07:bb:ea:f6:7f:4f:81:3e:32:fc:2e:fb:bb:6e:
                    a0:20:3b:90:dc:d5:ca:c2:d0:a1:88:ca:6a:0a:44:
                    53:bf
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Key Identifier:
                62:D3:80:81:56:42:E7:D1:CA:A8:72:18:33:A4:07:39:3F:8D:91:68
            X509v3 Authority Key Identifier:
                keyid:62:D3:80:81:56:42:E7:D1:CA:A8:72:18:33:A4:07:39:3F:8D:91:6
8

            X509v3 Basic Constraints:
                CA:TRUE
    Signature Algorithm: sha1WithRSAEncryption
        69:ed:2b:c3:3f:04:8e:ab:14:2f:17:56:a2:51:96:d3:98:e5:
        a0:9a:be:86:39:c7:7c:27:8a:50:05:d3:c1:6e:49:81:fc:f7:
        f0:b1:67:5d:33:da:58:01:bc:73:79:76:a7:80:80:9b:82:c8:
        a8:81:8d:20:69:e7:fb:b5:4a:a4:8f:e0:34:81:ae:b1:7a:79:
        9b:3a:83:11:4a:22:bb:cc:98:09:d5:30:d9:27:14:74:2c:a5:
        4e:b9:62:ff:39:0d:db:90:fc:d1:c4:0a:e4:5e:80:08:2a:27:
        7b:89:8c:c0:2c:6d:ac:f1:ea:71:30:44:04:cd:d3:a4:73:b0:
        77:d6:6b:7a:22:33:d6:65:ed:48:30:ef:db:52:cc:ae:ec:b5:
        e0:bf:e1:80:a4:d3:83:5d:dd:c2:7c:3c:63:a5:5c:5c:cd:29:
        60:83:9c:49:02:68:1c:02:92:b7:61:70:b8:59:84:f6:2b:10:
        b8:d7:71:60:58:38:db:c1:6d:7a:35:32:6d:dd:5e:d6:4f:4e:
        28:af:57:ea:10:c5:f8:5c:16:dc:46:bc:13:8c:fe:48:0e:99:
        cc:85:08:4b:0d:a6:7e:6e:e5:84:8d:fe:34:aa:7d:35:b3:97:
        e7:a8:4f:45:f6:26:da:e0:a5:f6:f5:8e:a5:c4:0e:ac:22:14:
        11:3e:00:3f
-----BEGIN CERTIFICATE-----
MIIDdTCCAl2gAwIBAgIJAKtBY8ZrOmVdMA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV
BAYTAmpwMRMwEQYDVQQIDApTb21lLVN0YXRlMREwDwYDVQQKDAh5YXN1eWFzdTEa
MBgGA1UEAwwReWFzdXlhc3UudGVzdC5jb20wHhcNMTExMTIxMTUwODQwWhcNMTEx
MjIxMTUwODQwWjBRMQswCQYDVQQGEwJqcDETMBEGA1UECAwKU29tZS1TdGF0ZTER
MA8GA1UECgwIeWFzdXlhc3UxGjAYBgNVBAMMEXlhc3V5YXN1LnRlc3QuY29tMIIB
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlhO3cnbf8K2W/y0/zT8fRXp/
4DBJ1kr9DbdLfBzd81+hJ3DJ7dRB14NrJNVqYQAsknw7hYJT+8XlmzdIwBpDfCsR
BTvRdJtmG+HBVrCXZ+xUi9955Z4EOaeUZlzTidWtWp/0fzzuv+wO4L7eIkX7O1jL
BrNQKoYVLlUZWfDnsvw8c0aXnO4js/8VLPbJTTJMsD2DV2Bt5Zuj4fxzKrn4KTga
SbrfZgshrUfm6ojiE2hHG2JZdfESnee3eZbfsUEPgpIn0G3B0a79EycYoxXCpcoS
dpE+oJ3jkwsd+3x9SNDBB7vq9n9PgT4y/C77u26gIDuQ3NXKwtChiMpqCkRTvwID
AQABo1AwTjAdBgNVHQ4EFgQUYtOAgVZC59HKqHIYM6QHOT+NkWgwHwYDVR0jBBgw
FoAUYtOAgVZC59HKqHIYM6QHOT+NkWgwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0B
AQUFAAOCAQEAae0rwz8EjqsULxdWolGW05jloJq+hjnHfCeKUAXTwW5Jgfz38LFn
XTPaWAG8c3l2p4CAm4LIqIGNIGnn+7VKpI/gNIGusXp5mzqDEUoiu8yYCdUw2ScU
dCylTrli/zkN25D80cQK5F6ACCone4mMwCxtrPHqcTBEBM3TpHOwd9ZreiIz1mXt
SDDv21LMruy14L/hgKTTg13dwnw8Y6VcXM0pYIOcSQJoHAKSt2FwuFmE9isQuNdx
YFg428FtejUybd1e1k9OKK9X6hDF+FwW3Ea8E4z+SA6ZzIUISw2mfm7lhI3+NKp9
NbOX56hPRfYm2uCl9vWOpcQOrCIUET4APw==
-----END CERTIFICATE-----

2011年11月20日日曜日

masquerade RPと接続確認をしてみる

http://memoyasu.blogspot.com/2011/11/openid.html」で構築したRP(OpenIDプラグインを使用したもの)と接続確認をしてみます。
全体像をポンチ絵に書いてみると以下になります。

①RP(http://localhost:3000/consumer/login)にアクセスします。OPのURLとして「http://localhost」を入力して、Loginボタンを押下します
(内部処理では、RPは、OPのログインURLを検索(Discovery)し、OpenID通信に必要となる共有鍵を交換します。その後、RPからOPにリクエストを送信します)

②OP側で以下の画面が表示されます(期待したログイン画面は表示されませんでした)。要約すると、「ユーザのID情報の盗聴を守るために、自分で「http://localhost/login」にアクセスしてログインしてください」とのことです(HTTP通信で平文で通信しているから、こういう画面が表示される仕様なのか?時間があったら、ソースを調べてみよう)。
③言われたとおり、「http://localhost/login」にアクセスしてログインします。すると、RPにOpenIDを提示してよいかを確認する同意画面が表示されます。ボタンを押下します。

④RP側で以下の画面が表示されることを確認できれば接続確認OKです(RPでは、OPから受信したレスポンスを検証OKと判断したようです)

masquerade OPにOpenIDのアカウントを作成する

http://memoyasu.blogspot.com/2011/11/masqueradeopenid.html」で構築したOpenIDサーバ(OP)に、ログインアカウントを作成してログインしてみます(同時に、OpenIDもちゃんと発行されるかを確認します)。

①「http://localhost:3001/」にアクセスします。signupタブを押下し、以下の項目を入力します。入力したら、「Signup」ボタンを押下します。
Login
Email
Password
Password confirmation

②以下の画面が表示されたら、アカウント作成は成功です。



念のため、MySQLのaccountsテーブルに、アカウントが作成されているかを確認します。
mysql> use openiddb;
Database changed
mysql> select login,email from accounts;
+----------+-------------------+
| login    | email             |
+----------+-------------------+
| yasuyasu2 | yasuyasu2@test.com |
+----------+-------------------+
1 row in set (0.00 sec)

③OPにログインします。ログインしてみると、以下のエラー画面が出ました。まだ、作成したアカウントがactivated(有効)になっていないようです(emalアドレスを受信し、アカウントを有効化するリンクをクリックする必要があります)。



ボタンを押下すると、「We sent you an email containing an activation link.」と表示されるため、emailを受信して、アカウントを有効化するリンクをクリックします。以下の画面が表示され、アカウントが有効化されました!
⑤再度ログインしてみます。無事ログインできました!また、OpenIDも発行されました!

masquerade 自分でOpenIDサーバをたてる

「masquerade」を使用し、OpenIDサーバ(OP)を立ててみます。

【参考URL】
https://github.com/dbloete/masquerade/wiki

①以下のサイトから、dbloete-masquerade-fdf8ef1.zipファイルをダウンロードし、任意の場所に格納します。
https://github.com/dbloete/masquerade/

②configフォルダ直下にあるdatabase.yml.exampleをdatabase.ymlに変名します。また、database.ymlに使用するDB情報(MySQLを使用)を設定します。
※予め、MySQLにopeniddbというデータベースを作成する必要があります。
development:
  adapter: mysql2
  host: localhost
  database: openiddb
  username: root
  password: password
  encoding: utf8
test:
  adapter: mysql2
  host: localhost
  database: openiddb
  username: root
  password: password
  encoding: utf8
production:
  adapter: mysql2
  host: localhost
  database: openiddb
  username: root
  password: password
  encoding: utf8

③configフォルダ直下にあるapp_config.yml.exampleをapp_config.ymlに変名します。また、実行環境に合わせて修正します。

④DBマイグレートを実行します。rakeコマンドを実行します。

C:\Users\yasu\Downloads\dbloete-masquerade-fdf8ef1>rake db:migrate
rake aborted!
126: 指定されたモジュールが見つかりません。   - C:/Ruby193/lib/ruby/gems/1.9.1/gem
s/mysql-2.8.1-x86-mingw32/lib/1.9/mysql_api.so

(See full trace by running task with --trace)

LIBMYSQL.dllが見つからない旨のエラーが発生しました。「http://exposed.egoism.jp/wordpress/?p=295」を参照し、libmysql.dllをRubyのbinフォルダおよびlibフォルダにコピーします。
再度、rakeコマンドを実行します。

C:\Users\yasu\Downloads\dbloete-masquerade-fdf8ef1>rake db:migrate
==  CreateInitialSchema: migrating ============================================
-- create_table(:accounts, {:force=>true})
   -> 0.3100s
-- add_index(:accounts, :login, {:unique=>true})
   -> 0.3720s
-- add_index(:accounts, :email, {:unique=>true})
   -> 0.3320s
-- create_table(:personas)
   -> 0.1510s
-- add_index(:personas, [:account_id, :title], {:unique=>true})
   -> 0.3730s
-- create_table(:sites)
   -> 0.1940s
-- add_index(:sites, [:account_id, :url], {:unique=>true})
   -> 0.3530s
-- create_table(:release_policies)
   -> 0.3090s
-- add_index(:release_policies, [:site_id, :property], {:unique=>true})
   -> 1.0720s
-- create_table(:open_id_associations, {:force=>true})
   -> 0.9300s
-- create_table(:open_id_nonces, {:force=>true})
   -> 0.1610s
-- create_table(:open_id_requests, {:force=>true})
   -> 0.2960s
-- add_index(:open_id_requests, :token, {:unique=>true})
   -> 0.3280s
-- create_table(:countries, {:force=>true})
   -> 0.2060s
-- add_index(:countries, :code, {:unique=>true})
   -> 0.3380s
-- create_table(:languages)
   -> 0.2480s
==  CreateInitialSchema: migrated (5.9880s) ===================================

==  AddTypeIdentifierToReleasePolicies: migrating =============================
-- add_column(:release_policies, :type_identifier, :string)
   -> 0.4710s
-- remove_index(:release_policies, {:column=>[:site_id, :property]})
   -> 0.3910s
-- add_index(:release_policies, [:site_id, :property, :type_identifier], {:uniqu
e=>true, :name=>"unique_property"})
   -> 0.3740s
==  AddTypeIdentifierToReleasePolicies: migrated (1.4610s) ====================

==  AddAxPropertiesToPersona: migrating =======================================
-- add_column(:personas, :address, :string)
   -> 0.4380s
-- add_column(:personas, :address_additional, :string)
   -> 0.4590s
-- add_column(:personas, :city, :string)
   -> 0.4240s
-- add_column(:personas, :state, :string)
   -> 1.4440s
-- add_column(:personas, :company_name, :string)
   -> 2.6610s
-- add_column(:personas, :job_title, :string)
   -> 0.7400s
-- add_column(:personas, :address_business, :string)
   -> 0.4900s
-- add_column(:personas, :address_additional_business, :string)
   -> 0.5840s
-- add_column(:personas, :postcode_business, :string)
   -> 0.5400s
-- add_column(:personas, :city_business, :string)
   -> 0.5170s
-- add_column(:personas, :state_business, :string)
   -> 0.7380s
-- add_column(:personas, :country_business, :string)
   -> 1.4160s
-- add_column(:personas, :phone_home, :string)
   -> 0.4050s
-- add_column(:personas, :phone_mobile, :string)
   -> 0.6170s
-- add_column(:personas, :phone_work, :string)
   -> 0.5300s
-- add_column(:personas, :phone_fax, :string)
   -> 0.5850s
-- add_column(:personas, :im_aim, :string)
   -> 0.6920s
-- add_column(:personas, :im_icq, :string)
   -> 0.5820s
-- add_column(:personas, :im_msn, :string)
   -> 0.3670s
-- add_column(:personas, :im_yahoo, :string)
   -> 0.5900s
-- add_column(:personas, :im_jabber, :string)
   -> 0.3650s
-- add_column(:personas, :im_skype, :string)
   -> 0.4500s
-- add_column(:personas, :image_default, :string)
   -> 1.9550s
-- add_column(:personas, :biography, :string)
   -> 1.9280s
-- add_column(:personas, :web_default, :string)
   -> 1.3610s
-- add_column(:personas, :web_blog, :string)
   -> 0.6520s
==  AddAxPropertiesToPersona: migrated (21.5550s) =============================

==  AddYubicoIdentityToAccount: migrating =====================================
-- add_column(:accounts, :yubico_identity, :string, {:limit=>12})
   -> 0.5360s
==  AddYubicoIdentityToAccount: migrated (0.5370s) ============================

==  AddPublicPersona: migrating ===============================================
-- add_column(:accounts, :public_persona_id, :integer)
   -> 0.3990s
==  AddPublicPersona: migrated (0.4010s) ======================================

==  AddAuthenticationAttributesToAccount: migrating ===========================
-- add_column(:accounts, :last_authenticated_at, :datetime)
   -> 0.6540s
-- add_column(:accounts, :last_authenticated_with_yubikey, :boolean)
   -> 0.4520s
==  AddAuthenticationAttributesToAccount: migrated (1.1090s) ==================

==  SplitDob: migrating =======================================================
-- add_column(:personas, :dob_day, :integer, {:limit=>2})
   -> 0.7480s
-- add_column(:personas, :dob_month, :integer, {:limit=>2})
   -> 0.5800s
-- add_column(:personas, :dob_year, :integer, {:limit=>4})
   -> 0.4610s
-- remove_column(:personas, :dob)
   -> 0.8010s
==  SplitDob: migrated (2.6080s) ==============================================

⑤ポート3001でサーバを起動します。

C:\Users\yasu\Downloads\dbloete-masquerade-fdf8ef1>rails server -p 3001
=> Booting WEBrick
=> Rails 3.0.10 application starting in development on http://0.0.0.0:3001
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-11-20 14:32:01] INFO  WEBrick 1.3.1
[2011-11-20 14:32:01] INFO  ruby 1.9.3 (2011-10-30) [i386-mingw32]
[2011-11-20 14:32:01] INFO  WEBrick::HTTPServer#start: pid=6884 port=3001

⑥「http://localhost:3001/」にアクセスし、以下の画面が表示されることを確認します。

2011年11月19日土曜日

Ruby Installing mysql2 (0.2.17) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension

以下のエラーが発生した際の対処方法について説明します。


Installing mysql2 (0.2.17) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension

        C:/Ruby193/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.


上記のエラーは、MySQLのライブラリが検出できないため発生しているようです。
対処方法としては、gemコマンドにオプションを指定して、MySQL2をインストールします。

C:\Users\yasu\Downloads\dbloete-masquerade-fdf8ef1>subst X:  "C:\Program Files (
x86)\MySQL\MySQL Server 5.5"

C:\Users\yasu\Downloads\dbloete-masquerade-fdf8ef1>gem install mysql2 -v 0.2.17
-- --with-mysql-dir=X: --with-mysql-lib=X:\lib
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed mysql2-0.2.17
1 gem installed
Installing ri documentation for mysql2-0.2.17...
Installing RDoc documentation for mysql2-0.2.17...

C:\Users\yasu\Downloads\dbloete-masquerade-fdf8ef1>subst X: /D

【参考URL】
http://stackoverflow.com/questions/3608287/installing-mysql2-gem-for-rails-3

Ruby Please update your PATH to include build tools or download the DevKit from 'http://rubyinstaller.org/downloads'

以下のエラーが発生した際の対処方法について説明します。
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
An error occured while installing json (1.6.1), and Bundler cannot continue.
Make sure that `gem install json -v '1.6.1'` succeeds before bundling.

上記のエラー原因は、Devkitの未インストールのようです。
【参照先URL】
http://qastuffs.blogspot.com/2010/10/how-to-install-ruby-debug-gems-on.html

以下の手順でインストールします。

①以下のサイトからDevkitをインストールします。
http://rubyinstaller.org/downloads/

②ダウンロードしたDevKit-tdm-32-4.5.2-20110712-1620-sfx.exeをダブルクリックし、ファイルを抽出します。

③ファイルを抽出したフォルダに移動し、以下のコマンドを実行します。

C:\Users\yasu\Downloads>ruby dk.rb init
[INFO] found RubyInstaller v1.8.7 at C:/Ruby187
[INFO] found RubyInstaller v1.9.3 at C:/Ruby193
Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

C:\Users\yasu\Downloads>ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/Ruby187'
[INFO] Installing 'C:/Ruby187/lib/ruby/site_ruby/devkit.rb'
[INFO] Updating convenience notice gem override for 'C:/Ruby193'
[INFO] Installing 'C:/Ruby193/lib/ruby/gems/1.9.1/doc/bundler-1.0.21/ri/Bundler/
Source/Rubygems/defaults/operating_system.rb'
[INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/devkit.rb'