sun.security.internal.interfaces.TlsMasterSecret Java Examples

The following examples show how to use sun.security.internal.interfaces.TlsMasterSecret. 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: TestMasterSecret.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #2
Source File: TestMasterSecret.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #3
Source File: TestMasterSecret.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #4
Source File: TestMasterSecret.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #5
Source File: TestMasterSecret.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #6
Source File: TestMasterSecret.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #7
Source File: TestMasterSecret.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #8
Source File: TestMasterSecret.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #9
Source File: TestMasterSecret.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #10
Source File: TestMasterSecret.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #11
Source File: TestMasterSecret.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #12
Source File: TestMasterSecret.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #13
Source File: TestMasterSecret.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #14
Source File: TestMasterSecret.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #15
Source File: TestMasterSecret.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #16
Source File: TestMasterSecret.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #17
Source File: TestMasterSecret.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }

    try (BufferedReader reader = Files.newBufferedReader(
            Paths.get(BASE, "masterdata.txt"))) {

        int n = 0;
        int lineNumber = 0;

        String algorithm = null;
        byte[] premaster = null;
        byte[] clientRandom = null;
        byte[] serverRandom = null;
        int protoMajor = 0;
        int protoMinor = 0;
        int preMajor = 0;
        int preMinor = 0;
        byte[] master = null;

        while (true) {
            String line = reader.readLine();
            lineNumber++;
            if (line == null) {
                break;
            }
            if (line.startsWith("m-") == false) {
                continue;
            }
            String data = line.substring(PREFIX_LENGTH);
            if (line.startsWith("m-algorithm:")) {
                algorithm = data;
            } else if (line.startsWith("m-premaster:")) {
                premaster = parse(data);
            } else if (line.startsWith("m-crandom:")) {
                clientRandom = parse(data);
            } else if (line.startsWith("m-srandom:")) {
                serverRandom = parse(data);
            } else if (line.startsWith("m-protomajor:")) {
                protoMajor = Integer.parseInt(data);
            } else if (line.startsWith("m-protominor:")) {
                protoMinor = Integer.parseInt(data);
            } else if (line.startsWith("m-premajor:")) {
                preMajor = Integer.parseInt(data);
            } else if (line.startsWith("m-preminor:")) {
                preMinor = Integer.parseInt(data);
            } else if (line.startsWith("m-master:")) {
                master = parse(data);

                System.out.print(".");
                n++;

                KeyGenerator kg =
                    KeyGenerator.getInstance("SunTlsMasterSecret", provider);
                SecretKey premasterKey =
                    new SecretKeySpec(premaster, algorithm);
                TlsMasterSecretParameterSpec spec =
                    new TlsMasterSecretParameterSpec(premasterKey,
                        protoMajor, protoMinor, clientRandom, serverRandom,
                        null, -1, -1);

                try {
                    kg.init(spec);
                    TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
                    byte[] enc = key.getEncoded();
                    if (Arrays.equals(master, enc) == false) {
                        throw new Exception("mismatch line: " + lineNumber);
                    }
                    if ((preMajor != key.getMajorVersion()) ||
                            (preMinor != key.getMinorVersion())) {
                       throw new Exception("version mismatch line: " + lineNumber);
                    }
                } catch (InvalidAlgorithmParameterException iape) {
                    // SSLv3 support is removed in S12
                    if (preMajor == 3 && preMinor == 0) {
                        System.out.println("Skip testing SSLv3");
                        continue;
                    }
                }
            } else {
                throw new Exception("Unknown line: " + line);
            }
        }
        if (n == 0) {
            throw new Exception("no tests");
        }
        System.out.println();
        System.out.println("OK: " + n + " tests");
    }
}
 
Example #18
Source File: TestMasterSecret.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #19
Source File: TestMasterSecret.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #20
Source File: TestMasterSecret.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #21
Source File: TestMasterSecret.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #22
Source File: TestMasterSecret.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #23
Source File: TestMasterSecret.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #24
Source File: TestMasterSecret.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #25
Source File: TestMasterSecret.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyGenerator", "SunTlsMasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey,
                    protoMajor, protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}
 
Example #26
Source File: TestMasterSecret.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    InputStream in = new FileInputStream(new File(BASE, "masterdata.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    int n = 0;
    int lineNumber = 0;

    String algorithm = null;
    byte[] premaster = null;
    byte[] clientRandom = null;
    byte[] serverRandom = null;
    int protoMajor = 0;
    int protoMinor = 0;
    int preMajor = 0;
    int preMinor = 0;
    byte[] master = null;

    while (true) {
        String line = reader.readLine();
        lineNumber++;
        if (line == null) {
            break;
        }
        if (line.startsWith("m-") == false) {
            continue;
        }
        String data = line.substring(PREFIX_LENGTH);
        if (line.startsWith("m-algorithm:")) {
            algorithm = data;
        } else if (line.startsWith("m-premaster:")) {
            premaster = parse(data);
        } else if (line.startsWith("m-crandom:")) {
            clientRandom = parse(data);
        } else if (line.startsWith("m-srandom:")) {
            serverRandom = parse(data);
        } else if (line.startsWith("m-protomajor:")) {
            protoMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-protominor:")) {
            protoMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-premajor:")) {
            preMajor = Integer.parseInt(data);
        } else if (line.startsWith("m-preminor:")) {
            preMinor = Integer.parseInt(data);
        } else if (line.startsWith("m-master:")) {
            master = parse(data);

            System.out.print(".");
            n++;

            KeyGenerator kg =
                KeyGenerator.getInstance("SunTlsMasterSecret", provider);
            SecretKey premasterKey =
                new SecretKeySpec(premaster, algorithm);
            TlsMasterSecretParameterSpec spec =
                new TlsMasterSecretParameterSpec(premasterKey, protoMajor,
                    protoMinor, clientRandom, serverRandom,
                    null, -1, -1);
            kg.init(spec);
            TlsMasterSecret key = (TlsMasterSecret)kg.generateKey();
            byte[] enc = key.getEncoded();
            if (Arrays.equals(master, enc) == false) {
                throw new Exception("mismatch line: " + lineNumber);
            }
            if ((preMajor != key.getMajorVersion()) ||
                    (preMinor != key.getMinorVersion())) {
                throw new Exception("version mismatch line: " + lineNumber);
            }
        } else {
            throw new Exception("Unknown line: " + line);
        }
    }
    if (n == 0) {
        throw new Exception("no tests");
    }
    in.close();
    System.out.println();
    System.out.println("OK: " + n + " tests");
}