Package com.subgraph.orchid

Examples of com.subgraph.orchid.ConnectionHandshakeException


    if(config.getHandshakeV3Enabled() && ConnectionHandshakeV3.sessionSupportsHandshake(socket.getSession())) {
      return new ConnectionHandshakeV3(connection, socket);
    } else if(config.getHandshakeV2Enabled()) {
      return new ConnectionHandshakeV2(connection, socket);
    } else {
      throw new ConnectionHandshakeException("No valid handshake type available for this connection");
    }
     
  }
View Full Code Here


        if(c.getCommand() == t) {
          return c;
        }
      }
      final List<Integer> expected = Arrays.asList(expectedTypes);
      throw new ConnectionHandshakeException("Expecting Cell command "+ expected + " and got [ "+ c.getCommand() +" ] instead");
    } catch (ConnectionIOException e) {
      throw new ConnectionHandshakeException("Connection exception while performing handshake "+ e);
    }
  }
View Full Code Here

    return null;
  }
 
  protected void verifyIdentityKey(PublicKey publicKey) throws ConnectionHandshakeException {
    if(!(publicKey instanceof RSAPublicKey)) {
      throw new ConnectionHandshakeException("Identity certificate public key is not an RSA key as expected");
    }
    final TorPublicKey identityKey = new TorPublicKey((RSAPublicKey)publicKey);
    final Router router = connection.getRouter();
    if((router instanceof BridgeRouter) && (router.getIdentityHash() == null)) {
      logger.info("Setting Bridge fingerprint from connection handshake for "+ router);
      ((BridgeRouter) router).setIdentity(identityKey.getFingerprint());
    } else if(!identityKey.getFingerprint().equals(router.getIdentityHash())) {
      throw new ConnectionHandshakeException("Router identity does not match certificate key");
    }
  }
View Full Code Here

 
  void recvCerts() throws ConnectionHandshakeException  {
    final Cell cell = expectCell(Cell.CERTS);
    final int ncerts = cell.getByte();
    if(ncerts != 2) {
      throw new ConnectionHandshakeException("Expecting 2 certificates and got "+ ncerts);
    }

    linkCertificate = null;
    identityCertificate = null;
   
    for(int i = 0; i < ncerts; i++) {
      int type = cell.getByte();
      if(type == 1) {
        linkCertificate = testAndReadCertificate(cell, linkCertificate, "Link (type = 1)");
      } else if(type == 2) {
        identityCertificate = testAndReadCertificate(cell, identityCertificate, "Identity (type = 2)");
      } else {
        throw new ConnectionHandshakeException("Unexpected certificate type = "+ type + " in CERTS cell");
      }
    }
   
  }
View Full Code Here

  private X509Certificate testAndReadCertificate(Cell cell, X509Certificate currentValue, String type) throws ConnectionHandshakeException {
    if(currentValue == null) {
      return readCertificateFromCell(cell);
    } else {
      throw new ConnectionHandshakeException("Duplicate "+ type + " certificates in CERTS cell");
    }
  }
View Full Code Here

    PublicKey publicKey = identityCertificate.getPublicKey();
    verifyIdentityKey(publicKey);
    RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
   
    if(rsaPublicKey.getModulus().bitLength() != 1024) {
      throw new ConnectionHandshakeException("Invalid RSA modulus length in router identity key");
    }
   
    try {
      identityCertificate.checkValidity();
      identityCertificate.verify(rsaPublicKey);
      linkCertificate.checkValidity();
      linkCertificate.verify(rsaPublicKey);
    } catch (GeneralSecurityException e) {
      throw new ConnectionHandshakeException("Router presented invalid certificate chain in CERTS cell");
    }
 
    RSAPublicKey rsa2 = (RSAPublicKey) linkCertificate.getPublicKey();
    if(!getConnectionPublicKey().getModulus().equals(rsa2.getModulus())) {
      throw new ConnectionHandshakeException("Link certificate in CERTS cell does not match connection certificate");
    }
  }
View Full Code Here

  private X509Certificate getIdentityCertificateFromSession(SSLSession session) throws ConnectionHandshakeException {
    try {
      X509Certificate[] chain = session.getPeerCertificateChain();
      if(chain.length != 2) {
        throw new ConnectionHandshakeException("Expecting 2 certificate chain from router and received chain length "+ chain.length);
      }
      chain[0].verify(chain[1].getPublicKey());
      return chain[1];
    } catch (SSLPeerUnverifiedException e) {
      throw new ConnectionHandshakeException("No certificates received from router");
    } catch (GeneralSecurityException e) {
      throw new ConnectionHandshakeException("Incorrect signature on certificate chain");
    } catch (CertificateException e) {
      throw new ConnectionHandshakeException("Malformed certificate received");
    }
  }
View Full Code Here

        throw new ConnectionTimeoutException();
      } catch (IOException e) {
        throw new ConnectionFailedException(e.getClass().getName() + " : "+ e.getMessage());
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new ConnectionHandshakeException("Handshake interrupted");
      } catch (ConnectionHandshakeException e) {
        throw e;
      } catch (ConnectionIOException e) {
        throw new ConnectionFailedException(e.getMessage());
      }
View Full Code Here

TOP

Related Classes of com.subgraph.orchid.ConnectionHandshakeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.