Rice Pastry API

org.mpisws.p2p.transport.signature
Class CertificateTransprotLayerImpl<Identifier>

java.lang.Object
  extended by org.mpisws.p2p.transport.signature.CertificateTransprotLayerImpl<Identifier>
All Implemented Interfaces:
CertificateManager<Identifier>, CertificateTransportLayer<Identifier,java.nio.ByteBuffer>, TransportLayer<Identifier,java.nio.ByteBuffer>, TransportLayerCallback<Identifier,java.nio.ByteBuffer>, Destructable

public class CertificateTransprotLayerImpl<Identifier>
extends java.lang.Object
implements CertificateTransportLayer<Identifier,java.nio.ByteBuffer>, TransportLayerCallback<Identifier,java.nio.ByteBuffer>, CertificateManager<Identifier>

TODO: make it store known certs to a file, make it periodically check the revocation server.

Author:
Jeff Hoye

Field Summary
static byte CERT_REQUEST
           
static byte CERT_RESPONSE
           
static byte CERT_RESPONSE_FAILED
           
static java.lang.String DEFAULT_SIGNATURE_ALGORITHM
           
static byte PASSTHROUGH
           
 
Constructor Summary
CertificateTransprotLayerImpl(IdentifierSerializer<Identifier> iSerializer, X509Serializer cSerializer, java.security.cert.X509Certificate localCert, java.security.PrivateKey localPrivate, TransportLayer<Identifier,java.nio.ByteBuffer> tl, Environment env)
           
 
Method Summary
 void acceptMessages(boolean b)
          Toggle accepting incoming messages.
 void acceptSockets(boolean b)
          Toggle accepting new sockets.
 void destroy()
           
 Identifier getLocalIdentifier()
          The local node.
 java.security.Signature getVerifier(Identifier i)
          Returns null if we don't know the cert for the identifier.
 void handleCertRequest(P2PSocket<Identifier> sock)
           
 boolean hasCertificate(Identifier i)
           
 void incomingSocket(P2PSocket<Identifier> sock)
          Notification of a new socket.
 void messageReceived(Identifier i, java.nio.ByteBuffer m, java.util.Map<java.lang.String,java.lang.Object> options)
          Called when a new message is received.
 SocketRequestHandle<Identifier> openSocket(Identifier i, SocketCallback<Identifier> deliverSocketToMe, java.util.Map<java.lang.String,java.lang.Object> options)
          Open a socket to the Identifier
 Cancellable requestCertificate(Identifier source, Identifier principal, Continuation<java.security.cert.X509Certificate,java.lang.Exception> c, java.util.Map<java.lang.String,java.lang.Object> options)
          CERT_REQUEST, int requestId, Identifier
 MessageRequestHandle<Identifier,java.nio.ByteBuffer> sendMessage(Identifier i, java.nio.ByteBuffer m, MessageCallback<Identifier,java.nio.ByteBuffer> deliverAckToMe, java.util.Map<java.lang.String,java.lang.Object> options)
          Send the message to the identifier
 void setCallback(TransportLayerCallback<Identifier,java.nio.ByteBuffer> callback)
          Set the callback for incoming sockets/messages
 void setErrorHandler(ErrorHandler<Identifier> handler)
          To be notified of problems not related to an outgoing messaage/socket.
 byte[] sign(byte[] bytes)
           
 void verify(Identifier id, byte[] msg, int moff, int mlen, byte[] signature, int soff, int slen)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PASSTHROUGH

public static final byte PASSTHROUGH
See Also:
Constant Field Values

CERT_REQUEST

public static final byte CERT_REQUEST
See Also:
Constant Field Values

CERT_RESPONSE

public static final byte CERT_RESPONSE
See Also:
Constant Field Values

CERT_RESPONSE_FAILED

public static final byte CERT_RESPONSE_FAILED
See Also:
Constant Field Values

DEFAULT_SIGNATURE_ALGORITHM

public static final java.lang.String DEFAULT_SIGNATURE_ALGORITHM
See Also:
Constant Field Values
Constructor Detail

CertificateTransprotLayerImpl

public CertificateTransprotLayerImpl(IdentifierSerializer<Identifier> iSerializer,
                                     X509Serializer cSerializer,
                                     java.security.cert.X509Certificate localCert,
                                     java.security.PrivateKey localPrivate,
                                     TransportLayer<Identifier,java.nio.ByteBuffer> tl,
                                     Environment env)
                              throws java.security.InvalidKeyException,
                                     java.security.NoSuchAlgorithmException,
                                     java.security.NoSuchProviderException
Throws:
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException
Method Detail

requestCertificate

public Cancellable requestCertificate(Identifier source,
                                      Identifier principal,
                                      Continuation<java.security.cert.X509Certificate,java.lang.Exception> c,
                                      java.util.Map<java.lang.String,java.lang.Object> options)
CERT_REQUEST, int requestId, Identifier

Specified by:
requestCertificate in interface CertificateManager<Identifier>
Specified by:
requestCertificate in interface CertificateTransportLayer<Identifier,java.nio.ByteBuffer>
Returns:
UnknownCertificateException if the source doesn't know the certificate for the principal

openSocket

public SocketRequestHandle<Identifier> openSocket(Identifier i,
                                                  SocketCallback<Identifier> deliverSocketToMe,
                                                  java.util.Map<java.lang.String,java.lang.Object> options)
Description copied from interface: TransportLayer
Open a socket to the Identifier

Specified by:
openSocket in interface TransportLayer<Identifier,java.nio.ByteBuffer>
Parameters:
i - who to open the socket to
deliverSocketToMe - the callback when the socket is opened
options - options on how to open the socket (don't source route, encrypt etc) (may not be respected if layer cannot provide service)
Returns:
an object to cancel opening the socket if it takes to long, or is no longer relevant

incomingSocket

public void incomingSocket(P2PSocket<Identifier> sock)
                    throws java.io.IOException
Description copied from interface: TransportLayerCallback
Notification of a new socket.

Specified by:
incomingSocket in interface TransportLayerCallback<Identifier,java.nio.ByteBuffer>
Parameters:
sock - the incoming socket
Throws:
java.io.IOException

handleCertRequest

public void handleCertRequest(P2PSocket<Identifier> sock)

hasCertificate

public boolean hasCertificate(Identifier i)
Specified by:
hasCertificate in interface CertificateManager<Identifier>

acceptMessages

public void acceptMessages(boolean b)
Description copied from interface: TransportLayer
Toggle accepting incoming messages. Useful in flow control if overwhelmed by incoming sockets. Default: true

Specified by:
acceptMessages in interface TransportLayer<Identifier,java.nio.ByteBuffer>

acceptSockets

public void acceptSockets(boolean b)
Description copied from interface: TransportLayer
Toggle accepting new sockets. Useful in flow control if overwhelmed by incoming sockets. Default: true

Specified by:
acceptSockets in interface TransportLayer<Identifier,java.nio.ByteBuffer>

getLocalIdentifier

public Identifier getLocalIdentifier()
Description copied from interface: TransportLayer
The local node.

Specified by:
getLocalIdentifier in interface TransportLayer<Identifier,java.nio.ByteBuffer>
Returns:
The local node.

sendMessage

public MessageRequestHandle<Identifier,java.nio.ByteBuffer> sendMessage(Identifier i,
                                                                        java.nio.ByteBuffer m,
                                                                        MessageCallback<Identifier,java.nio.ByteBuffer> deliverAckToMe,
                                                                        java.util.Map<java.lang.String,java.lang.Object> options)
Description copied from interface: TransportLayer
Send the message to the identifier

Specified by:
sendMessage in interface TransportLayer<Identifier,java.nio.ByteBuffer>
Parameters:
i - the destination
m - the message
deliverAckToMe - layer dependent notification when the message is sent (can indicate placed on the wire, point-to-point acknowledgment, or end-to-end acknowledgement)
options - delivery options (don't source route, encrypt etc) (may not be respected if layer cannot provide service)
Returns:
ability to cancel the message if no longer relevant

setCallback

public void setCallback(TransportLayerCallback<Identifier,java.nio.ByteBuffer> callback)
Description copied from interface: TransportLayer
Set the callback for incoming sockets/messages

Specified by:
setCallback in interface TransportLayer<Identifier,java.nio.ByteBuffer>
Parameters:
callback - the callback for incoming sockets/messages

setErrorHandler

public void setErrorHandler(ErrorHandler<Identifier> handler)
Description copied from interface: TransportLayer
To be notified of problems not related to an outgoing messaage/socket. Or to be notified if a callback isn't provided.

Specified by:
setErrorHandler in interface TransportLayer<Identifier,java.nio.ByteBuffer>
Parameters:
handler - to be notified of problems not related to a specific messaage/socket.

destroy

public void destroy()
Specified by:
destroy in interface Destructable

messageReceived

public void messageReceived(Identifier i,
                            java.nio.ByteBuffer m,
                            java.util.Map<java.lang.String,java.lang.Object> options)
                     throws java.io.IOException
Description copied from interface: TransportLayerCallback
Called when a new message is received.

Specified by:
messageReceived in interface TransportLayerCallback<Identifier,java.nio.ByteBuffer>
Parameters:
i - The node it is coming from
m - the message
options - describe how the message arrived (udp/tcp, encrypted etc)
Throws:
java.io.IOException - if there is a problem decoding the message

sign

public byte[] sign(byte[] bytes)
            throws java.security.SignatureException
Specified by:
sign in interface CertificateManager<Identifier>
Throws:
java.security.SignatureException

verify

public void verify(Identifier id,
                   byte[] msg,
                   int moff,
                   int mlen,
                   byte[] signature,
                   int soff,
                   int slen)
            throws java.security.InvalidKeyException,
                   java.security.NoSuchAlgorithmException,
                   java.security.NoSuchProviderException,
                   java.security.SignatureException,
                   UnknownCertificateException
Specified by:
verify in interface CertificateManager<Identifier>
Throws:
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException
java.security.SignatureException
UnknownCertificateException

getVerifier

public java.security.Signature getVerifier(Identifier i)
                                    throws java.security.NoSuchAlgorithmException,
                                           java.security.NoSuchProviderException,
                                           java.security.InvalidKeyException
Returns null if we don't know the cert for the identifier.

Parameters:
i -
Returns:
Throws:
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException
java.security.InvalidKeyException

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.