Imported Upstream version 3.13.6
[platform/upstream/nss.git] / mozilla / security / nss / lib / util / secplcy.h
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is the Netscape security libraries.
15  *
16  * The Initial Developer of the Original Code is
17  * Netscape Communications Corporation.
18  * Portions created by the Initial Developer are Copyright (C) 1994-2000
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */
36
37 #ifndef __secplcy_h__
38 #define __secplcy_h__
39
40 #include "utilrename.h"
41
42 #include "prtypes.h"
43
44 /*
45 ** Cipher policy enforcement. This code isn't very pretty, but it accomplishes
46 ** the purpose of obscuring policy information from potential fortifiers. :-)
47 **
48 ** The following routines are generic and intended for anywhere where cipher
49 ** policy enforcement is to be done, e.g. SSL and PKCS7&12.
50 */
51
52 #define SEC_CIPHER_NOT_ALLOWED 0
53 #define SEC_CIPHER_ALLOWED 1
54 #define SEC_CIPHER_RESTRICTED 2 /* cipher is allowed in limited cases 
55                                    e.g. step-up */
56
57 /* The length of the header string for each cipher table. 
58    (It's the same regardless of whether we're using md5 strings or not.) */
59 #define SEC_POLICY_HEADER_LENGTH 48
60
61 /* If we're testing policy stuff, we may want to use the plaintext version */
62 #define SEC_POLICY_USE_MD5_STRINGS 1
63
64 #define SEC_POLICY_THIS_IS_THE \
65     "\x2a\x3a\x51\xbf\x2f\x71\xb7\x73\xaa\xca\x6b\x57\x70\xcd\xc8\x9f"
66 #define SEC_POLICY_STRING_FOR_THE \
67     "\x97\x15\xe2\x70\xd2\x8a\xde\xa9\xe7\xa7\x6a\xe2\x83\xe5\xb1\xf6"
68 #define SEC_POLICY_SSL_TAIL \
69     "\x70\x16\x25\xc0\x2a\xb2\x4a\xca\xb6\x67\xb1\x89\x20\xdf\x87\xca"
70 #define SEC_POLICY_SMIME_TAIL \
71     "\xdf\xd4\xe7\x2a\xeb\xc4\x1b\xb5\xd8\xe5\xe0\x2a\x16\x9f\xc4\xb9"
72 #define SEC_POLICY_PKCS12_TAIL \
73     "\x1c\xf8\xa4\x85\x4a\xc6\x8a\xfe\xe6\xca\x03\x72\x50\x1c\xe2\xc8"
74
75 #if defined(SEC_POLICY_USE_MD5_STRINGS)
76
77 /* We're not testing. 
78    Use md5 checksums of the strings. */
79
80 #define SEC_POLICY_SSL_HEADER \
81     SEC_POLICY_THIS_IS_THE SEC_POLICY_STRING_FOR_THE SEC_POLICY_SSL_TAIL
82
83 #define SEC_POLICY_SMIME_HEADER \
84     SEC_POLICY_THIS_IS_THE SEC_POLICY_STRING_FOR_THE SEC_POLICY_SMIME_TAIL
85
86 #define SEC_POLICY_PKCS12_HEADER \
87     SEC_POLICY_THIS_IS_THE SEC_POLICY_STRING_FOR_THE SEC_POLICY_PKCS12_TAIL
88
89 #else
90
91 /* We're testing. 
92    Use plaintext versions of the strings, for testing purposes. */
93 #define SEC_POLICY_SSL_HEADER \
94     "This is the string for the SSL policy table.    "
95 #define SEC_POLICY_SMIME_HEADER \
96     "This is the string for the PKCS7 policy table.  "
97 #define SEC_POLICY_PKCS12_HEADER \
98     "This is the string for the PKCS12 policy table. "
99
100 #endif
101
102 /* Local cipher tables have to have these members at the top. */
103 typedef struct _sec_cp_struct
104 {
105   char policy_string[SEC_POLICY_HEADER_LENGTH];
106   long unused; /* placeholder for max keybits in pkcs12 struct */
107   char num_ciphers;
108   char begin_ciphers;
109   /* cipher policy settings follow. each is a char. */
110 } secCPStruct;
111
112 struct SECCipherFindStr
113 {
114   /* (policy) and (ciphers) are opaque to the outside world */
115   void *policy;
116   void *ciphers;
117   long index;
118   PRBool onlyAllowed;
119 };
120
121 typedef struct SECCipherFindStr SECCipherFind;
122
123 SEC_BEGIN_PROTOS
124
125 SECCipherFind *sec_CipherFindInit(PRBool onlyAllowed,
126                                   secCPStruct *policy,
127                                   long *ciphers);
128
129 long sec_CipherFindNext(SECCipherFind *find);
130
131 char sec_IsCipherAllowed(long cipher, secCPStruct *policies,
132                          long *ciphers);
133
134 void sec_CipherFindEnd(SECCipherFind *find);
135
136 SEC_END_PROTOS
137
138 #endif /* __SECPLCY_H__ */