<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jiramot.info &#187; security</title>
	<atom:link href="http://www.jiramot.info/tag/security/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jiramot.info</link>
	<description>me?.note.each{ println it }</description>
	<lastBuildDate>Fri, 30 Jul 2010 19:57:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SSLUtilities : Accept All Certificate in Java</title>
		<link>http://www.jiramot.info/sslutilities-accept-all-certificate-in-java</link>
		<comments>http://www.jiramot.info/sslutilities-accept-all-certificate-in-java#comments</comments>
		<pubDate>Fri, 12 Dec 2008 09:52:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.jiramot.info/?p=123</guid>
		<description><![CDATA[

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
&#160;
/**
 * This class provide various static methods that relax X509 certificate and
 * hostname verification while using the SSL over the HTTP protocol.
 * 
 * @author Jiramot.info
 */
public final class SSLUtilities &#123;
&#160;
	/**
	 * Hostname verifier for the Sun's deprecated API.
	 * 
	 * @deprecated see [...]]]></description>
			<content:encoded><![CDATA[<p><span id="more-123"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.GeneralSecurityException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.SecureRandom</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.cert.X509Certificate</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.HostnameVerifier</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.HttpsURLConnection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.SSLContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.TrustManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.X509TrustManager</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * This class provide various static methods that relax X509 certificate and
 * hostname verification while using the SSL over the HTTP protocol.
 * 
 * @author Jiramot.info
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> SSLUtilities <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Hostname verifier for the Sun's deprecated API.
	 * 
	 * @deprecated see {@link #_hostnameVerifier}.
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">HostnameVerifier</span> __hostnameVerifier<span style="color: #339933;">;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Thrust managers for the Sun's deprecated API.
	 * 
	 * @deprecated see {@link #_trustManagers}.
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">TrustManager</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> __trustManagers<span style="color: #339933;">;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Hostname verifier.
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> HostnameVerifier _hostnameVerifier<span style="color: #339933;">;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Thrust managers.
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> TrustManager<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> _trustManagers<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Set the default Hostname Verifier to an instance of a fake class that
	 * trust all hostnames. This method uses the old deprecated API from the
	 * com.sun.ssl package.
	 * 
	 * @deprecated see {@link #_trustAllHostnames()}.
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> __trustAllHostnames<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Create a trust manager that does not validate certificate chains</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>__hostnameVerifier <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			__hostnameVerifier <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> _FakeHostnameVerifier<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// if</span>
		<span style="color: #666666; font-style: italic;">// Install the all-trusting host name verifier</span>
		com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">HttpsURLConnection</span>
				.<span style="color: #006633;">setDefaultHostnameVerifier</span><span style="color: #009900;">&#40;</span>__hostnameVerifier<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// __trustAllHttpsCertificates</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Set the default X509 Trust Manager to an instance of a fake class that
	 * trust all certificates, even the self-signed ones. This method uses the
	 * old deprecated API from the com.sun.ssl package.
	 * 
	 * @deprecated see {@link #_trustAllHttpsCertificates()}.
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> __trustAllHttpsCertificates<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">SSLContext</span> context<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Create a trust manager that does not validate certificate chains</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>__trustManagers <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			__trustManagers <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">TrustManager</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">new</span> _FakeX509TrustManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// if</span>
		<span style="color: #666666; font-style: italic;">// Install the all-trusting trust manager</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			context <span style="color: #339933;">=</span> com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">SSLContext</span>.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SSL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			context.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, __trustManagers, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SecureRandom</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">GeneralSecurityException</span> gse<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalStateException</span><span style="color: #009900;">&#40;</span>gse.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// catch</span>
		com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">HttpsURLConnection</span>.<span style="color: #006633;">setDefaultSSLSocketFactory</span><span style="color: #009900;">&#40;</span>context
				.<span style="color: #006633;">getSocketFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// __trustAllHttpsCertificates</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Return true if the protocol handler property java. protocol.handler.pkgs
	 * is set to the Sun's com.sun.net.ssl. internal.www.protocol deprecated
	 * one, false otherwise.
	 * 
	 * @return true if the protocol handler property is set to the Sun's
	 *         deprecated one, false otherwise.
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> isDeprecatedSSLProtocol<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;com.sun.net.ssl.internal.www.protocol&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>
				.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java.protocol.handler.pkgs&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// isDeprecatedSSLProtocol</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Set the default Hostname Verifier to an instance of a fake class that
	 * trust all hostnames.
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> _trustAllHostnames<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Create a trust manager that does not validate certificate chains</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_hostnameVerifier <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			_hostnameVerifier <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FakeHostnameVerifier<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// if</span>
		<span style="color: #666666; font-style: italic;">// Install the all-trusting host name verifier:</span>
		HttpsURLConnection.<span style="color: #006633;">setDefaultHostnameVerifier</span><span style="color: #009900;">&#40;</span>_hostnameVerifier<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// _trustAllHttpsCertificates</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Set the default X509 Trust Manager to an instance of a fake class that
	 * trust all certificates, even the self-signed ones.
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> _trustAllHttpsCertificates<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		SSLContext context<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Create a trust manager that does not validate certificate chains</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_trustManagers <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			_trustManagers <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TrustManager<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">new</span> FakeX509TrustManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// if</span>
		<span style="color: #666666; font-style: italic;">// Install the all-trusting trust manager:</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			context <span style="color: #339933;">=</span> SSLContext.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SSL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			context.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, _trustManagers, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SecureRandom</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">GeneralSecurityException</span> gse<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalStateException</span><span style="color: #009900;">&#40;</span>gse.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// catch</span>
		HttpsURLConnection.<span style="color: #006633;">setDefaultSSLSocketFactory</span><span style="color: #009900;">&#40;</span>context
				.<span style="color: #006633;">getSocketFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// _trustAllHttpsCertificates</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Set the default Hostname Verifier to an instance of a fake class that
	 * trust all hostnames.
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> trustAllHostnames<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Is the deprecated protocol setted?</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isDeprecatedSSLProtocol<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			__trustAllHostnames<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			_trustAllHostnames<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// else</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// trustAllHostnames</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Set the default X509 Trust Manager to an instance of a fake class that
	 * trust all certificates, even the self-signed ones.
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> trustAllHttpsCertificates<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Is the deprecated protocol setted?</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isDeprecatedSSLProtocol<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			__trustAllHttpsCertificates<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			_trustAllHttpsCertificates<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// else</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// trustAllHttpsCertificates</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * This class implements a fake hostname verificator, trusting any host
	 * name. This class uses the old deprecated API from the com.sun. ssl
	 * package.
	 * 
	 * @author Jiramot.info
	 * 
	 * @deprecated see {@link SSLUtilities.FakeHostnameVerifier}.
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> _FakeHostnameVerifier <span style="color: #000000; font-weight: bold;">implements</span>
			com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">HostnameVerifier</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Always return true, indicating that the host name is an acceptable
		 * match with the server's authentication scheme.
		 * 
		 * @param hostname
		 *            the host name.
		 * @param session
		 *            the SSL session used on the connection to host.
		 * @return the true boolean value indicating the host name is trusted.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> verify<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> hostname, <span style="color: #003399;">String</span> session<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// verify</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// _FakeHostnameVerifier</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * This class allow any X509 certificates to be used to authenticate the
	 * remote side of a secure socket, including self-signed certificates. This
	 * class uses the old deprecated API from the com.sun.ssl package.
	 * 
	 * @author Jiramot.info
	 * 
	 * @deprecated see {@link SSLUtilities.FakeX509TrustManager}.
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> _FakeX509TrustManager <span style="color: #000000; font-weight: bold;">implements</span>
			com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">X509TrustManager</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Empty array of certificate authority certificates.
		 */</span>
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> _AcceptedIssuers <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Always return true, trusting for client SSL chain peer certificate
		 * chain.
		 * 
		 * @param chain
		 *            the peer certificate chain.
		 * @return the true boolean value indicating the chain is trusted.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isClientTrusted<span style="color: #009900;">&#40;</span><span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> chain<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// checkClientTrusted</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Always return true, trusting for server SSL chain peer certificate
		 * chain.
		 * 
		 * @param chain
		 *            the peer certificate chain.
		 * @return the true boolean value indicating the chain is trusted.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isServerTrusted<span style="color: #009900;">&#40;</span><span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> chain<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// checkServerTrusted</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Return an empty array of certificate authority certificates which are
		 * trusted for authenticating peers.
		 * 
		 * @return a empty array of issuer certificates.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> getAcceptedIssuers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>_AcceptedIssuers<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// getAcceptedIssuers</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// _FakeX509TrustManager</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * This class implements a fake hostname verificator, trusting any host
	 * name.
	 * 
	 * @author Jiramot.info
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> FakeHostnameVerifier <span style="color: #000000; font-weight: bold;">implements</span> HostnameVerifier <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Always return true, indicating that the host name is an acceptable
		 * match with the server's authentication scheme.
		 * 
		 * @param hostname
		 *            the host name.
		 * @param session
		 *            the SSL session used on the connection to host.
		 * @return the true boolean value indicating the host name is trusted.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> verify<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> hostname, javax.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">SSLSession</span> session<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// verify</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// FakeHostnameVerifier</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * This class allow any X509 certificates to be used to authenticate the
	 * remote side of a secure socket, including self-signed certificates.
	 * 
	 * @author Jiramot.info
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> FakeX509TrustManager <span style="color: #000000; font-weight: bold;">implements</span> X509TrustManager <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Empty array of certificate authority certificates.
		 */</span>
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> _AcceptedIssuers <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Always trust for client SSL chain peer certificate chain with any
		 * authType authentication types.
		 * 
		 * @param chain
		 *            the peer certificate chain.
		 * @param authType
		 *            the authentication type based on the client certificate.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> checkClientTrusted<span style="color: #009900;">&#40;</span><span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> chain, <span style="color: #003399;">String</span> authType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// checkClientTrusted</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Always trust for server SSL chain peer certificate chain with any
		 * authType exchange algorithm types.
		 * 
		 * @param chain
		 *            the peer certificate chain.
		 * @param authType
		 *            the key exchange algorithm used.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> checkServerTrusted<span style="color: #009900;">&#40;</span><span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> chain, <span style="color: #003399;">String</span> authType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// checkServerTrusted</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Return an empty array of certificate authority certificates which are
		 * trusted for authenticating peers.
		 * 
		 * @return a empty array of issuer certificates.
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> getAcceptedIssuers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>_AcceptedIssuers<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// getAcceptedIssuers</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// FakeX509TrustManager</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// SSLUtilities</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.jiramot.info/sslutilities-accept-all-certificate-in-java/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Acception Self-Signed SSL Certificates in Java</title>
		<link>http://www.jiramot.info/acception-self-signed-ssl-certificates-in-java</link>
		<comments>http://www.jiramot.info/acception-self-signed-ssl-certificates-in-java#comments</comments>
		<pubDate>Fri, 12 Dec 2008 08:50:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.jiramot.info/?p=114</guid>
		<description><![CDATA[Approach 1:  สร้าง SocketFactory ขึ้นมาใหม่
Class 1: NativeTrustManager
สร้าง TrustManager โดยที่ไม่มีการ throw Exception ออกมาเมื่อมีการทำ self-singed SSL certificate


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
&#160;
import javax.net.ssl.X509TrustManager;
&#160;
public class NaiveTrustManager implements X509TrustManager&#123;
&#160;
	/**
	* Doesn't throw an exception, so this is how it approves a certificate.
	* @see javax.net.ssl.X509TrustManager#checkClientTrusted(java.security.cert.X509Certificate[], String)
	**/
	public void checkClientTrusted&#40;X509Certificate&#91;&#93; chain, String authType&#41;
			throws CertificateException &#123;
&#160;
	&#125;
&#160;
	/**
	* Doesn't throw an exception, so this is how it approves a [...]]]></description>
			<content:encoded><![CDATA[<p>Approach 1:  สร้าง SocketFactory ขึ้นมาใหม่</p>
<p>Class 1: NativeTrustManager<br />
สร้าง TrustManager โดยที่ไม่มีการ throw Exception ออกมาเมื่อมีการทำ self-singed SSL certificate<br />
<span id="more-114"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.cert.CertificateException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.cert.X509Certificate</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.X509TrustManager</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NaiveTrustManager <span style="color: #000000; font-weight: bold;">implements</span> X509TrustManager<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	* Doesn't throw an exception, so this is how it approves a certificate.
	* @see javax.net.ssl.X509TrustManager#checkClientTrusted(java.security.cert.X509Certificate[], String)
	**/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> checkClientTrusted<span style="color: #009900;">&#40;</span><span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> chain, <span style="color: #003399;">String</span> authType<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">CertificateException</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	* Doesn't throw an exception, so this is how it approves a certificate.
	* @see javax.net.ssl.X509TrustManager#checkServerTrusted(java.security.cert.X509Certificate[], String)
	**/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> checkServerTrusted<span style="color: #009900;">&#40;</span><span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> chain, <span style="color: #003399;">String</span> authType<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">CertificateException</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	* @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
	**/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">X509Certificate</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> getAcceptedIssuers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// I've seen someone return new X509Certificate[ 0 ]; </span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Class 2: สร้าง SelfSignedSSLSocketFactory ใหม่โดยจำทำการ accept self-signed certificate</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">etherdia.gen.util.ssl</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.KeyManagementException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.NoSuchAlgorithmException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.SecureRandom</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.KeyManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.SSLContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.SSLSocketFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.TrustManager</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SelfSignedSSLSocketFactory <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> SSLSocketFactory sslSocketFactory<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Logger logger <span style="color: #339933;">=</span> Logger
			.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>SelfSignedSSLSocketFactory .<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Returns a SSL Factory instance that accepts all server certificates.
	 * 
	 * SSLSocket sock = (SSLSocket) getSocketFactory.createSocket(host, 443);
	 * 
	 * @return An SSL-specific socket factory.
	 **/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> SSLSocketFactory getSocketFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.net.ssl.trustStore &quot;</span>,
				<span style="color: #0000ff;">&quot;org.jiramot.sslutils.NaiveTrustManager&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sslSocketFactory <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				TrustManager<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> tm <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TrustManager<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">new</span> NaiveTrustManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
				SSLContext context <span style="color: #339933;">=</span> SSLContext.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SSL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				context.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> KeyManager<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, tm, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SecureRandom</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				sslSocketFactory <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SSLSocketFactory<span style="color: #009900;">&#41;</span> context
						.<span style="color: #006633;">getSocketFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">KeyManagementException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No SSL algorithm support: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">NoSuchAlgorithmException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>
						<span style="color: #0000ff;">&quot;Exception when setting up the Naive key management.&quot;</span>,
						e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> sslSocketFactory<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Approach 2: สร้าง Security Provider ใหม่โดย extends java.security.Provider โดยทำการแก้ไขให้ทำการสร้าง NativeTrustManager</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.AccessController</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.KeyStore</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.PrivilegedAction</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.Provider</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.Security</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.ManagerFactoryParameters</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.TrustManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.TrustManagerFactorySpi</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Provides all secure socket factories, with a socket that ignores problems in
 * the chain of certificate trust. This is good for embedded applications that
 * just want the encryption aspect of SSL communication, without worrying too
 * much about validating the identify of the server at the other end of the
 * connection. In other words, this may leave you vulnerable to a
 * man-in-the-middle attack.
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NaiveTrustProvider <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Provider</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/** The name of our algorithm **/</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> TRUST_PROVIDER_ALG <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;NaiveTrustAlgorithm&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/** Need to refer to ourselves somehow to know if we're already registered **/</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> TRUST_PROVIDER_ID <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;NaiveTrustProvider&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Hook in at the provider level to handle libraries and 3rd party utilities
	 * that use their own factory. Requires permission to execute
	 * AccessController.doPrivileged, so this probably won't work in applets or
	 * other high-security jvms
	 **/</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> NaiveTrustProvider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>
				TRUST_PROVIDER_ID,
				<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#41;</span> <span style="color: #cc66cc;">0.1</span>,
				<span style="color: #0000ff;">&quot;NaiveTrustProvider (provides all secure socket factories by ignoring problems in the chain of certificate trust)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">AccessController</span>.<span style="color: #006633;">doPrivileged</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">PrivilegedAction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				put<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TrustManagerFactory.&quot;</span>
						<span style="color: #339933;">+</span> NaiveTrustManagerFactory.<span style="color: #006633;">getAlgorithm</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
						NaiveTrustManagerFactory.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * This is the only method the client code need to call. Yup, just put
	 * NaiveTrustProvider.setAlwaysTrust() into your initialization code and
	 * you're good to go
	 * 
	 * @param enableNaiveTrustProvider
	 *            set to true to always trust (set to false it not yet
	 *            implemented)
	 **/</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> setAlwaysTrust<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> enableNaiveTrustProvider<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>enableNaiveTrustProvider<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">Provider</span> registered <span style="color: #339933;">=</span> <span style="color: #003399;">Security</span>.<span style="color: #006633;">getProvider</span><span style="color: #009900;">&#40;</span>TRUST_PROVIDER_ID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">==</span> registered<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">Security</span>.<span style="color: #006633;">insertProviderAt</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> NaiveTrustProvider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">Security</span>.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ssl.TrustManagerFactory.algorithm&quot;</span>,
						TRUST_PROVIDER_ALG<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">UnsupportedOperationException</span><span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">&quot;Disable Naive trust provider not yet implemented&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * The factory for the NaiveTrustProvider
	 **/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> NaiveTrustManagerFactory <span style="color: #000000; font-weight: bold;">extends</span>
			TrustManagerFactorySpi <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">public</span> NaiveTrustManagerFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> engineInit<span style="color: #009900;">&#40;</span>ManagerFactoryParameters mgrparams<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> engineInit<span style="color: #009900;">&#40;</span><span style="color: #003399;">KeyStore</span> keystore<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Returns a collection of trust managers that are naive. This
		 * collection is just a single element array containing our
		 * {@link NaiveTrustManager} class.
		 **/</span>
		<span style="color: #000000; font-weight: bold;">protected</span> TrustManager<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> engineGetTrustManagers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Returns a new array of just a single NaiveTrustManager.</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> TrustManager<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">new</span> NaiveTrustManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * Returns our &quot;NaiveTrustAlgorithm&quot; string.
		 * 
		 * @return The string, &quot;NaiveTrustAlgorithm&quot;
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> getAlgorithm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> TRUST_PROVIDER_ALG<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>ที่มา <a href="http://www.howardism.org/Technical/Java/SelfSignedCerts.htmlr">SelfSignedCerts</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jiramot.info/acception-self-signed-ssl-certificates-in-java/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenSSH Security with Fake banner in FreeBSD</title>
		<link>http://www.jiramot.info/openssh-security-with-fake-banner-in-freebsd</link>
		<comments>http://www.jiramot.info/openssh-security-with-fake-banner-in-freebsd#comments</comments>
		<pubDate>Mon, 24 Nov 2008 04:22:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.jiramot.info/?p=76</guid>
		<description><![CDATA[โดยปกติแล้วเจ้าเซอเวอร์ของเรามันจะโชว์เวอร์ชันของ ssh โดยจะบอกทั้งเวอร์ชั่น ระบบปฏิบัติการ ทำให้เป็นเป้าหมายของเหล่า hacker สามารถค้นหาและสามารถเล่นงานได้โดยง่าย
การทำ fake banner เป็นการเปลี่ยนรายละเอียนของโปรแกรมหรือเซอร์วิส เพื่อให้แสดงข้อมูลอย่างที่เราต้องการ ในตัวอย่างนี้ผมจะทำการเปลี่ยน banner ของ service OpenSSH ที่ลงในระบบปฏิบัตการ FreeBSD
โดยค่าปกติของ SSH Banner เป็นค่า SSH-2.0-OpenSSH_4.5p1
โดยเราจะเปลี่ยนให้เป็นค่า SSH-2.0-JiramotService
โดยทำการเข้าไปแก้ไฟล์ซอร์ส versioh.h ของ OpenSSH โดยใน FreeBSD จะอยู่ที่ 
/usr/scr/crypto/openssh/ 
จากนั้นแก้ให้เป็น
#define SSH_VERSION             (ssh_version_get())
#define SSH_RELEASE          [...]]]></description>
			<content:encoded><![CDATA[<p>โดยปกติแล้วเจ้าเซอเวอร์ของเรามันจะโชว์เวอร์ชันของ ssh โดยจะบอกทั้งเวอร์ชั่น ระบบปฏิบัติการ ทำให้เป็นเป้าหมายของเหล่า hacker สามารถค้นหาและสามารถเล่นงานได้โดยง่าย<br />
การทำ fake banner เป็นการเปลี่ยนรายละเอียนของโปรแกรมหรือเซอร์วิส เพื่อให้แสดงข้อมูลอย่างที่เราต้องการ ในตัวอย่างนี้ผมจะทำการเปลี่ยน banner ของ service OpenSSH ที่ลงในระบบปฏิบัตการ FreeBSD</p>
<p>โดยค่าปกติของ SSH Banner เป็นค่า SSH-2.0-OpenSSH_4.5p1<br />
โดยเราจะเปลี่ยนให้เป็นค่า SSH-2.0-JiramotService</p>
<p>โดยทำการเข้าไปแก้ไฟล์ซอร์ส versioh.h ของ OpenSSH โดยใน FreeBSD จะอยู่ที่ </p>
<blockquote><p>/usr/scr/crypto/openssh/ </p></blockquote>
<p>จากนั้นแก้ให้เป็น</p>
<blockquote><p>#define SSH_VERSION             (ssh_version_get())<br />
#define SSH_RELEASE             (ssh_version_get())<br />
#define SSH_VERSION_BASE        &#8220;JiramotService&#8221;<br />
#define SSH_VERSION_ADDENDUM    &#8220;JiramotInfo&#8221;</p></blockquote>
<p>ทำการบันทึก จากนั้นรีคอมไฟล์ โดยไปที่</p>
<blockquote><p>/usr/src/secure/lib/libssh</p></blockquote>
<blockquote><p>make obj &#038;&#038; make depend &#038;&#038; make &#038;&#038; make install</p></blockquote>
<p>จากนั้นทำการ restart service</p>
<blockquote><p>/etc/rc.d/ssh restart</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.jiramot.info/openssh-security-with-fake-banner-in-freebsd/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache Security with Fake Banner</title>
		<link>http://www.jiramot.info/apache-security-fake-banner</link>
		<comments>http://www.jiramot.info/apache-security-fake-banner#comments</comments>
		<pubDate>Sun, 23 Nov 2008 07:09:21 +0000</pubDate>
		<dc:creator>tonhor</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.jiramot.info/?p=70</guid>
		<description><![CDATA[เพื่อเป็นการป้องการกันโจมที apache server โดยการทำ Fake banner ของ apache service
/etc/httpd/conf/httpd.conf            ; redhat distro
ServerTokens Full,OS,Minor,Minimal,Major,Prod
ServerTokens Setting
ProductOnly	Server: Apache
Major	Server: Apache/2
Minor	Server: Apache/2.0
Minimal	Server: Apache/2.0.55
OS	Server: Apache/2.0.55 (Debian)
Full (or not specified) default	Server: Apache/2.0.55 (Debian) PHP/5.1.2-1+b1 mod_ssl/2.0.55 OpenSSL/0.9.8b
ถ้าจะแก้ไข header :  กรณีที่ต้องการเปลี่ยน banner ไปเลย

/usr/include/httpd/httpd.h            ; apache v.1
/usr/include/httpd/ap_release.h    ; apache v.2
44 #define AP_SERVER_BASEPRODUCT &#8220;Apache&#8221;
45
46 #define AP_SERVER_MAJORVERSION_NUMBER 2
47 #define AP_SERVER_MINORVERSION_NUMBER 2
48 [...]]]></description>
			<content:encoded><![CDATA[<p>เพื่อเป็นการป้องการกันโจมที apache server โดยการทำ Fake banner ของ apache service</p>
<p>/etc/httpd/conf/httpd.conf            ; redhat distro</p>
<p><!--ec2-->ServerTokens Full,OS,Minor,Minimal,Major,Prod</p>
<blockquote><p>ServerTokens Setting<br />
ProductOnly	<!--coloro:#33FF33--><span style="#33ff33;"><!--/coloro-->Server: Apache<!--colorc--></span><!--/colorc--><br />
Major	<!--coloro:#33FF33--><span style="#33ff33;"><!--/coloro-->Server: Apache/2<!--colorc--></span><!--/colorc--><br />
Minor	<!--coloro:#33FF33--><span style="#33ff33;"><!--/coloro-->Server: Apache/2.0<!--colorc--></span><!--/colorc--><br />
Minimal	<!--coloro:#33FF33--><span style="#33ff33;"><!--/coloro-->Server: Apache/2.0.55<!--colorc--></span><!--/colorc--><br />
OS	<!--coloro:#33FF33--><span style="#33ff33;"><!--/coloro-->Server: Apache/2.0.55 (Debian)<!--colorc--></span><!--/colorc--><br />
Full (or not specified) default	<!--coloro:#33FF33--><span style="#33ff33;"><!--/coloro-->Server: Apache/2.0.55 (Debian) PHP/5.1.2-1+b1 mod_ssl/2.0.55 OpenSSL/0.9.8b</span></p></blockquote>
<p>ถ้าจะแก้ไข header :  กรณีที่ต้องการเปลี่ยน banner ไปเลย<br />
<!--c1--></p>
<p><!--ec1-->/usr/include/httpd/httpd.h            ; apache v.1<br />
/usr/include/httpd/ap_release.h    ; apache v.2</p>
<blockquote><p>44 #define AP_SERVER_BASEPRODUCT &#8220;Apache&#8221;<br />
45<br />
46 #define AP_SERVER_MAJORVERSION_NUMBER 2<br />
47 #define AP_SERVER_MINORVERSION_NUMBER 2<br />
48 #define AP_SERVER_PATCHLEVEL_NUMBER   9</p></blockquote>
<p>ตัวอย่างการ config ServerTokens แบบ Full ก็เช่นเวปนี้ จะได้</p>
<p>Apache/2.2.9 (FreeBSD) mod_ssl/2.2.9 OpenSSL/0.9.8e DAV/2</p>
<p>PHP/5.2.6 with Suhosin-Patch SVN/1.5.2</p>
<p>อิอิ</p>
<div class="codemain"><!--c2--></div>
<p><!--ec2--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jiramot.info/apache-security-fake-banner/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ป้องกัน dictionary attack ssh ด้วย SSHGuard</title>
		<link>http://www.jiramot.info/%e0%b8%9b%e0%b9%89%e0%b8%ad%e0%b8%87%e0%b8%81%e0%b8%b1%e0%b8%99-dictionary-attack-ssh-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-sshguard</link>
		<comments>http://www.jiramot.info/%e0%b8%9b%e0%b9%89%e0%b8%ad%e0%b8%87%e0%b8%81%e0%b8%b1%e0%b8%99-dictionary-attack-ssh-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-sshguard#comments</comments>
		<pubDate>Sat, 08 Nov 2008 19:34:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.jiramot.info/?p=6</guid>
		<description><![CDATA[freeBSD โดยปกติแล้วจะไม่ให้ทำการ ssh ด้วย root เพราะว่าจะทำให้โดน brute force ssh เข้ามาได้โดยง่าย
เพื่อความปลอดภัยแล้วจึงควรลง sshguard เพื่อกันไว้อีกชั้นก็ดี

$cd /usr/ports/security/sshguard-ipfw
$make install

แล้วไปทำการแก้ไฟล์ /etc/syslogd.conf
บรรทัดที่เขียนว่า
#auth.info;authpriv.info     &#124;exec /usr/local/sbin/sshguard
ให้นำ # ออกไป

$vi /etc/syslogd.conf

จากนั้นทำการ reload โดยการ

$/etc/rc.d/syslogd reload

โดยระบบจะเก็บ log อยู่ที่ /var/log/auth.log
จากนั้นก็ลอง login แล้วกรอกรหัสผิด 4 ครั้ง ระบบก็จะทำการ block ip เราไปชั่วคราว
]]></description>
			<content:encoded><![CDATA[<p>freeBSD โดยปกติแล้วจะไม่ให้ทำการ ssh ด้วย root เพราะว่าจะทำให้โดน brute force ssh เข้ามาได้โดยง่าย<br />
เพื่อความปลอดภัยแล้วจึงควรลง sshguard เพื่อกันไว้อีกชั้นก็ดี<br />
<code><big><em><br />
$cd /usr/ports/security/sshguard-ipfw<br />
$make install<br />
</em></big></code><br />
แล้วไปทำการแก้ไฟล์ /etc/syslogd.conf<br />
บรรทัดที่เขียนว่า<br />
#auth.info;authpriv.info     |exec /usr/local/sbin/sshguard<br />
ให้นำ # ออกไป<br />
<code><big><em><br />
$vi /etc/syslogd.conf<br />
</em></big></code><br />
จากนั้นทำการ reload โดยการ<br />
<code><big><em><br />
$/etc/rc.d/syslogd reload<br />
</em></big></code><br />
โดยระบบจะเก็บ log อยู่ที่ /var/log/auth.log</p>
<p>จากนั้นก็ลอง login แล้วกรอกรหัสผิด 4 ครั้ง ระบบก็จะทำการ block ip เราไปชั่วคราว</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jiramot.info/%e0%b8%9b%e0%b9%89%e0%b8%ad%e0%b8%87%e0%b8%81%e0%b8%b1%e0%b8%99-dictionary-attack-ssh-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-sshguard/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
