1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.jfr.event.security; 25 26 import java.util.List; 27 28 import jdk.jfr.Recording; 29 import jdk.jfr.consumer.RecordedEvent; 30 import jdk.test.lib.jfr.EventNames; 31 import jdk.test.lib.jfr.Events; 32 import jdk.test.lib.security.TestTLSHandshake; 33 34 /* 35 * @test 36 * @bug 8148188 37 * @summary Enhance the security libraries to record events of interest 38 * @key jfr 39 * @library /test/lib 40 * @run main/othervm jdk.jfr.event.security.TestTLSHandshakeEvent 41 */ 42 public class TestTLSHandshakeEvent { 43 public static void main(String[] args) throws Exception { 44 try (Recording recording = new Recording()) { 45 recording.enable(EventNames.TLSHandshake); 46 recording.start(); 47 TestTLSHandshake handshake = new TestTLSHandshake(); 48 handshake.run(); 49 recording.stop(); 50 51 List<RecordedEvent> events = Events.fromRecording(recording); 52 Events.hasEvents(events); 53 assertEvent(events, handshake); 54 } 55 } 56 57 private static void assertEvent(List<RecordedEvent> events, TestTLSHandshake handshake) throws Exception { 58 System.out.println(events); 59 for (RecordedEvent e : events) { 60 if (handshake.peerHost.equals(e.getString("peerHost"))) { 61 Events.assertField(e, "peerPort").equal(handshake.peerPort); 62 Events.assertField(e, "protocolVersion").equal(handshake.protocolVersion); 63 Events.assertField(e, "peerCertId").equal(TestTLSHandshake.CERT_SERIAL); 64 Events.assertField(e, "cipherSuite").equal(TestTLSHandshake.CIPHER_SUITE); 65 return; 66 } 67 } 68 System.out.println(events); 69 throw new Exception("Could not find event with hostname: " + handshake.peerHost); 70 } 71 }