01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.xnet.provider.jsse;
19:
20: import java.util.Arrays;
21:
22: import junit.framework.TestCase;
23:
24: /**
25: * Tests for <code>CertificateVerify</code> constructor and methods
26: *
27: */
28: public class CertificateVerifyTest extends TestCase {
29:
30: public void testCertificateVerify() throws Exception {
31: byte[] anonHash = new byte[0];
32: byte[] RSAHash = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
33: 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
34: 0, 1, 2, 3, 4, 5, 6 };
35: byte[] DSAHash = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
36: 2, 3, 4, 5, 6, 7, 8, 9, 0 };
37: byte[][] signatures = new byte[][] { RSAHash, DSAHash };
38: try {
39: new CertificateVerify(anonHash);
40: fail("Anonymous: No expected AlertException");
41: } catch (AlertException e) {
42: }
43: try {
44: HandshakeIODataStream in = new HandshakeIODataStream();
45: new CertificateVerify(in, 0);
46: fail("Anonymous: No expected AlertException");
47: } catch (AlertException e) {
48: }
49: for (int i = 0; i < signatures.length; i++) {
50: CertificateVerify message = new CertificateVerify(
51: signatures[i]);
52: assertEquals("incorrect type",
53: Handshake.CERTIFICATE_VERIFY, message.getType());
54: assertTrue("incorrect CertificateVerify", Arrays.equals(
55: message.signedHash, signatures[i]));
56:
57: HandshakeIODataStream out = new HandshakeIODataStream();
58: message.send(out);
59: byte[] encoded = out.getData(1000);
60: assertEquals("incorrect out data length", message.length(),
61: encoded.length);
62:
63: HandshakeIODataStream in = new HandshakeIODataStream();
64: in.append(encoded);
65: CertificateVerify message_2 = new CertificateVerify(in,
66: message.length());
67: assertTrue("incorrect message decoding", Arrays.equals(
68: message.signedHash, message_2.signedHash));
69:
70: in.append(encoded);
71: try {
72: message_2 = new CertificateVerify(in,
73: message.length() - 1);
74: fail("Small length: No expected AlertException");
75: } catch (AlertException e) {
76: }
77:
78: in.append(encoded);
79: in.append(new byte[] { 1, 2, 3 });
80: try {
81: message_2 = new CertificateVerify(in,
82: message.length() + 3);
83: fail("Extra bytes: No expected AlertException ");
84: } catch (AlertException e) {
85: }
86: }
87: }
88:
89: }
|