-
Notifications
You must be signed in to change notification settings - Fork 43
/
FlexiProviderController.java
142 lines (122 loc) · 5.3 KB
/
FlexiProviderController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//-----BEGIN DISCLAIMER-----
/*******************************************************************************
* Copyright (c) 2011, 2021 JCrypTool Team and Contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
//-----END DISCLAIMER-----
/**
*
*/
package de.flexiprovider;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.jcryptool.core.logging.utils.LogUtil;
import org.jcryptool.core.operations.providers.AbstractProviderController;
import de.flexiprovider.core.FlexiCoreProvider;
import de.flexiprovider.ec.FlexiECProvider;
import de.flexiprovider.nf.FlexiNFProvider;
import de.flexiprovider.pqc.FlexiPQCProvider;
/**
* Serves as the focal point for adressing the FlexiProvider library.<br>
* Attempts at putting the FlexiProvider library as the priority 1-4 providers for JCrypTool.
*
* @author tkern
*
*/
public class FlexiProviderController extends AbstractProviderController {
public static final FlexiNFProvider FLEXI_NF_PROVIDER = new FlexiNFProvider();
public static final FlexiPQCProvider FLEXI_PQC_PROVIDER = new FlexiPQCProvider();
public static final FlexiECProvider FLEXI_EC_PROVIDER = new FlexiECProvider();
public static final FlexiCoreProvider FLEXICORE_PROVIDER = new FlexiCoreProvider();
private static final Provider[] FLEXI_PROVIDERS = new Provider[] {FlexiProviderController.FLEXICORE_PROVIDER, FLEXI_EC_PROVIDER, FLEXI_PQC_PROVIDER, FLEXI_NF_PROVIDER};
static {
FLEXICORE_PROVIDER.remove("SecureRandom.BBS");
FLEXICORE_PROVIDER.remove("SecureRandom.BBSRandom");
FLEXICORE_PROVIDER.remove("Alg.Alias.SecureRandom.BBSRandom");
FLEXI_EC_PROVIDER.remove("SecureRandom.ECPRNG");
}
/**
* Empty no-args constructor.
*/
public FlexiProviderController() {
}
// these get cached before any of JCT's providers are set, so they can be repositioned (before or after) according to the current needs
private List<Provider> defaultProviders = null;
private void cacheDefaultProviders() {
if (defaultProviders == null) {
defaultProviders = new LinkedList<>();
for (Provider p : Security.getProviders()) {
defaultProviders.add(p);
}
}
}
@Override
public void setProviders__sunPromoted() {
LogUtil.logInfo(FlexiProviderPlugin.PLUGIN_ID, "promoting sun security providers in FlexiProviderController");
cacheDefaultProviders();
for(Provider p: Security.getProviders()) {
Security.removeProvider(p.getName());
}
// add the sun providers first
for (Provider provider: defaultProviders) {
// LogUtil.logInfo(FlexiProviderPlugin.PLUGIN_ID, "adding Provider: " + provider.getName());
Security.addProvider(provider);
}
// add the Flexiproviders after
for (Provider provider : FLEXI_PROVIDERS) {
// LogUtil.logInfo(FlexiProviderPlugin.PLUGIN_ID, "adding Provider: " + provider.getName());
Security.addProvider(provider);
}
// System.out.println("Sun cryptoprovider prioritized");
}
@Override
public void setProviders__flexiPromoted() {
// LogUtil.logInfo(FlexiProviderPlugin.PLUGIN_ID, "promoting flexi security providers in FlexiProviderController");
cacheDefaultProviders();
for(Provider p: Security.getProviders()) {
Security.removeProvider(p.getName());
}
// add the Flexiproviders first
for (Provider provider : FLEXI_PROVIDERS) {
// LogUtil.logInfo(FlexiProviderPlugin.PLUGIN_ID, "adding Provider: " + provider.getName());
Security.addProvider(provider);
}
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
// add the sun providers after
for (Provider provider: defaultProviders) {
// LogUtil.logInfo(FlexiProviderPlugin.PLUGIN_ID, "adding Provider: " + provider.getName());
Security.addProvider(provider);
}
// System.out.println("FlexiProvider cryptoprovider prioritized");
}
/**
* Adds the four distinctive FlexiProvider cryptographic providers as the top priority providers for the platform.
*
* @see org.jcryptool.core.operations.providers.AbstractProviderController#addProviders()
*/
@Override
public List<String> addProviders() {
List<String> providers = new ArrayList<String>(4);
providers.add(FlexiProviderController.FLEXICORE_PROVIDER.getName() + AbstractProviderController.SEPARATOR + FlexiProviderController.FLEXICORE_PROVIDER.getInfo());
providers.add(FLEXI_EC_PROVIDER.getName() + AbstractProviderController.SEPARATOR + FLEXI_EC_PROVIDER.getInfo());
providers.add(FLEXI_PQC_PROVIDER.getName() + AbstractProviderController.SEPARATOR + FLEXI_PQC_PROVIDER.getInfo());
providers.add(FLEXI_NF_PROVIDER.getName() + AbstractProviderController.SEPARATOR + FLEXI_NF_PROVIDER.getInfo());
setProviders__sunPromoted();
LogUtil.logInfo(FlexiProviderPlugin.PLUGIN_ID, "CURRENT PROVIDERS: ----");
for (Provider p: Security.getProviders()) {
LogUtil.logInfo(FlexiProviderPlugin.PLUGIN_ID, "- " + p.getName());
}
LogUtil.logInfo(FlexiProviderPlugin.PLUGIN_ID, "END: CURRENT PROVIDERS: ----");
return providers;
}
public static void reset_crypto_providers_generic() {
// TODO Auto-generated method stub
}
}