コード例 #1
0
  protected void processCertificateVerify(
      ServerHandshakeState state, byte[] body, TlsHandshakeHash prepareFinishHash)
      throws IOException {
    ByteArrayInputStream buf = new ByteArrayInputStream(body);

    DigitallySigned clientCertificateVerify = DigitallySigned.parse(state.serverContext, buf);

    TlsProtocol.assertEmpty(buf);

    // Verify the CertificateVerify message contains a correct signature.
    try {
      // TODO For TLS 1.2, this needs to be the hash specified in the DigitallySigned
      byte[] certificateVerifyHash =
          TlsProtocol.getCurrentPRFHash(state.serverContext, prepareFinishHash, null);

      org.bouncycastle.asn1.x509.Certificate x509Cert = state.clientCertificate.getCertificateAt(0);
      SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
      AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(keyInfo);

      TlsSigner tlsSigner = TlsUtils.createTlsSigner(state.clientCertificateType);
      tlsSigner.init(state.serverContext);
      tlsSigner.verifyRawSignature(
          clientCertificateVerify.getAlgorithm(),
          clientCertificateVerify.getSignature(),
          publicKey,
          certificateVerifyHash);
    } catch (Exception e) {
      throw new TlsFatalAlert(AlertDescription.decrypt_error);
    }
  }
コード例 #2
0
 public byte[] generateCertificateSignature(byte[] hash) throws IOException {
   try {
     if (TlsUtils.isTLSv12(context)) {
       return signer.generateRawSignature(signatureAndHashAlgorithm, privateKey, hash);
     } else {
       return signer.generateRawSignature(privateKey, hash);
     }
   } catch (CryptoException e) {
     throw new TlsFatalAlert(AlertDescription.internal_error, e);
   }
 }
コード例 #3
0
  public void processServerCertificate(Certificate serverCertificate) throws IOException {
    X509CertificateStructure x509Cert = serverCertificate.certs[0];
    SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();

    try {
      this.serverPublicKey = PublicKeyFactory.createKey(keyInfo);
    } catch (RuntimeException e) {
      throw new TlsFatalAlert(AlertDescription.unsupported_certificate);
    }

    if (tlsSigner == null) {
      try {
        this.dhAgreeServerPublicKey =
            validateDHPublicKey((DHPublicKeyParameters) this.serverPublicKey);
      } catch (ClassCastException e) {
        throw new TlsFatalAlert(AlertDescription.certificate_unknown);
      }

      TlsUtils.validateKeyUsage(x509Cert, KeyUsage.keyAgreement);
    } else {
      if (!tlsSigner.isValidPublicKey(this.serverPublicKey)) {
        throw new TlsFatalAlert(AlertDescription.certificate_unknown);
      }

      TlsUtils.validateKeyUsage(x509Cert, KeyUsage.digitalSignature);
    }

    // TODO
    /*
     * Perform various checks per RFC2246 7.4.2: "Unless otherwise specified, the
     * signing algorithm for the certificate must be the same as the algorithm for the
     * certificate key."
     */
  }
コード例 #4
0
  public void processServerCertificate(Certificate serverCertificate) throws IOException {
    if (serverCertificate.isEmpty()) {
      throw new TlsFatalAlert(AlertDescription.bad_certificate);
    }

    org.ripple.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0);

    SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
    try {
      this.serverPublicKey = PublicKeyFactory.createKey(keyInfo);
    } catch (RuntimeException e) {
      throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e);
    }

    if (tlsSigner == null) {
      try {
        this.dhAgreePublicKey =
            TlsDHUtils.validateDHPublicKey((DHPublicKeyParameters) this.serverPublicKey);
        this.dhParameters = validateDHParameters(dhAgreePublicKey.getParameters());
      } catch (ClassCastException e) {
        throw new TlsFatalAlert(AlertDescription.certificate_unknown, e);
      }

      TlsUtils.validateKeyUsage(x509Cert, KeyUsage.keyAgreement);
    } else {
      if (!tlsSigner.isValidPublicKey(this.serverPublicKey)) {
        throw new TlsFatalAlert(AlertDescription.certificate_unknown);
      }

      TlsUtils.validateKeyUsage(x509Cert, KeyUsage.digitalSignature);
    }

    super.processServerCertificate(serverCertificate);
  }