Version 55.1 by Paul Hoadley on 2012/03/19 19:33

Show last authors
1 == Introduction ==
2
3 Sooner or later you will need to develop WebObjects applications that work with SSL requests over https protocol. If ssl is configured on your deployment server, you can probably just change http to https in the app entry URL and the app will probably just work over https protocol. However if your application requires security, you cannot just depend on your users typing in a URL that begins with https. Also since SSL encryption adds more load to the webserver, you may want decide that just some pages need to be returned securely over https and the rest returned via plain old http. In any case, you may want to or need to set up your local OS X development machine to support https protocol so that you can properly test your application. Note also that setting up ssl for testing can be a far simpler task (and not really secure) than setting up real authentic SSL certificates for use in a production server.
4
5 {{info title="Compatability"}}
6
7 These instructions were written and tested on the following, but should work on any 10.5.X config or later
8 * OS X Leopard Client 10.5.4
9 * Standard built-in apache2
10 * If you like record and verify your OS config as follows:
11 ** $ openssl version
12 *** OpenSSL 0.9.8g 19 Oct 2007
13 ** $ httpd \-v
14 *** Server version: Apache/2.2.8 (Unix)
15
16 {{/info}}
17
18 === References ===
19
20 * [[http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html#selfcert]]
21 * [[http://www.macosxhints.com/article.php?story=20080628074917113]]
22 * [[http://www.macosxhints.com/article.php?story=20041129143420344]]
23
24 == Development via Apache Webserver ==
25
26 By default, WebObjects development installations typically run via DirectConnect. For https development, we must run thru the apache webserver built in to every OS X machine. So before going any further, configure your WebObjects development environment so that your development application launches and [[runs thru apache>>Development Tools-Running Through Apache]] using the host name "localhost".
27
28 == Configuring Apache for [[https://localhost]] ==
29
30 === Make the private key and SSL certificate ===
31
32 Normally creating SSL certificates for production use is quite involved, however since we are just doing localhost development and testing, we can bypass all the mumbo-jumbo and create the minimal unpassworded private key and SSL certificate the easy way. Do not use this method for creating production server SSL certificates
33
34 Open terminal and follow the commands shown below in my transcript which is self-explanatory if you are familiar with Terminal...
35
36 {{noformat}}
37
38 mymac$ cd /etc/apache2/
39 mymac$ sudo -s
40
41 bash-3.2# mkdir devsslcerts
42 bash-3.2# cd devsslcerts/
43
44
45 {{/noformat}}
46
47 Next run the one single openssl command that will make the two files we need in their final folder that we just created above.
48 Note you will be asked for a bunch of info for the certificate. Follow what I have done below. **In particular, enter "localhost" in the Common Name field**
49
50 {{noformat}}
51
52 bash-3.2# openssl req -days 3650 -new -x509 -nodes -out localhost_server.crt -keyout localhost_server.key
53
54 Generating a 1024 bit RSA private key
55 .........................++++++
56 .....++++++
57 writing new private key to 'localhost_server.key'
58 -----
59 You are about to be asked to enter information that will be incorporated
60 into your certificate request.
61 What you are about to enter is what is called a Distinguished Name or a DN.
62 There are quite a few fields but you can leave some blank
63 For some fields there will be a default value,
64 If you enter '.', the field will be left blank.
65 -----
66 Country Name (2 letter code) [AU]:US
67 State or Province Name (full name) [Some-State]:Florida
68 Locality Name (eg, city) []:Tampa
69 Organization Name (eg, company) [Internet Widgits Pty Ltd]:Five WebObjects Sailors, Inc.
70 Organizational Unit Name (eg, section) []:Software Engineering Department
71 Common Name (eg, YOUR name) []:localhost
72 Email Address []:developer@webobjects.com
73
74 bash-3.2# ls -al
75 total 16
76 drwxr-xr-x 4 root wheel 136 Jul 21 16:58 .
77 drwxr-xr-x 10 root wheel 340 Jul 21 16:56 ..
78 -rw-r--r-- 1 root wheel 1497 Jul 21 16:58 localhost_server.crt
79 -rw-r--r-- 1 root wheel 887 Jul 21 16:58 localhost_server.key
80
81
82 {{/noformat}}
83
84 === Configure Apache2 to Use Your Development Certificates for localhost ===
85
86 Using your favorite command line editor, edit the apache config file at
87 **/etc/apache2/httpd.conf**
88 making the changes shown in the following 2 screenshots:
89
90 {{panel title="Setting Apache server name to localhost"}}
91
92 !step1_servernamelocalhost.jpg!
93
94 {{/panel}}
95
96 {{panel title="Including SSL Configuration file into main Apache config file"}}
97
98 !step2_includesslconfig.jpg!
99
100 {{/panel}}
101
102 Next edit the ssl config file itself at
103 **/etc/apache2/extra/httpd-ssl.conf**
104 making the changes shown in the following sceenshot:
105
106 {{panel title="Setting up the SSL Config file"}}
107
108 !step3_sslconfig.jpg!
109
110 {{/panel}}
111
112 Restart apache
113
114 {{noformat}}
115
116 bash-3.2# apachectl graceful
117
118 {{/noformat}}
119
120 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
121
122 JEFF SCHMITZ
123
124 Right at this point I got the error:
125
126 ulimit: open files: cannot modify limit: Invalid arg
127
128 After a quick google search I found this which seems to have fixed the error:
129
130 [[http://www.perkiset.org/forum/all_things_apple/apache_osx_and_ulimit_a_little_chunk_of_weirdness-t909.0.html]]
131
132 Also, for my [[https://]]... links my rewrite rules in apache weren't getting fired.  To get them to work I had to add them to the httpd-ssl.conf file just below the General setup stuff shown in the figure above.  I just copied them from my httpd.conf file and pasted them in.  Not sure if this is the best way to handle it, but it's working for me on my development machine at least.
133
134 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
135
136 Finally, verify that https is working:
137
138 {{panel title="Verify https://localhost is working"}}
139
140 !httpslocalhost2.jpg!
141
142 {{/panel}}
143
144 == Detecting SSL ==
145
146 Code for detecting whether SSL is active for the current request:
147 I'm told this won't work with IIS:
148
149 {{code}}
150
151 // Is this page being accessed securely?
152 boolean secureMode = false;
153 String header = context.request().headerForKey("https");
154 if( header == null ) {
155 log.debug( "no https header, looking for server_port" );
156 header = context.request().headerForKey( "server_port" );
157 if( header == null ) {
158 log.debug( "no server_port header found, assuming insecure connection" );
159 } else {
160 log.debug( "server_port header found, using it" );
161 secureMode = header.equals( "443" );
162 }
163 } else {
164 log.debug( "https header found, using it" );
165 secureMode = header.equals( "on" );
166 }
167 log.debug( "secure mode set to " + secureMode );
168
169 {{/code}}
170
171 == Using SSL in DirectConnect ==
172
173 Mike Schrag said in early 2011 that it was possible to use SSL in DirectConnect, that is was simply hidden. A property was added to enable it, and instructions added to the Properties file of ERExtensions. This is the part from the Properties file:
174
175 {{code}}
176
177
178 ## You should probably not enable any of these settings in a normal Apache webserver deployment,
179 ## in particular the ssl port property, as this is used by ERX to generate https URLs, which must
180 ## match your Apache config.
181 ##
182 ## To enable SSL support with DirectConnect, you must do the following:
183 ##
184 ## * In your Resources folder, run "keytool -genkey -alias WebObjects -keyalg RSA -keystore adaptorssl.key". Select a
185 ## password for your keystore (i.e. "changeit"), and set the "your first name and last name" field to match the hostname
186 ## that you will be running your directconnect app off of.
187 ## * In your Resources folder, create an executable script (it MUST BE EXECUTABLE) named "adaptorsslpassphrase" with the
188 ## contents:
189 ## echo changeit
190 ## where you should replace "changeit" for whatever password you selected in the previous step.
191 ## * Set the following property to true
192 #er.extensions.ERXApplication.ssl.enabled=true
193
194 ## (optional) To specify an SSL host name other than what is returned from a call to
195 ## application.host(), you can override it below
196 #er.extensions.ERXApplication.ssl.host=localhost
197
198 ## (optional) To select an SSL port other than 443, uncomment the following. If you are already running Apache with SSL,
199 ## you probably want to set this. If the port number is 0, the SSL port will be automatically assigned (using the same
200 ## mechanism that WO uses to set the regular port)
201 #er.extensions.ERXApplication.ssl.port=0
202
203 {{/code}}