use of org.eclipse.californium.elements.auth.X509CertPath in project leshan by eclipse.
the class EndpointContextSerDes method serialize.
public static JsonObject serialize(EndpointContext context) {
JsonObject peer = Json.object();
peer.set(KEY_ADDRESS, context.getPeerAddress().getHostString());
peer.set(KEY_PORT, context.getPeerAddress().getPort());
Principal principal = context.getPeerIdentity();
if (principal != null) {
if (principal instanceof PreSharedKeyIdentity) {
peer.set(KEY_ID, principal.getName());
} else if (principal instanceof RawPublicKeyIdentity) {
PublicKey publicKey = ((RawPublicKeyIdentity) principal).getKey();
peer.set(KEY_RPK, Hex.encodeHexString(publicKey.getEncoded()));
} else if (principal instanceof X500Principal || principal instanceof X509CertPath) {
peer.set(KEY_DN, principal.getName());
}
}
/**
* copy the attributes *
*/
Map<String, String> attributes = context.entries();
if (!attributes.isEmpty()) {
JsonObject attContext = Json.object();
for (String key : attributes.keySet()) {
attContext.set(key, attributes.get(key));
}
peer.set(KEY_ATTRIBUTES, attContext);
}
return peer;
}
use of org.eclipse.californium.elements.auth.X509CertPath in project leshan by eclipse.
the class EndpointContextUtil method extractIdentity.
public static Identity extractIdentity(EndpointContext context) {
InetSocketAddress peerAddress = context.getPeerAddress();
Principal senderIdentity = context.getPeerIdentity();
if (senderIdentity != null) {
if (senderIdentity instanceof PreSharedKeyIdentity) {
return Identity.psk(peerAddress, senderIdentity.getName());
} else if (senderIdentity instanceof RawPublicKeyIdentity) {
PublicKey publicKey = ((RawPublicKeyIdentity) senderIdentity).getKey();
return Identity.rpk(peerAddress, publicKey);
} else if (senderIdentity instanceof X500Principal || senderIdentity instanceof X509CertPath) {
// Extract common name
String x509CommonName = extractCN(senderIdentity.getName());
return Identity.x509(peerAddress, x509CommonName);
}
throw new IllegalStateException("Unable to extract sender identity : unexpected type of Principal");
}
return Identity.unsecure(peerAddress);
}
Aggregations