forked from eclipse-leshan/leshan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
missing files for PR eclipse-leshan#7
- Loading branch information
1 parent
6b3d04e
commit 106a4e1
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/java/org/eclipse/californium/scandium/dtls/pskstore/InMemoryPskStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2014 Institute for Pervasive Computing, ETH Zurich and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Julien Vermillard - Sierra Wireless | ||
******************************************************************************/ | ||
package org.eclipse.californium.scandium.dtls.pskstore; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* An in-memory pre-shared-key storage. To be used only for testing and evaluation. | ||
* You are supposed to store your key in a secure way: | ||
* keeping them in-memory is not a good idea. | ||
*/ | ||
public class InMemoryPskStore implements PskStore { | ||
|
||
private Map<String, byte[]> keys = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public byte[] getKey(String identity) { | ||
byte[] key = keys.get(identity); | ||
if (key == null) { | ||
return null; | ||
} else { | ||
// defensive copy | ||
return Arrays.copyOf(key, key.length); | ||
} | ||
} | ||
|
||
/** | ||
* Set a key value for a given identity. | ||
* | ||
* @param identity the identity associated with the key | ||
* @param key the key used to authenticate the identity | ||
*/ | ||
public void setKey(String identity, byte[] key) { | ||
keys.put(identity, key); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/org/eclipse/californium/scandium/dtls/pskstore/PskStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2014 Institute for Pervasive Computing, ETH Zurich and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Julien Vermillard - Sierra Wireless | ||
******************************************************************************/ | ||
package org.eclipse.californium.scandium.dtls.pskstore; | ||
|
||
/** | ||
* A storage for pre-shared-key identity. | ||
*/ | ||
public interface PskStore { | ||
|
||
/** | ||
* Get the key for a given identity. | ||
* @param identity the identity to authenticate | ||
* @return the key or <code>null</code> if not found | ||
*/ | ||
byte[] getKey(String identity); | ||
|
||
} |