Example usage for org.bouncycastle.util Arrays contains

List of usage examples for org.bouncycastle.util Arrays contains

Introduction

In this page you can find the example usage for org.bouncycastle.util Arrays contains.

Prototype

public static boolean contains(short[] a, short val) 

Source Link

Usage

From source file:org.opendaylight.capwap.dtls.DtlsClient.java

License:Open Source License

public TlsAuthentication getAuthentication() throws IOException {
    return new TlsAuthentication() {
        public void notifyServerCertificate(org.bouncycastle.crypto.tls.Certificate serverCertificate)
                throws IOException {
            Certificate[] chain = serverCertificate.getCertificateList();
            log.trace("Received server certificate chain of length " + chain.length);
            for (int i = 0; i != chain.length; i++) {
                Certificate entry = chain[i];
                // TODO Create fingerprint based on certificate signature algorithm digest
                //log.trace("    fingerprint:SHA-256 " + org.opendaylight.capwap.dtls.DtlsUtils.fingerprint(entry) + " (" + entry.getSubject()
                log.trace("    fingerprint:SHA-256 " + DtlsUtils.fingerprint(entry) + " (" + entry.getSubject()
                        + ")");
            }//from w  w  w  . ja v  a 2  s  .c  om
        }

        public TlsCredentials getClientCredentials(CertificateRequest certificateRequest) throws IOException {
            short[] certificateTypes = certificateRequest.getCertificateTypes();
            if (certificateTypes == null
                    || !Arrays.contains(certificateTypes, ClientCertificateType.rsa_sign)) {
                return null;
            }

            SignatureAndHashAlgorithm signatureAndHashAlgorithm = null;
            Vector<?> sigAlgs = certificateRequest.getSupportedSignatureAlgorithms();
            if (sigAlgs != null) {
                for (int i = 0; i < sigAlgs.size(); ++i) {
                    SignatureAndHashAlgorithm sigAlg = (SignatureAndHashAlgorithm) sigAlgs.elementAt(i);
                    if (sigAlg.getSignature() == SignatureAlgorithm.rsa) {
                        signatureAndHashAlgorithm = sigAlg;
                        break;
                    }
                }

                if (signatureAndHashAlgorithm == null) {
                    return null;
                }
            }

            return DtlsUtils.loadSignerCredentials(context,
                    new String[] { cert.getAbsolutePath(), root.getAbsolutePath() }, key.getAbsolutePath(),
                    signatureAndHashAlgorithm);
        }
    };
}

From source file:org.opendaylight.usc.crypto.dtls.DtlsClient.java

License:Open Source License

public TlsAuthentication getAuthentication() throws IOException {
    return new TlsAuthentication() {
        public void notifyServerCertificate(org.bouncycastle.crypto.tls.Certificate serverCertificate)
                throws IOException {
            Certificate[] chain = serverCertificate.getCertificateList();
            log.trace("Received server certificate chain of length " + chain.length);
            for (int i = 0; i != chain.length; i++) {
                Certificate entry = chain[i];
                // TODO Create fingerprint based on certificate signature algorithm digest
                log.trace("    fingerprint:SHA-256 " + DtlsUtils.fingerprint(entry) + " (" + entry.getSubject()
                        + ")");
            }/*from  www  .  java  2 s. c  o  m*/
        }

        public TlsCredentials getClientCredentials(CertificateRequest certificateRequest) throws IOException {
            short[] certificateTypes = certificateRequest.getCertificateTypes();
            if (certificateTypes == null
                    || !Arrays.contains(certificateTypes, ClientCertificateType.rsa_sign)) {
                return null;
            }

            SignatureAndHashAlgorithm signatureAndHashAlgorithm = null;
            Vector<?> sigAlgs = certificateRequest.getSupportedSignatureAlgorithms();
            if (sigAlgs != null) {
                for (int i = 0; i < sigAlgs.size(); ++i) {
                    SignatureAndHashAlgorithm sigAlg = (SignatureAndHashAlgorithm) sigAlgs.elementAt(i);
                    if (sigAlg.getSignature() == SignatureAlgorithm.rsa) {
                        signatureAndHashAlgorithm = sigAlg;
                        break;
                    }
                }

                if (signatureAndHashAlgorithm == null) {
                    return null;
                }
            }

            return DtlsUtils.loadSignerCredentials(context,
                    new String[] { cert.getAbsolutePath(), root.getAbsolutePath() }, key.getAbsolutePath(),
                    signatureAndHashAlgorithm);
        }
    };
}

From source file:org.restcomm.media.rtp.crypto.DtlsSrtpServer.java

License:Open Source License

@Override
public int getSelectedCipherSuite() throws IOException {
    /*/*from www .j  ava2  s .  co m*/
     * TODO RFC 5246 7.4.3. In order to negotiate correctly, the server MUST check any candidate cipher suites against the
     * "signature_algorithms" extension before selecting them. This is somewhat inelegant but is a compromise designed to
     * minimize changes to the original cipher suite design.
     */

    /*
     * RFC 4429 5.1. A server that receives a ClientHello containing one or both of these extensions MUST use the client's
     * enumerated capabilities to guide its selection of an appropriate cipher suite. One of the proposed ECC cipher suites
     * must be negotiated only if the server can successfully complete the handshake while using the curves and point
     * formats supported by the client [...].
     */
    boolean eccCipherSuitesEnabled = supportsClientECCCapabilities(this.namedCurves, this.clientECPointFormats);

    int[] cipherSuites = getCipherSuites();
    for (int i = 0; i < cipherSuites.length; ++i) {
        int cipherSuite = cipherSuites[i];

        if (Arrays.contains(this.offeredCipherSuites, cipherSuite)
                && (eccCipherSuitesEnabled || !TlsECCUtils.isECCCipherSuite(cipherSuite))
                && org.bouncycastle.crypto.tls.TlsUtils.isValidCipherSuiteForVersion(cipherSuite,
                        serverVersion)) {
            return this.selectedCipherSuite = cipherSuite;
        }
    }
    throw new TlsFatalAlert(AlertDescription.handshake_failure);
}

From source file:org.restcomm.sbc.media.dtls.DtlsSrtpServer.java

License:Open Source License

@Override
public int getSelectedCipherSuite() throws IOException {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("> getSelectedCipherSuite()");
    }/*from w  ww  .  j a  v  a 2  s . c o  m*/
    /*
     * TODO RFC 5246 7.4.3. In order to negotiate correctly, the server MUST check any candidate cipher suites against the
     * "signature_algorithms" extension before selecting them. This is somewhat inelegant but is a compromise designed to
     * minimize changes to the original cipher suite design.
     */

    /*
     * RFC 4429 5.1. A server that receives a ClientHello containing one or both of these extensions MUST use the client's
     * enumerated capabilities to guide its selection of an appropriate cipher suite. One of the proposed ECC cipher suites
     * must be negotiated only if the server can successfully complete the handshake while using the curves and point
     * formats supported by the client [...].
     */
    boolean eccCipherSuitesEnabled = supportsClientECCCapabilities(this.namedCurves, this.clientECPointFormats);

    int[] cipherSuites = getCipherSuites();
    for (int i = 0; i < cipherSuites.length; ++i) {
        int cipherSuite = cipherSuites[i];

        if (Arrays.contains(this.offeredCipherSuites, cipherSuite)
                && (eccCipherSuitesEnabled || !TlsECCUtils.isECCCipherSuite(cipherSuite))
                && org.bouncycastle.crypto.tls.TlsUtils.isValidCipherSuiteForVersion(cipherSuite,
                        serverVersion)) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("> SelectedCipherSuite=" + cipherSuite);
            }
            return this.selectedCipherSuite = cipherSuite;
        }
    }
    throw new TlsFatalAlert(AlertDescription.handshake_failure);
}