このページは機械翻訳したものです。
このセクションでは、openssl コマンドを使用して、MySQL サーバーおよびクライアントで使用する SSL 証明書およびキーファイルを設定する方法について説明します。 1 番目の例は、コマンド行から使用する場合などの単純化された手順を示しています。 2 番目では、より詳細なものを含むスクリプトを示します。 最初の 2 つの例は、Unix で使用するためのものであり、どちらの例でも OpenSSL の一部である openssl コマンドが使用されます。 3 番目の例では、Windows 上で SSL ファイルを設定する方法について説明します。
ここで説明する手順よりも SSL に必要なファイルを生成する方が簡単です: サーバーで自動生成するか、mysql_ssl_rsa_setup プログラムを使用します。 セクション6.3.3.1「MySQL を使用した SSL および RSA 証明書とキーの作成」を参照してください。
証明書および鍵ファイルを生成する際にどの方法を使用するのかには関係なく、サーバーおよびクライアントの証明書と鍵で使用される Common Name の値はそれぞれ、CA 証明書で使用されている Common Name の値と異なる必要があります。 そうしないと、OpenSSL を使用してコンパイルされたサーバーで証明書およびキーファイルが機能しません。 この場合の一般的なエラーは、次のとおりです。
Press CTRL+C to copyERROR 2026 (HY000): SSL connection error: error:00000001:lib(0):func(0):reason(1)
次の例には、MySQL サーバーおよびクライアントの証明書および鍵ファイルを作成するためのコマンドセットを示します。 openssl コマンドでは、複数のプロンプトに応答する必要があります。 すべてのプロンプトに対して Enter キーを押せば、テストファイルを生成できます。 本番環境用のファイルを生成するには、空でない回答を提供するようにしてください。
Press CTRL+C to copy# Create clean environment rm -rf newcerts mkdir newcerts && cd newcerts # Create CA certificate openssl genrsa 2048 > ca-key.pem openssl req -new -x509 -nodes -days 3600 \ -key ca-key.pem -out ca.pem # Create server certificate, remove passphrase, and sign it # server-cert.pem = public key, server-key.pem = private key openssl req -newkey rsa:2048 -days 3600 \ -nodes -keyout server-key.pem -out server-req.pem openssl rsa -in server-key.pem -out server-key.pem openssl x509 -req -in server-req.pem -days 3600 \ -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem # Create client certificate, remove passphrase, and sign it # client-cert.pem = public key, client-key.pem = private key openssl req -newkey rsa:2048 -days 3600 \ -nodes -keyout client-key.pem -out client-req.pem openssl rsa -in client-key.pem -out client-key.pem openssl x509 -req -in client-req.pem -days 3600 \ -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem
証明書が生成されたら、それらを確認します。
Press CTRL+C to copyopenssl verify -CAfile ca.pem server-cert.pem client-cert.pem
次のようなレスポンスが表示されます:
Press CTRL+C to copyserver-cert.pem: OK client-cert.pem: OK
証明書の内容を表示するには (たとえば、証明書が有効な日付の範囲を確認するには)、次のように openssl を起動します:
Press CTRL+C to copyopenssl x509 -text -in ca.pem openssl x509 -text -in server-cert.pem openssl x509 -text -in client-cert.pem
この時点で、次のようなファイルセットを使用できます。
ca.pem
: これを使用して、サーバー側でssl_ca
システム変数を設定し、クライアント側で--ssl-ca
オプションを設定します。 (CA 証明書を使用する場合は、両側で同じものを指定する必要があります。)server-cert.pem
,server-key.pem
: これらを使用して、サーバー側でssl_cert
およびssl_key
システム変数を設定します。client-cert.pem
,client-key.pem
: これらは、クライアント側の--ssl-cert
および--ssl-key
オプションの引数として使用します。
その他の使用手順については、セクション6.3.1「暗号化接続を使用するための MySQL の構成」 を参照してください。
次に、MySQL に SSL 証明書および鍵ファイルを設定する方法を示したサンプルスクリプトを示します。 スクリプトの実行後、セクション6.3.1「暗号化接続を使用するための MySQL の構成」 の説明に従って SSL 接続用のファイルを使用します。
Press CTRL+C to copyDIR=`pwd`/openssl PRIV=$DIR/private mkdir $DIR $PRIV $DIR/newcerts cp /usr/share/ssl/openssl.cnf $DIR replace ./demoCA $DIR -- $DIR/openssl.cnf # Create necessary files: $database, $serial and $new_certs_dir # directory (optional) touch $DIR/index.txt echo "01" > $DIR/serial # # Generation of Certificate Authority(CA) # openssl req -new -x509 -keyout $PRIV/cakey.pem -out $DIR/ca.pem \ -days 3600 -config $DIR/openssl.cnf # Sample output: # Using configuration from /home/jones/openssl/openssl.cnf # Generating a 1024 bit RSA private key # ................++++++ # .........++++++ # writing new private key to '/home/jones/openssl/private/cakey.pem' # Enter PEM pass phrase: # Verifying password - Enter PEM pass phrase: # ----- # You are about to be asked to enter information to 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]:FI # State or Province Name (full name) [Some-State]:. # Locality Name (eg, city) []: # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB # Organizational Unit Name (eg, section) []: # Common Name (eg, YOUR name) []:MySQL admin # Email Address []: # # Create server request and key # openssl req -new -keyout $DIR/server-key.pem -out \ $DIR/server-req.pem -days 3600 -config $DIR/openssl.cnf # Sample output: # Using configuration from /home/jones/openssl/openssl.cnf # Generating a 1024 bit RSA private key # ..++++++ # ..........++++++ # writing new private key to '/home/jones/openssl/server-key.pem' # Enter PEM pass phrase: # Verifying password - 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]:FI # State or Province Name (full name) [Some-State]:. # Locality Name (eg, city) []: # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB # Organizational Unit Name (eg, section) []: # Common Name (eg, YOUR name) []:MySQL server # Email Address []: # # Please enter the following 'extra' attributes # to be sent with your certificate request # A challenge password []: # An optional company name []: # # Remove the passphrase from the key # openssl rsa -in $DIR/server-key.pem -out $DIR/server-key.pem # # Sign server cert # openssl ca -cert $DIR/ca.pem -policy policy_anything \ -out $DIR/server-cert.pem -config $DIR/openssl.cnf \ -infiles $DIR/server-req.pem # Sample output: # Using configuration from /home/jones/openssl/openssl.cnf # Enter PEM pass phrase: # Check that the request matches the signature # Signature ok # The Subjects Distinguished Name is as follows # countryName :PRINTABLE:'FI' # organizationName :PRINTABLE:'MySQL AB' # commonName :PRINTABLE:'MySQL admin' # Certificate is to be certified until Sep 13 14:22:46 2003 GMT # (365 days) # Sign the certificate? [y/n]:y # # # 1 out of 1 certificate requests certified, commit? [y/n]y # Write out database with 1 new entries # Data Base Updated # # Create client request and key # openssl req -new -keyout $DIR/client-key.pem -out \ $DIR/client-req.pem -days 3600 -config $DIR/openssl.cnf # Sample output: # Using configuration from /home/jones/openssl/openssl.cnf # Generating a 1024 bit RSA private key # .....................................++++++ # .............................................++++++ # writing new private key to '/home/jones/openssl/client-key.pem' # Enter PEM pass phrase: # Verifying password - 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]:FI # State or Province Name (full name) [Some-State]:. # Locality Name (eg, city) []: # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB # Organizational Unit Name (eg, section) []: # Common Name (eg, YOUR name) []:MySQL user # Email Address []: # # Please enter the following 'extra' attributes # to be sent with your certificate request # A challenge password []: # An optional company name []: # # Remove the passphrase from the key # openssl rsa -in $DIR/client-key.pem -out $DIR/client-key.pem # # Sign client cert # openssl ca -cert $DIR/ca.pem -policy policy_anything \ -out $DIR/client-cert.pem -config $DIR/openssl.cnf \ -infiles $DIR/client-req.pem # Sample output: # Using configuration from /home/jones/openssl/openssl.cnf # Enter PEM pass phrase: # Check that the request matches the signature # Signature ok # The Subjects Distinguished Name is as follows # countryName :PRINTABLE:'FI' # organizationName :PRINTABLE:'MySQL AB' # commonName :PRINTABLE:'MySQL user' # Certificate is to be certified until Sep 13 16:45:17 2003 GMT # (365 days) # Sign the certificate? [y/n]:y # # # 1 out of 1 certificate requests certified, commit? [y/n]y # Write out database with 1 new entries # Data Base Updated # # Create a my.cnf file that you can use to test the certificates # cat <<EOF > $DIR/my.cnf [client] ssl-ca=$DIR/ca.pem ssl-cert=$DIR/client-cert.pem ssl-key=$DIR/client-key.pem [mysqld] ssl_ca=$DIR/ca.pem ssl_cert=$DIR/server-cert.pem ssl_key=$DIR/server-key.pem EOF
Windows 用の OpenSSL がシステムにインストールされていない場合は、それをダウンロードします。 次に、使用可能なパッケージの概要を示します。
Press CTRL+C to copyhttp://www.slproweb.com/products/Win32OpenSSL.html
アーキテクチャー (32 ビットまたは 64 ビット) に応じて、Win32 OpenSSL Light または Win64 OpenSSL Light パッケージを選択します。 デフォルトのインストール場所は、ダウンロードしたパッケージに応じて C:\OpenSSL-Win32
または C:\OpenSSL-Win64
です。 次の手順では、デフォルトの場所が C:\OpenSSL-Win32
であることが前提となっています。 64 ビットのパッケージを使用している場合は、必要に応じて、これを変更します。
設定中に「...critical component is missing: Microsoft Visual C++ 2008 Redistributables」
というメッセージが発生した場合は、設定を取り消し、アーキテクチャー (32 ビットまたは 64 ビット) に応じて、次のパッケージのいずれかをダウンロードします。
-
Visual C++ 2008 Redistributables (x86) (次の場所で入手可能):
Press CTRL+C to copyhttp://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF
-
Visual C++ 2008 Redistributables (x64) (次の場所で入手可能):
Press CTRL+C to copyhttp://www.microsoft.com/downloads/details.aspx?familyid=bd2a6171-e2d6-4230-b809-9a8d7548c1b6
追加のパッケージをインストールしたら、OpenSSL の設定手順を再開します。
インストール時に、インストールパスとしてデフォルトの C:\OpenSSL-Win32
のままにして、デフォルトの「Copy OpenSSL DLL files to the Windows system directory」
オプションも選択されたままにします。
インストールが完了したら、C:\OpenSSL-Win32\bin
をサーバーの Windows システムパス変数に追加します (Windows のバージョンによっては、次のパス設定手順が若干異なる場合があります):
Windows デスクトップで、「マイコンピュータ」 アイコンを右クリックして を選択します。
表示された
メニューから タブを選択し、 ボタンをクリックします。「システム変数」で を選択してから、 ボタンをクリックします。 のダイアログが表示されます。
末尾に
「;C:\OpenSSL-Win32\bin」
を追加します (セミコロンに注意してください)。「OK」を 3 回押します。
-
新しいコマンドコンソール (Start>Run>cmd.exe) を開いて、OpenSSL が使用可能であることを確認することで、OpenSSL が Path 変数に正しく統合されたことをチェックします。
Press CTRL+C to copyMicrosoft Windows [Version ...] Copyright (c) 2006 Microsoft Corporation. All rights reserved. C:\Windows\system32>cd \ C:\>openssl OpenSSL> exit <<< If you see the OpenSSL prompt, installation was successful. C:\>
OpenSSL がインストールされたら、(このセクションの前半で示した) 例 1 と同様の手順を次のように変更して使用します。
-
次のように Unix コマンドを変更します。
Press CTRL+C to copy# Create clean environment rm -rf newcerts mkdir newcerts && cd newcerts
Windows では、代わりに次のコマンドを使用します。
Press CTRL+C to copy# Create clean environment md c:\newcerts cd c:\newcerts
コマンド行の末尾に
「\」
文字が表示されたら、この「\」
文字を削除し、コマンド行をすべて 1 行で入力する必要があります。
証明書およびキーファイルを生成した後、それらを SSL 接続に使用するには、セクション6.3.1「暗号化接続を使用するための MySQL の構成」 を参照してください。