• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DTLSConnector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.californium.scandium.DTLSConnector的典型用法代码示例。如果您正苦于以下问题:Java DTLSConnector类的具体用法?Java DTLSConnector怎么用?Java DTLSConnector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DTLSConnector类属于org.eclipse.californium.scandium包,在下文中一共展示了DTLSConnector类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: dtlsPSKRequest

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
public static Response dtlsPSKRequest(String uri, String method, byte[] payload, int contentFormat, String pskIdentity, byte[] pskKey) throws Exception {

		Request request = Utils.newRequest(method);
		request.setURI(uri);
		request.setPayload(payload);
		request.getOptions().setContentFormat(contentFormat);

		DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(0));
		builder.setPskStore(new StaticPskStore(pskIdentity, pskKey));
		builder.setSupportedCipherSuites(new CipherSuite[] {CipherSuite.TLS_PSK_WITH_AES_128_CCM_8});

		DTLSConnector dtlsconnector = new DTLSConnector(builder.build(), null);

		NetworkConfig nc = NetworkConfig.getStandard().setInt("COAP_SECURE_PORT", 15686);

		dtlsEndpoint = new CoapEndpoint(dtlsconnector, nc);
		dtlsEndpoint.start();

		// execute request
		request.send(dtlsEndpoint);
		Response response = request.waitForResponse();
		
		return response;
	}
 
开发者ID:erwah,项目名称:acetest,代码行数:25,代码来源:DTLSUtils.java


示例2: createX509CertClient

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
public void createX509CertClient(PrivateKey privatekey, Certificate[] trustedCertificates) {
    ObjectsInitializer initializer = new ObjectsInitializer();
    // TODO security instance with certificate info
    initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec(
            "coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(),
            12345));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.add(initializer.create(2));

    InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
    DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
    // TODO we should read the config from the security object
    config.setIdentity(privatekey, clientX509CertChain, false);
    config.setTrustStore(trustedCertificates);

    CoapServer coapServer = new CoapServer();
    coapServer.addEndpoint(new CoapEndpoint(new DTLSConnector(config.build()), NetworkConfig.getStandard()));

    LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
    builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
    builder.setObjects(objects);
    client = builder.build();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:26,代码来源:SecureIntegrationTestHelper.java


示例3: CoAPSAuthorizationServer

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
public CoAPSAuthorizationServer() throws Exception {
   
      add(new TokenResource());
      add(new IntrospectResource());

   InMemoryPskStore pskStore = new InMemoryPskStore();
   pskStore.setKey(config.getPskIdentity(), config.getPskKey().getBytes());

DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(config.getCoapsPort()));
builder.setClientAuthenticationRequired(true);
builder.setPskStore(pskStore);

DTLSConnector connector = new DTLSConnector(builder.build(), null);

  	for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
  		// only binds to IPv4 addresses and localhost
	if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
		@SuppressWarnings("static-access")
		CoapEndpoint endpoint = new CoapEndpoint(connector, new NetworkConfig().getStandard()); 
		addEndpoint(endpoint);
		EndpointManager.getEndpointManager().setDefaultSecureEndpoint(endpoint);
	}
}
  }
 
开发者ID:erwah,项目名称:acetest,代码行数:25,代码来源:CoAPSAuthorizationServer.java


示例4: DtlsPSKServer

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
public DtlsPSKServer() throws Exception {
    
       add(new TemperatureResource());
    
	DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(config.getCoapsPort()));
	builder.setClientAuthenticationRequired(true);

	// use the global in memory psk key store thats populated using the access tokens from the global config object
	builder.setPskStore(config.getPskStorage());
	
	DTLSConnector connector = new DTLSConnector(builder.build(), null);

   	for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
   		// only binds to IPv4 addresses and localhost
		if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
			@SuppressWarnings("static-access")
			CoapEndpoint endpoint = new CoapEndpoint(connector, new NetworkConfig().getStandard()); 
			addEndpoint(endpoint);
			EndpointManager.getEndpointManager().setDefaultSecureEndpoint(endpoint);
		}
	}
	
}
 
开发者ID:erwah,项目名称:acetest,代码行数:24,代码来源:DtlsPSKServer.java


示例5: DtlsRPKServer

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
public DtlsRPKServer() throws Exception {
    
       add(new TemperatureResource());
    
	DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(config.getCoapsPort()));
	builder.setClientAuthenticationRequired(true);
	// use the global in memory psk key store from the global config object
	builder.setTrustedPublicKeysStore(config.getPublicKeyStorage());
	
	PublicKey publicKey = config.getRpk().getPublicKey();
	PrivateKey privateKey = config.getRpk().getPrivateKey();
	
	builder.setIdentity(privateKey, publicKey);
	
	DTLSConnector connector = new DTLSConnector(builder.build(), null);

   	for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
   		// only binds to IPv4 addresses and localhost
		if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
			@SuppressWarnings("static-access")
			CoapEndpoint endpoint = new CoapEndpoint(connector, new NetworkConfig().getStandard()); 
			addEndpoint(endpoint);
			EndpointManager.getEndpointManager().setDefaultSecureEndpoint(endpoint);
		}
	}
	
}
 
开发者ID:erwah,项目名称:acetest,代码行数:28,代码来源:DtlsRPKServer.java


示例6: createRPKClient

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
public void createRPKClient() {
    ObjectsInitializer initializer = new ObjectsInitializer();
    initializer.setInstancesForObject(LwM2mId.SECURITY,
            Security.rpk(
                    "coaps://" + server.getSecuredAddress().getHostString() + ":"
                            + server.getSecuredAddress().getPort(),
                    12345, clientPublicKey.getEncoded(), clientPrivateKey.getEncoded(),
                    serverPublicKey.getEncoded()));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.add(initializer.create(2));

    InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
    DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
    // TODO we should read the config from the security object
    // TODO no way to provide a dynamic config with the current scandium API
    config.setIdentity(clientPrivateKey, clientPublicKey);

    CoapServer coapServer = new CoapServer();
    coapServer.addEndpoint(new CoapEndpoint(new DTLSConnector(config.build()), NetworkConfig.getStandard()));

    LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
    builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
    builder.setObjects(objects);
    client = builder.build();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:28,代码来源:SecureIntegrationTestHelper.java


示例7: initCoap

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
protected void initCoap() {
	DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(); //new InetSocketAddress(0)
	builder.setPskStore(new StaticPskStore("", security_key.getBytes()));
	coap = new CoapEndpoint(new DTLSConnector(builder.build()), NetworkConfig.getStandard());
}
 
开发者ID:ffleurey,项目名称:ThingML-Tradfri,代码行数:6,代码来源:TradfriGateway.java


示例8: connectionOpen

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
/**
 * init the connection to the gateway
 * @param gatewayIP IP or DNS of the gateway
 * @param gatewaySecret Secret, is on the bottom label on the gateway
 * @param configFile path to a Properties-File that is writeable, can be null (than a new file in the current directory will be created)
 */
public void connectionOpen(String gatewayIP, String gatewaySecret, Integer udpPort) {
	this.gatewayIP = gatewayIP;
	this.gatewaySecret = gatewaySecret;
	this.udpPort = udpPort;
	
	String connectionSecret = "", connectionIdentity = "";
	Map<String, String> connectionParams = this.getIdentityInformation(this.gatewaySecret);
	
	connectionSecret = connectionParams.get("psk");
	connectionIdentity = connectionParams.get("identity");
	
	try {
		// load key store
		KeyStore keyStore = KeyStore.getInstance("JKS");
		InputStream in = getClass().getClassLoader().getResourceAsStream(KEY_STORE_LOCATION);
		keyStore.load(in, KEY_STORE_PASSWORD.toCharArray());
		in.close();

		// load trust store
		KeyStore trustStore = KeyStore.getInstance("JKS");
		in = getClass().getClassLoader().getResourceAsStream(TRUST_STORE_LOCATION);
		trustStore.load(in, TRUST_STORE_PASSWORD.toCharArray());
		in.close();

		// You can load multiple certificates if needed
		Certificate[] trustedCertificates = new Certificate[1];
		trustedCertificates[0] = trustStore.getCertificate("root");

		DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
		builder.setAddress(new InetSocketAddress(this.udpPort));
		builder.setPskStore(new StaticPskStore(connectionIdentity, connectionSecret.getBytes()));
		builder.setIdentity((PrivateKey)keyStore.getKey("client", KEY_STORE_PASSWORD.toCharArray()),
				keyStore.getCertificateChain("client"), true);
		builder.setTrustStore(trustedCertificates);
		
		//try to fix timeouts at user
		builder.setRetransmissionTimeout(50000);
		
		dtlsConnector = new DTLSConnector(builder.build());
		
	} catch (Exception e) {
		System.err.println("[GWConnection] Error while initializing key store: ");
		e.printStackTrace();
		System.exit(-1);
	}
	
	//custom network config without a config file
	NetworkConfig networkConfig = NetworkConfig.createStandardWithoutFile();
	networkConfig.set(Keys.ACK_TIMEOUT, 40000);
	networkConfig.setInt(Keys.MAX_RESOURCE_BODY_SIZE, 8192);
	NetworkConfig.setStandard(networkConfig);
	
	client = new CoapClient();
	
	client.setEndpoint(new CoapEndpoint(dtlsConnector, networkConfig));
	client.setTimeout(60000);
	
	//client.setEndpoint(new CoapEndpoint(dtlsConnector, NetworkConfig.getStandard()));
	
	//after opening connection: fetch well known
	System.out.println("[GWConnection] Fetching well-known...");
	System.out.println("[GWConnection] " + this.get("/.well-known/core").getResponseText());
}
 
开发者ID:peterkappelt,项目名称:JTradfri,代码行数:70,代码来源:GWConnection.java


示例9: dtlsRPKRequest

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
public static Response dtlsRPKRequest(String uri, String method, byte[] payload, int contentFormat, JsonWebKey popKey, ArrayList<PublicKey> trustedPublicKeys) throws Exception {

		Request request = Utils.newRequest(method);
		request.setURI(uri);
		request.setPayload(payload);
		request.getOptions().setContentFormat(contentFormat);

		DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(0));

		PublicKey publicKey = null;
		PrivateKey privateKey = null;
		
		if(popKey.getKeyType().equalsIgnoreCase("ec")) {
			EllipticCurveJsonWebKey ecPopKey = (EllipticCurveJsonWebKey) popKey;
			privateKey = ecPopKey.getPrivateKey();
			publicKey = ecPopKey.getPublicKey();			
		}
		else if(popKey.getKeyType().equalsIgnoreCase("rsa")) {
			RsaJsonWebKey rsaPopKey = (RsaJsonWebKey) popKey;
			privateKey = rsaPopKey.getPrivateKey();
			publicKey = rsaPopKey.getPublicKey();			
		}
		
		// use the POP key as the requests identity
		builder.setIdentity(privateKey, publicKey);

		// authenticate the remote part using PSK
		builder.setTrustedPublicKeysStore(trustedPublicKeys);

		DTLSConnector dtlsconnector = new DTLSConnector(builder.build(), null);

		NetworkConfig nc = NetworkConfig.getStandard().setInt("COAP_SECURE_PORT", 15685);

		dtlsEndpoint = new CoapEndpoint(dtlsconnector, nc);
		dtlsEndpoint.start();

		// execute request
		request.send(dtlsEndpoint);
		Response response = request.waitForResponse();
		
		return response;
	}
 
开发者ID:erwah,项目名称:acetest,代码行数:43,代码来源:DTLSUtils.java


示例10: dont_sent_request_if_identity_change

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
@Test
public void dont_sent_request_if_identity_change()
        throws NonUniqueSecurityInfoException, InterruptedException, IOException {
    // Create PSK server & start it
    helper.createServer(); // default server support PSK
    helper.server.start();

    // Create PSK Client
    helper.createPSKClient();

    // Add client credentials to the server
    helper.getSecurityStore()
            .add(SecurityInfo.newPreSharedKeyInfo(helper.getCurrentEndpoint(), GOOD_PSK_ID, GOOD_PSK_KEY));

    // Check client is not registered
    helper.assertClientNotRegisterered();

    // Start it and wait for registration
    helper.client.start();
    helper.waitForRegistration(1);

    // Check client is well registered
    helper.assertClientRegisterered();

    // Ensure we can send a read request
    helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0, 1));

    // Get the previous address and stop client silently (no deregistration)
    InetSocketAddress securedAddress = helper.client.getSecuredAddress();
    helper.client.destroy(false);
    helper.client = null;

    // add new credential to the server
    helper.getSecurityStore().add(SecurityInfo.newPreSharedKeyInfo(GOOD_ENDPOINT, "anotherPSK", GOOD_PSK_KEY));

    // Create a new connector for the same address/port and start a new DTLS handshake
    Builder builder = new DtlsConnectorConfig.Builder();
    builder.setAddress(securedAddress);
    builder.setPskStore(new StaticPskStore("anotherPSK", GOOD_PSK_KEY));
    DTLSConnector dtlsConnector = new DTLSConnector(builder.build());
    dtlsConnector.start();
    SimpleMessageCallback callback = new SimpleMessageCallback();
    dtlsConnector.send(RawData.outbound(new byte[0], new AddressEndpointContext(helper.server.getSecuredAddress()),
            callback, false));

    // Wait until new handshake DTLS is done
    EndpointContext endpointContext = callback.getEndpointContext(1000);
    assertEquals(endpointContext.getPeerIdentity().getName(), "anotherPSK");

    // Try to send a read request this should failed with an SendFailedException.
    try {
        helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0, 1));
    } catch (SendFailedException e) {
        assertTrue("must be caused by an EndpointMismatchException",
                e.getCause() instanceof EndpointMismatchException);
    } finally {
        dtlsConnector.destroy();
    }
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:60,代码来源:SecurityTest.java


示例11: initCoap

import org.eclipse.californium.scandium.DTLSConnector; //导入依赖的package包/类
protected void initCoap() {
	final DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(); // new InetSocketAddress(0)
	builder.setPskStore(new StaticPskStore("", security_key.getBytes()));
	coap = new CoapEndpoint(new DTLSConnector(builder.build()), NetworkConfig.getStandard());
}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:6,代码来源:TradfriGateway.java



注:本文中的org.eclipse.californium.scandium.DTLSConnector类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Preconditions类代码示例发布时间:2022-05-23
下一篇:
Java ListenerRegistration类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap