/**
* @param keyStoreType the type of the keystore (jks,pkcs12,etc)
* @param keyStorePath the file-system path of the keystore
* @param certificateSelector the selector of signing certificate
* @param keyStorePasswordProvider the provider of the keystore loading password
* @param entryPasswordProvider the provider of entry passwords
* @param returnFullChain indicates of the full certificate chain should be returned,if available
* @throws KeyStoreException
*/
public FileSystemKeyStoreKeyingDataProvider(
final String keyStoreType,final String keyStorePath,SigningCertSelector certificateSelector,KeyStorePasswordProvider keyStorePasswordProvider,KeyEntryPasswordProvider entryPasswordProvider,boolean returnFullChain) throws KeyStoreException
{
super(new KeyStoreBuilderCreator()
{
@Override
public Builder getBuilder(ProtectionParameter loadProtection)
{
return KeyStore.Builder.newInstance(
keyStoreType,null,new File(keyStorePath),loadProtection);
}
},certificateSelector,keyStorePasswordProvider,entryPasswordProvider,returnFullChain);
}
项目:cn1
文件:KeyStore3Test.java
public void test_getKeyStore() throws KeyStoreException,NoSuchAlgorithmException,CertificateException,FileNotFoundException,IOException {
String alias = "BKS";
char[] pwd = new char[] { '1','2','3','4','5','6' };
InputStream fis = KeyStore2Test.class
.getResourceAsstream("builderimpl.ks");
KeyStore ks = KeyStore.getInstance(alias);
ks.load(fis,pwd);
Builder b = Builder.newInstance(ks,new PasswordProtection(pwd));
KeyStore firstKeyStore = b.getKeyStore();
ProtectionParameter firstProtParameter = b
.getProtectionParameter(alias);
assertSame(firstKeyStore,b.getKeyStore());
assertSame(firstProtParameter,b.getProtectionParameter(alias));
b = Builder.newInstance(alias,ks.getProvider(),new KeyStore.PasswordProtection(pwd));
firstKeyStore = b.getKeyStore();
firstProtParameter = b.getProtectionParameter(alias);
assertNotSame(firstKeyStore,b.getProtectionParameter(alias));
}
项目:freeVM
文件:KeyStore3Test.java
public void test_getKeyStore() throws KeyStoreException,b.getProtectionParameter(alias));
}
项目:neoscada
文件:MonitorStateInjector.java
/**
* Inject attributes to the value after the value update has been performed
* using {@link #performDataUpdate(Builder)}
*
* @param builder
* the builder to use for changing @R_38_4045@ion
*/
public void injectAttributes ( final DataItemValue.Builder builder )
{
builder.setAttribute ( this.attributeActive,Variant.valueOf ( this.active ) );
builder.setAttribute ( this.attributeState,Variant.valueOf ( this.state ) );
builder.setAttribute ( this.attributeUnsafe,Variant.valueOf ( this.unsafe ) );
// be sure we don't have a null value
final Severity severity = this.severity == null ? Severity.ALARM : this.severity;
switch ( severity )
{
case @R_38_4045@ION:
builder.setAttribute ( this.attributeInfo,Variant.valueOf ( this.alarm ) );
builder.setAttribute ( this.attributeInfoAckrequired,Variant.valueOf ( this.akn ) );
break;
case WARNING:
builder.setAttribute ( this.attributeWarning,Variant.valueOf ( this.alarm ) );
builder.setAttribute ( this.attributeWarningAckrequired,Variant.valueOf ( this.akn ) );
break;
case ALARM:
builder.setAttribute ( this.attributealarm,Variant.valueOf ( this.alarm ) );
builder.setAttribute ( this.attributealarmAckrequired,Variant.valueOf ( this.akn ) );
break;
case ERROR:
builder.setAttribute ( this.attributeError,Variant.valueOf ( this.alarm ) );
builder.setAttribute ( this.attributeErrorAckrequired,Variant.valueOf ( this.akn ) );
break;
}
}
@Test
public void test_init_Builder() {
TestKeyStore testKeyStore = TestKeyStore.getClient();
Builder builder = Builder.newInstance(
testKeyStore.keyStore,new PasswordProtection(testKeyStore.storePassword));
KeyStoreBuilderParameters ksbp = new KeyStoreBuilderParameters(builder);
assertNotNull(ksbp);
assertNotNull(ksbp.getParameters());
assertEquals(1,ksbp.getParameters().size());
assertSame(builder,ksbp.getParameters().get(0));
}
@Test
public void test_init_List() {
TestKeyStore testKeyStore1 = TestKeyStore.getClient();
TestKeyStore testKeyStore2 = TestKeyStore.getServer();
Builder builder1 = Builder.newInstance(
testKeyStore1.keyStore,new PasswordProtection(testKeyStore1.storePassword));
Builder builder2 = Builder.newInstance(
testKeyStore2.keyStore,new PasswordProtection(testKeyStore2.storePassword));
List<Builder> list = Arrays.asList(builder1,builder2);
KeyStoreBuilderParameters ksbp = new KeyStoreBuilderParameters(list);
assertNotNull(ksbp);
assertNotNull(ksbp.getParameters());
assertNotSame(list,ksbp.getParameters());
assertEquals(2,ksbp.getParameters().size());
assertSame(builder1,ksbp.getParameters().get(0));
assertSame(builder2,ksbp.getParameters().get(1));
// confirm result is not modifiable
try {
ksbp.getParameters().set(0,builder2);
fail();
} catch (UnsupportedOperationException expected) {
// Ignored.
}
// confirm result is a copy of original
list.set(0,builder2);
assertSame(builder1,ksbp.getParameters().get(0));
}
项目:conscrypt
文件:KeyManagerFactoryTest.java
@Before
public void setUp() throws Exception {
// note the rare usage of DSA keys here in addition to RSA
String[] keyAlgorithms = StandardNames.IS_RI
? new String[] { "RSA","DSA","EC","EC_RSA" }
: new String[] { "RSA","DH_RSA","DH_DSA","EC_RSA" };
testKeyStore = new TestKeyStore.Builder()
.keyAlgorithms(keyAlgorithms)
.aliasPrefix("rsa-dsa-ec-dh")
.build();
}
项目:signer
文件:PDFSigner.java
/**
*
* Faz a leitura do token em LINUX,precisa setar a lib (.so) e a senha do token.
*/
@SuppressWarnings("restriction")
private KeyStore getKeyStoretoken() {
try {
// ATENÇÃO ALteraR CONfigURAÇÃO ABAIXO CONFORME O TOKEN USADO
// Para TOKEN Branco a linha abaixo
// String pkcs11LibraryPath =
// "/usr/lib/watchdata/ICP/lib/libwdpkcs_icp.so";
// Para TOKEN Azul a linha abaixo
String pkcs11LibraryPath = "/usr/lib/libetoken.so";
StringBuilder buf = new StringBuilder();
buf.append("library = ").append(pkcs11LibraryPath).append("\nname = Provedor\n");
Provider p = new sun.security.pkcs11.SunPKCS11(new ByteArrayInputStream(buf.toString().getBytes()));
Security.addProvider(p);
// ATENÇÃO ALteraR "SENHA" ABAIXO
Builder builder = KeyStore.Builder.newInstance("PKCS11",p,new KeyStore.PasswordProtection("senha".tochararray()));
KeyStore ks;
ks = builder.getKeyStore();
return ks;
} catch (Exception e1) {
e1.printstacktrace();
return null;
} finally {
}
}
项目:signer
文件:CAdESSignerTest.java
/**
*
* Faz a leitura do token em LINUX,new KeyStore.PasswordProtection("senha".tochararray()));
KeyStore ks;
ks = builder.getKeyStore();
return ks;
} catch (Exception e1) {
e1.printstacktrace();
return null;
} finally {
}
}
项目:signer
文件:CAdESTimeStampSignerTest.java
@SuppressWarnings("restriction")
private KeyStore getKeyStoretoken() {
try {
// ATENÇÃO ALteraR CONfigURAÇÃO ABAIXO CONFORME O TOKEN USADO
// Para TOKEN Branco a linha abaixo
// String pkcs11LibraryPath =
// "/usr/lib/watchdata/ICP/lib/libwdpkcs_icp.so";
// Para TOKEN Azul a linha abaixo
String pkcs11LibraryPath = "/usr/lib/libetoken.so";
StringBuilder buf = new StringBuilder();
buf.append("library = ").append(pkcs11LibraryPath).append("\nname = Provedor\n");
Provider p = new sun.security.pkcs11.SunPKCS11(new ByteArrayInputStream(buf.toString().getBytes()));
Security.addProvider(p);
// ATENÇÃO ALteraR "SENHA" ABAIXO
Builder builder = KeyStore.Builder.newInstance("PKCS11",new KeyStore.PasswordProtection("senha".tochararray()));
KeyStore ks;
ks = builder.getKeyStore();
return ks;
} catch (Exception e1) {
e1.printstacktrace();
return null;
}
}
项目:xades4j
文件:PKCS11KeyStoreKeyingDataProvider.java
/**
* The provider name is used as a key to search for installed providers. If a
* provider exists with the same name,it will be used even if it relies on a
* different native library.
* @param nativeLibraryPath the path for the native library of the specific PKCS#11 provider
* @param providerName this string is concatenated with the prefix SunPKCS11- to produce this provider instance's name
* @param slotId the id of the slot that this provider instance is to be associated with (can be {@code null})
* @param certificateSelector the selector of signing certificate
* @param keyStorePasswordProvider the provider of the keystore loading password (can be {@code null})
* @param entryPasswordProvider the provider of entry passwords (may be {@code null})
* @param returnFullChain indicates of the full certificate chain should be returned,if available
* @throws KeyStoreException
*/
public PKCS11KeyStoreKeyingDataProvider(
final String nativeLibraryPath,final String providerName,final Integer slotId,boolean returnFullChain) throws KeyStoreException
{
super(new KeyStoreBuilderCreator()
{
@Override
public Builder getBuilder(ProtectionParameter loadProtection)
{
Provider p = getInstalledProvider(providerName);
if (p == null)
{
StringBuilder config = new StringBuilder("name = ").append(providerName);
config.append(System.getProperty("line.separator"));
config.append("library = ").append(nativeLibraryPath);
if(slotId != null)
{
config.append(System.getProperty("line.separator"));
config.append("slot = ").append(slotId);
}
ByteArrayInputStream configStream = new ByteArrayInputStream(config.toString().getBytes());
p = createPkcs11Provider(configStream);
Security.addProvider(p);
}
return KeyStore.Builder.newInstance("PKCS11",returnFullChain);
}
项目:android-1
文件:CertificateServiceImpl.java
private Builder loadKeyStore(final CertificateConfigEntry entry)
throws KeyStoreException
{
final File f = new File(entry.getKeyStore());
final KeyStoreType kt = entry.getKeyStoreType();
if ("PKCS11".equals(kt.getName()))
{
String config =
"name=" + f.getName() + "\nlibrary=" + f.getAbsoluteFile();
try
{
Class<?> pkcs11c =
Class.forName("sun.security.pkcs11.SunPKCS11");
Constructor<?> c = pkcs11c.getConstructor(InputStream.class);
Provider p =
(Provider) c.newInstance(new ByteArrayInputStream(config
.getBytes()));
Security.insertProviderAt(p,0);
}
catch (Exception e)
{
logger.error("Tried to access the PKCS11 provider on an "
+ "unsupported platform or the load Failed",e);
}
}
KeyStore.Builder ksBuilder =
KeyStore.Builder.newInstance(kt.getName(),f,new KeyStore.CallbackHandlerProtection(new CallbackHandler()
{
public void handle(Callback[] callbacks)
throws IOException,UnsupportedCallbackException
{
for (Callback cb : callbacks)
{
if (!(cb instanceof PasswordCallback))
throw new UnsupportedCallbackException(cb);
PasswordCallback pwcb = (PasswordCallback) cb;
if (entry.isSavePassword())
{
pwcb.setPassword(entry.getKeyStorePassword()
.tochararray());
return;
}
else
{
// AuthenticationWindow aw =
// new AuthenticationWindow(
// f.getName(),// null,// kt.getName(),// false,// null
// );
// aw.setAllowSavePassword(false);
// aw.setVisible(true);
// if (!aw.isCanceled())
// pwcb.setPassword(aw.getpassword());
// else
// throw new IOException("User cancel");
}
}
}
}));
return ksBuilder;
}
项目:xades4j
文件:KeyStoreKeyingDataProvider.java
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。