SlideShare a Scribd company logo
vincentjava@yahoo.com.tw
段維瀚老師 製
Lab
設計一個 WebApp
可以支援 http 與 https
http://localhost:8080/WebSecure/
https://localhost:8443/WebSecure/secure/
段維瀚 老師 1
vincentjava@yahoo.com.tw
段維瀚老師 製
建立 Eclipse Dynamic Web Project
在 webapp/secure 資料夾下建立 index.jsp
在 webapp 資料夾下建立 index.jsp
vincentjava@yahoo.com.tw
段維瀚老師 製
生成金鑰
在指定目錄下建立 tomcat.keystore
指定目錄
在tomcat安裝目錄下的 /conf 中新建立 /keys 資料夾
/Users/vincenttuan/Documents/apache-tomcat-9.0.68/conf/keys
建立 tomcat.keystore 指令:
keytool -genkeypair -alias tomcat -keyalg RSA -keypass
123456 -storepass 123456 -keysize 1024 -validity 365 -
keystore tomcat.keystore
完整路徑名稱:
» keystoreFile="/Users/vincenttuan/Documents/apache-tomcat-9.0.68/conf/keys/tomcat.keystore"
vincentjava@yahoo.com.tw
段維瀚老師 製
修改 web.xml
/secure/* 路徑資源下
要使用 SSL 加密
vincentjava@yahoo.com.tw
段維瀚老師 製
修改 web.xml
<security-constraint> 標籤配置
<security-constraint>
<display-name>Constraint1</display-name>
<web-resource-collection>
<web-resource-name>secure</web-resource-name>
<description/>
<url-pattern>/secure/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
vincentjava@yahoo.com.tw
段維瀚老師 製
修改 server.xml
第一次執行 WebSecure Web 應用程式後會產生 Servers
預設配置
新增配置
vincentjava@yahoo.com.tw
段維瀚老師 製
修改 server.xml
<Connector
port="8443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="200"
scheme="https"
secure="true"
SSLEnabled="true"
keystoreFile="/Users/vincenttuan/Documents/apache-tomcat-9.0.68/conf/keys/tomcat.keystore"
keystorePass="123456"
clientAuth="false"
sslProtocol="TLS"/> 完整金鑰路徑名稱
vincentjava@yahoo.com.tw
段維瀚老師 製
<Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="443"/>
<Connector
port="443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="200"
scheme="https"
secure="true"
SSLEnabled="true"
keystoreFile="/Users/vincenttuan/Documents/apache-tomcat-9.0.68/conf/keys/tomcat.keystore"
keystorePass="123456"
clientAuth="false"
sslProtocol="TLS"/>
正式環境:
HTTP PORT:80
HTTPS PORT:443
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector
port="8443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="200"
scheme="https"
secure="true"
SSLEnabled="true"
keystoreFile="/Users/vincenttuan/Documents/apache-tomcat-9.0.68/conf/keys/tomcat.keystore"
keystorePass="123456"
clientAuth="false"
sslProtocol="TLS"/>
測試環境:
HTTP PORT:8080
HTTPS PORT:8443
vincentjava@yahoo.com.tw
段維瀚老師 製
正式與測試環境執行 URL
正式環境 (80、443 port 可以不用加入)
http://localhost/WebSecure/
https://localhost/WebSecure/secure/
測試環境
http://localhost:8080/WebSecure/
https://localhost:8443/WebSecure/secure/
vincentjava@yahoo.com.tw
段維瀚老師 製
自簽憑證
透過 OpenSSL 工具來產生可信賴的 SSL/TLS 自簽憑證
https://blog.miniasp.com/post/2019/02/25/Creati
ng-Self-signed-Certificate-using-OpenSSL
安裝 OpenSSL
使用 Git 內建的 OpenSSL 工具
當你安裝好 Git for Windows 的時候,其實就已經內建了 OpenSSL
工具
將 C:Program FilesGitusrbin 路徑加入到 PATH 環境變數之
中,以後就可以直接輸入 openssl 來執行此工具。
vincentjava@yahoo.com.tw
段維瀚老師 製
建立 ssl.conf 設定檔
[req]
prompt = no
default_md = sha256
default_bits = 2048
distinguished_name = dn
x509_extensions = v3_req
[dn]
C = TW
ST = Taiwan
L = Taipei
O = WebSecure
OU = Pcschool
emailAddress = admin@example.com
CN = study
[v3_req]
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
IP.1 = 127.0.0.1
vincentjava@yahoo.com.tw
段維瀚老師 製
建立金鑰與憑證
建立出私密金鑰 (server.key) 與憑證檔案
(server.crt)
產生 PKCS#12 憑證檔案 (*.pfx 或 *.p12) 給 Tomcat
使用
openssl req -x509 -new -nodes -sha256 -utf8 -days
3650 -newkey rsa:2048 -keyout server.key -out
server.crt -config ssl.conf
openssl pkcs12 -export -in server.crt -inkey
server.key -out server.pfx
vincentjava@yahoo.com.tw
段維瀚老師 製
查看憑證 for mac
vincentjava@yahoo.com.tw
段維瀚老師 製
修改 server.xml
<Connector
SSLEnabled="true"
SSLEngine="on"
clientAuth="false"
keystoreFile="/Users/vincenttuan/Documents/apache-tomcat-9.0.68/conf/keys/server.pfx"
keystorePass="123456"
keystoreType="pkcs12"
maxThreads="200"
port="8443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
scheme="https"
secure="true"/>
vincentjava@yahoo.com.tw
段維瀚老師 製
執行
不安全的
警告消失

More Related Content

PDF
Storytelling For The Web: Integrate Storytelling in your Design Process
PDF
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
PDF
2024 Trend Updates: What Really Works In SEO & Content Marketing
PDF
人機界面-20230717整理.pdf
PDF
Session1(更新20230205).pdf
DOCX
資訊安全筆記 2023_0129_0205.docx
PDF
Session1.pdf
DOC
資訊安全筆記 2023_0129.doc
Storytelling For The Web: Integrate Storytelling in your Design Process
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
2024 Trend Updates: What Really Works In SEO & Content Marketing
人機界面-20230717整理.pdf
Session1(更新20230205).pdf
資訊安全筆記 2023_0129_0205.docx
Session1.pdf
資訊安全筆記 2023_0129.doc
Ad

Lab 1 建立 HTTP與HTTPS網站.pdf