~ubuntu-branches/ubuntu/saucy/nut/saucy

« back to all changes in this revision

Viewing changes to docs/ssl.txt

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Quette
  • Date: 2004-05-28 13:10:01 UTC
  • mto: (16.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040528131001-yj2m9qcez4ya2w14
Tags: upstream-1.4.2
ImportĀ upstreamĀ versionĀ 1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Desc: Configuring SSL
 
2
File: ssl.txt
 
3
Date: 25 February 2004
 
4
Auth: Russell Kroll <rkroll@exploits.org>
 
5
 
 
6
SSL is now available as a development option.  It encrypts sessions with
 
7
upsd and can also be used to authenticate servers.  This means that
 
8
stealing port 3493 from upsd will no longer net you interesting
 
9
passwords.
 
10
 
 
11
Several things must happen before this will work, however:
 
12
 
 
13
------------------------------------------------------------------------------
 
14
 
 
15
 1. Install OpenSSL.
 
16
 
 
17
------------------------------------------------------------------------------
 
18
 
 
19
 2. Recompile NUT from source, starting with 'configure --with-ssl'.
 
20
 
 
21
------------------------------------------------------------------------------
 
22
 
 
23
 3. Install everything as usual.
 
24
 
 
25
------------------------------------------------------------------------------
 
26
 
 
27
 4. Create a certificate and key for upsd.  
 
28
 
 
29
    openssl (the program) should be in your PATH, unless you installed
 
30
    it from source yourself, in which case it may be in 
 
31
    /usr/local/ssl/bin.
 
32
 
 
33
        openssl req -new -x509 -nodes -out upsd.crt -keyout upsd.key
 
34
 
 
35
    You can also put a "-days nnn" in there to set the expiration.  If
 
36
    you skip this, it may default to 30 days.  This is probably not what
 
37
    you want.    
 
38
 
 
39
    It will ask several questions.  What you put in there doesn't matter
 
40
    a whole lot, since nobody is going to see it for now.  Future
 
41
    versions of the clients may present data from it, so you might use
 
42
    this opportunity to identify each server somehow.
 
43
 
 
44
------------------------------------------------------------------------------
 
45
 
 
46
 5. Figure out the hash for the key.
 
47
 
 
48
        openssl x509 -hash -noout -in upsd.crt
 
49
 
 
50
    You'll get back a single line with 8 hex characters.  This is the
 
51
    hash of the certificate, which is used for naming the client-side
 
52
    certificate.  For the purposes of this example the hash is
 
53
    0123abcd.
 
54
 
 
55
------------------------------------------------------------------------------
 
56
 
 
57
 6. Install the client-side certificate.
 
58
 
 
59
        mkdir <certpath>
 
60
        chmod 0755 <certpath>
 
61
        cp upsd.crt <certpath>/<hash>.0
 
62
 
 
63
    Example:
 
64
 
 
65
        mkdir /usr/local/ups/etc/certs
 
66
        chmod 0755 /usr/local/ups/etc/certs
 
67
        cp upsd.crt /usr/local/ups/etc/certs/0123abcd.0
 
68
 
 
69
    If you already have a file with that name in there, increment the
 
70
    0 until you get a unique filename that works.
 
71
 
 
72
    If you have multiple client systems (like upsmon slaves), be sure
 
73
    to install this file on them as well.
 
74
 
 
75
    I recommend making a directory under your existing confpath to
 
76
    keep everything in the same place.  Remember the path you created,
 
77
    since you will need to put it in upsmon.conf later.  
 
78
 
 
79
    It must not be writable by unprivileged users, since someone could
 
80
    insert a new client certificate and fool upsmon into trusting a
 
81
    fake upsd.
 
82
 
 
83
------------------------------------------------------------------------------
 
84
 
 
85
 7. Create the combined file for upsd.
 
86
 
 
87
        cat upsd.crt upsd.key > upsd.pem
 
88
 
 
89
        chown root:nut upsd.pem
 
90
        chmod 0640 upsd.pem
 
91
 
 
92
    This file must be kept secure, since anyone possessing it could
 
93
    pretend to be upsd and harvest authentication data if they get a
 
94
    hold of port 3493.
 
95
 
 
96
    Having it be owned by root and readable by group nut allows upsd
 
97
    to read the file without being able to change the contents.  This
 
98
    is done to minimize the impact if someone should break into upsd.
 
99
 
 
100
------------------------------------------------------------------------------
 
101
 
 
102
 8. Install the server-side certificate.
 
103
 
 
104
        mv upsd.pem <upsd certfile path>
 
105
 
 
106
    Example:
 
107
 
 
108
        mv upsd.pem /usr/local/ups/etc/upsd.pem
 
109
 
 
110
    After that, edit your upsd.conf and tell it where to find it:
 
111
 
 
112
        CERTFILE /usr/local/ups/etc/upsd.pem
 
113
 
 
114
------------------------------------------------------------------------------
 
115
 
 
116
 9. Clean up the temporary files.
 
117
 
 
118
        rm -f upsd.crt upsd.key
 
119
 
 
120
------------------------------------------------------------------------------
 
121
 
 
122
10. Restart upsd.
 
123
 
 
124
    It should come back up without any complaints.  If it says something
 
125
    about keys or certificates, then you probably missed a step.
 
126
 
 
127
    If you run upsd as a separate user id (like nutsrv), make sure that
 
128
    user can read the upsd.pem file.
 
129
 
 
130
------------------------------------------------------------------------------
 
131
 
 
132
11. Point upsmon at the certificates.
 
133
 
 
134
    Edit your upsmon.conf, and tell it where the CERTPATH is:
 
135
 
 
136
        CERTPATH <path>
 
137
 
 
138
        CERTPATH /usr/local/ups/etc/certs
 
139
 
 
140
------------------------------------------------------------------------------
 
141
 
 
142
12. Recommended: make upsmon verify all connections with certificates.
 
143
 
 
144
    Put this in upsmon.conf:
 
145
 
 
146
        CERTVERIFY 1
 
147
 
 
148
    Without this, there is no guarantee that the upsd is the right host.
 
149
    Enabling this greatly reduces the risk of man in the middle attacks.
 
150
 
 
151
    This effectively forces the use of SSL, so don't use this unless
 
152
    all of your upsd hosts are ready for SSL and have their certificates
 
153
    in order.
 
154
 
 
155
------------------------------------------------------------------------------
 
156
 
 
157
13. Recommended: force upsmon to use SSL.
 
158
 
 
159
    Again in upsmon.conf:
 
160
 
 
161
        FORCESSL 1
 
162
 
 
163
    If you don't use CERTVERIFY 1, then this will at least make sure
 
164
    that nobody can sniff your sessions without a large effort.  Setting
 
165
    this will make upsmon drop connections if the remote upsd doesn't
 
166
    support SSL, so don't use it unless all of them have it running.
 
167
 
 
168
------------------------------------------------------------------------------
 
169
 
 
170
14. Restart upsmon.
 
171
 
 
172
    You should see something like this in the syslog from upsd:
 
173
 
 
174
    foo upsd[1234]: Client mon@localhost logged in to UPS [myups] (SSL)
 
175
 
 
176
    If upsd or upsmon give any error messages, or the (SSL) is missing,
 
177
    then something isn't right.
 
178
 
 
179
    If in doubt about upsmon, start it with -D so it will stay in 
 
180
    the foreground and print debug messages.  It should print something
 
181
    like this every couple of seconds:
 
182
 
 
183
        polling ups: myups@localhost [SSL]
 
184
 
 
185
    Obviously, if the [SSL] isn't there, something's broken.
 
186
 
 
187
------------------------------------------------------------------------------
 
188
 
 
189
15. Recommended: sniff the connection to see it for yourself.
 
190
 
 
191
    Using tcpdump, Ethereal, or another network sniffer tool, tell it
 
192
    to monitor port 3493/tcp and see what happens.  You should only see
 
193
    "STARTTLS" go out, "OK STARTTLS" come back, and the rest will be
 
194
    certificate data and then seemingly random characters.
 
195
 
 
196
    If you see any plaintext besides that (USERNAME, PASSWORD, etc.)
 
197
    then something is not working.
 
198
 
 
199
------------------------------------------------------------------------------
 
200
 
 
201
Note: SSL support is still considered development code, since various
 
202
bits of the implementation may change in the near future.  One thing
 
203
that may happen before long is support for gnutls to avoid licensing
 
204
issues with OpenSSL.
 
205
 
 
206
This is why the other documentation doesn't mention any of these
 
207
directives yet.  SSL support is a treat for those of you that RTFM.
 
208
 
 
209
Potential problems
 
210
==================
 
211
 
 
212
If you specify a certificate expiration date, you will eventually 
 
213
see things like this in your syslog:
 
214
 
 
215
Oct 29 07:27:25 rktoy upsmon[3789]: Poll UPS [for750@rktoy] failed - 
 
216
SSL error: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:
 
217
certificate verify failed
 
218
 
 
219
You can verify that it is expired by using openssl to display the date:
 
220
 
 
221
        openssl x509 -enddate -noout -in <certfile>
 
222
 
 
223
It'll display a date like this:
 
224
 
 
225
        notAfter=Oct 28 20:05:32 2002 GMT
 
226
 
 
227
If that's after the current date, you need to generate another cert/key
 
228
pair using the procedure above.