~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/security/nss/tests/pkcs11/netscape/suites/security/ssl/sslc.c

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contents of this file are subject to the Mozilla Public
 
3
 * License Version 1.1 (the "License"); you may not use this file
 
4
 * except in compliance with the License. You may obtain a copy of
 
5
 * the License at http://www.mozilla.org/MPL/
 
6
 * 
 
7
 * Software distributed under the License is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the License for the specific language governing
 
10
 * rights and limitations under the License.
 
11
 * 
 
12
 * The Original Code is the Netscape security libraries.
 
13
 * 
 
14
 * The Initial Developer of the Original Code is Netscape
 
15
 * Communications Corporation.  Portions created by Netscape are 
 
16
 * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 
17
 * Rights Reserved.
 
18
 * 
 
19
 * Contributor(s):
 
20
 * 
 
21
 * Alternatively, the contents of this file may be used under the
 
22
 * terms of the GNU General Public License Version 2 or later (the
 
23
 * "GPL"), in which case the provisions of the GPL are applicable 
 
24
 * instead of those above.  If you wish to allow use of your 
 
25
 * version of this file only under the terms of the GPL and not to
 
26
 * allow others to use your version of this file under the MPL,
 
27
 * indicate your decision by deleting the provisions above and
 
28
 * replace them with the notice and other provisions required by
 
29
 * the GPL.  If you do not delete the provisions above, a recipient
 
30
 * may use your version of this file under either the MPL or the
 
31
 * GPL.
 
32
 */
 
33
 
 
34
/* include replacer-generated variables file */
 
35
 
 
36
 
 
37
#include "ssl.h"
 
38
#include "sslproto.h"
 
39
 
 
40
#include "sslt.h"
 
41
#include "sslc.h"
 
42
#include "ssls.h"
 
43
 
 
44
#include "pk11func.h"
 
45
 
 
46
#define MAX_CIPHERS 100
 
47
 
 
48
struct cipherspec cipher_array[MAX_CIPHERS];
 
49
int cipher_array_size=0;
 
50
char *password = "";
 
51
char *nickname = "SSLServer";
 
52
char *client_nick = "SSLClient";
 
53
 
 
54
void InitCiphers() {
 
55
  int i=0;
 
56
 
 
57
/* These ciphers are listed in priority order. */
 
58
  DIPHER(2,SSL_ALLOWED,128,40,     "RC2-CBC-Export", EN_RC2_128_CBC_EXPORT40_WITH_MD5)
 
59
    CIPHER(2,SSL_NOT_ALLOWED,128,128,"RC4",            EN_RC4_128_WITH_MD5)
 
60
    CIPHER(2,SSL_ALLOWED,128,40,     "RC4-Export",     EN_RC4_128_EXPORT40_WITH_MD5)
 
61
    DIPHER(2,SSL_NOT_ALLOWED,128,128,"RC2-CBC",        EN_RC2_128_CBC_WITH_MD5)
 
62
    DIPHER(2,SSL_ALLOWED,128,40,     "RC2-CBC-40", EN_RC2_128_CBC_EXPORT40_WITH_MD5)
 
63
    DIPHER(2,SSL_NOT_ALLOWED,128,128,"IDEA-CBC",       EN_IDEA_128_CBC_WITH_MD5)
 
64
    DIPHER(2,SSL_NOT_ALLOWED,56,56,  "DES-CBC",        EN_DES_64_CBC_WITH_MD5)
 
65
    CIPHER(2,SSL_NOT_ALLOWED,168,168,"DES-EDE3-CBC",   EN_DES_192_EDE3_CBC_WITH_MD5)
 
66
  /* SSL 3 suites */
 
67
 
 
68
    CIPHER(3,SSL_RESTRICTED,128,128, "RC4",            RSA_WITH_RC4_128_MD5)
 
69
    DIPHER(3,SSL_RESTRICTED,128,128, "RC4",            RSA_WITH_RC4_128_SHA)
 
70
    CIPHER(3,SSL_RESTRICTED,168,168, "3DES-EDE-CBC",   RSA_WITH_3DES_EDE_CBC_SHA)
 
71
    CIPHER(3,SSL_NOT_ALLOWED,56,56,"DES-CBC",        RSA_WITH_DES_CBC_SHA)
 
72
    CIPHER(3,SSL_ALLOWED,128,40,     "RC4-40",         RSA_EXPORT_WITH_RC4_40_MD5)
 
73
    CIPHER(3,SSL_ALLOWED,128,40,     "RC2-CBC-40",     RSA_EXPORT_WITH_RC2_CBC_40_MD5)
 
74
 
 
75
    DIPHER(3,SSL_ALLOWED,0,0,        "NULL",           NULL_WITH_NULL_NULL)
 
76
    DIPHER(3,SSL_ALLOWED,0,0,        "NULL",           RSA_WITH_NULL_MD5)
 
77
    DIPHER(3,SSL_ALLOWED,0,0,        "NULL",           RSA_WITH_NULL_SHA)
 
78
 
 
79
#if 0
 
80
    DIPHER(3,SSL_NOT_ALLOWED,0,0,    "IDEA-CBC",       RSA_WITH_IDEA_CBC_SHA)
 
81
    DIPHER(3,SSL_ALLOWED,128,40,     "DES-CBC-40",     RSA_EXPORT_WITH_DES40_CBC_SHA)
 
82
#endif
 
83
 
 
84
  /*
 
85
    
 
86
  CIPHER(DH_DSS_EXPORT_WITH_DES40_CBC_SHA),
 
87
  CIPHER(DH_DSS_WITH_DES_CBC_SHA),
 
88
  CIPHER(DH_DSS_WITH_3DES_EDE_CBC_SHA),
 
89
  CIPHER(DH_RSA_EXPORT_WITH_DES40_CBC_SHA),
 
90
  CIPHER(DH_RSA_WITH_DES_CBC_SHA),
 
91
  CIPHER(DH_RSA_WITH_3DES_EDE_CBC_SHA),
 
92
  CIPHER(DHE_DSS_EXPORT_WITH_DES40_CBC_SHA),
 
93
  CIPHER(DHE_DSS_WITH_DES_CBC_SHA),
 
94
  CIPHER(DHE_DSS_WITH_3DES_EDE_CBC_SHA),
 
95
  CIPHER(DHE_RSA_EXPORT_WITH_DES40_CBC_SHA),
 
96
  CIPHER(DHE_RSA_WITH_DES_CBC_SHA),
 
97
  CIPHER(DHE_RSA_WITH_3DES_EDE_CBC_SHA),
 
98
 
 
99
  CIPHER(DH_ANON_EXPORT_WITH_RC4_40_MD5),
 
100
  CIPHER(DH_ANON_WITH_RC4_128_MD5),
 
101
  CIPHER(DH_ANON_WITH_DES_CBC_SHA),
 
102
  CIPHER(DH_ANON_WITH_3DES_EDE_CBC_SHA),
 
103
 
 
104
  CIPHER(3,SSL_NOT_ALLOWED,0,0,"Fortezza",        FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA),
 
105
  CIPHER(3,SSL_NOT_ALLOWED,0,0,"Fortezza",        FORTEZZA_DMS_WITH_RC4_128_SHA),
 
106
 
 
107
  */
 
108
 
 
109
    DIPHER(3,SSL_NOT_ALLOWED,192,192,"3DES-EDE-CBC",RSA_FIPS_WITH_3DES_EDE_CBC_SHA)
 
110
    DIPHER(3,SSL_NOT_ALLOWED,64,64,  "DES-CBC",       RSA_FIPS_WITH_DES_CBC_SHA)
 
111
    
 
112
    cipher_array_size =i;
 
113
}
 
114
 
 
115
 
 
116
 
 
117
/* ClearCiphers()
 
118
 *   Clear out all ciphers */
 
119
 
 
120
void ClearCiphers(struct ThreadData *td) {
 
121
int i;
 
122
 
 
123
for (i=0;i<cipher_array_size;i++) {
 
124
SSL_EnableCipher(cipher_array[i].enableid,0);
 
125
}
 
126
}
 
127
 
 
128
 
 
129
/* EnableCiphers
 
130
 *   enable only those ciphers set for this test */
 
131
 
 
132
void EnableCiphers(struct ThreadData *td) {
 
133
  int i;
 
134
 
 
135
  for (i=0;i<cipher_array_size;i++) {
 
136
    if (cipher_array[i].on) {
 
137
      SSL_EnableCipher(cipher_array[i].enableid,1);
 
138
    }
 
139
  }
 
140
}
 
141
 
 
142
/* SetPolicy */
 
143
 
 
144
void SetPolicy() {
 
145
  int i;
 
146
 
 
147
  for (i=0;i<cipher_array_size;i++) {
 
148
    if (REP_Policy == POLICY_DOMESTIC) {
 
149
      SSL_SetPolicy(cipher_array[i].enableid,SSL_ALLOWED);
 
150
    }
 
151
    else {
 
152
      SSL_SetPolicy(cipher_array[i].enableid,cipher_array[i].exportable);
 
153
    }
 
154
  }
 
155
}
 
156
 
 
157
char *MyPWFunc(PK11SlotInfo *slot, PRBool retry, void *arg)
 
158
{
 
159
    static PRBool called=PR_FALSE;
 
160
    if(called) {
 
161
        return NULL;
 
162
    } else {
 
163
        called = PR_TRUE;
 
164
        return PL_strdup(password);
 
165
    }
 
166
}
 
167
 
 
168
/* 
 
169
 * VersionEnables
 
170
 *  errors (40-49)
 
171
 */
 
172
 
 
173
int Version2Enable(PRFileDesc *s, int v) {
 
174
  if (SSL_Enable(s, SSL_ENABLE_SSL2, 1) <0) return Error(43);
 
175
  else return 0;
 
176
}
 
177
 
 
178
int Version3Enable(PRFileDesc *s) {
 
179
    if (SSL_Enable(s, SSL_ENABLE_SSL3, 1) <0) return Error(42);
 
180
    else return 0;
 
181
}
 
182
 
 
183
int Version23Clear(PRFileDesc *s) {
 
184
  if (SSL_Enable(s,SSL_ENABLE_SSL2,0) <0) return Error(40);
 
185
  if (SSL_Enable(s,SSL_ENABLE_SSL3,0) <0) return Error(41);
 
186
  return 0;
 
187
}
 
188
 
 
189
 
 
190
 
 
191
char *nicknames[MAX_NICKNAME];
 
192
 
 
193
void SetupNickNames() {
 
194
  nicknames[CLIENT_CERT_VERISIGN]        = "CLIENT_CERT_VERISIGN";
 
195
  nicknames[CLIENT_CERT_HARDCOREII_1024] = "CLIENT_CERT_HARDCOREII_1024";
 
196
  nicknames[CLIENT_CERT_HARDCOREII_512]  = "CLIENT_CERT_HARDCOREII_512";
 
197
  nicknames[CLIENT_CERT_SPARK]           = "CLIENT_CERT_SPARK";
 
198
  nicknames[SERVER_CERT_HARDCOREII_512]  = nickname;
 
199
  /* nicknames[SERVER_CERT_HARDCOREII_512]  = "SERVER_CERT_HARDCOREII_512"; */
 
200
  nicknames[SERVER_CERT_VERISIGN_REGULAR]= "SERVER_CERT_VERISIGN_REGULAR";
 
201
  nicknames[SERVER_CERT_VERISIGN_STEPUP] = "SERVER_CERT_VERISIGN_STEPUP";
 
202
  nicknames[SERVER_CERT_SPARK]           = "SERVER_CERT_SPARK";
 
203
}
 
204
 
 
205
 
 
206
 
 
207
 
 
208
 
 
209
 
 
210
 
 
211
/* 
 
212
 * SetServerSecParms
 
213
 * errors(10-19)
 
214
 */
 
215
 
 
216
int SetServerSecParms(struct ThreadData *td) {
 
217
  int rv;
 
218
  SECKEYPrivateKey *privKey;
 
219
  PRFileDesc *s;
 
220
 
 
221
  s = td->r;
 
222
 
 
223
  rv = SSL_Enable(s, SSL_SECURITY, 1);     /* Enable security on this socket */
 
224
  if (rv < 0)  return Error(10);
 
225
 
 
226
  if (SSLT_CLIENTAUTH_INITIAL == REP_ServerDoClientAuth) {
 
227
    rv = SSL_Enable(s, SSL_REQUEST_CERTIFICATE, 1);
 
228
    if (rv < 0)  return Error(11);
 
229
    }
 
230
 
 
231
  ClearCiphers(td);
 
232
  EnableCiphers(td);
 
233
 
 
234
  PK11_SetPasswordFunc(MyPWFunc);
 
235
  SSL_SetPKCS11PinArg(s,(void*) MyPWFunc);
 
236
 
 
237
 
 
238
  /* Find the certificates we are going to use from the database */
 
239
 
 
240
 
 
241
  /* Test for dummy certificate, which shouldn't exist */
 
242
  td->cert = PK11_FindCertFromNickname("XXXXXX_CERT_HARDCOREII_1024",NULL);
 
243
  if (td->cert != NULL) return Error(16);
 
244
 
 
245
 
 
246
  td->cert = NULL;
 
247
  if (NO_CERT != REP_ServerCert) {
 
248
    td->cert = PK11_FindCertFromNickname(nicknames[REP_ServerCert],NULL);
 
249
  }
 
250
 
 
251
 
 
252
  /* Note: if we're set to use NO_CERT as the server cert, then we'll
 
253
   * just essentially skip the rest of this (except for session ID cache setup)
 
254
   */
 
255
 
 
256
  
 
257
  if ( (NULL == td->cert)  && ( NO_CERT != REP_ServerCert )) {
 
258
    PR_fprintf(PR_STDERR, "Can't find certificate %s\n", nicknames[REP_ServerCert]);
 
259
    PR_fprintf(PR_STDERR, "Server: Seclib error: %s\n",
 
260
               SECU_ErrorString ((int16) PR_GetError()));
 
261
    return Error(12);
 
262
  }
 
263
  
 
264
 
 
265
  if ((NO_CERT != REP_ServerCert)) {
 
266
    privKey = PK11_FindKeyByAnyCert(td->cert, NULL);
 
267
    if (privKey == NULL) {
 
268
      dbmsg((PR_STDERR, "Can't find key for this certificate\n"));
 
269
      return Error(13);
 
270
    }
 
271
    
 
272
    rv = SSL_ConfigSecureServer(s,td->cert,privKey, kt_rsa);
 
273
    if (rv != PR_SUCCESS) {
 
274
      dbmsg((PR_STDERR, "Can't config server error(%d) \n",rv));
 
275
      return Error(14);
 
276
    }
 
277
  }
 
278
  
 
279
  rv = SSL_ConfigServerSessionIDCache(10, 0, 0, ".");
 
280
  if (rv != 0) {    
 
281
    dbmsg((PR_STDERR, "Can't config server session ID cache (%d) \n",rv));
 
282
    return Error(15);
 
283
  }
 
284
 
 
285
  return 0;
 
286
}
 
287
 
 
288
 
 
289
 
 
290
 
 
291
 
 
292
 
 
293