{"id":220,"date":"2020-06-10T10:27:15","date_gmt":"2020-06-10T02:27:15","guid":{"rendered":"http:\/\/www.gbase8.cn\/?p=220"},"modified":"2020-09-17T06:18:07","modified_gmt":"2020-09-16T22:18:07","slug":"gbase-8a%e9%9b%86%e7%be%a4ssl%e9%85%8d%e7%bd%ae-jdbc","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/220","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u96c6\u7fa4SSL\u914d\u7f6e-JDBC"},"content":{"rendered":"\n<p>\u7531\u4e8essl\u662f\u4e00\u5957\u8f6f\u52a0\u5bc6\u65b9\u5f0f\uff0c\u548c\u4e3b\u673a\u914d\u7f6e\u65e0\u5173\uff0c\u4ee5\u4e0b\u64cd\u4f5c\u5747\u5728\u5ba2\u6237\u7aef\u6267\u884c\uff0c\u8fd9\u91cc\u7684\u5ba2\u6237\u7aef\u662f\u4e00\u4e2a\u62bd\u8c61\u540d\u79f0\uff0c\u5ba2\u6237\u7aef\u5373\u53ef\u4ee5\u662flinux\u73af\u5883\uff0c\u4e5f\u53ef\u4ee5\u662fwindows\u73af\u5883\u3002\u672c\u7ae0\u8282\u4ee5windows\u73af\u5883\u4e3a\u4f8b\u8bf4\u660e\uff0clinux\u73af\u5883\u4e0b\u914d\u7f6e\u65b9\u5f0f\u4e0e\u6b64\u76f8\u540c\u3002<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u628agbase Client\u51ed\u8bc1\u8f6c\u6362\u6210DER\u683c\u5f0f\u3002\uff08\u672c\u64cd\u4f5c\u53ef\u4ee5\u5728linux\u73af\u5883\u4e0b\u751f\u6210\u518dcopy\u81f3windows\u73af\u5883\u4e0b\uff09<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>openssl x509 -outform DER -in client-cert.pem -out client.cert<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5f53\u524d\u76ee\u5f55\u4e0b\u4f1a\u751f\u6210client.cert\u6587\u4ef6<\/p>\n\n\n\n<p>\u6839\u636eclient.cert\u6587\u4ef6\u751f\u6210\u5ba2\u6237\u7aefkeystore\u6587\u4ef6<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>C:\\Program Files (x86)\\Java\\jre1.8.0_60\\bin&gt;keytool -import -file c:\\SSL\\client.<br>cert -keystore keystore<br>\u8f93\u5165\u5bc6\u94a5\u5e93\u53e3\u4ee4:<br>\u518d\u6b21\u8f93\u5165\u65b0\u53e3\u4ee4:<br>\u6240\u6709\u8005: EMAILADDRESS=1, CN=1, OU=1, O=1, L=1, ST=1, C=11<br>\u53d1\u5e03\u8005: EMAILADDRESS=1, CN=1, OU=1, O=1, L=1, ST=1, C=11<br>\u5e8f\u5217\u53f7: 1<br>\u6709\u6548\u671f\u5f00\u59cb\u65e5\u671f: Fri Nov 25 05:52:22 CST 2016, \u622a\u6b62\u65e5\u671f: Sun Nov 25 05:52:22 CST<br>2018<br>\u8bc1\u4e66\u6307\u7eb9:<br>MD5: 37:24:8E:14:C7:77:E4:67:CA:BB:17:36:A6:04:CF:9E<br>SHA1: CB:24:7E:D0:2D:6B:99:30:9B:A6:D5:4B:0E:9A:9D:A8:46:DC:FB:A3<br>SHA256: CC:82:98:4D:E9:49:A2:F1:7C:8B:6A:A7:13:4E:A7:8E:B2:67:8E:E7:05:<br>BD:59:18:34:72:F3:8E:D9:83:4A:2D<br>\u7b7e\u540d\u7b97\u6cd5\u540d\u79f0: SHA1withRSA<br>\u7248\u672c: 1<br>\u662f\u5426\u4fe1\u4efb\u6b64\u8bc1\u4e66? [\u5426]: \u662f<br>\u8bc1\u4e66\u5df2\u6dfb\u52a0\u5230\u5bc6\u94a5\u5e93\u4e2d<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6839\u636eca-cert.pem\u6587\u4ef6\u751f\u6210truststore<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>C:\\Program Files (x86)\\Java\\jre1.8.0_60\\bin&gt;keytool -import -file c:\\SSL\\ca-cert<br>.pem -keystore truststore<br>\u8f93\u5165\u5bc6\u94a5\u5e93\u53e3\u4ee4:<br>\u518d\u6b21\u8f93\u5165\u65b0\u53e3\u4ee4:<br>\u6240\u6709\u8005: EMAILADDRESS=1, CN=1, OU=1, O=1, L=1, ST=1, C=11<br>\u53d1\u5e03\u8005: EMAILADDRESS=1, CN=1, OU=1, O=1, L=1, ST=1, C=11<br>\u5e8f\u5217\u53f7: b03b0e19ba5e219f<br>\u6709\u6548\u671f\u5f00\u59cb\u65e5\u671f: Fri Nov 25 05:46:43 CST 2016, \u622a\u6b62\u65e5\u671f: Mon Nov 23 05:46:43 CST<br>2026<br>\u8bc1\u4e66\u6307\u7eb9:<br>MD5: 3A:A6:E4:CA:24:6F:DB:29:2C:7B:1A:82:C3:9B:2F:8B<br>SHA1: 3F:84:D5:2F:3E:EC:A2:D9:B4:0A:63:85:B9:4B:82:F8:5F:1A:16:59<br>SHA256: 62:AE:D2:7B:CE:64:90:CE:47:DE:40:7B:67:1F:E8:41:11:DA:74:F6:AA:<br>DB:6A:D2:A5:D3:70:D4:F9:FA:3C:8C<br>\u7b7e\u540d\u7b97\u6cd5\u540d\u79f0: SHA1withRSA<br>\u7248\u672c: 3<br>\u6269\u5c55:<br>1: ObjectId: 2.5.29.35 Criticality=false<br>AuthorityKeyIdentifier [<br>KeyIdentifier [<br>0000: FF 62 CD C7 DC D9 93 48 E7 D7 88 A1 17 EF 80 C7 .b\u2026..H\u2026\u2026..<br>0010: F2 E9 29 90 ..).<br>]<br>]<br>2: ObjectId: 2.5.29.19 Criticality=false<br>BasicConstraints:[<br>CA:true<br>PathLen:2147483647<br>]<br>3: ObjectId: 2.5.29.14 Criticality=false<br>SubjectKeyIdentifier [<br>KeyIdentifier [<br>0000: FF 62 CD C7 DC D9 93 48 E7 D7 88 A1 17 EF 80 C7 .b\u2026..H\u2026\u2026..<br>0010: F2 E9 29 90 ..).<br>]<br>]<br>\u662f\u5426\u4fe1\u4efb\u6b64\u8bc1\u4e66? [\u5426]: \u662f<br>\u8bc1\u4e66\u5df2\u6dfb\u52a0\u5230\u5bc6\u94a5\u5e93\u4e2d<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5c06\u4e24\u4e2a\u6587\u4ef6\u653e\u7f6e\u5728\u4e00\u4e2a\u81ea\u5b9a\u4e49\u76ee\u5f55\uff0c\u4ee5\u4fbf\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5f15\u7528\uff0c\u5982\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>c:\/SSL\/keystore c:\/SSL\/truststore<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Java\u7a0b\u5e8f\u6837\u4f8b\uff1a\uff08\u5de5\u7a0b\u9700\u5f15\u7528\u96c6\u7fa4JDBC\u63a5\u53e3\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package gbase.sc;\n\nimport java.sql.*;\n\npublic class GBaseConTest {\n\tpublic static void main(String&#91;] args) {\n\n\t\tString trustStorePath = \"c:\/SSL\/truststore\";\n\t\tString keyStorePath = \"c:\/SSL\/keystore\";\n\t\tSystem.setProperty(\"javax.net.ssl.keyStore\", keyStorePath);\n\n\t\tSystem.setProperty(\"javax.net.ssl.keyStorePassword\", \"123456\");\n\n\t\tSystem.setProperty(\"javax.net.ssl.trustStore\", trustStorePath);\n\n\t\tSystem.setProperty(\"javax.net.ssl.trustStorePassword\", \"123456\");\n\n\t\tConnection con = null;\n\t\tStatement stm = null;\n\t\tResultSet rs = null;\n\t\tResultSetMetaData rsmd = null;\n\n\t\ttry {\n\t\t\t\/\/ \u52a0\u8f7djdbc\u9a71\u52a8\u7c7b\n\t\t\tClass.forName(\"com.gbase.jdbc.Driver\");\n\t\t\t\/\/ \u83b7\u53d6\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u6ce8\u610fIP\u3001\u7528\u6237\u540d\u548c\u5bc6\u7801\u53ca\u6570\u636e\u5e93\u9700\u8981\u8ddf\u81ea\u5df1\u670d\u52a1\u5668\u4e00\u81f4\n\t\t\tcon = (Connection) DriverManager.getConnection(\n\t\t\t\t\t\"jdbc:gbase:\/\/192.168.5.121:5258\/zhao?user=gbase&amp;password=gbase20110531&amp;useSSL=true&amp;requireSSL=true\");\n\t\t\tSystem.out.println(\"\u8fde\u63a5\u5efa\u7acb\u6210\u529f\uff01\");\n\n\t\t\tstm = con.createStatement();\n\n\t\t\trs = stm.executeQuery(\"select * from bryan\");\n\t\t\tif (rs == null) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\trsmd = rs.getMetaData();\n\t\t\tint rsColoumnCount = rsmd.getColumnCount();\n\n\t\t\twhile (rs.next()) {\n\t\t\t\tSystem.out.println(\"executeSQLByStatement===========================\");\n\t\t\t\tfor (int i = 0; i &lt; rsColoumnCount; i++) {\n\t\t\t\t\tSystem.out.print(rsmd.getColumnName(i + 1).concat(\" = \"));\n\t\t\t\t\tSystem.out.println(rs.getObject(i + 1));\n\t\t\t\t}\n\t\t\t\tSystem.out.println(\"executeSQLByStatement===========================\");\n\n\t\t\t}\n\n\t\t} catch (ClassNotFoundException ex) {\n\t\t\t\/\/ \u8f93\u51fa\u9a71\u52a8\u76f8\u5173\u5f02\u5e38\n\t\t\tSystem.out.println(ex.toString());\n\t\t} catch (SQLException ex1) {\n\t\t\t\/\/ \u8f93\u51fa\u5176\u4ed6sql\u5f02\u5e38\n\t\t\tSystem.out.println(ex1.toString());\n\t\t} finally {\n\t\t\ttry {\n\t\t\t\tif (con != null) {\n\t\t\t\t\t\/\/ \u5173\u95ed\u8fde\u63a5\n\n\t\t\t\t\trs.close();\n\t\t\t\t\tstm.close();\n\t\t\t\t\tcon.close();\n\t\t\t\t\tSystem.out.println(\"\u8fde\u63a5\u5df2\u5173\u95ed\");\n\t\t\t\t}\n\t\t\t} catch (SQLException ex2) {\n\t\t\t\tSystem.out.println(ex2.toString());\n\t\t\t}\n\n\t\t}\n\n\t}\n}<\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>\u8fde\u63a5\u5efa\u7acb\u6210\u529f\uff01 executeSQLByStatement=========================== a = 1 b = asdf executeSQLByStatement=========================== executeSQLByStatement=========================== a = 2 b = wer executeSQLByStatement=========================== executeSQLByStatement=========================== a = 3 b = time executeSQLByStatement=========================== executeSQLByStatement=========================== a = 1 b = asdf executeSQLByStatement=========================== executeSQLByStatement=========================== a = 2 b = wer executeSQLByStatement=========================== executeSQLByStatement=========================== a = 3 b = time executeSQLByStatement=========================== executeSQLByStatement=========================== a = 1 b = asdf executeSQLByStatement=========================== executeSQLByStatement=========================== a = 2 b = wer executeSQLByStatement=========================== executeSQLByStatement=========================== a = 3 b = time executeSQLByStatement=========================== executeSQLByStatement=========================== a = 1 b = asdf executeSQLByStatement=========================== executeSQLByStatement=========================== a = 2 b = wer executeSQLByStatement=========================== executeSQLByStatement=========================== a = 3 b = time executeSQLByStatement=========================== \u8fde\u63a5\u5df2\u5173\u95ed &nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u96c6\u7fa4SSL\u914d\u7f6e-JDBC<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,7],"tags":[16,15],"class_list":{"0":"post-220","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-gbase8a","8":"tag-jdbc","9":"tag-ssl"},"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=220"}],"version-history":[{"count":4,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":1398,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/220\/revisions\/1398"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}