author | coffeys |
Tue, 20 Nov 2018 13:12:48 +0000 | |
changeset 52621 | f7309a1491d9 |
child 53010 | 086dfcfc3731 |
permissions | -rw-r--r-- |
52621
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
1 |
/* |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
4 |
* |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
8 |
* |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
13 |
* accompanied this code). |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
14 |
* |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
18 |
* |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
21 |
* questions. |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
22 |
*/ |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
23 |
|
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
24 |
package jdk.jfr.event.security; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
25 |
|
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
26 |
import java.util.List; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
27 |
|
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
28 |
import jdk.jfr.AnnotationElement; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
29 |
import jdk.jfr.EventType; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
30 |
import jdk.jfr.FlightRecorder; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
31 |
import jdk.jfr.Recording; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
32 |
import jdk.jfr.consumer.RecordedEvent; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
33 |
import jdk.test.lib.Asserts; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
34 |
import jdk.test.lib.jfr.Events; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
35 |
import jdk.test.lib.jfr.EventNames; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
36 |
import jdk.test.lib.security.TestCertificate; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
37 |
|
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
38 |
/* |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
39 |
* @test |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
40 |
* @bug 8148188 |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
41 |
* @summary Enhance the security libraries to record events of interest |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
42 |
* @key jfr |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
43 |
* @library /test/lib |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
44 |
* @modules jdk.jfr/jdk.jfr.events |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
45 |
* @run main/othervm jdk.jfr.event.security.TestX509ValidationEvent |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
46 |
*/ |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
47 |
public class TestX509ValidationEvent { |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
48 |
public static void main(String[] args) throws Exception { |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
49 |
try (Recording recording = new Recording()) { |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
50 |
recording.enable(EventNames.X509Validation); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
51 |
recording.start(); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
52 |
// intermeditate certificate test |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
53 |
TestCertificate.generateChain(false); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
54 |
recording.stop(); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
55 |
List<RecordedEvent> events = Events.fromRecording(recording); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
56 |
Asserts.assertEquals(events.size(), 3, "Incorrect number of events"); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
57 |
assertEvent1(events); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
58 |
} |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
59 |
|
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
60 |
try (Recording recording = new Recording()) { |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
61 |
recording.enable(EventNames.X509Validation); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
62 |
recording.start(); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
63 |
// self signed certificate test |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
64 |
TestCertificate.generateChain(true); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
65 |
recording.stop(); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
66 |
List<RecordedEvent> events = Events.fromRecording(recording); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
67 |
Asserts.assertEquals(events.size(), 2, "Incorrect number of events"); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
68 |
assertEvent2(events); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
69 |
} |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
70 |
} |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
71 |
|
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
72 |
private static void assertEvent1(List<RecordedEvent> events) throws Exception { |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
73 |
for (RecordedEvent e : events) { |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
74 |
int pos = e.getInt("certificatePosition"); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
75 |
switch (pos) { |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
76 |
case 1: |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
77 |
Events.assertField(e, "certificateId") |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
78 |
.equal(TestCertificate.ROOT_CA.certId); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
79 |
break; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
80 |
case 2: |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
81 |
Events.assertField(e, "certificateId") |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
82 |
.equal(TestCertificate.TWO.certId); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
83 |
break; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
84 |
case 3: |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
85 |
Events.assertField(e, "certificateId") |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
86 |
.equal(TestCertificate.ONE.certId); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
87 |
break; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
88 |
default: |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
89 |
System.out.println(events); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
90 |
throw new Exception("Unexpected position:" + pos); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
91 |
} |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
92 |
} |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
93 |
} |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
94 |
|
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
95 |
/* |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
96 |
* Self signed certificate test |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
97 |
*/ |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
98 |
private static void assertEvent2(List<RecordedEvent> events) throws Exception { |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
99 |
for (RecordedEvent e : events) { |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
100 |
int pos = e.getInt("certificatePosition"); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
101 |
switch (pos) { |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
102 |
case 1: |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
103 |
case 2: |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
104 |
Events.assertField(e, "certificateId") |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
105 |
.equal(TestCertificate.ROOT_CA.certId); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
106 |
break; |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
107 |
default: |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
108 |
System.out.println(events); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
109 |
throw new Exception("Unexpected position:" + pos); |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
110 |
} |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
111 |
} |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
112 |
} |
f7309a1491d9
8148188: Enhance the security libraries to record events of interest
coffeys
parents:
diff
changeset
|
113 |
} |