Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/provider/SecureRandom/DRBGS11n.java
41154 views
1
/*
2
* Copyright (c) 2016, 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
import sun.security.provider.DRBG;
24
import sun.security.provider.MoreDrbgParameters;
25
26
import java.io.ByteArrayInputStream;
27
import java.io.ByteArrayOutputStream;
28
import java.io.ObjectInputStream;
29
import java.io.ObjectOutputStream;
30
import java.lang.reflect.Field;
31
32
/**
33
* @test
34
* @bug 8157308
35
* @modules java.base/sun.security.provider:+open
36
* @summary Make AbstractDrbg non-Serializable
37
* @run main DRBGS11n mech
38
* @run main DRBGS11n capability
39
*/
40
public class DRBGS11n {
41
42
public static void main(String[] args) throws Exception {
43
44
DRBG d = new DRBG(null);
45
Field f = DRBG.class.getDeclaredField("mdp");
46
f.setAccessible(true);
47
MoreDrbgParameters mdp = (MoreDrbgParameters)f.get(d);
48
49
// Corrupt the mech or capability fields inside DRBG#mdp.
50
f = MoreDrbgParameters.class.getDeclaredField(args[0]);
51
f.setAccessible(true);
52
f.set(mdp, null);
53
54
try {
55
revive(d);
56
} catch (IllegalArgumentException iae) {
57
// Expected
58
return;
59
}
60
61
throw new Exception("revive should fail");
62
}
63
64
static <T> T revive(T in) throws Exception {
65
ByteArrayOutputStream bout = new ByteArrayOutputStream();
66
new ObjectOutputStream(bout).writeObject(in);
67
return (T) new ObjectInputStream(
68
new ByteArrayInputStream(bout.toByteArray())).readObject();
69
}
70
}
71
72