Ejemplo n.º 1
0
  public CertificateRequest getCertificateRequest() throws IOException {
    Vector serverSigAlgs = null;

    if (TlsUtils.isSignatureAlgorithmsExtensionAllowed(serverVersion)) {
      short[] hashAlgorithms =
          new short[] {
            HashAlgorithm.sha512,
            HashAlgorithm.sha384,
            HashAlgorithm.sha256,
            HashAlgorithm.sha224,
            HashAlgorithm.sha1
          };
      short[] signatureAlgorithms = new short[] {SignatureAlgorithm.rsa};

      serverSigAlgs = new Vector();
      for (int i = 0; i < hashAlgorithms.length; ++i) {
        for (int j = 0; j < signatureAlgorithms.length; ++j) {
          serverSigAlgs.addElement(
              new SignatureAndHashAlgorithm(hashAlgorithms[i], signatureAlgorithms[j]));
        }
      }
    }

    return new CertificateRequest(
        new short[] {ClientCertificateType.rsa_sign}, serverSigAlgs, null);
  }
Ejemplo n.º 2
0
  /**
   * Determines whether a specific array of <tt>byte</tt>s appears to contain a DTLS record.
   *
   * @param buf the array of <tt>byte</tt>s to be analyzed
   * @param off the offset within <tt>buf</tt> at which the analysis is to start
   * @param len the number of bytes within <tt>buf</tt> starting at <tt>off</tt> to be analyzed
   * @return <tt>true</tt> if the specified <tt>buf</tt> appears to contain a DTLS record
   */
  public static boolean isDtlsRecord(byte[] buf, int off, int len) {
    boolean b = false;

    if (len >= DTLS_RECORD_HEADER_LENGTH) {
      short type = TlsUtils.readUint8(buf, off);

      switch (type) {
        case ContentType.alert:
        case ContentType.application_data:
        case ContentType.change_cipher_spec:
        case ContentType.handshake:
          int major = buf[off + 1] & 0xff;
          int minor = buf[off + 2] & 0xff;
          ProtocolVersion version = null;

          if ((major == ProtocolVersion.DTLSv10.getMajorVersion())
              && (minor == ProtocolVersion.DTLSv10.getMinorVersion())) {
            version = ProtocolVersion.DTLSv10;
          }
          if ((version == null)
              && (major == ProtocolVersion.DTLSv12.getMajorVersion())
              && (minor == ProtocolVersion.DTLSv12.getMinorVersion())) {
            version = ProtocolVersion.DTLSv12;
          }
          if (version != null) {
            int length = TlsUtils.readUint16(buf, off + 11);

            if (DTLS_RECORD_HEADER_LENGTH + length <= len) b = true;
          }
          break;
        default:
          // Unless a new ContentType has been defined by the Bouncy
          // Castle Crypto APIs, the specified buf does not represent a
          // DTLS record.
          break;
      }
    }
    return b;
  }