当前位置: 首页>>代码示例>>Java>>正文


Java StaticPskStore类代码示例

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


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

示例1: dtlsPSKRequest

import org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore; //导入依赖的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: initCoap

import org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore; //导入依赖的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

示例3: connectionOpen

import org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore; //导入依赖的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

示例4: dont_sent_request_if_identity_change

import org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore; //导入依赖的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

示例5: initCoap

import org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore; //导入依赖的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.dtls.pskstore.StaticPskStore类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。