以下代码使用PKCS#11设备(智能卡)创建客户端身份验证的SSL上下文.这一切都适用于Java 6:
// Configure the SunPkcs11 provider
String pkcs11config;
pkcs11config = "name = Cryptoki";
pkcs11config += "\nlibrary = /SCDriver/libbit4ipki.dylib";
InputStream confStream = new ByteArrayInputStream(pkcs11config.getBytes());
SunPKCS11 sunpkcs11 = new SunPKCS11(confStream);
Security.addProvider(sunpkcs11);
// Specify keystore builder parameters for PKCS#11 keystores
Builder scBuilder = Builder.newInstance("PKCS11", sunpkcs11, new KeyStore.CallbackHandlerProtection(new PasswordRetriever()));
// Create and init KeyManagerFactory
KeyManagerFactory factory = KeyManagerFactory.getInstance("NewSunX509");
factory.init(new KeyStoreBuilderParameters(scBuilder));
// create and init ssl context
m_ssl_context = SSLContext.getInstance("TLS");
m_ssl_context.init(factory.getKeyManagers(), new TrustManager[] {new PkTrustManager()}, null);
SSLContext.setDefault(m_ssl_context);
Run Code Online (Sandbox Code Playgroud)
该PkTrustManager仅仅是和"空"类,服用任何服务器/客户端证书为好,并PasswordRetriever刚刚经历一个对话框,询问密码(要求我发布这些源代码).在Java 7上,我在ssl上下文的SSL握手期间得到以下异常:
java.security.InvalidKeyException: …Run Code Online (Sandbox Code Playgroud) 我有循环依赖的问题:当使用新的RLMLinkingObjects反向关系时,我收到以下错误:
Type argument 'RCon *' does not satisfy the bound ('RLMObject *') of type parameter 'RLMObjectType'
Run Code Online (Sandbox Code Playgroud)
我有两个课程RCon和RSan.RCon有多个RSan引用,RSan由多个RCon引用,因此它是多对多关系.以下是类的声明示例.
头等舱:
// RSan.h
#import <Realm/Realm.h>
#import <UIKit/UIKit.h>
@class RCon;
@interface RSan : RLMObject
@property (readonly) RLMLinkingObjects<RCon*>* cons;
@end
RLM_ARRAY_TYPE(RSan)
Run Code Online (Sandbox Code Playgroud)
另一类:
// RCon.h
#import <Realm/Realm.h>
#import <UIKit/UIKit.h>
#import "RSan.h"
@interface RCon : RLMObject
@property RLMArray<RSan*><RSan>* sans;
@end
RLM_ARRAY_TYPE(RCon)
Run Code Online (Sandbox Code Playgroud)