2011年10月27日木曜日

maven: jetty plugin ssl オレオレ証明書 の設定

jetty plugin 8.x での設定

1.keystore の作成
JDKのkeytoolでkeystoreを作成する。

keytool -keystore keystore -alias jetty -genkey -keyalg RSA -storepass (pass) -keypass (pass) -dname "CN=(domain)"


作成されたkeystoreを任意の場所へ


2.pom.xmlの編集
下記のようにpom.xmlにJetty pluginの設定を編集。
jetty-maven-pluginの"<connectors>"にSslSocketConnectorを追加する。

<connector implementation="org.eclipse.jetty.server.ssl.SslSocketConnector">
            <port>8443</port>
            <maxIdleTime>60000</maxIdleTime>
            <keystore>(任意のkeystoreへのパス)</keystore>
            <password>(pass)</password>
            <keyPassword>(pass)</keyPassword>
      </connector>


3.パスワードの暗号化
pom.xmlにパスワードを平文で保存するのは良くないので、
暗号化する。
java -cp jetty-http-8.x.jar:jetty-util-8.x.jar org.eclipse.jetty.http.security.Password (pass)


を実行すると、(pass)->jetty6の場合
jetty6
OBF:1ktv1x0r1z0f1z0f1x1v1kqz
MD5:e032a01e5c4dbb03a29fb031f6b37658


というような値が取得できるので、OBFまたはMD5をpom.xmlに入力する。





ついでに、iPhone等の開発でオレオレ証明書を利用する場合は、
NSURLRequestなら次のようなimplementの追加

@implementation NSURLRequest(NSHTTPURLRequest)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
   return YES; // Or whatever logic
}
@end


ASIHttpRequestならvalidatesSecureCertificate = NOでOK