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: /**
19: * @author Boris Kuznetsov
20: * @version $Revision$
21: */package org.apache.harmony.xnet.provider.jsse;
22:
23: import org.apache.harmony.xnet.provider.jsse.Message;
24: import org.apache.harmony.xnet.provider.jsse.Handshake;
25: import org.apache.harmony.xnet.provider.jsse.HandshakeIODataStream;
26: import org.apache.harmony.xnet.provider.jsse.AlertProtocol;
27:
28: import java.io.IOException;
29:
30: /**
31: *
32: * Represents certificate verify message
33: * @see TLS 1.0 spec., 7.4.8. Certificate verify
34: * (http://www.ietf.org/rfc/rfc2246.txt)
35: */
36: public class CertificateVerify extends Message {
37:
38: /**
39: * Signature
40: */
41: byte[] signedHash;
42:
43: /**
44: * Creates outbound message
45: *
46: * @param hash
47: */
48: public CertificateVerify(byte[] hash) {
49: if (hash == null || hash.length == 0) {
50: fatalAlert(AlertProtocol.INTERNAL_ERROR,
51: "INTERNAL ERROR: incorrect certificate verify hash");
52: }
53: this .signedHash = hash;
54: length = hash.length + 2;
55: }
56:
57: /**
58: * Creates inbound message
59: *
60: * @param in
61: * @param length
62: * @throws IOException
63: */
64: public CertificateVerify(HandshakeIODataStream in, int length)
65: throws IOException {
66: if (length == 0) {
67: fatalAlert(AlertProtocol.DECODE_ERROR,
68: "DECODE ERROR: incorrect CertificateVerify");
69: } else {
70: if (in.readUint16() != length - 2) {
71: fatalAlert(AlertProtocol.DECODE_ERROR,
72: "DECODE ERROR: incorrect CertificateVerify");
73: }
74: signedHash = in.read(length - 2);
75: }
76: this .length = length;
77: }
78:
79: /**
80: * Sends message
81: *
82: * @param out
83: */
84: public void send(HandshakeIODataStream out) {
85: if (signedHash.length != 0) {
86: out.writeUint16(signedHash.length);
87: out.write(signedHash);
88: }
89: }
90:
91: /**
92: * Returns message type
93: *
94: * @return
95: */
96: public int getType() {
97: return Handshake.CERTIFICATE_VERIFY;
98: }
99: }
|