source code taken from cacert-20090625.tar.bz2
[cacert.git] / cacert / pages / account / 17.php
1 <? /*
2 LibreSSL - CAcert web application
3 Copyright (C) 2004-2008 CAcert Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */ ?>
18 <? if(array_key_exists('HTTP_USER_AGENT',$_SERVER) && strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { ?>
19 <object classid="clsid:127698e4-e730-4e5c-a2b1-21490a70c8a1" codebase="/xenroll.cab#Version=5,131,3659,0" id="cec">
20 <?=_("You must enable ActiveX for this to work.")?>
21 </object>
22 <form method="post" action="account.php" name="CertReqForm"><p>
23 <input type="hidden" name="session" value="UsedXenroll">
24 <?=_("Key Strength:")?> <select name="CspProvider"></select>
25 <input type="hidden" name="oldid" value="<?=$id?>">
26 <INPUT TYPE=HIDDEN NAME="CSR">
27 <input type="hidden" name="keytype" value="MS">
28 <?=_("'Enhanced Provider' is generally the best option, which has a key size of 1024bit. If you need a bigger key size you will need to use a different browser.")?>
29 <input type="submit" name="GenReq" value="Create Certificate"><br>
30 </p></form>
31 <script type="text/vbscript" language="vbscript">
32 <!--
33 Function GetProviderList()
34 Dim CspList, cspIndex, ProviderName
35 On Error Resume Next
36
37 count = 0
38 base = 0
39 enhanced = 0
40 CspList = ""
41 ProviderName = ""
42
43 For ProvType = 0 to 13
44 cspIndex = 0
45 cec.ProviderType = ProvType
46 ProviderName = cec.enumProviders(cspIndex,0)
47
48 while ProviderName <> ""
49 Set oOption = document.createElement("OPTION")
50 oOption.text = ProviderName
51 oOption.value = ProvType
52 Document.CertReqForm.CspProvider.add(oOption)
53 if ProviderName = "Microsoft Base Cryptographic Provider v1.0" Then
54 base = count
55 end if
56 if ProviderName = "Microsoft Enhanced Cryptographic Provider v1.0" Then
57 enhanced = count
58 end if
59 cspIndex = cspIndex +1
60 ProviderName = ""
61 ProviderName = cec.enumProviders(cspIndex,0)
62 count = count + 1
63 wend
64 Next
65 Document.CertReqForm.CspProvider.selectedIndex = base
66 if enhanced then
67 Document.CertReqForm.CspProvider.selectedIndex = enhanced
68 end if
69 End Function
70
71 Function CSR(keyflags)
72 CSR = ""
73 szName = ""
74 cec.HashAlgorithm = "MD5"
75 err.clear
76 On Error Resume Next
77 set options = document.all.CspProvider.options
78 index = options.selectedIndex
79 cec.providerName = options(index).text
80 tmpProviderType = options(index).value
81 cec.providerType = tmpProviderType
82 cec.KeySpec = 2
83 if tmpProviderType < 2 Then
84 cec.KeySpec = 1
85 end if
86 cec.GenKeyFlags = &h04000001 OR keyflags
87 CSR = cec.createPKCS10(szName, "1.3.6.1.5.5.7.3.2")
88 if len(CSR)<>0 then Exit Function
89 cec.GenKeyFlags = &h04000000 OR keyflags
90 CSR = cec.createPKCS10(szName, "1.3.6.1.5.5.7.3.2")
91 if len(CSR)<>0 then Exit Function
92 if cec.providerName = "Microsoft Enhanced Cryptographic Provider v1.0" Then
93 if MsgBox("<?=_("The 1024-bit key generation failed. Would you like to try 512 instead?")?>", vbOkCancel)=vbOk Then
94 cec.providerName = "Microsoft Base Cryptographic Provider v1.0"
95 else
96 Exit Function
97 end if
98 end if
99 cec.GenKeyFlags = 1 OR keyflags
100 CSR = cec.createPKCS10(szName, "1.3.6.1.5.5.7.3.2")
101 if len(CSR)<>0 then Exit Function
102 cec.GenKeyFlags = keyflags
103 CSR = cec.createPKCS10(szName, "1.3.6.1.5.5.7.3.2")
104 if len(CSR)<>0 then Exit Function
105 cec.GenKeyFlags = 0
106 CSR = cec.createPKCS10(szName, "1.3.6.1.5.5.7.3.2")
107 End Function
108
109 Sub GenReq_OnClick
110 Dim TheForm
111 Set TheForm = Document.CertReqForm
112 err.clear
113 result = CSR(2)
114 if len(result)=0 Then
115 result = MsgBox("Unable to generate PKCS#10.", 0, "Alert")
116 Exit Sub
117 end if
118 TheForm.CSR.Value = result
119 TheForm.Submit
120 Exit Sub
121 End Sub
122
123 GetProviderList()
124 -->
125 </script>
126 <? } else { ?>
127 <p>
128 <form method="post" action="account.php">
129 <input type="hidden" name="keytype" value="NS">
130 <?=_("Keysize:")?> <keygen name="SPKAC" challenge="<? $_SESSION['spkac_hash']=make_hash(); echo $_SESSION['spkac_hash']; ?>">
131
132
133 <input type="submit" name="submit" value="<?=_("Create Certificate Request")?>">
134 <input type="hidden" name="oldid" value="<?=$id?>">
135 </form>
136 </p>
137 <? } ?>