sun.security.internal.spec.TlsRsaPremasterSecretParameterSpec Java Examples

The following examples show how to use sun.security.internal.spec.TlsRsaPremasterSecretParameterSpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RSAClientKeyExchange.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
RSAClientKeyExchange(ProtocolVersion protocolVersion,
        ProtocolVersion maxVersion,
        SecureRandom generator, PublicKey publicKey) throws IOException {
    if (publicKey.getAlgorithm().equals("RSA") == false) {
        throw new SSLKeyException("Public key not of type RSA");
    }
    this.protocolVersion = protocolVersion;

    try {
        String s = ((protocolVersion.v >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                maxVersion.v, protocolVersion.v), generator);
        preMaster = kg.generateKey();

        Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
        cipher.init(Cipher.WRAP_MODE, publicKey, generator);
        encrypted = cipher.wrap(preMaster);
    } catch (GeneralSecurityException e) {
        throw (SSLKeyException)new SSLKeyException
                            ("RSA premaster secret error").initCause(e);
    }
}
 
Example #2
Source File: RSAClientKeyExchange.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
RSAClientKeyExchange(ProtocolVersion protocolVersion,
        ProtocolVersion maxVersion,
        SecureRandom generator, PublicKey publicKey) throws IOException {
    if (publicKey.getAlgorithm().equals("RSA") == false) {
        throw new SSLKeyException("Public key not of type RSA: " +
            publicKey.getAlgorithm());
    }
    this.protocolVersion = protocolVersion;

    try {
        String s = ((protocolVersion.v >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                maxVersion.v, protocolVersion.v), generator);
        preMaster = kg.generateKey();

        Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
        cipher.init(Cipher.WRAP_MODE, publicKey, generator);
        encrypted = cipher.wrap(preMaster);
    } catch (GeneralSecurityException e) {
        throw (SSLKeyException)new SSLKeyException
                            ("RSA premaster secret error").initCause(e);
    }
}
 
Example #3
Source File: RSAClientKeyExchange.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static SecretKey generatePreMasterSecret(
        ProtocolVersion version, byte[] encodedSecret,
        SecureRandom generator) {

    if (debug != null && Debug.isOn("handshake")) {
        System.out.println("Generating a random fake premaster secret");
    }

    try {
        String s = ((version.v >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                version.major, version.minor, encodedSecret), generator);
        return kg.generateKey();
    } catch (InvalidAlgorithmParameterException |
            NoSuchAlgorithmException iae) {
        // unlikely to happen, otherwise, must be a provider exception
        if (debug != null && Debug.isOn("handshake")) {
            System.out.println("RSA premaster secret generation error:");
            iae.printStackTrace(System.out);
        }
        throw new RuntimeException("Could not generate dummy secret", iae);
    }
}
 
Example #4
Source File: RSAClientKeyExchange.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
RSAClientKeyExchange(ProtocolVersion protocolVersion,
        ProtocolVersion maxVersion,
        SecureRandom generator, PublicKey publicKey) throws IOException {
    if (publicKey.getAlgorithm().equals("RSA") == false) {
        throw new SSLKeyException("Public key not of type RSA: " +
            publicKey.getAlgorithm());
    }
    this.protocolVersion = protocolVersion;

    try {
        String s = ((protocolVersion.v >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                maxVersion.v, protocolVersion.v), generator);
        preMaster = kg.generateKey();

        Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
        cipher.init(Cipher.WRAP_MODE, publicKey, generator);
        encrypted = cipher.wrap(preMaster);
    } catch (GeneralSecurityException e) {
        throw (SSLKeyException)new SSLKeyException
                            ("RSA premaster secret error").initCause(e);
    }
}
 
Example #5
Source File: RSAClientKeyExchange.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
RSAClientKeyExchange(ProtocolVersion protocolVersion,
        ProtocolVersion maxVersion,
        SecureRandom generator, PublicKey publicKey) throws IOException {
    if (publicKey.getAlgorithm().equals("RSA") == false) {
        throw new SSLKeyException("Public key not of type RSA: " +
            publicKey.getAlgorithm());
    }
    this.protocolVersion = protocolVersion;

    try {
        String s = protocolVersion.useTLS12PlusSpec() ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret";
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                maxVersion.v, protocolVersion.v), generator);
        preMaster = kg.generateKey();

        Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
        cipher.init(Cipher.WRAP_MODE, publicKey, generator);
        encrypted = cipher.wrap(preMaster);
    } catch (GeneralSecurityException e) {
        throw (SSLKeyException)new SSLKeyException
                            ("RSA premaster secret error").initCause(e);
    }
}
 
Example #6
Source File: RSAClientKeyExchange.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
RSAClientKeyExchange(ProtocolVersion protocolVersion,
        ProtocolVersion maxVersion,
        SecureRandom generator, PublicKey publicKey) throws IOException {
    if (publicKey.getAlgorithm().equals("RSA") == false) {
        throw new SSLKeyException("Public key not of type RSA: " +
            publicKey.getAlgorithm());
    }
    this.protocolVersion = protocolVersion;

    try {
        String s = ((protocolVersion.v >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                maxVersion.v, protocolVersion.v), generator);
        preMaster = kg.generateKey();

        Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
        cipher.init(Cipher.WRAP_MODE, publicKey, generator);
        encrypted = cipher.wrap(preMaster);
    } catch (GeneralSecurityException e) {
        throw (SSLKeyException)new SSLKeyException
                            ("RSA premaster secret error").initCause(e);
    }
}
 
Example #7
Source File: P11TlsRsaPremasterSecretGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
        throw new InvalidAlgorithmParameterException(MSG);
    }

    TlsRsaPremasterSecretParameterSpec spec =
        (TlsRsaPremasterSecretParameterSpec) params;

    int version = (spec.getMajorVersion() << 8) | spec.getMinorVersion();

    if ((version == 0x0300 && !supportSSLv3) || (version < 0x0300) ||
        (version > 0x0302)) {
         throw new InvalidAlgorithmParameterException
                ("Only" + (supportSSLv3? " SSL 3.0,": "") +
                 " TLS 1.0, and TLS 1.1 are supported (0x" +
                 Integer.toHexString(version) + ")");
    }
    this.spec = spec;
}
 
Example #8
Source File: RSAClientKeyExchange.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
RSAClientKeyExchange(ProtocolVersion protocolVersion,
        ProtocolVersion maxVersion,
        SecureRandom generator, PublicKey publicKey) throws IOException {
    if (publicKey.getAlgorithm().equals("RSA") == false) {
        throw new SSLKeyException("Public key not of type RSA: " +
            publicKey.getAlgorithm());
    }
    this.protocolVersion = protocolVersion;

    try {
        String s = ((protocolVersion.v >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                maxVersion.v, protocolVersion.v), generator);
        preMaster = kg.generateKey();

        Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
        cipher.init(Cipher.WRAP_MODE, publicKey, generator);
        encrypted = cipher.wrap(preMaster);
    } catch (GeneralSecurityException e) {
        throw (SSLKeyException)new SSLKeyException
                            ("RSA premaster secret error").initCause(e);
    }
}
 
Example #9
Source File: RSAClientKeyExchange.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static SecretKey generatePreMasterSecret(
        ProtocolVersion version, byte[] encodedSecret,
        SecureRandom generator) {

    if (debug != null && Debug.isOn("handshake")) {
        System.out.println("Generating a random fake premaster secret");
    }

    try {
        String s = ((version.v >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                version.major, version.minor, encodedSecret), generator);
        return kg.generateKey();
    } catch (InvalidAlgorithmParameterException |
            NoSuchAlgorithmException iae) {
        // unlikely to happen, otherwise, must be a provider exception
        if (debug != null && Debug.isOn("handshake")) {
            System.out.println("RSA premaster secret generation error:");
            iae.printStackTrace(System.out);
        }
        throw new RuntimeException("Could not generate dummy secret", iae);
    }
}
 
Example #10
Source File: RSAClientKeyExchange.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
RSAClientKeyExchange(ProtocolVersion protocolVersion,
        ProtocolVersion maxVersion,
        SecureRandom generator, PublicKey publicKey) throws IOException {
    if (publicKey.getAlgorithm().equals("RSA") == false) {
        throw new SSLKeyException("Public key not of type RSA: " +
            publicKey.getAlgorithm());
    }
    this.protocolVersion = protocolVersion;

    try {
        String s = ((protocolVersion.v >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                maxVersion.v, protocolVersion.v), generator);
        preMaster = kg.generateKey();

        Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
        cipher.init(Cipher.WRAP_MODE, publicKey, generator);
        encrypted = cipher.wrap(preMaster);
    } catch (GeneralSecurityException e) {
        throw (SSLKeyException)new SSLKeyException
                            ("RSA premaster secret error").initCause(e);
    }
}
 
Example #11
Source File: RSAClientKeyExchange.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
RSAClientKeyExchange(ProtocolVersion protocolVersion,
        ProtocolVersion maxVersion,
        SecureRandom generator, PublicKey publicKey) throws IOException {
    if (publicKey.getAlgorithm().equals("RSA") == false) {
        throw new SSLKeyException("Public key not of type RSA: " +
            publicKey.getAlgorithm());
    }
    this.protocolVersion = protocolVersion;

    try {
        String s = ((protocolVersion.v >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                maxVersion.v, protocolVersion.v), generator);
        preMaster = kg.generateKey();

        Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
        cipher.init(Cipher.WRAP_MODE, publicKey, generator);
        encrypted = cipher.wrap(preMaster);
    } catch (GeneralSecurityException e) {
        throw (SSLKeyException)new SSLKeyException
                            ("RSA premaster secret error").initCause(e);
    }
}
 
Example #12
Source File: TestPremaster.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void test(KeyGenerator kg,
        int clientVersion, int serverVersion) throws Exception {

    System.out.printf(
            "Testing RSA pre-master secret key generation between " +
            "client (0x%04X) and server(0x%04X)%n",
            clientVersion, serverVersion);
    kg.init(new TlsRsaPremasterSecretParameterSpec(
                                clientVersion, serverVersion));
    SecretKey key = kg.generateKey();
    byte[] encoded = key.getEncoded();
    if (encoded != null) {  // raw key material may be not extractable
        if (encoded.length != 48) {
            throw new Exception("length: " + encoded.length);
        }
        int v = versionOf(encoded[0], encoded[1]);
        if (clientVersion != v) {
            if (serverVersion != v || clientVersion >= 0x0302) {
                throw new Exception(String.format(
                    "version mismatch: (0x%04X) rather than (0x%04X) " +
                    "is used in pre-master secret", v, clientVersion));
            }
            System.out.printf("Use compatible version (0x%04X)%n", v);
        }
        System.out.println("Passed, version matches!");
   } else {
        System.out.println("Raw key material is not extractable");
   }
}
 
Example #13
Source File: RSACipher.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
protected void engineInit(int opmode, Key key,
        AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {

    if (params != null) {
        if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
            throw new InvalidAlgorithmParameterException(
                    "Parameters not supported");
        }
        spec = params;
        this.random = random;   // for TLS RSA premaster secret
    }
    init(opmode, key);
}
 
Example #14
Source File: TestPremaster.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void test(KeyGenerator kg,
        int clientVersion, int serverVersion) throws Exception {

    System.out.printf(
            "Testing RSA pre-master secret key generation between " +
            "client (0x%04X) and server(0x%04X)%n",
            clientVersion, serverVersion);
    kg.init(new TlsRsaPremasterSecretParameterSpec(
                                clientVersion, serverVersion));

    SecretKey key = kg.generateKey();
    byte[] encoded = key.getEncoded();
    if (encoded != null) {  // raw key material may be not extractable
        if (encoded.length != 48) {
            throw new Exception("length: " + encoded.length);
        }
        int v = versionOf(encoded[0], encoded[1]);
        if (clientVersion != v) {
            if (serverVersion != v || clientVersion >= 0x0302) {
                throw new Exception(String.format(
                    "version mismatch: (0x%04X) rather than (0x%04X) " +
                    "is used in pre-master secret", v, clientVersion));
            }
            System.out.printf("Use compatible version (0x%04X)%n", v);
        }
        System.out.println("Passed, version matches!");
   } else {
        System.out.println("Raw key material is not extractable");
   }
}
 
Example #15
Source File: P11TlsRsaPremasterSecretGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsRsaPremasterSecretParameterSpec)params;
}
 
Example #16
Source File: P11RSACipher.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null) {
        if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
            throw new InvalidAlgorithmParameterException(
                    "Parameters not supported");
        }
        spec = params;
        this.random = random;   // for TLS RSA premaster secret
    }
    implInit(opmode, key);
}
 
Example #17
Source File: TlsRsaPremasterSecretGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsRsaPremasterSecretParameterSpec)params;
    this.random = random;
}
 
Example #18
Source File: RSACipher.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {

    if (params != null) {
        if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
            throw new InvalidAlgorithmParameterException(
                    "Parameters not supported");
        }
        spec = params;
        this.random = random;   // for TLS RSA premaster secret
    }
    init(opmode, key);
}
 
Example #19
Source File: RSAClientKeyExchange.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
RSAClientKeyExchange(ProtocolVersion protocolVersion,
        ProtocolVersion maxVersion,
        SecureRandom generator, PublicKey publicKey) throws IOException {
    if (publicKey.getAlgorithm().equals("RSA") == false) {
        throw new SSLKeyException("Public key not of type RSA");
    }
    this.protocolVersion = protocolVersion;

    int major, minor;

    if (rsaPreMasterSecretFix || maxVersion.v >= ProtocolVersion.TLS11.v) {
        major = maxVersion.major;
        minor = maxVersion.minor;
    } else {
        major = protocolVersion.major;
        minor = protocolVersion.minor;
    }

    try {
        String s = ((protocolVersion.v >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(major, minor),
                generator);
        preMaster = kg.generateKey();

        Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
        cipher.init(Cipher.WRAP_MODE, publicKey, generator);
        encrypted = cipher.wrap(preMaster);
    } catch (GeneralSecurityException e) {
        throw (SSLKeyException)new SSLKeyException
                            ("RSA premaster secret error").initCause(e);
    }
}
 
Example #20
Source File: TlsRsaPremasterSecretGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (params instanceof TlsRsaPremasterSecretParameterSpec == false) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsRsaPremasterSecretParameterSpec)params;
    this.random = random;
}
 
Example #21
Source File: RSAClientKeyExchange.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static SecretKey generatePreMasterSecret(
        int clientVersion, int serverVersion,
        byte[] encodedSecret, SecureRandom generator) {

    if (debug != null && Debug.isOn("handshake")) {
        System.out.println("Generating a premaster secret");
    }

    try {
        String s = ((clientVersion >= ProtocolVersion.TLS12.v) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = JsseJce.getKeyGenerator(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                clientVersion, serverVersion, encodedSecret),
                generator);
        return kg.generateKey();
    } catch (InvalidAlgorithmParameterException |
            NoSuchAlgorithmException iae) {
        // unlikely to happen, otherwise, must be a provider exception
        if (debug != null && Debug.isOn("handshake")) {
            System.out.println("RSA premaster secret generation error:");
            iae.printStackTrace(System.out);
        }
        throw new RuntimeException("Could not generate premaster secret", iae);
    }
}
 
Example #22
Source File: P11RSACipher.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null) {
        if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
            throw new InvalidAlgorithmParameterException(
                    "Parameters not supported");
        }
        spec = params;
        this.random = random;   // for TLS RSA premaster secret
    }
    implInit(opmode, key);
}
 
Example #23
Source File: TlsRsaPremasterSecretGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (params instanceof TlsRsaPremasterSecretParameterSpec == false) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsRsaPremasterSecretParameterSpec)params;
    this.random = random;
}
 
Example #24
Source File: RSAKeyExchange.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static SecretKey generatePremasterSecret(
        int clientVersion, int serverVersion, byte[] encodedSecret,
        SecureRandom generator) throws GeneralSecurityException {

    if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
        SSLLogger.fine("Generating a premaster secret");
    }

    try {
        String s = ((clientVersion >= ProtocolVersion.TLS12.id) ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
        KeyGenerator kg = KeyGenerator.getInstance(s);
        kg.init(new TlsRsaPremasterSecretParameterSpec(
                clientVersion, serverVersion, encodedSecret),
                generator);
        return kg.generateKey();
    } catch (InvalidAlgorithmParameterException |
            NoSuchAlgorithmException iae) {
        // unlikely to happen, otherwise, must be a provider exception
        if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
            SSLLogger.fine("RSA premaster secret generation error:");
            iae.printStackTrace(System.out);
        }

        throw new GeneralSecurityException(
                "Could not generate premaster secret", iae);
    }
}
 
Example #25
Source File: RSAKeyExchange.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
static RSAPremasterSecret createPremasterSecret(
        ClientHandshakeContext chc) throws GeneralSecurityException {
    String algorithm = chc.negotiatedProtocol.useTLS12PlusSpec() ?
            "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret";
    KeyGenerator kg = KeyGenerator.getInstance(algorithm);
    TlsRsaPremasterSecretParameterSpec spec =
            new TlsRsaPremasterSecretParameterSpec(
                    chc.clientHelloVersion,
                    chc.negotiatedProtocol.id);
    kg.init(spec, chc.sslContext.getSecureRandom());

    return new RSAPremasterSecret(kg.generateKey());
}
 
Example #26
Source File: TestPremaster.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void test(KeyGenerator kg,
        int clientVersion, int serverVersion) throws Exception {

    System.out.printf(
            "Testing RSA pre-master secret key generation between " +
            "client (0x%04X) and server(0x%04X)%n",
            clientVersion, serverVersion);
    kg.init(new TlsRsaPremasterSecretParameterSpec(
                                clientVersion, serverVersion));

    SecretKey key = kg.generateKey();
    byte[] encoded = key.getEncoded();
    if (encoded != null) {  // raw key material may be not extractable
        if (encoded.length != 48) {
            throw new Exception("length: " + encoded.length);
        }
        int v = versionOf(encoded[0], encoded[1]);
        if (clientVersion != v) {
            if (serverVersion != v || clientVersion >= 0x0302) {
                throw new Exception(String.format(
                    "version mismatch: (0x%04X) rather than (0x%04X) " +
                    "is used in pre-master secret", v, clientVersion));
            }
            System.out.printf("Use compatible version (0x%04X)%n", v);
        }
        System.out.println("Passed, version matches!");
   } else {
        System.out.println("Raw key material is not extractable");
   }
}
 
Example #27
Source File: TestPremaster.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void test(KeyGenerator kg,
        int clientVersion, int serverVersion) throws Exception {

    System.out.printf(
            "Testing RSA pre-master secret key generation between " +
            "client (0x%04X) and server(0x%04X)%n",
            clientVersion, serverVersion);
    kg.init(new TlsRsaPremasterSecretParameterSpec(
                                clientVersion, serverVersion));
    SecretKey key = kg.generateKey();
    byte[] encoded = key.getEncoded();
    if (encoded != null) {  // raw key material may be not extractable
        if (encoded.length != 48) {
            throw new Exception("length: " + encoded.length);
        }
        int v = versionOf(encoded[0], encoded[1]);
        if (clientVersion != v) {
            if (serverVersion != v || clientVersion >= 0x0302) {
                throw new Exception(String.format(
                    "version mismatch: (0x%04X) rather than (0x%04X) " +
                    "is used in pre-master secret", v, clientVersion));
            }
            System.out.printf("Use compatible version (0x%04X)%n", v);
        }
        System.out.println("Passed, version matches!");
   } else {
        System.out.println("Raw key material is not extractable");
   }
}
 
Example #28
Source File: P11RSACipher.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null) {
        if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
            throw new InvalidAlgorithmParameterException(
                    "Parameters not supported");
        }
        spec = params;
        this.random = random;   // for TLS RSA premaster secret
    }
    implInit(opmode, key);
}
 
Example #29
Source File: TlsRsaPremasterSecretGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsRsaPremasterSecretParameterSpec)params;
    this.random = random;
}
 
Example #30
Source File: P11TlsRsaPremasterSecretGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsRsaPremasterSecretParameterSpec)params;
}