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.AnnotationElement; 29 import jdk.jfr.EventType; 30 import jdk.jfr.FlightRecorder; 31 import jdk.jfr.Recording; 32 import jdk.jfr.consumer.RecordedEvent; 33 import jdk.test.lib.Asserts; 34 import jdk.test.lib.jfr.Events; 35 import jdk.test.lib.jfr.EventNames; 36 import jdk.test.lib.security.TestCertificate; 37 38 /* 39 * @test 40 * @bug 8148188 41 * @summary Enhance the security libraries to record events of interest 42 * @key jfr 43 * @library /test/lib 44 * @modules jdk.jfr/jdk.jfr.events 45 * @run main/othervm jdk.jfr.event.security.TestX509ValidationEvent 46 */ 47 public class TestX509ValidationEvent { 48 public static void main(String[] args) throws Exception { 49 try (Recording recording = new Recording()) { 50 recording.enable(EventNames.X509Validation); 51 recording.start(); 52 TestCertificate.generateChain(); 53 recording.stop(); 54 55 List<RecordedEvent> events = Events.fromRecording(recording); 56 Asserts.assertEquals(events.size(), 3, "Incorrect number of events"); 57 assertEvent(events); 58 } 59 } 60 61 private static void assertEvent(List<RecordedEvent> events) throws Exception { 62 for (RecordedEvent e : events) { 63 int pos = e.getInt("certificatePosition"); 64 switch (pos) { 65 case 1: 66 Events.assertField(e, "certificateId") 67 .equal(TestCertificate.ROOT_CA.serialNumber); 68 break; 69 case 2: 70 Events.assertField(e, "certificateId") 71 .equal(TestCertificate.TWO.serialNumber); 72 break; 73 case 3: 74 Events.assertField(e, "certificateId") 75 .equal(TestCertificate.ONE.serialNumber); 76 break; 77 default: 78 System.out.println(events); 79 throw new Exception("Unexpected position:" + pos); 80 } 81 } 82 } 83 }