jdk/test/java/security/Signature/VerifyRangeCheckOverflow.java
author jjg
Mon, 25 Nov 2013 17:42:28 -0800
changeset 21894 3535c1819067
parent 14856 92a1bcf46888
permissions -rw-r--r--
8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12875
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
     1
/*
14856
92a1bcf46888 8004982: JDK8 source with GPL header errors
katleman
parents: 12875
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
12875
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
     4
 *
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
     8
 *
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    13
 * accompanied this code).
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    14
 *
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    18
 *
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    21
 * questions.
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    22
 */
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    23
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    24
/*
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    25
 * Portions Copyright (c) 2012 IBM Corporation
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    26
 */
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    27
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    28
/* @test
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    29
 * @bug 7172149
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    30
 * @summary AIOOBE from Signature.verify after integer overflow
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    31
 * @author Jonathan Lu
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    32
 */
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    33
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    34
import java.security.KeyPair;
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    35
import java.security.KeyPairGenerator;
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    36
import java.security.PublicKey;
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    37
import java.security.Signature;
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    38
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    39
public class VerifyRangeCheckOverflow {
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    40
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    42
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    43
        keyPairGenerator.initialize(1024);
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    44
        KeyPair keys = keyPairGenerator.generateKeyPair();
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    45
        PublicKey publicKey = keys.getPublic();
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    46
        byte[] sigBytes = new byte[100];
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    47
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    48
        Signature signature = Signature.getInstance("SHA1withDSA");
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    49
        signature.initVerify(publicKey);
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    50
        try {
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    51
            signature.verify(sigBytes, Integer.MAX_VALUE, 1);
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    52
        } catch (IllegalArgumentException ex) {
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    53
            // Expected
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    54
        }
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    55
    }
43a1cd4cfc32 7172149: ArrayIndexOutOfBoundsException from Signature.verify
xuelei
parents:
diff changeset
    56
}