2
|
1 |
/*
|
715
|
2 |
* Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.security.mscapi;
|
|
27 |
|
|
28 |
import java.security.AccessController;
|
|
29 |
import java.security.PrivilegedAction;
|
|
30 |
import java.security.Provider;
|
|
31 |
import java.security.ProviderException;
|
|
32 |
import java.util.HashMap;
|
|
33 |
import java.util.Map;
|
|
34 |
|
|
35 |
import sun.security.action.PutAllAction;
|
|
36 |
|
|
37 |
|
|
38 |
/**
|
|
39 |
* A Cryptographic Service Provider for the Microsoft Crypto API.
|
|
40 |
*
|
|
41 |
* @since 1.6
|
|
42 |
*/
|
|
43 |
|
|
44 |
public final class SunMSCAPI extends Provider {
|
|
45 |
|
|
46 |
private static final long serialVersionUID = 8622598936488630849L; //TODO
|
|
47 |
|
|
48 |
private static final String INFO = "Sun's Microsoft Crypto API provider";
|
|
49 |
|
|
50 |
static {
|
51
|
51 |
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
|
52 |
public Void run() {
|
2
|
53 |
System.loadLibrary("sunmscapi");
|
|
54 |
return null;
|
|
55 |
}
|
|
56 |
});
|
|
57 |
}
|
|
58 |
|
|
59 |
public SunMSCAPI() {
|
|
60 |
super("SunMSCAPI", 1.7d, INFO);
|
|
61 |
|
|
62 |
// if there is no security manager installed, put directly into
|
|
63 |
// the provider. Otherwise, create a temporary map and use a
|
|
64 |
// doPrivileged() call at the end to transfer the contents
|
|
65 |
final Map map = (System.getSecurityManager() == null)
|
|
66 |
? (Map)this : new HashMap();
|
|
67 |
|
|
68 |
/*
|
|
69 |
* Secure random
|
|
70 |
*/
|
|
71 |
map.put("SecureRandom.Windows-PRNG", "sun.security.mscapi.PRNG");
|
|
72 |
|
|
73 |
/*
|
|
74 |
* Key store
|
|
75 |
*/
|
|
76 |
map.put("KeyStore.Windows-MY", "sun.security.mscapi.KeyStore$MY");
|
|
77 |
map.put("KeyStore.Windows-ROOT", "sun.security.mscapi.KeyStore$ROOT");
|
|
78 |
|
|
79 |
/*
|
|
80 |
* Signature engines
|
|
81 |
*/
|
|
82 |
map.put("Signature.SHA1withRSA",
|
|
83 |
"sun.security.mscapi.RSASignature$SHA1");
|
|
84 |
map.put("Signature.MD5withRSA",
|
|
85 |
"sun.security.mscapi.RSASignature$MD5");
|
|
86 |
map.put("Signature.MD2withRSA",
|
|
87 |
"sun.security.mscapi.RSASignature$MD2");
|
|
88 |
|
|
89 |
// supported key classes
|
|
90 |
map.put("Signature.SHA1withRSA SupportedKeyClasses",
|
|
91 |
"sun.security.mscapi.Key");
|
|
92 |
map.put("Signature.MD5withRSA SupportedKeyClasses",
|
|
93 |
"sun.security.mscapi.Key");
|
|
94 |
map.put("Signature.MD2withRSA SupportedKeyClasses",
|
|
95 |
"sun.security.mscapi.Key");
|
|
96 |
map.put("Signature.NONEwithRSA SupportedKeyClasses",
|
|
97 |
"sun.security.mscapi.Key");
|
|
98 |
|
|
99 |
/*
|
|
100 |
* Key Pair Generator engines
|
|
101 |
*/
|
|
102 |
map.put("KeyPairGenerator.RSA",
|
|
103 |
"sun.security.mscapi.RSAKeyPairGenerator");
|
|
104 |
map.put("KeyPairGenerator.RSA KeySize", "1024");
|
|
105 |
|
|
106 |
/*
|
|
107 |
* Cipher engines
|
|
108 |
*/
|
|
109 |
map.put("Cipher.RSA", "sun.security.mscapi.RSACipher");
|
|
110 |
map.put("Cipher.RSA/ECB/PKCS1Padding",
|
|
111 |
"sun.security.mscapi.RSACipher");
|
|
112 |
map.put("Cipher.RSA SupportedModes", "ECB");
|
|
113 |
map.put("Cipher.RSA SupportedPaddings", "PKCS1PADDING");
|
|
114 |
map.put("Cipher.RSA SupportedKeyClasses", "sun.security.mscapi.Key");
|
|
115 |
|
|
116 |
if (map != this) {
|
|
117 |
AccessController.doPrivileged(new PutAllAction(this, map));
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
// set to true once self verification is complete
|
|
122 |
private static volatile boolean integrityVerified;
|
|
123 |
|
|
124 |
static void verifySelfIntegrity(Class c) {
|
|
125 |
if (integrityVerified) {
|
|
126 |
return;
|
|
127 |
}
|
|
128 |
doVerifySelfIntegrity(c);
|
|
129 |
}
|
|
130 |
|
|
131 |
private static synchronized void doVerifySelfIntegrity(Class c) {
|
|
132 |
integrityVerified = JarVerifier.verify(c);
|
|
133 |
if (integrityVerified == false) {
|
|
134 |
throw new ProviderException
|
|
135 |
("The SunMSCAPI provider may have been tampered with.");
|
|
136 |
}
|
|
137 |
}
|
|
138 |
}
|